var diag22state = 0; 
//发送	
FuncReadDID = function(did){
	if(CANHw.isConnected() == false){
		return; 
	}
	var data = {0x03,0x22,did>>8,did&0xff,0,0,0,0};
	var ret = CANHw.SendMsg(DiagReqID,data);
	diag22state = 1;
	//console.log("did = " + tostring(did,16));
	//console.log("ret = " + ret);
	//FuncDisplay("did = " + tostring(did,16));
}

//接收
FuncDiag22Pro = function(data){
	//console.log("诊断22服务")
	if(#data < 3){
		return;
	}
	var did = (data[1]<<8) + data[2];
	select(did) {
		case 0xF186 {
			FuncDisplay("当前会话： " + data[3]);
		}
		case 0xF193 {
			FuncDisplay("硬件版本号");
			FuncDisplay(string.pack(table.slice(data,3)));
		}
		case 0xF195 {
			FuncDisplay("软件版本号");
			FuncDisplay(string.pack(table.slice(data,3)));
		}
		case 0xF198 {
			FuncDisplay("repair_shopcode");
			FuncDisplay(string.pack(table.slice(data,3)));
		}
		case 0xF199 {
			FuncDisplay("installation_date");
			FuncDisplay(string.format("%x%X%x%x",data[3],data[4],data[5],data[6]));
		}
		case 0xF187 {
			FuncDisplay("车辆备用零部件编号");
			FuncDisplay(string.pack(table.slice(data,3)));

		}
		case 0xF18A {
			FuncDisplay("系统供应商公司名称代码");
			FuncDisplay(string.pack(table.slice(data,3)));

		}
		case 0xF197 {
			FuncDisplay("ECU  系统名称");
			FuncDisplay(string.pack(table.slice(data,3)));

		}
		case 0x1701 {
			var 水平 = (data[3]<<8) + (data[4]);
			var 靠背 = (data[5]<<8) + (data[6]);
			FuncDisplay("水平当前位置: " ++ (水平-0x8000) );
			FuncDisplay("靠背当前位置" ++ (靠背 - 0x8000) );
		}
		case 0x1702 {
			if(#data < 10){
				FuncDisplay("DID-0x1702长度错误")
				return; 
			}
			var 水平1 = (data[3]<<8) + (data[4]);
			var 水平2 = (data[5]<<8) + (data[6]);
			var 靠背1 = (data[7]<<8) + (data[8]);
			var 靠背2 = (data[9]<<8) + (data[10]);
			FuncDisplay("水平1: " + (水平1-0x8000) + "水平2: " + (水平2-0x8000));
			FuncDisplay("靠背1: " + (靠背1-0x8000) + "靠背2: " + (靠背2-0x8000));
			FuncDisplay("水平1: " + (水平1) + "水平2: " + (水平2));
			FuncDisplay("靠背1: " + (靠背1) + "靠背2: " + (靠背2));
		}
		case 0x1706 {
			var 水平 = data[3]&0x01;
			var 靠背 = (data[3]>>1)&0x01;
			FuncDisplay("座椅水平方向电机学习状态: " + 水平);
			FuncDisplay("座椅靠背方向电机学习状态" + 靠背);
		}
		case 0x1707 {
			var 电流 = (data[3]<<8) + data[4];
			FuncDisplay("电流: " + tostring(电流));

		}
		case 0x1708 {
			FuncDisplay("输入状态: ");
			var 座椅向前 = data[3]&0x01;
			var 座椅向后 = (data[3]>>1)&0x01;
			var 靠背向前 = (data[3]>>2)&0x01;
			var 靠背向后 = (data[3]>>3)&0x01;
			var 快进按键 = (data[3]>>4)&0x01;
			var 快出按键 = (data[3]>>5)&0x01;
			var 锁扣状态 = (data[3]>>6)&0x01;
			var 坐人状态 = (data[3]>>7)&0x01;
			FuncDisplay("座椅向前: " + 座椅向前);
			FuncDisplay("座椅向后: " + 座椅向后);
			FuncDisplay("靠背向前: " + 靠背向前);
			FuncDisplay("靠背向后: " + 靠背向后);
			FuncDisplay("快进按键: " + 快进按键);
			FuncDisplay("快出按键: " + 快出按键);
			FuncDisplay("锁扣状态: " + 锁扣状态);
			FuncDisplay("坐人状态: " + 坐人状态);
		}
		case 0x1709 {
			FuncDisplay("输出状态: ");
			var 座椅向前 = data[3]&0x01;
			var 座椅向后 = (data[3]>>1)&0x01;
			var 靠背向前 = (data[3]>>2)&0x01;
			var 靠背向后 = (data[3]>>3)&0x01;
			var 快进按键 = (data[3]>>4)&0x01;
			var 快出按键 = (data[3]>>5)&0x01;

			FuncDisplay("座椅向前: " + 座椅向前);
			FuncDisplay("座椅向后: " + 座椅向后);
			FuncDisplay("靠背向前: " + 靠背向前);
			FuncDisplay("靠背向后: " + 靠背向后);
			FuncDisplay("快进输出: " + 快进按键);
			FuncDisplay("快出输出: " + 快进按键);

		}
		case 0x170B {
			var 系统供电电压 = data[3]/10;
			FuncDisplay("系统供电电压: " + tostring(系统供电电压) + " V");

		}
		else {
			FuncDisplay("未知DID - " + tostring(did,16));
		}
	}
	
}