Module_OcppBackend.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  1. #include <sys/time.h>
  2. #include <sys/timeb.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <sys/ioctl.h>
  6. #include <sys/socket.h>
  7. #include <sys/ipc.h>
  8. #include <sys/shm.h>
  9. #include <sys/shm.h>
  10. #include <sys/mman.h>
  11. #include <linux/wireless.h>
  12. #include <linux/sockios.h>
  13. #include <linux/socket.h>
  14. #include <arpa/inet.h>
  15. #include <netinet/in.h>
  16. #include <unistd.h>
  17. #include <stdarg.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #include <fcntl.h>
  22. #include <termios.h>
  23. #include <errno.h>
  24. #include <errno.h>
  25. #include <string.h>
  26. #include <time.h>
  27. #include <ctype.h>
  28. #include <ifaddrs.h>
  29. #include "libwebsockets.h"
  30. #include <lws_config.h>
  31. #include "hashmap.h"
  32. #include "SystemLogMessage.h"
  33. #include "ShareMemory.h"
  34. #include <pthread.h>
  35. #include "MessageHandler.h"
  36. #include "sqlite3.h"
  37. #if 0
  38. #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  39. #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  40. #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  41. #endif
  42. #define Debug
  43. //#define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  44. #define PASS 1
  45. #define FAIL -1
  46. typedef enum boolean { FALSE, TRUE } BOOL;
  47. struct lws *wsi_client;
  48. struct lws_context *context;
  49. static int sendbuffer = 0;
  50. extern int server_sign;
  51. //extern int server_pending;
  52. //extern struct OCPP16Data *ShmOCPP16Data;
  53. extern void CheckSystemValue(void);
  54. //extern int TransactionMessageAttemptsGet(void);
  55. extern int FirstHeartBeatResponse(void);
  56. extern void OCPP_get_TableAuthlocalAllData(void);
  57. pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
  58. pthread_mutex_t lock_sentData = PTHREAD_MUTEX_INITIALIZER;
  59. //struct json_object *parsed_json;
  60. //extern struct node Node;
  61. //==========================================
  62. // Function prototype
  63. //==========================================
  64. void trim(char *s);
  65. int mystrcmp(char *p1,char *p2);
  66. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
  67. void getSubStr(char *dest, char* src, char *split, int idx);
  68. void split(char **arr, char *str, const char *del);
  69. int strpos(char *source, char *substr, int skip);
  70. int strposs(char *source, char *substr, int idx);
  71. char *random_uuid( char buf[37] );
  72. static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len);
  73. char * strchr(const char *p, int ch);
  74. void* processTransactionQueue(void* data);
  75. void ReceivedMessage(void *in, size_t len);
  76. struct StartTime
  77. {
  78. unsigned int connect;
  79. unsigned int bootNotification;
  80. }startTime;
  81. #if 0
  82. unsigned char *SendBuffer;
  83. int SendBufLen=(1024*4);//(1024*3);
  84. #endif
  85. int SendBufLen=(1024*4);//(1024*3);
  86. unsigned char SendBuffer[1024*4]={0};
  87. static int ConnectionEstablished=0;
  88. static int TransactionQueueInterval = 10;//3; // TransactionMessageAttempts
  89. static int TransactionQueueNum = 0;
  90. int defaultWaitingTime = 10; //10 second
  91. extern int BootNotificationInterval;
  92. //char guid[37];
  93. //map_t hashMap;
  94. //data_struct_t* mapItem; --- remove for temporally
  95. //data_struct_t mapItem[0]={0};
  96. sqlite3 *db;
  97. char *errMsg = NULL;
  98. static char *createsql = "CREATE TABLE IF NOT EXISTS log_buffer("
  99. "idx integer primary key,"
  100. "user_id text,"
  101. "cmd_sn text,"
  102. "charger_id text,"
  103. "gun_type text,"
  104. "gun_no text,"
  105. "rfid_no text,"
  106. "stime text,"
  107. "etime text,"
  108. "time_len text,"
  109. "s_soc text,"
  110. "e_soc text,"
  111. "stop_reason text,"
  112. "power text,"
  113. "meter_before text,"
  114. "meter_after text,"
  115. "charge_price text,"
  116. "reserve text,"
  117. "surplus_before text,"
  118. "surplus_after text,"
  119. "service_price text,"
  120. "is_pay text,"
  121. "charge_strategy text,"
  122. "charge_parameter text,"
  123. "vin text,"
  124. "vehicle_no text,"
  125. "start_method text,"
  126. "card_type text,"
  127. "is_upload text,"
  128. "guid text UNIQUE,"
  129. "is_buf2OK text);";
  130. #if 0
  131. static char *createsChargingRecordsql = "CREATE TABLE IF NOT EXISTS ChargingRecord("
  132. "idx integer primary key,"
  133. "gun_type text,"
  134. "connectorId text,"
  135. "idTag text,"
  136. "transactionId text,"
  137. "stime text,"
  138. "etime text,"
  139. "time_len text,"
  140. "s_soc text,"
  141. "e_soc text,"
  142. "stop_reason text,"
  143. "power text,"
  144. "meter_before text,"
  145. "meter_after text,"
  146. "reservationId text,"
  147. "guid text UNIQUE);";
  148. //"is_buf2OK text);";
  149. #endif
  150. static char *sqlOcppAuthCache = "create table if not exists ocpp_auth_cache (idx integer primary key,"
  151. "idtag text UNIQUE,"
  152. "parent_idtag text,"
  153. "expir_date text,"
  154. "status text);";
  155. static char *sqlOcppAuthLocal = "create table if not exists ocpp_auth_local (idx integer primary key,"
  156. "idtag text UNIQUE,"
  157. "parent_idtag text,"
  158. "expir_date text,"
  159. "status text,"
  160. "version text);";
  161. #if 0
  162. static char *sqlInitialOcppAuthLocal = "insert or replace into ocpp_auth_local(idtag, parent_idtag, expir_date, status, version) values('PaHdImHiOnNG','none','2099-12-31T23:59:59.999Z','Accepted','0')";
  163. #endif
  164. int DiffTimeb(struct timeb ST, struct timeb ET)
  165. {
  166. //return milli-second
  167. unsigned int StartTime,StopTime;
  168. StartTime=(unsigned int)ST.time;
  169. StopTime=(unsigned int)ET.time;
  170. return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  171. }
  172. //=================================
  173. // Common routine
  174. //=================================
  175. void trim(char *s)
  176. {
  177. int i=0, j, k, l=0;
  178. while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
  179. i++;
  180. j = strlen(s)-1;
  181. while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
  182. j--;
  183. if(i==0 && j==strlen(s)-1) { }
  184. else if(i==0) s[j+1] = '\0';
  185. else {
  186. for(k=i; k<=j; k++) s[l++] = s[k];
  187. s[l] = '\0';
  188. }
  189. }
  190. int mystrcmp(char *p1,char *p2)
  191. {
  192. while(*p1==*p2)
  193. {
  194. if(*p1=='\0' || *p2=='\0')
  195. break;
  196. p1++;
  197. p2++;
  198. }
  199. if(*p1=='\0' && *p2=='\0')
  200. return(PASS);
  201. else
  202. return(FAIL);
  203. }
  204. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
  205. {
  206. strncpy(dest, src + start, cnt);
  207. dest[cnt] = 0;
  208. }
  209. void getSubStr(char *dest, char* src, char *split, int idx)
  210. {
  211. int start = (strposs(src,",",idx)+1);
  212. int cnt = (strposs(src,",",idx+1)-2)-(strposs(src,",",idx)+1);
  213. strncpy(dest, src + start, cnt);
  214. dest[cnt] = 0;
  215. }
  216. void split(char **arr, char *str, const char *del)
  217. {
  218. char *s = strtok(str, del);
  219. while(s != NULL)
  220. {
  221. *arr++ = s;
  222. s = strtok(NULL, del);
  223. }
  224. }
  225. int strpos(char *source, char *substr, int skip)
  226. {
  227. char stack[strlen(source)];
  228. strncpy(stack, source+skip, strlen(source)-skip);
  229. char *p = strstr(stack, substr);
  230. if (p)
  231. return p - stack+skip;
  232. return -1;
  233. }
  234. int strposs(char *source, char *substr, int idx)
  235. {
  236. char stack[strlen(source)];
  237. int result=0;
  238. int count=0;
  239. while(count<=idx)
  240. {
  241. memset(stack,0,sizeof stack);
  242. strncpy(stack, source+result, strlen(source)-result);
  243. int loc = strcspn(stack, substr);
  244. if(loc>0)
  245. result += (loc+1);
  246. else
  247. result = -1;
  248. count++;
  249. }
  250. return result;
  251. }
  252. char *random_uuid( char buf[37] )
  253. {
  254. const char *c = "89ab";
  255. char *p = buf;
  256. int n;
  257. for( n = 0; n < 16; ++n )
  258. {
  259. int b = rand()%255;
  260. switch( n )
  261. {
  262. case 6:
  263. sprintf(p, "4%x", b%15 );
  264. break;
  265. case 8:
  266. sprintf(p, "%c%x", c[rand()%strlen(c)], b%15 );
  267. break;
  268. default:
  269. sprintf(p, "%02x", b);
  270. break;
  271. }
  272. p += 2;
  273. switch( n )
  274. {
  275. case 3:
  276. case 5:
  277. case 7:
  278. case 9:
  279. *p++ = '-';
  280. break;
  281. }
  282. }
  283. *p = 0;
  284. return buf;
  285. }
  286. //==========================================
  287. // Web socket tranceive routine
  288. //==========================================
  289. int SendData(struct lws *wsi)
  290. {
  291. int n;
  292. int len;
  293. unsigned char out[LWS_SEND_BUFFER_PRE_PADDING + 4096 + LWS_SEND_BUFFER_POST_PADDING] = {0};
  294. len = strlen((char *)SendBuffer);
  295. if(len == 0)
  296. return 0;
  297. memcpy (out + LWS_SEND_BUFFER_PRE_PADDING, SendBuffer, len );
  298. DEBUG_INFO("out + LWS_SEND_BUFFER_PRE_PADDING = %s\n", out + LWS_SEND_BUFFER_PRE_PADDING);
  299. n = lws_write(wsi, out + LWS_SEND_BUFFER_PRE_PADDING, len, LWS_WRITE_TEXT);
  300. memset(SendBuffer, 0, len);
  301. return n;
  302. }
  303. static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
  304. {
  305. switch (reason)
  306. {
  307. case LWS_CALLBACK_PROTOCOL_INIT:
  308. #ifdef SystemLogMessage
  309. DEBUG_INFO("LWS_CALLBACK_PROTOCOL_INIT\n");
  310. #endif
  311. break;
  312. case LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH:
  313. #ifdef SystemLogMessage
  314. DEBUG_INFO("LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH\n");
  315. #endif
  316. break;
  317. case LWS_CALLBACK_CLOSED_CLIENT_HTTP:
  318. #ifdef SystemLogMessage
  319. DEBUG_INFO("LWS_CALLBACK_CLOSED_CLIENT_HTTP\n");
  320. #endif
  321. break;
  322. case LWS_CALLBACK_WSI_DESTROY:
  323. #ifdef SystemLogMessage
  324. DEBUG_INFO("LWS_CALLBACK_WSI_DESTROY\n");
  325. #endif
  326. server_sign = FALSE;
  327. break;
  328. case LWS_CALLBACK_LOCK_POLL:
  329. #ifdef SystemLogMessage
  330. //DEBUG_INFO("LWS_CALLBACK_LOCK_POLL\n");
  331. #endif
  332. break;
  333. case LWS_CALLBACK_ADD_POLL_FD:
  334. #ifdef SystemLogMessage
  335. DEBUG_INFO("LWS_CALLBACK_ADD_POLL_FD\n");
  336. #endif
  337. break;
  338. case LWS_CALLBACK_DEL_POLL_FD:
  339. #ifdef SystemLogMessage
  340. DEBUG_INFO("LWS_CALLBACK_DEL_POLL_FD\n");
  341. #endif
  342. break;
  343. case LWS_CALLBACK_UNLOCK_POLL:
  344. #ifdef SystemLogMessage
  345. //DEBUG_INFO("LWS_CALLBACK_UNLOCK_POLL\n");
  346. #endif
  347. break;
  348. case LWS_CALLBACK_CHANGE_MODE_POLL_FD:
  349. #ifdef SystemLogMessage
  350. //DEBUG_INFO("LWS_CALLBACK_CHANGE_MODE_POLL_FD\n");
  351. #endif
  352. break;
  353. case LWS_CALLBACK_WSI_CREATE:
  354. #ifdef SystemLogMessage
  355. DEBUG_INFO("LWS_CALLBACK_WSI_CREATE\n");
  356. #endif
  357. break;
  358. case LWS_CALLBACK_GET_THREAD_ID:
  359. //#ifdef SystemLogMessage
  360. //DEBUG_INFO("LWS_CALLBACK_GET_THREAD_ID\n");
  361. //#endif
  362. break;
  363. case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER:
  364. #ifdef SystemLogMessage
  365. DEBUG_INFO("LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER\n");
  366. #endif
  367. break;
  368. case LWS_CALLBACK_CLIENT_ESTABLISHED://3
  369. #ifdef SystemLogMessage
  370. DEBUG_INFO("LWS_CALLBACK_CLIENT_ESTABLISHED\n");
  371. #endif
  372. //connected
  373. ConnectionEstablished=1;
  374. break;
  375. case LWS_CALLBACK_CLIENT_CONNECTION_ERROR://1
  376. #ifdef Debug
  377. DEBUG_ERROR("LWS_CALLBACK_CLIENT_CONNECTION_ERROR:%s\n",in);
  378. #endif
  379. #ifdef SystemLogMessage
  380. DEBUG_ERROR("LWS_CALLBACK_CLIENT_CONNECTION_ERROR\n");
  381. #endif
  382. //disconnected
  383. ConnectionEstablished=0;
  384. break;
  385. case LWS_CALLBACK_CLOSED://4
  386. #ifdef SystemLogMessage
  387. DEBUG_INFO("LWS_CALLBACK_CLOSED\n");
  388. ConnectionEstablished=0;
  389. #endif
  390. //disconnected
  391. break;
  392. case LWS_CALLBACK_CLIENT_WRITEABLE://10
  393. //if(need to send message and its relevant data already store into SendBuffer)
  394. #ifdef SystemLogMessage
  395. DEBUG_INFO("LWS_CALLBACK_CLIENT_WRITEABLE\n");
  396. #endif
  397. SendData(wsi);
  398. break;
  399. case LWS_CALLBACK_CLIENT_RECEIVE://8
  400. ((char *)in)[len] = '\0';
  401. #ifdef SystemLogMessage
  402. DEBUG_INFO("LWS_CALLBACK_CLIENT_RECEIVE, RX length: %d\n", (int)len);
  403. //DEBUG_INFO("Message: %s\n", (char *)in);
  404. #endif
  405. ReceivedMessage(in, len);
  406. break;
  407. default:
  408. #ifdef Debug
  409. DEBUG_INFO("OCPP16Callback:reason=%d\n", reason);
  410. #endif
  411. break;
  412. }
  413. return 0;
  414. }
  415. static struct lws_protocols protocols[] = {
  416. {
  417. "ocpp1.6",
  418. OCPP16Callback,
  419. 10240,
  420. 10240,
  421. },
  422. {
  423. "ocpp1.6",
  424. OCPP16Callback,
  425. 10240,
  426. 10240,
  427. },
  428. {
  429. NULL, NULL, 0 // End of list
  430. }
  431. };
  432. int ConnectWsServer()
  433. {
  434. int result = PASS;
  435. struct lws_context_creation_info ContextInfo;
  436. struct lws_client_connect_info ConnInfo;
  437. int use_ssl=0;
  438. //lws_set_log_level(LLL_PARSER | LLL_HEADER, NULL);
  439. if(context!=NULL)
  440. lws_context_destroy(context);
  441. memset(&ContextInfo, 0, sizeof(struct lws_context_creation_info));
  442. ContextInfo.port = CONTEXT_PORT_NO_LISTEN;
  443. ContextInfo.iface = NULL;
  444. ContextInfo.ssl_private_key_password = NULL;
  445. ContextInfo.ssl_cert_filepath = NULL;
  446. ContextInfo.ssl_private_key_filepath = NULL;
  447. ContextInfo.ssl_ca_filepath = "/root/cacert.pem";
  448. ContextInfo.ssl_cipher_list = NULL; //use default one
  449. ContextInfo.gid = -1;
  450. ContextInfo.uid = -1;
  451. if(use_ssl)
  452. ContextInfo.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
  453. ContextInfo.protocols = protocols;
  454. ContextInfo.timeout_secs = 9999;//30;
  455. //if(ping pong enabled)
  456. ContextInfo.ws_ping_pong_interval = 30;//0 for none, else interval in seconds
  457. context = lws_create_context(&ContextInfo);
  458. if (context == NULL)
  459. {
  460. #ifdef SystemLogMessage
  461. DEBUG_ERROR("lws_create_context NG");
  462. #endif
  463. result = FAIL;
  464. }
  465. memset(&ConnInfo,0,sizeof(struct lws_client_connect_info));
  466. // fill up below information
  467. ConnInfo.context = context;
  468. ConnInfo.address=(const char *)GetOcppServerURL();//"172.17.40.13";//"192.168.137.1";//"192.168.201.202";//"172.1.0.109";//"172.17.40.13";//"192.168.201.202";//"192.168.10.125";
  469. ConnInfo.port = GetOcppPort();//2012;//8080;
  470. ConnInfo.path=(const char *)GetOcppPath();//"/ocpp/RDTEST103";//"/ocpp/OCTT_1";//"/RDTEST103";//"/0591201511030003";//"/RDTEST103";
  471. ConnInfo.host=lws_canonical_hostname(context);
  472. ConnInfo.origin="origin";
  473. ConnInfo.protocol = protocols[1].name;
  474. ConnInfo.ietf_version_or_minus_one = -1;
  475. if(use_ssl)
  476. ConnInfo.ssl_connection = LCCSCF_USE_SSL | LCCSCF_ALLOW_SELFSIGNED | LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK;;
  477. wsi_client = lws_client_connect_via_info(&ConnInfo);
  478. if (!wsi_client)
  479. {
  480. #ifdef SystemLogMessage
  481. DEBUG_ERROR("lws_client_connect_via_info NG");
  482. #endif
  483. result = FAIL;
  484. }
  485. return result;
  486. }
  487. #if 0
  488. struct _node {
  489. char uuid[37];
  490. char data[2000];
  491. struct _node *next;//struct node *next;
  492. }node;
  493. typedef struct _node *pnode;
  494. struct _node staticNodeArray[100]={0};
  495. #endif
  496. //void createq();
  497. int showfront(char *uuid, char *data);
  498. int addq(char *uuid, char *data) ;
  499. int delq();
  500. int sentqueue();
  501. #if 0
  502. int storequeue();
  503. int readfiletoqueue();
  504. #endif
  505. void CheckTransactionPacket(char *uuid);
  506. int queue_operation(int type, char *frontUUID, char *frontData);
  507. #if 0
  508. pnode front, rear;
  509. void createq() {
  510. //front = rear = (pnode)malloc(sizeof(node)); --- remove temporally
  511. //front->next = rear->next = NULL;
  512. front = rear = NULL;
  513. }
  514. #endif
  515. int showfront(char *uuid, char *data) {
  516. FILE *fp;
  517. int result = FALSE; // 1: TRUE 0:FALSE
  518. char str[1200]={0};
  519. char sstr[50]={ 0 };//sstr[200]={ 0 };
  520. int c = 0;
  521. char *loc;
  522. char rmFileCmd[100]={0};
  523. struct stat stats;
  524. stat("../Storage/OCPP", &stats);
  525. // Check for directory existence
  526. if (S_ISDIR(stats.st_mode) == 1)
  527. {
  528. DEBUG_INFO("\n OCPP directory exist \n");
  529. }
  530. else
  531. {
  532. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  533. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  534. system(rmFileCmd);
  535. }
  536. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  537. if((access("../Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
  538. {
  539. DEBUG_INFO("TransactionRelatedQueue exist.\n");
  540. }
  541. else
  542. {
  543. DEBUG_INFO("TransactionRelatedQueue not exist\n");
  544. FILE *log = fopen("../Storage/OCPP/TransactionRelatedQueue", "w+");
  545. if(log == NULL)
  546. {
  547. DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  548. return 0;
  549. }
  550. else
  551. {
  552. fclose(log);
  553. }
  554. }
  555. //opening file for reading
  556. fp = fopen("../Storage/OCPP/TransactionRelatedQueue" , "r");
  557. if(fp == NULL) {
  558. DEBUG_INFO("Error opening TransactionRelatedQueue file");
  559. return FALSE;
  560. }
  561. printf("test\n");
  562. if( fgets (str, 1200, fp)!=NULL ) {
  563. /* writing content to stdout */
  564. if (str[0] == '\n')
  565. {
  566. DEBUG_INFO("It is a blank line");
  567. fclose(fp);
  568. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  569. sprintf(rmFileCmd,"rm -f %s","../Storage/OCPP/TransactionRelatedQueue");
  570. system(rmFileCmd);
  571. result = FALSE;
  572. return result;
  573. }
  574. else
  575. {
  576. puts(str);
  577. /*********************uuid***************/
  578. loc = strstr(str, "\"");
  579. memset(sstr ,0, sizeof(sstr) );
  580. c = 0;
  581. while (loc[1+c] != '\"')
  582. {
  583. sstr[c] = loc[1+c];
  584. c++;
  585. }
  586. sstr[c] = '\0';
  587. DEBUG_INFO("\n uuid:%s", sstr);
  588. DEBUG_INFO("\n data:%s", str);
  589. strcpy(uuid,sstr);
  590. strcpy(data,str);
  591. result = TRUE;
  592. }
  593. //return 1;
  594. }
  595. else
  596. {
  597. DEBUG_INFO("queue is null\n");
  598. strcpy(uuid,"");
  599. strcpy(data,"");
  600. result = FALSE;
  601. //return 0;
  602. }
  603. fclose(fp);
  604. return result;
  605. #if 0
  606. pnode p;
  607. p = front;
  608. if(p)
  609. {
  610. //printf("姓å? %s ?»è©± %s\n", p->name, p->phone);
  611. printf("\n uuid:%s", p->uuid);
  612. printf("\n data:%s", p->data);
  613. strcpy(uuid,p->uuid);
  614. strcpy(data,p->data);
  615. return 1;
  616. }
  617. else
  618. {
  619. printf("queue is null\n");
  620. strcpy(uuid,"");
  621. strcpy(data,"");
  622. return 0;
  623. }
  624. #endif
  625. }
  626. int addq(char *uuid, char *data) {
  627. FILE *outfile;
  628. char rmFileCmd[100]={0};
  629. struct stat stats;
  630. stat("../Storage/OCPP", &stats);
  631. DEBUG_INFO("addq\n");
  632. // Check for directory existence
  633. if (S_ISDIR(stats.st_mode) == 1)
  634. {
  635. DEBUG_INFO("\n OCPP directory exist \n");
  636. }
  637. else
  638. {
  639. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  640. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  641. system(rmFileCmd);
  642. }
  643. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  644. if((access("../Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
  645. {
  646. DEBUG_INFO("TransactionRelatedQueue exist.\n");
  647. }
  648. else
  649. {
  650. DEBUG_INFO("TransactionRelatedQueue not exist\n");
  651. FILE *log = fopen("../Storage/OCPP/TransactionRelatedQueue", "w+");
  652. if(log == NULL)
  653. {
  654. DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  655. return 0;
  656. }
  657. else
  658. {
  659. fclose(log);
  660. }
  661. }
  662. // open file for writing
  663. outfile = fopen ("../Storage/OCPP/TransactionRelatedQueue", "a");
  664. DEBUG_INFO("data=%s\n",data);
  665. fputs(data, outfile);
  666. fputs("\n", outfile);
  667. fclose (outfile);
  668. TransactionQueueNum = TransactionQueueNum + 1;
  669. return 0;
  670. #if 0
  671. //pnode p = (pnode )malloc(sizeof(node)); --- remove temporally
  672. int nodeCurrentFreeIndex =0;
  673. for (int i = 0; i < 100; i++) // Worst case 100+1
  674. if (staticNodeArray[i].uuid[0] == 0) // Worst case 100
  675. nodeCurrentFreeIndex = i;
  676. pnode p = &staticNodeArray[nodeCurrentFreeIndex];
  677. memset(p, 0, sizeof(node));
  678. if(p)
  679. {
  680. strcpy(p->uuid, uuid);
  681. strcpy(p->data, data);
  682. //printf("請輸?¥å???");
  683. //scanf("%s", p->name);
  684. //printf("請輸?¥é›»è©?");
  685. //scanf("%s", p->phone);
  686. p->next = NULL;
  687. if(rear)
  688. {
  689. rear->next = p;
  690. rear = p;
  691. }
  692. else
  693. {
  694. front = rear = p;
  695. }
  696. }
  697. else
  698. {
  699. printf("?¡æ??–å?記憶體空?“新增è??™\n");
  700. }
  701. #endif
  702. }
  703. int delq() {
  704. char tempfile[] = "../Storage/OCPP/temp.json";
  705. FILE *infile;
  706. FILE *outfile;
  707. int resultRename=0;
  708. char filename[60]={0};
  709. char rmFileCmd[100]={0};
  710. struct stat stats;
  711. stat("../Storage/OCPP", &stats);
  712. // Check for directory existence
  713. if (S_ISDIR(stats.st_mode) == 1)
  714. {
  715. DEBUG_INFO("\n OCPP directory exist \n");
  716. }
  717. else
  718. {
  719. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  720. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  721. system(rmFileCmd);
  722. }
  723. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  724. if((access("../Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
  725. {
  726. DEBUG_INFO("TransactionRelatedQueue exist.\n");
  727. }
  728. else
  729. {
  730. DEBUG_INFO("TransactionRelatedQueue not exist\n");
  731. FILE *log = fopen("../Storage/OCPP/TransactionRelatedQueue", "w+");
  732. if(log == NULL)
  733. {
  734. DEBUG_INFO("log is NULL\n");
  735. return 0;
  736. }
  737. else
  738. {
  739. fclose(log);
  740. }
  741. }
  742. // open file for writing
  743. strcpy(filename, "../Storage/OCPP/TransactionRelatedQueue");
  744. infile = fopen ("../Storage/OCPP/TransactionRelatedQueue", "r");
  745. outfile = fopen (tempfile, "w");
  746. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  747. int c;
  748. c = fgetc(infile);
  749. //printf("file c:%d\n",c);
  750. rewind(infile);
  751. if(c == EOF)
  752. {
  753. DEBUG_INFO("TransactionRelatedQueue is NULL\n");
  754. fclose(infile);
  755. fclose(outfile);
  756. sprintf(rmFileCmd,"rm -f %s",tempfile);
  757. system(rmFileCmd);
  758. }
  759. else
  760. {
  761. char buf[1200]={0};
  762. int i = 0;
  763. //DEBUG_INFO("Orignal File is not NULL\n");
  764. while (fgets(buf, sizeof(buf), infile) != NULL)
  765. {
  766. //printf("Orignal File get strings \n");
  767. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  768. if(i==0)
  769. {
  770. TransactionQueueNum = TransactionQueueNum - 1;
  771. }
  772. if(i != 0)
  773. fprintf(outfile,"%s\n", buf);
  774. i = i + 1;
  775. }
  776. fclose(infile);
  777. fclose(outfile);
  778. sprintf(rmFileCmd,"rm -f %s",filename);
  779. system(rmFileCmd);
  780. resultRename = rename(tempfile, filename);
  781. if(resultRename == 0)
  782. {
  783. DEBUG_INFO("TransactionRelatedQueue file renamed successfully");
  784. }
  785. else
  786. {
  787. DEBUG_INFO("Error: unable to rename the TransactionRelatedQueue file");
  788. }
  789. }
  790. return 0;
  791. #if 0
  792. pnode p;
  793. if(front)
  794. {
  795. p = front;
  796. if(front->next)
  797. front = front->next;
  798. else
  799. front = rear = NULL;
  800. printf("delete uuid: %s data: %s\n", p->uuid, p->data);
  801. //free(p); --- remove temporally
  802. //new
  803. memset(p, 0, sizeof(node));
  804. p=NULL;
  805. }
  806. else
  807. {
  808. printf("queue is Empty\n");
  809. printf("\n delete: queue is null");
  810. }
  811. return 0;
  812. #endif
  813. }
  814. int showqueue() {
  815. char rmFileCmd[100]={0};
  816. struct stat stats;
  817. stat("../Storage/OCPP", &stats);
  818. // Check for directory existence
  819. if (S_ISDIR(stats.st_mode) == 1)
  820. {
  821. DEBUG_INFO("\n OCPP directory exist \n");
  822. }
  823. else
  824. {
  825. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  826. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  827. system(rmFileCmd);
  828. }
  829. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  830. if((access("../Storage/OCPP/TransactionRelatedQueue",F_OK))!=-1)
  831. {
  832. DEBUG_INFO("TransactionRelatedQueue exist.\n");
  833. }
  834. else
  835. {
  836. DEBUG_INFO("TransactionRelatedQueue not exist\n");
  837. FILE *log = fopen("../Storage/OCPP/TransactionRelatedQueue", "w+");
  838. if(log == NULL)
  839. {
  840. DEBUG_INFO("log is NULL\n");
  841. return 0;
  842. }
  843. else
  844. {
  845. fclose(log);
  846. }
  847. }
  848. FILE *fp = fopen("../Storage/OCPP/TransactionRelatedQueue", "r");
  849. char line[1200]={0};
  850. // check if file exist (and you can open it) or not
  851. if (fp == NULL) {
  852. DEBUG_INFO("can open file TransactionRelatedQueue!");
  853. return 0;
  854. }
  855. while(fgets(line, sizeof line, fp) != NULL) {
  856. DEBUG_INFO("%s\n", line);
  857. }
  858. fclose(fp);
  859. return 0;
  860. #if 0
  861. pnode p;
  862. p = front;
  863. while(p)
  864. {
  865. printf("uuid: %s data: %s\n", p->uuid, p->data);
  866. p = p->next;
  867. }
  868. return 0;
  869. #endif
  870. }
  871. int sentqueue()
  872. {
  873. FILE *fp;
  874. int result = FALSE; // 1: TRUE 0:FALSE
  875. char str[1200]={0};
  876. char rmFileCmd[100]={0};
  877. struct stat stats;
  878. DEBUG_INFO("sentqueue\n");
  879. stat("../Storage/OCPP", &stats);
  880. // Check for directory existence
  881. if(S_ISDIR(stats.st_mode) == 1)
  882. {
  883. DEBUG_INFO("\n OCPP directory exist \n");
  884. }
  885. else
  886. {
  887. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  888. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  889. system(rmFileCmd);
  890. }
  891. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  892. // opening file for reading
  893. fp = fopen("../Storage/OCPP/TransactionRelatedQueue" , "r");
  894. if(fp == NULL) {
  895. DEBUG_INFO("Error opening file");
  896. return FALSE;
  897. }
  898. if( fgets (str, 1200, fp)!=NULL ) {
  899. //writing content to stdout
  900. //puts(str);
  901. DEBUG_INFO("\n uuid:%s", "");
  902. DEBUG_INFO("\n data:%s", str);
  903. LWS_Send(str);
  904. result = TRUE;
  905. //return 1;
  906. }
  907. else
  908. {
  909. DEBUG_INFO("queue is null\n");
  910. result = FALSE;
  911. //return 0;
  912. }
  913. fclose(fp);
  914. DEBUG_INFO("sentqueue end\n");
  915. return result;
  916. #if 0
  917. pnode p;
  918. p = front;
  919. printf("sentqueue\n");
  920. while(p)
  921. {
  922. printf("uuid: %s data: %s\n", p->uuid, p->data);
  923. LWS_Send(p->data);
  924. p = p->next;
  925. }
  926. printf("sentqueue end\n");
  927. return 0;
  928. #endif
  929. }
  930. #if 0
  931. int storequeue(){
  932. //write queue to flash
  933. unsigned int i,Chk;
  934. unsigned char *ptr = NULL;
  935. int fd,wrd;
  936. // Save factory default setting value to flash backup setting block
  937. fd = open("./Storage/OCPP/queue.txt", O_RDWR);
  938. if (fd < 0)
  939. {
  940. #ifdef SystemLogMessage
  941. DEBUG_ERROR("open ./Storage/OCPP/queue.txt NG");
  942. #endif
  943. //free(ptr);
  944. return 0;
  945. }
  946. wrd=write(fd, &front, sizeof(node));
  947. if(wrd!=(sizeof(node)))
  948. {
  949. #ifdef SystemLogMessage
  950. DEBUG_ERROR("write ./Storage/OCPP/queue.txt NG");
  951. #endif
  952. //free(ptr);
  953. return 0;
  954. }
  955. close(fd);
  956. close(wrd);
  957. return 0;
  958. }
  959. int readfiletoqueue(){
  960. FILE *infile;
  961. //pnode p = (pnode )malloc(sizeof(node));
  962. struct _node Pnode;
  963. memset(&Pnode, 0, sizeof(node));
  964. // Open person.dat for reading
  965. infile = fopen ("./Storage/OCPP/queue.txt", "r");
  966. if (infile == NULL)
  967. {
  968. fprintf(stderr, "\nError opening file\n");
  969. exit (1);
  970. }
  971. // read file contents till end of file
  972. while(fread(&Pnode, sizeof(node), 1, infile))
  973. printf ("uuid = %s name = %s\n", Pnode.uuid,
  974. Pnode.data);
  975. // close file
  976. fclose (infile);
  977. // free(p);
  978. return 0;
  979. }
  980. #endif
  981. //
  982. void* processTransactionQueue(void* data) {
  983. char frontUUID[100] ={0};
  984. char frontData[1200] ={0};
  985. int queueNotEmpty = 0;
  986. while(1)
  987. {
  988. if(FirstHeartBeatResponse() == 1)
  989. {
  990. memset(frontUUID, 0, sizeof(frontUUID));
  991. memset(frontData, 0, sizeof(frontData));
  992. queueNotEmpty = 0;
  993. queueNotEmpty = queue_operation(1,frontUUID, frontData);//showfront(frontUUID, frontData); ---> remove temporally
  994. //showfront();
  995. if(queueNotEmpty == 1)
  996. {
  997. DEBUG_INFO("processTransactionQueue queue is not empty!\n");
  998. sendbuffer = 1;
  999. }
  1000. if(TransactionQueueNum != 0)
  1001. {
  1002. TransactionQueueInterval = 1;
  1003. }
  1004. else
  1005. {
  1006. TransactionQueueInterval = 10;
  1007. }
  1008. //TransactionQueueInterval = TransactionMessageAttemptsGet();
  1009. sleep(TransactionQueueInterval); // sleep for 30 seconds
  1010. }
  1011. }
  1012. pthread_exit(NULL); // ���}�l�����
  1013. return 0;
  1014. }
  1015. void CheckTransactionPacket(char *uuid)
  1016. {
  1017. char frontUUID[100]={0};
  1018. char frontData[1200]={0};
  1019. int queueNotEmpty = 0;
  1020. int cmpResult = 0;
  1021. queue_operation(0,"","");//showqueue(); ---> remove temporally
  1022. queueNotEmpty = queue_operation(1,frontUUID, frontData);//showfront(frontUUID, frontData); ---> remove temporally
  1023. if(queueNotEmpty == 1)
  1024. {
  1025. cmpResult = strcmp(frontUUID, uuid);
  1026. //cmpResult = strcmp(frontData, uuid);
  1027. if (cmpResult == 0)
  1028. {
  1029. DEBUG_INFO("TransactionPacket Compare All right!\n");
  1030. queue_operation(2,"","");//delq(); ---> remove temporally
  1031. }
  1032. }
  1033. }
  1034. /* type: 0 (showqueue ); type: 1(showfront); type: 2(delq) type: 3 (sentqueue) type: 4 (addq) type: 5(store queue to /Storage/OCPP/ )*/
  1035. int queue_operation(int type, char *frontUUID, char *frontData)
  1036. {
  1037. pthread_mutex_unlock(&lock_sentData);
  1038. pthread_mutex_lock(&lock_sentData);
  1039. int result=0;
  1040. if(type == 0) // show items in queue
  1041. result = showqueue();
  1042. else if(type == 1) // show first item
  1043. result = showfront(frontUUID, frontData);
  1044. else if(type == 2) // delete item
  1045. result = delq();
  1046. else if(type == 3) // sent items in queue
  1047. result = sentqueue();
  1048. else if(type == 4) // add items to the queue
  1049. result = addq(frontUUID, frontData);
  1050. pthread_mutex_unlock(&lock_sentData);
  1051. return result;
  1052. }
  1053. char * strchr(const char *p, int ch)
  1054. {
  1055. char c;
  1056. c = ch;
  1057. for (;; ++p) {
  1058. if (*p == c)
  1059. return ((char *)p);
  1060. if (*p == '\0')
  1061. return (NULL);
  1062. }
  1063. /* NOTREACHED */
  1064. return NULL;
  1065. }
  1066. int removeMessageSentFile(void)
  1067. {
  1068. char rmFileCmd[100]={0};
  1069. struct stat stats;
  1070. //
  1071. stat("../Storage/OCPP", &stats);
  1072. // Check for directory existence
  1073. if (S_ISDIR(stats.st_mode) == 1)
  1074. {
  1075. DEBUG_INFO("\n OCPP directory exist \n");
  1076. }
  1077. else
  1078. {
  1079. DEBUG_INFO("\n directory not exist, create dir \n");
  1080. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  1081. system(rmFileCmd);
  1082. }
  1083. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  1084. if((access("../Storage/OCPP/MessageSent",F_OK))!=-1)
  1085. {
  1086. DEBUG_INFO("MessageSent file exist.\n");
  1087. sprintf(rmFileCmd,"rm -f %s","../Storage/OCPP/MessageSent");
  1088. system(rmFileCmd);
  1089. }
  1090. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  1091. return 0;
  1092. }
  1093. #define SystemLogMessage
  1094. //================================================
  1095. // Main process
  1096. //================================================
  1097. int main(void)
  1098. {
  1099. pthread_t t;
  1100. #ifdef SystemLogMessage
  1101. DEBUG_INFO("Initialization...\n");
  1102. #endif
  1103. if(ProcessShareMemory()== FAIL)
  1104. {
  1105. return FAIL;
  1106. }
  1107. //Create Process: Resend Transaction
  1108. pthread_create(&t, NULL, processTransactionQueue, NULL); //
  1109. sqlite3_config(SQLITE_CONFIG_URI,1);
  1110. if(sqlite3_open("file:/../Storage/OCPP/charger.db", &db))
  1111. {
  1112. #ifdef Debug
  1113. DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db));
  1114. #endif
  1115. sqlite3_close( db );
  1116. exit(0);
  1117. }
  1118. else
  1119. {
  1120. #ifdef Debug
  1121. DEBUG_INFO( "Opened database successfully\n");
  1122. #endif
  1123. }
  1124. //Table log buffer
  1125. int rc =sqlite3_exec(db, createsql, 0, 0, &errMsg);
  1126. if (SQLITE_OK != rc)
  1127. {
  1128. #ifdef Debug
  1129. DEBUG_INFO( "Create log buffer table error message: %s\n", errMsg);
  1130. #endif
  1131. return 0;
  1132. }
  1133. else
  1134. {
  1135. #ifdef Debug
  1136. DEBUG_INFO( "Opened log buffer table successfully\n");
  1137. #endif
  1138. }
  1139. //Table OcppAuthCache
  1140. rc =sqlite3_exec(db, sqlOcppAuthCache, 0, 0, &errMsg);
  1141. if (SQLITE_OK != rc)
  1142. {
  1143. #ifdef Debug
  1144. DEBUG_INFO( "Create OcppAuthCache error message: %s\n", errMsg);
  1145. #endif
  1146. return 0;
  1147. }
  1148. else
  1149. {
  1150. #ifdef Debug
  1151. DEBUG_INFO( "Opened OcppAuthCache table successfully\n");
  1152. #endif
  1153. }
  1154. // Table OcppAuthLocal
  1155. rc =sqlite3_exec(db, sqlOcppAuthLocal, 0, 0, &errMsg);
  1156. if (SQLITE_OK != rc)
  1157. {
  1158. #ifdef Debug
  1159. DEBUG_INFO( "Create Table OcppAuthLocal error %s\n",errMsg);
  1160. #endif
  1161. return 0;
  1162. }
  1163. else
  1164. {
  1165. #ifdef Debug
  1166. DEBUG_INFO( "Opened OcppAuthLocal table successfully\n");
  1167. #endif
  1168. }
  1169. initialConfigurationTable();
  1170. removeMessageSentFile();
  1171. //queryAllData();
  1172. OCPP_get_TableAuthlocalAllData();
  1173. for(;;)
  1174. {
  1175. while(ConnectionEstablished==0)
  1176. {
  1177. if((time((time_t*)NULL)-startTime.connect)>=60)
  1178. {
  1179. #ifdef Debug
  1180. DEBUG_INFO("Execute ConnectWsServer\n");
  1181. #endif
  1182. ConnectWsServer();
  1183. startTime.connect=time((time_t*)NULL);
  1184. }
  1185. lws_service(context, 10000);//timeout_ms
  1186. }
  1187. if(( (BootNotificationInterval != 0 && ((time((time_t*)NULL)-startTime.bootNotification)>=BootNotificationInterval) ) || ((time((time_t*)NULL)-startTime.bootNotification)>=defaultWaitingTime) ) && ((server_sign == FALSE)/*|| (server_pending == TRUE)*/))
  1188. {
  1189. //hashmapForMessageNew();
  1190. sendBootNotificationRequest();
  1191. startTime.bootNotification=time((time_t*)NULL);
  1192. }
  1193. if(server_sign == TRUE)
  1194. {
  1195. if(sendbuffer == 1)
  1196. {
  1197. queue_operation(3, "", "");//sentqueue(); ---> remove temporally
  1198. sendbuffer = 0;
  1199. //queue_operation(5,"", "");
  1200. }
  1201. // Check System Value
  1202. CheckSystemValue();
  1203. }
  1204. lws_service(context, 100);//timeout_ms
  1205. }
  1206. pthread_join(t, NULL); // ���ݤl��������槹��
  1207. //hashmapForMessageFree();
  1208. return FAIL;
  1209. }