-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSX1272.h
executable file
·1413 lines (1228 loc) · 40.7 KB
/
SX1272.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Library for LoRa 868 / 915MHz SX1272 LoRa module
*
* Copyright (C) Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
* Version: 1.1
* Design: David Gascón
* Implementation: Covadonga Albiñana & Victor Boria
*/
#ifndef SX1272_h
#define SX1272_h
/******************************************************************************
* Includes
******************************************************************************/
#include <stdint.h>
#ifdef RASPBERRY2
#include "arduPi_pi2.h"
#else
#include "arduPi.h"
#endif
#ifndef inttypes_h
#include <inttypes.h>
#endif
/******************************************************************************
* Definitions & Declarations
*****************************************************************************/
// added by C. Pham
// do not remove!
#define W_REQUESTED_ACK
//#define W_NET_KEY
//#define W_INITIALIZATION
#define SX1272_RST 7
#define SX1272Chip 0
#define SX1276Chip 1
// end
#define SX1272_SS 10
#define SX1272_debug_mode 0
//! MACROS //
#define bitRead(value, bit) (((value) >> (bit)) & 0x01) // read a bit
#define bitSet(value, bit) ((value) |= (1UL << (bit))) // set bit to '1'
#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) // set bit to '0'
//! REGISTERS //
#define REG_FIFO 0x00
#define REG_OP_MODE 0x01
#define REG_BITRATE_MSB 0x02
#define REG_BITRATE_LSB 0x03
#define REG_FDEV_MSB 0x04
#define REG_FDEV_LSB 0x05
#define REG_FRF_MSB 0x06
#define REG_FRF_MID 0x07
#define REG_FRF_LSB 0x08
#define REG_PA_CONFIG 0x09
#define REG_PA_RAMP 0x0A
#define REG_OCP 0x0B
#define REG_LNA 0x0C
#define REG_RX_CONFIG 0x0D
#define REG_FIFO_ADDR_PTR 0x0D
#define REG_RSSI_CONFIG 0x0E
#define REG_FIFO_TX_BASE_ADDR 0x0E
#define REG_RSSI_COLLISION 0x0F
#define REG_FIFO_RX_BASE_ADDR 0x0F
#define REG_RSSI_THRESH 0x10
#define REG_FIFO_RX_CURRENT_ADDR 0x10
#define REG_RSSI_VALUE_FSK 0x11
#define REG_IRQ_FLAGS_MASK 0x11
#define REG_RX_BW 0x12
#define REG_IRQ_FLAGS 0x12
#define REG_AFC_BW 0x13
#define REG_RX_NB_BYTES 0x13
#define REG_OOK_PEAK 0x14
#define REG_RX_HEADER_CNT_VALUE_MSB 0x14
#define REG_OOK_FIX 0x15
#define REG_RX_HEADER_CNT_VALUE_LSB 0x15
#define REG_OOK_AVG 0x16
#define REG_RX_PACKET_CNT_VALUE_MSB 0x16
#define REG_RX_PACKET_CNT_VALUE_LSB 0x17
#define REG_MODEM_STAT 0x18
#define REG_PKT_SNR_VALUE 0x19
#define REG_AFC_FEI 0x1A
#define REG_PKT_RSSI_VALUE 0x1A
#define REG_AFC_MSB 0x1B
#define REG_RSSI_VALUE_LORA 0x1B
#define REG_AFC_LSB 0x1C
#define REG_HOP_CHANNEL 0x1C
#define REG_FEI_MSB 0x1D
#define REG_MODEM_CONFIG1 0x1D
#define REG_FEI_LSB 0x1E
#define REG_MODEM_CONFIG2 0x1E
#define REG_PREAMBLE_DETECT 0x1F
#define REG_SYMB_TIMEOUT_LSB 0x1F
#define REG_RX_TIMEOUT1 0x20
#define REG_PREAMBLE_MSB_LORA 0x20
#define REG_RX_TIMEOUT2 0x21
#define REG_PREAMBLE_LSB_LORA 0x21
#define REG_RX_TIMEOUT3 0x22
#define REG_PAYLOAD_LENGTH_LORA 0x22
#define REG_RX_DELAY 0x23
#define REG_MAX_PAYLOAD_LENGTH 0x23
#define REG_OSC 0x24
#define REG_HOP_PERIOD 0x24
#define REG_PREAMBLE_MSB_FSK 0x25
#define REG_FIFO_RX_BYTE_ADDR 0x25
#define REG_PREAMBLE_LSB_FSK 0x26
// added by C. Pham
#define REG_MODEM_CONFIG3 0x26
// end
#define REG_SYNC_CONFIG 0x27
#define REG_SYNC_VALUE1 0x28
#define REG_SYNC_VALUE2 0x29
#define REG_SYNC_VALUE3 0x2A
#define REG_SYNC_VALUE4 0x2B
#define REG_SYNC_VALUE5 0x2C
#define REG_SYNC_VALUE6 0x2D
#define REG_SYNC_VALUE7 0x2E
#define REG_SYNC_VALUE8 0x2F
#define REG_PACKET_CONFIG1 0x30
#define REG_PACKET_CONFIG2 0x31
#define REG_DETECT_OPTIMIZE 0x31
#define REG_PAYLOAD_LENGTH_FSK 0x32
#define REG_NODE_ADRS 0x33
#define REG_BROADCAST_ADRS 0x34
#define REG_FIFO_THRESH 0x35
#define REG_SEQ_CONFIG1 0x36
#define REG_SEQ_CONFIG2 0x37
#define REG_DETECTION_THRESHOLD 0x37
#define REG_TIMER_RESOL 0x38
#define REG_TIMER1_COEF 0x39
// added by C. Pham
#define REG_SYNC_WORD 0x39
//end
#define REG_TIMER2_COEF 0x3A
#define REG_IMAGE_CAL 0x3B
#define REG_TEMP 0x3C
#define REG_LOW_BAT 0x3D
#define REG_IRQ_FLAGS1 0x3E
#define REG_IRQ_FLAGS2 0x3F
#define REG_DIO_MAPPING1 0x40
#define REG_DIO_MAPPING2 0x41
#define REG_VERSION 0x42
#define REG_AGC_REF 0x43
#define REG_AGC_THRESH1 0x44
#define REG_AGC_THRESH2 0x45
#define REG_AGC_THRESH3 0x46
#define REG_PLL_HOP 0x4B
#define REG_TCXO 0x58
#define REG_PA_DAC 0x5A
#define REG_PLL 0x5C
#define REG_PLL_LOW_PN 0x5E
#define REG_FORMER_TEMP 0x6C
#define REG_BIT_RATE_FRAC 0x70
// added by C. Pham
// copied from LoRaMAC-Node
/*!
* RegImageCal
*/
#define RF_IMAGECAL_AUTOIMAGECAL_MASK 0x7F
#define RF_IMAGECAL_AUTOIMAGECAL_ON 0x80
#define RF_IMAGECAL_AUTOIMAGECAL_OFF 0x00 // Default
#define RF_IMAGECAL_IMAGECAL_MASK 0xBF
#define RF_IMAGECAL_IMAGECAL_START 0x40
#define RF_IMAGECAL_IMAGECAL_RUNNING 0x20
#define RF_IMAGECAL_IMAGECAL_DONE 0x00 // Default
#define RF_IMAGECAL_TEMPCHANGE_HIGHER 0x08
#define RF_IMAGECAL_TEMPCHANGE_LOWER 0x00
#define RF_IMAGECAL_TEMPTHRESHOLD_MASK 0xF9
#define RF_IMAGECAL_TEMPTHRESHOLD_05 0x00
#define RF_IMAGECAL_TEMPTHRESHOLD_10 0x02 // Default
#define RF_IMAGECAL_TEMPTHRESHOLD_15 0x04
#define RF_IMAGECAL_TEMPTHRESHOLD_20 0x06
#define RF_IMAGECAL_TEMPMONITOR_MASK 0xFE
#define RF_IMAGECAL_TEMPMONITOR_ON 0x00 // Default
#define RF_IMAGECAL_TEMPMONITOR_OFF 0x01
// added by C. Pham
// The crystal oscillator frequency of the module
#define RH_LORA_FXOSC 32000000.0
// The Frequency Synthesizer step = RH_LORA_FXOSC / 2^^19
#define RH_LORA_FCONVERT (524288 / RH_LORA_FXOSC)
// Frf = frf(Hz)*2^19/RH_LORA_FXOSC
/////
//FREQUENCY CHANNELS:
// added by C. Pham for Senegal
const uint32_t CH_04_868 = 0xD7CCCC; // channel 04, central freq = 863.20MHz
const uint32_t CH_05_868 = 0xD7E000; // channel 05, central freq = 863.50MHz
const uint32_t CH_06_868 = 0xD7F333; // channel 06, central freq = 863.80MHz
const uint32_t CH_07_868 = 0xD80666; // channel 07, central freq = 864.10MHz
const uint32_t CH_08_868 = 0xD81999; // channel 08, central freq = 864.40MHz
const uint32_t CH_09_868 = 0xD82CCC; // channel 09, central freq = 864.70MHz
//
const uint32_t CH_10_868 = 0xD84CCC; // channel 10, central freq = 865.20MHz
const uint32_t CH_11_868 = 0xD86000; // channel 11, central freq = 865.50MHz
const uint32_t CH_12_868 = 0xD87333; // channel 12, central freq = 865.80MHz
const uint32_t CH_13_868 = 0xD88666; // channel 13, central freq = 866.10MHz
const uint32_t CH_14_868 = 0xD89999; // channel 14, central freq = 866.40MHz
const uint32_t CH_15_868 = 0xD8ACCC; // channel 15, central freq = 866.70MHz
const uint32_t CH_16_868 = 0xD8C000; // channel 16, central freq = 867.00MHz
const uint32_t CH_17_868 = 0xD90000; // channel 17, central freq = 868.00MHz
// added by C. Pham
const uint32_t CH_18_868 = 0xD90666; // 868.1MHz for LoRaWAN test
const uint32_t CH_00_900 = 0xE1C51E; // channel 00, central freq = 903.08MHz
const uint32_t CH_01_900 = 0xE24F5C; // channel 01, central freq = 905.24MHz
const uint32_t CH_02_900 = 0xE2D999; // channel 02, central freq = 907.40MHz
const uint32_t CH_03_900 = 0xE363D7; // channel 03, central freq = 909.56MHz
const uint32_t CH_04_900 = 0xE3EE14; // channel 04, central freq = 911.72MHz
const uint32_t CH_05_900 = 0xE47851; // channel 05, central freq = 913.88MHz
const uint32_t CH_06_900 = 0xE5028F; // channel 06, central freq = 916.04MHz
const uint32_t CH_07_900 = 0xE58CCC; // channel 07, central freq = 918.20MHz
const uint32_t CH_08_900 = 0xE6170A; // channel 08, central freq = 920.36MHz
const uint32_t CH_09_900 = 0xE6A147; // channel 09, central freq = 922.52MHz
const uint32_t CH_10_900 = 0xE72B85; // channel 10, central freq = 924.68MHz
const uint32_t CH_11_900 = 0xE7B5C2; // channel 11, central freq = 926.84MHz
const uint32_t CH_12_900 = 0xE4C000; // default channel 915MHz, the module is configured with it
// added by C. Pham
const uint32_t CH_00_433 = 0x6C5333; // 433.3MHz
const uint32_t CH_01_433 = 0x6C6666; // 433.6MHz
const uint32_t CH_02_433 = 0x6C7999; // 433.9MHz
const uint32_t CH_03_433 = 0x6C9333; // 434.3MHz
// end
//LORA BANDWIDTH:
// modified by C. Pham
const uint8_t SX1272_BW_125 = 0x00;
const uint8_t SX1272_BW_250 = 0x01;
const uint8_t SX1272_BW_500 = 0x02;
// use the following constants with setBW()
const uint8_t BW_7_8 = 0x00;
const uint8_t BW_10_4 = 0x01;
const uint8_t BW_15_6 = 0x02;
const uint8_t BW_20_8 = 0x03;
const uint8_t BW_31_25 = 0x04;
const uint8_t BW_41_7 = 0x05;
const uint8_t BW_62_5 = 0x06;
const uint8_t BW_125 = 0x07;
const uint8_t BW_250 = 0x08;
const uint8_t BW_500 = 0x09;
// end
const double SignalBwLog[] =
{
5.0969100130080564143587833158265,
5.397940008672037609572522210551,
5.6989700043360188047862611052755
};
//LORA CODING RATE:
const uint8_t CR_5 = 0x01;
const uint8_t CR_6 = 0x02;
const uint8_t CR_7 = 0x03;
const uint8_t CR_8 = 0x04;
//LORA SPREADING FACTOR:
const uint8_t SF_6 = 0x06;
const uint8_t SF_7 = 0x07;
const uint8_t SF_8 = 0x08;
const uint8_t SF_9 = 0x09;
const uint8_t SF_10 = 0x0A;
const uint8_t SF_11 = 0x0B;
const uint8_t SF_12 = 0x0C;
//LORA MODES:
const uint8_t LORA_SLEEP_MODE = 0x80;
const uint8_t LORA_STANDBY_MODE = 0x81;
const uint8_t LORA_TX_MODE = 0x83;
const uint8_t LORA_RX_MODE = 0x85;
// added by C. Pham
const uint8_t LORA_CAD_MODE = 0x87;
#define LNA_MAX_GAIN 0x23
#define LNA_OFF_GAIN 0x00
#define LNA_LOW_GAIN 0x20
//end
const uint8_t LORA_STANDBY_FSK_REGS_MODE = 0xC1;
//FSK MODES:
const uint8_t FSK_SLEEP_MODE = 0x00;
const uint8_t FSK_STANDBY_MODE = 0x01;
const uint8_t FSK_TX_MODE = 0x03;
const uint8_t FSK_RX_MODE = 0x05;
//OTHER CONSTANTS:
const uint8_t HEADER_ON = 0;
const uint8_t HEADER_OFF = 1;
const uint8_t CRC_ON = 1;
const uint8_t CRC_OFF = 0;
const uint8_t LORA = 1;
const uint8_t FSK = 0;
const uint8_t BROADCAST_0 = 0x00;
const uint8_t MAX_LENGTH = 255;
const uint8_t MAX_PAYLOAD = 251;
const uint8_t MAX_LENGTH_FSK = 64;
const uint8_t MAX_PAYLOAD_FSK = 60;
//modified by C. Pham, 7 instead of 5 because we added a type field which should be PKT_TYPE_ACK and the SNR
const uint8_t ACK_LENGTH = 7;
// added by C. Pham
#ifdef W_NET_KEY
const uint8_t NET_KEY_LENGTH=2;
const uint8_t OFFSET_PAYLOADLENGTH = 4+NET_KEY_LENGTH;
const uint8_t net_key_0 = 0x12;
const uint8_t net_key_1 = 0x34;
#else
// modified by C. Pham to remove the retry field
const uint8_t OFFSET_PAYLOADLENGTH = 4;
#endif
const uint8_t OFFSET_RSSI = 139;
const uint8_t NOISE_FIGURE = 6.0;
const uint8_t NOISE_ABSOLUTE_ZERO = 174.0;
const uint16_t MAX_TIMEOUT = 10000; //10000 msec = 10.0 sec
const uint16_t MAX_WAIT = 12000; //12000 msec = 12.0 sec
const uint8_t MAX_RETRIES = 5;
const uint8_t CORRECT_PACKET = 0;
const uint8_t INCORRECT_PACKET = 1;
const uint8_t INCORRECT_PACKET_TYPE = 2;
// added by C. Pham
// Packet type definition
#define PKT_TYPE_MASK 0xF0
#define PKT_FLAG_MASK 0x0F
#define PKT_TYPE_DATA 0x10
#define PKT_TYPE_ACK 0x20
#define PKT_FLAG_ACK_REQ 0x08
#define PKT_FLAG_DATA_ENCRYPTED 0x04
#define PKT_FLAG_DATA_WAPPKEY 0x02
#define PKT_FLAG_DATA_DOWNLINK 0x01
#define SX1272_ERROR_ACK 3
#define SX1272_ERROR_TOA 4
//! Structure :
/*!
*/
struct pack
{
// added by C. Pham
#ifdef W_NET_KEY
uint8_t netkey[NET_KEY_LENGTH];
#endif
//! Structure Variable : Packet destination
/*!
*/
uint8_t dst;
// added by C. Pham
//! Structure Variable : Packet type
/*!
*/
uint8_t type;
//! Structure Variable : Packet source
/*!
*/
uint8_t src;
//! Structure Variable : Packet number
/*!
*/
uint8_t packnum;
// modified by C. Pham
// will not be used in the transmitted packet
//! Structure Variable : Packet length
/*!
*/
uint8_t length;
//! Structure Variable : Packet payload
/*!
*/
uint8_t* data;
// modified by C. Pham
// will not be used in the transmitted packet
//! Structure Variable : Retry number
/*!
*/
uint8_t retry;
};
/******************************************************************************
* Class
******************************************************************************/
//! SX1272 Class
/*!
SX1272 Class defines all the variables and functions used to manage
SX1272 modules.
*/
class SX1272
{
public:
SX1272();
//! It puts the module ON
/*!
\param void
\return uint8_t setLORA state
*/
uint8_t ON();
//! It puts the module OFF
/*!
\param void
\return void
*/
void OFF();
//! It reads an internal module register.
/*!
\param byte address : address register to read from.
\return the content of the register.
*/
byte readRegister(byte address);
//! It writes in an internal module register.
/*!
\param byte address : address register to write in.
\param byte data : value to write in the register.
*/
void writeRegister(byte address, byte data);
//! It clears the interruption flags.
/*!
\param void
\return void
*/
void clearFlags();
//! It sets the LoRa mode on.
/*!
It stores in global '_LORA' variable '1' when success
\return '0' on success, '1' otherwise
*/
uint8_t setLORA();
//! It sets the FSK mode on.
/*!
It stores in global '_FSK' variable '1' when success
\return '0' on success, '1' otherwise
*/
uint8_t setFSK();
//! It gets the BW, SF and CR of the module.
/*!
It stores in global '_bandwidth' variable the BW
It stores in global '_codingRate' variable the CR
It stores in global '_spreadingFactor' variable the SF
\return '0' on success, '1' otherwise
*/
uint8_t getMode();
//! It sets the BW, SF and CR of the module.
/*!
It stores in global '_bandwidth' variable the BW
It stores in global '_codingRate' variable the CR
It stores in global '_spreadingFactor' variable the SF
\param uint8_t mode : there is a mode number to different values of
the configured parameters with this function.
\return '0' on success, '1' otherwise
*/
int8_t setMode(uint8_t mode);
//! It gets the header mode configured.
/*!
It stores in global '_header' variable '0' when header is sent
(explicit header mode) or '1' when is not sent (implicit header
mode).
\return '0' on success, '1' otherwise
*/
uint8_t getHeader();
//! It sets explicit header mode.
/*!
It stores in global '_header' variable '1' when success
\return '0' on success, '1' otherwise
*/
int8_t setHeaderON();
//! It sets implicit header mode.
/*!
It stores in global '_header' variable '0' when success
\return '0' on success, '1' otherwise
*/
int8_t setHeaderOFF();
//! It gets the CRC configured.
/*!
It stores in global '_CRC' variable '1' enabling CRC generation on
payload, or '0' disabling the CRC.
\return '0' on success, '1' otherwise
*/
uint8_t getCRC();
//! It sets CRC on.
/*!
It stores in global '_CRC' variable '1' when success
\return '0' on success, '1' otherwise
*/
uint8_t setCRC_ON();
//! It sets CRC off.
/*!
It stores in global '_CRC' variable '0' when success
\return '0' on success, '1' otherwise
*/
uint8_t setCRC_OFF();
//! It is true if the SF selected exists.
/*!
\param uint8_t spr : spreading factor value to check.
\return 'true' on success, 'false' otherwise
*/
boolean isSF(uint8_t spr);
//! It gets the SF configured.
/*!
It stores in global '_spreadingFactor' variable the current value of SF
\return '0' on success, '1' otherwise
*/
int8_t getSF();
//! It sets the SF.
/*!
It stores in global '_spreadingFactor' variable the current value of SF
\param uint8_t spr : spreading factor value to set in the configuration.
\return '0' on success, '1' otherwise
*/
uint8_t setSF(uint8_t spr);
//! It is true if the BW selected exists.
/*!
\param uint16_t band : bandwidth value to check.
\return 'true' on success, 'false' otherwise
*/
boolean isBW(uint16_t band);
//! It gets the BW configured.
/*!
It stores in global '_bandwidth' variable the BW selected
in the configuration
\return '0' on success, '1' otherwise
*/
int8_t getBW();
//! It sets the BW.
/*!
It stores in global '_bandwidth' variable the BW selected
in the configuration
\param uint16_t band : bandwidth value to set in the configuration.
\return '0' on success, '1' otherwise
*/
int8_t setBW(uint16_t band);
//! It is true if the CR selected exists.
/*!
\param uint8_t cod : the coding rate value to check.
\return 'true' on success, 'false' otherwise
*/
boolean isCR(uint8_t cod);
//! It gets the CR configured.
/*!
It stores in global '_codingRate' variable the CR selected
in the configuration
\return '0' on success, '1' otherwise
*/
int8_t getCR();
//! It sets the CR.
/*!
It stores in global '_codingRate' variable the CR selected
in the configuration
\param uint8_t cod : coding rate value to set in the configuration.
\return '0' on success, '1' otherwise
*/
int8_t setCR(uint8_t cod);
//! It is true if the channel selected exists.
/*!
\param uint32_t ch : frequency channel value to check.
\return 'true' on success, 'false' otherwise
*/
boolean isChannel(uint32_t ch);
//! It gets frequency channel the module is using.
/*!
It stores in global '_channel' variable the frequency channel
\return '0' on success, '1' otherwise
*/
uint8_t getChannel();
//! It sets frequency channel the module is using.
/*!
It stores in global '_channel' variable the frequency channel
\param uint32_t ch : frequency channel value to set in the configuration.
\return '0' on success, '1' otherwise
*/
int8_t setChannel(uint32_t ch);
//! It gets the output power of the signal.
/*!
It stores in global '_power' variable the output power of the signal
\return '0' on success, '1' otherwise
*/
uint8_t getPower();
//! It sets the output power of the signal.
/*!
It stores in global '_power' variable the output power of the signal
\param char p : 'M', 'H' or 'L' if you want Maximum, High or Low
output power signal.
\return '0' on success, '1' otherwise
*/
int8_t setPower(char p);
//! It sets the output power of the signal.
/*!
It stores in global '_power' variable the output power of the signal
\param uint8_t pow : value to set as output power.
\return '0' on success, '1' otherwise
*/
int8_t setPowerNum(uint8_t pow);
//! It gets the preamble length configured.
/*!
It stores in global '_preamblelength' variable the preamble length
\return '0' on success, '1' otherwise
*/
uint8_t getPreambleLength();
//! It sets the preamble length.
/*!
It stores in global '_preamblelength' variable the preamble length
\param uint16_t l : preamble length to set in the configuration.
\return '0' on success, '1' otherwise
*/
uint8_t setPreambleLength(uint16_t l);
//! It gets the payload length of the last packet to send/receive.
/*!
It stores in global '_payloadlength' variable the payload length of
the last packet to send/receive.
\return '0' on success, '1' otherwise
*/
uint8_t getPayloadLength();
//! It sets the packet length to send/receive.
/*!
It stores in global '_payloadlength' variable the payload length of
the last packet to send/receive.
\return '0' on success, '1' otherwise
*/
int8_t setPacketLength();
//! It sets the packet length to send/receive.
/*!
It stores in global '_payloadlength' variable the payload length of
the last packet to send/receive.
\param uint8_t l : payload length to set in the configuration.
\return '0' on success, '1' otherwise
*/
int8_t setPacketLength(uint8_t l);
//! It gets the node address of the mote.
/*!
It stores in global '_nodeAddress' variable the node address
\return '0' on success, '1' otherwise
*/
uint8_t getNodeAddress();
//! It sets the node address of the mote.
/*!
It stores in global '_nodeAddress' variable the node address
\param uint8_t addr : address value to set as node address.
\return '0' on success, '1' otherwise
*/
int8_t setNodeAddress(uint8_t addr);
//! It gets the SNR of the latest received packet.
/*!
It stores in global '_SNR' variable the SNR
\return '0' on success, '1' otherwise
*/
int8_t getSNR();
//! It gets the current value of RSSI.
/*!
It stores in global '_RSSI' variable the current value of RSSI
\return '0' on success, '1' otherwise
*/
uint8_t getRSSI();
//! It gets the RSSI of the latest received packet.
/*!
It stores in global '_RSSIpacket' variable the RSSI of the latest
packet received.
\return '0' on success, '1' otherwise
*/
int16_t getRSSIpacket();
//! It sets the total of retries when a packet is not correctly received.
/*!
It stores in global '_maxRetries' variable the number of retries.
\param uint8_t ret : number of retries.
\return '0' on success, '1' otherwise
*/
uint8_t setRetries(uint8_t ret);
//! It gets the maximum current supply by the module.
/*!
*
\return '0' on success, '1' otherwise
*/
uint8_t getMaxCurrent();
//! It sets the maximum current supply by the module.
/*!
It stores in global '_maxCurrent' variable the maximum current supply.
\param uint8_t rate : maximum current supply.
\return '0' on success, '1' otherwise
*/
int8_t setMaxCurrent(uint8_t rate);
//! It gets the content of the main configuration registers.
/*!
It stores in global '_bandwidth' variable the BW.
It stores in global '_codingRate' variable the CR.
It stores in global '_spreadingFactor' variable the SF.
It stores in global '_power' variable the output power of the signal.
It stores in global '_channel' variable the frequency channel.
It stores in global '_CRC' variable '1' enabling CRC generation on
payload, or '0' disabling the CRC.
It stores in global '_header' variable '0' when header is sent
(explicit header mode) or '1' when is not sent (implicit header
mode).
It stores in global '_preamblelength' variable the preamble length.
It stores in global '_payloadlength' variable the payload length of
the last packet to send/receive.
It stores in global '_nodeAddress' variable the node address.
It stores in global '_temp' variable the module temperature.
\return '0' on success, '1' otherwise
*/
uint8_t getRegs();
//! It sets the maximum number of bytes from a frame that fit in a packet structure.
/*!
It stores in global '_payloadlength' variable the maximum number of bytes.
\param uint16_t length16 : total frame length.
\return '0' on success, '1' otherwise
*/
uint8_t truncPayload(uint16_t length16);
//! It writes an ACK in FIFO to send it.
/*!
*
\return '0' on success, '1' otherwise
*/
uint8_t setACK();
//! It puts the module in reception mode.
/*!
*
\return '0' on success, '1' otherwise
*/
uint8_t receive();
//! It receives a packet before MAX_TIMEOUT.
/*!
*
\return '0' on success, '1' otherwise
*/
uint8_t receivePacketMAXTimeout();
//! It receives a packet before a timeout.
/*!
*
\return '0' on success, '1' otherwise
*/
uint8_t receivePacketTimeout();
//! It receives a packet before a timeout.
/*!
\param uint16_t wait : time to wait to receive something.
\return '0' on success, '1' otherwise
*/
uint8_t receivePacketTimeout(uint16_t wait);
//! It receives a packet before MAX_TIMEOUT and reply with an ACK.
/*!
*
\return '0' on success, '1' otherwise
*/
uint8_t receivePacketMAXTimeoutACK();
//! It receives a packet before a timeout and reply with an ACK.
/*!
*
\return '0' on success, '1' otherwise
*/
uint8_t receivePacketTimeoutACK();
//! It receives a packet before a timeout and reply with an ACK.
/*!
\param uint16_t wait : time to wait to receive something.
\return '0' on success, '1' otherwise
*/
uint8_t receivePacketTimeoutACK(uint16_t wait);
//! It puts the module in 'promiscuous' reception mode.
/*!
*
\return '0' on success, '1' otherwise
*/
uint8_t receiveAll();
//! It puts the module in 'promiscuous' reception mode with a timeout.
/*!
\param uint16_t wait : time to wait to receive something.
\return '0' on success, '1' otherwise
*/
uint8_t receiveAll(uint16_t wait);
//! It checks if there is an available packet and its destination.
/*!
*
\return 'true' on success, 'false' otherwise
*/
boolean availableData();
//! It checks if there is an available packet and its destination before a timeout.
/*!
*
\param uint16_t wait : time to wait while there is no a valid header received.
\return 'true' on success, 'false' otherwise
*/
boolean availableData(uint16_t wait);
//! It writes a packet in FIFO in order to send it.
/*!
\param uint8_t dest : packet destination.
\param char *payload : packet payload.
\return '0' on success, '1' otherwise
*/
uint8_t setPacket(uint8_t dest, char *payload);
//! It writes a packet in FIFO in order to send it.
/*!
\param uint8_t dest : packet destination.
\param uint8_t *payload: packet payload.
\return '0' on success, '1' otherwise
*/
uint8_t setPacket(uint8_t dest, uint8_t *payload);
//! It reads a received packet from the FIFO, if it arrives before ending MAX_TIMEOUT time.
/*!
*
\return '0' on success, '1' otherwise
*/
uint8_t getPacketMAXTimeout();
//! It reads a received packet from the FIFO, if it arrives before ending '_sendTime' time.
/*!
*
\return '0' on success, '1' otherwise
*/
int8_t getPacket();
//! It receives and gets a packet from FIFO, if it arrives before ending 'wait' time.
/*!
*
\param uint16_t wait : time to wait while there is no a complete packet received.
\return '0' on success, '1' otherwise
*/
int8_t getPacket(uint16_t wait);
//! It sends the packet stored in FIFO before ending MAX_TIMEOUT.
/*!
*
\return '0' on success, '1' otherwise
*/
uint8_t sendWithMAXTimeout();
//! It sends the packet stored in FIFO before ending _sendTime time.
/*!
*
\return '0' on success, '1' otherwise
*/
uint8_t sendWithTimeout();
//! It tries to send the packet stored in FIFO before ending 'wait' time.
/*!
\param uint16_t wait : time to wait to send the packet.
\return '0' on success, '1' otherwise
*/
uint8_t sendWithTimeout(uint16_t wait);
//! It tries to send the packet wich payload is a parameter before ending MAX_TIMEOUT.
/*!
\param uint8_t dest : packet destination.
\param char *payload : packet payload.
\return '0' on success, '1' otherwise
*/
uint8_t sendPacketMAXTimeout(uint8_t dest, char *payload);
//! It tries to send the packet wich payload is a parameter before ending MAX_TIMEOUT.
/*!
\param uint8_t dest : packet destination.
\param uint8_t *payload : packet payload.
\param uint16_t length : payload buffer length.
\return '0' on success, '1' otherwise
*/
uint8_t sendPacketMAXTimeout(uint8_t dest, uint8_t *payload, uint16_t length);
//! It sends the packet wich payload is a parameter before ending MAX_TIMEOUT.
/*!
\param uint8_t dest : packet destination.
\param char *payload : packet payload.
\return '0' on success, '1' otherwise
*/
uint8_t sendPacketTimeout(uint8_t dest, char *payload);
//! It sends the packet wich payload is a parameter before ending MAX_TIMEOUT.
/*!
\param uint8_t dest : packet destination.
\param uint8_t *payload: packet payload.
\param uint16_t length : payload buffer length.
\return '0' on success, '1' otherwise
*/
uint8_t sendPacketTimeout(uint8_t dest, uint8_t *payload, uint16_t length);
//! It sends the packet wich payload is a parameter before ending 'wait' time.
/*!
\param uint8_t dest : packet destination.
\param char *payload : packet payload.
\param uint16_t wait : time to wait.
\return '0' on success, '1' otherwise
*/
uint8_t sendPacketTimeout(uint8_t dest, char *payload, uint16_t wait);
//! It sends the packet wich payload is a parameter before ending 'wait' time.
/*!
\param uint8_t dest : packet destination.
\param uint8_t *payload : packet payload.
\param uint16_t length : payload buffer length.
\param uint16_t wait : time to wait.
\return '0' on success, '1' otherwise
*/
uint8_t sendPacketTimeout(uint8_t dest, uint8_t *payload, uint16_t length, uint16_t wait);
//! It sends the packet wich payload is a parameter before MAX_TIMEOUT, and replies with ACK.
/*!