Eric Jung / GMMP_mbed_Ethernet_Reinit

Dependents:   ThingPlug_Ethernet_Example

Fork of GMMP_mbed by Eric Jung

Embed: (wiki syntax)

« Back to documentation index

M2M GW/Device Heartbeat

M2M GW/Device Heartbeat

TCP Always On 단말인 경우 해당 세션을 감시하기 위해 주기적으로 Heartbeat 메시지를 전송한다. More...

Functions

int GO_HB (const char *pszGWID)

Detailed Description

TCP Always On 단말인 경우 해당 세션을 감시하기 위해 주기적으로 Heartbeat 메시지를 전송한다.


M2M 단말은 Profile 정보의 Heartbeat Period 값을 주기로 전송하며, 0인 경우에는 세션을 유지하지 않는다.

전송 패킷 : Struct_Heartbeat.h 참조


Function Documentation

int GO_HB ( const char *  pszGWID )
Parameters:
pszGWIDGW ID
Returns:
성공 : GMMMP_SUCCESS, 실패 : ErrorCode.h 참조
 GW/Device Heartbeat 보고 샘플 코드 (Sample_Control_TCP_AlwaysOn 샘플 참조)

int Recv(GMMPHeader* pstGMMPHeader, void* pBody)
{
    U8 cMessageType = pstGMMPHeader->ucMessageType;

    if(cMessageType  == OPERATION_PROFILE_RSP)
    {
        //생략
    }
    else if(pstGMMPHeader->ucMessageType == OPERATION_HEARTBEAT_RSP)
    {
        stHeartBeatMsgReqHdr* pstRspHdr =(stHeartBeatMsgReqHdr*) pBody;


        return 0;
    }

    return 0;
}

void* TimerThread()
{
    int nCount = 0;
    while(bTimer == true)
    {
        if(strlen(pszGWAuthID) > 0 && strlen(pszAuthKey) > 0  )
        {
            SetTID (GetTID ()+1);

            int nRet = GMMP_SetHB (pszGWAuthID, pszAuthKey, pszDomainCode, pszGWID);
            if(nRet != GMMP_SUCCESS)
            {
                if(nCount > 2)
                {
                    break;
                }
                nCount++;
            }
        }

        sleep(nTimerSec);
    }

    return NULL;
}

void* TCPReadThread(void *data)
{
    //생략
}


int Init()
{
    //생략
}

int GW_Profile()
{
    //생략
}

int main()
{
    if(Init() != 0)
    {
        printf("Init Error");
        return -1;
    }

    pthread_t thread_id = 0;
    pthread_t timer_id = 0;

    pthread_create(&thread_id, NULL, TCPReadThread, NULL);
    pthread_create(&timer_id, NULL, TimerThread, NULL);

    pthread_join(thread_id, NULL);
    pthread_join(timer_id, NULL);
    return 0;

}

Definition at line 362 of file GMMP.cpp.