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 주기 보고

M2M GW/Device 주기 보고

M2M 단말에서 수집된 데이터를 OMP로 전송하는 절차이다. More...

Functions

int GO_Delivery (const char *pszGWID, const char *pszDeviceID, const char cReportType, const char cMediaType, const char *pszMessageBody)

Detailed Description

M2M 단말에서 수집된 데이터를 OMP로 전송하는 절차이다.


수집된 데이터를 전송하는 M2M 단말은 반드시 등록 절차를 통해 OMP에 등록되어 있어야 한다.
수집된 데이터는 타입에 따라서 수집 데이터(collect data), 장애 데이터(alarm data), 이벤트 데이터(event data), 장애 해제(alarm clear) 데이터 등으로 분류 된다.
이 값에 대한 설정은 cReportType 변수의 Report Type에 따라 구분된다. Define_Delivery.h 참조

전송 패킷 : Struct_Delivery.h 참조


Function Documentation

int GO_Delivery ( const char *  pszGWID,
const char *  pszDeviceID,
const char  cReportType,
const char  cMediaType,
const char *  pszMessageBody 
)
Parameters:
pszGWIDOMP로 제공 받은 GW ID값.
pszDeviceIDOMP로 제공 받은 Device ID값.
cReportTypeReport Type
Define_Delivery.h 참조

  • 0x01 : collect data
  • 0x02 : alarm data
  • 0x03 : event data
  • 0x04 : alarm clear
cMediaTypeMessage Body의 미디어 타입을 의미 Struct_Delivery.h 참조
pszMessageBodyData[2048 Byte]
nTotalCountMessage Body에 전달될 내용이 2048 Bytes를 초과할 경우 여러 개의 메시지로 전송하며 전체 메시지 개수를 표시 한다
nCurrentCount여러 개의 메시지로 전송되는 경우 현재 메시지의 순서로서 1에서 Total Count까지의 값이 기록 된다.
Returns:
성공 : GMMMP_SUCCESS, 실패 : ErrorCode.h 참조
 GW/Device 주기 보고 샘플 코드 (Sample_Delivery 샘플 참조)
int GW_Delivery()
{
    int nRet = 0;
    int nTotalCount = 0;
    int nLoop = 0;
    int nMessageBodyLen = strlen(pszMessage);

    if(nMessageBodyLen < MAX_MSG_BODY)
    {
        nTotalCount = 1;
    }
    else
    {
        nTotalCount = nMessageBodyLen/MAX_MSG_BODY;

        if(nMessageBodyLen%MAX_MSG_BODY > 0)
        {
            nTotalCount++;
        }
    }

    int nMessagePos = 0;
    int nSendLen = 0;
    int nSendedLen = nMessageBodyLen;

    char szMessage[MAX_MSG_BODY];

    for(nLoop = 1 ; nLoop <= nTotalCount ; nLoop++)
    {
        memset(szMessage, 0, sizeof(szMessage) );

        if(nSendedLen >= MAX_MSG_BODY)
        {
            nSendLen = MAX_MSG_BODY;
        }
        else
        {
            nSendLen = nSendedLen;
        }

        memcpy(szMessage, pszMessage+nMessagePos, nSendLen);

        printf("Send Message Len = %d\n", strlen(szMessage) );

        nRet = GO_Delivery (pszGWID, NULL, DELIVERY_COLLECT_DATA,  0x01, szMessage);

        if(nRet < 0)
        {
            printf("GO_Delivery Error : %d\n", nRet);

            return 1;
        }

        nSendedLen -= nSendLen;
        nMessagePos+= nSendedLen;
    }

    return 0;
}

int Device_Delivery()
{
    int nRet = 0;
    int nTotalCount = 0;
    int nLoop = 0;
    int nMessageBodyLen = strlen(pszMessage);

    if(nMessageBodyLen < MAX_MSG_BODY)
    {
        nTotalCount = 1;
    }
    else
    {
        nTotalCount = nMessageBodyLen/MAX_MSG_BODY;

        if(nMessageBodyLen%MAX_MSG_BODY > 0)
        {
            nTotalCount++;
        }
    }

    int nMessagePos = 0;
    int nSendLen = 0;
    int nSendedLen = nMessageBodyLen;

    char szMessage[MAX_MSG_BODY];

    for(nLoop = 1 ; nLoop <= nTotalCount ; nLoop++)
    {
        memset(szMessage, 0, sizeof(szMessage) );

        if(nSendedLen >= MAX_MSG_BODY)
        {
            nSendLen = MAX_MSG_BODY;
        }
        else
        {
            nSendLen = nSendedLen;
        }

        memcpy(szMessage, pszMessage+nMessagePos, nSendLen);

        printf("Send Message Len = %d\n", strlen(szMessage) );

        nRet = GO_Delivery (pszGWID, pszDeviceID, DELIVERY_COLLECT_DATA,  0x01, szMessage);

        if(nRet < 0)
        {
            printf("GO_Delivery Error : %d\n", nRet);

            return 1;
        }

        nSendedLen -= nSendLen;
        nMessagePos+= nSendedLen;
    }

    return 0;
}

int Init()
{
    if(Initialize(szServerIP, nServerPort, pszDomainCode , pszGWAuthID, GMMP_ON_LOG, nErrorLevel, GMMP_NETWORK_ALYWAYS_OFF, "Log") != 0)
    {
        printf("Server Connect Error\n");

        return 1;
    }

    SetCallFunction( (void*)Recv);
    SetAuthKey(pszAuthKey);
    SetGWID(pszGWID);


    return 0;
}

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

    if(GW_Delivery() != 0)
    {
        printf("GW_Delivery Error");
        return -1;
    }

    if(Device_Delivery() != 0)
    {
        printf("Device_Delivery Error");
        return -1;
    }

    return 0;

}

Definition at line 326 of file GMMP.cpp.