Module_OcppBackend20.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Sample_OCPP_Task.h
  3. *
  4. * Created on: 2020
  5. * Author: foluswen
  6. */
  7. #ifndef HEADER_MODULE_OCPPBACKEND20_H_
  8. #define HEADER_MODULE_OCPPBACKEND20_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 <sys/sysinfo.h>
  19. #include <linux/wireless.h>
  20. #include <linux/sockios.h>
  21. #include <linux/socket.h>
  22. #include <linux/unistd.h>
  23. #include <linux/kernel.h>
  24. #include <arpa/inet.h>
  25. #include <netinet/in.h>
  26. #include <unistd.h>
  27. #include <stdarg.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <fcntl.h>
  31. #include <termios.h>
  32. #include <errno.h>
  33. #include <string.h>
  34. #include <time.h>
  35. #include <ctype.h>
  36. #include <ifaddrs.h>
  37. #include <pthread.h>
  38. #include <mcheck.h>
  39. #include <uuid/uuid.h>
  40. #include <libwebsockets.h>
  41. #include <lws_config.h>
  42. #include <sqlite3.h>
  43. #include <json-c/json.h>
  44. #include "hashmap.h"
  45. #include "SystemLogMessage.h"
  46. #include "MessageHandler.h"
  47. #define ROOTCA_CS "/Storage/OCPP/rootCaCs.pem" // for verify connect wss
  48. #define ROOTCA_MF "/Storage/OCPP/rootCaMf.pem" // for verify signedUpdateFirmware
  49. #define ROOTCA_V2G "/Storage/rootCaV2g.pem" // for 15118
  50. #define ROOTCA_MO "/Storage/rootCaMo.pem" // for 15118
  51. #define CERTIFICATE_CP "/Storage/OCPP/certCP.pem" // for security profile 3
  52. #define CERTIFICATE_V2G "/Storage/certV2G.pem" // for 15118
  53. #define CERTIFICATE_PnCAuth "/Storage/certPnCAuth.pem" // for PnC authorization
  54. #define PRIVATE_KEY_CP "/Storage/OCPP/certCP.key" // for security profile 3
  55. #define PRIVATE_KEY_V2G "/Storage/certV2G.key" // for 15118
  56. #define CSR_CP "/Storage/OCPP/certCP.csr" // for get CERTIFICATE_CP
  57. #define CSR_V2G "/Storage/certV2G.csr" // for get CERTIFICATE_V2G
  58. #define is_error(ptr) ((unsigned long)ptr > (unsigned long)-4000L)
  59. #define PASS 1
  60. #define FAIL -1
  61. typedef enum {
  62. NO=0,
  63. YES
  64. }Logic_Value;
  65. typedef enum {
  66. OFF=0,
  67. ON
  68. }Switch_Value;
  69. enum GUN_TYPE
  70. {
  71. GUN_TYPE_UNKNOWN=0,
  72. GUN_TYPE_CHAdeMO,
  73. GUN_TYPE_CCS,
  74. GUN_TYPE_GBT,
  75. GUN_TYPE_DO,
  76. GUN_TYPE_AC
  77. };
  78. #ifndef SPEC_LATEST_SUPPORTED
  79. #define SPEC_LATEST_SUPPORTED 13
  80. #endif
  81. // Hash map operation constant
  82. #define HASH_OP_ADD 0
  83. #define HASH_OP_GET 1
  84. #define HASH_OP_REMOVE 2
  85. // OCPP Message type constant
  86. #define MESSAGE_TYPE_CALL 2
  87. #define MESSAGE_TYPE_CALLRESULT 3
  88. #define MESSAGE_TYPE_CALLERROR 4
  89. // Queue operation constant
  90. #define QUEUE_OPERATION_SHOWQUEUE 0
  91. #define QUEUE_OPERATION_SHOWFRONT 1
  92. #define QUEUE_OPERATION_DEL 2
  93. #define QUEUE_OPERATION_SENT 3
  94. #define QUEUE_OPERATION_ADD 4
  95. #define QUEUE_OPERATION_STORE 5
  96. #define QUEUE_MESSAGE_LENGTH 1024*495
  97. // Websocket TX/RX buffer size
  98. #define WEBSOCKET_BUFFER_SIZE (1024*500)
  99. struct QueueOpInfo
  100. {
  101. int TransactionMessageResend; // the number of retry to submit a transaction-related message when the Central System fails to process it.
  102. int PreTransactionMessageResend;
  103. int TransactionQueueNum;
  104. int IsUsing;
  105. int stopTransactionId;
  106. };
  107. struct yuarel {
  108. char *scheme; /* scheme, without ":" and "//" */
  109. char *username; /* username, default: NULL */
  110. char *password; /* password, default: NULL */
  111. char *host; /* hostname or IP address */
  112. int port; /* port, default: 0 */
  113. char *path; /* path, without leading "/", default: NULL */
  114. char *query; /* query, default: NULL */
  115. char *fragment; /* fragment, default: NULL */
  116. };
  117. /* A struct to hold the query string parameter values. */
  118. struct yuarel_param {
  119. char *key;
  120. char *val;
  121. };
  122. extern int yuarel_parse(struct yuarel *url, char *url_str);
  123. extern int yuarel_split_path(char *path, char **parts, int max_parts);
  124. extern int yuarel_parse_query(char *query, char delimiter, struct yuarel_param *params, int max_params);
  125. extern void CheckSystemValue(void);
  126. extern void checkNetworkProfile(void);
  127. extern int FirstHeartBeatResponse(void);
  128. extern void OCPP_get_TableAuthlocalAllData(void);
  129. extern int TransactionMessageAttemptsGet(void);
  130. extern int TransactionMessageRetryIntervalGet(void);
  131. extern int GetOcppConnStatus(void);
  132. extern void SetOcppConnStatus(uint8_t status);
  133. extern int GetHeartBeatWithNOResponse(void);
  134. extern void SetHeartBeatWithNOResponse(void);
  135. extern int DB_Initial();
  136. extern uint8_t GetOcppSecurityProfile();
  137. void MergeCertificates();
  138. extern void GetOcppChargerBoxId(uint8_t *data);
  139. extern void GetOcppSecurityPassword(uint8_t *data);
  140. extern int InitShareMemory();
  141. extern int ProcessShareMemory();
  142. extern void CheckSystemValue(void);
  143. extern int isQueueOverSize();
  144. extern int showfront(char *uuid, char *data);
  145. extern int addq(char *uuid, char *data) ;
  146. extern int delq();
  147. extern int sentqueue();
  148. extern void CheckTransactionPacket(char *uuid);
  149. extern int queue_operation(int type, char *frontUUID, char *frontData);
  150. extern char *random_uuid( char buf[37]);
  151. extern void work(char s[]);
  152. extern char* strchr(const char *p, int ch);
  153. extern void splitstring(char *src, const char *separator, char **dest,int *num);
  154. extern char* stringtrim( char * s );
  155. extern char* stringtrimspace( char * s );
  156. extern char * strtrim( char * s );
  157. extern void refreshStartTimer(struct timespec *timer);
  158. extern int getDiffSecNow(struct timespec timer);
  159. extern int getDiffSecBetween(struct timespec start, struct timespec end);
  160. extern struct lws *wsi_client;
  161. extern struct lws_context *context;
  162. extern unsigned char SendBuffer[WEBSOCKET_BUFFER_SIZE];
  163. extern int SendBufLen;
  164. extern char OcppPath[384];
  165. extern char OcppProtocol[10];
  166. extern char OcppHost[128];
  167. extern char OcppTempPath[256];
  168. extern int OcppPort;
  169. extern unsigned char StartTransactionIdTagTemp[20];
  170. extern pthread_mutex_t lock_send;
  171. extern uint8_t isWebsocketSendable;
  172. extern uint8_t isQueueSendable;
  173. extern uint8_t counterLwsRestart;
  174. extern uint8_t counterQueueSent;
  175. #endif /* HEADER_MODULE_OCPPBACKEND20_H_ */