Exemplo n.º 1
0
/*************************************************
* Function: PCT_Sleep
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_Sleep()
{
    u32 u32Index;
    MSG_Init();

    g_struProtocolController.u8keyRecv = PCT_KEY_UNRECVED;
    memcpy(g_struProtocolController.u8SessionKey, g_struRegisterInfo.u8PrivateKey, ZC_HS_SESSION_KEY_LEN);
    memcpy(g_struProtocolController.IvSend, g_struRegisterInfo.u8PrivateKey, ZC_HS_SESSION_KEY_LEN);
    memcpy(g_struProtocolController.IvRecv, g_struRegisterInfo.u8PrivateKey, ZC_HS_SESSION_KEY_LEN);
    for (u32Index = 0; u32Index < ZC_TIMER_MAX_NUM; u32Index++)
    {
        if (g_struTimer[u32Index].u8Status == ZC_TIMER_STATUS_USED)
        {
            TIMER_StopTimer((u8)u32Index);
        }
    }

    TIMER_Init();
    g_struProtocolController.u8ReconnectTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8SendMoudleTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8HeartTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8CloudAckTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8MainState = PCT_STATE_INIT;
    g_struProtocolController.u8RegisterTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u32CloudNotAckNum = 0;
    PCT_SendNotifyMsg(ZC_CODE_WIFI_DISCONNECTED);
    ZC_ClientSleep();
}
Exemplo n.º 2
0
/*************************************************
* Function: PCT_HandleOtaBeginMsg
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_HandleOtaBeginMsg(PTC_ProtocolCon *pstruContoller, MSG_Buffer *pstruBuffer)
{
    ZC_MessageHead *pstruMsg;
    ZC_Printf("Ota Begin\n");
    pstruMsg = (ZC_MessageHead*)pstruBuffer->u8MsgBuffer;
    PCT_SendAckToCloud(pstruMsg->MsgId);    
    
    PCT_SendNotifyMsg(ZC_CODE_ZOTA_BEGIN);
    return;
}
Exemplo n.º 3
0
/*************************************************
* Function: PCT_WakeUp
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_WakeUp()
{
    if (PCT_STATE_INIT == g_struProtocolController.u8MainState)
    {
        g_struProtocolController.pstruMoudleFun->pfunSetTimer(PCT_TIMER_REGISTER, 
            PCT_TIMER_INTERVAL_REGISTER, &g_struProtocolController.u8RegisterTimer);
        /*Intial Bc send Num*/
        g_struProtocolController.u16SendBcNum = 0;
        PCT_SendNotifyMsg(ZC_CODE_WIFI_CONNECTED);
        ZC_ClientWakeUp();
    }
    
}
/*************************************************
* Function: PCT_ModuleOtaFileBeginMsg
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_ModuleOtaFileBeginMsg(PTC_ProtocolCon *pstruContoller, u8 *pu8Msg)
{
    ZC_OtaFileBeginReq *pstruOta;
    ZC_Printf("Ota File Begin\n");
    
    pstruOta = (ZC_OtaFileBeginReq *)(pu8Msg);
    
    pstruContoller->struOtaInfo.u32RecvOffset = 0;
    pstruContoller->struOtaInfo.u32TotalLen = ZC_HTONL(pstruOta->u32FileTotalLen);
    pstruContoller->struOtaInfo.u8Crc[0] = pstruOta->u8TotalFileCrc[0];
    pstruContoller->struOtaInfo.u8Crc[1] = pstruOta->u8TotalFileCrc[1];    
    PCT_SendNotifyMsg(ZC_CODE_ACK);
    return;
}
/*************************************************
* Function: PCT_RecvAccessMsg4
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_RecvAccessMsg4(PTC_ProtocolCon *pstruContoller)
{
    MSG_Buffer *pstruBuffer;
    ZC_MessageHead *pstruMsg;
    ZC_HandShakeMsg4 *pstruMsg4;
    pstruBuffer = (MSG_Buffer *)MSG_PopMsg(&g_struRecvQueue);
    if (NULL == pstruBuffer)
    {
        return;
    }
    
    pstruMsg = (ZC_MessageHead*)pstruBuffer->u8MsgBuffer;
    pstruMsg4 = (ZC_HandShakeMsg4 *)(pstruMsg + 1);
    
    if (ZC_CODE_HANDSHAKE_4 == pstruMsg->MsgCode)
    {
        if (ZC_RET_ERROR == PCT_CheckCrc(pstruMsg->TotalMsgCrc, (u8*)pstruMsg4, ZC_HTONS(pstruMsg->Payloadlen)))
        {
            PCT_DisConnectCloud(pstruContoller);
        }
        else
        {   
            TIMER_StopTimer(pstruContoller->u8AccessTimer);
            if (0 == memcmp(pstruMsg4->RandMsg, pstruContoller->RandMsg, ZC_HS_MSG_LEN))
            {
                pstruContoller->u8MainState = PCT_STATE_CONNECT_CLOUD;
                
                ZC_Printf("recv msg4 ok\n");
                PCT_SendNotifyMsg(ZC_CODE_CLOUD_CONNECTED);
            }
            else
            {
                PCT_DisConnectCloud(pstruContoller);
                ZC_Printf("Recv msg4 rand error \n");            
            }
        }
    }
    pstruBuffer->u32Len = 0;
    pstruBuffer->u8Status = MSG_BUFFER_IDLE;

    if (PCT_TIMER_INVAILD != pstruContoller->u8HeartTimer)
    {
        TIMER_StopTimer(pstruContoller->u8HeartTimer);
    }
    pstruContoller->pstruMoudleFun->pfunSetTimer(PCT_TIMER_SENDHEART, 
        PCT_TIMER_INTERVAL_HEART, &pstruContoller->u8HeartTimer);
}
Exemplo n.º 6
0
/*************************************************
* Function: PCT_HandleOtaFileEndMsg
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_HandleOtaEndMsg(PTC_ProtocolCon *pstruContoller, MSG_Buffer *pstruBuffer)
{
    ZC_MessageHead *pstruMsg;
    u32 u32RetVal;
    ZC_Printf("Ota End\n");

    pstruMsg = (ZC_MessageHead*)pstruBuffer->u8MsgBuffer;
    u32RetVal = pstruContoller->pstruMoudleFun->pfunUpdateFinish(pstruContoller->struOtaInfo.u32TotalLen);
    if (ZC_RET_ERROR == u32RetVal)
    {
        PCT_SendErrorMsg(pstruMsg->MsgId, NULL, 0);
    }
    else
    {
        PCT_SendAckToCloud(pstruMsg->MsgId);
        PCT_SendNotifyMsg(ZC_CODE_ZOTA_END);
    }
}
/*************************************************
* Function: PCT_Sleep
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_Sleep()
{
    u32 u32Index;
    MSG_Init();

    g_struProtocolController.u8keyRecv = PCT_KEY_UNRECVED;
    for (u32Index = 0; u32Index < ZC_TIMER_MAX_NUM; u32Index++)
    {
        if (g_struTimer[u32Index].u8Status == ZC_TIMER_STATUS_USED)
        {
            TIMER_StopTimer((u8)u32Index);
        }
    }

    TIMER_Init();
    g_struProtocolController.u8ReconnectTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8SendMoudleTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8HeartTimer = PCT_TIMER_INVAILD;
    g_struProtocolController.u8MainState = PCT_STATE_INIT;
    g_struProtocolController.u8RegisterTimer = PCT_TIMER_INVAILD;
    PCT_SendNotifyMsg(ZC_CODE_WIFI_DISCONNECTED);
    //ZC_ClientSleep();
}