From 835574e6875400fe1ec713e12d8df6de3915c046 Mon Sep 17 00:00:00 2001 From: lyon Date: Tue, 24 Jan 2023 21:10:06 +0800 Subject: [PATCH] add wifi.state enum --- package/PikaStdDevice/pika_hal.h | 10 +++++ package/network/_network.c | 25 ++++++++++++ package/network/_network.pyi | 40 ++++++++++++------- package/network/network.py | 16 ++++---- port/linux/package/pikascript/_network.pyi | 40 ++++++++++++------- port/linux/package/pikascript/network.py | 16 ++++---- .../pikascript-lib/PikaStdDevice/pika_hal.h | 10 +++++ .../pikascript-lib/network/_network.c | 25 ++++++++++++ 8 files changed, 138 insertions(+), 44 deletions(-) create mode 100644 package/network/_network.c create mode 100644 port/linux/package/pikascript/pikascript-lib/network/_network.c diff --git a/package/PikaStdDevice/pika_hal.h b/package/PikaStdDevice/pika_hal.h index 9fc898ba2..3ce601b55 100644 --- a/package/PikaStdDevice/pika_hal.h +++ b/package/PikaStdDevice/pika_hal.h @@ -383,6 +383,16 @@ typedef enum { PIKA_HAL_WIFI_MODE_AP, } PIKA_HAL_WIFI_MODE; +typedef enum { + _PIKA_HAL_WIFI_STATUS_UNUSED = 0, + PIKA_HAL_WIFI_STATUS_IDLE, + PIKA_HAL_WIFI_STATUS_CONNECTING, + PIKA_HAL_WIFI_STATUS_WRONG_PASSWORD, + PIKA_HAL_WIFI_STATUS_NO_AP_FOUND, + PIKA_HAL_WIFI_STATUS_CONNECT_FAIL, + PIKA_HAL_WIFI_STATUS_GOT_IP, +} PIKA_HAL_WIFI_STATUS; + #define PIKA_HAL_WIFI_PARAM_MAX_LEN 32 typedef struct pika_hal_WIFI_config { PIKA_HAL_WIFI_MODE mode; diff --git a/package/network/_network.c b/package/network/_network.c new file mode 100644 index 000000000..a1ef38302 --- /dev/null +++ b/package/network/_network.c @@ -0,0 +1,25 @@ +#include "_network.h" +#include "../pikascript-lib/PikaStdDevice/pika_hal.h" + +/* +STA_IF: int +AP_IF: int +STAT_IDLE: int +STAT_CONNECTING: int +STAT_WRONG_PASSWORD: int +STAT_NO_AP_FOUND: int +STAT_CONNECT_FAIL: int +STAT_GOT_IP: int +*/ + +void _network___init__(PikaObj* self) { + obj_setInt(self, "STA_IF", PIKA_HAL_WIFI_MODE_STA); + obj_setInt(self, "AP_IF", PIKA_HAL_WIFI_MODE_AP); + obj_setInt(self, "STAT_IDLE", PIKA_HAL_WIFI_STATUS_IDLE); + obj_setInt(self, "STAT_CONNECTING", PIKA_HAL_WIFI_STATUS_CONNECTING); + obj_setInt(self, "STAT_WRONG_PASSWORD", + PIKA_HAL_WIFI_STATUS_WRONG_PASSWORD); + obj_setInt(self, "STAT_NO_AP_FOUND", PIKA_HAL_WIFI_STATUS_NO_AP_FOUND); + obj_setInt(self, "STAT_CONNECT_FAIL", PIKA_HAL_WIFI_STATUS_CONNECT_FAIL); + obj_setInt(self, "STAT_GOT_IP", PIKA_HAL_WIFI_STATUS_GOT_IP); +}; diff --git a/package/network/_network.pyi b/package/network/_network.pyi index e15356942..318755aa3 100644 --- a/package/network/_network.pyi +++ b/package/network/_network.pyi @@ -1,27 +1,39 @@ +STA_IF: int +AP_IF: int +STAT_IDLE: int +STAT_CONNECTING: int +STAT_WRONG_PASSWORD: int +STAT_NO_AP_FOUND: int +STAT_CONNECT_FAIL: int +STAT_GOT_IP: int + class WLAN: - def __init__(self, interface_id:int):... + def __init__(self, interface_id: int): ... - def active(self, is_active:int):... + def active(self, is_active: int): ... - def checkActive(self) -> int:... + def checkActive(self) -> int: ... - def connect(self, ssid:str, key:str):... - - def connectWIthBssid(self, ssid:str, key:str, bssid:str):... + def connect(self, ssid: str, key: str): ... - def disconnect(self):... + def connectWIthBssid(self, ssid: str, key: str, bssid: str): ... - def status(self) -> int:... + def disconnect(self): ... - def statusWithParam(self, param:str) -> int:... + def status(self) -> int: ... - def isconnected(self) -> int:... + def statusWithParam(self, param: str) -> int: ... - def config(self, **kwargs):... + def isconnected(self) -> int: ... - def checkConfig(self, param:str) -> any:... + def config(self, **kwargs): ... - def ifconfig(self, config:tuple):... + def checkConfig(self, param: str) -> any: ... - def checkIfconfig(self) -> tuple:... + def ifconfig(self, config: tuple): ... + + def checkIfconfig(self) -> tuple: ... + + +def __init__(): ... diff --git a/package/network/network.py b/package/network/network.py index 6f9cd7f08..250e5da3d 100644 --- a/package/network/network.py +++ b/package/network/network.py @@ -1,14 +1,14 @@ import _network -STA_IF = 0 -AP_IF = 1 +STA_IF = _network.STA_IF +AP_IF = _network.AP_IF -STAT_IDLE = 0 -STAT_CONNECTING = 1 -STAT_WRONG_PASSWORD = 2 -STAT_NO_AP_FOUND = 3 -STAT_CONNECT_FAIL = 4 -STAT_GOT_IP = 5 +STAT_IDLE = _network.STAT_IDLE +STAT_CONNECTING = _network.STAT_CONNECTING +STAT_WRONG_PASSWORD = _network.STAT_WRONG_PASSWORD +STAT_NO_AP_FOUND = _network.STAT_NO_AP_FOUND +STAT_CONNECT_FAIL = _network.STAT_CONNECT_FAIL +STAT_GOT_IP = _network.STAT_GOT_IP class WLAN(_network.WLAN): def __init__(self, interface_id:int): diff --git a/port/linux/package/pikascript/_network.pyi b/port/linux/package/pikascript/_network.pyi index e15356942..318755aa3 100644 --- a/port/linux/package/pikascript/_network.pyi +++ b/port/linux/package/pikascript/_network.pyi @@ -1,27 +1,39 @@ +STA_IF: int +AP_IF: int +STAT_IDLE: int +STAT_CONNECTING: int +STAT_WRONG_PASSWORD: int +STAT_NO_AP_FOUND: int +STAT_CONNECT_FAIL: int +STAT_GOT_IP: int + class WLAN: - def __init__(self, interface_id:int):... + def __init__(self, interface_id: int): ... - def active(self, is_active:int):... + def active(self, is_active: int): ... - def checkActive(self) -> int:... + def checkActive(self) -> int: ... - def connect(self, ssid:str, key:str):... - - def connectWIthBssid(self, ssid:str, key:str, bssid:str):... + def connect(self, ssid: str, key: str): ... - def disconnect(self):... + def connectWIthBssid(self, ssid: str, key: str, bssid: str): ... - def status(self) -> int:... + def disconnect(self): ... - def statusWithParam(self, param:str) -> int:... + def status(self) -> int: ... - def isconnected(self) -> int:... + def statusWithParam(self, param: str) -> int: ... - def config(self, **kwargs):... + def isconnected(self) -> int: ... - def checkConfig(self, param:str) -> any:... + def config(self, **kwargs): ... - def ifconfig(self, config:tuple):... + def checkConfig(self, param: str) -> any: ... - def checkIfconfig(self) -> tuple:... + def ifconfig(self, config: tuple): ... + + def checkIfconfig(self) -> tuple: ... + + +def __init__(): ... diff --git a/port/linux/package/pikascript/network.py b/port/linux/package/pikascript/network.py index 6f9cd7f08..250e5da3d 100644 --- a/port/linux/package/pikascript/network.py +++ b/port/linux/package/pikascript/network.py @@ -1,14 +1,14 @@ import _network -STA_IF = 0 -AP_IF = 1 +STA_IF = _network.STA_IF +AP_IF = _network.AP_IF -STAT_IDLE = 0 -STAT_CONNECTING = 1 -STAT_WRONG_PASSWORD = 2 -STAT_NO_AP_FOUND = 3 -STAT_CONNECT_FAIL = 4 -STAT_GOT_IP = 5 +STAT_IDLE = _network.STAT_IDLE +STAT_CONNECTING = _network.STAT_CONNECTING +STAT_WRONG_PASSWORD = _network.STAT_WRONG_PASSWORD +STAT_NO_AP_FOUND = _network.STAT_NO_AP_FOUND +STAT_CONNECT_FAIL = _network.STAT_CONNECT_FAIL +STAT_GOT_IP = _network.STAT_GOT_IP class WLAN(_network.WLAN): def __init__(self, interface_id:int): diff --git a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.h b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.h index 9fc898ba2..3ce601b55 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.h +++ b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.h @@ -383,6 +383,16 @@ typedef enum { PIKA_HAL_WIFI_MODE_AP, } PIKA_HAL_WIFI_MODE; +typedef enum { + _PIKA_HAL_WIFI_STATUS_UNUSED = 0, + PIKA_HAL_WIFI_STATUS_IDLE, + PIKA_HAL_WIFI_STATUS_CONNECTING, + PIKA_HAL_WIFI_STATUS_WRONG_PASSWORD, + PIKA_HAL_WIFI_STATUS_NO_AP_FOUND, + PIKA_HAL_WIFI_STATUS_CONNECT_FAIL, + PIKA_HAL_WIFI_STATUS_GOT_IP, +} PIKA_HAL_WIFI_STATUS; + #define PIKA_HAL_WIFI_PARAM_MAX_LEN 32 typedef struct pika_hal_WIFI_config { PIKA_HAL_WIFI_MODE mode; diff --git a/port/linux/package/pikascript/pikascript-lib/network/_network.c b/port/linux/package/pikascript/pikascript-lib/network/_network.c new file mode 100644 index 000000000..a1ef38302 --- /dev/null +++ b/port/linux/package/pikascript/pikascript-lib/network/_network.c @@ -0,0 +1,25 @@ +#include "_network.h" +#include "../pikascript-lib/PikaStdDevice/pika_hal.h" + +/* +STA_IF: int +AP_IF: int +STAT_IDLE: int +STAT_CONNECTING: int +STAT_WRONG_PASSWORD: int +STAT_NO_AP_FOUND: int +STAT_CONNECT_FAIL: int +STAT_GOT_IP: int +*/ + +void _network___init__(PikaObj* self) { + obj_setInt(self, "STA_IF", PIKA_HAL_WIFI_MODE_STA); + obj_setInt(self, "AP_IF", PIKA_HAL_WIFI_MODE_AP); + obj_setInt(self, "STAT_IDLE", PIKA_HAL_WIFI_STATUS_IDLE); + obj_setInt(self, "STAT_CONNECTING", PIKA_HAL_WIFI_STATUS_CONNECTING); + obj_setInt(self, "STAT_WRONG_PASSWORD", + PIKA_HAL_WIFI_STATUS_WRONG_PASSWORD); + obj_setInt(self, "STAT_NO_AP_FOUND", PIKA_HAL_WIFI_STATUS_NO_AP_FOUND); + obj_setInt(self, "STAT_CONNECT_FAIL", PIKA_HAL_WIFI_STATUS_CONNECT_FAIL); + obj_setInt(self, "STAT_GOT_IP", PIKA_HAL_WIFI_STATUS_GOT_IP); +};