Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of GMMP_mbed by
GMMP_Operation.cpp
00001 /** 00002 * @file GMMP_Operation.cpp 00003 * @date 2015/07/20 00004 * @version 0.0.1.0 00005 **/ 00006 00007 /* 00008 #include <stdio.h> 00009 #include <stdlib.h> 00010 #include <string.h> 00011 #include <time.h> 00012 #include <signal.h> 00013 #include <pthread.h> 00014 #include <unistd.h> 00015 #include <stdarg.h> 00016 */ 00017 #include <time.h> 00018 00019 #include "GMMP_Operation.h" 00020 00021 long g_nTID = 0; 00022 int g_bLog = false; 00023 00024 int g_nErrorLevel = GMMP_ERROR_LEVEL_ERROR; 00025 00026 00027 //GW/Device 등록/해지 Request 00028 int GMMP_SetReg(const char* pszAuthID, 00029 const char* pszAuthKey, 00030 const char* pszDomainCode, 00031 const char* pszGWID, 00032 const char* pszManufactureID) 00033 { 00034 debugln("GMMP_SetReg()"); 00035 00036 int nRet = GMMP_SUCCESS; 00037 00038 if(pszGWID == NULL) { 00039 GwRegist_Req stRegist_Req; 00040 memset(&stRegist_Req, 0 ,sizeof(stRegist_Req)); 00041 00042 nRet = SetHeader ((void*)&stRegist_Req, sizeof(stRegist_Req), 1, 1, OPERATION_GW_REG_REQ, pszAuthID, NULL); 00043 if(nRet != GMMP_SUCCESS) { 00044 return nRet; 00045 } 00046 00047 memcpy(stRegist_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); 00048 memcpy(stRegist_Req.body.usManufactureID, pszManufactureID, strlen(pszManufactureID)); 00049 00050 GMMP_Trace (&stRegist_Req.header, &stRegist_Req.body); 00051 00052 nRet = GMMP_GW_Reg_Req((GwRegist_Req*)&stRegist_Req); 00053 00054 } 00055 else 00056 { 00057 /* 00058 if(pszAuthKey == NULL || strlen(pszAuthKey) > LEN_AUTH_KEY || strlen(pszGWID) > LEN_GW_ID) 00059 { 00060 return LIB_PARAM_ERROR; 00061 } 00062 */ 00063 00064 DeviceRegist_Req stRegist_Req; 00065 00066 memset(&stRegist_Req, 0 ,sizeof(stRegist_Req)); 00067 00068 nRet = SetHeader ((void*)&stRegist_Req, sizeof(stRegist_Req), 1, 1, OPERATION_DEVICE_REG_REQ, pszAuthID, pszAuthKey); 00069 if(nRet != GMMP_SUCCESS) 00070 { 00071 return nRet; 00072 } 00073 00074 memcpy(stRegist_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); 00075 memcpy(stRegist_Req.body.usGWID, pszGWID, strlen(pszGWID)); 00076 memcpy(stRegist_Req.body.usManufactureID, pszManufactureID, strlen(pszManufactureID)); 00077 00078 GMMP_Trace (&stRegist_Req.header, &stRegist_Req.body); 00079 00080 nRet = GMMP_Device_Reg_Req((DeviceRegist_Req*)&stRegist_Req); 00081 } 00082 00083 return nRet; 00084 } 00085 00086 int GMMP_SetDeReg (const char* pszAuthID, 00087 const char* pszAuthKey, 00088 const char* pszDomainCode, 00089 const char* pszGWID, 00090 const char* pszDeviceID) 00091 { 00092 /* 00093 if(pszAuthID == NULL 00094 || pszAuthKey == NULL 00095 || pszDomainCode == NULL 00096 || pszGWID == NULL 00097 || strlen(pszAuthID) > LEN_AUTH_ID 00098 || strlen(pszAuthKey) > LEN_AUTH_KEY 00099 || strlen(pszDomainCode) > LEN_DOMAIN_CODE 00100 || strlen(pszGWID) > LEN_GW_ID) 00101 { 00102 return LIB_PARAM_ERROR; 00103 } 00104 */ 00105 00106 int nRet = GMMP_SUCCESS; 00107 00108 if(pszDeviceID == NULL) //GW DeReg 00109 { 00110 GwDeRegist_Req stDeRegist_Req; 00111 memset(&stDeRegist_Req, 0 ,sizeof(stDeRegist_Req)); 00112 00113 nRet = SetHeader ((void*)&stDeRegist_Req, sizeof(stDeRegist_Req), 1, 1, OPERATION_GW_DEREG_REQ, pszAuthID, pszAuthKey); 00114 if(nRet != GMMP_SUCCESS) 00115 { 00116 return nRet; 00117 } 00118 00119 memcpy(stDeRegist_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); 00120 memcpy(stDeRegist_Req.body.usGWID, pszGWID, strlen(pszGWID)); 00121 00122 GMMP_Trace (&stDeRegist_Req.header, &stDeRegist_Req.body); 00123 00124 nRet = GMMP_GW_DeReg_Req((GwDeRegist_Req*)&stDeRegist_Req); 00125 } 00126 else 00127 { 00128 DeviceDeRegist_Req stDeviceDeRegist_Req; 00129 00130 memset(&stDeviceDeRegist_Req, 0 ,sizeof(stDeviceDeRegist_Req)); 00131 00132 nRet = SetHeader ((void*)&stDeviceDeRegist_Req, sizeof(stDeviceDeRegist_Req), 1, 1, OPERATION_DEVICE_DEREG_REQ, pszAuthID, pszAuthKey); 00133 if(nRet != GMMP_SUCCESS) 00134 { 00135 return nRet; 00136 } 00137 00138 memcpy(stDeviceDeRegist_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); 00139 memcpy(stDeviceDeRegist_Req.body.usGWID, pszGWID, strlen(pszGWID)); 00140 memcpy(stDeviceDeRegist_Req.body.usDeviceID, pszDeviceID, strlen(pszDeviceID)); 00141 00142 GMMP_Trace (&stDeviceDeRegist_Req.header, &stDeviceDeRegist_Req.body); 00143 00144 nRet = GMMP_Device_DeReg_Req((DeviceDeRegist_Req*)&stDeviceDeRegist_Req); 00145 } 00146 00147 return nRet; 00148 } 00149 00150 //Profile Info Request 00151 int GMMP_SetProfile (const char* pszAuthID, const char* pszAuthKey, const char* pszDomainCode, const char* pszGWID, const char* pszDeviceID) 00152 { 00153 /* 00154 if(pszAuthID == NULL 00155 || pszAuthKey == NULL 00156 || pszDomainCode == NULL 00157 || pszGWID ==NULL 00158 || strlen(pszAuthID) > LEN_AUTH_ID 00159 || strlen(pszAuthKey) > LEN_AUTH_KEY 00160 || strlen(pszDomainCode) > LEN_DOMAIN_CODE 00161 || strlen(pszGWID) > LEN_GW_ID) 00162 { 00163 return LIB_PARAM_ERROR; 00164 } 00165 */ 00166 00167 int nRet = GMMP_SUCCESS; 00168 00169 Profile_Req stProfile_Req; 00170 00171 memset(&stProfile_Req, 0 ,sizeof(stProfile_Req)); 00172 00173 nRet = SetHeader ((void*)&stProfile_Req, sizeof(stProfile_Req), 1, 1, OPERATION_PROFILE_REQ, pszAuthID, pszAuthKey); 00174 if(nRet != GMMP_SUCCESS) 00175 { 00176 return nRet; 00177 } 00178 00179 memcpy(stProfile_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); 00180 memcpy(stProfile_Req.body.usGWID, pszGWID, strlen(pszGWID)); 00181 00182 if(pszDeviceID != NULL) //Device 판단 00183 { 00184 if(strlen(pszDeviceID) > LEN_DEVICE_ID) //Device ID 길이 확인 00185 { 00186 } 00187 else 00188 { 00189 memcpy(stProfile_Req.body.usDeviceID, pszDeviceID, strlen(pszDeviceID)); 00190 } 00191 } 00192 00193 GMMP_Trace (&stProfile_Req.header, &stProfile_Req.body); 00194 00195 nRet = GMMP_Profile_Req(&stProfile_Req); 00196 00197 return nRet; 00198 } 00199 00200 //수집 데이터 보고 Request 00201 int GMMP_SetDelivery (const char* pszAuthID, 00202 const char* pszAuthKey, 00203 const char* pszDomainCode, 00204 const char* pszGWID, 00205 const char* pszDeviceID, 00206 const char cReportType, 00207 const char cMediaType, 00208 const char* pszMessageBody, 00209 const int nTotalCount, 00210 const int nCurrentCount) 00211 { 00212 /* 00213 if(pszAuthID == NULL 00214 || pszAuthKey == NULL 00215 || pszDomainCode == NULL 00216 || pszGWID == NULL 00217 || strlen(pszAuthID) > LEN_AUTH_ID 00218 || strlen(pszAuthKey) > LEN_AUTH_KEY 00219 || strlen(pszDomainCode) > LEN_DOMAIN_CODE 00220 || strlen(pszGWID) > LEN_GW_ID 00221 || cReportType < 0x00 00222 || cReportType > 0x04 00223 || cMediaType < 0x01 00224 || pszMessageBody == NULL 00225 || strlen(pszMessageBody) > MAX_MSG_BODY) 00226 { 00227 return LIB_PARAM_ERROR; 00228 } 00229 */ 00230 00231 int nMessageBodyLen = strlen(pszMessageBody); 00232 00233 //debug("msgBodyLen = "); 00234 //debugln(nMessageBodyLen); 00235 DBG("msgBodyLen = %d", nMessageBodyLen); 00236 00237 int nRet = GMMP_SUCCESS; 00238 00239 Delivery_Req stDelivery_Req; 00240 00241 //debug(F("ReqSize = ")); 00242 //debugln(sizeof(stDelivery_Req)); 00243 DBG("ReqSize = %d", sizeof(stDelivery_Req)); 00244 00245 memset(&stDelivery_Req, 0, sizeof(stDelivery_Req)); 00246 00247 int PacketSize = sizeof(stDelivery_Req) - MAX_MSG_BODY + nMessageBodyLen ; //Message Body의 속성은 Optinal이다 00248 00249 // debug(F("pacektSize = ")); 00250 // debugln(PacketSize); 00251 DBG("packetSize = %d", PacketSize); 00252 00253 nRet = SetHeader ((void*)&stDelivery_Req, PacketSize, nTotalCount, nCurrentCount, OPERATION_DELIVERY_REQ, pszAuthID, pszAuthKey); 00254 if(nRet != GMMP_SUCCESS) 00255 { 00256 return nRet; 00257 } 00258 00259 memcpy(stDelivery_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); 00260 memcpy(stDelivery_Req.body.usGWID, pszGWID, strlen(pszGWID)); 00261 00262 if(pszDeviceID != NULL) //Device 판단 00263 { 00264 if(strlen(pszDeviceID) > LEN_DEVICE_ID) //Device ID 길이 확인 00265 { 00266 } 00267 else 00268 { 00269 memcpy(stDelivery_Req.body.usDeviceID, pszDeviceID, strlen(pszDeviceID)); 00270 } 00271 } 00272 00273 stDelivery_Req.body.ucReportType = cReportType; 00274 stDelivery_Req.body.ucMediaType = cMediaType; 00275 00276 if(nMessageBodyLen > 0) 00277 { 00278 memcpy(stDelivery_Req.body.usMessageBody, pszMessageBody, nMessageBodyLen); 00279 } 00280 00281 GMMP_Trace (&stDelivery_Req.header, &stDelivery_Req.body); 00282 00283 nRet = GMMP_Delivery_Req(&stDelivery_Req, PacketSize); 00284 00285 return nRet; 00286 } 00287 00288 //제어 수신 기능은 Thread에서 처리 00289 //제어 수신 보고 Response 00290 int GMMP_SetControl (const char* pszAuthID, const char* pszAuthKey, const char* pszDomainCode, const char* pszGWID, const char* pszDeviceID, const char cControlType, const char cResultCode) 00291 { 00292 /* 00293 if(pszAuthID == NULL 00294 || pszAuthKey == NULL 00295 || pszDomainCode == NULL 00296 || pszGWID ==NULL 00297 || strlen(pszAuthID) > LEN_AUTH_ID 00298 || strlen(pszAuthKey) > LEN_AUTH_KEY 00299 || strlen(pszDomainCode) > LEN_DOMAIN_CODE 00300 || strlen(pszGWID) > LEN_GW_ID) 00301 { 00302 return LIB_PARAM_ERROR; 00303 } 00304 */ 00305 00306 int nRet = GMMP_SUCCESS; 00307 00308 Control_Rsp stControl_Rsp; 00309 00310 memset(&stControl_Rsp, 0 ,sizeof(stControl_Rsp)); 00311 00312 nRet = SetHeader ((void*)&stControl_Rsp, sizeof(stControl_Rsp), 1, 1, OPERATION_CONTROL_RSP, pszAuthID, pszAuthKey); 00313 if(nRet != GMMP_SUCCESS) 00314 { 00315 return nRet; 00316 } 00317 00318 memcpy(stControl_Rsp.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); 00319 memcpy(stControl_Rsp.body.usGWID, pszGWID, strlen(pszGWID)); 00320 00321 if(pszDeviceID != NULL) //Device 판단 00322 { 00323 if(strlen(pszDeviceID) > LEN_DEVICE_ID) //Device ID 길이 확인 00324 { 00325 } 00326 else 00327 { 00328 memcpy(stControl_Rsp.body.usDeviceID, pszDeviceID, strlen(pszDeviceID)); 00329 } 00330 } 00331 00332 stControl_Rsp.body.ucControlType = cControlType; 00333 stControl_Rsp.body.ucResultCode = cResultCode; 00334 00335 GMMP_Trace (&stControl_Rsp.header, &stControl_Rsp.body); 00336 00337 nRet = GMMP_Control_Rsp(&stControl_Rsp); 00338 00339 return nRet; 00340 } 00341 00342 //제어 동작 완료 결과 보고 Request 00343 int GMMP_SetNotifi (const char* pszAuthID, 00344 const char* pszAuthKey, 00345 const char* pszDomainCode, 00346 const char* pszGWID, 00347 const char* pszDeviceID, 00348 const char cControlType, 00349 const char cResultCode, 00350 const char* pszMessageBody, 00351 const int nMessageSize) 00352 { 00353 /* 00354 if(pszAuthID == NULL 00355 || pszAuthKey == NULL 00356 || pszDomainCode == NULL 00357 || pszGWID ==NULL 00358 || strlen(pszAuthID) > LEN_AUTH_ID 00359 || strlen(pszAuthKey) > LEN_AUTH_KEY 00360 || strlen(pszDomainCode) > LEN_DOMAIN_CODE 00361 || strlen(pszGWID) > LEN_GW_ID) 00362 { 00363 return LIB_PARAM_ERROR; 00364 } 00365 */ 00366 00367 int nRet = GMMP_SUCCESS; 00368 00369 Notifi_Req stNotifi_Req; 00370 00371 memset(&stNotifi_Req, 0 ,sizeof(stNotifi_Req)); 00372 00373 int PacketSize =sizeof(stNotifi_Req) - MAX_MSG_BODY + nMessageSize ; //Message Body의 속성은 Optinal이다 00374 00375 nRet = SetHeader ((void*)&stNotifi_Req, PacketSize, 1, 1, OPERATION_NOTIFICATION_REQ, pszAuthID, pszAuthKey); 00376 if(nRet != GMMP_SUCCESS) 00377 { 00378 return nRet; 00379 } 00380 00381 memcpy(stNotifi_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); 00382 memcpy(stNotifi_Req.body.usGWID, pszGWID, strlen(pszGWID)); 00383 00384 if(pszDeviceID != NULL) //Device 판단 00385 { 00386 if(strlen(pszDeviceID) > LEN_DEVICE_ID) //Device ID 길이 확인 00387 { 00388 } 00389 else 00390 { 00391 memcpy(stNotifi_Req.body.usDeviceID, pszDeviceID, strlen(pszDeviceID)); 00392 } 00393 } 00394 00395 stNotifi_Req.body.ucControlType = cControlType; 00396 stNotifi_Req.body.ucResultCode = cResultCode; 00397 00398 if(pszMessageBody != NULL) //Message 사용 판단 00399 { 00400 if(nMessageSize > MAX_MSG_BODY) 00401 { 00402 } 00403 else 00404 { 00405 memcpy(stNotifi_Req.body.usMessageBody, pszMessageBody, nMessageSize); 00406 } 00407 } 00408 00409 GMMP_Trace (&stNotifi_Req.header, &stNotifi_Req.body); 00410 00411 nRet = GMMP_Notifi_Req(&stNotifi_Req, PacketSize); 00412 00413 return nRet; 00414 } 00415 00416 int GMMP_SetHB (const char* pszAuthID, 00417 const char* pszAuthKey, 00418 const char* pszDomainCode, 00419 const char* pszGWID) 00420 { 00421 /* 00422 if(pszAuthID == NULL 00423 || pszAuthKey == NULL 00424 || pszDomainCode == NULL 00425 || pszGWID ==NULL 00426 || strlen(pszAuthID) > LEN_AUTH_ID 00427 || strlen(pszAuthKey) > LEN_AUTH_KEY 00428 || strlen(pszDomainCode) > LEN_DOMAIN_CODE 00429 || strlen(pszGWID) > LEN_GW_ID) 00430 { 00431 return LIB_PARAM_ERROR; 00432 } 00433 */ 00434 00435 int nRet = GMMP_SUCCESS; 00436 00437 HB_Req stHB_Req; 00438 00439 memset(&stHB_Req, 0 ,sizeof(stHB_Req)); 00440 00441 nRet = SetHeader ((void*)&stHB_Req, sizeof(stHB_Req), 1, 1, OPERATION_HEARTBEAT_REQ, pszAuthID, pszAuthKey); 00442 if(nRet != GMMP_SUCCESS) 00443 { 00444 return nRet; 00445 } 00446 00447 memcpy(stHB_Req.body.usDomainCode, pszDomainCode, strlen(pszDomainCode)); 00448 memcpy(stHB_Req.body.usGWID, pszGWID, strlen(pszGWID)); 00449 00450 GMMP_Trace (&stHB_Req.header, &stHB_Req.body); 00451 00452 nRet = GMMP_Heartbeat_Req(&stHB_Req); 00453 00454 return nRet; 00455 } 00456 00457 //GW/Device 등록/해지 Response 00458 int GMMP_GetReg (GwRegist_Rsp* pstGwRegist_Rsp, DeviceRegist_Rsp* pstDeviceRegist_Rsp) 00459 { 00460 int nRet = GMMP_SUCCESS; 00461 00462 if(pstGwRegist_Rsp != NULL) 00463 { 00464 nRet = GMMP_GW_Reg_Rsp(pstGwRegist_Rsp); 00465 GMMP_Trace (&pstGwRegist_Rsp->header, &pstGwRegist_Rsp->body); 00466 } 00467 else 00468 { 00469 nRet = GMMP_Device_Reg_Rsp(pstDeviceRegist_Rsp); 00470 GMMP_Trace (&pstDeviceRegist_Rsp->header, &pstDeviceRegist_Rsp->body); 00471 } 00472 00473 CloseSocket(); 00474 00475 return nRet; 00476 } 00477 00478 int GMMP_GetDeReg (GwDeRegist_Rsp* pstGwRegist_Rsp, DeviceDeRegist_Rsp* pstDeviceDeRegist_Rsp) 00479 { 00480 int nRet = GMMP_SUCCESS; 00481 00482 if(pstGwRegist_Rsp != NULL) 00483 { 00484 nRet = GMMP_GW_DeReg_Rsp(pstGwRegist_Rsp); 00485 GMMP_Trace (&pstGwRegist_Rsp->header, &pstGwRegist_Rsp->body); 00486 } 00487 else 00488 { 00489 nRet = GMMP_Device_DeReg_Rsp(pstDeviceDeRegist_Rsp); 00490 GMMP_Trace (&pstDeviceDeRegist_Rsp->header, &pstDeviceDeRegist_Rsp->body); 00491 } 00492 00493 CloseSocket(); 00494 00495 return nRet; 00496 } 00497 00498 //Profile Info Response 00499 int GMMP_GetProfile (Profile_Rsp* pstProfile_Rsp) 00500 { 00501 int nRet = GMMP_Profile_Rsp(pstProfile_Rsp); 00502 00503 GMMP_Trace (&pstProfile_Rsp->header, &pstProfile_Rsp->body); 00504 00505 CloseSocket(); 00506 00507 return nRet; 00508 } 00509 00510 //수집 데이터 보고 Response 00511 int GMMP_GetDelivery (Delivery_Rsp* pstDelivery_Rsp) 00512 { 00513 int nRet = GMMP_Delivery_Rsp(pstDelivery_Rsp); 00514 00515 GMMP_Trace (&pstDelivery_Rsp->header, &pstDelivery_Rsp->body); 00516 00517 CloseSocket(); 00518 00519 return nRet; 00520 } 00521 //제어 동작 완료 결과 보고 Response 00522 int GMMP_GetNotifi (Notifi_Rsp* pstNotifi_Rsp) 00523 { 00524 int nRet = GMMP_Notifi_Rsp(pstNotifi_Rsp); 00525 00526 GMMP_Trace (&pstNotifi_Rsp->header, &pstNotifi_Rsp->body); 00527 00528 CloseSocket(); 00529 00530 return nRet; 00531 } 00532 00533 int GMMP_GetHB (HB_Rsp* pstHB_Rsp) //TCP Always ON 모드일 경우 (Thread 생성) 사용 TCP Disconnect하지 않음 00534 { 00535 int nRet = GMMP_Heartbeat_Rsp(pstHB_Rsp); 00536 00537 GMMP_Trace (&pstHB_Rsp->header, &pstHB_Rsp->body); 00538 00539 return nRet; 00540 } 00541 00542 int GMMP_Read (GMMPHeader* pstGMMPHeader, void** pBody) 00543 { 00544 return GMMP_Read2(pstGMMPHeader, pBody, 1); 00545 } 00546 00547 int GMMP_Read2(GMMPHeader* pstGMMPHeader, void** pBody, byte blocking) 00548 { 00549 ConvertShort cvtShort; 00550 //ConvertInt cvtint; 00551 00552 int nRet = 0; 00553 int nHeaderSize = sizeof(GMMPHeader); 00554 00555 memset(pstGMMPHeader, 0, nHeaderSize); 00556 00557 cvtShort.sU8 = 0; 00558 //cvtint.sU8 = 0; 00559 00560 nRet = 0; 00561 00562 nRet = ReadTCP2((char*)pstGMMPHeader, nHeaderSize, blocking); 00563 if (nRet != GMMP_SUCCESS) 00564 { 00565 return nRet; 00566 } 00567 00568 memcpy(cvtShort.usShort, pstGMMPHeader->usMessageLength, sizeof(pstGMMPHeader->usMessageLength)); 00569 cvtShort.sU8 = btols(cvtShort.sU8); 00570 00571 if (cvtShort.sU8 < nHeaderSize) 00572 { 00573 return GMMP_HEADER_SIZE_ERROR; 00574 } 00575 00576 int nBodySize = 0; 00577 00578 if ((*pBody = MallocBody (pstGMMPHeader->ucMessageType, &nBodySize))== NULL || nBodySize <= 0) 00579 { 00580 return GMMP_MALLOC_ERROR; 00581 } 00582 00583 memset(*pBody, 0, nBodySize); 00584 00585 int ReadPacketSize = cvtShort.sU8 - nHeaderSize; 00586 00587 nRet = ReadTCP2((char*)(*pBody), ReadPacketSize, blocking); 00588 if(nRet != GMMP_SUCCESS) 00589 { 00590 CloseSocket(); 00591 00592 return nRet; 00593 } 00594 00595 return GMMP_SUCCESS; 00596 } 00597 00598 int GMMP_Recv (GMMPHeader* pstGMMPHeader, void* pBody) 00599 { 00600 GMMP_Trace (pstGMMPHeader, pBody); 00601 00602 char cMessageType = pstGMMPHeader->ucMessageType ; 00603 00604 if(cMessageType == OPERATION_GW_REG_RSP) 00605 { 00606 stGwRegistrationRspHdr* pstRspHdr =(stGwRegistrationRspHdr*) pBody; 00607 OG_Reg_Recv(pstGMMPHeader, pstRspHdr, NULL); 00608 } 00609 else if(cMessageType == OPERATION_GW_DEREG_RSP) 00610 { 00611 stGwDeRegistrationRspHdr* pstRspHdr =(stGwDeRegistrationRspHdr*) pBody; 00612 OG_DeReg_Recv(pstGMMPHeader, pstRspHdr, NULL); 00613 } 00614 else if(cMessageType == OPERATION_PROFILE_RSP) 00615 { 00616 stProfileRspHdr* pstRspHdr =(stProfileRspHdr*) pBody; 00617 OG_Profile_Recv(pstGMMPHeader, pstRspHdr); 00618 } 00619 else if(cMessageType == OPERATION_DEVICE_REG_RSP) 00620 { 00621 stDeviceRegistrationRspHdr* pstRspHdr =(stDeviceRegistrationRspHdr*) pBody; 00622 OG_Reg_Recv(pstGMMPHeader, NULL, pstRspHdr); 00623 } 00624 else if(cMessageType == OPERATION_DEVICE_DEREG_RSP) 00625 { 00626 stDeviceDeRegistrationRspHdr* pstRspHdr =(stDeviceDeRegistrationRspHdr*) pBody; 00627 OG_DeReg_Recv(pstGMMPHeader, NULL, pstRspHdr); 00628 } 00629 else if(cMessageType == OPERATION_DELIVERY_RSP) 00630 { 00631 stPacketDeliveryRspHdr* pstRspHdr =(stPacketDeliveryRspHdr*) pBody; 00632 OG_Delivery_Recv(pstGMMPHeader, pstRspHdr); 00633 } 00634 else if(cMessageType == OPERATION_CONTROL_REQ) 00635 { 00636 stControlReqHdr* pstReqHdr =(stControlReqHdr*) pBody; 00637 GMMP_Ctrl_Recv (pstGMMPHeader, pstReqHdr); 00638 } 00639 else if(cMessageType == OPERATION_HEARTBEAT_RSP) 00640 { 00641 stHeartBeatMsgRspHdr* pstRspHdr =(stHeartBeatMsgRspHdr*) pBody; 00642 OG_HB_Recv(pstGMMPHeader, pstRspHdr); 00643 } 00644 else if(cMessageType == OPERATION_NOTIFICATION_RSP) 00645 { 00646 stNotificationRspHdr* pstRspHdr =(stNotificationRspHdr*) pBody; 00647 OG_Notifi_Recv(pstGMMPHeader, pstRspHdr); 00648 } 00649 00650 return GMMP_SUCCESS; 00651 } 00652 00653 int GMMP_Ctrl_Recv (GMMPHeader* pstGMMPHeader, stControlReqHdr* pstReqHdr) 00654 { 00655 char cControlType = pstReqHdr->ucControlType; 00656 00657 //단순 제어 명령어인 경우 00658 switch(cControlType) 00659 { 00660 case CONTROL_Reset: 00661 break; 00662 case CONTROL_Turn_Off: 00663 break; 00664 case CONTROL_Report_On: 00665 break; 00666 case CONTROL_Report_Off: 00667 break; 00668 case CONTROL_Time_Sync: 00669 break; 00670 case CONTROL_Pause: 00671 break; 00672 case CONTROL_Restart: 00673 break; 00674 case CONTROL_Signal_Power_Check: 00675 break; 00676 case CONTROL_Diagnostic: 00677 break; 00678 case CONTROL_Reserved: 00679 break; 00680 case CONTROL_Profile_Reset: 00681 break; 00682 case CONTROL_Status_Check: 00683 break; 00684 case CONTROL_FW_Download: //FTP 연결 00685 break; 00686 case CONTROL_FW_Update: 00687 break; 00688 case CONTROL_App_Download: //FTP 연결 00689 break; 00690 case CONTROL_App_Update: 00691 break; 00692 case CONTROL_Remote_Access: //Remote Info 연결 00693 break; 00694 case CONTROL_Multimedia_Control_Start: //Multimedia URL Info 연결 00695 break; 00696 case CONTROL_Multimedia_Control_Pause: 00697 break; 00698 case CONTROL_Multimedia_Control_Stop: 00699 break; 00700 case CONTROL_Multimedia_Control_Restart: 00701 break; 00702 default: 00703 break; 00704 } 00705 00706 OG_Ctrl_Recv(pstGMMPHeader, pstReqHdr); 00707 00708 return 1; 00709 } 00710 00711 void SetTID (long nTid) 00712 { 00713 g_nTID = nTid; 00714 } 00715 00716 long GetTID () 00717 { 00718 return g_nTID; 00719 } 00720 00721 //protected 00722 int SetHeader (void* pData, 00723 int nPacketSize, 00724 int nTotalCount, 00725 int nCurrentCount, 00726 const char cMessageType, 00727 const char* pszAuthID, 00728 const char* pszAuthKey) 00729 { 00730 GMMPHeader* pHeader = (GMMPHeader*)pData; 00731 ConvertShort cvtShort; 00732 00733 // debug(F("authID len = ")); 00734 // debugln(strlen(pszAuthID)); 00735 DBG("authID len = %d", strlen(pszAuthID)); 00736 00737 memset(pHeader, 0, sizeof(GMMPHeader)); 00738 memset(cvtShort.usShort, 0, sizeof(cvtShort.usShort)); 00739 00740 pHeader->ucVersion = GMMP_VERSION; 00741 00742 ConvertInt cvtInt; 00743 00744 time_t t; time ( &t ); 00745 00746 // debug(F("TIME = ")); 00747 // debugln(t); 00748 DBG("TIME = %d", t); 00749 00750 memcpy(cvtInt.usInt, &t, sizeof(cvtInt.usInt)); 00751 00752 cvtInt.sU8 = ltobi(cvtInt.sU8); 00753 00754 memcpy(&pHeader->unOriginTimeStamp, &cvtInt.usInt, sizeof(cvtInt.usInt)); 00755 memcpy(&pHeader->usAuthID, pszAuthID, strlen(pszAuthID)); 00756 00757 if(pszAuthKey != NULL) 00758 { 00759 memcpy(&pHeader->usAuthKey, pszAuthKey, strlen(pszAuthKey)); 00760 } 00761 00762 // debug(F("TID = ")); 00763 // debugln(g_nTID); 00764 DBG("TID = %ld", g_nTID); 00765 00766 memcpy(&cvtInt.usInt, &g_nTID, sizeof(g_nTID)); 00767 cvtInt.sU8 = ltobi(cvtInt.sU8); 00768 00769 memcpy(pHeader->usTID, &cvtInt.usInt, sizeof(pHeader->usTID)); 00770 00771 cvtShort.sU8 = ltobs((short)nPacketSize); 00772 memcpy(pHeader->usMessageLength, cvtShort.usShort, sizeof(cvtShort.usShort)); 00773 00774 cvtShort.sU8 = ltobs((short)nTotalCount); 00775 memcpy(pHeader->usTotalCount, cvtShort.usShort, sizeof(cvtShort.usShort)); 00776 00777 cvtShort.sU8 = ltobs((short)nCurrentCount); 00778 memcpy(pHeader->usCurrentCount, cvtShort.usShort, sizeof(cvtShort.usShort)); 00779 00780 pHeader->ucMessageType = cMessageType; 00781 00782 return GMMP_SUCCESS; 00783 } 00784 00785 int SetIntiSocket (void) 00786 { 00787 return Connect(); 00788 } 00789 00790 char* MallocBody (const char Type, int* nBodySize) 00791 { 00792 char* pBuffer = NULL; 00793 00794 switch(Type) 00795 { 00796 case OPERATION_GW_REG_RSP: 00797 { 00798 pBuffer = (char*)malloc(sizeof(stGwRegistrationRspHdr)); 00799 *nBodySize = sizeof(stGwRegistrationRspHdr); 00800 break; 00801 } 00802 case OPERATION_GW_DEREG_RSP: 00803 { 00804 pBuffer = (char*)malloc(sizeof(stGwDeRegistrationRspHdr)); 00805 *nBodySize = sizeof(stGwDeRegistrationRspHdr); 00806 break; 00807 } 00808 case OPERATION_PROFILE_RSP: 00809 { 00810 pBuffer = (char*)malloc(sizeof(stProfileRspHdr)); 00811 *nBodySize = sizeof(stProfileRspHdr); 00812 break; 00813 } 00814 case OPERATION_DEVICE_REG_RSP: 00815 { 00816 pBuffer = (char*)malloc(sizeof(stDeviceRegistrationRspHdr)); 00817 *nBodySize = sizeof(stDeviceRegistrationRspHdr); 00818 break; 00819 } 00820 case OPERATION_DEVICE_DEREG_RSP: 00821 { 00822 pBuffer = (char*)malloc(sizeof(stDeviceDeRegistrationRspHdr)); 00823 *nBodySize = sizeof(stDeviceDeRegistrationRspHdr); 00824 break; 00825 } 00826 case OPERATION_DELIVERY_RSP: 00827 { 00828 pBuffer = (char*)malloc(sizeof(stPacketDeliveryRspHdr)); 00829 *nBodySize = sizeof(stPacketDeliveryRspHdr); 00830 break; 00831 } 00832 case OPERATION_CONTROL_REQ: 00833 { 00834 pBuffer = (char*)malloc(sizeof(stControlReqHdr)); 00835 *nBodySize = sizeof(stControlReqHdr); 00836 break; 00837 } 00838 case OPERATION_HEARTBEAT_RSP: 00839 { 00840 pBuffer = (char*)malloc(sizeof(stHeartBeatMsgRspHdr)); 00841 *nBodySize = sizeof(stHeartBeatMsgRspHdr); 00842 break; 00843 } 00844 case OPERATION_NOTIFICATION_RSP: 00845 { 00846 pBuffer = (char*)malloc(sizeof(stNotificationRspHdr)); 00847 *nBodySize = sizeof(stNotificationRspHdr); 00848 break; 00849 } 00850 default: 00851 { 00852 nBodySize = 0; 00853 } 00854 } 00855 00856 return pBuffer; 00857 } 00858 00859 int GMMP_Trace (GMMPHeader* pstGMMPHeader, void* pBody) 00860 { 00861 ConvertInt cvtint; 00862 00863 char cMessageType = pstGMMPHeader->ucMessageType ; 00864 00865 memcpy(cvtint.usInt, pstGMMPHeader->usTID, sizeof(pstGMMPHeader->usTID)); 00866 cvtint.sU8 = btoli(cvtint.sU8); 00867 00868 if(cMessageType == OPERATION_GW_REG_REQ) 00869 { 00870 stGwRegistrationReqHdr* pstRspHdr =(stGwRegistrationReqHdr*) pBody; 00871 } 00872 else if(cMessageType == OPERATION_GW_REG_RSP) 00873 { 00874 stGwRegistrationRspHdr* pstRspHdr =(stGwRegistrationRspHdr*) pBody; 00875 } 00876 else if(cMessageType == OPERATION_GW_DEREG_REQ) 00877 { 00878 stGwDeRegistrationReqHdr* pstRspHdr =(stGwDeRegistrationReqHdr*) pBody; 00879 } 00880 else if(cMessageType == OPERATION_GW_DEREG_RSP) 00881 { 00882 stGwDeRegistrationRspHdr* pstRspHdr =(stGwDeRegistrationRspHdr*) pBody; 00883 } 00884 else if(cMessageType == OPERATION_PROFILE_REQ) 00885 { 00886 stProfileReqHdr* pstRspHdr =(stProfileReqHdr*) pBody; 00887 } 00888 else if(cMessageType == OPERATION_PROFILE_RSP) 00889 { 00890 stProfileRspHdr* pstRspHdr =(stProfileRspHdr*) pBody; 00891 00892 memcpy(cvtint.usInt, pstRspHdr->unHeartbeatPeriod, sizeof(pstRspHdr->unHeartbeatPeriod)); 00893 cvtint.sU8 = btoli(cvtint.sU8); 00894 00895 memcpy(cvtint.usInt, pstRspHdr->unReportPeriod, sizeof(pstRspHdr->unReportPeriod)); 00896 cvtint.sU8 = btoli(cvtint.sU8); 00897 00898 memcpy(cvtint.usInt, pstRspHdr->unReportOffset, sizeof(pstRspHdr->unReportOffset)); 00899 cvtint.sU8 = btoli(cvtint.sU8); 00900 00901 memcpy(cvtint.usInt, pstRspHdr->unResponseTimeout, sizeof(pstRspHdr->unResponseTimeout)); 00902 cvtint.sU8 = btoli(cvtint.sU8); 00903 } 00904 else if(cMessageType == OPERATION_DEVICE_REG_REQ) 00905 { 00906 stDeviceRegistrationReqHdr* pstRspHdr =(stDeviceRegistrationReqHdr*) pBody; 00907 } 00908 else if(cMessageType == OPERATION_DEVICE_REG_RSP) 00909 { 00910 stDeviceRegistrationRspHdr* pstRspHdr =(stDeviceRegistrationRspHdr*) pBody; 00911 } 00912 else if(cMessageType == OPERATION_DEVICE_DEREG_REQ) 00913 { 00914 stDeviceDeRegistrationReqHdr* pstRspHdr =(stDeviceDeRegistrationReqHdr*) pBody; 00915 } 00916 else if(cMessageType == OPERATION_DEVICE_DEREG_RSP) 00917 { 00918 stDeviceDeRegistrationRspHdr* pstRspHdr =(stDeviceDeRegistrationRspHdr*) pBody; 00919 } 00920 else if(cMessageType == OPERATION_DELIVERY_REQ) 00921 { 00922 stPacketDeliveryReqHdr* pstRspHdr =(stPacketDeliveryReqHdr*) pBody; 00923 } 00924 else if(cMessageType == OPERATION_DELIVERY_RSP) 00925 { 00926 stPacketDeliveryRspHdr* pstRspHdr =(stPacketDeliveryRspHdr*) pBody; 00927 00928 memcpy(cvtint.usInt, pstRspHdr->unBackOffTime, sizeof(pstRspHdr->unBackOffTime)); 00929 cvtint.sU8 = btoli(cvtint.sU8); 00930 } 00931 else if(cMessageType == OPERATION_CONTROL_REQ) 00932 { 00933 stControlReqHdr* pstReqHdr =(stControlReqHdr*) pBody; 00934 } 00935 else if(cMessageType == OPERATION_CONTROL_RSP) 00936 { 00937 stControlRspHdr* pstRspHdr =(stControlRspHdr*) pBody; 00938 } 00939 else if(cMessageType == OPERATION_HEARTBEAT_REQ) 00940 { 00941 stHeartBeatMsgRspHdr* pstRspHdr =(stHeartBeatMsgRspHdr*) pBody; 00942 } 00943 else if(cMessageType == OPERATION_HEARTBEAT_RSP) 00944 { 00945 stHeartBeatMsgRspHdr* pstRspHdr =(stHeartBeatMsgRspHdr*) pBody; 00946 } 00947 else if(cMessageType == OPERATION_NOTIFICATION_REQ) 00948 { 00949 stNotificationReqHdr* pstRspHdr =(stNotificationReqHdr*) pBody; 00950 } 00951 else if(cMessageType == OPERATION_NOTIFICATION_RSP) 00952 { 00953 stNotificationRspHdr* pstRspHdr =(stNotificationRspHdr*) pBody; 00954 } 00955 00956 return GMMP_SUCCESS; 00957 }
Generated on Wed Jul 13 2022 05:33:29 by
1.7.2
