var dataTool=require('./dataTool');var config=require('./JLConfig');var onfire=require('./onfire');export function receivedeviceinfo(callBack){onfire.on(config.DeviceInfo(),(res)=>{onfire.clear();var data=unpack33Protocol(res,1);var result=config.DevResult(2,data);result.data=analysisDeviceInfo(result.data);callBack.call(this,result)})}export function receiveReset(callBack){onfire.on(config.ResetFlag(),(res)=>{onfire.clear();var data=unpack33Protocol(res,1);var result=config.DevResult(1,data);callBack.call(this,result)})}export function receiveChannel(callBack){onfire.on(config.ChannelFlag(),(res)=>{onfire.clear();var data=unpack33Protocol(res,0);var result=config.DevResult(0,data);callBack.call(this,result)})}export function receiveObuAuth(callBack){onfire.on(config.Auth(),(res)=>{onfire.clear();var data=unpack33Protocol(res,1);var result=config.DevResult(3,data);callBack.call(this,result)})}function unpack33Protocol(data,type){var result_str='';for(var i=0;i127){lens1=(dataLen&0x7F)|0x80;lens2=(dataLen>>7)&0X7f;len=dataTool.tenToHex(lens1,2)+dataTool.tenToHex(lens2,2)}else{len=dataTool.tenToHex(dataLen,2)}return len}export function analysisDeviceInfo(cmd){var version_len=dataTool.hexToTen(cmd.substr(0,2));var version=dataTool.hexToString(cmd.substr(2,version_len*2));var obuSN_len=dataTool.hexToTen(cmd.substr(version_len*2+2,2));var obuSN=dataTool.hexToString(cmd.substr(version_len*2+4,obuSN_len*2));var mac_len=dataTool.hexToTen(cmd.substr(version_len*2+4+obuSN_len*2,2));var mac=cmd.substr(version_len*2+6+obuSN_len*2,mac_len*2);var actState=cmd.substr(cmd.length-2,2);return{version:version,obuSN:obuSN,mac:mac,actState:actState}}export function analysisCardFile(res){var data=res.data;var offset=0;var provider=data.substring(offset,offset+16);offset+=16;var cardType=data.substring(offset,offset+2);offset+=2;var cardVersion=data.substring(offset,offset+2);offset+=2;var cardId=data.substring(offset,offset+20);offset+=20;var signedDate=data.substring(offset,offset+8);offset+=8;var expiredDate=data.substring(offset,offset+8);offset+=8;var vehicleNumber=data.substring(offset,offset+24);offset+=24;var userType=data.substring(offset,offset+2);offset+=2;var plateColor=data.substring(offset,offset+2);offset+=2;var vehicleModel=data.substring(offset,offset+2);offset+=2;var cardInfo={"provider":provider,"cardType":cardType,"cardVersion":cardVersion,"cardId":cardId,"signedDate":signedDate,"expiredDate":expiredDate,"vehicleNumber":vehicleNumber,"userType":userType,"plateColor":plateColor,"vehicleModel":vehicleModel,};res={"code":res.code,"cardInfo":cardInfo,"err_msg":res.err_msg,"msg":res.msg};return res}export function analysisSystemFile(res){var offset=0;var data=res.data;var provider=data.substring(offset,offset+16);offset+=16;var type=data.substring(offset,offset+2);offset+=2;var version=data.substring(offset,offset+2);offset+=2;var serialNumber=data.substring(offset,offset+16);offset+=16;var signedDate=data.substring(offset,offset+8);offset+=8;var expiredDate=data.substring(offset,offset+8);offset+=8;var tamperStatus=data.substring(offset,offset+2);offset+=2;var systemInfo={"provider":provider,"type":type,"version":version,"serialNumber":serialNumber,"signedDate":signedDate,"expiredDate":expiredDate,"tamperStatus":tamperStatus};res={"code":res.code,"systemInfo":systemInfo,"err_msg":res.err_msg,"msg":res.msg};return res}