?? protocol.c.bak
字號:
//設置當前工作狀態
SysState.CarWorkState = Data[0];
switch (SysState.CarWorkState)
{
case WS_PT_CLASS_1_LOCK:
SysState.fClass1Loack.RemainTime = WorkPara.sClass1LockDelay_m;
SysState.fClass1Loack.flag = 0;
SysState.fClass1Loack.TimeEnabled = 1;
break;
case WS_PT_CLASS_2_LOCK:
SysState.fClass2Loack.flag = 1;
break;
}
//返回車輛狀態消息
SysState.fSendWorkState = 1;
}
//**************************************************************************
//函數:tmLoginMsg
//功能: 生成終端注冊消息
//輸出:Msg=消息,Msgtype=消息類型
//返回:0=消息無效,>0=消息長度
//**************************************************************************
int tmLoginMsg( unsigned char *Msg)
{
unsigned char *pMsg = Msg;
sprintf(pMsg , BasicPara.TM_Time);//生產日期
pMsg +=TM_TIMELENGTH;
sprintf(pMsg , BasicPara.TM_type);//型號
pMsg +=TM_TYPELENGTH;
sprintf(pMsg , BasicPara.TM_id);//編號
pMsg +=TM_IDLENGTH;
return (abs(Msg - pMsg));
}
//**************************************************************************
//函數:tmCarStateMsg
//功能: 生成車輛狀態消息
//輸出:Msg=消息
//返回:0=消息無效,>0=消息長度
//**************************************************************************
int tmCarStateMsg( unsigned char *Msg)
{
int len;
unsigned char *pMsg = Msg;
*pMsg++ = CS_PT_SENSOR;
for(len=0; len < SENSORSNUM; len++)
{
*pMsg++ = SysState.SensorsValue[len] / 256;
*pMsg++ = SysState.SensorsValue[len] % 256;
}
*pMsg++ = CS_PT_CARSTATE;
*pMsg++ = SysState.SwitchState[0];
*pMsg++ = SysState.SwitchState[1];
*pMsg++ = CS_PT_GPS;
sprintf((char*)pMsg, SysState.gpsInfo);//gps信息
pMsg +=strlen(SysState.gpsInfo);
return (abs(Msg - pMsg));
}
//**************************************************************************
//函數:tmCarStateMsg
//功能: 生成工作參數查詢/設置響應消息
//輸出:Msg=消息,Msgtype=消息類型
//返回:0=消息無效,>0=消息長度
//**************************************************************************
int tmGetWorkParaMsg( unsigned char *Msg)
{
int kk;
unsigned char *pMsg = Msg;
*pMsg++ = WP_PT_COMTYPE;
*pMsg++ = BasicPara.ComuMode;//通信模式
//中心gsm號碼
*pMsg++ = WP_PT_CENTNUM;
sprintf( pMsg, BasicPara.CenterGsmNum );
pMsg += CENTERNUMLEN;
//中心IP和port
*pMsg++ = WP_PT_CENTIP;
*pMsg++ = BasicPara.CenterIP[0][0];
*pMsg++ = BasicPara.CenterIP[0][1];
*pMsg++ = BasicPara.CenterIP[0][2];
*pMsg++ = BasicPara.CenterIP[0][3];
*pMsg++ = BasicPara.CenterPort[0]/ 256;
*pMsg++ = BasicPara.CenterPort[0]% 256;
//終端注冊消息發送間隔時間
*pMsg++ = WP_PT_MSGPERIOD;
*pMsg++ = WorkPara.sLoginMsgPeriod / 256;
*pMsg++ = WorkPara.sLoginMsgPeriod % 256;
//終端報警消息發送間隔時間
*pMsg++ = WP_PT_WARNPERIOD;
*pMsg++ = WorkPara.sWarnMsgPeriod / 256;
*pMsg++ = WorkPara.sWarnMsgPeriod % 256;
//16路傳感器報警門限
*pMsg++ = WP_PT_SENSORSBOUND;
for(kk=0; kk < SENSORSNUM; kk++)
{
*pMsg++ = WorkPara.SensorsBound[kk] / 256;
*pMsg++ = WorkPara.SensorsBound[kk] % 256;
}
//傳感器報警使能
*pMsg++ = WP_PT_SENSORWARNEN;
*pMsg++ = WorkPara.SensorsWarnEnabled[0];
*pMsg++ = WorkPara.SensorsWarnEnabled[1];
//開關量正常狀態
*pMsg++ = WP_PT_WAITCHSTATE;
*pMsg++ = WorkPara.SwitchNomalState[0];
*pMsg++ = WorkPara.SwitchNomalState[1];
//開關量報警使能
*pMsg++ = WP_PT_WAITCHWARNEN;
*pMsg++ = WorkPara.SwitchWarnEnable[0];
*pMsg++ = WorkPara.SwitchWarnEnable[1];
//活動范圍
//......
return (abs(Msg - pMsg));
}
//**************************************************************************
//函數:tmCarStateMsg
//功能: 生成工作狀態查詢/設置響應消息
//輸出:Msg=消息,Msgtype=消息類型
//返回:0=消息無效,>0=消息長度
//**************************************************************************
int tmGetWorkStateMsg( unsigned char *Msg)
{
*Msg = SysState.CarWorkState;
return 1;
}
//**************************************************************************
//函數:tmCreateMsg
//功能: 生成消息/指示
//輸入:主功能碼和子功能碼
//輸出:消息
//返回:0=消息無效,>0=消息長度
//**************************************************************************
void tmCreateMsg( TFrame *Frame)
{
unsigned char *pMsg = Frame->msg;
uint16_t ck;
//添加幀頭
myCopy( F_HEAD_STR, pMsg, 0, F_HEAD_LENGTH);
pMsg += F_HEAD_LENGTH;
Frame->msglen = F_HEAD_LENGTH;
//添加ID
myCopy( BasicPara.TM_Time, pMsg, 0, TM_TIMELENGTH);
pMsg += TM_TIMELENGTH;
Frame->msglen += TM_TIMELENGTH;
myCopy( BasicPara.TM_type, pMsg, 0, TM_TYPELENGTH);
pMsg += TM_TYPELENGTH;
Frame->msglen += TM_TYPELENGTH;
myCopy( BasicPara.TM_id, pMsg, 0, TM_IDLENGTH);
pMsg += TM_IDLENGTH;
Frame->msglen += TM_IDLENGTH;
//添加分段
*pMsg++ = '0';
Frame->msglen++;
//添加幀長
*pMsg++ = '0';
Frame->msglen++;
//添加幀主類型
*pMsg++ = Frame->type;
Frame->msglen++;
//添加幀子類型
*pMsg++ = Frame->code;
Frame->msglen++;
//添加數據段
switch (Frame->type)
{
case F_TYPE_RESPOND:
switch(Frame->code)
{
//注冊消息
case F_CODE_LOGIN:
Frame->msglen +=tmLoginMsg(pMsg);
break;
//車輛狀態消息
case F_CODE_CARSTATE:
Frame->msglen +=tmCarStateMsg(pMsg);
break;
//工作參數查詢響應消息
case F_CODE_GETWORKPARA:
Frame->msglen +=tmGetWorkParaMsg(pMsg);
break;
//工作參數設定響應消息
case F_CODE_SETWORKPARA:
Frame->msglen +=tmGetWorkParaMsg(pMsg);
break;
//工作狀態查詢響應消息
case F_CODE_GETWORKSTATE:
Frame->msglen +=tmGetWorkStateMsg(pMsg);
break;
//工作狀態設定響應消息
case F_CODE_SETWORKSTATE:
Frame->msglen +=tmGetWorkStateMsg(pMsg);
break;
}
break;
case F_TYPE_NOTE:break;
}
//計算校驗和
ck = cksum(Frame->msg, Frame->msglen);
Frame->msg[Frame->msglen++] = ck / 256;
Frame->msg[Frame->msglen++] = ck % 256;
Frame->msg[Frame->msglen] = Frame->msglen;
}
//**************************************************************************
//從source的beginindex開始拷貝degits字節到dest
//輸入:source=源字符串;beginindex=起始位置(從0開始算)
// dest=目標字符串; degits=請求字節數
//返回:實際拷貝的字節數
//dest以'\0'結束
//**************************************************************************
int myCopy(char *source , char *dest , int beginindex ,int degits)
{
int n ;
int len ;
len = strlen(source) ;
if (degits>=(len-beginindex))
{
for(n=beginindex;n<len;n++)
*(dest++)=source[n];
*dest='\0';
return (len-beginindex) ;
}else
{
for(n=beginindex;n<(degits+beginindex);n++)
*(dest++)=source[n];
*dest='\0';
return degits ;
}
}
//***************************************************************************
//尋找字符c在PStr中第Num次出現的位置
//返回: =-1 不存在
// >-1 c在PStr中第Num次出現的位置
//**************************************************************************
int FindeCharInStr ( char* PStr , int nSrcLength ,int cNum , char c )
{
int i ,FindeCharInStr = -1 ;
for(i = 0 ; i<nSrcLength;i++ , PStr++)
{
if (*PStr==c)
{
cNum-- ;
if (cNum < 1 )
{
FindeCharInStr = i ;
break ;
}
}
}
return FindeCharInStr ;
}
//void main(void)
//{
//////////////////////////////////////////////////////////////////////////////
//
// ParaInit();
//
// centSimunator("ctGetCarState");
// tmEventProcess();
// centSimunator("ctSetWorkPara");
// tmEventProcess();
// centSimunator("ctSetWorkState");
// tmEventProcess();
// centSimunator("ctNoteTmlogin");
// tmEventProcess();
// centSimunator("ctGetWorkState");
// tmEventProcess();
// centSimunator("ctGetWorkPara");
//
// tmEventProcess();
//}
int ctSetWorkPara(unsigned char *msg)
{
unsigned char *pcmd=msg;
int jj;
//設置工作參數
*pcmd++ = '#';
*pcmd++ = 'Z';
*pcmd++ = 'F';
*pcmd++ = '>';
*pcmd++ = '0';
*pcmd++ = '7';
*pcmd++ = '0';
*pcmd++ = '6';
*pcmd++ = '1';
*pcmd++ = '4';
*pcmd++ = '0';
*pcmd++ = '0';
*pcmd++ = '0';
*pcmd++ = '1';
*pcmd++ = '0';
*pcmd++ = '0';
*pcmd++ = '0';
*pcmd++ = '1';
*pcmd++ = '0';
*pcmd++ = '1';
//分段
*pcmd++ = '0';
//幀長
*pcmd++ = 'F';
//type
*pcmd++ = F_TYPE_COMMD;
//code
*pcmd++ = F_CODE_SETWORKPARA;
*pcmd++ = WP_PT_COMTYPE;
*pcmd++ = 1;//通信模式
*pcmd++ = WP_PT_CENTNUM;
myCopy( BasicPara.CenterGsmNum, pcmd ,0 ,CENTERNUMLEN);
pcmd += CENTERNUMLEN;
*pcmd++ = WP_PT_CENTIP;
//中心IP和端口
*pcmd++ = 192;
*pcmd++ = 168;
*pcmd++ = 2;
*pcmd++ = 3;
*pcmd++ = 3689/256;
*pcmd++ = 3689%256;
//終端消息發送間隔時間
*pcmd++ = WP_PT_MSGPERIOD;
*pcmd++ = 1;
*pcmd++ = 1;
//終端報警消息發送間隔時間
*pcmd++ = WP_PT_WARNPERIOD;
*pcmd++ = 1;
*pcmd++ = 2;
//16路傳感器報警門限
*pcmd++ = WP_PT_SENSORSBOUND;
for(jj=0; jj < 16; jj++)
{
*pcmd++ = 1;
*pcmd++ = jj;
}
//傳感器報警使能
*pcmd++ = WP_PT_SENSORWARNEN;
*pcmd++ = 1;
*pcmd++ = 2;
//開關量正常狀態值
*pcmd++ = WP_PT_WAITCHSTATE;
*pcmd++ = 0xff;
*pcmd++ = 0;
//開關量報警使能
*pcmd++ = WP_PT_WAITCHWARNEN;
*pcmd++ = 0;
*pcmd++ = 0xff;
msg[F_LENGTH_BEGIN] = 71+26;
// centFrameDeal(cmd , cmd[F_LENGTH_BEGIN] );
return msg[F_LENGTH_BEGIN];
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -