Skip to content

Commit

Permalink
[ASR] Fix -Wundef compile issue (#29644)
Browse files Browse the repository at this point in the history
* [ASR] Fix -Wundef compile issue

* update wifi scan implementation

---------

Co-authored-by: weicheng <weichengxu@asrmicro.com>
  • Loading branch information
2 people authored and pull[bot] committed Jan 5, 2024
1 parent 338db13 commit 228600d
Show file tree
Hide file tree
Showing 29 changed files with 104 additions and 87 deletions.
2 changes: 1 addition & 1 deletion examples/all-clusters-app/asr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ asr_executable("clusters_app") {
defines = [ "ASR_NETWORK_LAYER_BLE=${chip_config_network_layer_ble}" ]

if (chip_build_libshell) {
defines += [ "CONFIG_ENABLE_CHIP_SHELL=1" ]
defines += [ "CONFIG_ENABLE_CHIP_SHELL" ]
sources += [ "${examples_plat_dir}/shell/launch_shell.cpp" ]
include_dirs += [ "${examples_plat_dir}/shell" ]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/all-clusters-minimal-app/asr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ asr_executable("clusters_minimal_app") {
defines = [ "ASR_NETWORK_LAYER_BLE=${chip_config_network_layer_ble}" ]

if (chip_build_libshell) {
defines += [ "CONFIG_ENABLE_CHIP_SHELL=1" ]
defines += [ "CONFIG_ENABLE_CHIP_SHELL" ]
sources += [ "${examples_plat_dir}/shell/launch_shell.cpp" ]
include_dirs += [ "${examples_plat_dir}/shell" ]
}
Expand Down
4 changes: 2 additions & 2 deletions examples/bridge-app/asr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ asr_sdk_sources("bridge_app_sdk_sources") {
"ASR_LOG_ENABLED=1",
"CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}",
"CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${setupDiscriminator}",
"ENABLE_ASR_BRIDGE_SUBDEVICE_TEST=1",
"ENABLE_ASR_BRIDGE_SUBDEVICE_TEST",
]

if (chip_enable_factory_data) {
Expand Down Expand Up @@ -109,7 +109,7 @@ asr_executable("bridge_app") {
defines = [ "ASR_NETWORK_LAYER_BLE=${chip_config_network_layer_ble}" ]

if (chip_build_libshell) {
defines += [ "CONFIG_ENABLE_CHIP_SHELL=1" ]
defines += [ "CONFIG_ENABLE_CHIP_SHELL" ]
sources += [ "${examples_plat_dir}/shell/launch_shell.cpp" ]
include_dirs += [ "${examples_plat_dir}/shell" ]
}
Expand Down
6 changes: 3 additions & 3 deletions examples/bridge-app/asr/subdevice/SubDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
extern "C" {
#endif
#include <stdio.h>
#if CONFIG_ENABLE_ASR_APP_MESH
#ifdef CONFIG_ENABLE_ASR_APP_MESH
#include "app.h"
#include "sonata_gap_api.h"
#include "sonata_gatt_api.h"
Expand Down Expand Up @@ -65,7 +65,7 @@ void SubDevice::SetOnOff(bool aOn)
changed = (mState != kState_On);
mState = kState_On;
ChipLogProgress(DeviceLayer, "SubDevice[%s]: ON", mName);
#if CONFIG_ENABLE_ASR_APP_MESH
#ifdef CONFIG_ENABLE_ASR_APP_MESH
if (strcmp(mName, "Light 1") == 0)
{
app_mesh_control_fan(1);
Expand All @@ -81,7 +81,7 @@ void SubDevice::SetOnOff(bool aOn)
changed = (mState != kState_Off);
mState = kState_Off;
ChipLogProgress(DeviceLayer, "SubDevice[%s]: OFF", mName);
#if CONFIG_ENABLE_ASR_APP_MESH
#ifdef CONFIG_ENABLE_ASR_APP_MESH
if (strcmp(mName, "Light 1") == 0)
{
app_mesh_control_fan(0);
Expand Down
2 changes: 1 addition & 1 deletion examples/bridge-app/asr/subdevice/subdevice_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ using namespace ::chip::System;
using namespace ::chip::Platform;
using namespace ::chip::app::Clusters;

#if ENABLE_ASR_BRIDGE_SUBDEVICE_TEST
#ifdef ENABLE_ASR_BRIDGE_SUBDEVICE_TEST

static const int kNodeLabelSize = 32;
// Current ZCL implementation of Struct uses a max-size array of 254 bytes
Expand Down
2 changes: 1 addition & 1 deletion examples/dishwasher-app/asr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ asr_executable("dishwasher_app") {
defines = [ "ASR_NETWORK_LAYER_BLE=${chip_config_network_layer_ble}" ]

if (chip_build_libshell) {
defines += [ "CONFIG_ENABLE_CHIP_SHELL=1" ]
defines += [ "CONFIG_ENABLE_CHIP_SHELL" ]
sources += [ "${examples_plat_dir}/shell/launch_shell.cpp" ]
include_dirs += [ "${examples_plat_dir}/shell" ]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/dishwasher-app/asr/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <platform/ASR/NetworkCommissioningDriver.h>

#include "init_Matter.h"
#if CONFIG_ENABLE_CHIP_SHELL
#ifdef CONFIG_ENABLE_CHIP_SHELL
#include "matter_shell.h"
#endif
#include <app-common/zap-generated/attributes/Accessors.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/light-switch-app/asr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ asr_executable("light_switch_app") {
defines = [ "ASR_NETWORK_LAYER_BLE=${chip_config_network_layer_ble}" ]

if (chip_build_libshell) {
defines += [ "CONFIG_ENABLE_CHIP_SHELL=1" ]
defines += [ "CONFIG_ENABLE_CHIP_SHELL" ]
sources += [ "${examples_plat_dir}/shell/launch_shell.cpp" ]
include_dirs += [ "${examples_plat_dir}/shell" ]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/asr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ asr_executable("lighting_app") {
defines = [ "ASR_NETWORK_LAYER_BLE=${chip_config_network_layer_ble}" ]

if (chip_build_libshell) {
defines += [ "CONFIG_ENABLE_CHIP_SHELL=1" ]
defines += [ "CONFIG_ENABLE_CHIP_SHELL" ]
sources += [ "${examples_plat_dir}/shell/launch_shell.cpp" ]
include_dirs += [ "${examples_plat_dir}/shell" ]
}
Expand Down
4 changes: 2 additions & 2 deletions examples/lighting-app/asr/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <platform/ASR/NetworkCommissioningDriver.h>

#include "init_Matter.h"
#if CONFIG_ENABLE_CHIP_SHELL
#ifdef CONFIG_ENABLE_CHIP_SHELL
#include "matter_shell.h"
#endif
#include <app-common/zap-generated/attributes/Accessors.h>
Expand Down Expand Up @@ -164,7 +164,7 @@ void AppTask::AppTaskMain(void * pvParameter)

/* get led onoff status and level value */
led_startup_status();
#if CONFIG_ENABLE_CHIP_SHELL
#ifdef CONFIG_ENABLE_CHIP_SHELL
RegisterLightCommands();
#endif
/* Delete task */
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/asr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ asr_executable("lock_app") {
defines = [ "ASR_NETWORK_LAYER_BLE=${chip_config_network_layer_ble}" ]

if (chip_build_libshell) {
defines += [ "CONFIG_ENABLE_CHIP_SHELL=1" ]
defines += [ "CONFIG_ENABLE_CHIP_SHELL" ]
sources += [ "${examples_plat_dir}/shell/launch_shell.cpp" ]
include_dirs += [ "${examples_plat_dir}/shell" ]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/ota-requestor-app/asr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ asr_executable("ota_requestor_app") {
defines = [ "ASR_NETWORK_LAYER_BLE=${chip_config_network_layer_ble}" ]

if (chip_build_libshell) {
defines += [ "CONFIG_ENABLE_CHIP_SHELL=1" ]
defines += [ "CONFIG_ENABLE_CHIP_SHELL" ]
sources += [ "${examples_plat_dir}/shell/launch_shell.cpp" ]
include_dirs += [ "${examples_plat_dir}/shell" ]
}
Expand Down
4 changes: 2 additions & 2 deletions examples/platform/asr/init_Matter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <init_Matter.h>
#include <mbedtls/platform.h>
#if CONFIG_ENABLE_CHIP_SHELL
#ifdef CONFIG_ENABLE_CHIP_SHELL
#include <shell/launch_shell.h>
#endif
#include <platform/ASR/ASRFactoryDataProvider.h>
Expand Down Expand Up @@ -113,7 +113,7 @@ CHIP_ERROR MatterInitializer::Init_Matter_Server(void)
err = PlatformMgr().StartEventLoopTask();
ReturnErrorOnFailure(err);

#if CONFIG_ENABLE_CHIP_SHELL
#ifdef CONFIG_ENABLE_CHIP_SHELL
chip::LaunchShell();
#endif

Expand Down
2 changes: 1 addition & 1 deletion examples/platform/asr/init_asrPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void init_asrPlatform(void)
lega_recovery_phy_fsm_config();
#endif
asr_security_engine_init();
#if !CONFIG_ENABLE_CHIP_SHELL
#ifndef CONFIG_ENABLE_CHIP_SHELL
lega_at_init();
#endif
lega_at_cmd_register_all();
Expand Down
6 changes: 3 additions & 3 deletions examples/platform/asr/shell/matter_shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;

#if CONFIG_ENABLE_CHIP_SHELL
#ifdef CONFIG_ENABLE_CHIP_SHELL
#include "lib/shell/Engine.h"

using chip::Shell::Engine;
Expand Down Expand Up @@ -94,7 +94,7 @@ void asr_matter_onoff(int value)

void asr_matter_sensors(bool enable, int temp, int humi, int pressure)
{
#if ASR_BOARD_ENABLE_SENSORS
#ifdef ASR_BOARD_ENABLE_SENSORS
if (enable)
{
chip::app::Clusters::TemperatureMeasurement::Attributes::MeasuredValue::Set(
Expand All @@ -120,7 +120,7 @@ void asr_matter_ota(uint32_t timeout)
#endif
}

#if CONFIG_ENABLE_CHIP_SHELL
#ifdef CONFIG_ENABLE_CHIP_SHELL
static CHIP_ERROR sLightCommandHandler(int argc, char ** argv)
{
if (argc == 1 && strcmp(argv[0], "on") == 0)
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/asr/shell/matter_shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void asr_matter_reset(Reset_t type);
void asr_matter_onoff(int value);
void asr_matter_sensors(bool enable, int temp, int humi, int pressure);
void asr_matter_ota(uint32_t timeout);
#if CONFIG_ENABLE_CHIP_SHELL
#ifdef CONFIG_ENABLE_CHIP_SHELL
void RegisterLightCommands();
#endif
#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion examples/refrigerator-app/asr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ asr_executable("refrigerator_app") {
defines = [ "ASR_NETWORK_LAYER_BLE=${chip_config_network_layer_ble}" ]

if (chip_build_libshell) {
defines += [ "CONFIG_ENABLE_CHIP_SHELL=1" ]
defines += [ "CONFIG_ENABLE_CHIP_SHELL" ]
sources += [ "${examples_plat_dir}/shell/launch_shell.cpp" ]
include_dirs += [ "${examples_plat_dir}/shell" ]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/refrigerator-app/asr/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <platform/ASR/NetworkCommissioningDriver.h>

#include "init_Matter.h"
#if CONFIG_ENABLE_CHIP_SHELL
#ifdef CONFIG_ENABLE_CHIP_SHELL
#include "matter_shell.h"
#endif
#include <app-common/zap-generated/attributes/Accessors.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/temperature-measurement-app/asr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ asr_executable("temperature_measurement_app") {
defines = [ "ASR_NETWORK_LAYER_BLE=${chip_config_network_layer_ble}" ]

if (chip_build_libshell) {
defines += [ "CONFIG_ENABLE_CHIP_SHELL=1" ]
defines += [ "CONFIG_ENABLE_CHIP_SHELL" ]
sources += [ "${examples_plat_dir}/shell/launch_shell.cpp" ]
include_dirs += [ "${examples_plat_dir}/shell" ]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/thermostat/asr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ asr_executable("thermostat") {
defines = [ "ASR_NETWORK_LAYER_BLE=${chip_config_network_layer_ble}" ]

if (chip_build_libshell) {
defines += [ "CONFIG_ENABLE_CHIP_SHELL=1" ]
defines += [ "CONFIG_ENABLE_CHIP_SHELL" ]
sources += [ "${examples_plat_dir}/shell/launch_shell.cpp" ]
include_dirs += [ "${examples_plat_dir}/shell" ]
}
Expand Down
52 changes: 52 additions & 0 deletions src/platform/ASR/ASRUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ using namespace ::chip::DeviceLayer::Internal;
using chip::DeviceLayer::Internal::DeviceNetworkInfo;

namespace {
constexpr uint8_t kWiFiMaxNetworks = 15;
uint8_t NumAP = 0;
lega_wlan_wifi_conf wifi_conf;
lega_wlan_scan_ap_record_t scan_result[kWiFiMaxNetworks];
} // namespace
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP
CHIP_ERROR ASRUtils::IsAPEnabled(bool & apEnabled)
Expand Down Expand Up @@ -300,3 +303,52 @@ CHIP_ERROR ASRUtils::asr_wifi_connect(void)

return err;
}

void ASRUtils::lega_wifi_scan_ind(lega_wlan_scan_result_t * result)
{
NumAP = 0;
for (int i = 0; i < result->ap_num; i++)
{
if (i < kWiFiMaxNetworks)
{
memcpy(&scan_result[i], &result->ap_list[i], sizeof(lega_wlan_scan_ap_record_t));
NumAP++;
}
}
NetworkCommissioning::ASRWiFiDriver::GetInstance().OnScanWiFiNetworkDone();
}

CHIP_ERROR ASRUtils::StartScanWiFiNetworks(ByteSpan ssid)
{
if (Internal::ASRUtils::EnableStationMode() != CHIP_NO_ERROR)
{
ChipLogProgress(DeviceLayer, "Start Scan WiFi Networks Failed");
return CHIP_ERROR_INTERNAL;
}

NumAP = 0;
memset(scan_result, 0, sizeof(scan_result));
lega_wlan_scan_compeleted_cb_register(Internal::ASRUtils::lega_wifi_scan_ind);

if (!ssid.empty()) // ssid is given, only scan this network
{
char cSsid[DeviceLayer::Internal::kMaxWiFiSSIDLength] = {};
memcpy(cSsid, ssid.data(), ssid.size());
lega_wlan_start_scan_active(cSsid, 0);
}
else // scan all networks
{
lega_wlan_start_scan();
}
return CHIP_NO_ERROR;
}

lega_wlan_scan_ap_record_t * ASRUtils::GetScanResults(void)
{
return scan_result;
}

uint8_t ASRUtils::GetScanApNum(void)
{
return NumAP;
}
17 changes: 5 additions & 12 deletions src/platform/ASR/ASRUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@ extern "C" {
}
#endif

typedef struct
{
char wifi_mode; /* refer to hal_wifi_type_t*/
char security; /* security mode, refer to lega_wlan_security_e */
char wifi_ssid[32]; /* in station mode, indicate SSID of the wlan needs to be connected.
in softap mode, indicate softap SSID*/
char wifi_key[64]; /* in station mode, indicate Security key of the wlan needs to be connected,
in softap mode, indicate softap password.(ignored in an open system.) */
uint32_t ssid_len;
uint32_t key_len;
} lega_wlan_wifi_conf;

namespace chip {
namespace DeviceLayer {
namespace Internal {
Expand Down Expand Up @@ -77,6 +65,11 @@ class ASRUtils
static CHIP_ERROR StoreWiFiSecurityCode(uint32_t security);
static CHIP_ERROR wifi_get_mode(uint32_t & security);
static CHIP_ERROR wifi_set_mode(uint32_t security);

static void lega_wifi_scan_ind(lega_wlan_scan_result_t * result);
static CHIP_ERROR StartScanWiFiNetworks(ByteSpan ssid);
static lega_wlan_scan_ap_record_t * GetScanResults(void);
static uint8_t GetScanApNum(void);
};

} // namespace Internal
Expand Down
6 changes: 0 additions & 6 deletions src/platform/ASR/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,6 @@ void ConnectivityManagerImpl::lega_wifi_connect_state(lega_wifi_event_e stat)
}
}

void ConnectivityManagerImpl::lega_wifi_scan_ind(lega_wlan_scan_result_t * result)
{
NetworkCommissioning::ASRWiFiDriver::GetInstance().OnScanWiFiNetworkDone(result);
}

void ConnectivityManagerImpl::lega_wifi_get_ip_ind(lega_wlan_ip_stat_t * pnet)
{
ChipLogProgress(DeviceLayer, "Got ip : %s, gw : %s, mask : %s, mac : %s", pnet->ip, pnet->gate, pnet->mask, pnet->macaddr);
Expand Down Expand Up @@ -627,7 +622,6 @@ void ConnectivityManagerImpl::lega_wlan_err_stat_handler(lega_wlan_err_status_e

CHIP_ERROR ConnectivityManagerImpl::WiFi_init(void)
{
lega_wlan_scan_compeleted_cb_register(ConnectivityManagerImpl::lega_wifi_scan_ind);
lega_wlan_stat_chg_cb_register(ConnectivityManagerImpl::lega_wifi_connect_state);
lega_wlan_ip_got_cb_register(ConnectivityManagerImpl::lega_wifi_get_ip_ind);
lega_wlan_ip6_got_cb_register(ConnectivityManagerImpl::lega_wifi_get_ip6_ind);
Expand Down
1 change: 0 additions & 1 deletion src/platform/ASR/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
CHIP_ERROR ConfigureWiFiAP(void);
void ChangeWiFiAPState(WiFiAPState newState);
void UpdateInternetConnectivityState(void);
static void lega_wifi_scan_ind(lega_wlan_scan_result_t * result);
static void lega_wifi_connect_state(lega_wifi_event_e stat);
static void lega_wifi_get_ip_ind(lega_wlan_ip_stat_t * pnet);
static void lega_wifi_get_ip6_ind(lega_wlan_ip_stat_t * pnet);
Expand Down
Loading

0 comments on commit 228600d

Please sign in to comment.