19
19
20
20
typedef uint8_t port_t ;
21
21
22
- enum ttn_response_t {
22
+ enum ttn_response_t
23
+ {
23
24
TTN_ERROR_SEND_COMMAND_FAILED = (-1 ),
24
25
TTN_ERROR_UNEXPECTED_RESPONSE = (-10 ),
25
26
TTN_SUCCESSFUL_TRANSMISSION = 1 ,
26
27
TTN_SUCCESSFUL_RECEIVE = 2
27
28
};
28
29
29
- enum ttn_fp_t {
30
+ enum ttn_fp_t
31
+ {
30
32
TTN_FP_EU868,
31
33
TTN_FP_US915
32
34
};
33
35
34
- typedef struct airtime_s
36
+ typedef struct airtime_s
35
37
{
36
38
uint8_t sf;
37
39
uint8_t de;
@@ -43,55 +45,55 @@ typedef struct airtime_s
43
45
44
46
class TheThingsNetwork
45
47
{
46
- private:
47
- port_t port;
48
- Stream* modemStream;
49
- Stream* debugStream;
50
- bool model_EU;
51
- airtime_t info;
52
- ttn_fp_t fp;
53
- uint8_t sf;
54
- uint8_t fsb;
55
- void (* messageCallback)(const byte* payload, size_t length, port_t port);
48
+ private:
49
+ port_t port;
50
+ Stream * modemStream;
51
+ Stream * debugStream;
52
+ bool model_EU;
53
+ airtime_t info;
54
+ ttn_fp_t fp;
55
+ uint8_t sf;
56
+ uint8_t fsb;
57
+ void (*messageCallback)(const byte * payload, size_t length, port_t port);
56
58
57
- const char * readLine ( );
58
- void fillAirtimeInfo ();
59
- void trackAirtime (size_t payloadSize);
60
- void reset (bool adr = true );
61
- void configureEU868 (uint8_t sf);
62
- void configureUS915 (uint8_t sf, uint8_t fsb);
63
- void configureChannels (uint8_t sf, uint8_t fsb);
64
- bool waitForOk ();
65
- void sendCommand (uint8_t table, uint8_t index, bool with_space, bool print = true );
66
- bool sendMacSet (uint8_t index, const char * setting);
67
- bool sendChSet (uint8_t index, uint8_t channel, const char * setting);
68
- bool sendJoinSet (uint8_t type);
69
- bool sendPayload (uint8_t mode, uint8_t port, uint8_t * payload, size_t len);
70
- void sendGetValue (uint8_t table, uint8_t prefix, uint8_t index);
71
- const char *subString (const char *response, int16_t start, int16_t end = -2 );
72
- bool compareStrings (const char *str1, uint8_t msg, size_t length = -2 );
73
- uint8_t receivedPort (const char *response, size_t length);
74
- size_t bufLength (const char *data);
75
- size_t portLength (size_t port);
76
- const char *readValue (uint8_t prefixTable, uint8_t indexTable, uint8_t index);
77
- const char *readValue (uint8_t table, uint8_t index);
78
- void stateMessage (uint8_t type, uint8_t indexMsg, const char *output = NULL );
79
- void valueToShow (uint8_t index, const char *value = NULL );
59
+ uint32_t readLine ( const byte *buffer, uint32_t size );
60
+ void fillAirtimeInfo ();
61
+ void trackAirtime (size_t payloadSize);
62
+ void reset (bool adr = true );
63
+ void configureEU868 (uint8_t sf);
64
+ void configureUS915 (uint8_t sf, uint8_t fsb);
65
+ void configureChannels (uint8_t sf, uint8_t fsb);
66
+ bool waitForOk ();
67
+ void sendCommand (uint8_t table, uint8_t index, bool with_space, bool print = true );
68
+ bool sendMacSet (uint8_t index, const char * setting);
69
+ bool sendChSet (uint8_t index, uint8_t channel, const char * setting);
70
+ bool sendJoinSet (uint8_t type);
71
+ bool sendPayload (uint8_t mode, uint8_t port, uint8_t * payload, size_t len);
72
+ void sendGetValue (uint8_t table, uint8_t prefix, uint8_t index);
73
+ const char *subString (const char *response, int16_t start, int16_t end = -2 );
74
+ bool compareStrings (const char *str1, uint8_t msg, size_t length = -2 );
75
+ uint8_t receivedPort (const char *response, size_t length);
76
+ size_t bufLength (const char *data);
77
+ size_t portLength (size_t port);
78
+ const char *readValue (uint8_t prefixTable, uint8_t indexTable, uint8_t index);
79
+ const char *readValue (uint8_t table, uint8_t index);
80
+ void stateMessage (uint8_t type, uint8_t indexMsg, const char *output = NULL );
81
+ void valueToShow (uint8_t index, const char *value = NULL );
80
82
81
- public:
82
- TheThingsNetwork (Stream& modemStream, Stream& debugStream, ttn_fp_t fp, uint8_t sf = TTN_DEFAULT_SF, uint8_t fsb = TTN_DEFAULT_FSB);
83
- float airtime;
84
- float calculateAirtime (size_t payload);
85
- void showStatus ();
86
- void onMessage (void (*cb)(const byte* payload, size_t length, port_t port));
87
- bool provision (const char *appEui, const char *appKey);
88
- bool join (const char *appEui, const char *appKey, int8_t retries = -1 , uint32_t retryDelay = 10000 );
89
- bool join (int8_t retries = -1 , uint32_t retryDelay = 10000 );
90
- bool personalize (const char *devAddr, const char *nwkSKey, const char *appSKey);
91
- bool personalize ();
92
- ttn_response_t sendBytes (const byte* payload, size_t length, port_t port = 1 , bool confirm = false );
93
- void sleep (unsigned long mseconds);
94
- int8_t poll (port_t port = 1 , bool confirm = false );
83
+ public:
84
+ TheThingsNetwork (Stream & modemStream, Stream & debugStream, ttn_fp_t fp, uint8_t sf = TTN_DEFAULT_SF, uint8_t fsb = TTN_DEFAULT_FSB);
85
+ float airtime;
86
+ float calculateAirtime (size_t payload);
87
+ void showStatus ();
88
+ void onMessage (void (*cb)(const byte * payload, size_t length, port_t port));
89
+ bool provision (const char *appEui, const char *appKey);
90
+ bool join (const char *appEui, const char *appKey, int8_t retries = -1 , uint32_t retryDelay = 10000 );
91
+ bool join (int8_t retries = -1 , uint32_t retryDelay = 10000 );
92
+ bool personalize (const char *devAddr, const char *nwkSKey, const char *appSKey);
93
+ bool personalize ();
94
+ ttn_response_t sendBytes (const byte * payload, size_t length, port_t port = 1 , bool confirm = false );
95
+ void sleep (unsigned long mseconds);
96
+ int8_t poll (port_t port = 1 , bool confirm = false );
95
97
};
96
98
97
99
#endif
0 commit comments