void GPS_MeiTrack::getFullCommandLine(TCHAR *pCommandLine,TCHAR *pParameters,TCHAR *pCmdCH) { int nLen = strlen(pParameters)+5;//要加上<*检验码>\r\n 的长度 sprintf(pCommandLine,_T("@@%s%d%s*"), pCmdCH, nLen, pParameters); //计算出校验码 nLen = strlen(pCommandLine); getCheckCode(pCommandLine,nLen,pCommandLine+nLen); strcat(pCommandLine,"\r\n"); }
/**************************************************************** * Function Name : generateCmd * Description : Build require command for specific electical parameter. * Input : None * Output : None * Return : None ****************************************************************/ AMTReadCmd generateCmd(AMT_Addr addr, AMTCmdType cmdType) { u8 idx; IdentityCode idCode; AMTReadCmd cmd; cmd.ammeterCmdStruct.startCode = START_CODE; cmd.ammeterCmdStruct.addrEndCode = START_CODE; cmd.ammeterCmdStruct.endCode = END_CODE; for(idx = 0;idx < ADDR_LENGTH;idx++) { cmd.ammeterCmdStruct.addr[idx] = addr[idx]; //地址赋值。没有找到好的方法,只能先用数组。 } cmd.ammeterCmdStruct.cmdCode = READ_CMD_CODE; cmd.ammeterCmdStruct.dataSectionLength = DATA_SECTION_LENGTH_CODE; switch(cmdType) //这种方法扩展性很好,但比较冗长,有待改进 { case READ_CURRENT: idCode.code = READ_CURRENT_CODE;break; case READ_VOLTAGE: idCode.code = READ_VOLTAGE_CODE;break; case READ_POWER: idCode.code = READ_POWER_CODE;break; case READ_POWER_FACTOR: idCode.code = READ_POWER_FACTOR_CODE;break; default: break; } for(idx = 0;idx < ID_CODE_LENGTH;idx++) { cmd.ammeterCmdStruct.idCode[idx] = idCode.codeArr[idx]; } cmd.ammeterCmdStruct.checkCode = getCheckCode(cmd); amtCmd = cmd; return cmd; }
long GPS_MeiTrack::getGpsInfo( char *buf,int nbufLen,GPSINFO &gpsInfo ) { int nRet = 1; const char *pBuf = buf; int nBufferDataLen = strlen(buf); do{ //$$A126,863070010099660,AAA,029,22.513211,114.058928,121022092220,V,0,00,0,0,0,0,11872388,363251,000|0|0000|0000,0000,|||09C3|0000,,*FE //$$D175,863070010099660,AAA,144,22.513211,114.058928,121022092543,V,0,25,0,0,0,0,11872388,363251,460|0|2792|0E89,0000,|||0A1F|037E,,,50,10454,39,79,,73,1878.9,113,119,3,46,0,46,*F5 //$$S175,863070010099660,AAA,144,22.513211,114.058928,121022155026,V,0,26,0,0,0,0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n //$$ pBuf+=2; const char *pstrMark = pBuf; //S //<数据包标识符>//1 个字节。类型为 ASCII 码,值从 0x41 至 0x7A if(*pstrMark<0x41 || *pstrMark > 0x7A) { //这个数据有问题 nRet = -1; break; } strncpy(gpsInfo.CMDID,pstrMark,1); pBuf++; //<数据长度>,//数据长度是从分隔符“,”开始,到“\r\n”结束符的长度。 类型为十进制。 int nDataLen = 0; int nLen = 0; char strTemp[512]; //175,863070010099660,AAA,144,22.513211,114.058928,121022155026,V,0,26,0,0,0,0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n pBuf = getStr_betweenComma(pBuf,strTemp); //pBuf->863070010099660,AAA,144,22.513211,114.058928,121022155026,V,0,26,0,0,0,0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n nDataLen = atoi(strTemp)-1; nBufferDataLen = nDataLen+6; const char * pCheckCode =NULL; { //判断数据长度 是否正确 //判断最后是否是 \r\n const char *pLast = pBuf+nDataLen; if( (*(pLast-2) !=0x0d) || (*(pLast-1) !=0x0a)) { //数据无效 nRet = -3; break; } //校验数据有效性 memcpy(strTemp,(pLast-4),2); strTemp[2]='\0'; int nCheckCode = getCheckCode(buf,nDataLen+3,strTemp+3);//3=7-4 if(strcmp(strTemp,strTemp+3)!=0) { nRet = -4; break; } pCheckCode = pLast-5; } //<IMEI>863070010099660 pBuf = getStr_betweenComma(pBuf,gpsInfo.COMMADDR); //pBuf->AAA,144,22.513211,114.058928,121022155026,V,0,26,0,0,0,0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n //<指令类型>AAA, //char commandType[5]; strncpy(gpsInfo.CMDID,pstrMark,1); char *pCommandType = gpsInfo.CMDID+1; pBuf = getStr_betweenComma(pBuf,pCommandType); //pBuf->144,22.513211,114.058928,121022155026,V,0,26,0,0,0,0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n gpsInfo.nMsgID = MSG_LOGIN;//AAA时 是正常报文数据 if(strncmp(pCommandType,"AAA",3)!=0) { //自动事件报告 //gpsInfo.nMsgID=; gpsInfo.nMsgID = MSG_TERMINALFEEDBACK; } //<事件代码>,144, char eventCode[5]; memset(eventCode,0,5); pBuf = getStr_betweenComma(pBuf,eventCode); { //如果是MSG_TERMINALFEEDBACK 那么这里只需要判断是否是 OK即可。 if(gpsInfo.nMsgID == MSG_TERMINALFEEDBACK) { gpsInfo.nWarnFlag=0;//失败 if(strncmp(eventCode,"OK",2)==0) { gpsInfo.nWarnFlag = 1;//成功 } break;//不再继续下面的代码 } } //pBuf->22.513211,114.058928,121022155026,V,0,26,0,0,0,0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n //报警代码 int nEventCode = atoi(eventCode); //19 WAR_OVERSPEED //20 WAR_INZONE //21 WAR_OUTZONE gpsInfo.nWarnFlag=0; switch(nEventCode) { case 19: gpsInfo.nWarnFlag |=WAR_OVERSPEED; break; case 20: gpsInfo.nWarnFlag |=WAR_INZONE; break; case 21: gpsInfo.nWarnFlag |=WAR_OUTZONE; break; } //<(-)纬度>,22.513211, pBuf = getStr_betweenComma(pBuf,gpsInfo.Latitude); //pBuf->114.058928,121022155026,V,0,26,0,0,0,0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n //<(-)经度>114.058928, pBuf = getStr_betweenComma(pBuf,gpsInfo.Longitude); //pBuf->121022155026,V,0,26,0,0,0,0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n //,<日期和时间>,121022155026, strcpy(gpsInfo.Time,"20"); pBuf = getStr_betweenComma(pBuf,gpsInfo.Time+2); //pBuf->V,0,26,0,0,0,0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n //<定位状态>,V, pBuf = getStr_betweenComma(pBuf,strTemp); //pBuf->0,26,0,0,0,0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n gpsInfo.bValid = !strncmp(strTemp,"A",1); //<卫星个数>,0, pBuf = getStr_betweenComma(pBuf,strTemp); //pBuf->26,0,0,0,0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } //<GSM 信号强度>,26, pBuf = getStr_betweenComma(pBuf,strTemp); //pBuf->0,0,0,0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } //<速度>,0, pBuf = getStr_betweenComma(pBuf,gpsInfo.Speed); //pBuf->0,0,0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } //<方向>,0, pBuf = getStr_betweenComma(pBuf,gpsInfo.Heading); //pBuf->0,0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } //obd信息 gpsInfo.nHaveOBDInfo = 0; stOBDInfo *pOBDInfo = &(gpsInfo.st_OBD_Info); //<水平定位精度>,0, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Horizontal_positioning_accuracy); //pBuf->0,12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } //<海拔高度>,0, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Altitude); //pBuf->12445866,386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } //<里程数>,12445866, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Mileage); //pBuf->386301,460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } //<运行时间>,386301, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Runing_Time); //pBuf->460|0|2792|0E89,0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } //<基站信息>,460|0|2792|0E89, pBuf = getStr_betweenComma(pBuf,pOBDInfo->AGPS_Info); //pBuf->0000,|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } //<输入输出口状态>,0000, pBuf = getStr_betweenComma(pBuf,pOBDInfo->status_InOutTake); //pBuf->|||0A2A|0381,,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } //<模拟量输入口值>,|||0A2A|0381, pBuf = getStr_betweenComma(pBuf,pOBDInfo->outputValue); //pBuf->,,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } //<RFID 号>/<图片名>/<围栏序号>, , pBuf = getStr_betweenComma(pBuf,pOBDInfo->RFID); //pBuf->,50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } //<定制数据>, , pBuf = getStr_betweenComma(pBuf,pOBDInfo->Customize_Data); //pBuf->50,10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } //<协议版本 V>,50, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Protocol_Version); //pBuf->10218,39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } //<发动 机转速>,10218, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Engine_speed); //pBuf->39,79,,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } gpsInfo.nHaveOBDInfo++; //<发动机计算负荷>,39,79, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Engine_load); //pBuf->,73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } gpsInfo.nHaveOBDInfo++; //<发动机冷却液温度>, , pBuf = getStr_betweenComma(pBuf,pOBDInfo->Engine_coolant_temperature); //pBuf->73,1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } gpsInfo.nHaveOBDInfo++; //<百公里油耗>,73, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Hundred_kilometers); //pBuf->1878.9,113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } gpsInfo.nHaveOBDInfo++; //<进气温度>,1878.9, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Intake_air_temperature); //pBuf->113,119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } gpsInfo.nHaveOBDInfo++; //<油压>,113, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Hydraulic); //pBuf->119,1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } gpsInfo.nHaveOBDInfo++; //<大气压力>,119, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Atmospheric_pressure); //pBuf->1,46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } gpsInfo.nHaveOBDInfo++; //<进气管绝对压力>,1, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Intake_pressure); //pBuf->46,0,46,*E5\r\n if(pBuf==pCheckCode) { break; } gpsInfo.nHaveOBDInfo++; //<空气流量>,46, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Air_flow); //pBuf->0,46,*E5\r\n if(pBuf==pCheckCode) { break; } gpsInfo.nHaveOBDInfo++; //<节气门位置>,0, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Throttle_Position); //pBuf->46,*E5\r\n if(pBuf==pCheckCode) { break; } gpsInfo.nHaveOBDInfo++; //<单次行驶里程>,46, pBuf = getStr_betweenComma(pBuf,pOBDInfo->Single_mileage); //pBuf->*E5\r\n if(pBuf==pCheckCode) { break; } gpsInfo.nHaveOBDInfo++; //<百分比剩余油量>, pBuf = getStr_betweenComma(pBuf,strTemp); if(pBuf==pCheckCode) { break; } gpsInfo.nHaveOBDInfo++; //<故障码及冻结帧/就绪状态> pBuf = getStr_betweenComma(pBuf,strTemp); if(pBuf==pCheckCode) { break; } gpsInfo.nHaveOBDInfo++; }while(0); return (nRet>0)?nBufferDataLen:nRet; }
void BY8001::fillCheckCode(){ byte checkCode = getCheckCode(); sendBuffer[(int)sendBuffer[1]] = checkCode; }
void OnetAuth::networkFinished(QNetworkReply *reply) { reply->deleteLater(); if (reply->error()) { if (Settings::instance()->getBool("debug")) qWarning() << "Error OnetAuth network: " << reply->errorString(); Settings::instance()->setBool("authorizing", false); emit authStateChanged(); return; } int category = reply->property("category").toInt(); QVariant possibleRedirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if (!possibleRedirectUrl.toUrl().isEmpty()) { QNetworkReply *replyRedirect = accessManager->get(QNetworkRequest(possibleRedirectUrl.toUrl())); replyRedirect->setProperty("category", category); return; } QByteArray bData = reply->readAll(); switch (category) { case AT_chat: getDeploy(); break; case AT_deploy: gotDeploy(QString(bData)); getKropka1(); break; case AT_kropka_1: getKropka1Full(); break; case AT_kropka_1_full: getKropka5Full(); break; case AT_kropka_5_full: getSk(); break; case AT_sk: if (bRegisteredNick) getSecureLogin(); else { showCaptchaDialog(); getCheckCode(); } break; case AT_secure_login: if (bOverride) getOverride(); else getUo(); break; case AT_override: getUo(); break; case AT_check_code: getUo(); break; case AT_uo: { if (!Settings::instance()->getBool("logged")) { requestFinished(bData); saveCookies(); } Settings::instance()->setBool("authorizing", false); emit authStateChanged(); break; } case AT_refresh_sk: saveCookies(); break; default: if (Settings::instance()->getBool("debug")) qWarning() << "Error OnetAuth undefined category"; Settings::instance()->setBool("authorizing", false); emit authStateChanged(); break; } }