1010#include < esp_wifi.h>
1111#include < esp_crc.h>
1212
13- #include " ../device/fuji .h"
13+ #include " fujiDevice .h"
1414#include " fnWiFi.h"
1515
1616#include " string_utils.h"
@@ -86,24 +86,24 @@ static void on_ping_timeout(esp_ping_handle_t hdl, void *args)
8686static void on_ping_end (esp_ping_handle_t hdl, void *args)
8787{
8888 ip_addr_t target_addr;
89- uint32_t transmitted;
90- uint32_t received;
91- uint32_t total_time_ms;
92- esp_ping_get_profile (hdl, ESP_PING_PROF_REQUEST, &transmitted, sizeof (transmitted));
93- esp_ping_get_profile (hdl, ESP_PING_PROF_REPLY, &received, sizeof (received));
94- esp_ping_get_profile (hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof (target_addr));
95- esp_ping_get_profile (hdl, ESP_PING_PROF_DURATION, &total_time_ms, sizeof (total_time_ms));
96- uint32_t loss = (uint32_t )((1 - ((float )received) / transmitted) * 100 );
97- if (IP_IS_V4 (&target_addr)) {
98- printf (" \n --- %s ping statistics ---" , inet_ntoa (*ip_2_ip4 (&target_addr)));
99- } else {
100- printf (" \n --- %s ping statistics ---" , inet6_ntoa (*ip_2_ip6 (&target_addr)));
101- }
102- printf (" %" PRIu32 " packets transmitted, %" PRIu32 " received, %" PRIu32 " %% packet loss, time %" PRIu32 " ms" ,
103- transmitted, received, loss, total_time_ms);
104- // delete the ping sessions, so that we clean up all resources and can create a new ping session
105- // we don't have to call delete function in the callback, instead we can call delete function from other tasks
106- esp_ping_delete_session (hdl);
89+ uint32_t transmitted;
90+ uint32_t received;
91+ uint32_t total_time_ms;
92+ esp_ping_get_profile (hdl, ESP_PING_PROF_REQUEST, &transmitted, sizeof (transmitted));
93+ esp_ping_get_profile (hdl, ESP_PING_PROF_REPLY, &received, sizeof (received));
94+ esp_ping_get_profile (hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof (target_addr));
95+ esp_ping_get_profile (hdl, ESP_PING_PROF_DURATION, &total_time_ms, sizeof (total_time_ms));
96+ uint32_t loss = (uint32_t )((1 - ((float )received) / transmitted) * 100 );
97+ if (IP_IS_V4 (&target_addr)) {
98+ printf (" \n --- %s ping statistics ---" , inet_ntoa (*ip_2_ip4 (&target_addr)));
99+ } else {
100+ printf (" \n --- %s ping statistics ---" , inet6_ntoa (*ip_2_ip6 (&target_addr)));
101+ }
102+ printf (" %" PRIu32 " packets transmitted, %" PRIu32 " received, %" PRIu32 " %% packet loss, time %" PRIu32 " ms" ,
103+ transmitted, received, loss, total_time_ms);
104+ // delete the ping sessions, so that we clean up all resources and can create a new ping session
105+ // we don't have to call delete function in the callback, instead we can call delete function from other tasks
106+ esp_ping_delete_session (hdl);
107107}
108108
109109static int ping (int argc, char **argv)
@@ -178,10 +178,10 @@ static int ping(int argc, char **argv)
178178 esp_ping_start (ping);
179179
180180 char c = 0 ;
181-
181+
182182 uint16_t seqno;
183183 esp_ping_get_profile (ping, ESP_PING_PROF_SEQNO, &seqno, sizeof (seqno));
184-
184+
185185 // Make stdin input non blocking so we can query for input AND check ping seqno
186186 int flags = fcntl (fileno (stdin), F_GETFL, 0 );
187187 fcntl (fileno (stdin), F_SETFL, flags | O_NONBLOCK);
@@ -224,7 +224,7 @@ static void ipconfig_wlan()
224224 // if (status == WL_NO_SHIELD) {
225225 // return;
226226 // }
227-
227+
228228 // printf("\r\n");
229229 // printf("SSID: %s\r\n", fnWiFi.get_current_ssid().c_str());
230230 // printf("BSSID: %s\r\n", fnWiFi.get_current_bssid_str().c_str());
@@ -235,7 +235,7 @@ static void ipconfig_wlan()
235235 // printf("Subnet Mask: %s (/%d)\r\n", WiFi.subnetMask().toString().c_str(), WiFi.subnetCIDR());
236236 // printf("Gateway: %s\r\n", WiFi.gatewayIP().toString().c_str());
237237 // printf("IPv6: %s\r\n", WiFi.localIPv6().toString().c_str());
238-
238+
239239 // printf("\r\n");
240240 // printf("Hostname: %s\r\n", WiFi.getHostname());
241241 // printf("DNS1: %s\r\n", WiFi.dnsIP(0).toString().c_str());
@@ -293,16 +293,16 @@ std::vector<std::string> getLocalUrl() {
293293 };
294294}
295295
296- void serial_write (std::vector<uint8_t > &data) {
296+ void serial_write (std::vector<uint8_t > &data) {
297297 // print buffer bytes
298298 for (int i = 0 ; i < data.size (); i++) {
299299 fprintf (stdout, " %c" , data[i]);
300300 }
301301}
302302
303303
304- void set_state (improv::State state) {
305-
304+ void set_state (improv::State state) {
305+
306306 std::vector<uint8_t > data = {' I' , ' M' , ' P' , ' R' , ' O' , ' V' };
307307 data.resize (11 );
308308 data[6 ] = improv::IMPROV_SERIAL_VERSION;
@@ -354,7 +354,7 @@ void set_error(improv::Error error) {
354354void getAvailableWifiNetworks () {
355355// int networkNum = WiFi.scanNetworks();
356356
357- // for (int id = 0; id < networkNum; ++id) {
357+ // for (int id = 0; id < networkNum; ++id) {
358358// std::vector<uint8_t> data = improv::build_rpc_response(
359359// improv::GET_WIFI_NETWORKS, {WiFi.SSID(id), String(WiFi.RSSI(id)), (WiFi.encryptionType(id) == WIFI_AUTH_OPEN ? "NO" : "YES")}, false);
360360// send_response(data);
@@ -432,7 +432,7 @@ static int improv_c(int argc, char **argv)
432432 } else {
433433 set_state (improv::State::STATE_AUTHORIZED);
434434 }
435-
435+
436436 break ;
437437 }
438438
@@ -442,23 +442,23 @@ static int improv_c(int argc, char **argv)
442442 set_error (improv::Error::ERROR_INVALID_RPC);
443443 break ;
444444 }
445-
445+
446446 set_state (improv::STATE_PROVISIONING);
447-
447+
448448 if (connectWifi (cmd.ssid , cmd.password )) {
449449
450450 // blink_led(100, 3);
451-
451+
452452 // TODO: Persist credentials here
453453
454- set_state (improv::STATE_PROVISIONED);
454+ set_state (improv::STATE_PROVISIONED);
455455 std::vector<uint8_t > data = improv::build_rpc_response (improv::WIFI_SETTINGS, getLocalUrl (), false );
456456 send_response (data);
457457 } else {
458458 set_state (improv::STATE_STOPPED);
459459 set_error (improv::Error::ERROR_UNABLE_TO_CONNECT);
460460 }
461-
461+
462462 break ;
463463 }
464464
@@ -520,4 +520,4 @@ namespace ESP32Console::Commands
520520 {
521521 return ConsoleCommand (" improv" , &improv_c, " Wifi config via IMPROV protocol" );
522522 }
523- }
523+ }
0 commit comments