@@ -12,17 +12,66 @@ static const char *otRoleString[] = {
12
12
" Leader" , // /< The Thread Leader role.
13
13
};
14
14
15
- ot_device_role_t getOtDeviceRole () {
15
+ ot_device_role_t otGetDeviceRole () {
16
+ if (!OThreadCLI) {
17
+ return OT_ROLE_DISABLED;
18
+ }
16
19
otInstance *instance = esp_openthread_get_instance ();
17
20
return (ot_device_role_t ) otThreadGetDeviceRole (instance);
18
21
}
19
22
20
- const char * getStringOtDeviceRole () {
21
- return otRoleString[getOtDeviceRole ()];
23
+ const char * otGetStringDeviceRole () {
24
+ return otRoleString[otGetDeviceRole ()];
25
+ }
26
+
27
+ bool otGetRespCmd (const char *cmd, char *resp, uint32_t respTimeout) {
28
+ if (!OThreadCLI) {
29
+ return false ;
30
+ }
31
+ StreamString cliRespAllLines;
32
+ char cliResp[256 ] = {0 };
33
+ if (resp != NULL ) {
34
+ *resp = ' \0 ' ;
35
+ }
36
+ if (cmd == NULL ) {
37
+ return true ;
38
+ }
39
+ OThreadCLI.println (cmd);
40
+ log_d (" CMD[%s]" , cmd);
41
+ uint32_t timeout = millis () + respTimeout;
42
+ while (millis () < timeout) {
43
+ size_t len = OThreadCLI.readBytesUntil (' \n ' , cliResp, sizeof (cliResp));
44
+ // clip it on EOL
45
+ for (int i = 0 ; i < len; i++) {
46
+ if (cliResp[i] == ' \r ' || cliResp[i] == ' \n ' ) {
47
+ cliResp[i] = ' \0 ' ;
48
+ }
49
+ }
50
+ log_d (" Resp[%s]" , cliResp);
51
+ if (strncmp (cliResp, " Done" , 4 ) && strncmp (cliResp, " Error" , 4 )) {
52
+ cliRespAllLines += cliResp;
53
+ cliRespAllLines.println (); // Adds whatever EOL is for the OS
54
+ } else {
55
+ break ;
56
+ }
57
+ }
58
+ if (!strncmp (cliResp, " Error" , 4 ) || millis () > timeout) {
59
+ return false ;
60
+ }
61
+ if (resp != NULL ) {
62
+ strcpy (resp, cliRespAllLines.c_str ());
63
+ }
64
+ return true ;
22
65
}
23
66
24
67
bool otExecCommand (const char *cmd, const char *arg, ot_cmd_return_t *returnCode) {
25
- char cliResp[256 ];
68
+ if (!OThreadCLI) {
69
+ return false ;
70
+ }
71
+ char cliResp[256 ] = {0 };
72
+ if (cmd == NULL ) {
73
+ return true ;
74
+ }
26
75
if (arg == NULL ) {
27
76
OThreadCLI.println (cmd);
28
77
} else {
@@ -73,5 +122,40 @@ bool otExecCommand(const char *cmd, const char *arg, ot_cmd_return_t *returnCode
73
122
}
74
123
}
75
124
125
+ void otPrintNetworkInformation (Stream &output) {
126
+ if (!OThreadCLI) {
127
+ return ;
128
+ }
129
+ char resp[512 ];
130
+ output.println (" Thread Setup:" );
131
+ if (otGetRespCmd (" state" , resp)) {
132
+ output.printf (" Node State: \t %s" , resp);
133
+ }
134
+ if (otGetRespCmd (" networkname" , resp)) {
135
+ output.printf (" Network Name: \t %s" , resp);
136
+ }
137
+ if (otGetRespCmd (" channel" , resp)) {
138
+ output.printf (" Channel: \t %s" , resp);
139
+ }
140
+ if (otGetRespCmd (" panid" , resp)) {
141
+ output.printf (" Pan ID: \t %s" , resp);
142
+ }
143
+ if (otGetRespCmd (" extpanid" , resp)) {
144
+ output.printf (" Ext Pan ID: \t %s" , resp);
145
+ }
146
+ if (otGetRespCmd (" networkkey" , resp)) {
147
+ output.printf (" Network Key: \t %s" , resp);
148
+ }
149
+ if (otGetRespCmd (" ipaddr" , resp)) {
150
+ output.println (" Node IP Addresses are:" );
151
+ output.printf (" %s" , resp);
152
+ }
153
+ if (otGetRespCmd (" ipmaddr" , resp)) {
154
+ output.println (" Node Multicast Addresses are:" );
155
+ output.printf (" %s" , resp);
156
+ }
157
+ }
158
+
159
+
76
160
#endif /* CONFIG_OPENTHREAD_ENABLED */
77
161
#endif /* SOC_IEEE802154_SUPPORTED */
0 commit comments