MySensors Library & Examples  2.3.2-62-ge298769
Timing.h
1 /* ThroughSerial digital communication data link layer
2  used as a Strategy by the PJON framework (included in version v4.1)
3 
4  Contributors:
5  - Fred Larsen, Development, testing and debugging
6  - Zbigniew Zasieczny, collision avoidance multi-drop RS485 (latency)
7  and SoftwareSerial compatibility
8  - Franketto (Arduino forum user) RS485 TX enable pin compatibility
9  ____________________________________________________________________________
10 
11  Based on ThroughSerial, developed by sticilface
12  copyright 2018 by Giovanni Blu Mitolo All rights reserved
13 
14  Licensed under the Apache License, Version 2.0 (the "License");
15  you may not use this file except in compliance with the License.
16  You may obtain a copy of the License at
17 
18  http://www.apache.org/licenses/LICENSE-2.0
19 
20  Unless required by applicable law or agreed to in writing, software
21  distributed under the License is distributed on an "AS IS" BASIS,
22  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23  See the License for the specific language governing permissions and
24  limitations under the License. */
25 
26 #pragma once
27 
28 /* Maximum 1 second random initial delay */
29 #ifndef TS_INITIAL_DELAY
30 #define TS_INITIAL_DELAY 1000
31 #endif
32 
33 /* Maximum 64 microseconds random delay in case of collision */
34 #ifndef TS_COLLISION_DELAY
35 #define TS_COLLISION_DELAY 64
36 #endif
37 
38 /* Set 45 milliseconds as the maximum timeframe between transmission and
39  synchronous acknowledgement response. Its optimal configuration is
40  strictly related to the maximum time needed by receiver to receive, compute
41  and transmit back a response. Set TS_RESPONSE_TIME_OUT to 0 and do not use
42  the acknowledgement feature if the system operates in master-slave mode and
43  or applies the request-response scheme. */
44 #ifndef TS_RESPONSE_TIME_OUT
45 #define TS_RESPONSE_TIME_OUT 45000
46 #endif
47 
48 /* Minum duration of channel free for use before transmission, used to avoid
49  disrupting an ongoing acknowledgement exchange. Set TS_TIME_IN to 0 and do
50  not use the acknowledgement feature if the system operates in master-slave
51  mode and or applies the request-response scheme. */
52 #ifndef TS_TIME_IN
53 #define TS_TIME_IN TS_RESPONSE_TIME_OUT + TS_COLLISION_DELAY
54 #endif
55 
56 /* Set 100 microseconds as the interval between each byte read.
57  Depending on the latency, baud rate and computation time the
58  optimal TS_READ_INTERVAL value may variate.
59  Always set: TS_READ_INTERVAL > (byte transmission time + latency) */
60 #ifndef TS_READ_INTERVAL
61 #define TS_READ_INTERVAL 100
62 #endif
63 
64 /* Byte reception timeout (Default 1 second) */
65 #ifndef TS_BYTE_TIME_OUT
66 #define TS_BYTE_TIME_OUT 1000000
67 #endif
68 
69 /* Response length (the response is composed by the last TS_RESPONSE_LENGTH
70  bytes of the packet received). Setting TS_RESPONSE_LENGTH < 4 when using
71  ThroughSerial in multi-master mode reduces reliability and leads to higher
72  chances of detecting a false positive. */
73 #ifndef TS_RESPONSE_LENGTH
74 #define TS_RESPONSE_LENGTH 1
75 #endif
76 
77 /* Maximum transmission attempts */
78 #ifndef TS_MAX_ATTEMPTS
79 #define TS_MAX_ATTEMPTS 20
80 #endif
81 
82 /* Back-off exponential degree */
83 #ifndef TS_BACK_OFF_DEGREE
84 #define TS_BACK_OFF_DEGREE 4
85 #endif
86 
87 /* Delay before enabling and disabling RS485 DE and or RE pin */
88 #ifndef TS_RS485_DELAY
89 #define TS_RS485_DELAY 1
90 #endif
91 
92 /* Force blocking sending hack (adds a delay for each character sent). */
93 
94 #ifndef TS_FLUSH_OFFSET
95 #define TS_FLUSH_OFFSET 152
96 #endif