-
Notifications
You must be signed in to change notification settings - Fork 24
/
ocpp_helper.h
65 lines (56 loc) · 2.05 KB
/
ocpp_helper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef __OCPP_HELPER_H
#define __OCPP_HELPER_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include <fcntl.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
#include "ocpp_ws_client.h"
#include "cJSON.h"
//Message length defined for OCPP Payload
#define MESSAGE_LEN 1000
//Declaring buffer for OCPP Payload
char ocppMessagePayload[MESSAGE_LEN];
//Declaring GUID 16 octects according to RFC4122 https://tools.ietf.org/html/rfc4122
typedef unsigned char uuid_t[16];
//UUID structure defined as mentioned in RFC4122
struct uuid
{
uint32_t time_low;
uint16_t time_mid;
uint16_t time_hi_and_version;
uint16_t clock_seq;
uint8_t node[6];
};
//UUID comes in lower and upper cases, to convert the GUID returned and changing it to lower format
static const char *fmt_lower =
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
//OCPP frame structure defined
typedef struct _ocpp_frame
{
char *messageCode; //messageCode of character type
char *messageID; //messageID or UUID for uniquely identifying each message
char *action; //What action is to be used
cJSON *jsonPacket; //JSON packet associated with that particular action
}ocpp_frame;
/**
* Fucntion prototypes defined here
*/
static int random_get_fd(void);
static void random_get_bytes(void *buf, size_t nbytes);
static void __uuid_generate_random(uuid_t out, int *num);
static void uuid_unpack(const uuid_t in, struct uuid *uu);
static void uuid_pack(const struct uuid *uu, uuid_t ptr);
static void uuid_unparse_lower(const uuid_t uu, char *out);
static void uuid_unparse_x(const uuid_t uu, char *out, const char *fmt);
ocpp_frame *formOCPPFrame(char *messagecode, char *actiontocms, cJSON *jsonpacket);
cJSON *readConfigFile(const char *filePath);
cJSON *bootNotificationRequest(cJSON *config);
int sendFrameToCMS(wsclient *c,ocpp_frame *packet);
ocpp_frame *parseOCPPFrame(char *payload);
static int getSubString(char *source, char *target,int from, int to);
int changeTimeOfMachine(char *isoTime);
#endif