mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
add network module, add WIFI hal
This commit is contained in:
parent
cba8f7ec44
commit
012022dea4
@ -26,5 +26,6 @@ PikaObj* PikaStdDevice_Time(PikaObj* self) {
|
||||
obj_setSysOut(self, "Error: please install and import 'time' module");
|
||||
return NULL;
|
||||
}
|
||||
obj_refcntInc(time);
|
||||
return time;
|
||||
}
|
||||
|
@ -279,3 +279,30 @@ int pika_hal_DAC_ioctl_merge_config(pika_hal_DAC_config* dst,
|
||||
_IOCTL_CONFIG_USE_DEFAULT(max, 3300000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_WIFI_ioctl_merge_config(pika_hal_WIFI_config* dst,
|
||||
pika_hal_WIFI_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(mode, PIKA_HAL_WIFI_MODE_STA);
|
||||
if (src->ssid[0] != '\0') {
|
||||
pika_platform_memcpy(dst->ssid, src->ssid, PIKA_HAL_WIFI_PARAM_MAX_LEN);
|
||||
}
|
||||
if (src->password[0] != '\0') {
|
||||
pika_platform_memcpy(dst->password, src->password,
|
||||
PIKA_HAL_WIFI_PARAM_MAX_LEN);
|
||||
}
|
||||
if (src->ip[0] != '\0') {
|
||||
pika_platform_memcpy(dst->ip, src->ip, PIKA_HAL_WIFI_PARAM_MAX_LEN);
|
||||
}
|
||||
if (src->netmask[0] != '\0') {
|
||||
pika_platform_memcpy(dst->netmask, src->netmask,
|
||||
PIKA_HAL_WIFI_PARAM_MAX_LEN);
|
||||
}
|
||||
if (src->gateway[0] != '\0') {
|
||||
pika_platform_memcpy(dst->gateway, src->gateway,
|
||||
PIKA_HAL_WIFI_PARAM_MAX_LEN);
|
||||
}
|
||||
if (src->dns[0] != '\0') {
|
||||
pika_platform_memcpy(dst->dns, src->dns, PIKA_HAL_WIFI_PARAM_MAX_LEN);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -377,6 +377,23 @@ typedef struct {
|
||||
PIKA_HAL_PWM_DUTY duty;
|
||||
} pika_hal_PWM_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_WIFI_MODE_UNUSED = 0,
|
||||
PIKA_HAL_WIFI_MODE_STA,
|
||||
PIKA_HAL_WIFI_MODE_AP,
|
||||
} PIKA_HAL_WIFI_MODE;
|
||||
|
||||
#define PIKA_HAL_WIFI_PARAM_MAX_LEN 32
|
||||
typedef struct pika_hal_WIFI_config {
|
||||
PIKA_HAL_WIFI_MODE mode;
|
||||
char ssid[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char password[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char ip[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char netmask[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char gateway[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char dns[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
} pika_hal_WIFI_config;
|
||||
|
||||
typedef struct pika_dev_impl {
|
||||
int (*open)(pika_dev* dev, char* name);
|
||||
int (*close)(pika_dev* dev);
|
||||
|
@ -10,5 +10,5 @@ pika_hal_table_add(ADC)
|
||||
pika_hal_table_add(DAC)
|
||||
pika_hal_table_add(PWM)
|
||||
pika_hal_table_add(SOFT_SPI)
|
||||
pika_hal_table_add(WIFI)
|
||||
|
||||
/* clang-format on */
|
||||
|
27
package/network/_network.pyi
Normal file
27
package/network/_network.pyi
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
class WLAN:
|
||||
def __init__(self, interface_id:int):...
|
||||
|
||||
def active(self, is_active:int):...
|
||||
|
||||
def checkActive(self) -> int:...
|
||||
|
||||
def connect(self, ssid:str, key:str):...
|
||||
|
||||
def connectWIthBssid(self, ssid:str, key:str, bssid:str):...
|
||||
|
||||
def disconnect(self):...
|
||||
|
||||
def status(self) -> int:...
|
||||
|
||||
def statusWithParam(self, param:str) -> int:...
|
||||
|
||||
def isconnected(self) -> int:...
|
||||
|
||||
def config(self, **kwargs):...
|
||||
|
||||
def checkConfig(self, param:str) -> any:...
|
||||
|
||||
def ifconfig(self, config:tuple):...
|
||||
|
||||
def checkIfconfig(self) -> tuple:...
|
43
package/network/_network_WLAN.c
Normal file
43
package/network/_network_WLAN.c
Normal file
@ -0,0 +1,43 @@
|
||||
#include "_network_WLAN.h"
|
||||
#include "../pikascript-lib/PikaStdDevice/pika_hal.h"
|
||||
|
||||
void _network_WLAN___init__(PikaObj* self, int interface_id) {}
|
||||
|
||||
void _network_WLAN_active(PikaObj* self, int is_active) {}
|
||||
|
||||
int _network_WLAN_checkActive(PikaObj* self) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Arg* _network_WLAN_checkConfig(PikaObj* self, char* param) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void _network_WLAN_config(PikaObj* self, PikaDict* kwargs) {}
|
||||
|
||||
void _network_WLAN_connect(PikaObj* self, char* ssid, char* key) {}
|
||||
|
||||
void _network_WLAN_connectWIthBssid(PikaObj* self,
|
||||
char* ssid,
|
||||
char* key,
|
||||
char* bssid) {}
|
||||
|
||||
void _network_WLAN_disconnect(PikaObj* self) {}
|
||||
|
||||
int _network_WLAN_isconnected(PikaObj* self) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _network_WLAN_status(PikaObj* self) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _network_WLAN_statusWithParam(PikaObj* self, char* param) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
PikaObj* _network_WLAN_checkIfconfig(PikaObj* self) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void _network_WLAN_ifconfig(PikaObj* self, PikaObj* config) {}
|
54
package/network/network.py
Normal file
54
package/network/network.py
Normal file
@ -0,0 +1,54 @@
|
||||
import _network
|
||||
|
||||
STA_IF = 0
|
||||
AP_IF = 1
|
||||
|
||||
STAT_IDLE = 0
|
||||
STAT_CONNECTING = 1
|
||||
STAT_WRONG_PASSWORD = 2
|
||||
STAT_NO_AP_FOUND = 3
|
||||
STAT_CONNECT_FAIL = 4
|
||||
STAT_GOT_IP = 5
|
||||
|
||||
class WLAN(_network.WLAN):
|
||||
def __init__(self, interface_id:int):
|
||||
super().__init__(interface_id)
|
||||
|
||||
def active(self, is_active=None):
|
||||
if is_active is None:
|
||||
return super().checkActive()
|
||||
else:
|
||||
return super().active(is_active)
|
||||
|
||||
def connect(self, ssid=None, key=None, bssid=None):
|
||||
if bssid is None:
|
||||
return super().connect(ssid, key)
|
||||
else:
|
||||
return super().connectWithBssid(ssid, key, bssid)
|
||||
|
||||
def disconnect(self):
|
||||
return super().disconnect()
|
||||
|
||||
def disconnect(self):
|
||||
return super().disconnect()
|
||||
|
||||
def status(self, param=None):
|
||||
if param is None:
|
||||
return super().status()
|
||||
else:
|
||||
return super().statusWithParam(param)
|
||||
|
||||
def isconnected(self) -> int:
|
||||
return super().isconnected()
|
||||
|
||||
def config(self, *para, **kwargs):
|
||||
if len(para) == 1:
|
||||
return super().checkConfig(para[0])
|
||||
else:
|
||||
return super().config(**kwargs)
|
||||
|
||||
def ifconfig(self, config=None):
|
||||
if config is None:
|
||||
return super().checkIfconfig()
|
||||
else:
|
||||
return super().ifconfig(config)
|
3
port/linux/.vscode/settings.json
vendored
3
port/linux/.vscode/settings.json
vendored
@ -105,7 +105,8 @@
|
||||
"pikastddevice_uart.h": "c",
|
||||
"datamemory.h": "c",
|
||||
"pika_adapter_old_api.h": "c",
|
||||
"pikastddevice_common.h": "c"
|
||||
"pikastddevice_common.h": "c",
|
||||
"_network_wlan.h": "c"
|
||||
},
|
||||
"python.formatting.provider": "autopep8",
|
||||
}
|
27
port/linux/package/pikascript/_network.pyi
Normal file
27
port/linux/package/pikascript/_network.pyi
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
class WLAN:
|
||||
def __init__(self, interface_id:int):...
|
||||
|
||||
def active(self, is_active:int):...
|
||||
|
||||
def checkActive(self) -> int:...
|
||||
|
||||
def connect(self, ssid:str, key:str):...
|
||||
|
||||
def connectWIthBssid(self, ssid:str, key:str, bssid:str):...
|
||||
|
||||
def disconnect(self):...
|
||||
|
||||
def status(self) -> int:...
|
||||
|
||||
def statusWithParam(self, param:str) -> int:...
|
||||
|
||||
def isconnected(self) -> int:...
|
||||
|
||||
def config(self, **kwargs):...
|
||||
|
||||
def checkConfig(self, param:str) -> any:...
|
||||
|
||||
def ifconfig(self, config:tuple):...
|
||||
|
||||
def checkIfconfig(self) -> tuple:...
|
@ -3,7 +3,7 @@ import random, re, modbus, socket, unittest, binascii, ctypes, requests, mqtt
|
||||
import pika_lua, pika_cjson, cjson_test, json
|
||||
import GTestTask, TempDevTest
|
||||
import cb_test
|
||||
import configparser
|
||||
import configparser, network
|
||||
import test_module1, test_cmodule, test_module4, import_test
|
||||
import hashlib, hmac, aes, base64, time
|
||||
|
||||
|
54
port/linux/package/pikascript/network.py
Normal file
54
port/linux/package/pikascript/network.py
Normal file
@ -0,0 +1,54 @@
|
||||
import _network
|
||||
|
||||
STA_IF = 0
|
||||
AP_IF = 1
|
||||
|
||||
STAT_IDLE = 0
|
||||
STAT_CONNECTING = 1
|
||||
STAT_WRONG_PASSWORD = 2
|
||||
STAT_NO_AP_FOUND = 3
|
||||
STAT_CONNECT_FAIL = 4
|
||||
STAT_GOT_IP = 5
|
||||
|
||||
class WLAN(_network.WLAN):
|
||||
def __init__(self, interface_id:int):
|
||||
super().__init__(interface_id)
|
||||
|
||||
def active(self, is_active=None):
|
||||
if is_active is None:
|
||||
return super().checkActive()
|
||||
else:
|
||||
return super().active(is_active)
|
||||
|
||||
def connect(self, ssid=None, key=None, bssid=None):
|
||||
if bssid is None:
|
||||
return super().connect(ssid, key)
|
||||
else:
|
||||
return super().connectWithBssid(ssid, key, bssid)
|
||||
|
||||
def disconnect(self):
|
||||
return super().disconnect()
|
||||
|
||||
def disconnect(self):
|
||||
return super().disconnect()
|
||||
|
||||
def status(self, param=None):
|
||||
if param is None:
|
||||
return super().status()
|
||||
else:
|
||||
return super().statusWithParam(param)
|
||||
|
||||
def isconnected(self) -> int:
|
||||
return super().isconnected()
|
||||
|
||||
def config(self, *para, **kwargs):
|
||||
if len(para) == 1:
|
||||
return super().checkConfig(para[0])
|
||||
else:
|
||||
return super().config(**kwargs)
|
||||
|
||||
def ifconfig(self, config=None):
|
||||
if config is None:
|
||||
return super().checkIfconfig()
|
||||
else:
|
||||
return super().ifconfig(config)
|
@ -279,3 +279,30 @@ int pika_hal_DAC_ioctl_merge_config(pika_hal_DAC_config* dst,
|
||||
_IOCTL_CONFIG_USE_DEFAULT(max, 3300000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_WIFI_ioctl_merge_config(pika_hal_WIFI_config* dst,
|
||||
pika_hal_WIFI_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(mode, PIKA_HAL_WIFI_MODE_STA);
|
||||
if (src->ssid[0] != '\0') {
|
||||
pika_platform_memcpy(dst->ssid, src->ssid, PIKA_HAL_WIFI_PARAM_MAX_LEN);
|
||||
}
|
||||
if (src->password[0] != '\0') {
|
||||
pika_platform_memcpy(dst->password, src->password,
|
||||
PIKA_HAL_WIFI_PARAM_MAX_LEN);
|
||||
}
|
||||
if (src->ip[0] != '\0') {
|
||||
pika_platform_memcpy(dst->ip, src->ip, PIKA_HAL_WIFI_PARAM_MAX_LEN);
|
||||
}
|
||||
if (src->netmask[0] != '\0') {
|
||||
pika_platform_memcpy(dst->netmask, src->netmask,
|
||||
PIKA_HAL_WIFI_PARAM_MAX_LEN);
|
||||
}
|
||||
if (src->gateway[0] != '\0') {
|
||||
pika_platform_memcpy(dst->gateway, src->gateway,
|
||||
PIKA_HAL_WIFI_PARAM_MAX_LEN);
|
||||
}
|
||||
if (src->dns[0] != '\0') {
|
||||
pika_platform_memcpy(dst->dns, src->dns, PIKA_HAL_WIFI_PARAM_MAX_LEN);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -377,6 +377,23 @@ typedef struct {
|
||||
PIKA_HAL_PWM_DUTY duty;
|
||||
} pika_hal_PWM_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_WIFI_MODE_UNUSED = 0,
|
||||
PIKA_HAL_WIFI_MODE_STA,
|
||||
PIKA_HAL_WIFI_MODE_AP,
|
||||
} PIKA_HAL_WIFI_MODE;
|
||||
|
||||
#define PIKA_HAL_WIFI_PARAM_MAX_LEN 32
|
||||
typedef struct pika_hal_WIFI_config {
|
||||
PIKA_HAL_WIFI_MODE mode;
|
||||
char ssid[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char password[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char ip[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char netmask[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char gateway[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
char dns[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
} pika_hal_WIFI_config;
|
||||
|
||||
typedef struct pika_dev_impl {
|
||||
int (*open)(pika_dev* dev, char* name);
|
||||
int (*close)(pika_dev* dev);
|
||||
|
@ -10,5 +10,5 @@ pika_hal_table_add(ADC)
|
||||
pika_hal_table_add(DAC)
|
||||
pika_hal_table_add(PWM)
|
||||
pika_hal_table_add(SOFT_SPI)
|
||||
pika_hal_table_add(WIFI)
|
||||
|
||||
/* clang-format on */
|
||||
|
@ -0,0 +1,43 @@
|
||||
#include "_network_WLAN.h"
|
||||
#include "../pikascript-lib/PikaStdDevice/pika_hal.h"
|
||||
|
||||
void _network_WLAN___init__(PikaObj* self, int interface_id) {}
|
||||
|
||||
void _network_WLAN_active(PikaObj* self, int is_active) {}
|
||||
|
||||
int _network_WLAN_checkActive(PikaObj* self) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Arg* _network_WLAN_checkConfig(PikaObj* self, char* param) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void _network_WLAN_config(PikaObj* self, PikaDict* kwargs) {}
|
||||
|
||||
void _network_WLAN_connect(PikaObj* self, char* ssid, char* key) {}
|
||||
|
||||
void _network_WLAN_connectWIthBssid(PikaObj* self,
|
||||
char* ssid,
|
||||
char* key,
|
||||
char* bssid) {}
|
||||
|
||||
void _network_WLAN_disconnect(PikaObj* self) {}
|
||||
|
||||
int _network_WLAN_isconnected(PikaObj* self) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _network_WLAN_status(PikaObj* self) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _network_WLAN_statusWithParam(PikaObj* self, char* param) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
PikaObj* _network_WLAN_checkIfconfig(PikaObj* self) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void _network_WLAN_ifconfig(PikaObj* self, PikaObj* config) {}
|
Loading…
x
Reference in New Issue
Block a user