Skip to content

Commit

Permalink
Replace Wifi by WiFi into src/
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple committed Jan 5, 2022
1 parent 6ddb3e4 commit b346dc8
Show file tree
Hide file tree
Showing 39 changed files with 220 additions and 220 deletions.
4 changes: 2 additions & 2 deletions examples/all-clusters-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ Start the console

From within the console you can then invoke rpcs:

rpcs.chip.rpc.Wifi.Connect(ssid=b"MySSID", secret=b"MyPASSWORD")
rpcs.chip.rpc.Wifi.GetIP6Address()
rpcs.chip.rpc.WiFi.Connect(ssid=b"MySSID", secret=b"MyPASSWORD")
rpcs.chip.rpc.WiFi.GetIP6Address()

rpcs.chip.rpc.Lighting.Get()
rpcs.chip.rpc.Lighting.Set(on=True, level=128, color=protos.chip.rpc.LightingColor(hue=5, saturation=5))
4 changes: 2 additions & 2 deletions examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,10 @@ class SetupListModel : public ListScreen::Model
{
std::string resetWiFi = "Reset WiFi";
std::string resetToFactory = "Reset to factory";
std::string forceWifiCommissioningBasic = "Force WiFi commissioning (basic)";
std::string forceWiFiCommissioningBasic = "Force WiFi commissioning (basic)";
options.emplace_back(resetWiFi);
options.emplace_back(resetToFactory);
options.emplace_back(forceWifiCommissioningBasic);
options.emplace_back(forceWiFiCommissioningBasic);
}
virtual std::string GetTitle() { return "Setup"; }
virtual int GetItemCount() { return options.size(); }
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ CommissioningParameters PairingCommand::GetCommissioningParameters()
switch (mNetworkType)
{
case PairingNetworkType::WiFi:
return CommissioningParameters().SetWifiCredentials(Controller::WifiCredentials(mSSID, mPassword));
return CommissioningParameters().SetWiFiCredentials(Controller::WiFiCredentials(mSSID, mPassword));
case PairingNetworkType::Thread:
return CommissioningParameters().SetThreadOperationalDataset(mOperationalDataset);
case PairingNetworkType::Ethernet:
Expand Down
4 changes: 2 additions & 2 deletions examples/ipv6only-app/common/wifi_service/wifi_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ message ConnectionResult {
CONNECTION_ERROR error = 1;
}

// The Wifi service provides the common RPC interface for interacting
// The WiFi service provides the common RPC interface for interacting
// with a WIFI capable CHIP device.
// The current state can be retrieved using the various 'Get' RPCs.
// A device can be connected to an AP using the StartScan, and Connect RPCs.
service Wifi {
service WiFi {
rpc GetChannel(pw.protobuf.Empty) returns (Channel) {}
rpc GetSsid(pw.protobuf.Empty) returns (Ssid) {}
rpc GetState(pw.protobuf.Empty) returns (State) {}
Expand Down
6 changes: 3 additions & 3 deletions examples/ipv6only-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ Start the console:

An example flow of performing a scan, connecting, and getting the IPv6 address:

scan = rpcs.chip.rpc.Wifi.StartScan(pw_rpc_timeout_s=5)
scan = rpcs.chip.rpc.WiFi.StartScan(pw_rpc_timeout_s=5)
ap = next(filter(lambda a: b"SSID\000" in a.ssid, next(scan.responses()).aps))

connect = protos.chip.rpc.ConnectionData(ssid=ap.ssid,security_type=ap.security_type,secret=b"PASSWORD")
rpcs.chip.rpc.Wifi.Connect(connect, pw_rpc_timeout_s=10)
rpcs.chip.rpc.WiFi.Connect(connect, pw_rpc_timeout_s=10)

rpcs.chip.rpc.Wifi.GetIP6Address()
rpcs.chip.rpc.WiFi.GetIP6Address()
10 changes: 5 additions & 5 deletions examples/ipv6only-app/esp32/include/wifi_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
namespace chip {
namespace rpc {

class Wifi final : public pw_rpc::nanopb::Wifi::Service<Wifi>
class WiFi final : public pw_rpc::nanopb::WiFi::Service<WiFi>
{
public:
// Singleton
static Wifi & Instance() { return instance_; }
static WiFi & Instance() { return instance_; }

// Initalize the wifi station
pw::Status Init();

// Blocks the calling thread until wifi connection is completed successfully.
// NOTE: Currently only supports blocking a single thread.
void BlockUntilWifiConnected() { xSemaphoreTake(wifi_connected_semaphore_, portMAX_DELAY); }
void BlockUntilWiFiConnected() { xSemaphoreTake(wifi_connected_semaphore_, portMAX_DELAY); }

// The following functions are the RPC handlers

Expand Down Expand Up @@ -125,7 +125,7 @@ class Wifi final : public pw_rpc::nanopb::Wifi::Service<Wifi>
}

private:
static Wifi instance_;
static WiFi instance_;
esp_netif_t * esp_netif_ = nullptr;
SemaphoreHandle_t wifi_connected_semaphore_;

Expand Down Expand Up @@ -156,7 +156,7 @@ class Wifi final : public pw_rpc::nanopb::Wifi::Service<Wifi>
}
}

static void WifiEventHandler(void * arg, esp_event_base_t event_base, int32_t event_id, void * event_data);
static void WiFiEventHandler(void * arg, esp_event_base_t event_base, int32_t event_id, void * event_data);
};

} // namespace rpc
Expand Down
6 changes: 3 additions & 3 deletions examples/ipv6only-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void UdpReceiver(void * pvParameters)
while (1)
{
// Start the udp server after the wifi is connectd.
chip::rpc::Wifi::Instance().BlockUntilWifiConnected();
chip::rpc::WiFi::Instance().BlockUntilWiFiConnected();
ESP_LOGI(TAG, "UDP server starting");

portno = 8765;
Expand Down Expand Up @@ -121,7 +121,7 @@ void UdpReceiver(void * pvParameters)

void RegisterServices(pw::rpc::Server & server)
{
server.RegisterService(chip::rpc::Wifi::Instance());
server.RegisterService(chip::rpc::WiFi::Instance());
}

void RunRpcService(void *)
Expand All @@ -144,7 +144,7 @@ extern "C" void app_main()
}
ESP_ERROR_CHECK(ret);

ESP_LOGI(TAG, "Wifi Init: %s", pw_StatusString(chip::rpc::Wifi::Instance().Init()));
ESP_LOGI(TAG, "WiFi Init: %s", pw_StatusString(chip::rpc::WiFi::Instance().Init()));
ESP_LOGI(TAG, "----------- chip-esp32-ipv6-example starting -----------");

xTaskCreate(RunRpcService, "RPC", kRpcStackSizeBytes / sizeof(StackType_t), nullptr, kRpcTaskPriority, &rpcTaskHandle);
Expand Down
56 changes: 28 additions & 28 deletions examples/ipv6only-app/esp32/main/wifi_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,33 @@ constexpr pw::containers::FlatMap<uint8_t, uint32_t, 73> kChannelToFreqMap({ {
// Creating the object will register all handlers needed, destroying will
// unregister. The object is only needed during initialization, after the station
// is up it is safe to destroy this object.
class WifiInitStationEventHandler
class WiFiInitStationEventHandler
{
public:
WifiInitStationEventHandler()
WiFiInitStationEventHandler()
{
handler_context_.event_group = xEventGroupCreate();
esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &EventHandler, &handler_context_);
}

~WifiInitStationEventHandler()
~WiFiInitStationEventHandler()
{
vEventGroupDelete(handler_context_.event_group);
esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &EventHandler);
}

pw::Status WaitForStationUp()
{
EventBits_t bits = xEventGroupWaitBits(handler_context_.event_group, kWifiStationUpBit, pdFALSE, pdFALSE, portMAX_DELAY);
if (!(bits & kWifiStationUpBit))
EventBits_t bits = xEventGroupWaitBits(handler_context_.event_group, kWiFiStationUpBit, pdFALSE, pdFALSE, portMAX_DELAY);
if (!(bits & kWiFiStationUpBit))
{
return pw::Status::Unknown();
}
return pw::OkStatus();
}

private:
static constexpr uint8_t kWifiStationUpBit = BIT0;
static constexpr uint8_t kWiFiStationUpBit = BIT0;
struct HandlerContext
{
size_t retry_count = 0;
Expand All @@ -84,7 +84,7 @@ class WifiInitStationEventHandler
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START)
{
ESP_LOGI(TAG, "EVENT: WIFI_EVENT_STATION_START");
xEventGroupSetBits(context->event_group, kWifiStationUpBit);
xEventGroupSetBits(context->event_group, kWiFiStationUpBit);
}
}
};
Expand All @@ -93,10 +93,10 @@ class WifiInitStationEventHandler
// Creating the object will register all handlers needed, destroying will
// unregister. The object is only needed during connection, once connected
// is up it is safe to destroy this object.
class WifiConnectionEventHandler
class WiFiConnectionEventHandler
{
public:
WifiConnectionEventHandler(esp_netif_t * esp_netif)
WiFiConnectionEventHandler(esp_netif_t * esp_netif)
{
handler_context_.esp_netif = esp_netif;
handler_context_.event_group = xEventGroupCreate();
Expand All @@ -105,7 +105,7 @@ class WifiConnectionEventHandler
esp_event_handler_register(IP_EVENT, IP_EVENT_GOT_IP6, &EventHandler, &handler_context_);
}

~WifiConnectionEventHandler()
~WiFiConnectionEventHandler()
{
esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &EventHandler);
esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &EventHandler);
Expand All @@ -117,13 +117,13 @@ class WifiConnectionEventHandler
// Waits for the events to determine if connected successfully.
pw::Status WaitForConnection(chip_rpc_ConnectionResult * result)
{
EventBits_t bits = xEventGroupWaitBits(handler_context_.event_group, kWifiFailBit | kWifiIpv6ConnectedBit, pdFALSE, pdFALSE,
EventBits_t bits = xEventGroupWaitBits(handler_context_.event_group, kWiFiFailBit | kWiFiIpv6ConnectedBit, pdFALSE, pdFALSE,
portMAX_DELAY);
if (bits & kWifiIpv6ConnectedBit)
if (bits & kWiFiIpv6ConnectedBit)
{
result->error = chip_rpc_CONNECTION_ERROR_OK;
}
else if (bits & kWifiFailBit)
else if (bits & kWiFiFailBit)
{
result->error = handler_context_.error_code;
return pw::Status::Unavailable();
Expand All @@ -138,9 +138,9 @@ class WifiConnectionEventHandler

private:
static constexpr size_t kWiFiConnectRetryMax = 5;
static constexpr uint8_t kWifiIpv6ConnectedBit = BIT0;
static constexpr uint8_t kWifiIpv4ConnectedBit = BIT1;
static constexpr uint8_t kWifiFailBit = BIT2;
static constexpr uint8_t kWiFiIpv6ConnectedBit = BIT0;
static constexpr uint8_t kWiFiIpv4ConnectedBit = BIT1;
static constexpr uint8_t kWiFiFailBit = BIT2;

struct HandlerContext
{
Expand All @@ -167,7 +167,7 @@ class WifiConnectionEventHandler
{
context->error_code =
static_cast<_chip_rpc_CONNECTION_ERROR>((static_cast<system_event_sta_disconnected_t *>(event_data))->reason);
xEventGroupSetBits(context->event_group, kWifiFailBit);
xEventGroupSetBits(context->event_group, kWiFiFailBit);
}
}
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_CONNECTED)
Expand All @@ -179,13 +179,13 @@ class WifiConnectionEventHandler
{
auto * event = static_cast<ip_event_got_ip_t *>(event_data);
ESP_LOGI(TAG, "got ip4: " IPSTR, IP2STR(&event->ip_info.ip));
xEventGroupSetBits(context->event_group, kWifiIpv4ConnectedBit);
xEventGroupSetBits(context->event_group, kWiFiIpv4ConnectedBit);
}
else if (event_base == IP_EVENT && event_id == IP_EVENT_GOT_IP6)
{
auto * event = static_cast<ip_event_got_ip6_t *>(event_data);
ESP_LOGI(TAG, "got ip6: " IPV6STR, IPV62STR(event->ip6_info.ip));
xEventGroupSetBits(context->event_group, kWifiIpv6ConnectedBit);
xEventGroupSetBits(context->event_group, kWiFiIpv6ConnectedBit);
}
}
};
Expand All @@ -197,17 +197,17 @@ wifi_ap_record_t scan_records[kScanRecordsMax] = { 0 };

} // namespace

Wifi Wifi::instance_;
WiFi WiFi::instance_;

pw::Status Wifi::Init()
pw::Status WiFi::Init()
{
wifi_connected_semaphore_ = xSemaphoreCreateBinary();
PW_TRY(EspToPwStatus(esp_netif_init()));
PW_TRY(EspToPwStatus(esp_event_loop_create_default()));
esp_netif_ = esp_netif_create_default_wifi_sta();
PW_TRY(EspToPwStatus(esp_netif_dhcpc_stop(esp_netif_)));

WifiInitStationEventHandler event_handler;
WiFiInitStationEventHandler event_handler;

wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
PW_TRY(EspToPwStatus(esp_wifi_init(&cfg)));
Expand All @@ -218,7 +218,7 @@ pw::Status Wifi::Init()
return pw::OkStatus();
}

pw::Status Wifi::Connect(const chip_rpc_ConnectionData & request, chip_rpc_ConnectionResult & response)
pw::Status WiFi::Connect(const chip_rpc_ConnectionData & request, chip_rpc_ConnectionResult & response)
{
wifi_config_t wifi_config {
.sta = {
Expand All @@ -240,7 +240,7 @@ pw::Status Wifi::Connect(const chip_rpc_ConnectionData & request, chip_rpc_Conne
memcpy(wifi_config.sta.password, request.secret.bytes,
std::min(sizeof(wifi_config.sta.password), static_cast<size_t>(request.secret.size)));

WifiConnectionEventHandler event_handler(esp_netif_);
WiFiConnectionEventHandler event_handler(esp_netif_);
PW_TRY(EspToPwStatus(esp_wifi_set_config(WIFI_IF_STA, &wifi_config)));
esp_err_t err = esp_wifi_connect();

Expand All @@ -263,7 +263,7 @@ pw::Status Wifi::Connect(const chip_rpc_ConnectionData & request, chip_rpc_Conne
return pw::OkStatus();
}

void Wifi::StartScan(const chip_rpc_ScanConfig & request, ServerWriter<chip_rpc_ScanResults> & writer)
void WiFi::StartScan(const chip_rpc_ScanConfig & request, ServerWriter<chip_rpc_ScanResults> & writer)
{
wifi_scan_config_t scan_config{ 0 };
if (request.ssid_count != 0)
Expand Down Expand Up @@ -321,13 +321,13 @@ void Wifi::StartScan(const chip_rpc_ScanConfig & request, ServerWriter<chip_rpc_
writer.Finish();
}

void Wifi::WifiEventHandler(void * arg, esp_event_base_t event_base, int32_t event_id, void * event_data)
void WiFi::WiFiEventHandler(void * arg, esp_event_base_t event_base, int32_t event_id, void * event_data)
{
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED)
{
ESP_LOGI(TAG, "******** DISCONNECTED FROM AP *********");
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &WifiEventHandler);
esp_event_handler_unregister(IP_EVENT, IP_EVENT_GOT_IP6, &WifiEventHandler);
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &WiFiEventHandler);
esp_event_handler_unregister(IP_EVENT, IP_EVENT_GOT_IP6, &WiFiEventHandler);
}
else if (event_base == IP_EVENT && event_id == IP_EVENT_GOT_IP6)
{
Expand Down
16 changes: 8 additions & 8 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ using chip::Shell::Engine;

#if CHIP_DEVICE_CONFIG_ENABLE_WPA
/*
* The device shall check every kWifiStartCheckTimeUsec whether Wi-Fi management
* has been fully initialized. If after kWifiStartCheckAttempts Wi-Fi management
* The device shall check every kWiFiStartCheckTimeUsec whether Wi-Fi management
* has been fully initialized. If after kWiFiStartCheckAttempts Wi-Fi management
* still hasn't been initialized, the device configuration is reset, and device
* needs to be paired again.
*/
static constexpr useconds_t kWifiStartCheckTimeUsec = 100 * 1000; // 100 ms
static constexpr uint8_t kWifiStartCheckAttempts = 5;
static constexpr useconds_t kWiFiStartCheckTimeUsec = 100 * 1000; // 100 ms
static constexpr uint8_t kWiFiStartCheckAttempts = 5;
#endif

namespace {
Expand All @@ -91,16 +91,16 @@ void EventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg
} // namespace

#if CHIP_DEVICE_CONFIG_ENABLE_WPA
static bool EnsureWifiIsStarted()
static bool EnsureWiFiIsStarted()
{
for (int cnt = 0; cnt < kWifiStartCheckAttempts; cnt++)
for (int cnt = 0; cnt < kWiFiStartCheckAttempts; cnt++)
{
if (chip::DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted())
{
return true;
}

usleep(kWifiStartCheckTimeUsec);
usleep(kWiFiStartCheckTimeUsec);
}

return chip::DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted();
Expand Down Expand Up @@ -153,7 +153,7 @@ int ChipLinuxAppInit(int argc, char ** argv)
if (LinuxDeviceOptions::GetInstance().mWiFi)
{
chip::DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement();
if (!EnsureWifiIsStarted())
if (!EnsureWiFiIsStarted())
{
ChipLogError(NotSpecified, "Wi-Fi Management taking too long to start - device configuration will be reset.");
}
Expand Down
Loading

0 comments on commit b346dc8

Please sign in to comment.