Skip to content

Commit 5ec6ba4

Browse files
[Silabs] Adds feature to update network name in LCD status screen for WiFi combinations (#34410)
* chore: Update network name in LCD status screen * Merge redundent event handler * chore: Update LCD status screen to include network name from DeviceNetworkInfo * Adds auto update of LCD (#322) * Add an optional `withLock` parameter to `UpdateLCDStatusScreen` to control concurrent access to the chip stack. * Added GetScreen API * chore: Update LCD status screen to include network name from DeviceNetworkInfo * Align `PostEvent` * chore: Set LCD screen in BaseApplication::OnPlatformEvent --------- Co-authored-by: Rohan S <3526930+brosahay@users.noreply.github.com> --------- Co-authored-by: Rohan S <3526930+brosahay@users.noreply.github.com>
1 parent f8d8c22 commit 5ec6ba4

7 files changed

+73
-57
lines changed

examples/platform/silabs/BaseApplication.cpp

+42-25
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,6 @@ bool BaseApplication::sIsFactoryResetTriggered = false;
166166
LEDWidget * BaseApplication::sAppActionLed = nullptr;
167167
BaseApplicationDelegate BaseApplication::sAppDelegate = BaseApplicationDelegate();
168168

169-
#ifdef DIC_ENABLE
170-
namespace {
171-
void AppSpecificConnectivityEventCallback(const ChipDeviceEvent * event, intptr_t arg)
172-
{
173-
SILABS_LOG("AppSpecificConnectivityEventCallback: call back for IPV4");
174-
if ((event->Type == DeviceEventType::kInternetConnectivityChange) &&
175-
(event->InternetConnectivityChange.IPv4 == kConnectivity_Established))
176-
{
177-
SILABS_LOG("Got IPv4 Address! Starting DIC module\n");
178-
if (DIC_OK != dic_init(dic::control::subscribeCB))
179-
SILABS_LOG("Failed to initialize DIC module\n");
180-
}
181-
}
182-
} // namespace
183-
#endif // DIC_ENABLE
184-
185169
void BaseApplicationDelegate::OnCommissioningSessionStarted()
186170
{
187171
isComissioningStarted = true;
@@ -203,7 +187,7 @@ void BaseApplicationDelegate::OnCommissioningWindowClosed()
203187
ChipLogError(DeviceLayer, "Failed to enable the TA Deep Sleep");
204188
}
205189
}
206-
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917qq
190+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
207191
}
208192

209193
void BaseApplicationDelegate::OnFabricCommitted(const FabricTable & fabricTable, FabricIndex fabricIndex)
@@ -297,10 +281,6 @@ CHIP_ERROR BaseApplication::Init()
297281
SILABS_LOG("Current Software Version String: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);
298282
SILABS_LOG("Current Software Version: %d", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION);
299283

300-
#ifdef DIC_ENABLE
301-
chip::DeviceLayer::PlatformMgr().AddEventHandler(AppSpecificConnectivityEventCallback, reinterpret_cast<intptr_t>(nullptr));
302-
#endif // DIC_ENABLE
303-
304284
ConfigurationMgr().LogDeviceConfig();
305285

306286
OutputQrCode(true /*refreshLCD at init*/);
@@ -730,14 +710,25 @@ SilabsLCD & BaseApplication::GetLCD(void)
730710
return slLCD;
731711
}
732712

733-
void BaseApplication::UpdateLCDStatusScreen(void)
713+
void BaseApplication::UpdateLCDStatusScreen(bool withChipStackLock)
734714
{
735715
SilabsLCD::DisplayStatus_t status;
736716
bool enabled, attached;
737-
chip::DeviceLayer::PlatformMgr().LockChipStack();
717+
if (withChipStackLock)
718+
{
719+
chip::DeviceLayer::PlatformMgr().LockChipStack();
720+
}
738721
#ifdef SL_WIFI
739722
enabled = ConnectivityMgr().IsWiFiStationEnabled();
740723
attached = ConnectivityMgr().IsWiFiStationConnected();
724+
chip::DeviceLayer::NetworkCommissioning::Network network;
725+
memset(reinterpret_cast<void *>(&network), 0, sizeof(network));
726+
chip::DeviceLayer::NetworkCommissioning::GetConnectedNetwork(network);
727+
if (network.networkIDLen)
728+
{
729+
chip::Platform::CopyString(status.networkName, sizeof(status.networkName),
730+
reinterpret_cast<const char *>(network.networkID));
731+
}
741732
#endif /* SL_WIFI */
742733
#if CHIP_ENABLE_OPENTHREAD
743734
enabled = ConnectivityMgr().IsThreadEnabled();
@@ -751,7 +742,10 @@ void BaseApplication::UpdateLCDStatusScreen(void)
751742
? SilabsLCD::ICDMode_e::SIT
752743
: SilabsLCD::ICDMode_e::LIT;
753744
#endif
754-
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
745+
if (withChipStackLock)
746+
{
747+
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
748+
}
755749
slLCD.SetStatus(status);
756750
}
757751
#endif
@@ -822,10 +816,33 @@ void BaseApplication::DoProvisioningReset()
822816

823817
void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t)
824818
{
825-
if (event->Type == DeviceEventType::kServiceProvisioningChange)
819+
switch (event->Type)
826820
{
821+
case DeviceEventType::kServiceProvisioningChange:
827822
// Note: This is only called on Attach, we need to add a method to detect Thread Network Detach
828823
BaseApplication::sIsProvisioned = event->ServiceProvisioningChange.IsServiceProvisioned;
824+
break;
825+
case DeviceEventType::kInternetConnectivityChange:
826+
#ifdef DIC_ENABLE
827+
VerifyOrReturn(event->InternetConnectivityChange.IPv4 == kConnectivity_Established);
828+
if (DIC_OK != dic_init(dic::control::subscribeCB))
829+
{
830+
SILABS_LOG("Failed to initialize DIC module\n");
831+
}
832+
#endif // DIC_ENABLE
833+
break;
834+
case DeviceEventType::kWiFiConnectivityChange:
835+
#ifdef DISPLAY_ENABLED
836+
SilabsLCD::Screen_e screen;
837+
AppTask::GetLCD().GetScreen(screen);
838+
// Update the LCD screen with SSID and connected state
839+
VerifyOrReturn(screen == SilabsLCD::Screen_e::StatusScreen);
840+
BaseApplication::UpdateLCDStatusScreen(false);
841+
AppTask::GetLCD().SetScreen(screen);
842+
#endif // DISPLAY_ENABLED
843+
break;
844+
default:
845+
break;
829846
}
830847
}
831848

examples/platform/silabs/BaseApplication.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class BaseApplication
132132
*/
133133
static SilabsLCD & GetLCD(void);
134134

135-
static void UpdateLCDStatusScreen(void);
135+
static void UpdateLCDStatusScreen(bool withChipStackLock = true);
136136
#endif
137137

138138
/**

examples/platform/silabs/display/lcd.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ void SilabsLCD::SetCustomUI(customUICB cb)
203203
customUI = cb;
204204
}
205205

206+
void SilabsLCD::GetScreen(Screen_e & screen)
207+
{
208+
screen = static_cast<Screen_e>(mCurrentScreen);
209+
}
210+
206211
void SilabsLCD::SetScreen(Screen_e screen)
207212
{
208213
if (screen >= InvalidScreen)
@@ -226,6 +231,7 @@ void SilabsLCD::SetScreen(Screen_e screen)
226231
default:
227232
break;
228233
}
234+
mCurrentScreen = screen;
229235
}
230236

231237
void SilabsLCD::CycleScreens(void)

examples/platform/silabs/display/lcd.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
#endif // QR_CODE_ENABLED
2727

2828
#include "demo-ui.h"
29-
30-
#define MAX_STR_LEN 48
29+
#include <platform/internal/DeviceNetworkInfo.h>
3130

3231
class SilabsLCD
3332
{
@@ -52,11 +51,11 @@ class SilabsLCD
5251

5352
typedef struct dStatus
5453
{
55-
uint8_t nbFabric = 0;
56-
bool connected = false;
57-
char networkName[50] = { "TODO" };
58-
bool advertising = false;
59-
ICDMode_e icdMode = NotICD;
54+
uint8_t nbFabric = 0;
55+
bool connected = false;
56+
char networkName[chip::DeviceLayer::Internal::kMaxWiFiSSIDLength] = { 0 };
57+
bool advertising = false;
58+
ICDMode_e icdMode = NotICD;
6059
} DisplayStatus_t;
6160

6261
typedef void (*customUICB)(GLIB_Context_t * context);
@@ -68,6 +67,7 @@ class SilabsLCD
6867
void WriteDemoUI(bool state);
6968
void SetCustomUI(customUICB cb);
7069

70+
void GetScreen(Screen_e & screen);
7171
void SetScreen(Screen_e screen);
7272
void CycleScreens(void);
7373
void SetStatus(DisplayStatus_t & status);

src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,8 @@ void ConnectivityManagerImpl::DriveStationState()
357357

358358
void ConnectivityManagerImpl::OnStationConnected()
359359
{
360-
ChipDeviceEvent event;
361360
wfx_setup_ip6_link_local(SL_WFX_STA_INTERFACE);
362-
363361
NetworkCommissioning::SlWiFiDriver::GetInstance().OnConnectWiFiNetwork();
364-
// Alert other components of the new state.
365-
event.Type = DeviceEventType::kWiFiConnectivityChange;
366-
event.WiFiConnectivityChange.Result = kConnectivity_Established;
367-
(void) PlatformMgr().PostEvent(&event);
368362
// Setting the rs911x in the power save mode
369363
#if (CHIP_CONFIG_ENABLE_ICD_SERVER && RS911X_WIFI)
370364
#if SLI_SI917
@@ -378,19 +372,22 @@ void ConnectivityManagerImpl::OnStationConnected()
378372
}
379373
#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER && RS911X_WIFI */
380374
UpdateInternetConnectivityState();
375+
// Alert other components of the new state.
376+
ChipDeviceEvent event;
377+
event.Type = DeviceEventType::kWiFiConnectivityChange;
378+
event.WiFiConnectivityChange.Result = kConnectivity_Established;
379+
(void) PlatformMgr().PostEvent(&event);
381380
}
382381

383382
void ConnectivityManagerImpl::OnStationDisconnected()
384383
{
385384
// TODO: Invoke WARM to perform actions that occur when the WiFi station interface goes down.
386-
385+
UpdateInternetConnectivityState();
387386
// Alert other components of the new state.
388387
ChipDeviceEvent event;
389388
event.Type = DeviceEventType::kWiFiConnectivityChange;
390389
event.WiFiConnectivityChange.Result = kConnectivity_Lost;
391390
(void) PlatformMgr().PostEvent(&event);
392-
393-
UpdateInternetConnectivityState();
394391
}
395392

396393
void ConnectivityManagerImpl::DriveStationState(::chip::System::Layer * aLayer, void * aAppState)
@@ -440,8 +437,6 @@ void ConnectivityManagerImpl::UpdateInternetConnectivityState(void)
440437
event.InternetConnectivityChange.IPv6 = GetConnectivityChange(hadIPv6Conn, haveIPv6Conn);
441438
event.InternetConnectivityChange.ipAddress = addr;
442439

443-
(void) PlatformMgr().PostEvent(&event);
444-
445440
if (haveIPv4Conn != hadIPv4Conn)
446441
{
447442
ChipLogProgress(DeviceLayer, "%s Internet connectivity %s", "IPv4", (haveIPv4Conn) ? "ESTABLISHED" : "LOST");
@@ -451,6 +446,7 @@ void ConnectivityManagerImpl::UpdateInternetConnectivityState(void)
451446
{
452447
ChipLogProgress(DeviceLayer, "%s Internet connectivity %s", "IPv6", (haveIPv6Conn) ? "ESTABLISHED" : "LOST");
453448
}
449+
(void) PlatformMgr().PostEvent(&event);
454450
}
455451
}
456452

src/platform/silabs/NetworkCommissioningWiFiDriver.cpp

+8-13
Original file line numberDiff line numberDiff line change
@@ -325,19 +325,14 @@ void SlWiFiDriver::ScanNetworks(ByteSpan ssid, WiFiDriver::ScanCallback * callba
325325
CHIP_ERROR GetConnectedNetwork(Network & network)
326326
{
327327
wfx_wifi_provision_t wifiConfig;
328-
329-
if (!wfx_is_sta_connected() || !wfx_get_wifi_provision(&wifiConfig))
330-
{
331-
return CHIP_ERROR_INCORRECT_STATE;
332-
}
333-
334-
uint8_t length = strnlen(wifiConfig.ssid, DeviceLayer::Internal::kMaxWiFiSSIDLength);
335-
if (length > sizeof(network.networkID))
336-
{
337-
ChipLogError(DeviceLayer, "SSID too long");
338-
return CHIP_ERROR_INTERNAL;
339-
}
340-
328+
network.networkIDLen = 0;
329+
network.connected = false;
330+
// we are able to fetch the wifi provision data and STA should be connected
331+
VerifyOrReturnError(wfx_get_wifi_provision(&wifiConfig), CHIP_ERROR_UNINITIALIZED);
332+
VerifyOrReturnError(wfx_is_sta_connected(), CHIP_ERROR_NOT_CONNECTED);
333+
network.connected = true;
334+
uint8_t length = strnlen(wifiConfig.ssid, DeviceLayer::Internal::kMaxWiFiSSIDLength);
335+
VerifyOrReturnError(length < sizeof(network.networkID), CHIP_ERROR_BUFFER_TOO_SMALL);
341336
memcpy(network.networkID, wifiConfig.ssid, length);
342337
network.networkIDLen = length;
343338

src/platform/silabs/NetworkCommissioningWiFiDriver.h

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ inline constexpr uint8_t kWiFiScanNetworksTimeOutSeconds = 10;
3030
inline constexpr uint8_t kWiFiConnectNetworkTimeoutSeconds = 20;
3131
} // namespace
3232

33+
CHIP_ERROR GetConnectedNetwork(Network & network);
34+
3335
template <typename T>
3436
class SlScanResponseIterator : public Iterator<T>
3537
{

0 commit comments

Comments
 (0)