Module_OcppBackend.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Sample_OCPP_Task.h
  3. *
  4. * Created on: 2020¦~5¤ë26¤é
  5. * Author: foluswen
  6. */
  7. #ifndef HEADER_MODULE_OCPPBACKEND_H_
  8. #define HEADER_MODULE_OCPPBACKEND_H_
  9. #include <sys/time.h>
  10. #include <sys/timeb.h>
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #include <sys/ioctl.h>
  14. #include <sys/socket.h>
  15. #include <sys/ipc.h>
  16. #include <sys/shm.h>
  17. #include <sys/mman.h>
  18. #include <linux/wireless.h>
  19. #include <linux/sockios.h>
  20. #include <linux/socket.h>
  21. #include <arpa/inet.h>
  22. #include <netinet/in.h>
  23. #include <unistd.h>
  24. #include <stdarg.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <unistd.h>
  28. #include <fcntl.h>
  29. #include <termios.h>
  30. #include <errno.h>
  31. #include <string.h>
  32. #include <time.h>
  33. #include <ctype.h>
  34. #include <ifaddrs.h>
  35. #include <pthread.h>
  36. #include <mcheck.h>
  37. #include <uuid/uuid.h>
  38. #include <libwebsockets.h>
  39. #include <lws_config.h>
  40. #include <sqlite3.h>
  41. #include <json-c/json.h>
  42. #include "hashmap.h"
  43. #include "SystemLogMessage.h"
  44. #include "MessageHandler.h"
  45. #define is_error(ptr) ((unsigned long)ptr > (unsigned long)-4000L)
  46. #define PASS 1
  47. #define FAIL -1
  48. #define YES 1
  49. #define NO 0
  50. #ifndef SPEC_LATEST_SUPPORTED
  51. #define SPEC_LATEST_SUPPORTED 13
  52. #endif
  53. // Hash map operation constant
  54. #define HASH_OP_ADD 0
  55. #define HASH_OP_GET 1
  56. #define HASH_OP_REMOVE 2
  57. // OCPP Message type constant
  58. #define MESSAGE_TYPE_CALL 2
  59. #define MESSAGE_TYPE_CALLRESULT 3
  60. #define MESSAGE_TYPE_CALLERROR 4
  61. // Queue operation constant
  62. #define QUEUE_OPERATION_SHOWQUEUE 0
  63. #define QUEUE_OPERATION_SHOWFRONT 1
  64. #define QUEUE_OPERATION_DEL 2
  65. #define QUEUE_OPERATION_SENT 3
  66. #define QUEUE_OPERATION_ADD 4
  67. #define QUEUE_OPERATION_STORE 5
  68. #define QUEUE_MESSAGE_LENGTH 3584
  69. // Websocket TX/RX buffer size
  70. #define WEBSOCKET_BUFFER_SIZE (1024*200)
  71. enum GUN_TYPE
  72. {
  73. GUN_TYPE_UNKNOWN=0,
  74. GUN_TYPE_CHAdeMO,
  75. GUN_TYPE_CCS,
  76. GUN_TYPE_GBT,
  77. GUN_TYPE_DO,
  78. GUN_TYPE_AC
  79. };
  80. struct yuarel {
  81. char *scheme; /* scheme, without ":" and "//" */
  82. char *username; /* username, default: NULL */
  83. char *password; /* password, default: NULL */
  84. char *host; /* hostname or IP address */
  85. int port; /* port, default: 0 */
  86. char *path; /* path, without leading "/", default: NULL */
  87. char *query; /* query, default: NULL */
  88. char *fragment; /* fragment, default: NULL */
  89. };
  90. /* A struct to hold the query string parameter values. */
  91. struct yuarel_param {
  92. char *key;
  93. char *val;
  94. };
  95. extern int yuarel_parse(struct yuarel *url, char *url_str);
  96. extern int yuarel_split_path(char *path, char **parts, int max_parts);
  97. extern int yuarel_parse_query(char *query, char delimiter, struct yuarel_param *params, int max_params);
  98. extern void CheckSystemValue(void);
  99. extern int FirstHeartBeatResponse(void);
  100. extern void OCPP_get_TableAuthlocalAllData(void);
  101. extern int TransactionMessageAttemptsGet(void);
  102. extern int TransactionMessageRetryIntervalGet(void);
  103. extern int GetOcppConnStatus(void);
  104. extern void SetOcppConnStatus(uint8_t status);
  105. extern int GetHeartBeatWithNOResponse(void);
  106. extern void SetHeartBeatWithNOResponse(void);
  107. extern uint8_t GetOcppSecurityProfile();
  108. extern void GetOcppChargerBoxId(uint8_t *data);
  109. extern void GetOcppSecurityPassword(uint8_t *data);
  110. extern void SetOcppVersion(uint8_t *version);
  111. extern int InitShareMemory();
  112. extern int ProcessShareMemory();
  113. extern void CheckSystemValue(void);
  114. extern int isQueueOverSize();
  115. extern int showfront(char *uuid, char *data);
  116. extern int addq(char *uuid, char *data) ;
  117. extern int delq();
  118. extern int sentqueue();
  119. extern void CheckTransactionPacket(char *uuid);
  120. extern int queue_operation(int type, char *frontUUID, char *frontData);
  121. extern char *random_uuid( char buf[37]);
  122. extern void work(char s[]);
  123. extern char* strchr(const char *p, int ch);
  124. extern void splitstring(char *src, const char *separator, char **dest,int *num);
  125. extern char* stringtrim( char * s );
  126. extern char* stringtrimspace( char * s );
  127. extern char * strtrim( char * s );
  128. extern struct lws *wsi_client;
  129. extern struct lws_context *context;
  130. extern unsigned char SendBuffer[WEBSOCKET_BUFFER_SIZE];
  131. extern int SendBufLen;
  132. extern char OcppPath[384];
  133. extern char OcppProtocol[10];
  134. extern char OcppHost[128];
  135. extern char OcppTempPath[256];
  136. extern int OcppPort;
  137. extern unsigned char StartTransactionIdTagTemp[20];
  138. extern pthread_mutex_t lock_send;
  139. extern uint32_t startTimeDog;
  140. extern uint32_t startTimeQueue;
  141. extern uint8_t isWebsocketSendable;
  142. extern uint8_t counterLwsRestart;
  143. extern uint8_t counterQueueSent;
  144. #endif /* HEADER_MODULE_OCPPBACKEND_H_ */