ThingPlug GMMP library for mbed

Dependents:   ThingPlug_WiFi_Example

Committer:
lesmin
Date:
Wed Aug 12 08:58:26 2015 +0000
Revision:
3:e841a647d1df
Parent:
2:873c169fba78
Child:
4:bb6c1ee1d5f0
GMMP InitMemory patched

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lesmin 0:32c20cfb2b30 1 /** GMMP 공통 정의
lesmin 0:32c20cfb2b30 2 * @file GMMP.cpp
lesmin 0:32c20cfb2b30 3 * @date 2015/07/20
lesmin 0:32c20cfb2b30 4 * @version 0.0.1.0
lesmin 0:32c20cfb2b30 5 **/
lesmin 0:32c20cfb2b30 6
lesmin 0:32c20cfb2b30 7 #ifndef GMMP_h
lesmin 0:32c20cfb2b30 8 #define GMMP_h
lesmin 0:32c20cfb2b30 9
lesmin 0:32c20cfb2b30 10 /*
lesmin 0:32c20cfb2b30 11 #include <stdio.h>
lesmin 0:32c20cfb2b30 12 #include <stdlib.h>
lesmin 0:32c20cfb2b30 13 #include <string.h>
lesmin 0:32c20cfb2b30 14 #include <time.h>
lesmin 0:32c20cfb2b30 15 #include <pthread.h>
lesmin 0:32c20cfb2b30 16 #include <unistd.h>
lesmin 0:32c20cfb2b30 17 #include <stdarg.h>
lesmin 0:32c20cfb2b30 18 */
lesmin 0:32c20cfb2b30 19
lesmin 0:32c20cfb2b30 20 //#include <inttypes.h>
lesmin 0:32c20cfb2b30 21 //#include <Time.h>
lesmin 0:32c20cfb2b30 22 //#include <Arduino.h>
lesmin 0:32c20cfb2b30 23
lesmin 0:32c20cfb2b30 24 #define USE_SNIC_WIFI //Murata Type YD Wi-Fi
lesmin 0:32c20cfb2b30 25 //#define USE_WIZNET_W5500
lesmin 0:32c20cfb2b30 26
lesmin 0:32c20cfb2b30 27 #if defined(TARGET_LPC1768)
lesmin 0:32c20cfb2b30 28 #include "EthernetInterface.h"
lesmin 0:32c20cfb2b30 29 #elif defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_NUCLEO_L152RE)
lesmin 0:32c20cfb2b30 30
lesmin 0:32c20cfb2b30 31 #ifdef USE_SNIC_WIFI
lesmin 0:32c20cfb2b30 32 #include "SNIC_WifiInterface.h"
lesmin 0:32c20cfb2b30 33 #endif//USE_SNIC_WIFI
lesmin 0:32c20cfb2b30 34
lesmin 0:32c20cfb2b30 35 #ifdef USE_WIZNET_W5500
lesmin 0:32c20cfb2b30 36 #include "WIZnetInterface.h"
lesmin 0:32c20cfb2b30 37 #endif//USE_WIZNET_W5500
lesmin 0:32c20cfb2b30 38 #endif
lesmin 0:32c20cfb2b30 39
lesmin 0:32c20cfb2b30 40 #include "NTPClient.h"
lesmin 0:32c20cfb2b30 41
lesmin 0:32c20cfb2b30 42 #include "GMMP.h"
lesmin 0:32c20cfb2b30 43
lesmin 0:32c20cfb2b30 44 byte g_serverIp[LEN_IP] ; ///< 서버 IP 정보를 저장한다.
lesmin 0:32c20cfb2b30 45 int g_nServerPort = 0; ///< 서버 Port 정보를 저장한다.
lesmin 0:32c20cfb2b30 46
lesmin 0:32c20cfb2b30 47 char g_szAuthID[LEN_AUTH_ID];///< OMP Portal을 통해 사전에 등록된 M2M GW 의 Serial Number 저장 변수, 자동화를 위해 사용된다.
lesmin 0:32c20cfb2b30 48
lesmin 0:32c20cfb2b30 49 char g_szAuthKey[LEN_AUTH_KEY]; ///< 등록 절차 시 OMP에서 할당 받은 AuthKey 저장 변수, 자동화를 위해 사용된다.
lesmin 0:32c20cfb2b30 50
lesmin 0:32c20cfb2b30 51 char g_szDomainCode[LEN_DOMAIN_CODE]; ///< OMP Portal을 통해 사전에 등록된 서비스 영역별 구분 코드 저장 변수, 자동화를 위해 사용된다.
lesmin 0:32c20cfb2b30 52
lesmin 0:32c20cfb2b30 53 char g_szGWID[LEN_GW_ID]; ///< OMP에서 할당 받은 Gateway의 ID 문자열 저장 변수, 자동화를 위해 사용된다.
lesmin 0:32c20cfb2b30 54
lesmin 0:32c20cfb2b30 55 /**
lesmin 0:32c20cfb2b30 56 * @brief OMP서버로 부터 수신한 패킷을 제공할 콜백함수 포인트 구조체
lesmin 0:32c20cfb2b30 57 * @param pstGMMPHeader GMMP Header의 구조체 포인트
lesmin 0:32c20cfb2b30 58 * @param pstBody GMMP Body의 구조체 포인트
lesmin 0:32c20cfb2b30 59 * @return 성공:0, 실패: 1이상 , 에러코드 참조
lesmin 0:32c20cfb2b30 60 */
lesmin 0:32c20cfb2b30 61 typedef int (*callback_Reg)(GMMPHeader* pstGMMPHeader, void* pstBody);
lesmin 0:32c20cfb2b30 62
lesmin 0:32c20cfb2b30 63 callback_Reg g_CallFunctionRegRecv = NULL; ///< OMP서버로 부터 수신한 패킷을 제공할 콜백함수 포인트 변수.
lesmin 0:32c20cfb2b30 64 //callback_Reg g_CallHeartbeatRegRecv = NULL; ///< OMP서버로 부터 수신한 패킷 중 Heartbeat 패킷을 제공할 콜백함수 포인트 변수. (TCP Always On mode에서만 사용된다.)
lesmin 0:32c20cfb2b30 65
lesmin 0:32c20cfb2b30 66 void Uninitialize()
lesmin 0:32c20cfb2b30 67 {
lesmin 0:32c20cfb2b30 68 InitMemory();
lesmin 0:32c20cfb2b30 69 CloseSocket();
lesmin 0:32c20cfb2b30 70 }
lesmin 0:32c20cfb2b30 71
lesmin 0:32c20cfb2b30 72
lesmin 0:32c20cfb2b30 73
lesmin 0:32c20cfb2b30 74 int Initialize(byte* serverIp,
lesmin 0:32c20cfb2b30 75 const int nPort,
lesmin 0:32c20cfb2b30 76 const char* pszDomainCode,
lesmin 0:32c20cfb2b30 77 const char* pszGWAuthID,
lesmin 0:32c20cfb2b30 78 byte* mac)
lesmin 0:32c20cfb2b30 79 {
lesmin 0:32c20cfb2b30 80 debugln("Initialize()");
lesmin 0:32c20cfb2b30 81
lesmin 0:32c20cfb2b30 82 InitMemory();
lesmin 0:32c20cfb2b30 83
lesmin 0:32c20cfb2b30 84 //delay(2000);
lesmin 0:32c20cfb2b30 85 #if defined(TARGET_LPC1768)
lesmin 0:32c20cfb2b30 86 EthernetInterface eth;
lesmin 0:32c20cfb2b30 87 #elif defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_NUCLEO_L152RE)
lesmin 0:32c20cfb2b30 88
lesmin 0:32c20cfb2b30 89 #ifdef USE_SNIC_WIFI
lesmin 0:32c20cfb2b30 90 C_SNIC_WifiInterface wifi( D8, D2, NC, NC, D3);
lesmin 0:32c20cfb2b30 91
lesmin 2:873c169fba78 92 #define MBED_AP_SSID "tide855" //"tide867"
lesmin 0:32c20cfb2b30 93 /** Securiry Options
lesmin 0:32c20cfb2b30 94 e_SEC_OPEN = 0x00, //Open
lesmin 0:32c20cfb2b30 95 e_SEC_WEP = 0x01, // WEP
lesmin 0:32c20cfb2b30 96 e_SEC_WPA_TKIP = 0x02, // WPA-PSK(TKIP)
lesmin 0:32c20cfb2b30 97 e_SEC_WPA2_AES = 0x04, // WPA2-PSK(AES)
lesmin 0:32c20cfb2b30 98 e_SEC_WPA2_MIXED = 0x06, // WPA2-PSK(TKIP/AES)
lesmin 0:32c20cfb2b30 99 e_SEC_WPA_AES = 0x07 // WPA-PSK(AES) **/
lesmin 2:873c169fba78 100 #define MBED_AP_SECURITY_TYPE e_SEC_WPA2_AES//e_SEC_OPEN
lesmin 2:873c169fba78 101 #define MBED_AP_SECUTIRY_KEY "tidetide"
lesmin 0:32c20cfb2b30 102
lesmin 0:32c20cfb2b30 103 #endif//USE_SNIC_WIFI
lesmin 0:32c20cfb2b30 104
lesmin 0:32c20cfb2b30 105 #ifdef USE_WIZNET_W5500
lesmin 0:32c20cfb2b30 106 //unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x34,0x56};
lesmin 0:32c20cfb2b30 107 SPI spi(PA_7, PA_6, PA_5); // mosi, miso, sclk
lesmin 0:32c20cfb2b30 108 WIZnetInterface ethernet(&spi, PB_6, PA_9);//scs(PB_6), nRESET(PA_9); // reset pin is dummy, don't affect any pin of WIZ550io
lesmin 0:32c20cfb2b30 109 #endif//USE_WIZNET_W5500
lesmin 0:32c20cfb2b30 110
lesmin 0:32c20cfb2b30 111 #endif
lesmin 0:32c20cfb2b30 112 //NTPClient ntp;
lesmin 0:32c20cfb2b30 113
lesmin 0:32c20cfb2b30 114 infoln("Getting IP...");
lesmin 0:32c20cfb2b30 115
lesmin 0:32c20cfb2b30 116 #if defined(TARGET_LPC1768)
lesmin 0:32c20cfb2b30 117 eth.init(); //Use DHCP
lesmin 0:32c20cfb2b30 118 eth.connect();
lesmin 0:32c20cfb2b30 119 wait(0.5);
lesmin 0:32c20cfb2b30 120 printf("IP Address is %s\r\n", eth.getIPAddress());
lesmin 0:32c20cfb2b30 121 #elif defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_NUCLEO_L152RE)
lesmin 0:32c20cfb2b30 122
lesmin 0:32c20cfb2b30 123 #ifdef USE_SNIC_WIFI
lesmin 0:32c20cfb2b30 124 wifi.init();
lesmin 0:32c20cfb2b30 125
lesmin 0:32c20cfb2b30 126 wait(0.5);
lesmin 0:32c20cfb2b30 127 int s = wifi.disconnect();
lesmin 0:32c20cfb2b30 128 if( s != 0 ) {
lesmin 0:32c20cfb2b30 129 return -1;
lesmin 0:32c20cfb2b30 130 }
lesmin 0:32c20cfb2b30 131
lesmin 0:32c20cfb2b30 132 wait(0.3);
lesmin 0:32c20cfb2b30 133 // Connect AP
lesmin 0:32c20cfb2b30 134 wifi.connect( MBED_AP_SSID
lesmin 0:32c20cfb2b30 135 , strlen(MBED_AP_SSID)
lesmin 0:32c20cfb2b30 136 , MBED_AP_SECURITY_TYPE
lesmin 0:32c20cfb2b30 137 , MBED_AP_SECUTIRY_KEY
lesmin 0:32c20cfb2b30 138 , strlen(MBED_AP_SECUTIRY_KEY) );
lesmin 0:32c20cfb2b30 139 wait(0.5);
lesmin 0:32c20cfb2b30 140 wifi.setIPConfig( true ); //Use DHCP
lesmin 0:32c20cfb2b30 141 wait(0.5);
lesmin 0:32c20cfb2b30 142
lesmin 0:32c20cfb2b30 143 tagWIFI_STATUS_T wifi_status;
lesmin 0:32c20cfb2b30 144 if( wifi.getWifiStatus(&wifi_status) ) printf("wifi_status error!\r\n");
lesmin 0:32c20cfb2b30 145
lesmin 1:272f2e355446 146 printf("MAC Address is %02x:%02x:%02x:%02x:%02x:%02x\r\n",
lesmin 1:272f2e355446 147 wifi_status.mac_address[0], wifi_status.mac_address[1], wifi_status.mac_address[2],
lesmin 1:272f2e355446 148 wifi_status.mac_address[3], wifi_status.mac_address[4], wifi_status.mac_address[5]);
lesmin 0:32c20cfb2b30 149 printf("IP Address is %s\r\n", wifi.getIPAddress());
lesmin 0:32c20cfb2b30 150 #endif//USE_SNIC_WIFI
lesmin 0:32c20cfb2b30 151
lesmin 0:32c20cfb2b30 152 #ifdef USE_WIZNET_W5500
lesmin 0:32c20cfb2b30 153 //mbed_mac_address((char *)MAC_Addr); //Use mbed mac addres
lesmin 0:32c20cfb2b30 154
lesmin 0:32c20cfb2b30 155 int ret = ethernet.init(mac);
lesmin 0:32c20cfb2b30 156 printf("SPI Initialized \r\n");
lesmin 0:32c20cfb2b30 157 wait(1); // 1 second for stable state
lesmin 0:32c20cfb2b30 158
lesmin 0:32c20cfb2b30 159 printf("W5500 Networking Started \r\n");
lesmin 0:32c20cfb2b30 160 wait(1); // 1 second for stable state
lesmin 0:32c20cfb2b30 161
lesmin 0:32c20cfb2b30 162 if (!ret) {
lesmin 0:32c20cfb2b30 163 printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress());
lesmin 0:32c20cfb2b30 164 ret = ethernet.connect();
lesmin 0:32c20cfb2b30 165 if (!ret) {
lesmin 0:32c20cfb2b30 166 printf("IP: %s, MASK: %s, GW: %s\r\n",
lesmin 0:32c20cfb2b30 167 ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway());
lesmin 0:32c20cfb2b30 168 } else {
lesmin 0:32c20cfb2b30 169 printf("Error ethernet.connect() - ret = %d\r\n", ret);
lesmin 0:32c20cfb2b30 170 //exit(0);
lesmin 0:32c20cfb2b30 171 }
lesmin 0:32c20cfb2b30 172 } else {
lesmin 0:32c20cfb2b30 173 printf("Error ethernet.init() - ret = %d\r\n", ret);
lesmin 0:32c20cfb2b30 174 //exit(0);
lesmin 0:32c20cfb2b30 175 }
lesmin 0:32c20cfb2b30 176
lesmin 0:32c20cfb2b30 177 #endif//USE_WIZNET_W5500
lesmin 0:32c20cfb2b30 178 #endif
lesmin 0:32c20cfb2b30 179
lesmin 0:32c20cfb2b30 180
lesmin 0:32c20cfb2b30 181 NTPClient ntp;
lesmin 0:32c20cfb2b30 182 printf("Trying to update time...\r\n");
lesmin 0:32c20cfb2b30 183 //if (ntp.setTime("0.pool.ntp.org") == 0)
lesmin 0:32c20cfb2b30 184 // if (ntp.setTime("time-a.timefreq.bldrdoc.gov") == 0)
lesmin 0:32c20cfb2b30 185 // if (ntp.setTime("kr.pool.ntp.org") == 0)
lesmin 2:873c169fba78 186 // if (ntp.setTime("112.220.115.166") == 0)
lesmin 0:32c20cfb2b30 187 if (ntp.setTime("211.233.40.78") == 0) //MURATA UDP does not support DNS resolver...
lesmin 0:32c20cfb2b30 188 {
lesmin 0:32c20cfb2b30 189 printf("Set time successfully\r\n");
lesmin 0:32c20cfb2b30 190 time_t ctTime;
lesmin 0:32c20cfb2b30 191 ctTime = time(NULL);
lesmin 0:32c20cfb2b30 192 // printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
lesmin 0:32c20cfb2b30 193 ctTime += 32400; // GMT+9/Seoul
lesmin 0:32c20cfb2b30 194 printf("Time is set to (GMT+9): %s\r\n", ctime(&ctTime));
lesmin 0:32c20cfb2b30 195 }
lesmin 0:32c20cfb2b30 196 else
lesmin 0:32c20cfb2b30 197 {
lesmin 0:32c20cfb2b30 198 printf("Error\r\n");
lesmin 0:32c20cfb2b30 199 }
lesmin 0:32c20cfb2b30 200
lesmin 0:32c20cfb2b30 201
lesmin 0:32c20cfb2b30 202 if(SetServerInfo(serverIp, nPort, pszGWAuthID, pszDomainCode) != 0)
lesmin 0:32c20cfb2b30 203 {
lesmin 0:32c20cfb2b30 204 return LIB_PARAM_ERROR;
lesmin 0:32c20cfb2b30 205 }
lesmin 0:32c20cfb2b30 206 SetTID(0);
lesmin 0:32c20cfb2b30 207
lesmin 0:32c20cfb2b30 208 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 209 }
lesmin 0:32c20cfb2b30 210
lesmin 0:32c20cfb2b30 211 void SetAuthKey(const char* pszAuthKey)
lesmin 0:32c20cfb2b30 212 {
lesmin 0:32c20cfb2b30 213 memcpy(g_szAuthKey, pszAuthKey, strlen(pszAuthKey));
lesmin 0:32c20cfb2b30 214 }
lesmin 0:32c20cfb2b30 215
lesmin 0:32c20cfb2b30 216 void SetGWID(const char* pszGWID)
lesmin 0:32c20cfb2b30 217 {
lesmin 0:32c20cfb2b30 218 if(pszGWID != NULL)
lesmin 0:32c20cfb2b30 219 {
lesmin 0:32c20cfb2b30 220 memcpy(g_szGWID, pszGWID, strlen(pszGWID));
lesmin 0:32c20cfb2b30 221 }
lesmin 0:32c20cfb2b30 222 }
lesmin 0:32c20cfb2b30 223
lesmin 0:32c20cfb2b30 224 char* GetGWID()
lesmin 0:32c20cfb2b30 225 {
lesmin 0:32c20cfb2b30 226 return g_szGWID;
lesmin 0:32c20cfb2b30 227 }
lesmin 0:32c20cfb2b30 228
lesmin 0:32c20cfb2b30 229 int SetServerInfo(byte* serverIp, int nPort, const char* pszAuthID, const char* pszDoamainCode)
lesmin 0:32c20cfb2b30 230 {
lesmin 0:32c20cfb2b30 231 /*
lesmin 0:32c20cfb2b30 232 if(pszAuthID == NULL || strlen(pszAuthID) > LEN_AUTH_ID
lesmin 0:32c20cfb2b30 233 || pszDoamainCode == NULL || strlen(pszDoamainCode) > LEN_DOMAIN_CODE)
lesmin 0:32c20cfb2b30 234 {
lesmin 0:32c20cfb2b30 235 return LIB_PARAM_ERROR;
lesmin 0:32c20cfb2b30 236 }
lesmin 0:32c20cfb2b30 237 */
lesmin 0:32c20cfb2b30 238
lesmin 0:32c20cfb2b30 239 memcpy(g_serverIp, serverIp, LEN_IP);
lesmin 0:32c20cfb2b30 240 memcpy(g_szAuthID, pszAuthID, strlen(pszAuthID));
lesmin 0:32c20cfb2b30 241 memcpy(g_szDomainCode, pszDoamainCode, strlen(pszDoamainCode));
lesmin 0:32c20cfb2b30 242
lesmin 0:32c20cfb2b30 243 g_nServerPort = nPort;
lesmin 0:32c20cfb2b30 244
lesmin 0:32c20cfb2b30 245 int nRet = SetIntiSocket();
lesmin 0:32c20cfb2b30 246 if(nRet != GMMP_SUCCESS)
lesmin 0:32c20cfb2b30 247 {
lesmin 0:32c20cfb2b30 248 return nRet;
lesmin 0:32c20cfb2b30 249 }
lesmin 0:32c20cfb2b30 250
lesmin 0:32c20cfb2b30 251 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 252 }
lesmin 0:32c20cfb2b30 253
lesmin 0:32c20cfb2b30 254 void SetCallFunction(int (* pCallFunctionName)(GMMPHeader* pstGMMPHeader, void* pstBody))
lesmin 0:32c20cfb2b30 255 {
lesmin 0:32c20cfb2b30 256 g_CallFunctionRegRecv = (callback_Reg)pCallFunctionName;
lesmin 0:32c20cfb2b30 257 }
lesmin 0:32c20cfb2b30 258
lesmin 0:32c20cfb2b30 259 int GO_Reg(const char* pszGWID,
lesmin 0:32c20cfb2b30 260 const char* pszManufactureID)
lesmin 0:32c20cfb2b30 261 {
lesmin 0:32c20cfb2b30 262 debugln("GO_Reg()");
lesmin 0:32c20cfb2b30 263 SetTID(GetTID()+1);
lesmin 0:32c20cfb2b30 264
lesmin 0:32c20cfb2b30 265 int nRet = GMMP_SetReg(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID, pszManufactureID);
lesmin 0:32c20cfb2b30 266 debugln("GO_SetReg() Done");
lesmin 0:32c20cfb2b30 267
lesmin 0:32c20cfb2b30 268 return nRet;
lesmin 0:32c20cfb2b30 269 }
lesmin 0:32c20cfb2b30 270
lesmin 0:32c20cfb2b30 271 int GO_DeReg(const char* pszGWID, const char* pszDeviceID)
lesmin 0:32c20cfb2b30 272 {
lesmin 0:32c20cfb2b30 273 SetTID(GetTID()+1);
lesmin 0:32c20cfb2b30 274
lesmin 0:32c20cfb2b30 275 int nRet = GMMP_SetDeReg(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID, pszDeviceID);
lesmin 0:32c20cfb2b30 276
lesmin 0:32c20cfb2b30 277 return nRet;
lesmin 0:32c20cfb2b30 278 }
lesmin 0:32c20cfb2b30 279
lesmin 0:32c20cfb2b30 280 int GO_Profile(const char* pszGWID,
lesmin 0:32c20cfb2b30 281 const char* pszDeviceID,
lesmin 0:32c20cfb2b30 282 const long nTID /*=0*/)
lesmin 0:32c20cfb2b30 283 {
lesmin 0:32c20cfb2b30 284 if(nTID == 0) {
lesmin 0:32c20cfb2b30 285 SetTID(GetTID()+1);
lesmin 0:32c20cfb2b30 286 } else {
lesmin 0:32c20cfb2b30 287 SetTID(nTID);
lesmin 0:32c20cfb2b30 288 }
lesmin 0:32c20cfb2b30 289
lesmin 0:32c20cfb2b30 290 int nRet = GMMP_SetProfile(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID, pszDeviceID);
lesmin 0:32c20cfb2b30 291
lesmin 0:32c20cfb2b30 292 return nRet;
lesmin 0:32c20cfb2b30 293 }
lesmin 0:32c20cfb2b30 294
lesmin 0:32c20cfb2b30 295 int GO_Delivery(const char* pszGWID,
lesmin 0:32c20cfb2b30 296 const char* pszDeviceID,
lesmin 0:32c20cfb2b30 297 const char cReportType,
lesmin 0:32c20cfb2b30 298 const char cMediaType,
lesmin 0:32c20cfb2b30 299 const char* pszMessageBody)
lesmin 0:32c20cfb2b30 300 {
lesmin 0:32c20cfb2b30 301 SetTID(GetTID()+1);
lesmin 0:32c20cfb2b30 302
lesmin 0:32c20cfb2b30 303 int nRet = GMMP_SetDelivery(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID, pszDeviceID, cReportType, cMediaType, pszMessageBody, 1, 1);
lesmin 0:32c20cfb2b30 304
lesmin 0:32c20cfb2b30 305 return nRet;
lesmin 0:32c20cfb2b30 306 }
lesmin 0:32c20cfb2b30 307
lesmin 0:32c20cfb2b30 308 int GO_Control(const char* pszGWID,
lesmin 0:32c20cfb2b30 309 const char* pszDeviceID,
lesmin 0:32c20cfb2b30 310 long nTID,
lesmin 0:32c20cfb2b30 311 const char cControlType,
lesmin 0:32c20cfb2b30 312 const char cResultCode)
lesmin 0:32c20cfb2b30 313 {
lesmin 0:32c20cfb2b30 314 SetTID(nTID);
lesmin 0:32c20cfb2b30 315
lesmin 0:32c20cfb2b30 316 return GMMP_SetControl(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID, pszDeviceID, cControlType, cResultCode);
lesmin 0:32c20cfb2b30 317 }
lesmin 0:32c20cfb2b30 318
lesmin 0:32c20cfb2b30 319 int GO_Notifi(const char* pszGWID,
lesmin 0:32c20cfb2b30 320 const char* pszDeviceID,
lesmin 0:32c20cfb2b30 321 const char cControlType,
lesmin 0:32c20cfb2b30 322 const char cResultCode,
lesmin 0:32c20cfb2b30 323 const char* pszMessageBody,
lesmin 0:32c20cfb2b30 324 const int nMessageBodySize)
lesmin 0:32c20cfb2b30 325 {
lesmin 0:32c20cfb2b30 326 int nRet = GMMP_SetNotifi(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID, pszDeviceID, cControlType, cResultCode, pszMessageBody, nMessageBodySize);
lesmin 0:32c20cfb2b30 327
lesmin 0:32c20cfb2b30 328 return nRet;
lesmin 0:32c20cfb2b30 329 }
lesmin 0:32c20cfb2b30 330
lesmin 0:32c20cfb2b30 331 int GO_HB(const char* pszGWID)
lesmin 0:32c20cfb2b30 332 {
lesmin 0:32c20cfb2b30 333 int nRet = GMMP_SetHB(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID);
lesmin 0:32c20cfb2b30 334
lesmin 0:32c20cfb2b30 335 return nRet;
lesmin 0:32c20cfb2b30 336 }
lesmin 0:32c20cfb2b30 337
lesmin 0:32c20cfb2b30 338 int OG_Reg_Recv(GMMPHeader* pstGMMPHeader, stGwRegistrationRspHdr* pstGWBody, stDeviceRegistrationRspHdr* pstDeviceBody)
lesmin 0:32c20cfb2b30 339 {
lesmin 0:32c20cfb2b30 340 int nRet = 0;
lesmin 0:32c20cfb2b30 341
lesmin 0:32c20cfb2b30 342 if(g_CallFunctionRegRecv != NULL)
lesmin 0:32c20cfb2b30 343 {
lesmin 0:32c20cfb2b30 344 if(pstGWBody != NULL)
lesmin 0:32c20cfb2b30 345 {
lesmin 0:32c20cfb2b30 346 nRet= (*g_CallFunctionRegRecv)(pstGMMPHeader, pstGWBody);
lesmin 0:32c20cfb2b30 347
lesmin 0:32c20cfb2b30 348 if(nRet != GMMP_SUCCESS)
lesmin 0:32c20cfb2b30 349 {
lesmin 0:32c20cfb2b30 350 return nRet;
lesmin 0:32c20cfb2b30 351 }
lesmin 0:32c20cfb2b30 352 }
lesmin 0:32c20cfb2b30 353 else
lesmin 0:32c20cfb2b30 354 {
lesmin 0:32c20cfb2b30 355 nRet = (*g_CallFunctionRegRecv)(pstGMMPHeader, pstDeviceBody);
lesmin 0:32c20cfb2b30 356
lesmin 0:32c20cfb2b30 357 if(nRet != GMMP_SUCCESS)
lesmin 0:32c20cfb2b30 358 {
lesmin 0:32c20cfb2b30 359 return nRet;
lesmin 0:32c20cfb2b30 360 }
lesmin 0:32c20cfb2b30 361 }
lesmin 0:32c20cfb2b30 362 }
lesmin 0:32c20cfb2b30 363
lesmin 0:32c20cfb2b30 364 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 365 }
lesmin 0:32c20cfb2b30 366
lesmin 0:32c20cfb2b30 367 int OG_DeReg_Recv(GMMPHeader* pstGMMPHeader, stGwDeRegistrationRspHdr* pstGWBody, stDeviceDeRegistrationRspHdr* pstDeviceBody)
lesmin 0:32c20cfb2b30 368 {
lesmin 0:32c20cfb2b30 369 if(g_CallFunctionRegRecv != NULL)
lesmin 0:32c20cfb2b30 370 {
lesmin 0:32c20cfb2b30 371 if(pstGWBody != NULL)
lesmin 0:32c20cfb2b30 372 {
lesmin 0:32c20cfb2b30 373 return (*g_CallFunctionRegRecv)(pstGMMPHeader, pstGWBody);
lesmin 0:32c20cfb2b30 374 }
lesmin 0:32c20cfb2b30 375 else
lesmin 0:32c20cfb2b30 376 {
lesmin 0:32c20cfb2b30 377 return (*g_CallFunctionRegRecv)(pstGMMPHeader, pstDeviceBody);
lesmin 0:32c20cfb2b30 378 }
lesmin 0:32c20cfb2b30 379 }
lesmin 0:32c20cfb2b30 380
lesmin 0:32c20cfb2b30 381 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 382 }
lesmin 0:32c20cfb2b30 383
lesmin 0:32c20cfb2b30 384 int OG_Profile_Recv(GMMPHeader* pstGMMPHeader, stProfileRspHdr* pstBody)
lesmin 0:32c20cfb2b30 385 {
lesmin 0:32c20cfb2b30 386 if(g_CallFunctionRegRecv != NULL)
lesmin 0:32c20cfb2b30 387 {
lesmin 0:32c20cfb2b30 388 return (*g_CallFunctionRegRecv)(pstGMMPHeader, pstBody);
lesmin 0:32c20cfb2b30 389 }
lesmin 0:32c20cfb2b30 390
lesmin 0:32c20cfb2b30 391 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 392 }
lesmin 0:32c20cfb2b30 393
lesmin 0:32c20cfb2b30 394 int OG_Delivery_Recv(GMMPHeader* pstGMMPHeader, stPacketDeliveryRspHdr* pstBody)
lesmin 0:32c20cfb2b30 395 {
lesmin 0:32c20cfb2b30 396 if(g_CallFunctionRegRecv != NULL)
lesmin 0:32c20cfb2b30 397 {
lesmin 0:32c20cfb2b30 398 return (*g_CallFunctionRegRecv)(pstGMMPHeader, pstBody);
lesmin 0:32c20cfb2b30 399 }
lesmin 0:32c20cfb2b30 400
lesmin 0:32c20cfb2b30 401 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 402 }
lesmin 0:32c20cfb2b30 403
lesmin 0:32c20cfb2b30 404 int OG_Ctrl_Recv(GMMPHeader* pstGMMPHeader, stControlReqHdr* pstBody)
lesmin 0:32c20cfb2b30 405 {
lesmin 0:32c20cfb2b30 406 if(g_CallFunctionRegRecv != NULL)
lesmin 0:32c20cfb2b30 407 {
lesmin 0:32c20cfb2b30 408 return (*g_CallFunctionRegRecv)(pstGMMPHeader, pstBody);
lesmin 0:32c20cfb2b30 409 }
lesmin 0:32c20cfb2b30 410
lesmin 0:32c20cfb2b30 411 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 412 }
lesmin 0:32c20cfb2b30 413
lesmin 0:32c20cfb2b30 414 int OG_HB_Recv(GMMPHeader* pstGMMPHeader, stHeartBeatMsgRspHdr* pstBody)
lesmin 0:32c20cfb2b30 415 {
lesmin 0:32c20cfb2b30 416 if(g_CallFunctionRegRecv != NULL)
lesmin 0:32c20cfb2b30 417 {
lesmin 0:32c20cfb2b30 418 return (*g_CallFunctionRegRecv)(pstGMMPHeader, pstBody);
lesmin 0:32c20cfb2b30 419 }
lesmin 0:32c20cfb2b30 420
lesmin 0:32c20cfb2b30 421 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 422 }
lesmin 0:32c20cfb2b30 423
lesmin 0:32c20cfb2b30 424 int OG_Notifi_Recv(GMMPHeader* pstGMMPHeader, stNotificationRspHdr* pstBody)
lesmin 0:32c20cfb2b30 425 {
lesmin 0:32c20cfb2b30 426 if(g_CallFunctionRegRecv != NULL)
lesmin 0:32c20cfb2b30 427 {
lesmin 0:32c20cfb2b30 428 return (*g_CallFunctionRegRecv)(pstGMMPHeader, pstBody);
lesmin 0:32c20cfb2b30 429 }
lesmin 0:32c20cfb2b30 430
lesmin 0:32c20cfb2b30 431 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 432 }
lesmin 0:32c20cfb2b30 433
lesmin 0:32c20cfb2b30 434 int GetReadData(GMMPHeader* pstGMMPHeader, void** pBody)
lesmin 0:32c20cfb2b30 435 {
lesmin 0:32c20cfb2b30 436 int nHeaderCound = 0;
lesmin 0:32c20cfb2b30 437 int nRet = 0;
lesmin 0:32c20cfb2b30 438
lesmin 0:32c20cfb2b30 439 while(true)
lesmin 0:32c20cfb2b30 440 {
lesmin 0:32c20cfb2b30 441 nRet = GMMP_Read(pstGMMPHeader, pBody);
lesmin 0:32c20cfb2b30 442 if(nRet == GMMP_HEADER_SIZE_ERROR) {
lesmin 0:32c20cfb2b30 443 if(nHeaderCound > 3) {
lesmin 0:32c20cfb2b30 444 break;
lesmin 0:32c20cfb2b30 445 }
lesmin 0:32c20cfb2b30 446 nHeaderCound++;
lesmin 0:32c20cfb2b30 447 continue;
lesmin 0:32c20cfb2b30 448 }
lesmin 0:32c20cfb2b30 449 else if(nRet == GMMP_SUCCESS) {
lesmin 0:32c20cfb2b30 450 break;
lesmin 0:32c20cfb2b30 451 }
lesmin 0:32c20cfb2b30 452 else {
lesmin 0:32c20cfb2b30 453 return nRet;
lesmin 0:32c20cfb2b30 454 }
lesmin 0:32c20cfb2b30 455 }
lesmin 0:32c20cfb2b30 456
lesmin 0:32c20cfb2b30 457 GMMP_Recv(pstGMMPHeader, *pBody);
lesmin 0:32c20cfb2b30 458
lesmin 0:32c20cfb2b30 459 return nRet;
lesmin 0:32c20cfb2b30 460 }
lesmin 0:32c20cfb2b30 461
lesmin 0:32c20cfb2b30 462 long Char2int(void* pBuffer, int nSize)
lesmin 0:32c20cfb2b30 463 {
lesmin 0:32c20cfb2b30 464 if(nSize != sizeof(long)) {
lesmin 0:32c20cfb2b30 465 return 0;
lesmin 0:32c20cfb2b30 466 }
lesmin 0:32c20cfb2b30 467
lesmin 0:32c20cfb2b30 468 long nInt = 0;
lesmin 0:32c20cfb2b30 469 memcpy(&nInt, pBuffer, sizeof(long));
lesmin 0:32c20cfb2b30 470 return btoli(nInt);
lesmin 0:32c20cfb2b30 471 }
lesmin 0:32c20cfb2b30 472
lesmin 0:32c20cfb2b30 473 int Char2short(void* pBuffer, short nSize)
lesmin 0:32c20cfb2b30 474 {
lesmin 0:32c20cfb2b30 475 if(nSize != sizeof(short)) {
lesmin 0:32c20cfb2b30 476 return 0;
lesmin 0:32c20cfb2b30 477 }
lesmin 0:32c20cfb2b30 478
lesmin 0:32c20cfb2b30 479 short nShort = 0;
lesmin 0:32c20cfb2b30 480 memcpy(&nShort, pBuffer, sizeof(short));
lesmin 0:32c20cfb2b30 481 return btols(nShort);
lesmin 0:32c20cfb2b30 482 }
lesmin 0:32c20cfb2b30 483
lesmin 0:32c20cfb2b30 484 void InitMemory()
lesmin 0:32c20cfb2b30 485 {
lesmin 3:e841a647d1df 486 memset(g_szDomainCode, 0 , sizeof(g_szDomainCode)); //patch
lesmin 0:32c20cfb2b30 487 memset(g_szAuthID, 0 , sizeof(g_szAuthID));
lesmin 0:32c20cfb2b30 488 memset(g_szAuthKey, 0 , sizeof(g_szAuthKey));
lesmin 0:32c20cfb2b30 489 memset(g_szGWID, 0 , sizeof(g_szGWID));
lesmin 0:32c20cfb2b30 490
lesmin 0:32c20cfb2b30 491 g_nServerPort = 0;
lesmin 0:32c20cfb2b30 492
lesmin 0:32c20cfb2b30 493 g_CallFunctionRegRecv = NULL;
lesmin 0:32c20cfb2b30 494 }
lesmin 0:32c20cfb2b30 495
lesmin 0:32c20cfb2b30 496 #endif