forked from gioblu/PJON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPJONDefines.h
232 lines (196 loc) · 7.06 KB
/
PJONDefines.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*-O//\ __ __
|-gfo\ |__| | | | |\ | ™
|!y°o:\ | __| |__| | \| v8.2
|y"s§+`\ multi-master, multi-media communications bus system framework
/so+:-..`\ Copyright 2010-2017 by Giovanni Blu Mitolo gioscarab@gmail.com
|+/:ngr-*.`\
|5/:%&-a3f.:;\
\+//u/+g%{osv,,\
\=+&/osw+olds.\\
\:/+-.-°-:+oss\
| | \oy\\
> <
______-| |-___________________________________________________________________
PJON™ is a self-funded, no-profit open-source project created and maintained by
Giovanni Blu Mitolo with the support of the internet community if you want
to see the PJON project growing with a faster pace, consider a donation
at the following link: https://www.paypal.me/PJON
For the PJON™ Protocol specification see the specification directory.
PJON™ Standard compliant tools:
- ModuleInterface - Easy config and value sync between IOT modules
https://github.com/fredilarsen/ModuleInterface
- Command line PJON wrapper over unnamed pipes by Zbigniew Zasieczny
https://github.com/Girgitt/PJON-piper
- PJON-python - PJON running on Python by Zbigniew Zasieczny
https://github.com/Girgitt/PJON-python
- Logic analyzer by Andrew Grande (obsolete)
https://github.com/aperepel/saleae-pjon-protocol-analyzer
______________________________________________________________________________
Copyright 2010-2017 by Giovanni Blu Mitolo gioscarab@gmail.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include "utils/PJON_CRC8.h"
#include "utils/PJON_CRC32.h"
/* Id used for broadcasting to all devices */
#define PJON_BROADCAST 0
/* Master device id */
#define PJON_MASTER_ID 254
/* Device id of still unindexed devices */
#define PJON_NOT_ASSIGNED 255
/* Maximum devices handled by master */
#ifndef PJON_MAX_DEVICES
#define PJON_MAX_DEVICES 25
#endif
/* Communication modes */
#define PJON_SIMPLEX 150
#define PJON_HALF_DUPLEX 151
/* Protocol symbols */
#define PJON_ACK 6
#define PJON_BUSY 666
#define PJON_NAK 21
/* Dynamic addressing */
#define PJON_ID_ACQUIRE 199
#define PJON_ID_REQUEST 200
#define PJON_ID_CONFIRM 201
#define PJON_ID_NEGATE 203
#define PJON_ID_LIST 204
#define PJON_ID_REFRESH 205
/* INTERNAL CONSTANTS */
#define PJON_FAIL 65535
#define PJON_TO_BE_SENT 74
/* HEADER BITS DEFINITION: */
/* 0 - Local network
1 - Shared network */
#define PJON_MODE_BIT 0B00000001
/* 0 - No info inclusion
1 - Local: Sender device id included
Shared: Sender device id + Sender bus id */
#define PJON_TX_INFO_BIT 0B00000010
/* 0 - Acknowledgement disabled
1 - Acknowledgement enabled */
#define PJON_ACK_REQ_BIT 0B00000100
/* 0 - Synchronous acknowledgement requested
1 - Asynchronous acknowledgement requested */
#define PJON_ACK_MODE_BIT 0B00001000
/* 0 - Not addressing related
1 - Addressing related */
#define PJON_ADDRESS_BIT 0B00010000
/* 0 - CRC8 (1 byte) included at the end of the packet
1 - CRC32 (4 bytes) included at the end of the packet */
#define PJON_CRC_BIT 0B00100000
/* 0 - 1 byte length (max 255 characters)
1 - 2 bytes length (max 65535 characters) */
#define PJON_EXT_LEN_BIT 0B01000000
/* 0 - 1 byte header
1 - 2 bytes header */
#define PJON_EXT_HEAD_BIT 0B10000000
/* EXTENDED HEADER BITS DEFINITION: */
/* 0 - No routing
1 - Routing */
#define PJON_ROUTING_BIT 0B0100000000000000
/* 0 - No segmentation
1 - Segmentation */
#define PJON_SEGM_BIT 0B0010000000000000
/* 0 - Not including session
1 - Including session */
#define PJON_SESSION_BIT 0B0001000000000000
/* 0 - No parity included
1 - Parity included */
#define PJON_PARITY_BIT 0B0000100000000000
/* 0 - Not encoded
1 - Encoded */
#define PJON_ENCODING_BIT 0B0000010000000000
/* 0 - No data compression
1 - Data compression */
#define PJON_DATA_COMP_BIT 0B0000001000000000
/* 0 - Not encrypted
1 - Encrypted */
#define PJON_ENCRYPTION_BIT 0B0000000100000000
/* ERRORS: */
#define PJON_CONNECTION_LOST 101
#define PJON_PACKETS_BUFFER_FULL 102
#define PJON_CONTENT_TOO_LONG 104
#define PJON_ID_ACQUISITION_FAIL 105
#define PJON_DEVICES_BUFFER_FULL 254
/* CONSTRAINTS: */
/* Packet buffer length, if full PJON_PACKETS_BUFFER_FULL error is thrown.
The packet buffer is preallocated, so its length strongly affects
memory consumption */
#ifndef PJON_MAX_PACKETS
#define PJON_MAX_PACKETS 5
#endif
/* Max packet length, higher if necessary.
The max packet length defines the length of packets pre-allocated buffers
so it strongly affects memory consumption */
#ifndef PJON_PACKET_MAX_LENGTH
#define PJON_PACKET_MAX_LENGTH 50
#endif
/* If set to true avoids async ack code memory allocation if not used
(it saves around 1kB of memory) */
#ifndef PJON_INCLUDE_ASYNC_ACK
#define PJON_INCLUDE_ASYNC_ACK false
#endif
/* Maximum packet ids record kept in memory (to avoid duplicated exchanges) */
#ifndef PJON_MAX_RECENT_PACKET_IDS
#define PJON_MAX_RECENT_PACKET_IDS 10
#endif
/* If set to true ensures packet ordered sending */
#ifndef PJON_ORDERED_SENDING
#define PJON_ORDERED_SENDING false
#endif
/* Dynamic addressing timing constants:
Maximum number of device id collisions during auto-addressing */
#define PJON_MAX_ACQUIRE_ID_COLLISIONS 10
/* Delay between device id acquisition and self request */
#define PJON_ACQUIRE_ID_DELAY 1000
/* Maximum id scan time (6 seconds) */
#define PJON_ID_SCAN_TIME 6000000
/* Master free id broadcast response interval (0.1 seconds) */
#define PJON_ID_REQUEST_INTERVAL 100000
/* Master ID_REQUEST and ID_NEGATE timeout */
#define PJON_ADDRESSING_TIMEOUT 2900000
/* Master reception time during LIST_ID broadcast (75 milliseconds) */
#define PJON_LIST_IDS_TIME 75000
struct PJON_Packet {
uint8_t attempts;
char content[PJON_PACKET_MAX_LENGTH];
uint16_t length;
uint32_t registration;
uint16_t state;
uint32_t timing;
};
struct PJON_Packet_Record {
uint16_t id;
uint8_t header;
uint8_t sender_id;
uint8_t sender_bus_id[4];
};
/* Last received packet Metainfo */
struct PJON_Packet_Info {
uint16_t header = 0;
uint16_t id = 0;
uint8_t receiver_id = 0;
uint8_t receiver_bus_id[4];
uint8_t sender_id = 0;
uint8_t sender_bus_id[4];
};
typedef void (* PJON_Receiver)(
uint8_t *payload,
uint16_t length,
const PJON_Packet_Info &packet_info
);
static void PJON_dummy_receiver_handler(
uint8_t *payload,
uint16_t length,
const PJON_Packet_Info &packet_info
) {};
typedef void (* PJON_Error)(uint8_t code, uint8_t data);
static void PJON_dummy_error_handler(uint8_t code, uint8_t data) {};