-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathusb.cpp
More file actions
131 lines (117 loc) · 3.08 KB
/
usb.cpp
File metadata and controls
131 lines (117 loc) · 3.08 KB
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
#include "usb.h"
#include <Arduino.h>
#include "icons.h"
#include "screen.h"
#include "lorawan.h"
#include "SerialCommand.h"
#include "menu.h"
SerialCommand sCmd;
/**************************************************************************/
/*!
@brief Called by SerialCommand to set the OTAA keys.
*/
/**************************************************************************/
void setOtaaKeys(){
char *arg1;
char *arg2;
arg1 = sCmd.next();
if (arg1 == NULL || !(strlen(arg1) == 16)) {
Serial.println("INVALID APPEUI");
return;
}
arg2 = sCmd.next();
if (arg2 == NULL || !(strlen(arg2) == 32)) {
Serial.println("INVALID APPKEY");
return;
}
if(provisionOTAA(arg1,arg2)){
Serial.println("OK");
return;
} else {
Serial.println("RN2483 FAILURE");
}
return;
}
/**************************************************************************/
/*!
@brief Called by SerialCommand to set the ABP keys.
*/
/**************************************************************************/
void setAbpKeys(){
char *arg1;
char *arg2;
char *arg3;
arg1 = sCmd.next();
if (arg1 == NULL || !(strlen(arg1) == 8)) {
Serial.println("INVALID DEVADDR");
return;
}
arg2 = sCmd.next();
if (arg2 == NULL || !(strlen(arg2) == 32)) {
Serial.println("INVALID NWKSKEY");
return;
}
arg3 = sCmd.next();
if (arg3 == NULL || !(strlen(arg3) == 32)) {
Serial.println("INVALID APPSKEY");
return;
}
if(provisionABP(arg1,arg2,arg3)){
Serial.println("OK");
return;
} else {
Serial.println("RN2483 FAILURE");
}
return;
}
/**************************************************************************/
/*!
@brief Called by SerialCommand upon a request for the hardware EUI.
*/
/**************************************************************************/
void getHweui(){
char buffer[16];
if(getHweui(buffer, 16)>0){
Serial.println("OK");
Serial.print("Dev EUI: ");
Serial.println(buffer);
return;
}
Serial.println("RN2483 FAILURE");
return;
}
/**************************************************************************/
/*!
@brief called by SerialCommand to exit AT/USB/Serial mode
*/
/**************************************************************************/
void goToMenu() {
Serial.println("Exiting");
setState(&menuState);
}
/**************************************************************************/
/*!
@brief Sets up for AT/USB/Serial mode
*/
/**************************************************************************/
void enterUSBMode() {
drawFullScreenIcon(usbConnector);
sCmd.addCommand("!AT+CFGOTAA", setOtaaKeys);
sCmd.addCommand("!AT+CFGABP", setAbpKeys);
sCmd.addCommand("!AT+HWEUI?", getHweui);
sCmd.addCommand("!AT+EXIT", goToMenu);
Serial.println("USB MODE");
}
/**************************************************************************/
/*!
@brief Checks for commands on the serial line
*/
/**************************************************************************/
void usbSpin() {
sCmd.readSerial();
}
state usbState = {
&enterUSBMode,
&usbSpin,
NULL
};