-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibgw.h
165 lines (124 loc) · 3.2 KB
/
libgw.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#ifndef __ZIGBEE_GATEWAY_H__
#define __ZIGBEE_GATEWAY_H__
#define RSX_DEBUG
#define ZCDEVICE "/dev/usb/tts/0"
#define MAX_ATTRIBUTE_TABLE_SIZE 7
#define MAX_WAITING_TIME 60
#define BAUDRATE B115200
#define FALSE 0
#define TRUE 1
#define CR 0x0d
#define LF 0x0a
#define CURRENT_TIME time(NULL)
#define MAX_BUFFER_SIZE 256
#define MAX_ARRAY_SIZE 64
#define MAX_CHILD_TABLE_SIZE 30
#define MAX_RAWDATA_TABLE_SIZE MAX_CHILD_TABLE_SIZE //one node, one power-meter, one rawdata
#define CLUSTER_ID 0x0702 // the power meter cluster id
#ifdef RSX_DEBUG
#define PRINTH(p, size, str) \
do{\
char tmp[32];\
memset(tmp, 0x00, 32);\
memcpy(tmp, (p), (size));\
printf("[%s:%d]"str"%s\n",__FILE__, __LINE__, tmp);\
}while(0)
#else
#define PRINTH(p, size, str)
#endif
#include <time.h>
// 1/1000 seconds sleep
#define msleep(x) usleep((x)*1000)
typedef struct TimerTask_s TimerTask;
typedef struct TimerTaskData_s TimerTaskData;
typedef struct HostProtocol_s HostProtocol;
typedef struct Rawdata_s Rawdata;
typedef unsigned char int8u;
static const char HEX_TABLE[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
static const int8u empty_child[16] = "0000000000000000";
struct Rawdata_s
{
int8u macid[17];
time_t time;
char v[5];
char i[5];
char freq[5];
char pf[3];
char w[7];
char va[7];
char wh[9];
char rssi[3];
};
struct TimerTask_s
{
time_t start_time;
int delay_seconds;
};
struct TimerTaskData_s
{
TimerTask* task;
void (*handler)(void);
};
struct HostProtocol_s{
//version number
char ver[3];
//transaction sequence number
char seq[3];
//IEEE address
char longAddress[17];
//receiver sensitive
char rssi[3];
//zcl profile id
char profileId[5];
//zcl cluster id
char clusterId[5];
//source endpoint
char srcEndpoint[3];
//destination endpoint
char destEndpoint[3];
//zcl command id
char cmdId[3];
//profile wide or not
char is_profile_wide[3];
//zcl attribute id
char attributeId[5];
//response status reference ZCL status code
char status[3];
char v[9];
char i[9];
char freq[9];
char pf[9];
char w[9];
char va[9];
char wh[9];
};
void dbg(char* filename, int linenum, char* fmt, ...);
void disable_timer_task(TimerTask* task);
void enable_timer_task(TimerTask* task, int delay_seconds);
void run_timer_tasks(TimerTaskData tasks[]);
void init_serial(char* device);
void close_uart_port(void);
void uart_handler(int status);
void receive_uart_data(void);
void reset_child_table();
void reset_error_child_table();
void add_child_table(char* eui64);
void dispatcher(HostProtocol *p);
void list_children_command();
void allow_join_command();
void mtorr_command();
void print_child_table_command();
void parse_response_command(char* payload, HostProtocol* p);
void ask_power_meter_command(int8u index, char* eui);
void add_rawdata(Rawdata *r);
void transfer_data(int8u check_error);
void serialize_to_tmp(int8u check_error);
void calculate_crc(Rawdata *r);
void save_eui64list(void);
void choose_run_ebl(void);
void choose_upload_ebl(void);
void flush_uart_data(void);
void init_serial_FW(char* device);
void init_serial_noFW(char* device);
void updfrm_command(char* cmd);
#endif