Modified for W5500 Ethernet initialize
Fork of GMMP_mbed by
Operation/GMMP_Operation.cpp@0:7e575e5f88ec, 2015-08-09 (annotated)
- Committer:
- lesmin
- Date:
- Sun Aug 09 14:11:35 2015 +0000
- Revision:
- 0:7e575e5f88ec
forked from GMMP
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lesmin | 0:7e575e5f88ec | 1 | /** |
lesmin | 0:7e575e5f88ec | 2 | * @file GMMP_Operation.cpp |
lesmin | 0:7e575e5f88ec | 3 | * @date 2015/07/20 |
lesmin | 0:7e575e5f88ec | 4 | * @version 0.0.1.0 |
lesmin | 0:7e575e5f88ec | 5 | **/ |
lesmin | 0:7e575e5f88ec | 6 | |
lesmin | 0:7e575e5f88ec | 7 | /* |
lesmin | 0:7e575e5f88ec | 8 | #include <stdio.h> |
lesmin | 0:7e575e5f88ec | 9 | #include <stdlib.h> |
lesmin | 0:7e575e5f88ec | 10 | #include <string.h> |
lesmin | 0:7e575e5f88ec | 11 | #include <time.h> |
lesmin | 0:7e575e5f88ec | 12 | #include <signal.h> |
lesmin | 0:7e575e5f88ec | 13 | #include <pthread.h> |
lesmin | 0:7e575e5f88ec | 14 | #include <unistd.h> |
lesmin | 0:7e575e5f88ec | 15 | #include <stdarg.h> |
lesmin | 0:7e575e5f88ec | 16 | */ |
lesmin | 0:7e575e5f88ec | 17 | #include <time.h> |
lesmin | 0:7e575e5f88ec | 18 | |
lesmin | 0:7e575e5f88ec | 19 | #include "GMMP_Operation.h" |
lesmin | 0:7e575e5f88ec | 20 | |
lesmin | 0:7e575e5f88ec | 21 | long g_nTID = 0; |
lesmin | 0:7e575e5f88ec | 22 | int g_bLog = false; |
lesmin | 0:7e575e5f88ec | 23 | |
lesmin | 0:7e575e5f88ec | 24 | int g_nErrorLevel = GMMP_ERROR_LEVEL_ERROR; |
lesmin | 0:7e575e5f88ec | 25 | |
lesmin | 0:7e575e5f88ec | 26 | |
lesmin | 0:7e575e5f88ec | 27 | //GW/Device 등록/해지 Request |
lesmin | 0:7e575e5f88ec | 28 | int GMMP_SetReg(const char* pszAuthID, |
lesmin | 0:7e575e5f88ec | 29 | const char* pszAuthKey, |
lesmin | 0:7e575e5f88ec | 30 | const char* pszDomainCode, |
lesmin | 0:7e575e5f88ec | 31 | const char* pszGWID, |
lesmin | 0:7e575e5f88ec | 32 | const char* pszManufactureID) |
lesmin | 0:7e575e5f88ec | 33 | { |
lesmin | 0:7e575e5f88ec | 34 | debugln("GMMP_SetReg()"); |
lesmin | 0:7e575e5f88ec | 35 | |
lesmin | 0:7e575e5f88ec | 36 | int nRet = GMMP_SUCCESS; |
lesmin | 0:7e575e5f88ec | 37 | |
lesmin | 0:7e575e5f88ec | 38 | if(pszGWID == NULL) { |
lesmin | 0:7e575e5f88ec | 39 | GwRegist_Req stRegist_Req; |
lesmin | 0:7e575e5f88ec | 40 | memset(&stRegist_Req, 0 ,sizeof(stRegist_Req)); |
lesmin | 0:7e575e5f88ec | 41 | |
lesmin | 0:7e575e5f88ec | 42 | nRet = SetHeader((void*)&stRegist_Req, sizeof(stRegist_Req), 1, 1, OPERATION_GW_REG_REQ, pszAuthID, NULL); |
lesmin | 0:7e575e5f88ec | 43 | if(nRet != GMMP_SUCCESS) { |
lesmin | 0:7e575e5f88ec | 44 | return nRet; |
lesmin | 0:7e575e5f88ec | 45 | } |
lesmin | 0:7e575e5f88ec | 46 | |
lesmin | 0:7e575e5f88ec | 47 | memcpy(stRegist_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); |
lesmin | 0:7e575e5f88ec | 48 | memcpy(stRegist_Req.body.usManufactureID, pszManufactureID, strlen(pszManufactureID)); |
lesmin | 0:7e575e5f88ec | 49 | |
lesmin | 0:7e575e5f88ec | 50 | GMMP_Trace(&stRegist_Req.header, &stRegist_Req.body); |
lesmin | 0:7e575e5f88ec | 51 | |
lesmin | 0:7e575e5f88ec | 52 | nRet = GMMP_GW_Reg_Req((GwRegist_Req*)&stRegist_Req); |
lesmin | 0:7e575e5f88ec | 53 | |
lesmin | 0:7e575e5f88ec | 54 | } |
lesmin | 0:7e575e5f88ec | 55 | else |
lesmin | 0:7e575e5f88ec | 56 | { |
lesmin | 0:7e575e5f88ec | 57 | /* |
lesmin | 0:7e575e5f88ec | 58 | if(pszAuthKey == NULL || strlen(pszAuthKey) > LEN_AUTH_KEY || strlen(pszGWID) > LEN_GW_ID) |
lesmin | 0:7e575e5f88ec | 59 | { |
lesmin | 0:7e575e5f88ec | 60 | return LIB_PARAM_ERROR; |
lesmin | 0:7e575e5f88ec | 61 | } |
lesmin | 0:7e575e5f88ec | 62 | */ |
lesmin | 0:7e575e5f88ec | 63 | |
lesmin | 0:7e575e5f88ec | 64 | DeviceRegist_Req stRegist_Req; |
lesmin | 0:7e575e5f88ec | 65 | |
lesmin | 0:7e575e5f88ec | 66 | memset(&stRegist_Req, 0 ,sizeof(stRegist_Req)); |
lesmin | 0:7e575e5f88ec | 67 | |
lesmin | 0:7e575e5f88ec | 68 | nRet = SetHeader((void*)&stRegist_Req, sizeof(stRegist_Req), 1, 1, OPERATION_DEVICE_REG_REQ, pszAuthID, pszAuthKey); |
lesmin | 0:7e575e5f88ec | 69 | if(nRet != GMMP_SUCCESS) |
lesmin | 0:7e575e5f88ec | 70 | { |
lesmin | 0:7e575e5f88ec | 71 | return nRet; |
lesmin | 0:7e575e5f88ec | 72 | } |
lesmin | 0:7e575e5f88ec | 73 | |
lesmin | 0:7e575e5f88ec | 74 | memcpy(stRegist_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); |
lesmin | 0:7e575e5f88ec | 75 | memcpy(stRegist_Req.body.usGWID, pszGWID, strlen(pszGWID)); |
lesmin | 0:7e575e5f88ec | 76 | memcpy(stRegist_Req.body.usManufactureID, pszManufactureID, strlen(pszManufactureID)); |
lesmin | 0:7e575e5f88ec | 77 | |
lesmin | 0:7e575e5f88ec | 78 | GMMP_Trace(&stRegist_Req.header, &stRegist_Req.body); |
lesmin | 0:7e575e5f88ec | 79 | |
lesmin | 0:7e575e5f88ec | 80 | nRet = GMMP_Device_Reg_Req((DeviceRegist_Req*)&stRegist_Req); |
lesmin | 0:7e575e5f88ec | 81 | } |
lesmin | 0:7e575e5f88ec | 82 | |
lesmin | 0:7e575e5f88ec | 83 | return nRet; |
lesmin | 0:7e575e5f88ec | 84 | } |
lesmin | 0:7e575e5f88ec | 85 | |
lesmin | 0:7e575e5f88ec | 86 | int GMMP_SetDeReg(const char* pszAuthID, |
lesmin | 0:7e575e5f88ec | 87 | const char* pszAuthKey, |
lesmin | 0:7e575e5f88ec | 88 | const char* pszDomainCode, |
lesmin | 0:7e575e5f88ec | 89 | const char* pszGWID, |
lesmin | 0:7e575e5f88ec | 90 | const char* pszDeviceID) |
lesmin | 0:7e575e5f88ec | 91 | { |
lesmin | 0:7e575e5f88ec | 92 | /* |
lesmin | 0:7e575e5f88ec | 93 | if(pszAuthID == NULL |
lesmin | 0:7e575e5f88ec | 94 | || pszAuthKey == NULL |
lesmin | 0:7e575e5f88ec | 95 | || pszDomainCode == NULL |
lesmin | 0:7e575e5f88ec | 96 | || pszGWID == NULL |
lesmin | 0:7e575e5f88ec | 97 | || strlen(pszAuthID) > LEN_AUTH_ID |
lesmin | 0:7e575e5f88ec | 98 | || strlen(pszAuthKey) > LEN_AUTH_KEY |
lesmin | 0:7e575e5f88ec | 99 | || strlen(pszDomainCode) > LEN_DOMAIN_CODE |
lesmin | 0:7e575e5f88ec | 100 | || strlen(pszGWID) > LEN_GW_ID) |
lesmin | 0:7e575e5f88ec | 101 | { |
lesmin | 0:7e575e5f88ec | 102 | return LIB_PARAM_ERROR; |
lesmin | 0:7e575e5f88ec | 103 | } |
lesmin | 0:7e575e5f88ec | 104 | */ |
lesmin | 0:7e575e5f88ec | 105 | |
lesmin | 0:7e575e5f88ec | 106 | int nRet = GMMP_SUCCESS; |
lesmin | 0:7e575e5f88ec | 107 | |
lesmin | 0:7e575e5f88ec | 108 | if(pszDeviceID == NULL) //GW DeReg |
lesmin | 0:7e575e5f88ec | 109 | { |
lesmin | 0:7e575e5f88ec | 110 | GwDeRegist_Req stDeRegist_Req; |
lesmin | 0:7e575e5f88ec | 111 | memset(&stDeRegist_Req, 0 ,sizeof(stDeRegist_Req)); |
lesmin | 0:7e575e5f88ec | 112 | |
lesmin | 0:7e575e5f88ec | 113 | nRet = SetHeader((void*)&stDeRegist_Req, sizeof(stDeRegist_Req), 1, 1, OPERATION_GW_DEREG_REQ, pszAuthID, pszAuthKey); |
lesmin | 0:7e575e5f88ec | 114 | if(nRet != GMMP_SUCCESS) |
lesmin | 0:7e575e5f88ec | 115 | { |
lesmin | 0:7e575e5f88ec | 116 | return nRet; |
lesmin | 0:7e575e5f88ec | 117 | } |
lesmin | 0:7e575e5f88ec | 118 | |
lesmin | 0:7e575e5f88ec | 119 | memcpy(stDeRegist_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); |
lesmin | 0:7e575e5f88ec | 120 | memcpy(stDeRegist_Req.body.usGWID, pszGWID, strlen(pszGWID)); |
lesmin | 0:7e575e5f88ec | 121 | |
lesmin | 0:7e575e5f88ec | 122 | GMMP_Trace(&stDeRegist_Req.header, &stDeRegist_Req.body); |
lesmin | 0:7e575e5f88ec | 123 | |
lesmin | 0:7e575e5f88ec | 124 | nRet = GMMP_GW_DeReg_Req((GwDeRegist_Req*)&stDeRegist_Req); |
lesmin | 0:7e575e5f88ec | 125 | } |
lesmin | 0:7e575e5f88ec | 126 | else |
lesmin | 0:7e575e5f88ec | 127 | { |
lesmin | 0:7e575e5f88ec | 128 | DeviceDeRegist_Req stDeviceDeRegist_Req; |
lesmin | 0:7e575e5f88ec | 129 | |
lesmin | 0:7e575e5f88ec | 130 | memset(&stDeviceDeRegist_Req, 0 ,sizeof(stDeviceDeRegist_Req)); |
lesmin | 0:7e575e5f88ec | 131 | |
lesmin | 0:7e575e5f88ec | 132 | nRet = SetHeader((void*)&stDeviceDeRegist_Req, sizeof(stDeviceDeRegist_Req), 1, 1, OPERATION_DEVICE_DEREG_REQ, pszAuthID, pszAuthKey); |
lesmin | 0:7e575e5f88ec | 133 | if(nRet != GMMP_SUCCESS) |
lesmin | 0:7e575e5f88ec | 134 | { |
lesmin | 0:7e575e5f88ec | 135 | return nRet; |
lesmin | 0:7e575e5f88ec | 136 | } |
lesmin | 0:7e575e5f88ec | 137 | |
lesmin | 0:7e575e5f88ec | 138 | memcpy(stDeviceDeRegist_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); |
lesmin | 0:7e575e5f88ec | 139 | memcpy(stDeviceDeRegist_Req.body.usGWID, pszGWID, strlen(pszGWID)); |
lesmin | 0:7e575e5f88ec | 140 | memcpy(stDeviceDeRegist_Req.body.usDeviceID, pszDeviceID, strlen(pszDeviceID)); |
lesmin | 0:7e575e5f88ec | 141 | |
lesmin | 0:7e575e5f88ec | 142 | GMMP_Trace(&stDeviceDeRegist_Req.header, &stDeviceDeRegist_Req.body); |
lesmin | 0:7e575e5f88ec | 143 | |
lesmin | 0:7e575e5f88ec | 144 | nRet = GMMP_Device_DeReg_Req((DeviceDeRegist_Req*)&stDeviceDeRegist_Req); |
lesmin | 0:7e575e5f88ec | 145 | } |
lesmin | 0:7e575e5f88ec | 146 | |
lesmin | 0:7e575e5f88ec | 147 | return nRet; |
lesmin | 0:7e575e5f88ec | 148 | } |
lesmin | 0:7e575e5f88ec | 149 | |
lesmin | 0:7e575e5f88ec | 150 | //Profile Info Request |
lesmin | 0:7e575e5f88ec | 151 | int GMMP_SetProfile(const char* pszAuthID, const char* pszAuthKey, const char* pszDomainCode, const char* pszGWID, const char* pszDeviceID) |
lesmin | 0:7e575e5f88ec | 152 | { |
lesmin | 0:7e575e5f88ec | 153 | /* |
lesmin | 0:7e575e5f88ec | 154 | if(pszAuthID == NULL |
lesmin | 0:7e575e5f88ec | 155 | || pszAuthKey == NULL |
lesmin | 0:7e575e5f88ec | 156 | || pszDomainCode == NULL |
lesmin | 0:7e575e5f88ec | 157 | || pszGWID ==NULL |
lesmin | 0:7e575e5f88ec | 158 | || strlen(pszAuthID) > LEN_AUTH_ID |
lesmin | 0:7e575e5f88ec | 159 | || strlen(pszAuthKey) > LEN_AUTH_KEY |
lesmin | 0:7e575e5f88ec | 160 | || strlen(pszDomainCode) > LEN_DOMAIN_CODE |
lesmin | 0:7e575e5f88ec | 161 | || strlen(pszGWID) > LEN_GW_ID) |
lesmin | 0:7e575e5f88ec | 162 | { |
lesmin | 0:7e575e5f88ec | 163 | return LIB_PARAM_ERROR; |
lesmin | 0:7e575e5f88ec | 164 | } |
lesmin | 0:7e575e5f88ec | 165 | */ |
lesmin | 0:7e575e5f88ec | 166 | |
lesmin | 0:7e575e5f88ec | 167 | int nRet = GMMP_SUCCESS; |
lesmin | 0:7e575e5f88ec | 168 | |
lesmin | 0:7e575e5f88ec | 169 | Profile_Req stProfile_Req; |
lesmin | 0:7e575e5f88ec | 170 | |
lesmin | 0:7e575e5f88ec | 171 | memset(&stProfile_Req, 0 ,sizeof(stProfile_Req)); |
lesmin | 0:7e575e5f88ec | 172 | |
lesmin | 0:7e575e5f88ec | 173 | nRet = SetHeader((void*)&stProfile_Req, sizeof(stProfile_Req), 1, 1, OPERATION_PROFILE_REQ, pszAuthID, pszAuthKey); |
lesmin | 0:7e575e5f88ec | 174 | if(nRet != GMMP_SUCCESS) |
lesmin | 0:7e575e5f88ec | 175 | { |
lesmin | 0:7e575e5f88ec | 176 | return nRet; |
lesmin | 0:7e575e5f88ec | 177 | } |
lesmin | 0:7e575e5f88ec | 178 | |
lesmin | 0:7e575e5f88ec | 179 | memcpy(stProfile_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); |
lesmin | 0:7e575e5f88ec | 180 | memcpy(stProfile_Req.body.usGWID, pszGWID, strlen(pszGWID)); |
lesmin | 0:7e575e5f88ec | 181 | |
lesmin | 0:7e575e5f88ec | 182 | if(pszDeviceID != NULL) //Device 판단 |
lesmin | 0:7e575e5f88ec | 183 | { |
lesmin | 0:7e575e5f88ec | 184 | if(strlen(pszDeviceID) > LEN_DEVICE_ID) //Device ID 길이 확인 |
lesmin | 0:7e575e5f88ec | 185 | { |
lesmin | 0:7e575e5f88ec | 186 | } |
lesmin | 0:7e575e5f88ec | 187 | else |
lesmin | 0:7e575e5f88ec | 188 | { |
lesmin | 0:7e575e5f88ec | 189 | memcpy(stProfile_Req.body.usDeviceID, pszDeviceID, strlen(pszDeviceID)); |
lesmin | 0:7e575e5f88ec | 190 | } |
lesmin | 0:7e575e5f88ec | 191 | } |
lesmin | 0:7e575e5f88ec | 192 | |
lesmin | 0:7e575e5f88ec | 193 | GMMP_Trace(&stProfile_Req.header, &stProfile_Req.body); |
lesmin | 0:7e575e5f88ec | 194 | |
lesmin | 0:7e575e5f88ec | 195 | nRet = GMMP_Profile_Req(&stProfile_Req); |
lesmin | 0:7e575e5f88ec | 196 | |
lesmin | 0:7e575e5f88ec | 197 | return nRet; |
lesmin | 0:7e575e5f88ec | 198 | } |
lesmin | 0:7e575e5f88ec | 199 | |
lesmin | 0:7e575e5f88ec | 200 | //수집 데이터 보고 Request |
lesmin | 0:7e575e5f88ec | 201 | int GMMP_SetDelivery(const char* pszAuthID, |
lesmin | 0:7e575e5f88ec | 202 | const char* pszAuthKey, |
lesmin | 0:7e575e5f88ec | 203 | const char* pszDomainCode, |
lesmin | 0:7e575e5f88ec | 204 | const char* pszGWID, |
lesmin | 0:7e575e5f88ec | 205 | const char* pszDeviceID, |
lesmin | 0:7e575e5f88ec | 206 | const char cReportType, |
lesmin | 0:7e575e5f88ec | 207 | const char cMediaType, |
lesmin | 0:7e575e5f88ec | 208 | const char* pszMessageBody, |
lesmin | 0:7e575e5f88ec | 209 | const int nTotalCount, |
lesmin | 0:7e575e5f88ec | 210 | const int nCurrentCount) |
lesmin | 0:7e575e5f88ec | 211 | { |
lesmin | 0:7e575e5f88ec | 212 | /* |
lesmin | 0:7e575e5f88ec | 213 | if(pszAuthID == NULL |
lesmin | 0:7e575e5f88ec | 214 | || pszAuthKey == NULL |
lesmin | 0:7e575e5f88ec | 215 | || pszDomainCode == NULL |
lesmin | 0:7e575e5f88ec | 216 | || pszGWID == NULL |
lesmin | 0:7e575e5f88ec | 217 | || strlen(pszAuthID) > LEN_AUTH_ID |
lesmin | 0:7e575e5f88ec | 218 | || strlen(pszAuthKey) > LEN_AUTH_KEY |
lesmin | 0:7e575e5f88ec | 219 | || strlen(pszDomainCode) > LEN_DOMAIN_CODE |
lesmin | 0:7e575e5f88ec | 220 | || strlen(pszGWID) > LEN_GW_ID |
lesmin | 0:7e575e5f88ec | 221 | || cReportType < 0x00 |
lesmin | 0:7e575e5f88ec | 222 | || cReportType > 0x04 |
lesmin | 0:7e575e5f88ec | 223 | || cMediaType < 0x01 |
lesmin | 0:7e575e5f88ec | 224 | || pszMessageBody == NULL |
lesmin | 0:7e575e5f88ec | 225 | || strlen(pszMessageBody) > MAX_MSG_BODY) |
lesmin | 0:7e575e5f88ec | 226 | { |
lesmin | 0:7e575e5f88ec | 227 | return LIB_PARAM_ERROR; |
lesmin | 0:7e575e5f88ec | 228 | } |
lesmin | 0:7e575e5f88ec | 229 | */ |
lesmin | 0:7e575e5f88ec | 230 | |
lesmin | 0:7e575e5f88ec | 231 | int nMessageBodyLen = strlen(pszMessageBody); |
lesmin | 0:7e575e5f88ec | 232 | |
lesmin | 0:7e575e5f88ec | 233 | //debug("msgBodyLen = "); |
lesmin | 0:7e575e5f88ec | 234 | //debugln(nMessageBodyLen); |
lesmin | 0:7e575e5f88ec | 235 | DBG("msgBodyLen = %d", nMessageBodyLen); |
lesmin | 0:7e575e5f88ec | 236 | |
lesmin | 0:7e575e5f88ec | 237 | int nRet = GMMP_SUCCESS; |
lesmin | 0:7e575e5f88ec | 238 | |
lesmin | 0:7e575e5f88ec | 239 | Delivery_Req stDelivery_Req; |
lesmin | 0:7e575e5f88ec | 240 | |
lesmin | 0:7e575e5f88ec | 241 | //debug(F("ReqSize = ")); |
lesmin | 0:7e575e5f88ec | 242 | //debugln(sizeof(stDelivery_Req)); |
lesmin | 0:7e575e5f88ec | 243 | DBG("ReqSize = %d", sizeof(stDelivery_Req)); |
lesmin | 0:7e575e5f88ec | 244 | |
lesmin | 0:7e575e5f88ec | 245 | memset(&stDelivery_Req, 0, sizeof(stDelivery_Req)); |
lesmin | 0:7e575e5f88ec | 246 | |
lesmin | 0:7e575e5f88ec | 247 | int PacketSize = sizeof(stDelivery_Req) - MAX_MSG_BODY + nMessageBodyLen ; //Message Body의 속성은 Optinal이다 |
lesmin | 0:7e575e5f88ec | 248 | |
lesmin | 0:7e575e5f88ec | 249 | // debug(F("pacektSize = ")); |
lesmin | 0:7e575e5f88ec | 250 | // debugln(PacketSize); |
lesmin | 0:7e575e5f88ec | 251 | DBG("packetSize = %d", PacketSize); |
lesmin | 0:7e575e5f88ec | 252 | |
lesmin | 0:7e575e5f88ec | 253 | nRet = SetHeader((void*)&stDelivery_Req, PacketSize, nTotalCount, nCurrentCount, OPERATION_DELIVERY_REQ, pszAuthID, pszAuthKey); |
lesmin | 0:7e575e5f88ec | 254 | if(nRet != GMMP_SUCCESS) |
lesmin | 0:7e575e5f88ec | 255 | { |
lesmin | 0:7e575e5f88ec | 256 | return nRet; |
lesmin | 0:7e575e5f88ec | 257 | } |
lesmin | 0:7e575e5f88ec | 258 | |
lesmin | 0:7e575e5f88ec | 259 | memcpy(stDelivery_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); |
lesmin | 0:7e575e5f88ec | 260 | memcpy(stDelivery_Req.body.usGWID, pszGWID, strlen(pszGWID)); |
lesmin | 0:7e575e5f88ec | 261 | |
lesmin | 0:7e575e5f88ec | 262 | if(pszDeviceID != NULL) //Device 판단 |
lesmin | 0:7e575e5f88ec | 263 | { |
lesmin | 0:7e575e5f88ec | 264 | if(strlen(pszDeviceID) > LEN_DEVICE_ID) //Device ID 길이 확인 |
lesmin | 0:7e575e5f88ec | 265 | { |
lesmin | 0:7e575e5f88ec | 266 | } |
lesmin | 0:7e575e5f88ec | 267 | else |
lesmin | 0:7e575e5f88ec | 268 | { |
lesmin | 0:7e575e5f88ec | 269 | memcpy(stDelivery_Req.body.usDeviceID, pszDeviceID, strlen(pszDeviceID)); |
lesmin | 0:7e575e5f88ec | 270 | } |
lesmin | 0:7e575e5f88ec | 271 | } |
lesmin | 0:7e575e5f88ec | 272 | |
lesmin | 0:7e575e5f88ec | 273 | stDelivery_Req.body.ucReportType = cReportType; |
lesmin | 0:7e575e5f88ec | 274 | stDelivery_Req.body.ucMediaType = cMediaType; |
lesmin | 0:7e575e5f88ec | 275 | |
lesmin | 0:7e575e5f88ec | 276 | if(nMessageBodyLen > 0) |
lesmin | 0:7e575e5f88ec | 277 | { |
lesmin | 0:7e575e5f88ec | 278 | memcpy(stDelivery_Req.body.usMessageBody, pszMessageBody, nMessageBodyLen); |
lesmin | 0:7e575e5f88ec | 279 | } |
lesmin | 0:7e575e5f88ec | 280 | |
lesmin | 0:7e575e5f88ec | 281 | GMMP_Trace(&stDelivery_Req.header, &stDelivery_Req.body); |
lesmin | 0:7e575e5f88ec | 282 | |
lesmin | 0:7e575e5f88ec | 283 | nRet = GMMP_Delivery_Req(&stDelivery_Req, PacketSize); |
lesmin | 0:7e575e5f88ec | 284 | |
lesmin | 0:7e575e5f88ec | 285 | return nRet; |
lesmin | 0:7e575e5f88ec | 286 | } |
lesmin | 0:7e575e5f88ec | 287 | |
lesmin | 0:7e575e5f88ec | 288 | //제어 수신 기능은 Thread에서 처리 |
lesmin | 0:7e575e5f88ec | 289 | //제어 수신 보고 Response |
lesmin | 0:7e575e5f88ec | 290 | int GMMP_SetControl(const char* pszAuthID, const char* pszAuthKey, const char* pszDomainCode, const char* pszGWID, const char* pszDeviceID, const char cControlType, const char cResultCode) |
lesmin | 0:7e575e5f88ec | 291 | { |
lesmin | 0:7e575e5f88ec | 292 | /* |
lesmin | 0:7e575e5f88ec | 293 | if(pszAuthID == NULL |
lesmin | 0:7e575e5f88ec | 294 | || pszAuthKey == NULL |
lesmin | 0:7e575e5f88ec | 295 | || pszDomainCode == NULL |
lesmin | 0:7e575e5f88ec | 296 | || pszGWID ==NULL |
lesmin | 0:7e575e5f88ec | 297 | || strlen(pszAuthID) > LEN_AUTH_ID |
lesmin | 0:7e575e5f88ec | 298 | || strlen(pszAuthKey) > LEN_AUTH_KEY |
lesmin | 0:7e575e5f88ec | 299 | || strlen(pszDomainCode) > LEN_DOMAIN_CODE |
lesmin | 0:7e575e5f88ec | 300 | || strlen(pszGWID) > LEN_GW_ID) |
lesmin | 0:7e575e5f88ec | 301 | { |
lesmin | 0:7e575e5f88ec | 302 | return LIB_PARAM_ERROR; |
lesmin | 0:7e575e5f88ec | 303 | } |
lesmin | 0:7e575e5f88ec | 304 | */ |
lesmin | 0:7e575e5f88ec | 305 | |
lesmin | 0:7e575e5f88ec | 306 | int nRet = GMMP_SUCCESS; |
lesmin | 0:7e575e5f88ec | 307 | |
lesmin | 0:7e575e5f88ec | 308 | Control_Rsp stControl_Rsp; |
lesmin | 0:7e575e5f88ec | 309 | |
lesmin | 0:7e575e5f88ec | 310 | memset(&stControl_Rsp, 0 ,sizeof(stControl_Rsp)); |
lesmin | 0:7e575e5f88ec | 311 | |
lesmin | 0:7e575e5f88ec | 312 | nRet = SetHeader((void*)&stControl_Rsp, sizeof(stControl_Rsp), 1, 1, OPERATION_CONTROL_RSP, pszAuthID, pszAuthKey); |
lesmin | 0:7e575e5f88ec | 313 | if(nRet != GMMP_SUCCESS) |
lesmin | 0:7e575e5f88ec | 314 | { |
lesmin | 0:7e575e5f88ec | 315 | return nRet; |
lesmin | 0:7e575e5f88ec | 316 | } |
lesmin | 0:7e575e5f88ec | 317 | |
lesmin | 0:7e575e5f88ec | 318 | memcpy(stControl_Rsp.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); |
lesmin | 0:7e575e5f88ec | 319 | memcpy(stControl_Rsp.body.usGWID, pszGWID, strlen(pszGWID)); |
lesmin | 0:7e575e5f88ec | 320 | |
lesmin | 0:7e575e5f88ec | 321 | if(pszDeviceID != NULL) //Device 판단 |
lesmin | 0:7e575e5f88ec | 322 | { |
lesmin | 0:7e575e5f88ec | 323 | if(strlen(pszDeviceID) > LEN_DEVICE_ID) //Device ID 길이 확인 |
lesmin | 0:7e575e5f88ec | 324 | { |
lesmin | 0:7e575e5f88ec | 325 | } |
lesmin | 0:7e575e5f88ec | 326 | else |
lesmin | 0:7e575e5f88ec | 327 | { |
lesmin | 0:7e575e5f88ec | 328 | memcpy(stControl_Rsp.body.usDeviceID, pszDeviceID, strlen(pszDeviceID)); |
lesmin | 0:7e575e5f88ec | 329 | } |
lesmin | 0:7e575e5f88ec | 330 | } |
lesmin | 0:7e575e5f88ec | 331 | |
lesmin | 0:7e575e5f88ec | 332 | stControl_Rsp.body.ucControlType = cControlType; |
lesmin | 0:7e575e5f88ec | 333 | stControl_Rsp.body.ucResultCode = cResultCode; |
lesmin | 0:7e575e5f88ec | 334 | |
lesmin | 0:7e575e5f88ec | 335 | GMMP_Trace(&stControl_Rsp.header, &stControl_Rsp.body); |
lesmin | 0:7e575e5f88ec | 336 | |
lesmin | 0:7e575e5f88ec | 337 | nRet = GMMP_Control_Rsp(&stControl_Rsp); |
lesmin | 0:7e575e5f88ec | 338 | |
lesmin | 0:7e575e5f88ec | 339 | return nRet; |
lesmin | 0:7e575e5f88ec | 340 | } |
lesmin | 0:7e575e5f88ec | 341 | |
lesmin | 0:7e575e5f88ec | 342 | //제어 동작 완료 결과 보고 Request |
lesmin | 0:7e575e5f88ec | 343 | int GMMP_SetNotifi(const char* pszAuthID, |
lesmin | 0:7e575e5f88ec | 344 | const char* pszAuthKey, |
lesmin | 0:7e575e5f88ec | 345 | const char* pszDomainCode, |
lesmin | 0:7e575e5f88ec | 346 | const char* pszGWID, |
lesmin | 0:7e575e5f88ec | 347 | const char* pszDeviceID, |
lesmin | 0:7e575e5f88ec | 348 | const char cControlType, |
lesmin | 0:7e575e5f88ec | 349 | const char cResultCode, |
lesmin | 0:7e575e5f88ec | 350 | const char* pszMessageBody, |
lesmin | 0:7e575e5f88ec | 351 | const int nMessageSize) |
lesmin | 0:7e575e5f88ec | 352 | { |
lesmin | 0:7e575e5f88ec | 353 | /* |
lesmin | 0:7e575e5f88ec | 354 | if(pszAuthID == NULL |
lesmin | 0:7e575e5f88ec | 355 | || pszAuthKey == NULL |
lesmin | 0:7e575e5f88ec | 356 | || pszDomainCode == NULL |
lesmin | 0:7e575e5f88ec | 357 | || pszGWID ==NULL |
lesmin | 0:7e575e5f88ec | 358 | || strlen(pszAuthID) > LEN_AUTH_ID |
lesmin | 0:7e575e5f88ec | 359 | || strlen(pszAuthKey) > LEN_AUTH_KEY |
lesmin | 0:7e575e5f88ec | 360 | || strlen(pszDomainCode) > LEN_DOMAIN_CODE |
lesmin | 0:7e575e5f88ec | 361 | || strlen(pszGWID) > LEN_GW_ID) |
lesmin | 0:7e575e5f88ec | 362 | { |
lesmin | 0:7e575e5f88ec | 363 | return LIB_PARAM_ERROR; |
lesmin | 0:7e575e5f88ec | 364 | } |
lesmin | 0:7e575e5f88ec | 365 | */ |
lesmin | 0:7e575e5f88ec | 366 | |
lesmin | 0:7e575e5f88ec | 367 | int nRet = GMMP_SUCCESS; |
lesmin | 0:7e575e5f88ec | 368 | |
lesmin | 0:7e575e5f88ec | 369 | Notifi_Req stNotifi_Req; |
lesmin | 0:7e575e5f88ec | 370 | |
lesmin | 0:7e575e5f88ec | 371 | memset(&stNotifi_Req, 0 ,sizeof(stNotifi_Req)); |
lesmin | 0:7e575e5f88ec | 372 | |
lesmin | 0:7e575e5f88ec | 373 | int PacketSize =sizeof(stNotifi_Req) - MAX_MSG_BODY + nMessageSize ; //Message Body의 속성은 Optinal이다 |
lesmin | 0:7e575e5f88ec | 374 | |
lesmin | 0:7e575e5f88ec | 375 | nRet = SetHeader((void*)&stNotifi_Req, PacketSize, 1, 1, OPERATION_NOTIFICATION_REQ, pszAuthID, pszAuthKey); |
lesmin | 0:7e575e5f88ec | 376 | if(nRet != GMMP_SUCCESS) |
lesmin | 0:7e575e5f88ec | 377 | { |
lesmin | 0:7e575e5f88ec | 378 | return nRet; |
lesmin | 0:7e575e5f88ec | 379 | } |
lesmin | 0:7e575e5f88ec | 380 | |
lesmin | 0:7e575e5f88ec | 381 | memcpy(stNotifi_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); |
lesmin | 0:7e575e5f88ec | 382 | memcpy(stNotifi_Req.body.usGWID, pszGWID, strlen(pszGWID)); |
lesmin | 0:7e575e5f88ec | 383 | |
lesmin | 0:7e575e5f88ec | 384 | if(pszDeviceID != NULL) //Device 판단 |
lesmin | 0:7e575e5f88ec | 385 | { |
lesmin | 0:7e575e5f88ec | 386 | if(strlen(pszDeviceID) > LEN_DEVICE_ID) //Device ID 길이 확인 |
lesmin | 0:7e575e5f88ec | 387 | { |
lesmin | 0:7e575e5f88ec | 388 | } |
lesmin | 0:7e575e5f88ec | 389 | else |
lesmin | 0:7e575e5f88ec | 390 | { |
lesmin | 0:7e575e5f88ec | 391 | memcpy(stNotifi_Req.body.usDeviceID, pszDeviceID, strlen(pszDeviceID)); |
lesmin | 0:7e575e5f88ec | 392 | } |
lesmin | 0:7e575e5f88ec | 393 | } |
lesmin | 0:7e575e5f88ec | 394 | |
lesmin | 0:7e575e5f88ec | 395 | stNotifi_Req.body.ucControlType = cControlType; |
lesmin | 0:7e575e5f88ec | 396 | stNotifi_Req.body.ucResultCode = cResultCode; |
lesmin | 0:7e575e5f88ec | 397 | |
lesmin | 0:7e575e5f88ec | 398 | if(pszMessageBody != NULL) //Message 사용 판단 |
lesmin | 0:7e575e5f88ec | 399 | { |
lesmin | 0:7e575e5f88ec | 400 | if(nMessageSize > MAX_MSG_BODY) |
lesmin | 0:7e575e5f88ec | 401 | { |
lesmin | 0:7e575e5f88ec | 402 | } |
lesmin | 0:7e575e5f88ec | 403 | else |
lesmin | 0:7e575e5f88ec | 404 | { |
lesmin | 0:7e575e5f88ec | 405 | memcpy(stNotifi_Req.body.usMessageBody, pszMessageBody, nMessageSize); |
lesmin | 0:7e575e5f88ec | 406 | } |
lesmin | 0:7e575e5f88ec | 407 | } |
lesmin | 0:7e575e5f88ec | 408 | |
lesmin | 0:7e575e5f88ec | 409 | GMMP_Trace(&stNotifi_Req.header, &stNotifi_Req.body); |
lesmin | 0:7e575e5f88ec | 410 | |
lesmin | 0:7e575e5f88ec | 411 | nRet = GMMP_Notifi_Req(&stNotifi_Req, PacketSize); |
lesmin | 0:7e575e5f88ec | 412 | |
lesmin | 0:7e575e5f88ec | 413 | return nRet; |
lesmin | 0:7e575e5f88ec | 414 | } |
lesmin | 0:7e575e5f88ec | 415 | |
lesmin | 0:7e575e5f88ec | 416 | int GMMP_SetHB(const char* pszAuthID, |
lesmin | 0:7e575e5f88ec | 417 | const char* pszAuthKey, |
lesmin | 0:7e575e5f88ec | 418 | const char* pszDomainCode, |
lesmin | 0:7e575e5f88ec | 419 | const char* pszGWID) |
lesmin | 0:7e575e5f88ec | 420 | { |
lesmin | 0:7e575e5f88ec | 421 | /* |
lesmin | 0:7e575e5f88ec | 422 | if(pszAuthID == NULL |
lesmin | 0:7e575e5f88ec | 423 | || pszAuthKey == NULL |
lesmin | 0:7e575e5f88ec | 424 | || pszDomainCode == NULL |
lesmin | 0:7e575e5f88ec | 425 | || pszGWID ==NULL |
lesmin | 0:7e575e5f88ec | 426 | || strlen(pszAuthID) > LEN_AUTH_ID |
lesmin | 0:7e575e5f88ec | 427 | || strlen(pszAuthKey) > LEN_AUTH_KEY |
lesmin | 0:7e575e5f88ec | 428 | || strlen(pszDomainCode) > LEN_DOMAIN_CODE |
lesmin | 0:7e575e5f88ec | 429 | || strlen(pszGWID) > LEN_GW_ID) |
lesmin | 0:7e575e5f88ec | 430 | { |
lesmin | 0:7e575e5f88ec | 431 | return LIB_PARAM_ERROR; |
lesmin | 0:7e575e5f88ec | 432 | } |
lesmin | 0:7e575e5f88ec | 433 | */ |
lesmin | 0:7e575e5f88ec | 434 | |
lesmin | 0:7e575e5f88ec | 435 | int nRet = GMMP_SUCCESS; |
lesmin | 0:7e575e5f88ec | 436 | |
lesmin | 0:7e575e5f88ec | 437 | HB_Req stHB_Req; |
lesmin | 0:7e575e5f88ec | 438 | |
lesmin | 0:7e575e5f88ec | 439 | memset(&stHB_Req, 0 ,sizeof(stHB_Req)); |
lesmin | 0:7e575e5f88ec | 440 | |
lesmin | 0:7e575e5f88ec | 441 | nRet = SetHeader((void*)&stHB_Req, sizeof(stHB_Req), 1, 1, OPERATION_HEARTBEAT_REQ, pszAuthID, pszAuthKey); |
lesmin | 0:7e575e5f88ec | 442 | if(nRet != GMMP_SUCCESS) |
lesmin | 0:7e575e5f88ec | 443 | { |
lesmin | 0:7e575e5f88ec | 444 | return nRet; |
lesmin | 0:7e575e5f88ec | 445 | } |
lesmin | 0:7e575e5f88ec | 446 | |
lesmin | 0:7e575e5f88ec | 447 | memcpy(stHB_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); |
lesmin | 0:7e575e5f88ec | 448 | memcpy(stHB_Req.body.usGWID, pszGWID, strlen(pszGWID)); |
lesmin | 0:7e575e5f88ec | 449 | |
lesmin | 0:7e575e5f88ec | 450 | GMMP_Trace(&stHB_Req.header, &stHB_Req.body); |
lesmin | 0:7e575e5f88ec | 451 | |
lesmin | 0:7e575e5f88ec | 452 | nRet = GMMP_Heartbeat_Req(&stHB_Req); |
lesmin | 0:7e575e5f88ec | 453 | |
lesmin | 0:7e575e5f88ec | 454 | return nRet; |
lesmin | 0:7e575e5f88ec | 455 | } |
lesmin | 0:7e575e5f88ec | 456 | |
lesmin | 0:7e575e5f88ec | 457 | //GW/Device 등록/해지 Response |
lesmin | 0:7e575e5f88ec | 458 | int GMMP_GetReg(GwRegist_Rsp* pstGwRegist_Rsp, DeviceRegist_Rsp* pstDeviceRegist_Rsp) |
lesmin | 0:7e575e5f88ec | 459 | { |
lesmin | 0:7e575e5f88ec | 460 | int nRet = GMMP_SUCCESS; |
lesmin | 0:7e575e5f88ec | 461 | |
lesmin | 0:7e575e5f88ec | 462 | if(pstGwRegist_Rsp != NULL) |
lesmin | 0:7e575e5f88ec | 463 | { |
lesmin | 0:7e575e5f88ec | 464 | nRet = GMMP_GW_Reg_Rsp(pstGwRegist_Rsp); |
lesmin | 0:7e575e5f88ec | 465 | GMMP_Trace(&pstGwRegist_Rsp->header, &pstGwRegist_Rsp->body); |
lesmin | 0:7e575e5f88ec | 466 | } |
lesmin | 0:7e575e5f88ec | 467 | else |
lesmin | 0:7e575e5f88ec | 468 | { |
lesmin | 0:7e575e5f88ec | 469 | nRet = GMMP_Device_Reg_Rsp(pstDeviceRegist_Rsp); |
lesmin | 0:7e575e5f88ec | 470 | GMMP_Trace(&pstDeviceRegist_Rsp->header, &pstDeviceRegist_Rsp->body); |
lesmin | 0:7e575e5f88ec | 471 | } |
lesmin | 0:7e575e5f88ec | 472 | |
lesmin | 0:7e575e5f88ec | 473 | CloseSocket(); |
lesmin | 0:7e575e5f88ec | 474 | |
lesmin | 0:7e575e5f88ec | 475 | return nRet; |
lesmin | 0:7e575e5f88ec | 476 | } |
lesmin | 0:7e575e5f88ec | 477 | |
lesmin | 0:7e575e5f88ec | 478 | int GMMP_GetDeReg(GwDeRegist_Rsp* pstGwRegist_Rsp, DeviceDeRegist_Rsp* pstDeviceDeRegist_Rsp) |
lesmin | 0:7e575e5f88ec | 479 | { |
lesmin | 0:7e575e5f88ec | 480 | int nRet = GMMP_SUCCESS; |
lesmin | 0:7e575e5f88ec | 481 | |
lesmin | 0:7e575e5f88ec | 482 | if(pstGwRegist_Rsp != NULL) |
lesmin | 0:7e575e5f88ec | 483 | { |
lesmin | 0:7e575e5f88ec | 484 | nRet = GMMP_GW_DeReg_Rsp(pstGwRegist_Rsp); |
lesmin | 0:7e575e5f88ec | 485 | GMMP_Trace(&pstGwRegist_Rsp->header, &pstGwRegist_Rsp->body); |
lesmin | 0:7e575e5f88ec | 486 | } |
lesmin | 0:7e575e5f88ec | 487 | else |
lesmin | 0:7e575e5f88ec | 488 | { |
lesmin | 0:7e575e5f88ec | 489 | nRet = GMMP_Device_DeReg_Rsp(pstDeviceDeRegist_Rsp); |
lesmin | 0:7e575e5f88ec | 490 | GMMP_Trace(&pstDeviceDeRegist_Rsp->header, &pstDeviceDeRegist_Rsp->body); |
lesmin | 0:7e575e5f88ec | 491 | } |
lesmin | 0:7e575e5f88ec | 492 | |
lesmin | 0:7e575e5f88ec | 493 | CloseSocket(); |
lesmin | 0:7e575e5f88ec | 494 | |
lesmin | 0:7e575e5f88ec | 495 | return nRet; |
lesmin | 0:7e575e5f88ec | 496 | } |
lesmin | 0:7e575e5f88ec | 497 | |
lesmin | 0:7e575e5f88ec | 498 | //Profile Info Response |
lesmin | 0:7e575e5f88ec | 499 | int GMMP_GetProfile(Profile_Rsp* pstProfile_Rsp) |
lesmin | 0:7e575e5f88ec | 500 | { |
lesmin | 0:7e575e5f88ec | 501 | int nRet = GMMP_Profile_Rsp(pstProfile_Rsp); |
lesmin | 0:7e575e5f88ec | 502 | |
lesmin | 0:7e575e5f88ec | 503 | GMMP_Trace(&pstProfile_Rsp->header, &pstProfile_Rsp->body); |
lesmin | 0:7e575e5f88ec | 504 | |
lesmin | 0:7e575e5f88ec | 505 | CloseSocket(); |
lesmin | 0:7e575e5f88ec | 506 | |
lesmin | 0:7e575e5f88ec | 507 | return nRet; |
lesmin | 0:7e575e5f88ec | 508 | } |
lesmin | 0:7e575e5f88ec | 509 | |
lesmin | 0:7e575e5f88ec | 510 | //수집 데이터 보고 Response |
lesmin | 0:7e575e5f88ec | 511 | int GMMP_GetDelivery(Delivery_Rsp* pstDelivery_Rsp) |
lesmin | 0:7e575e5f88ec | 512 | { |
lesmin | 0:7e575e5f88ec | 513 | int nRet = GMMP_Delivery_Rsp(pstDelivery_Rsp); |
lesmin | 0:7e575e5f88ec | 514 | |
lesmin | 0:7e575e5f88ec | 515 | GMMP_Trace(&pstDelivery_Rsp->header, &pstDelivery_Rsp->body); |
lesmin | 0:7e575e5f88ec | 516 | |
lesmin | 0:7e575e5f88ec | 517 | CloseSocket(); |
lesmin | 0:7e575e5f88ec | 518 | |
lesmin | 0:7e575e5f88ec | 519 | return nRet; |
lesmin | 0:7e575e5f88ec | 520 | } |
lesmin | 0:7e575e5f88ec | 521 | //제어 동작 완료 결과 보고 Response |
lesmin | 0:7e575e5f88ec | 522 | int GMMP_GetNotifi(Notifi_Rsp* pstNotifi_Rsp) |
lesmin | 0:7e575e5f88ec | 523 | { |
lesmin | 0:7e575e5f88ec | 524 | int nRet = GMMP_Notifi_Rsp(pstNotifi_Rsp); |
lesmin | 0:7e575e5f88ec | 525 | |
lesmin | 0:7e575e5f88ec | 526 | GMMP_Trace(&pstNotifi_Rsp->header, &pstNotifi_Rsp->body); |
lesmin | 0:7e575e5f88ec | 527 | |
lesmin | 0:7e575e5f88ec | 528 | CloseSocket(); |
lesmin | 0:7e575e5f88ec | 529 | |
lesmin | 0:7e575e5f88ec | 530 | return nRet; |
lesmin | 0:7e575e5f88ec | 531 | } |
lesmin | 0:7e575e5f88ec | 532 | |
lesmin | 0:7e575e5f88ec | 533 | int GMMP_GetHB(HB_Rsp* pstHB_Rsp) //TCP Always ON 모드일 경우 (Thread 생성) 사용 TCP Disconnect하지 않음 |
lesmin | 0:7e575e5f88ec | 534 | { |
lesmin | 0:7e575e5f88ec | 535 | int nRet = GMMP_Heartbeat_Rsp(pstHB_Rsp); |
lesmin | 0:7e575e5f88ec | 536 | |
lesmin | 0:7e575e5f88ec | 537 | GMMP_Trace(&pstHB_Rsp->header, &pstHB_Rsp->body); |
lesmin | 0:7e575e5f88ec | 538 | |
lesmin | 0:7e575e5f88ec | 539 | return nRet; |
lesmin | 0:7e575e5f88ec | 540 | } |
lesmin | 0:7e575e5f88ec | 541 | |
lesmin | 0:7e575e5f88ec | 542 | int GMMP_Read(GMMPHeader* pstGMMPHeader, void** pBody) |
lesmin | 0:7e575e5f88ec | 543 | { |
lesmin | 0:7e575e5f88ec | 544 | return GMMP_Read2(pstGMMPHeader, pBody, 1); |
lesmin | 0:7e575e5f88ec | 545 | } |
lesmin | 0:7e575e5f88ec | 546 | |
lesmin | 0:7e575e5f88ec | 547 | int GMMP_Read2(GMMPHeader* pstGMMPHeader, void** pBody, byte blocking) |
lesmin | 0:7e575e5f88ec | 548 | { |
lesmin | 0:7e575e5f88ec | 549 | ConvertShort cvtShort; |
lesmin | 0:7e575e5f88ec | 550 | //ConvertInt cvtint; |
lesmin | 0:7e575e5f88ec | 551 | |
lesmin | 0:7e575e5f88ec | 552 | int nRet = 0; |
lesmin | 0:7e575e5f88ec | 553 | int nHeaderSize = sizeof(GMMPHeader); |
lesmin | 0:7e575e5f88ec | 554 | |
lesmin | 0:7e575e5f88ec | 555 | memset(pstGMMPHeader, 0, nHeaderSize); |
lesmin | 0:7e575e5f88ec | 556 | |
lesmin | 0:7e575e5f88ec | 557 | cvtShort.sU8 = 0; |
lesmin | 0:7e575e5f88ec | 558 | //cvtint.sU8 = 0; |
lesmin | 0:7e575e5f88ec | 559 | |
lesmin | 0:7e575e5f88ec | 560 | nRet = 0; |
lesmin | 0:7e575e5f88ec | 561 | |
lesmin | 0:7e575e5f88ec | 562 | nRet = ReadTCP2((char*)pstGMMPHeader, nHeaderSize, blocking); |
lesmin | 0:7e575e5f88ec | 563 | if (nRet != GMMP_SUCCESS) |
lesmin | 0:7e575e5f88ec | 564 | { |
lesmin | 0:7e575e5f88ec | 565 | return nRet; |
lesmin | 0:7e575e5f88ec | 566 | } |
lesmin | 0:7e575e5f88ec | 567 | |
lesmin | 0:7e575e5f88ec | 568 | memcpy(cvtShort.usShort, pstGMMPHeader->usMessageLength, sizeof(pstGMMPHeader->usMessageLength)); |
lesmin | 0:7e575e5f88ec | 569 | cvtShort.sU8 = btols(cvtShort.sU8); |
lesmin | 0:7e575e5f88ec | 570 | |
lesmin | 0:7e575e5f88ec | 571 | if (cvtShort.sU8 < nHeaderSize) |
lesmin | 0:7e575e5f88ec | 572 | { |
lesmin | 0:7e575e5f88ec | 573 | return GMMP_HEADER_SIZE_ERROR; |
lesmin | 0:7e575e5f88ec | 574 | } |
lesmin | 0:7e575e5f88ec | 575 | |
lesmin | 0:7e575e5f88ec | 576 | int nBodySize = 0; |
lesmin | 0:7e575e5f88ec | 577 | |
lesmin | 0:7e575e5f88ec | 578 | if ((*pBody = MallocBody(pstGMMPHeader->ucMessageType, &nBodySize))== NULL || nBodySize <= 0) |
lesmin | 0:7e575e5f88ec | 579 | { |
lesmin | 0:7e575e5f88ec | 580 | return GMMP_MALLOC_ERROR; |
lesmin | 0:7e575e5f88ec | 581 | } |
lesmin | 0:7e575e5f88ec | 582 | |
lesmin | 0:7e575e5f88ec | 583 | memset(*pBody, 0, nBodySize); |
lesmin | 0:7e575e5f88ec | 584 | |
lesmin | 0:7e575e5f88ec | 585 | int ReadPacketSize = cvtShort.sU8 - nHeaderSize; |
lesmin | 0:7e575e5f88ec | 586 | |
lesmin | 0:7e575e5f88ec | 587 | nRet = ReadTCP2((char*)(*pBody), ReadPacketSize, blocking); |
lesmin | 0:7e575e5f88ec | 588 | if(nRet != GMMP_SUCCESS) |
lesmin | 0:7e575e5f88ec | 589 | { |
lesmin | 0:7e575e5f88ec | 590 | CloseSocket(); |
lesmin | 0:7e575e5f88ec | 591 | |
lesmin | 0:7e575e5f88ec | 592 | return nRet; |
lesmin | 0:7e575e5f88ec | 593 | } |
lesmin | 0:7e575e5f88ec | 594 | |
lesmin | 0:7e575e5f88ec | 595 | return GMMP_SUCCESS; |
lesmin | 0:7e575e5f88ec | 596 | } |
lesmin | 0:7e575e5f88ec | 597 | |
lesmin | 0:7e575e5f88ec | 598 | int GMMP_Recv(GMMPHeader* pstGMMPHeader, void* pBody) |
lesmin | 0:7e575e5f88ec | 599 | { |
lesmin | 0:7e575e5f88ec | 600 | GMMP_Trace(pstGMMPHeader, pBody); |
lesmin | 0:7e575e5f88ec | 601 | |
lesmin | 0:7e575e5f88ec | 602 | char cMessageType = pstGMMPHeader->ucMessageType ; |
lesmin | 0:7e575e5f88ec | 603 | |
lesmin | 0:7e575e5f88ec | 604 | if(cMessageType == OPERATION_GW_REG_RSP) |
lesmin | 0:7e575e5f88ec | 605 | { |
lesmin | 0:7e575e5f88ec | 606 | stGwRegistrationRspHdr* pstRspHdr =(stGwRegistrationRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 607 | OG_Reg_Recv(pstGMMPHeader, pstRspHdr, NULL); |
lesmin | 0:7e575e5f88ec | 608 | } |
lesmin | 0:7e575e5f88ec | 609 | else if(cMessageType == OPERATION_GW_DEREG_RSP) |
lesmin | 0:7e575e5f88ec | 610 | { |
lesmin | 0:7e575e5f88ec | 611 | stGwDeRegistrationRspHdr* pstRspHdr =(stGwDeRegistrationRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 612 | OG_DeReg_Recv(pstGMMPHeader, pstRspHdr, NULL); |
lesmin | 0:7e575e5f88ec | 613 | } |
lesmin | 0:7e575e5f88ec | 614 | else if(cMessageType == OPERATION_PROFILE_RSP) |
lesmin | 0:7e575e5f88ec | 615 | { |
lesmin | 0:7e575e5f88ec | 616 | stProfileRspHdr* pstRspHdr =(stProfileRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 617 | OG_Profile_Recv(pstGMMPHeader, pstRspHdr); |
lesmin | 0:7e575e5f88ec | 618 | } |
lesmin | 0:7e575e5f88ec | 619 | else if(cMessageType == OPERATION_DEVICE_REG_RSP) |
lesmin | 0:7e575e5f88ec | 620 | { |
lesmin | 0:7e575e5f88ec | 621 | stDeviceRegistrationRspHdr* pstRspHdr =(stDeviceRegistrationRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 622 | OG_Reg_Recv(pstGMMPHeader, NULL, pstRspHdr); |
lesmin | 0:7e575e5f88ec | 623 | } |
lesmin | 0:7e575e5f88ec | 624 | else if(cMessageType == OPERATION_DEVICE_DEREG_RSP) |
lesmin | 0:7e575e5f88ec | 625 | { |
lesmin | 0:7e575e5f88ec | 626 | stDeviceDeRegistrationRspHdr* pstRspHdr =(stDeviceDeRegistrationRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 627 | OG_DeReg_Recv(pstGMMPHeader, NULL, pstRspHdr); |
lesmin | 0:7e575e5f88ec | 628 | } |
lesmin | 0:7e575e5f88ec | 629 | else if(cMessageType == OPERATION_DELIVERY_RSP) |
lesmin | 0:7e575e5f88ec | 630 | { |
lesmin | 0:7e575e5f88ec | 631 | stPacketDeliveryRspHdr* pstRspHdr =(stPacketDeliveryRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 632 | OG_Delivery_Recv(pstGMMPHeader, pstRspHdr); |
lesmin | 0:7e575e5f88ec | 633 | } |
lesmin | 0:7e575e5f88ec | 634 | else if(cMessageType == OPERATION_CONTROL_REQ) |
lesmin | 0:7e575e5f88ec | 635 | { |
lesmin | 0:7e575e5f88ec | 636 | stControlReqHdr* pstReqHdr =(stControlReqHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 637 | GMMP_Ctrl_Recv(pstGMMPHeader, pstReqHdr); |
lesmin | 0:7e575e5f88ec | 638 | } |
lesmin | 0:7e575e5f88ec | 639 | else if(cMessageType == OPERATION_HEARTBEAT_RSP) |
lesmin | 0:7e575e5f88ec | 640 | { |
lesmin | 0:7e575e5f88ec | 641 | stHeartBeatMsgRspHdr* pstRspHdr =(stHeartBeatMsgRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 642 | OG_HB_Recv(pstGMMPHeader, pstRspHdr); |
lesmin | 0:7e575e5f88ec | 643 | } |
lesmin | 0:7e575e5f88ec | 644 | else if(cMessageType == OPERATION_NOTIFICATION_RSP) |
lesmin | 0:7e575e5f88ec | 645 | { |
lesmin | 0:7e575e5f88ec | 646 | stNotificationRspHdr* pstRspHdr =(stNotificationRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 647 | OG_Notifi_Recv(pstGMMPHeader, pstRspHdr); |
lesmin | 0:7e575e5f88ec | 648 | } |
lesmin | 0:7e575e5f88ec | 649 | |
lesmin | 0:7e575e5f88ec | 650 | return GMMP_SUCCESS; |
lesmin | 0:7e575e5f88ec | 651 | } |
lesmin | 0:7e575e5f88ec | 652 | |
lesmin | 0:7e575e5f88ec | 653 | int GMMP_Ctrl_Recv(GMMPHeader* pstGMMPHeader, stControlReqHdr* pstReqHdr) |
lesmin | 0:7e575e5f88ec | 654 | { |
lesmin | 0:7e575e5f88ec | 655 | char cControlType = pstReqHdr->ucControlType; |
lesmin | 0:7e575e5f88ec | 656 | |
lesmin | 0:7e575e5f88ec | 657 | //단순 제어 명령어인 경우 |
lesmin | 0:7e575e5f88ec | 658 | switch(cControlType) |
lesmin | 0:7e575e5f88ec | 659 | { |
lesmin | 0:7e575e5f88ec | 660 | case CONTROL_Reset: |
lesmin | 0:7e575e5f88ec | 661 | break; |
lesmin | 0:7e575e5f88ec | 662 | case CONTROL_Turn_Off: |
lesmin | 0:7e575e5f88ec | 663 | break; |
lesmin | 0:7e575e5f88ec | 664 | case CONTROL_Report_On: |
lesmin | 0:7e575e5f88ec | 665 | break; |
lesmin | 0:7e575e5f88ec | 666 | case CONTROL_Report_Off: |
lesmin | 0:7e575e5f88ec | 667 | break; |
lesmin | 0:7e575e5f88ec | 668 | case CONTROL_Time_Sync: |
lesmin | 0:7e575e5f88ec | 669 | break; |
lesmin | 0:7e575e5f88ec | 670 | case CONTROL_Pause: |
lesmin | 0:7e575e5f88ec | 671 | break; |
lesmin | 0:7e575e5f88ec | 672 | case CONTROL_Restart: |
lesmin | 0:7e575e5f88ec | 673 | break; |
lesmin | 0:7e575e5f88ec | 674 | case CONTROL_Signal_Power_Check: |
lesmin | 0:7e575e5f88ec | 675 | break; |
lesmin | 0:7e575e5f88ec | 676 | case CONTROL_Diagnostic: |
lesmin | 0:7e575e5f88ec | 677 | break; |
lesmin | 0:7e575e5f88ec | 678 | case CONTROL_Reserved: |
lesmin | 0:7e575e5f88ec | 679 | break; |
lesmin | 0:7e575e5f88ec | 680 | case CONTROL_Profile_Reset: |
lesmin | 0:7e575e5f88ec | 681 | break; |
lesmin | 0:7e575e5f88ec | 682 | case CONTROL_Status_Check: |
lesmin | 0:7e575e5f88ec | 683 | break; |
lesmin | 0:7e575e5f88ec | 684 | case CONTROL_FW_Download: //FTP 연결 |
lesmin | 0:7e575e5f88ec | 685 | break; |
lesmin | 0:7e575e5f88ec | 686 | case CONTROL_FW_Update: |
lesmin | 0:7e575e5f88ec | 687 | break; |
lesmin | 0:7e575e5f88ec | 688 | case CONTROL_App_Download: //FTP 연결 |
lesmin | 0:7e575e5f88ec | 689 | break; |
lesmin | 0:7e575e5f88ec | 690 | case CONTROL_App_Update: |
lesmin | 0:7e575e5f88ec | 691 | break; |
lesmin | 0:7e575e5f88ec | 692 | case CONTROL_Remote_Access: //Remote Info 연결 |
lesmin | 0:7e575e5f88ec | 693 | break; |
lesmin | 0:7e575e5f88ec | 694 | case CONTROL_Multimedia_Control_Start: //Multimedia URL Info 연결 |
lesmin | 0:7e575e5f88ec | 695 | break; |
lesmin | 0:7e575e5f88ec | 696 | case CONTROL_Multimedia_Control_Pause: |
lesmin | 0:7e575e5f88ec | 697 | break; |
lesmin | 0:7e575e5f88ec | 698 | case CONTROL_Multimedia_Control_Stop: |
lesmin | 0:7e575e5f88ec | 699 | break; |
lesmin | 0:7e575e5f88ec | 700 | case CONTROL_Multimedia_Control_Restart: |
lesmin | 0:7e575e5f88ec | 701 | break; |
lesmin | 0:7e575e5f88ec | 702 | default: |
lesmin | 0:7e575e5f88ec | 703 | break; |
lesmin | 0:7e575e5f88ec | 704 | } |
lesmin | 0:7e575e5f88ec | 705 | |
lesmin | 0:7e575e5f88ec | 706 | OG_Ctrl_Recv(pstGMMPHeader, pstReqHdr); |
lesmin | 0:7e575e5f88ec | 707 | |
lesmin | 0:7e575e5f88ec | 708 | return 1; |
lesmin | 0:7e575e5f88ec | 709 | } |
lesmin | 0:7e575e5f88ec | 710 | |
lesmin | 0:7e575e5f88ec | 711 | void SetTID(long nTid) |
lesmin | 0:7e575e5f88ec | 712 | { |
lesmin | 0:7e575e5f88ec | 713 | g_nTID = nTid; |
lesmin | 0:7e575e5f88ec | 714 | } |
lesmin | 0:7e575e5f88ec | 715 | |
lesmin | 0:7e575e5f88ec | 716 | long GetTID() |
lesmin | 0:7e575e5f88ec | 717 | { |
lesmin | 0:7e575e5f88ec | 718 | return g_nTID; |
lesmin | 0:7e575e5f88ec | 719 | } |
lesmin | 0:7e575e5f88ec | 720 | |
lesmin | 0:7e575e5f88ec | 721 | //protected |
lesmin | 0:7e575e5f88ec | 722 | int SetHeader(void* pData, |
lesmin | 0:7e575e5f88ec | 723 | int nPacketSize, |
lesmin | 0:7e575e5f88ec | 724 | int nTotalCount, |
lesmin | 0:7e575e5f88ec | 725 | int nCurrentCount, |
lesmin | 0:7e575e5f88ec | 726 | const char cMessageType, |
lesmin | 0:7e575e5f88ec | 727 | const char* pszAuthID, |
lesmin | 0:7e575e5f88ec | 728 | const char* pszAuthKey) |
lesmin | 0:7e575e5f88ec | 729 | { |
lesmin | 0:7e575e5f88ec | 730 | GMMPHeader* pHeader = (GMMPHeader*)pData; |
lesmin | 0:7e575e5f88ec | 731 | ConvertShort cvtShort; |
lesmin | 0:7e575e5f88ec | 732 | |
lesmin | 0:7e575e5f88ec | 733 | // debug(F("authID len = ")); |
lesmin | 0:7e575e5f88ec | 734 | // debugln(strlen(pszAuthID)); |
lesmin | 0:7e575e5f88ec | 735 | DBG("authID len = %d", strlen(pszAuthID)); |
lesmin | 0:7e575e5f88ec | 736 | |
lesmin | 0:7e575e5f88ec | 737 | memset(pHeader, 0, sizeof(GMMPHeader)); |
lesmin | 0:7e575e5f88ec | 738 | memset(cvtShort.usShort, 0, sizeof(cvtShort.usShort)); |
lesmin | 0:7e575e5f88ec | 739 | |
lesmin | 0:7e575e5f88ec | 740 | pHeader->ucVersion = GMMP_VERSION; |
lesmin | 0:7e575e5f88ec | 741 | |
lesmin | 0:7e575e5f88ec | 742 | ConvertInt cvtInt; |
lesmin | 0:7e575e5f88ec | 743 | |
lesmin | 0:7e575e5f88ec | 744 | time_t t; time ( &t ); |
lesmin | 0:7e575e5f88ec | 745 | |
lesmin | 0:7e575e5f88ec | 746 | // debug(F("TIME = ")); |
lesmin | 0:7e575e5f88ec | 747 | // debugln(t); |
lesmin | 0:7e575e5f88ec | 748 | DBG("TIME = %d", t); |
lesmin | 0:7e575e5f88ec | 749 | |
lesmin | 0:7e575e5f88ec | 750 | memcpy(cvtInt.usInt, &t, sizeof(cvtInt.usInt)); |
lesmin | 0:7e575e5f88ec | 751 | |
lesmin | 0:7e575e5f88ec | 752 | cvtInt.sU8 = ltobi(cvtInt.sU8); |
lesmin | 0:7e575e5f88ec | 753 | |
lesmin | 0:7e575e5f88ec | 754 | memcpy(&pHeader->unOriginTimeStamp, &cvtInt.usInt, sizeof(cvtInt.usInt)); |
lesmin | 0:7e575e5f88ec | 755 | memcpy(&pHeader->usAuthID, pszAuthID, strlen(pszAuthID)); |
lesmin | 0:7e575e5f88ec | 756 | |
lesmin | 0:7e575e5f88ec | 757 | if(pszAuthKey != NULL) |
lesmin | 0:7e575e5f88ec | 758 | { |
lesmin | 0:7e575e5f88ec | 759 | memcpy(&pHeader->usAuthKey, pszAuthKey, strlen(pszAuthKey)); |
lesmin | 0:7e575e5f88ec | 760 | } |
lesmin | 0:7e575e5f88ec | 761 | |
lesmin | 0:7e575e5f88ec | 762 | // debug(F("TID = ")); |
lesmin | 0:7e575e5f88ec | 763 | // debugln(g_nTID); |
lesmin | 0:7e575e5f88ec | 764 | DBG("TID = %ld", g_nTID); |
lesmin | 0:7e575e5f88ec | 765 | |
lesmin | 0:7e575e5f88ec | 766 | memcpy(&cvtInt.usInt, &g_nTID, sizeof(g_nTID)); |
lesmin | 0:7e575e5f88ec | 767 | cvtInt.sU8 = ltobi(cvtInt.sU8); |
lesmin | 0:7e575e5f88ec | 768 | |
lesmin | 0:7e575e5f88ec | 769 | memcpy(pHeader->usTID, &cvtInt.usInt, sizeof(pHeader->usTID)); |
lesmin | 0:7e575e5f88ec | 770 | |
lesmin | 0:7e575e5f88ec | 771 | cvtShort.sU8 = ltobs((short)nPacketSize); |
lesmin | 0:7e575e5f88ec | 772 | memcpy(pHeader->usMessageLength, cvtShort.usShort, sizeof(cvtShort.usShort)); |
lesmin | 0:7e575e5f88ec | 773 | |
lesmin | 0:7e575e5f88ec | 774 | cvtShort.sU8 = ltobs((short)nTotalCount); |
lesmin | 0:7e575e5f88ec | 775 | memcpy(pHeader->usTotalCount, cvtShort.usShort, sizeof(cvtShort.usShort)); |
lesmin | 0:7e575e5f88ec | 776 | |
lesmin | 0:7e575e5f88ec | 777 | cvtShort.sU8 = ltobs((short)nCurrentCount); |
lesmin | 0:7e575e5f88ec | 778 | memcpy(pHeader->usCurrentCount, cvtShort.usShort, sizeof(cvtShort.usShort)); |
lesmin | 0:7e575e5f88ec | 779 | |
lesmin | 0:7e575e5f88ec | 780 | pHeader->ucMessageType = cMessageType; |
lesmin | 0:7e575e5f88ec | 781 | |
lesmin | 0:7e575e5f88ec | 782 | return GMMP_SUCCESS; |
lesmin | 0:7e575e5f88ec | 783 | } |
lesmin | 0:7e575e5f88ec | 784 | |
lesmin | 0:7e575e5f88ec | 785 | int SetIntiSocket(void) |
lesmin | 0:7e575e5f88ec | 786 | { |
lesmin | 0:7e575e5f88ec | 787 | return Connect(); |
lesmin | 0:7e575e5f88ec | 788 | } |
lesmin | 0:7e575e5f88ec | 789 | |
lesmin | 0:7e575e5f88ec | 790 | char* MallocBody(const char Type, int* nBodySize) |
lesmin | 0:7e575e5f88ec | 791 | { |
lesmin | 0:7e575e5f88ec | 792 | char* pBuffer = NULL; |
lesmin | 0:7e575e5f88ec | 793 | |
lesmin | 0:7e575e5f88ec | 794 | switch(Type) |
lesmin | 0:7e575e5f88ec | 795 | { |
lesmin | 0:7e575e5f88ec | 796 | case OPERATION_GW_REG_RSP: |
lesmin | 0:7e575e5f88ec | 797 | { |
lesmin | 0:7e575e5f88ec | 798 | pBuffer = (char*)malloc(sizeof(stGwRegistrationRspHdr)); |
lesmin | 0:7e575e5f88ec | 799 | *nBodySize = sizeof(stGwRegistrationRspHdr); |
lesmin | 0:7e575e5f88ec | 800 | break; |
lesmin | 0:7e575e5f88ec | 801 | } |
lesmin | 0:7e575e5f88ec | 802 | case OPERATION_GW_DEREG_RSP: |
lesmin | 0:7e575e5f88ec | 803 | { |
lesmin | 0:7e575e5f88ec | 804 | pBuffer = (char*)malloc(sizeof(stGwDeRegistrationRspHdr)); |
lesmin | 0:7e575e5f88ec | 805 | *nBodySize = sizeof(stGwDeRegistrationRspHdr); |
lesmin | 0:7e575e5f88ec | 806 | break; |
lesmin | 0:7e575e5f88ec | 807 | } |
lesmin | 0:7e575e5f88ec | 808 | case OPERATION_PROFILE_RSP: |
lesmin | 0:7e575e5f88ec | 809 | { |
lesmin | 0:7e575e5f88ec | 810 | pBuffer = (char*)malloc(sizeof(stProfileRspHdr)); |
lesmin | 0:7e575e5f88ec | 811 | *nBodySize = sizeof(stProfileRspHdr); |
lesmin | 0:7e575e5f88ec | 812 | break; |
lesmin | 0:7e575e5f88ec | 813 | } |
lesmin | 0:7e575e5f88ec | 814 | case OPERATION_DEVICE_REG_RSP: |
lesmin | 0:7e575e5f88ec | 815 | { |
lesmin | 0:7e575e5f88ec | 816 | pBuffer = (char*)malloc(sizeof(stDeviceRegistrationRspHdr)); |
lesmin | 0:7e575e5f88ec | 817 | *nBodySize = sizeof(stDeviceRegistrationRspHdr); |
lesmin | 0:7e575e5f88ec | 818 | break; |
lesmin | 0:7e575e5f88ec | 819 | } |
lesmin | 0:7e575e5f88ec | 820 | case OPERATION_DEVICE_DEREG_RSP: |
lesmin | 0:7e575e5f88ec | 821 | { |
lesmin | 0:7e575e5f88ec | 822 | pBuffer = (char*)malloc(sizeof(stDeviceDeRegistrationRspHdr)); |
lesmin | 0:7e575e5f88ec | 823 | *nBodySize = sizeof(stDeviceDeRegistrationRspHdr); |
lesmin | 0:7e575e5f88ec | 824 | break; |
lesmin | 0:7e575e5f88ec | 825 | } |
lesmin | 0:7e575e5f88ec | 826 | case OPERATION_DELIVERY_RSP: |
lesmin | 0:7e575e5f88ec | 827 | { |
lesmin | 0:7e575e5f88ec | 828 | pBuffer = (char*)malloc(sizeof(stPacketDeliveryRspHdr)); |
lesmin | 0:7e575e5f88ec | 829 | *nBodySize = sizeof(stPacketDeliveryRspHdr); |
lesmin | 0:7e575e5f88ec | 830 | break; |
lesmin | 0:7e575e5f88ec | 831 | } |
lesmin | 0:7e575e5f88ec | 832 | case OPERATION_CONTROL_REQ: |
lesmin | 0:7e575e5f88ec | 833 | { |
lesmin | 0:7e575e5f88ec | 834 | pBuffer = (char*)malloc(sizeof(stControlReqHdr)); |
lesmin | 0:7e575e5f88ec | 835 | *nBodySize = sizeof(stControlReqHdr); |
lesmin | 0:7e575e5f88ec | 836 | break; |
lesmin | 0:7e575e5f88ec | 837 | } |
lesmin | 0:7e575e5f88ec | 838 | case OPERATION_HEARTBEAT_RSP: |
lesmin | 0:7e575e5f88ec | 839 | { |
lesmin | 0:7e575e5f88ec | 840 | pBuffer = (char*)malloc(sizeof(stHeartBeatMsgRspHdr)); |
lesmin | 0:7e575e5f88ec | 841 | *nBodySize = sizeof(stHeartBeatMsgRspHdr); |
lesmin | 0:7e575e5f88ec | 842 | break; |
lesmin | 0:7e575e5f88ec | 843 | } |
lesmin | 0:7e575e5f88ec | 844 | case OPERATION_NOTIFICATION_RSP: |
lesmin | 0:7e575e5f88ec | 845 | { |
lesmin | 0:7e575e5f88ec | 846 | pBuffer = (char*)malloc(sizeof(stNotificationRspHdr)); |
lesmin | 0:7e575e5f88ec | 847 | *nBodySize = sizeof(stNotificationRspHdr); |
lesmin | 0:7e575e5f88ec | 848 | break; |
lesmin | 0:7e575e5f88ec | 849 | } |
lesmin | 0:7e575e5f88ec | 850 | default: |
lesmin | 0:7e575e5f88ec | 851 | { |
lesmin | 0:7e575e5f88ec | 852 | nBodySize = 0; |
lesmin | 0:7e575e5f88ec | 853 | } |
lesmin | 0:7e575e5f88ec | 854 | } |
lesmin | 0:7e575e5f88ec | 855 | |
lesmin | 0:7e575e5f88ec | 856 | return pBuffer; |
lesmin | 0:7e575e5f88ec | 857 | } |
lesmin | 0:7e575e5f88ec | 858 | |
lesmin | 0:7e575e5f88ec | 859 | int GMMP_Trace(GMMPHeader* pstGMMPHeader, void* pBody) |
lesmin | 0:7e575e5f88ec | 860 | { |
lesmin | 0:7e575e5f88ec | 861 | ConvertInt cvtint; |
lesmin | 0:7e575e5f88ec | 862 | |
lesmin | 0:7e575e5f88ec | 863 | char cMessageType = pstGMMPHeader->ucMessageType ; |
lesmin | 0:7e575e5f88ec | 864 | |
lesmin | 0:7e575e5f88ec | 865 | memcpy(cvtint.usInt, pstGMMPHeader->usTID, sizeof(pstGMMPHeader->usTID)); |
lesmin | 0:7e575e5f88ec | 866 | cvtint.sU8 = btoli(cvtint.sU8); |
lesmin | 0:7e575e5f88ec | 867 | |
lesmin | 0:7e575e5f88ec | 868 | if(cMessageType == OPERATION_GW_REG_REQ) |
lesmin | 0:7e575e5f88ec | 869 | { |
lesmin | 0:7e575e5f88ec | 870 | stGwRegistrationReqHdr* pstRspHdr =(stGwRegistrationReqHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 871 | } |
lesmin | 0:7e575e5f88ec | 872 | else if(cMessageType == OPERATION_GW_REG_RSP) |
lesmin | 0:7e575e5f88ec | 873 | { |
lesmin | 0:7e575e5f88ec | 874 | stGwRegistrationRspHdr* pstRspHdr =(stGwRegistrationRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 875 | } |
lesmin | 0:7e575e5f88ec | 876 | else if(cMessageType == OPERATION_GW_DEREG_REQ) |
lesmin | 0:7e575e5f88ec | 877 | { |
lesmin | 0:7e575e5f88ec | 878 | stGwDeRegistrationReqHdr* pstRspHdr =(stGwDeRegistrationReqHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 879 | } |
lesmin | 0:7e575e5f88ec | 880 | else if(cMessageType == OPERATION_GW_DEREG_RSP) |
lesmin | 0:7e575e5f88ec | 881 | { |
lesmin | 0:7e575e5f88ec | 882 | stGwDeRegistrationRspHdr* pstRspHdr =(stGwDeRegistrationRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 883 | } |
lesmin | 0:7e575e5f88ec | 884 | else if(cMessageType == OPERATION_PROFILE_REQ) |
lesmin | 0:7e575e5f88ec | 885 | { |
lesmin | 0:7e575e5f88ec | 886 | stProfileReqHdr* pstRspHdr =(stProfileReqHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 887 | } |
lesmin | 0:7e575e5f88ec | 888 | else if(cMessageType == OPERATION_PROFILE_RSP) |
lesmin | 0:7e575e5f88ec | 889 | { |
lesmin | 0:7e575e5f88ec | 890 | stProfileRspHdr* pstRspHdr =(stProfileRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 891 | |
lesmin | 0:7e575e5f88ec | 892 | memcpy(cvtint.usInt, pstRspHdr->unHeartbeatPeriod, sizeof(pstRspHdr->unHeartbeatPeriod)); |
lesmin | 0:7e575e5f88ec | 893 | cvtint.sU8 = btoli(cvtint.sU8); |
lesmin | 0:7e575e5f88ec | 894 | |
lesmin | 0:7e575e5f88ec | 895 | memcpy(cvtint.usInt, pstRspHdr->unReportPeriod, sizeof(pstRspHdr->unReportPeriod)); |
lesmin | 0:7e575e5f88ec | 896 | cvtint.sU8 = btoli(cvtint.sU8); |
lesmin | 0:7e575e5f88ec | 897 | |
lesmin | 0:7e575e5f88ec | 898 | memcpy(cvtint.usInt, pstRspHdr->unReportOffset, sizeof(pstRspHdr->unReportOffset)); |
lesmin | 0:7e575e5f88ec | 899 | cvtint.sU8 = btoli(cvtint.sU8); |
lesmin | 0:7e575e5f88ec | 900 | |
lesmin | 0:7e575e5f88ec | 901 | memcpy(cvtint.usInt, pstRspHdr->unResponseTimeout, sizeof(pstRspHdr->unResponseTimeout)); |
lesmin | 0:7e575e5f88ec | 902 | cvtint.sU8 = btoli(cvtint.sU8); |
lesmin | 0:7e575e5f88ec | 903 | } |
lesmin | 0:7e575e5f88ec | 904 | else if(cMessageType == OPERATION_DEVICE_REG_REQ) |
lesmin | 0:7e575e5f88ec | 905 | { |
lesmin | 0:7e575e5f88ec | 906 | stDeviceRegistrationReqHdr* pstRspHdr =(stDeviceRegistrationReqHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 907 | } |
lesmin | 0:7e575e5f88ec | 908 | else if(cMessageType == OPERATION_DEVICE_REG_RSP) |
lesmin | 0:7e575e5f88ec | 909 | { |
lesmin | 0:7e575e5f88ec | 910 | stDeviceRegistrationRspHdr* pstRspHdr =(stDeviceRegistrationRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 911 | } |
lesmin | 0:7e575e5f88ec | 912 | else if(cMessageType == OPERATION_DEVICE_DEREG_REQ) |
lesmin | 0:7e575e5f88ec | 913 | { |
lesmin | 0:7e575e5f88ec | 914 | stDeviceDeRegistrationReqHdr* pstRspHdr =(stDeviceDeRegistrationReqHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 915 | } |
lesmin | 0:7e575e5f88ec | 916 | else if(cMessageType == OPERATION_DEVICE_DEREG_RSP) |
lesmin | 0:7e575e5f88ec | 917 | { |
lesmin | 0:7e575e5f88ec | 918 | stDeviceDeRegistrationRspHdr* pstRspHdr =(stDeviceDeRegistrationRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 919 | } |
lesmin | 0:7e575e5f88ec | 920 | else if(cMessageType == OPERATION_DELIVERY_REQ) |
lesmin | 0:7e575e5f88ec | 921 | { |
lesmin | 0:7e575e5f88ec | 922 | stPacketDeliveryReqHdr* pstRspHdr =(stPacketDeliveryReqHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 923 | } |
lesmin | 0:7e575e5f88ec | 924 | else if(cMessageType == OPERATION_DELIVERY_RSP) |
lesmin | 0:7e575e5f88ec | 925 | { |
lesmin | 0:7e575e5f88ec | 926 | stPacketDeliveryRspHdr* pstRspHdr =(stPacketDeliveryRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 927 | |
lesmin | 0:7e575e5f88ec | 928 | memcpy(cvtint.usInt, pstRspHdr->unBackOffTime, sizeof(pstRspHdr->unBackOffTime)); |
lesmin | 0:7e575e5f88ec | 929 | cvtint.sU8 = btoli(cvtint.sU8); |
lesmin | 0:7e575e5f88ec | 930 | } |
lesmin | 0:7e575e5f88ec | 931 | else if(cMessageType == OPERATION_CONTROL_REQ) |
lesmin | 0:7e575e5f88ec | 932 | { |
lesmin | 0:7e575e5f88ec | 933 | stControlReqHdr* pstReqHdr =(stControlReqHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 934 | } |
lesmin | 0:7e575e5f88ec | 935 | else if(cMessageType == OPERATION_CONTROL_RSP) |
lesmin | 0:7e575e5f88ec | 936 | { |
lesmin | 0:7e575e5f88ec | 937 | stControlRspHdr* pstRspHdr =(stControlRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 938 | } |
lesmin | 0:7e575e5f88ec | 939 | else if(cMessageType == OPERATION_HEARTBEAT_REQ) |
lesmin | 0:7e575e5f88ec | 940 | { |
lesmin | 0:7e575e5f88ec | 941 | stHeartBeatMsgRspHdr* pstRspHdr =(stHeartBeatMsgRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 942 | } |
lesmin | 0:7e575e5f88ec | 943 | else if(cMessageType == OPERATION_HEARTBEAT_RSP) |
lesmin | 0:7e575e5f88ec | 944 | { |
lesmin | 0:7e575e5f88ec | 945 | stHeartBeatMsgRspHdr* pstRspHdr =(stHeartBeatMsgRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 946 | } |
lesmin | 0:7e575e5f88ec | 947 | else if(cMessageType == OPERATION_NOTIFICATION_REQ) |
lesmin | 0:7e575e5f88ec | 948 | { |
lesmin | 0:7e575e5f88ec | 949 | stNotificationReqHdr* pstRspHdr =(stNotificationReqHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 950 | } |
lesmin | 0:7e575e5f88ec | 951 | else if(cMessageType == OPERATION_NOTIFICATION_RSP) |
lesmin | 0:7e575e5f88ec | 952 | { |
lesmin | 0:7e575e5f88ec | 953 | stNotificationRspHdr* pstRspHdr =(stNotificationRspHdr*) pBody; |
lesmin | 0:7e575e5f88ec | 954 | } |
lesmin | 0:7e575e5f88ec | 955 | |
lesmin | 0:7e575e5f88ec | 956 | return GMMP_SUCCESS; |
lesmin | 0:7e575e5f88ec | 957 | } |