@@ -44,7 +44,7 @@ bool TheThingsNetwork::sendCommand(String cmd) {
44
44
}
45
45
46
46
bool TheThingsNetwork::sendCommand (String cmd, String value) {
47
- int l = value.length ();
47
+ size_t l = value.length ();
48
48
byte buf[l];
49
49
value.getBytes (buf, l);
50
50
@@ -61,10 +61,10 @@ char btohexa_low(unsigned char b) {
61
61
return (b > 0x9u ) ? b + ' A' - 10 : b + ' 0' ;
62
62
}
63
63
64
- bool TheThingsNetwork::sendCommand (String cmd, const byte *buf, int length) {
64
+ bool TheThingsNetwork::sendCommand (String cmd, const byte *buf, size_t length) {
65
65
String str = cmd + " " ;
66
66
67
- for (int i = 0 ; i < length; i++) {
67
+ for (size_t i = 0 ; i < length; i++) {
68
68
str += btohexa_high (buf[i]);
69
69
str += btohexa_low (buf[i]);
70
70
}
@@ -96,7 +96,7 @@ void TheThingsNetwork::reset(bool adr) {
96
96
sendCommand (str);
97
97
}
98
98
99
- void TheThingsNetwork::onMessage (void (*cb)(const byte* payload, int length, int port)) {
99
+ void TheThingsNetwork::onMessage (void (*cb)(const byte* payload, size_t length, port_t port)) {
100
100
this ->messageCallback = cb;
101
101
}
102
102
@@ -130,7 +130,7 @@ bool TheThingsNetwork::provision(const byte appEui[8], const byte appKey[16]) {
130
130
return sendCommand (F (" mac save" ));
131
131
}
132
132
133
- bool TheThingsNetwork::join (int retries, long int retryDelay) {
133
+ bool TheThingsNetwork::join (int8_t retries, uint32_t retryDelay) {
134
134
configureChannels (this ->sf , this ->fsb );
135
135
String devEui = readValue (F (" sys get hweui" ));
136
136
String str = " " ;
@@ -163,13 +163,13 @@ bool TheThingsNetwork::join(int retries, long int retryDelay) {
163
163
return false ;
164
164
}
165
165
166
- bool TheThingsNetwork::join (const byte appEui[8 ], const byte appKey[16 ], int retries, long int retryDelay) {
166
+ bool TheThingsNetwork::join (const byte appEui[8 ], const byte appKey[16 ], int8_t retries, uint32_t retryDelay) {
167
167
reset ();
168
168
provision (appEui, appKey);
169
169
return join (retries, retryDelay);
170
170
}
171
171
172
- int TheThingsNetwork::sendBytes (const byte* payload, int length, int port, bool confirm) {
172
+ int TheThingsNetwork::sendBytes (const byte* payload, size_t length, port_t port, bool confirm) {
173
173
String str = " " ;
174
174
str.concat (F (" mac tx " ));
175
175
str.concat (confirm ? F (" cnf " ) : F (" uncnf " ));
@@ -193,12 +193,12 @@ int TheThingsNetwork::sendBytes(const byte* payload, int length, int port, bool
193
193
return 1 ;
194
194
}
195
195
if (response.startsWith (F (" mac_rx" ))) {
196
- int portEnds = response.indexOf (" " , 7 );
197
- int downlinkPort = response.substring (7 , portEnds).toInt ();
196
+ uint8_t portEnds = response.indexOf (" " , 7 );
197
+ port_t downlinkPort = response.substring (7 , portEnds).toInt ();
198
198
String data = response.substring (portEnds + 1 );
199
- int downlinkLength = data.length () / 2 ;
199
+ size_t downlinkLength = data.length () / 2 ;
200
200
byte downlink[64 ];
201
- for (int i = 0 , d = 0 ; i < downlinkLength; i++, d += 2 ) {
201
+ for (size_t i = 0 , d = 0 ; i < downlinkLength; i++, d += 2 ) {
202
202
downlink[i] = TTN_HEX_PAIR_TO_BYTE (data[d], data[d+1 ]);
203
203
}
204
204
debugPrint (F (" Successful transmission. Received " ));
@@ -214,7 +214,7 @@ int TheThingsNetwork::sendBytes(const byte* payload, int length, int port, bool
214
214
return -10 ;
215
215
}
216
216
217
- int TheThingsNetwork::poll (int port, bool confirm) {
217
+ int TheThingsNetwork::poll (port_t port, bool confirm) {
218
218
byte payload[] = { 0x00 };
219
219
return sendBytes (payload, 1 , port, confirm);
220
220
}
@@ -227,7 +227,7 @@ void TheThingsNetwork::fillAirtimeInfo() {
227
227
this ->info .cr = 0 ;
228
228
this ->info .de = 0 ;
229
229
230
- int i;
230
+ uint8_t i;
231
231
String message = readValue (F (" radio get sf" ));
232
232
for (i = 2 ; message[i] && i <= 3 ; i++) {
233
233
this ->info .sf = (this ->info .sf + message[i] - 48 ) * 10 ;
@@ -252,12 +252,12 @@ void TheThingsNetwork::fillAirtimeInfo() {
252
252
this ->info .de = this ->info .sf >= 11 ? 1 : 0 ;
253
253
}
254
254
255
- void TheThingsNetwork::trackAirtime (int payloadSize) {
255
+ void TheThingsNetwork::trackAirtime (size_t payloadSize) {
256
256
payloadSize = 13 + payloadSize;
257
257
258
258
float Tsym = pow (2 , this ->info .sf ) / this ->info .band ;
259
259
float Tpreamble = (this ->info .ps + 4.25 ) * Tsym;
260
- unsigned int payLoadSymbNb = 8 + (max (ceil ((8 * payloadSize - 4 * this ->info .sf + 28 + 16 - 20 * this ->info .header ) / (4 * (this ->info .sf - 2 * this ->info .de ))) * (this ->info .cr + 4 ), 0 ));
260
+ uint16_t payLoadSymbNb = 8 + (max (ceil ((8 * payloadSize - 4 * this ->info .sf + 28 + 16 - 20 * this ->info .header ) / (4 * (this ->info .sf - 2 * this ->info .de ))) * (this ->info .cr + 4 ), 0 ));
261
261
float Tpayload = payLoadSymbNb * Tsym;
262
262
float Tpacket = Tpreamble + Tpayload;
263
263
this ->airtime = this ->airtime + (Tpacket / 1000 );
@@ -288,10 +288,10 @@ void TheThingsNetwork::showStatus() {
288
288
debugPrintLn (F (" s" ));
289
289
}
290
290
291
- void TheThingsNetwork::configureEU868 (int sf) {
292
- int ch;
293
- int dr = -1 ;
294
- long int freq = 867100000 ;
291
+ void TheThingsNetwork::configureEU868 (uint8_t sf) {
292
+ uint8_t ch;
293
+ int8_t dr = -1 ;
294
+ uint32_t freq = 867100000 ;
295
295
String str = " " ;
296
296
297
297
str.concat (F (" mac set rx2 3 869525000" ));
@@ -360,13 +360,13 @@ void TheThingsNetwork::configureEU868(int sf) {
360
360
}
361
361
}
362
362
363
- void TheThingsNetwork::configureUS915 (int sf, int fsb) {
364
- int ch;
365
- int dr = -1 ;
363
+ void TheThingsNetwork::configureUS915 (uint8_t sf, uint8_t fsb) {
364
+ uint8_t ch;
365
+ int8_t dr = -1 ;
366
366
String str = " " ;
367
- int chLow = fsb > 0 ? (fsb - 1 ) * 8 : 0 ;
368
- int chHigh = fsb > 0 ? chLow + 7 : 71 ;
369
- int ch500 = fsb + 63 ;
367
+ uint8_t chLow = fsb > 0 ? (fsb - 1 ) * 8 : 0 ;
368
+ uint8_t chHigh = fsb > 0 ? chLow + 7 : 71 ;
369
+ uint8_t ch500 = fsb + 63 ;
370
370
371
371
sendCommand (F (" radio set freq 904200000" ));
372
372
str = " " ;
@@ -419,7 +419,7 @@ void TheThingsNetwork::configureUS915(int sf, int fsb) {
419
419
}
420
420
}
421
421
422
- void TheThingsNetwork::configureChannels (int sf, int fsb) {
422
+ void TheThingsNetwork::configureChannels (uint8_t sf, uint8_t fsb) {
423
423
switch (this ->fp ) {
424
424
case TTN_FP_EU868:
425
425
configureEU868 (sf);
@@ -437,7 +437,7 @@ void TheThingsNetwork::configureChannels(int sf, int fsb) {
437
437
sendCommand (retries);
438
438
}
439
439
440
- TheThingsNetwork::TheThingsNetwork (Stream& modemStream, Stream& debugStream, ttn_fp_t fp, int sf, int fsb) {
440
+ TheThingsNetwork::TheThingsNetwork (Stream& modemStream, Stream& debugStream, ttn_fp_t fp, uint8_t sf, uint8_t fsb) {
441
441
this ->debugStream = &debugStream;
442
442
this ->modemStream = &modemStream;
443
443
this ->fp = fp;
0 commit comments