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.
Dependents: ThingPlug_Ethernet_Example
Fork of GMMP_mbed by
GMMP.h
00001 /** 00002 * @mainpage GMMP (Global M2M Protocol) 개요 00003 * @brief GMMP는 M2M 단말과 개방형 M2M 플랫폼(OMP)사이의 TCP 기반 연동 규격으로서, 단말 등록/해지, 주기보고, 단말 제어 등의 기능을 수행하는 SKTelecom 내부 규격이다. 00004 * @brief M2M Portal Site : <a href="https://www.m2mportal.co.kr"> Mobius Portal </a> 00005 * @date 2015/07/20 00006 * @version 1.0 00007 * @file GMMP.h 00008 **/ 00009 00010 00011 #ifndef GMMP_H_ 00012 #define GMMP_H_ 00013 00014 #include "GMMP_Operation.h" 00015 00016 /** 00017 * @defgroup GMMP_Registration_Operation M2M GW/Device 등록 00018 *등록 절차는 현장에 설치된 M2M GW가 서비스 수행을 시작하기 위해서 최초로 수행해야 하는 절차이다.\n 00019 *1. GW 등록 절차\n 00020 (1) M2M GW는 M2M Portal을 통해 사전에 등록된 자기 자신의 AUTH_ID(MSISDN or MAC Address), Domain Code, Manufacture ID를 전송한다.\n 00021 (2) OMP는 M2M GW가 전송한 AUTH_ID(MSISDN or MAC Address), Manufacture ID 값이 정상인지 확인하고 이상이 없으면 M2M GW로 Auth Key, GW ID를 부여하여 응답 메시지를 전송한다.\n 00022 (3) OMP에서 M2M GW의 등록이 정상적으로 이루어지지 않으면 응답 메시지의 Result Code에 Fail Code 값을 포함하여 M2M GW로 전송한다.\n 00023 (4) 3회 이상 M2M GW의 등록이 정상적이지 않은 경우 M2M GW는 더 이상 등록 요청을 수행하지 않고 GW 장애 절차를 수행한다.(GMMP 규격 논외)\n 00024 (5) M2M GW의 등록이 정상적으로 수행되었으나 Profile 정보(주기보고의 주기정보 및 Heartbeat 주기정보 등)가 없는 경우에는 @ref GO_Profile을 수행한다.\n 00025 00026 NOTE :\n 00027 [사전 등록] M2M GW 등록 절차 수행을 위해서는 사전에 M2M 포털을 통해 등록 되어야 한다.\n 00028 [ID 등록] M2M GW의 Auth ID(MSISDN, MAC) 또는 Manufacture ID가 변경되었으나 M2M 포털을 통해 갱신 등록되지 않으면 M2M 단말 등록 절차는 Fail 처리 된다.\n 00029 [정상 등록] 등록 요청이 정상적으로 수행된 경우 더 이상 등록 절차를 수행 하지 않는다.\n 00030 [재 등록 요청] OMP 에 등록 과정을 수행한 단말에 대해서 전원을 껐다(Off) 켜(On)는 경우에는 재 등록을 수행할 필요가 없다. 단, 할당 받은 GW ID, Auth Key, Domain Code 등의 값이 유실되거나 삭제된 경우에는 재 등록 요청을 수행 할 수 있다.\n 00031 [할당 Field 사용] Auth Key 값은 GMMP Common Header의 Auth_key 필드에 설정되며, Domain Code, GW ID 값은 Message Type별 Field 정의영역 부분에 설정되어 반환 된다. 이후 모든 메시지에는 반드시 OMP에서 할당된 Auth Key, GW ID 값을 해당 메시지에 이용되어야 한다.\n 00032 [중복 등록 허용] 이미 등록되어 있는 M2M GW에 대해 재 등록 요청을 하는 경우에는 중복 등록이 허용이 된다. 이때 전달되는 Auth Key, GW ID 값은 이전의 등록절차에서 할당 되었던 동일한 값이 전달된다.\n 00033 [M2M GW Timeout] M2M GW에서 OMP로 Request 명령을 전송한 뒤 응답이 없는 경우 Timeout 처리를 수행한다. 이 값은 Profile 정보에 포함 되어 있으며, OMP의 제어 명령에 의해서 변경 될 수 있다. (Timeout은 default로 최소 30sec 이상으로 설정되어야 한다)\n 00034 00035 전송 패킷 : @ref Struct_Reg_GW.h, @ref Struct_Reg_Device.h 참조 00036 00037 * @ingroup GMMP_Registration_Operation 00038 * @{ 00039 */ 00040 00041 /** 00042 * 00043 *@brief GW,Device 등록 절차 진행 명령 함수, 옵션으로 암호화 진행 유무 Flag가 있다.\n 00044 등록 절차는 현장에 설치된 M2M GW가 서비스 수행을 시작하기 위해서 최초로 수행해야 하는 절차이다.\n 00045 등록 절차를 통해 GW ID, Device ID를 OMP로 부터 제공 받는다.\n 00046 *@warning GW 등록 절차가 진행되어야만 Device 등록 절차를 진행 할 수 있다.\n 00047 * @param pszGWID OMP에서 제공받은 GW ID, NULL이면 GW 등록, 아니면 Device 등록 절차를 진행한다.\n 00048 * @param pszManufactureID M2M GW,Device의 Manufacture ID이다.\n 00049 - AlphaNumeric : 문자,숫자 조합, 특수문자제외, SPACE 허용 안하며 빈자리는 0x00(NULL)로 채운다.\n 00050 Ex) 공장 제조 Serial No. : “AVB12132SET23DT”, “SKTSerial“\n 00051 * @return 성공 : GMMMP_SUCCESS, 실패 : @ref ErrorCode.h 참조 00052 * 00053 * @code GW/Device 등록 샘플 코드 (Sample_Registration 샘플 참조) 00054 00055 int GW_Reg() 00056 { 00057 int nRet = GMMP_SUCCESS; 00058 00059 nRet = GO_Reg(NULL, pszGWMFID, false); 00060 00061 if(nRet < 0) 00062 { 00063 printf("GW GO_Reg Error : %d\n", nRet); 00064 00065 return 1; 00066 } 00067 00068 return 0; 00069 } 00070 00071 int Device_Reg() 00072 { 00073 int nRet = GMMP_SUCCESS; 00074 00075 nRet = GO_Reg(GetGWID(), pszDeviceMFID, false); 00076 00077 if(nRet < 0) 00078 { 00079 printf("GW GO_Reg Error : %d\n", nRet); 00080 00081 return 1; 00082 } 00083 00084 return 0; 00085 } 00086 00087 int Init() 00088 { 00089 if(Initialize(szServerIP, nServerPort, pszDomainCode , pszGWAuthID, GMMP_ON_LOG, nErrorLevel, GMMP_NETWORK_ALYWAYS_OFF, "Log") != 0) 00090 { 00091 printf("Server Connect Error\n"); 00092 00093 return 1; 00094 } 00095 00096 SetCallFunction( (void*)Recv); 00097 00098 return 0; 00099 } 00100 00101 int main() 00102 { 00103 if(Init() != 0) 00104 { 00105 printf("Init Error"); 00106 return -1; 00107 } 00108 00109 if(GW_Reg() != 0) 00110 { 00111 printf("GW_Reg Error"); 00112 return -1; 00113 } 00114 00115 if(Device_Reg() != 0) 00116 { 00117 printf("Device_Reg Error"); 00118 return -1; 00119 } 00120 00121 return 0; 00122 00123 } 00124 @endcode 00125 */ 00126 00127 int GO_Reg(const char* pszGWID, 00128 const char* pszManufactureID); 00129 /** 00130 * @} 00131 */ 00132 00133 /** 00134 * @defgroup GMMP_DeRegistration_Operation M2M GW/Device 등록 해지 00135 *해지 절차는 M2M Device가 더 이상 서비스를 수행하지 않음을 OMP에 알리는 절차로서 Device ID값이 OMP에 반납된다.\n 00136 * GMMP_Device_DeRegistration_Request 메시지를 이용하여 해지 요청을 수행하고, \n 00137 * GMMP_Device_DeRegistration_Response 메시지를 통해 해지 결과를 받는다.\n 00138 * 현장에서 문제가 생기거나 또는 철거하는 경우 M2M 포털을 통해서 해지(DeRegistration)할 수 있다.\n 00139 * 이때 M2M GW가 DeRegistration 하는 경우 하위 Device 정보도 모두 해제 된다. 00140 00141 전송 패킷 : @ref Struct_DeReg_GW.h, @ref Struct_DeReg_Device.h 참조 00142 00143 * @ingroup GMMP_DeRegistration_Operation 00144 * @{ 00145 */ 00146 00147 /** 00148 *@brief GW,Device 해지 절차 진행 명령 함수 00149 *@brief 해지 절차는 등록 절차를 통해 OMP로 부터 제공 받은 GW ID, Device ID를 해지 한다. 00150 *@warning GW 등록 절차가 진행되어야만 Device 등록 절차를 진행 할 수 있다. GW 등록 해제 절차를 진행할 경우 하위 Device에 대해 자동 해지가 된다. 00151 *@warning OMP 연동을 통해 서비스를 재개하기 위해서는 다시 OMP를 통해 Auth Key, GW ID를 할당 받아야 한다. 00152 * @param pszGWID OMP로 제공 받은 GW ID값. 00153 * @param pszDeviceID OMP로 제공 받은 Device ID값. 00154 * @return 성공 : GMMMP_SUCCESS, 실패 : @ref ErrorCode.h 참조 00155 * 00156 * @code GW/Device 등록 해지 샘플 코드 (Sample_DeRegistration 샘플 참조) 샘플코드 참조 00157 * 00158 int GW_DeReg() 00159 { 00160 int nRet = GMMP_SUCCESS; 00161 00162 nRet = GO_DeReg(pszGWID, NULL); 00163 00164 if(nRet < 0) 00165 { 00166 printf("GW GO_Reg Error : %d\n", nRet); 00167 00168 return 1; 00169 } 00170 00171 return 0; 00172 } 00173 00174 int Device_DeReg() 00175 { 00176 int nRet = GMMP_SUCCESS; 00177 00178 nRet = GO_DeReg(GetGWID(), pszDeviceID); 00179 00180 if(nRet < 0) 00181 { 00182 printf("GW GO_Reg Error : %d\n", nRet); 00183 00184 return 1; 00185 } 00186 00187 return 0; 00188 } 00189 00190 int Init() 00191 { 00192 if(Initialize(szServerIP, nServerPort, pszDomainCode , pszGWAuthID, GMMP_ON_LOG, nErrorLevel, GMMP_NETWORK_ALYWAYS_OFF, "Log") != 0) 00193 { 00194 printf("Server Connect Error\n"); 00195 00196 return 1; 00197 } 00198 00199 SetCallFunction( (void*)Recv); 00200 SetAuthKey(pszAuthKey); 00201 SetGWID(pszGWID); 00202 00203 return 0; 00204 } 00205 00206 int main() 00207 { 00208 if(Init() != 0) 00209 { 00210 printf("Init Error"); 00211 return -1; 00212 } 00213 00214 if(GW_DeReg() != 0) 00215 { 00216 printf("GW_Reg Error"); 00217 return -1; 00218 } 00219 00220 if(Device_DeReg() != 0) 00221 { 00222 printf("Device_Reg Error"); 00223 return -1; 00224 } 00225 00226 return 0; 00227 00228 } 00229 @endcode 00230 */ 00231 int GO_DeReg(const char* pszGWID, 00232 const char* pszDeviceID); 00233 00234 /** 00235 * @} 00236 */ 00237 00238 /** 00239 * @defgroup GMMP_ProfileInfo_Operation M2M GW/Device Profile Info 00240 * 00241 M2M GW에 Profile 정보가 없는 경우에 또는 일부 존재 하지 않는 경우 OMP에 Profile 정보를 요청한다.\n 00242 Profile 정보가 미리 설정되어 있는 경우에는 Profile 요청 절차를 수행하지 않는다.\n 00243 M2M GW의 등록 절차 또는 M2M Device 등록 절차 이후에 수행될 수 있다. \n 00244 또한 OMP로부터 제어 명령(@ref GMMP_Control_Operation, Control Type @ref CONTROL_Profile_Reset)을 수신한 경우 Profile 정보 Operation을 수행한다. 00245 00246 전송 패킷 : @ref Struct_ProfileInfo.h 참조 00247 00248 * @ingroup GMMP_ProfileInfo_Operation 00249 * @{ 00250 */ 00251 /** 00252 * @param pszGWID OMP로 제공 받은 GW ID값. 00253 * @param pszDeviceID OMP로 제공 받은 Device ID값. 00254 * @param nTID T-ID는 M2M GW와 OMP 간의 트랜잭션을 구분하기 위한 값으로서 Request 요청하는 곳에서 할당하며 Response 받은 곳에서는 해당 T-ID 값을 그대로 반환한다.\n 00255 M2M GW와 OMP에서 T-ID 사용 범위는 다음과 같다.\n 00256 ※ M2M GW T-ID : 0 ~ 99,999 (10만개)\n 00257 ※ OMP T-ID : M2M GW가 사용 이외의 값\n 00258 * 00259 * @return 성공 : GMMMP_SUCCESS, 실패 : @ref ErrorCode.h 참조 00260 * @code GW/Device Profile Info 요청 샘플 코드 (Sample_Profile 샘플 참조) 00261 00262 int GW_Profile() 00263 { 00264 int nRet = GMMP_SUCCESS; 00265 00266 nRet = GO_Profile(pszGWID, NULL, nTID); 00267 00268 if(nRet < 0) 00269 { 00270 printf("GW GO_Profile Error : %d\n", nRet); 00271 00272 return 1; 00273 } 00274 00275 return 0; 00276 } 00277 00278 int Device_Profile() 00279 { 00280 int nRet = GMMP_SUCCESS; 00281 00282 nRet = GO_Profile(pszGWID, pszDeviceID, nTID); 00283 00284 if(nRet < 0) 00285 { 00286 printf("GW GO_Profile Error : %d\n", nRet); 00287 00288 return 1; 00289 } 00290 00291 return 0; 00292 } 00293 00294 int Init() 00295 { 00296 if(Initialize(szServerIP, nServerPort, pszDomainCode , pszGWAuthID, GMMP_ON_LOG, nErrorLevel, GMMP_NETWORK_ALYWAYS_OFF, "Log") != 0) 00297 { 00298 printf("Server Connect Error\n"); 00299 00300 return 1; 00301 } 00302 00303 SetCallFunction( (void*)Recv); 00304 SetAuthKey(pszAuthKey); 00305 00306 return 0; 00307 } 00308 00309 int main() 00310 { 00311 if(Init() != 0) 00312 { 00313 printf("Init Error"); 00314 return -1; 00315 } 00316 00317 if(GW_Profile() != 0) 00318 { 00319 printf("GW_Profile Error"); 00320 return -1; 00321 } 00322 00323 if(Device_Profile() != 0) 00324 { 00325 printf("Device_Profile Error"); 00326 return -1; 00327 } 00328 00329 return 0; 00330 00331 } 00332 @endcode 00333 */ 00334 int GO_Profile (const char* pszGWID, 00335 const char* pszDeviceID, 00336 const long nTID); 00337 /** 00338 * @} 00339 */ 00340 00341 /** 00342 * @defgroup GMMP_Delivery_Operation M2M GW/Device 주기 보고 00343 * 00344 M2M 단말에서 수집된 데이터를 OMP로 전송하는 절차이다.\n 00345 수집된 데이터를 전송하는 M2M 단말은 반드시 등록 절차를 통해 OMP에 등록되어 있어야 한다.\n 00346 수집된 데이터는 타입에 따라서 수집 데이터(collect data), 장애 데이터(alarm data), 이벤트 데이터(event data), 장애 해제(alarm clear) 데이터 등으로 분류 된다.\n 00347 이 값에 대한 설정은 cReportType 변수의 Report Type에 따라 구분된다. @ref Define_Delivery.h 참조 00348 00349 전송 패킷 : @ref Struct_Delivery.h 참조 00350 00351 * @ingroup GMMP_Delivery_Operation 00352 * @{ 00353 */ 00354 /** 00355 * 00356 * @param pszGWID OMP로 제공 받은 GW ID값. 00357 * @param pszDeviceID OMP로 제공 받은 Device ID값. 00358 * @param cReportType Report Type\n @ref Define_Delivery.h 참조 00359 - 0x01 : collect data\n 00360 - 0x02 : alarm data\n 00361 - 0x03 : event data\n 00362 - 0x04 : alarm clear\n 00363 * 00364 * @param cMediaType Message Body의 미디어 타입을 의미 @ref Struct_Delivery.h 참조 00365 * @param pszMessageBody Data[2048 Byte] 00366 * @param nTotalCount Message Body에 전달될 내용이 2048 Bytes를 초과할 경우 여러 개의 메시지로 전송하며 전체 메시지 개수를 표시 한다 00367 * @param nCurrentCount 여러 개의 메시지로 전송되는 경우 현재 메시지의 순서로서 1에서 Total Count까지의 값이 기록 된다. 00368 * @return 성공 : GMMMP_SUCCESS, 실패 : @ref ErrorCode.h 참조 00369 00370 @code GW/Device 주기 보고 샘플 코드 (Sample_Delivery 샘플 참조) 00371 int GW_Delivery() 00372 { 00373 int nRet = 0; 00374 int nTotalCount = 0; 00375 int nLoop = 0; 00376 int nMessageBodyLen = strlen(pszMessage); 00377 00378 if(nMessageBodyLen < MAX_MSG_BODY) 00379 { 00380 nTotalCount = 1; 00381 } 00382 else 00383 { 00384 nTotalCount = nMessageBodyLen/MAX_MSG_BODY; 00385 00386 if(nMessageBodyLen%MAX_MSG_BODY > 0) 00387 { 00388 nTotalCount++; 00389 } 00390 } 00391 00392 int nMessagePos = 0; 00393 int nSendLen = 0; 00394 int nSendedLen = nMessageBodyLen; 00395 00396 char szMessage[MAX_MSG_BODY]; 00397 00398 for(nLoop = 1 ; nLoop <= nTotalCount ; nLoop++) 00399 { 00400 memset(szMessage, 0, sizeof(szMessage) ); 00401 00402 if(nSendedLen >= MAX_MSG_BODY) 00403 { 00404 nSendLen = MAX_MSG_BODY; 00405 } 00406 else 00407 { 00408 nSendLen = nSendedLen; 00409 } 00410 00411 memcpy(szMessage, pszMessage+nMessagePos, nSendLen); 00412 00413 printf("Send Message Len = %d\n", strlen(szMessage) ); 00414 00415 nRet = GO_Delivery(pszGWID, NULL, DELIVERY_COLLECT_DATA, 0x01, szMessage); 00416 00417 if(nRet < 0) 00418 { 00419 printf("GO_Delivery Error : %d\n", nRet); 00420 00421 return 1; 00422 } 00423 00424 nSendedLen -= nSendLen; 00425 nMessagePos+= nSendedLen; 00426 } 00427 00428 return 0; 00429 } 00430 00431 int Device_Delivery() 00432 { 00433 int nRet = 0; 00434 int nTotalCount = 0; 00435 int nLoop = 0; 00436 int nMessageBodyLen = strlen(pszMessage); 00437 00438 if(nMessageBodyLen < MAX_MSG_BODY) 00439 { 00440 nTotalCount = 1; 00441 } 00442 else 00443 { 00444 nTotalCount = nMessageBodyLen/MAX_MSG_BODY; 00445 00446 if(nMessageBodyLen%MAX_MSG_BODY > 0) 00447 { 00448 nTotalCount++; 00449 } 00450 } 00451 00452 int nMessagePos = 0; 00453 int nSendLen = 0; 00454 int nSendedLen = nMessageBodyLen; 00455 00456 char szMessage[MAX_MSG_BODY]; 00457 00458 for(nLoop = 1 ; nLoop <= nTotalCount ; nLoop++) 00459 { 00460 memset(szMessage, 0, sizeof(szMessage) ); 00461 00462 if(nSendedLen >= MAX_MSG_BODY) 00463 { 00464 nSendLen = MAX_MSG_BODY; 00465 } 00466 else 00467 { 00468 nSendLen = nSendedLen; 00469 } 00470 00471 memcpy(szMessage, pszMessage+nMessagePos, nSendLen); 00472 00473 printf("Send Message Len = %d\n", strlen(szMessage) ); 00474 00475 nRet = GO_Delivery(pszGWID, pszDeviceID, DELIVERY_COLLECT_DATA, 0x01, szMessage); 00476 00477 if(nRet < 0) 00478 { 00479 printf("GO_Delivery Error : %d\n", nRet); 00480 00481 return 1; 00482 } 00483 00484 nSendedLen -= nSendLen; 00485 nMessagePos+= nSendedLen; 00486 } 00487 00488 return 0; 00489 } 00490 00491 int Init() 00492 { 00493 if(Initialize(szServerIP, nServerPort, pszDomainCode , pszGWAuthID, GMMP_ON_LOG, nErrorLevel, GMMP_NETWORK_ALYWAYS_OFF, "Log") != 0) 00494 { 00495 printf("Server Connect Error\n"); 00496 00497 return 1; 00498 } 00499 00500 SetCallFunction( (void*)Recv); 00501 SetAuthKey(pszAuthKey); 00502 SetGWID(pszGWID); 00503 00504 00505 return 0; 00506 } 00507 00508 int main() 00509 { 00510 if(Init() != 0) 00511 { 00512 printf("Init Error"); 00513 return -1; 00514 } 00515 00516 if(GW_Delivery() != 0) 00517 { 00518 printf("GW_Delivery Error"); 00519 return -1; 00520 } 00521 00522 if(Device_Delivery() != 0) 00523 { 00524 printf("Device_Delivery Error"); 00525 return -1; 00526 } 00527 00528 return 0; 00529 00530 } 00531 @endcode 00532 */ 00533 int GO_Delivery (const char* pszGWID, 00534 const char* pszDeviceID, 00535 const char cReportType, 00536 const char cMediaType, 00537 const char* pszMessageBody); 00538 /** 00539 * @} 00540 */ 00541 /** 00542 * @defgroup GMMP_Control_Operation M2M GW/Device 단말 제어 00543 * M2M 단말에 대한 특정 제어 명령을 전달하기 위한 절차로서 GMMP에서는 2가지 제어 방식을 지원한다.\n 00544 방식 1) TCP Always On 세션을 가지고 있는 M2M 단말인 경우 해당 세션을 통해 직접 제어 메시지를 전달하는 방식이다.\n 00545 방식 2) SMS 메시지를 통해 제어 명령을 전송하는 방식이다.\n 00546 00547 ※ Always ON 단말도 TCP 세션이 끊어져 있는 경우에는 SMS 메시지를 통한 제어 명령을 수신할 수 있다.\n 00548 00549 일반적으로 단말 제어 절차는 3단계로 이루어져 있다.\n 00550 1단계는 단말 제어 메시지를 통해 단말에게 제어 명령을 전달하고 응답하는 절차이다.\n 00551 2단계는 Control Type 에 따른 부가적인(Optional) 절차로서 Profile 정보, 큰 제어 데이터, FTP 정보, Remote Access 정보등을 획득하는 절차이다.\n 00552 3단계는 제어 결과를 플랫폼으로 통보하는 절차로서 단말 제어 결과 보고 메시지를 통해 제어 결과를 플랫폼으로 통보하고 그에 대한 결과를 수신한다.\n 00553 00554 제어절차시 Control Type 에 따라 M2M GW의 Reboot 절차가 수행될 수 있다.\n 00555 00556 단말 제어 메시지의 Control Type은 @ref Define_Control.h의 메시지 타입이 존재하며, 아래의 Control Type인 경우 부가 절차를 따른다.\n 00557 1. @ref CONTROL_Profile_Reset인 경우 @ref GMMP_ProfileInfo_Operation의 기능을 연계\n 00558 2. @ref CONTROL_FW_Download, @ref CONTROL_App_Download인 경우 @ref GMMP_FTP_Operation의 기능을 연계\n 00559 3. @ref CONTROL_Remote_Access인 경우 @ref GMMP_Remote_Operation의 기능을 연계\n 00560 4. @ref CONTROL_Multimedia_Control_Start인 경우 @ref GMMP_Multimedia_Operation의 기능을 연계 00561 00562 전송 패킷 : @ref Struct_Control.h @ref Struct_Control_Opt.h참조 00563 00564 * @ingroup GMMP_Control_Operation 00565 * @{ 00566 */ 00567 /** 00568 * 00569 * @param pszGWID OMP로 제공 받은 GW ID값. 00570 * @param pszDeviceID OMP로 제공 받은 Device ID값. 00571 * @param nTID T-ID는 M2M GW와 OMP 간의 트랜잭션을 구분하기 위한 값으로서 Request 요청하는 곳에서 할당하며 Response 받은 곳에서는 해당 T-ID 값을 그대로 반환한다.\n 00572 M2M GW와 OMP에서 T-ID 사용 범위는 다음과 같다.\n 00573 ※ M2M GW T-ID : 0 ~ 99,999 (10만개)\n 00574 ※ OMP T-ID : M2M GW가 사용 이외의 값\n 00575 * @param cControlType Data Collect Period & Time Setting , Reboot, Configuration, Time Sync, Change Server IP/Port(OMP), HB Period, etc\n 00576 * @ref Define_Operation.h 참조 00577 * @param cResultCode Result Code (0x00 : Success, other : Fail Reason)\n 00578 @ref OMPErrorCode.h 참조 00579 * 00580 * @return 성공 : GMMMP_SUCCESS, 실패 : @ref ErrorCode.h 참조 00581 @code GW/Device 제어 샘플 코드 (Sample_Control_TCP_AlwaysOn 샘플 참조) 00582 00583 int Recv(GMMPHeader* pstGMMPHeader, void* pBody) 00584 { 00585 U8 cMessageType = pstGMMPHeader->ucMessageType; 00586 00587 if(cMessageType == OPERATION_PROFILE_RSP) 00588 { 00589 stProfileRspHdr* pstRspHdr =(stProfileRspHdr*) pBody; 00590 00591 if(pstRspHdr->ucResultCode != 0x00) 00592 { 00593 printf("ResultCode : %x - %s\n", pstRspHdr->ucResultCode, GetStringtoOMPErrorCode(pstRspHdr->ucResultCode)); 00594 00595 return 1; 00596 } 00597 00598 if(strlen((char*)pstRspHdr->usDeviceID) <= 0) //GW Profile 조회 00599 { 00600 //주기값 재설정 00601 //pstRspHdr->unHeartbeatPeriod; 00602 //pstRspHdr->unReportOffset; 00603 //pstRspHdr->unReportPeriod; 00604 //pstRspHdr->unResponseTimeout; 00605 00606 00607 ConvertInt cvtInt; 00608 memcpy(&cvtInt.usInt, pstRspHdr->unHeartbeatPeriod, sizeof(pstRspHdr->unHeartbeatPeriod) ); 00609 00610 cvtInt.sU8 = ltobi(cvtInt.sU8); 00611 00612 //Profile 요청 수신 값에 Heartbeat 주기 값으로 변경 00613 if(cvtInt.sU8 > 0) 00614 { 00615 nTimerSec = cvtInt.sU8; 00616 } 00617 } 00618 else //Device Profile 조회 00619 { 00620 //주기값 재설정 00621 //pstRspHdr->unReportOffset; 00622 //pstRspHdr->unReportPeriod; 00623 //pstRspHdr->unResponseTimeout; 00624 00625 } 00626 } 00627 else if(pstGMMPHeader->ucMessageType == OPERATION_HEARTBEAT_RSP) 00628 { 00629 stHeartBeatMsgReqHdr* pstRspHdr =(stHeartBeatMsgReqHdr*) pBody; 00630 00631 00632 return 0; 00633 } 00634 00635 return 0; 00636 } 00637 00638 void* TimerThread() 00639 { 00640 //생략 00641 } 00642 00643 void* TCPReadThread(void *data) 00644 { 00645 //생략 00646 } 00647 00648 00649 int Init() 00650 { 00651 //생략 00652 } 00653 00654 int GW_Profile() 00655 { 00656 //생략 00657 } 00658 00659 int main() 00660 { 00661 if(Init() != 0) 00662 { 00663 printf("Init Error"); 00664 return -1; 00665 } 00666 00667 pthread_t thread_id = 0; 00668 pthread_t timer_id = 0; 00669 00670 pthread_create(&thread_id, NULL, TCPReadThread, NULL); 00671 pthread_create(&timer_id, NULL, TimerThread, NULL); 00672 00673 pthread_join(thread_id, NULL); 00674 pthread_join(timer_id, NULL); 00675 return 0; 00676 00677 } 00678 @endcode 00679 */ 00680 int GO_Control (const char* pszGWID, 00681 const char* pszDeviceID, 00682 long nTID, 00683 const char cControlType, 00684 const char cResultCode); 00685 /** 00686 * @} 00687 */ 00688 /** 00689 * @defgroup GMMP_Notification_Operation M2M GW/Device 제어 결과 보고 00690 전송 패킷 : @ref Struct_Notification.h 참조 00691 * 제어 결과를 플랫폼으로 통보하고 그에 대한 결과를 수신한다. 00692 */ 00693 /** 00694 * @ingroup GMMP_Notification_Operation 00695 * @{ 00696 */ 00697 /** 00698 * 00699 * @param pszGWID OMP로 제공 받은 GW ID값. 00700 * @param pszDeviceID OMP로 제공 받은 Device ID값. 00701 * @param cControlType 단말 제어 메시지에 수신한 값과 동일한 값을 사용한다 00702 * @param cResultCode Result Code (0x00 : Success, other : Fail Reason) 00703 * @param pszMessageBody Data[2048 Byte] 00704 * @param nMessageBodySize pszMessageBody의 크기 00705 * @return 성공 : GMMMP_SUCCESS, 실패 : @ref ErrorCode.h 참조 00706 * 00707 @code GW/Device 제어 결과 보고 샘플 코드 (Sample_Control_TCP_AlwaysOn 샘플 참조) 00708 00709 int Recv(GMMPHeader* pstGMMPHeader, void* pBody) 00710 { 00711 U8 cMessageType = pstGMMPHeader->ucMessageType; 00712 00713 if(cMessageType == OPERATION_PROFILE_RSP) 00714 { 00715 stProfileRspHdr* pstRspHdr =(stProfileRspHdr*) pBody; 00716 00717 if(pstRspHdr->ucResultCode != 0x00) 00718 { 00719 printf("ResultCode : %x - %s\n", pstRspHdr->ucResultCode, GetStringtoOMPErrorCode(pstRspHdr->ucResultCode)); 00720 00721 return 1; 00722 } 00723 00724 if(strlen((char*)pstRspHdr->usDeviceID) <= 0) //GW Profile 조회 00725 { 00726 //주기값 재설정 00727 //pstRspHdr->unHeartbeatPeriod; 00728 //pstRspHdr->unReportOffset; 00729 //pstRspHdr->unReportPeriod; 00730 //pstRspHdr->unResponseTimeout; 00731 00732 00733 int nHeartBeat = Char2int((char*)pstRspHdr->unHeartbeatPeriod); //수신받은 Heartbeat 주기 값을 확인. 00734 00735 //Profile 요청 수신 값에 Heartbeat 주기 값으로 변경 00736 if(nHeartBeat > 0) 00737 { 00738 nTimerSec = nHeartBeat; 00739 } 00740 } 00741 else //Device Profile 조회 00742 { 00743 //주기값 재설정 00744 //pstRspHdr->unReportOffset; 00745 //pstRspHdr->unReportPeriod; 00746 //pstRspHdr->unResponseTimeout; 00747 00748 } 00749 } 00750 else if(pstGMMPHeader->ucMessageType == OPERATION_HEARTBEAT_RSP) 00751 { 00752 stHeartBeatMsgReqHdr* pstRspHdr =(stHeartBeatMsgReqHdr*) pBody; 00753 00754 00755 return 0; 00756 } 00757 00758 return 0; 00759 } 00760 00761 void* TimerThread() 00762 { 00763 //생략 00764 } 00765 00766 void* TCPReadThread(void *data) 00767 { 00768 //생략 00769 } 00770 00771 00772 int Init() 00773 { 00774 //생략 00775 } 00776 00777 int GW_Profile() 00778 { 00779 //생략 00780 } 00781 00782 int main() 00783 { 00784 if(Init() != 0) 00785 { 00786 printf("Init Error"); 00787 return -1; 00788 } 00789 00790 pthread_t thread_id = 0; 00791 pthread_t timer_id = 0; 00792 00793 pthread_create(&thread_id, NULL, TCPReadThread, NULL); 00794 pthread_create(&timer_id, NULL, TimerThread, NULL); 00795 00796 pthread_join(thread_id, NULL); 00797 pthread_join(timer_id, NULL); 00798 return 0; 00799 00800 } 00801 @endcode 00802 */ 00803 int GO_Notifi (const char* pszGWID, 00804 const char* pszDeviceID, 00805 const char cControlType, 00806 const char cResultCode, 00807 const char* pszMessageBody, 00808 const int nMessageBodySize); 00809 /** 00810 * @} 00811 */ 00812 00813 /** 00814 * @defgroup GMMP_Heartbeat_Operation M2M GW/Device Heartbeat 00815 TCP Always On 단말인 경우 해당 세션을 감시하기 위해 주기적으로 Heartbeat 메시지를 전송한다.\n 00816 M2M 단말은 Profile 정보의 Heartbeat Period 값을 주기로 전송하며, 0인 경우에는 세션을 유지하지 않는다. 00817 00818 전송 패킷 : @ref Struct_Heartbeat.h 참조 00819 00820 * @ingroup GMMP_Heartbeat_Operation 00821 * @{ 00822 */ 00823 00824 /** 00825 * 00826 * @param pszGWID GW ID 00827 * @return 성공 : GMMMP_SUCCESS, 실패 : @ref ErrorCode.h 참조 00828 @code GW/Device Heartbeat 보고 샘플 코드 (Sample_Control_TCP_AlwaysOn 샘플 참조) 00829 00830 int Recv(GMMPHeader* pstGMMPHeader, void* pBody) 00831 { 00832 U8 cMessageType = pstGMMPHeader->ucMessageType; 00833 00834 if(cMessageType == OPERATION_PROFILE_RSP) 00835 { 00836 //생략 00837 } 00838 else if(pstGMMPHeader->ucMessageType == OPERATION_HEARTBEAT_RSP) 00839 { 00840 stHeartBeatMsgReqHdr* pstRspHdr =(stHeartBeatMsgReqHdr*) pBody; 00841 00842 00843 return 0; 00844 } 00845 00846 return 0; 00847 } 00848 00849 void* TimerThread() 00850 { 00851 int nCount = 0; 00852 while(bTimer == true) 00853 { 00854 if(strlen(pszGWAuthID) > 0 && strlen(pszAuthKey) > 0 ) 00855 { 00856 SetTID(GetTID()+1); 00857 00858 int nRet = GMMP_SetHB(pszGWAuthID, pszAuthKey, pszDomainCode, pszGWID); 00859 if(nRet != GMMP_SUCCESS) 00860 { 00861 if(nCount > 2) 00862 { 00863 break; 00864 } 00865 nCount++; 00866 } 00867 } 00868 00869 sleep(nTimerSec); 00870 } 00871 00872 return NULL; 00873 } 00874 00875 void* TCPReadThread(void *data) 00876 { 00877 //생략 00878 } 00879 00880 00881 int Init() 00882 { 00883 //생략 00884 } 00885 00886 int GW_Profile() 00887 { 00888 //생략 00889 } 00890 00891 int main() 00892 { 00893 if(Init() != 0) 00894 { 00895 printf("Init Error"); 00896 return -1; 00897 } 00898 00899 pthread_t thread_id = 0; 00900 pthread_t timer_id = 0; 00901 00902 pthread_create(&thread_id, NULL, TCPReadThread, NULL); 00903 pthread_create(&timer_id, NULL, TimerThread, NULL); 00904 00905 pthread_join(thread_id, NULL); 00906 pthread_join(timer_id, NULL); 00907 return 0; 00908 00909 } 00910 00911 @endcode 00912 */ 00913 int GO_HB (const char* pszGWID); 00914 /** 00915 * @} 00916 */ 00917 00918 int OG_Reg_Recv(GMMPHeader* pstGMMPHeader, stGwRegistrationRspHdr* pstGWBody, stDeviceRegistrationRspHdr* pstDeviceBody); 00919 int OG_DeReg_Recv(GMMPHeader* pstGMMPHeader, stGwDeRegistrationRspHdr* pstGWBody, stDeviceDeRegistrationRspHdr* pstDeviceBody); 00920 int OG_Profile_Recv(GMMPHeader* pstGMMPHeader, stProfileRspHdr* pstBody); 00921 int OG_Delivery_Recv(GMMPHeader* pstGMMPHeader, stPacketDeliveryRspHdr* pstBody); 00922 int OG_Ctrl_Recv(GMMPHeader* pstGMMPHeader, stControlReqHdr* pstBody); 00923 int OG_HB_Recv(GMMPHeader* pstGMMPHeader, stHeartBeatMsgRspHdr* pstBody); 00924 int OG_Notifi_Recv(GMMPHeader* pstGMMPHeader, stNotificationRspHdr* pstBody); 00925 00926 /** 00927 * @brief GMMP 라이브러리 초기화 및 기본 정보 입력 00928 * @param serverIp 접속할 서버 IP, 4 byte array. @ref g_serverIp에 저장된다, 00929 * @param nPort 접속할 서버 port, @ref g_nServerPort에 저장된다. 00930 * @param pszDomainCode OMP Portal을 통해 등록된 서비스 코드, @ref g_szDomainCode에 저장된다, 00931 * @param pszGWAuthID M2M GW 의 Serial Number 값이며, MSISDN 또는 MAC Address값을 사용할 수도 있다. @ref g_szAuthID에 저장된다. 00932 * @param nGMMPMode 로그 저장 유무, GMMP_OFF_LOG, GMMP_ON_LOG 00933 * @param nErrorLevel 로그 출력 레벨 00934 * @param nNetwrokType 통신 타입 00935 * @param mac MAC Address. 6 byte array. 00936 * @return 성공 : GMMP_SUCCESS, 실패: 1이상 , 에러코드 참조 00937 */ 00938 int Initialize(byte* serverIp, 00939 const int nPort, 00940 const char* pszDomainCode, 00941 const char* pszGWAuthID, 00942 byte* mac); 00943 00944 /** 00945 * @brief GMMP 라이브러리 Uninitialize 00946 */ 00947 void Uninitialize(); 00948 00949 /** 00950 * @brief TCP Always On 에서 사용하는 함수\n 00951 * Thread를 생성 하고 이 함수를 연결하여 사용한다. 00952 * @param pstGMMPHeader @ref GMMPHeader 구조체 포인트 00953 * @param pBody Body 메시지 구조체 포인트 00954 * @return 성공 : GMMMP_SUCCESS, 실패 : @ref ErrorCode.h 참조 00955 */ 00956 int GetReadData(GMMPHeader* pstGMMPHeader, void** pBody); 00957 00958 /** 00959 *char 타입의 데이터를 int로 변환한다. 00960 * @param pBuffer in 00961 * @param nSize in pBuffer size 00962 * @return int 00963 */ 00964 long Char2int(void* pBuffer, int nSize); 00965 00966 /** 00967 *char 타입의 데이터를 short로 변환한다. 00968 * @param pBuffer 00969 * @param nSize 00970 * @return 00971 */ 00972 int Char2short(void* pBuffer, int nSize); 00973 00974 /** 00975 *@fn void InitMemory(); 00976 *@brief 내부 변수 초기화 00977 */ 00978 void InitMemory(); 00979 00980 /** 00981 * @brief OMP로 제공 받은 AuthKey값을 저장하는 함수 00982 * @param pszAuthKey OMP로 부터 제공 받은 Auth Key 값 00983 */ 00984 void SetAuthKey(const char* pszAuthKey); 00985 /** 00986 @brief 저장된 AuthKey 00987 * @return 저장된 Auth Key 00988 */ 00989 char* GetAuthKey(); 00990 00991 00992 /** 00993 * @brief OMP로 제공 받은 GW ID값을 저장하는 함수 00994 * @param pszGWID OMP로 부터 제공 받은 GW ID 값 00995 */ 00996 void SetGWID(const char* pszGWID); 00997 00998 /** 00999 * 01000 * @return 저장된 GW ID 01001 */ 01002 char* GetGWID (); 01003 01004 /** 01005 *@brief 서버 정보 및 GW Auth ID, DomainCode를 저장한다. 01006 * @param serverIp Server IP 01007 * @param nPort Server Port 01008 * @param pszAuthID Auth ID 01009 * @param pszDomainCode DomainCode 01010 * @return 성공 : GMMP_SUCCESS, 실패 : LIB_PARAM_ERROR 01011 */ 01012 int SetServerInfo(byte* serverIp, int nPort, const char* pszAuthID, const char* pszDomainCode); 01013 01014 /** 01015 *@brief OMP서버로 부터 수신한 패킷을 제공할 콜백함수 저장 함수 01016 * @param pCallFunctionName 콜백을 제공 받을 함수 포인트 01017 */ 01018 void SetCallFunction(int (* pCallFunctionName)(GMMPHeader* pstGMMPHeader, void* pstBody)); 01019 01020 #endif /* GMMP_H_ */
Generated on Tue Jul 12 2022 21:35:52 by
