/************************************************* * Function: PCT_HandleEvent * Description: * Author: cxy * Returns: * Parameter: * History: *************************************************/ void PCT_HandleEvent(PTC_ProtocolCon *pstruContoller) { MSG_Buffer *pstruBuffer; ZC_MessageHead *pstruMsg; //u32 u32i; if (ZC_MAGIC_FLAG == g_struZcConfigDb.struDeviceInfo.u32UnBindFlag) { g_struProtocolController.u8MainState = PCT_STATE_WAIT_UNBIND; if (PCT_TIMER_INVAILD != pstruContoller->u8SendUnbindTimer) { TIMER_StopTimer(pstruContoller->u8SendUnbindTimer); } PCT_SendUnbindMsg(); return; } pstruBuffer = (MSG_Buffer *)MSG_PopMsg(&g_struRecvQueue); if (NULL == pstruBuffer) { return; } pstruMsg = (ZC_MessageHead*)pstruBuffer->u8MsgBuffer; ZC_Printf("event %d recv len =%d\n", pstruMsg->MsgId, ZC_HTONS(pstruMsg->Payloadlen) + sizeof(ZC_MessageHead)); #if 0 for (u32i = 0; u32i < ZC_HTONS(pstruMsg->Payloadlen) + sizeof(ZC_MessageHead); u32i++) ZC_Printf("data[%d] = 0x%02x\n", u32i, pstruBuffer->u8MsgBuffer[u32i]); #endif ZC_TraceData((u8*)pstruMsg, ZC_HTONS(pstruMsg->Payloadlen) + sizeof(ZC_MessageHead)); if (ZC_RET_ERROR == PCT_CheckCrc(pstruMsg->TotalMsgCrc, (u8*)(pstruMsg + 1), ZC_HTONS(pstruMsg->Payloadlen))) { PCT_SendEmptyMsg(pstruMsg->MsgId, ZC_SEC_ALG_AES); PCT_SendErrorMsg(pstruMsg->MsgId, NULL, 0); pstruBuffer->u32Len = 0; pstruBuffer->u8Status = MSG_BUFFER_IDLE; return; } /*when do OTA, does not send empty*/ switch (pstruMsg->MsgCode) { case ZC_CODE_ZOTA_BEGIN: PCT_HandleOtaBeginMsg(pstruContoller, pstruBuffer); break; case ZC_CODE_ZOTA_FILE_BEGIN: PCT_HandleOtaFileBeginMsg(pstruContoller, pstruBuffer); break; case ZC_CODE_ZOTA_FILE_CHUNK: PCT_HandleOtaFileChunkMsg(pstruContoller, pstruBuffer); break; case ZC_CODE_ZOTA_FILE_END: PCT_HandleOtaFileEndMsg(pstruContoller, pstruBuffer); break; case ZC_CODE_ZOTA_END: PCT_HandleOtaEndMsg(pstruContoller, pstruBuffer); break; #if 0 case ZC_CODE_OTA_BEGIN: case ZC_CODE_OTA_FILE_BEGIN: case ZC_CODE_OTA_FILE_CHUNK: case ZC_CODE_OTA_FILE_END: case ZC_CODE_OTA_END: case ZC_CODE_OTA_CONFIRM: PCT_HandleMoudleMsg(pstruContoller, pstruBuffer); break; #endif case ZC_CODE_TOKEN_SET: PCT_SetTokenKey(pstruContoller, pstruBuffer); break; case ZC_CODE_RESET_NETWORK: PCT_ResetNetWork(pstruContoller, pstruBuffer); break; case ZC_CODE_UNBIND: break; default: PCT_HandleMoudleMsg(pstruContoller, pstruBuffer); break; } pstruBuffer->u32Len = 0; pstruBuffer->u8Status = MSG_BUFFER_IDLE; return; }
/************************************************* * Function: PCT_HandleEvent * Description: * Author: cxy * Returns: * Parameter: * History: *************************************************/ void PCT_HandleEvent(PTC_ProtocolCon *pstruContoller) { MSG_Buffer *pstruBuffer; ZC_MessageHead *pstruMsg; if (PCT_TIMER_INVAILD != pstruContoller->u8SendMoudleTimer) { return; } pstruBuffer = (MSG_Buffer *)MSG_PopMsg(&g_struRecvQueue); if (NULL == pstruBuffer) { return; } pstruMsg = (ZC_MessageHead*)pstruBuffer->u8MsgBuffer; ZC_Printf("event %d recv len =%d\n", pstruMsg->MsgId, ZC_HTONS(pstruMsg->Payloadlen) + sizeof(ZC_MessageHead)); ZC_TraceData((u8*)pstruMsg, ZC_HTONS(pstruMsg->Payloadlen) + sizeof(ZC_MessageHead)); if (ZC_RET_ERROR == PCT_CheckCrc(pstruMsg->TotalMsgCrc, (u8*)(pstruMsg + 1), ZC_HTONS(pstruMsg->Payloadlen))) { PCT_SendEmptyMsg(pstruMsg->MsgId, ZC_SEC_ALG_AES); PCT_SendErrorMsg(pstruMsg->MsgId, NULL, 0); pstruBuffer->u32Len = 0; pstruBuffer->u8Status = MSG_BUFFER_IDLE; return; } /*when do OTA, does not send empty*/ switch (pstruMsg->MsgCode) { case ZC_CODE_ZOTA_BEGIN: PCT_HandleOtaBeginMsg(pstruContoller, pstruBuffer); break; case ZC_CODE_ZOTA_FILE_BEGIN: PCT_HandleOtaFileBeginMsg(pstruContoller, pstruBuffer); break; case ZC_CODE_ZOTA_FILE_CHUNK: PCT_HandleOtaFileChunkMsg(pstruContoller, pstruBuffer); break; case ZC_CODE_ZOTA_FILE_END: PCT_HandleOtaFileEndMsg(pstruContoller, pstruBuffer); break; case ZC_CODE_ZOTA_END: PCT_HandleOtaEndMsg(pstruContoller, pstruBuffer); break; case ZC_CODE_OTA_BEGIN: case ZC_CODE_OTA_FILE_BEGIN: case ZC_CODE_OTA_FILE_CHUNK: case ZC_CODE_OTA_FILE_END: case ZC_CODE_OTA_END: PCT_HandleMoudleMsg(pstruContoller, pstruBuffer); break; case ZC_CODE_TOKEN_SET: PCT_SetTokenKey(pstruContoller, pstruBuffer); break; default: PCT_HandleMoudleMsg(pstruContoller, pstruBuffer); PCT_SendEmptyMsg(pstruMsg->MsgId, ZC_SEC_ALG_AES); break; } pstruBuffer->u32Len = 0; pstruBuffer->u8Status = MSG_BUFFER_IDLE; return; }