mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
Merge branch 'master' of https://gitee.com/lyon1998/pikascript
This commit is contained in:
commit
814e01aa30
@ -336,6 +336,12 @@ int pika_hal_WIFI_ioctl_merge_config(pika_hal_WIFI_config* dst,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_LAN_ioctl_merge_config(pika_hal_LAN_config* dst,
|
||||
pika_hal_LAN_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(user_data, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_SG_ioctl_merge_config(pika_hal_SG_config* dst,
|
||||
pika_hal_SG_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(waveform, PIKA_HAL_SG_WAVEFORM_SINE);
|
||||
|
@ -32,17 +32,27 @@ typedef enum {
|
||||
PIKA_HAL_IOCTL_CONFIG,
|
||||
PIKA_HAL_IOCTL_ENABLE,
|
||||
PIKA_HAL_IOCTL_DISABLE,
|
||||
PIKA_HAL_IOCTL_WIFI_GET_ACTIVE,
|
||||
PIKA_HAL_IOCTL_WIFI_GET_STATUS,
|
||||
PIKA_HAL_IOCTL_NET_GET_ACTIVE,
|
||||
PIKA_HAL_IOCTL_NET_GET_STATUS,
|
||||
PIKA_HAL_IOCTL_WIFI_SCAN,
|
||||
PIKA_HAL_IOCTL_WIFI_CONNECT,
|
||||
PIKA_HAL_IOCTL_WIFI_DISCONNECT,
|
||||
PIKA_HAL_IOCTL_WIFI_SET_IFCONFIG,
|
||||
PIKA_HAL_IOCTL_WIFI_GET_IFCONFIG,
|
||||
PIKA_HAL_IOCTL_NET_SET_IFCONFIG,
|
||||
PIKA_HAL_IOCTL_NET_GET_IFCONFIG,
|
||||
PIKA_HAL_IOCTL_CAM_CAPTURE,
|
||||
_ = 0xFFFFFFFF, // make sure it is 4 byte width
|
||||
} PIKA_HAL_IOCTL_CMD;
|
||||
|
||||
#define PIKA_HAL_IOCTL_WIFI_GET_ACTIVE PIKA_HAL_IOCTL_NET_GET_ACTIVE
|
||||
#define PIKA_HAL_IOCTL_WIFI_GET_STATUS PIKA_HAL_IOCTL_NET_GET_STATUS
|
||||
#define PIKA_HAL_IOCTL_WIFI_SET_IFCONFIG PIKA_HAL_IOCTL_NET_SET_IFCONFIG
|
||||
#define PIKA_HAL_IOCTL_WIFI_GET_IFCONFIG PIKA_HAL_IOCTL_NET_GET_IFCONFIG
|
||||
|
||||
#define PIKA_HAL_IOCTL_LAN_GET_ACTIVE PIKA_HAL_IOCTL_NET_GET_ACTIVE
|
||||
#define PIKA_HAL_IOCTL_LAN_GET_STATUS PIKA_HAL_IOCTL_NET_GET_STATUS
|
||||
#define PIKA_HAL_IOCTL_LAN_SET_IFCONFIG PIKA_HAL_IOCTL_NET_SET_IFCONFIG
|
||||
#define PIKA_HAL_IOCTL_LAN_GET_IFCONFIG PIKA_HAL_IOCTL_NET_GET_IFCONFIG
|
||||
|
||||
/* posix file like API */
|
||||
pika_dev* pika_hal_open(PIKA_HAL_DEV_TYPE dev_type, char* name);
|
||||
int pika_hal_close(pika_dev* dev);
|
||||
@ -432,6 +442,13 @@ typedef enum {
|
||||
PIKA_HAL_WIFI_STATUS_GOT_IP,
|
||||
} PIKA_HAL_WIFI_STATUS;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_LAN_STATUS_UNUSED = 0,
|
||||
PIKA_HAL_LAN_STATUS_IDLE,
|
||||
PIKA_HAL_LAN_STATUS_CONNECTING,
|
||||
PIKA_HAL_LAN_STATUS_GOT_IP,
|
||||
} PIKA_HAL_LAN_STATUS;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_WIFI_CHANNEL_UNUSED = 0,
|
||||
PIKA_HAL_WIFI_CHANNEL_0,
|
||||
@ -479,12 +496,15 @@ typedef struct pika_hal_WIFI_connect_config {
|
||||
char password[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
} pika_hal_WIFI_connect_config;
|
||||
|
||||
typedef struct pika_hal_WIFI_ifconfig {
|
||||
typedef struct pika_hal_NET_ifconfig {
|
||||
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_ifconfig;
|
||||
} pika_hal_NET_ifconfig;
|
||||
|
||||
#define pika_hal_WIFI_ifconfig pika_hal_NET_ifconfig
|
||||
#define pika_hal_LAN_ifconfig pika_hal_NET_ifconfig
|
||||
|
||||
typedef struct pika_hal_WIFI_record {
|
||||
char ssid[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
@ -500,6 +520,10 @@ typedef struct pika_hal_WIFI_scan_result {
|
||||
pika_hal_WIFI_record records[];
|
||||
} pika_hal_WIFI_scan_result;
|
||||
|
||||
typedef struct pika_hal_LAN_config {
|
||||
void* user_data;
|
||||
} pika_hal_LAN_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_PWM_PERIOD_UNUSED = 0,
|
||||
PIKA_HAL_TIM_PERIOD_1NS = 1,
|
||||
|
@ -12,6 +12,7 @@ pika_hal_table_add(PWM)
|
||||
pika_hal_table_add(SOFT_SPI)
|
||||
pika_hal_table_add(SOFT_IIC)
|
||||
pika_hal_table_add(WIFI)
|
||||
pika_hal_table_add(LAN)
|
||||
pika_hal_table_add(TIM)
|
||||
pika_hal_table_add(SOFT_TIM)
|
||||
pika_hal_table_add(CAM)
|
||||
|
@ -378,7 +378,8 @@ class ModBusRTU(ModBus):
|
||||
|
||||
def setUart(self, uart: PikaStdDevice.UART):
|
||||
self._uart = uart
|
||||
uart.setCallBack(self.recvCallback, uart.SIGNAL_RX)
|
||||
debug('set uart', uart)
|
||||
uart.setCallback(self.recvCallback, uart.SIGNAL_RX)
|
||||
|
||||
def recv(self, count: int = 10):
|
||||
"""
|
||||
|
@ -7,37 +7,44 @@ STAT_NO_AP_FOUND: int
|
||||
STAT_CONNECT_FAIL: int
|
||||
STAT_GOT_IP: int
|
||||
|
||||
|
||||
class WLAN:
|
||||
class NET:
|
||||
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 ifconfig(self, ip: str, mask: str, gateway: str, dns: str): ...
|
||||
|
||||
def checkIfconfig(self) -> list: ...
|
||||
|
||||
def close(self): ...
|
||||
|
||||
|
||||
class WLAN(NET):
|
||||
def __init__(self, interface_id: int): ...
|
||||
|
||||
def connect(self, ssid: str, key: str): ...
|
||||
|
||||
def isconnected(self) -> int: ...
|
||||
|
||||
def config(self, **kwargs): ...
|
||||
|
||||
def checkConfig(self, param: str) -> any: ...
|
||||
|
||||
def ifconfig(self, ip: str, mask: str, gateway: str, dns: str): ...
|
||||
|
||||
def checkIfconfig(self) -> list: ...
|
||||
def connectWithBssid(self, ssid: str, key: str, bssid: str): ...
|
||||
|
||||
def scan(self) -> list: ...
|
||||
|
||||
def close(self): ...
|
||||
|
||||
class LAN(NET):
|
||||
def __init__(self, interface_id: int): ...
|
||||
|
||||
def isconnected(self) -> int: ...
|
||||
|
||||
|
||||
def __init__(): ...
|
||||
|
26
package/network/_network_LAN.c
Normal file
26
package/network/_network_LAN.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "_network_LAN.h"
|
||||
#include "../pikascript-lib/PikaStdDevice/pika_hal.h"
|
||||
#include "PikaStdData_List.h"
|
||||
#include "PikaStdData_Tuple.h"
|
||||
#include "_network_common.h"
|
||||
|
||||
void _network_LAN___init__(PikaObj* self, int interface_id) {
|
||||
char LAN_NAME[] = "LAN0";
|
||||
LAN_NAME[3] = '0' + interface_id;
|
||||
pika_debug("LAN_NAME: %s\n", LAN_NAME);
|
||||
pika_dev* hal_lan = pika_hal_open(PIKA_HAL_LAN, LAN_NAME);
|
||||
if (hal_lan == NULL) {
|
||||
return;
|
||||
}
|
||||
pika_hal_LAN_config cfg = {0};
|
||||
_net_check_res(pika_hal_ioctl(hal_lan, PIKA_HAL_IOCTL_CONFIG, &cfg));
|
||||
obj_setPtr(self, "hal_dev", hal_lan);
|
||||
}
|
||||
|
||||
int _network_LAN_isconnected(PikaObj* self) {
|
||||
if (_network_NET_status(self) == PIKA_HAL_LAN_STATUS_GOT_IP) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
102
package/network/_network_NET.c
Normal file
102
package/network/_network_NET.c
Normal file
@ -0,0 +1,102 @@
|
||||
#include "_network_NET.h"
|
||||
#include "../pikascript-lib/PikaStdDevice/pika_hal.h"
|
||||
#include "PikaStdData_List.h"
|
||||
#include "PikaStdData_Tuple.h"
|
||||
#include "_network_common.h"
|
||||
|
||||
void _network_NET___init__(PikaObj* self, int interface_id) {
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
obj_setSysOut(self, "Error: NET class need inhert");
|
||||
}
|
||||
|
||||
void _network_NET_active(PikaObj* self, int is_active) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return;
|
||||
}
|
||||
if (is_active) {
|
||||
_net_check_res(pika_hal_ioctl(hal_net, PIKA_HAL_IOCTL_ENABLE));
|
||||
return;
|
||||
}
|
||||
_net_check_res(pika_hal_ioctl(hal_net, PIKA_HAL_IOCTL_DISABLE));
|
||||
return;
|
||||
}
|
||||
|
||||
int _network_NET_checkActive(PikaObj* self) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return -1;
|
||||
}
|
||||
int is_active = 0;
|
||||
_net_check_res(
|
||||
pika_hal_ioctl(hal_net, PIKA_HAL_IOCTL_NET_GET_ACTIVE, &is_active));
|
||||
return is_active;
|
||||
}
|
||||
|
||||
int _network_NET_status(PikaObj* self) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return -1;
|
||||
}
|
||||
int status = 0;
|
||||
_net_check_res(
|
||||
pika_hal_ioctl(hal_net, PIKA_HAL_IOCTL_NET_GET_STATUS, &status));
|
||||
return status;
|
||||
}
|
||||
|
||||
int _network_NET_statusWithParam(PikaObj* self, char* param) {
|
||||
return _network_NET_status(self);
|
||||
}
|
||||
|
||||
PikaObj* _network_NET_checkIfconfig(PikaObj* self) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pika_hal_NET_ifconfig ifconfig = {0};
|
||||
_net_check_res(
|
||||
pika_hal_ioctl(hal_net, PIKA_HAL_IOCTL_NET_GET_IFCONFIG, &ifconfig));
|
||||
PikaObj* ifconfig_list = newNormalObj(New_PikaStdData_List);
|
||||
PikaStdData_List___init__(ifconfig_list);
|
||||
Arg* arg = arg_newStr(ifconfig.ip);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
arg = arg_newStr(ifconfig.netmask);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
arg = arg_newStr(ifconfig.gateway);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
arg = arg_newStr(ifconfig.dns);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
return ifconfig_list;
|
||||
}
|
||||
|
||||
void _network_NET_ifconfig(PikaObj* self,
|
||||
char* ip,
|
||||
char* mask,
|
||||
char* gateway,
|
||||
char* dns) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return;
|
||||
}
|
||||
pika_hal_NET_ifconfig ifconfig = {0};
|
||||
strcpy(ifconfig.ip, ip);
|
||||
strcpy(ifconfig.netmask, mask);
|
||||
strcpy(ifconfig.gateway, gateway);
|
||||
strcpy(ifconfig.dns, dns);
|
||||
pika_debug("ip:%s, mask:%s, gateway:%s, dns:%s\n", ip, mask, gateway, dns);
|
||||
_net_check_res(
|
||||
pika_hal_ioctl(hal_net, PIKA_HAL_IOCTL_NET_SET_IFCONFIG, &ifconfig));
|
||||
return;
|
||||
}
|
||||
|
||||
void _network_NET_close(PikaObj* self) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return;
|
||||
}
|
||||
_net_check_res(pika_hal_close(hal_net));
|
||||
}
|
@ -1,13 +1,9 @@
|
||||
#include "_network_WLAN.h"
|
||||
#include "_network_NET.h"
|
||||
#include "../pikascript-lib/PikaStdDevice/pika_hal.h"
|
||||
#include "PikaStdData_List.h"
|
||||
#include "PikaStdData_Tuple.h"
|
||||
|
||||
#define check_res(res) \
|
||||
if (res != 0) { \
|
||||
pika_platform_printf("check_res failed: %d, at %s:%d:%s()\r\n", res, \
|
||||
__FILE__, __LINE__, __FUNCTION__); \
|
||||
}
|
||||
#include "_network_common.h"
|
||||
|
||||
void _network_WLAN___init__(PikaObj* self, int interface_id) {
|
||||
pika_dev* hal_wifi = pika_hal_open(PIKA_HAL_WIFI, "WLAN0");
|
||||
@ -16,78 +12,20 @@ void _network_WLAN___init__(PikaObj* self, int interface_id) {
|
||||
}
|
||||
pika_hal_WIFI_config cfg = {0};
|
||||
cfg.mode = interface_id;
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_CONFIG, &cfg));
|
||||
obj_setPtr(self, "hal_wifi", hal_wifi);
|
||||
}
|
||||
|
||||
void _network_WLAN_active(PikaObj* self, int is_active) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
return;
|
||||
}
|
||||
if (is_active) {
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_ENABLE));
|
||||
return;
|
||||
}
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_DISABLE));
|
||||
return;
|
||||
}
|
||||
|
||||
int _network_WLAN_checkActive(PikaObj* self) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
return -1;
|
||||
}
|
||||
int is_active = 0;
|
||||
check_res(
|
||||
pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_GET_ACTIVE, &is_active));
|
||||
return is_active;
|
||||
}
|
||||
|
||||
void _network_WLAN_config(PikaObj* self, PikaDict* kwargs) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
return;
|
||||
}
|
||||
pika_hal_WIFI_config cfg = {0};
|
||||
if (pikaDict_isArgExist(kwargs, "ssid")) {
|
||||
strcpy(cfg.ap_ssid, pikaDict_getStr(kwargs, "ssid"));
|
||||
}
|
||||
if (pikaDict_isArgExist(kwargs, "password")) {
|
||||
strcpy(cfg.ap_password, pikaDict_getStr(kwargs, "password"));
|
||||
}
|
||||
if (pikaDict_isArgExist(kwargs, "channel")) {
|
||||
cfg.channel = pikaDict_getInt(kwargs, "channel") + 1;
|
||||
}
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_CONFIG, &cfg));
|
||||
}
|
||||
|
||||
Arg* _network_WLAN_checkConfig(PikaObj* self, char* param) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pika_hal_WIFI_config* cfg = hal_wifi->ioctl_config;
|
||||
if (strcmp(param, "ssid") == 0) {
|
||||
return arg_newStr(cfg->ap_ssid);
|
||||
} else if (strcmp(param, "password") == 0) {
|
||||
return arg_newStr(cfg->ap_password);
|
||||
} else if (strcmp(param, "channel") == 0) {
|
||||
return arg_newInt(cfg->channel - 1);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
_net_check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_CONFIG, &cfg));
|
||||
obj_setPtr(self, "hal_dev", hal_wifi);
|
||||
}
|
||||
|
||||
void _network_WLAN_connect(PikaObj* self, char* ssid, char* key) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
pika_dev* hal_wifi = _NET_OBJ_2DEV(self);
|
||||
if (hal_wifi == NULL) {
|
||||
return;
|
||||
}
|
||||
pika_hal_WIFI_connect_config conncfg = {0};
|
||||
strcpy(conncfg.ssid, ssid);
|
||||
strcpy(conncfg.password, key);
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_CONNECT, &conncfg));
|
||||
_net_check_res(
|
||||
pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_CONNECT, &conncfg));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -95,7 +33,7 @@ void _network_WLAN_connectWithBssid(PikaObj* self,
|
||||
char* ssid,
|
||||
char* key,
|
||||
char* bssid) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
pika_dev* hal_wifi = _NET_OBJ_2DEV(self);
|
||||
if (hal_wifi == NULL) {
|
||||
return;
|
||||
}
|
||||
@ -103,91 +41,33 @@ void _network_WLAN_connectWithBssid(PikaObj* self,
|
||||
strcpy(conncfg.ssid, ssid);
|
||||
strcpy(conncfg.password, key);
|
||||
strcpy(conncfg.bssid, bssid);
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_CONNECT, &conncfg));
|
||||
_net_check_res(
|
||||
pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_CONNECT, &conncfg));
|
||||
}
|
||||
|
||||
void _network_WLAN_disconnect(PikaObj* self) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
pika_dev* hal_wifi = _NET_OBJ_2DEV(self);
|
||||
if (hal_wifi == NULL) {
|
||||
return;
|
||||
}
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_DISCONNECT));
|
||||
}
|
||||
|
||||
int _network_WLAN_status(PikaObj* self) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
return -1;
|
||||
}
|
||||
PIKA_HAL_WIFI_STATUS status = 0;
|
||||
check_res(
|
||||
pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_GET_STATUS, &status));
|
||||
return status;
|
||||
_net_check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_DISCONNECT));
|
||||
}
|
||||
|
||||
int _network_WLAN_isconnected(PikaObj* self) {
|
||||
if (_network_WLAN_status(self) == PIKA_HAL_WIFI_STATUS_GOT_IP) {
|
||||
if (_network_NET_status(self) == PIKA_HAL_WIFI_STATUS_GOT_IP) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _network_WLAN_statusWithParam(PikaObj* self, char* param) {
|
||||
return _network_WLAN_status(self);
|
||||
}
|
||||
|
||||
PikaObj* _network_WLAN_checkIfconfig(PikaObj* self) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pika_hal_WIFI_ifconfig ifconfig = {0};
|
||||
check_res(
|
||||
pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_GET_IFCONFIG, &ifconfig));
|
||||
PikaObj* ifconfig_list = newNormalObj(New_PikaStdData_List);
|
||||
PikaStdData_List___init__(ifconfig_list);
|
||||
Arg* arg = arg_newStr(ifconfig.ip);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
arg = arg_newStr(ifconfig.netmask);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
arg = arg_newStr(ifconfig.gateway);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
arg = arg_newStr(ifconfig.dns);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
return ifconfig_list;
|
||||
}
|
||||
|
||||
void _network_WLAN_ifconfig(PikaObj* self,
|
||||
char* ip,
|
||||
char* mask,
|
||||
char* gateway,
|
||||
char* dns) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
return;
|
||||
}
|
||||
pika_hal_WIFI_ifconfig ifconfig = {0};
|
||||
strcpy(ifconfig.ip, ip);
|
||||
strcpy(ifconfig.netmask, mask);
|
||||
strcpy(ifconfig.gateway, gateway);
|
||||
strcpy(ifconfig.dns, dns);
|
||||
check_res(
|
||||
pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_SET_IFCONFIG, &ifconfig));
|
||||
return;
|
||||
}
|
||||
|
||||
PikaObj* _network_WLAN_scan(PikaObj* self) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
pika_dev* hal_wifi = _NET_OBJ_2DEV(self);
|
||||
if (hal_wifi == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pika_hal_WIFI_scan_result* result = NULL;
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_SCAN, &result));
|
||||
_net_check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_SCAN, &result));
|
||||
if (NULL == result) {
|
||||
return NULL;
|
||||
}
|
||||
@ -224,10 +104,37 @@ PikaObj* _network_WLAN_scan(PikaObj* self) {
|
||||
return scan_list;
|
||||
}
|
||||
|
||||
void _network_WLAN_close(PikaObj* self) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
void _network_WLAN_config(PikaObj* self, PikaDict* kwargs) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return;
|
||||
}
|
||||
check_res(pika_hal_close(hal_wifi));
|
||||
pika_hal_WIFI_config cfg = {0};
|
||||
if (pikaDict_isArgExist(kwargs, "ssid")) {
|
||||
strcpy(cfg.ap_ssid, pikaDict_getStr(kwargs, "ssid"));
|
||||
}
|
||||
if (pikaDict_isArgExist(kwargs, "password")) {
|
||||
strcpy(cfg.ap_password, pikaDict_getStr(kwargs, "password"));
|
||||
}
|
||||
if (pikaDict_isArgExist(kwargs, "channel")) {
|
||||
cfg.channel = pikaDict_getInt(kwargs, "channel") + 1;
|
||||
}
|
||||
_net_check_res(pika_hal_ioctl(hal_net, PIKA_HAL_IOCTL_CONFIG, &cfg));
|
||||
}
|
||||
|
||||
Arg* _network_WLAN_checkConfig(PikaObj* self, char* param) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pika_hal_WIFI_config* cfg = hal_net->ioctl_config;
|
||||
if (strcmp(param, "ssid") == 0) {
|
||||
return arg_newStr(cfg->ap_ssid);
|
||||
} else if (strcmp(param, "password") == 0) {
|
||||
return arg_newStr(cfg->ap_password);
|
||||
} else if (strcmp(param, "channel") == 0) {
|
||||
return arg_newInt(cfg->channel - 1);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
1
package/network/_network_common.c
Normal file
1
package/network/_network_common.c
Normal file
@ -0,0 +1 @@
|
||||
#include "_network_common.h"
|
13
package/network/_network_common.h
Normal file
13
package/network/_network_common.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef _H_NETOWRK_COMMON_H_
|
||||
#define _H_NETOWRK_COMMON_H_
|
||||
#include "_network_NET.h"
|
||||
|
||||
#define _net_check_res(res) \
|
||||
if (res != 0) { \
|
||||
pika_platform_printf("_net_check_res failed: %d, at %s:%d:%s()\r\n", \
|
||||
res, __FILE__, __LINE__, __FUNCTION__); \
|
||||
}
|
||||
|
||||
#define _NET_OBJ_2DEV(_self) obj_getPtr((_self), "hal_dev");
|
||||
|
||||
#endif
|
@ -11,6 +11,40 @@ STAT_CONNECT_FAIL = _network.STAT_CONNECT_FAIL
|
||||
STAT_GOT_IP = _network.STAT_GOT_IP
|
||||
|
||||
_instence:"WLAN" = None
|
||||
|
||||
class LAN(_network.LAN):
|
||||
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 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:
|
||||
t = super().checkIfconfig()
|
||||
return (t[0], t[1], t[2], t[3])
|
||||
else:
|
||||
return super().ifconfig(
|
||||
config[0], config[1], config[2], config[3])
|
||||
|
||||
class WLAN(_network.WLAN):
|
||||
def __init__(self, interface_id: int):
|
||||
global _instence
|
||||
|
@ -1,4 +1,4 @@
|
||||
#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
|
||||
#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
|
||||
#include "lvgl.h"
|
||||
#else
|
||||
#include "../../lvgl.h"
|
||||
@ -13,9 +13,9 @@
|
||||
#include "pika_lvgl_FLEX_ALIGN.h"
|
||||
#include "pika_lvgl_FLEX_FLOW.h"
|
||||
#include "pika_lvgl_LAYOUT_FLEX.h"
|
||||
#include "pika_lvgl_SIZE.h"
|
||||
#include "pika_lvgl_OPA.h"
|
||||
#include "pika_lvgl_PALETTE.h"
|
||||
#include "pika_lvgl_SIZE.h"
|
||||
#include "pika_lvgl_STATE.h"
|
||||
#include "pika_lvgl_TEXT_DECOR.h"
|
||||
#include "pika_lvgl_arc.h"
|
||||
@ -27,11 +27,14 @@
|
||||
|
||||
PikaObj* pika_lv_event_listener_g;
|
||||
Args* pika_lv_id_register_g;
|
||||
pika_platform_thread_mutex_t pika_lv_global_mutex_g = {0};
|
||||
|
||||
#if !PIKASCRIPT_VERSION_REQUIRE_MINIMUN(1, 11, 7)
|
||||
#error "pikascript version must be greater than 1.11.7"
|
||||
#if !PIKASCRIPT_VERSION_REQUIRE_MINIMUN(1, 13, 1)
|
||||
#error "pikascript version must be greater than 1.13.1"
|
||||
#endif
|
||||
|
||||
volatile int g_lvgl_inited = 0;
|
||||
|
||||
void pika_lvgl_STATE___init__(PikaObj* self) {
|
||||
obj_setInt(self, "DEFAULT", LV_STATE_DEFAULT);
|
||||
obj_setInt(self, "CHECKED", LV_STATE_CHECKED);
|
||||
@ -49,6 +52,20 @@ void pika_lvgl_STATE___init__(PikaObj* self) {
|
||||
obj_setInt(self, "ANY", LV_STATE_ANY);
|
||||
}
|
||||
|
||||
void pika_lvgl_lock(PikaObj* self) {
|
||||
if (!g_lvgl_inited) {
|
||||
return;
|
||||
}
|
||||
pika_platform_thread_mutex_lock(&pika_lv_global_mutex_g);
|
||||
}
|
||||
|
||||
void pika_lvgl_unlock(PikaObj* self) {
|
||||
if (!g_lvgl_inited) {
|
||||
return;
|
||||
}
|
||||
pika_platform_thread_mutex_unlock(&pika_lv_global_mutex_g);
|
||||
}
|
||||
|
||||
void pika_lvgl_flag_t___init__(PikaObj* self) {
|
||||
obj_setInt(self, "HIDDEN", LV_OBJ_FLAG_HIDDEN);
|
||||
obj_setInt(self, "CLICKABLE", LV_OBJ_FLAG_CLICKABLE);
|
||||
@ -201,9 +218,8 @@ PikaObj* pika_lvgl_scr_act(PikaObj* self) {
|
||||
return new_obj;
|
||||
}
|
||||
|
||||
volatile int g_lvgl_inited = 0;
|
||||
void pika_lvgl___init__(PikaObj* self) {
|
||||
if (!lv_is_initialized()){
|
||||
if (!lv_is_initialized()) {
|
||||
pika_debug("Error: lvgl is not initialized");
|
||||
return;
|
||||
}
|
||||
@ -211,7 +227,11 @@ void pika_lvgl___init__(PikaObj* self) {
|
||||
pika_lv_event_listener_g = obj_getObj(self, "lv_event_listener");
|
||||
pika_lv_id_register_g = New_args(NULL);
|
||||
if (!g_lvgl_inited) {
|
||||
pika_debug("Init pika_lv_global_mutex_g");
|
||||
pika_platform_thread_mutex_init(&pika_lv_global_mutex_g);
|
||||
pika_lvgl_lock(NULL);
|
||||
lv_png_init();
|
||||
pika_lvgl_unlock(NULL);
|
||||
g_lvgl_inited = 1;
|
||||
}
|
||||
}
|
||||
@ -301,11 +321,11 @@ void pika_lvgl_LAYOUT_FLEX___init__(PikaObj* self) {
|
||||
obj_setInt(self, "value", LV_LAYOUT_FLEX);
|
||||
}
|
||||
|
||||
void pika_lvgl_SIZE___init__(PikaObj *self){
|
||||
void pika_lvgl_SIZE___init__(PikaObj* self) {
|
||||
obj_setInt(self, "CONTENT", LV_SIZE_CONTENT);
|
||||
}
|
||||
|
||||
int pika_lvgl_pct(PikaObj *self, int x){
|
||||
int pika_lvgl_pct(PikaObj* self, int x) {
|
||||
return LV_PCT(x);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,10 @@ def __init__(): ...
|
||||
def __del__(): ...
|
||||
|
||||
|
||||
def lock(): ...
|
||||
def unlock(): ...
|
||||
|
||||
|
||||
class EVENT:
|
||||
ALL: int
|
||||
PRESSED: int
|
||||
@ -383,7 +387,7 @@ class lv_obj:
|
||||
# def area_is_visible(self, area: lv_area_t) -> int: ...
|
||||
def is_visible(self) -> int: ...
|
||||
def set_ext_click_area(self, size: int): ...
|
||||
def set_style_size(self, value:int, selector: int): ...
|
||||
def set_style_size(self, value: int, selector: int): ...
|
||||
# def get_click_area(self, area: lv_area_t): ...
|
||||
def hit_test(self, point: point_t) -> int: ...
|
||||
def set_flex_flow(self, flow: int): ...
|
||||
@ -606,6 +610,7 @@ class canvas(lv_obj):
|
||||
class chart_series_t:
|
||||
...
|
||||
|
||||
|
||||
class chart(lv_obj):
|
||||
def __init__(self, parent: lv_obj): ...
|
||||
def set_point_count(self, cnt: int): ...
|
||||
@ -617,6 +622,7 @@ class chart(lv_obj):
|
||||
def set_ext_y_array(self, ser: chart_series_t, array: any): ...
|
||||
def refresh(self): ...
|
||||
|
||||
|
||||
def scr_act() -> lv_obj: ...
|
||||
def pct(x: int) -> int: ...
|
||||
def timer_create_basic() -> lv_timer_t: ...
|
||||
|
@ -1,4 +1,4 @@
|
||||
#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
|
||||
#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
|
||||
#include "lvgl.h"
|
||||
#else
|
||||
#include "../../lvgl.h"
|
||||
|
@ -7,37 +7,44 @@ STAT_NO_AP_FOUND: int
|
||||
STAT_CONNECT_FAIL: int
|
||||
STAT_GOT_IP: int
|
||||
|
||||
|
||||
class WLAN:
|
||||
class NET:
|
||||
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 ifconfig(self, ip: str, mask: str, gateway: str, dns: str): ...
|
||||
|
||||
def checkIfconfig(self) -> list: ...
|
||||
|
||||
def close(self): ...
|
||||
|
||||
|
||||
class WLAN(NET):
|
||||
def __init__(self, interface_id: int): ...
|
||||
|
||||
def connect(self, ssid: str, key: str): ...
|
||||
|
||||
def isconnected(self) -> int: ...
|
||||
|
||||
def config(self, **kwargs): ...
|
||||
|
||||
def checkConfig(self, param: str) -> any: ...
|
||||
|
||||
def ifconfig(self, ip: str, mask: str, gateway: str, dns: str): ...
|
||||
|
||||
def checkIfconfig(self) -> list: ...
|
||||
def connectWithBssid(self, ssid: str, key: str, bssid: str): ...
|
||||
|
||||
def scan(self) -> list: ...
|
||||
|
||||
def close(self): ...
|
||||
|
||||
class LAN(NET):
|
||||
def __init__(self, interface_id: int): ...
|
||||
|
||||
def isconnected(self) -> int: ...
|
||||
|
||||
|
||||
def __init__(): ...
|
||||
|
@ -378,7 +378,8 @@ class ModBusRTU(ModBus):
|
||||
|
||||
def setUart(self, uart: PikaStdDevice.UART):
|
||||
self._uart = uart
|
||||
uart.setCallBack(self.recvCallback, uart.SIGNAL_RX)
|
||||
debug('set uart', uart)
|
||||
uart.setCallback(self.recvCallback, uart.SIGNAL_RX)
|
||||
|
||||
def recv(self, count: int = 10):
|
||||
"""
|
||||
|
@ -11,6 +11,40 @@ STAT_CONNECT_FAIL = _network.STAT_CONNECT_FAIL
|
||||
STAT_GOT_IP = _network.STAT_GOT_IP
|
||||
|
||||
_instence:"WLAN" = None
|
||||
|
||||
class LAN(_network.LAN):
|
||||
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 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:
|
||||
t = super().checkIfconfig()
|
||||
return (t[0], t[1], t[2], t[3])
|
||||
else:
|
||||
return super().ifconfig(
|
||||
config[0], config[1], config[2], config[3])
|
||||
|
||||
class WLAN(_network.WLAN):
|
||||
def __init__(self, interface_id: int):
|
||||
global _instence
|
||||
|
@ -336,6 +336,12 @@ int pika_hal_WIFI_ioctl_merge_config(pika_hal_WIFI_config* dst,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_LAN_ioctl_merge_config(pika_hal_LAN_config* dst,
|
||||
pika_hal_LAN_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(user_data, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pika_hal_SG_ioctl_merge_config(pika_hal_SG_config* dst,
|
||||
pika_hal_SG_config* src) {
|
||||
_IOCTL_CONFIG_USE_DEFAULT(waveform, PIKA_HAL_SG_WAVEFORM_SINE);
|
||||
|
@ -32,17 +32,27 @@ typedef enum {
|
||||
PIKA_HAL_IOCTL_CONFIG,
|
||||
PIKA_HAL_IOCTL_ENABLE,
|
||||
PIKA_HAL_IOCTL_DISABLE,
|
||||
PIKA_HAL_IOCTL_WIFI_GET_ACTIVE,
|
||||
PIKA_HAL_IOCTL_WIFI_GET_STATUS,
|
||||
PIKA_HAL_IOCTL_NET_GET_ACTIVE,
|
||||
PIKA_HAL_IOCTL_NET_GET_STATUS,
|
||||
PIKA_HAL_IOCTL_WIFI_SCAN,
|
||||
PIKA_HAL_IOCTL_WIFI_CONNECT,
|
||||
PIKA_HAL_IOCTL_WIFI_DISCONNECT,
|
||||
PIKA_HAL_IOCTL_WIFI_SET_IFCONFIG,
|
||||
PIKA_HAL_IOCTL_WIFI_GET_IFCONFIG,
|
||||
PIKA_HAL_IOCTL_NET_SET_IFCONFIG,
|
||||
PIKA_HAL_IOCTL_NET_GET_IFCONFIG,
|
||||
PIKA_HAL_IOCTL_CAM_CAPTURE,
|
||||
_ = 0xFFFFFFFF, // make sure it is 4 byte width
|
||||
} PIKA_HAL_IOCTL_CMD;
|
||||
|
||||
#define PIKA_HAL_IOCTL_WIFI_GET_ACTIVE PIKA_HAL_IOCTL_NET_GET_ACTIVE
|
||||
#define PIKA_HAL_IOCTL_WIFI_GET_STATUS PIKA_HAL_IOCTL_NET_GET_STATUS
|
||||
#define PIKA_HAL_IOCTL_WIFI_SET_IFCONFIG PIKA_HAL_IOCTL_NET_SET_IFCONFIG
|
||||
#define PIKA_HAL_IOCTL_WIFI_GET_IFCONFIG PIKA_HAL_IOCTL_NET_GET_IFCONFIG
|
||||
|
||||
#define PIKA_HAL_IOCTL_LAN_GET_ACTIVE PIKA_HAL_IOCTL_NET_GET_ACTIVE
|
||||
#define PIKA_HAL_IOCTL_LAN_GET_STATUS PIKA_HAL_IOCTL_NET_GET_STATUS
|
||||
#define PIKA_HAL_IOCTL_LAN_SET_IFCONFIG PIKA_HAL_IOCTL_NET_SET_IFCONFIG
|
||||
#define PIKA_HAL_IOCTL_LAN_GET_IFCONFIG PIKA_HAL_IOCTL_NET_GET_IFCONFIG
|
||||
|
||||
/* posix file like API */
|
||||
pika_dev* pika_hal_open(PIKA_HAL_DEV_TYPE dev_type, char* name);
|
||||
int pika_hal_close(pika_dev* dev);
|
||||
@ -432,6 +442,13 @@ typedef enum {
|
||||
PIKA_HAL_WIFI_STATUS_GOT_IP,
|
||||
} PIKA_HAL_WIFI_STATUS;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_LAN_STATUS_UNUSED = 0,
|
||||
PIKA_HAL_LAN_STATUS_IDLE,
|
||||
PIKA_HAL_LAN_STATUS_CONNECTING,
|
||||
PIKA_HAL_LAN_STATUS_GOT_IP,
|
||||
} PIKA_HAL_LAN_STATUS;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_WIFI_CHANNEL_UNUSED = 0,
|
||||
PIKA_HAL_WIFI_CHANNEL_0,
|
||||
@ -479,12 +496,15 @@ typedef struct pika_hal_WIFI_connect_config {
|
||||
char password[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
} pika_hal_WIFI_connect_config;
|
||||
|
||||
typedef struct pika_hal_WIFI_ifconfig {
|
||||
typedef struct pika_hal_NET_ifconfig {
|
||||
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_ifconfig;
|
||||
} pika_hal_NET_ifconfig;
|
||||
|
||||
#define pika_hal_WIFI_ifconfig pika_hal_NET_ifconfig
|
||||
#define pika_hal_LAN_ifconfig pika_hal_NET_ifconfig
|
||||
|
||||
typedef struct pika_hal_WIFI_record {
|
||||
char ssid[PIKA_HAL_WIFI_PARAM_MAX_LEN];
|
||||
@ -500,6 +520,10 @@ typedef struct pika_hal_WIFI_scan_result {
|
||||
pika_hal_WIFI_record records[];
|
||||
} pika_hal_WIFI_scan_result;
|
||||
|
||||
typedef struct pika_hal_LAN_config {
|
||||
void* user_data;
|
||||
} pika_hal_LAN_config;
|
||||
|
||||
typedef enum {
|
||||
_PIKA_HAL_PWM_PERIOD_UNUSED = 0,
|
||||
PIKA_HAL_TIM_PERIOD_1NS = 1,
|
||||
|
@ -12,6 +12,7 @@ pika_hal_table_add(PWM)
|
||||
pika_hal_table_add(SOFT_SPI)
|
||||
pika_hal_table_add(SOFT_IIC)
|
||||
pika_hal_table_add(WIFI)
|
||||
pika_hal_table_add(LAN)
|
||||
pika_hal_table_add(TIM)
|
||||
pika_hal_table_add(SOFT_TIM)
|
||||
pika_hal_table_add(CAM)
|
||||
|
@ -0,0 +1,26 @@
|
||||
#include "_network_LAN.h"
|
||||
#include "../pikascript-lib/PikaStdDevice/pika_hal.h"
|
||||
#include "PikaStdData_List.h"
|
||||
#include "PikaStdData_Tuple.h"
|
||||
#include "_network_common.h"
|
||||
|
||||
void _network_LAN___init__(PikaObj* self, int interface_id) {
|
||||
char LAN_NAME[] = "LAN0";
|
||||
LAN_NAME[3] = '0' + interface_id;
|
||||
pika_debug("LAN_NAME: %s\n", LAN_NAME);
|
||||
pika_dev* hal_lan = pika_hal_open(PIKA_HAL_LAN, LAN_NAME);
|
||||
if (hal_lan == NULL) {
|
||||
return;
|
||||
}
|
||||
pika_hal_LAN_config cfg = {0};
|
||||
_net_check_res(pika_hal_ioctl(hal_lan, PIKA_HAL_IOCTL_CONFIG, &cfg));
|
||||
obj_setPtr(self, "hal_dev", hal_lan);
|
||||
}
|
||||
|
||||
int _network_LAN_isconnected(PikaObj* self) {
|
||||
if (_network_NET_status(self) == PIKA_HAL_LAN_STATUS_GOT_IP) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
#include "_network_NET.h"
|
||||
#include "../pikascript-lib/PikaStdDevice/pika_hal.h"
|
||||
#include "PikaStdData_List.h"
|
||||
#include "PikaStdData_Tuple.h"
|
||||
#include "_network_common.h"
|
||||
|
||||
void _network_NET___init__(PikaObj* self, int interface_id) {
|
||||
obj_setErrorCode(self, -__LINE__);
|
||||
obj_setSysOut(self, "Error: NET class need inhert");
|
||||
}
|
||||
|
||||
void _network_NET_active(PikaObj* self, int is_active) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return;
|
||||
}
|
||||
if (is_active) {
|
||||
_net_check_res(pika_hal_ioctl(hal_net, PIKA_HAL_IOCTL_ENABLE));
|
||||
return;
|
||||
}
|
||||
_net_check_res(pika_hal_ioctl(hal_net, PIKA_HAL_IOCTL_DISABLE));
|
||||
return;
|
||||
}
|
||||
|
||||
int _network_NET_checkActive(PikaObj* self) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return -1;
|
||||
}
|
||||
int is_active = 0;
|
||||
_net_check_res(
|
||||
pika_hal_ioctl(hal_net, PIKA_HAL_IOCTL_NET_GET_ACTIVE, &is_active));
|
||||
return is_active;
|
||||
}
|
||||
|
||||
int _network_NET_status(PikaObj* self) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return -1;
|
||||
}
|
||||
int status = 0;
|
||||
_net_check_res(
|
||||
pika_hal_ioctl(hal_net, PIKA_HAL_IOCTL_NET_GET_STATUS, &status));
|
||||
return status;
|
||||
}
|
||||
|
||||
int _network_NET_statusWithParam(PikaObj* self, char* param) {
|
||||
return _network_NET_status(self);
|
||||
}
|
||||
|
||||
PikaObj* _network_NET_checkIfconfig(PikaObj* self) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pika_hal_NET_ifconfig ifconfig = {0};
|
||||
_net_check_res(
|
||||
pika_hal_ioctl(hal_net, PIKA_HAL_IOCTL_NET_GET_IFCONFIG, &ifconfig));
|
||||
PikaObj* ifconfig_list = newNormalObj(New_PikaStdData_List);
|
||||
PikaStdData_List___init__(ifconfig_list);
|
||||
Arg* arg = arg_newStr(ifconfig.ip);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
arg = arg_newStr(ifconfig.netmask);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
arg = arg_newStr(ifconfig.gateway);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
arg = arg_newStr(ifconfig.dns);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
return ifconfig_list;
|
||||
}
|
||||
|
||||
void _network_NET_ifconfig(PikaObj* self,
|
||||
char* ip,
|
||||
char* mask,
|
||||
char* gateway,
|
||||
char* dns) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return;
|
||||
}
|
||||
pika_hal_NET_ifconfig ifconfig = {0};
|
||||
strcpy(ifconfig.ip, ip);
|
||||
strcpy(ifconfig.netmask, mask);
|
||||
strcpy(ifconfig.gateway, gateway);
|
||||
strcpy(ifconfig.dns, dns);
|
||||
pika_debug("ip:%s, mask:%s, gateway:%s, dns:%s\n", ip, mask, gateway, dns);
|
||||
_net_check_res(
|
||||
pika_hal_ioctl(hal_net, PIKA_HAL_IOCTL_NET_SET_IFCONFIG, &ifconfig));
|
||||
return;
|
||||
}
|
||||
|
||||
void _network_NET_close(PikaObj* self) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return;
|
||||
}
|
||||
_net_check_res(pika_hal_close(hal_net));
|
||||
}
|
@ -1,13 +1,9 @@
|
||||
#include "_network_WLAN.h"
|
||||
#include "_network_NET.h"
|
||||
#include "../pikascript-lib/PikaStdDevice/pika_hal.h"
|
||||
#include "PikaStdData_List.h"
|
||||
#include "PikaStdData_Tuple.h"
|
||||
|
||||
#define check_res(res) \
|
||||
if (res != 0) { \
|
||||
pika_platform_printf("check_res failed: %d, at %s:%d:%s()\r\n", res, \
|
||||
__FILE__, __LINE__, __FUNCTION__); \
|
||||
}
|
||||
#include "_network_common.h"
|
||||
|
||||
void _network_WLAN___init__(PikaObj* self, int interface_id) {
|
||||
pika_dev* hal_wifi = pika_hal_open(PIKA_HAL_WIFI, "WLAN0");
|
||||
@ -16,78 +12,20 @@ void _network_WLAN___init__(PikaObj* self, int interface_id) {
|
||||
}
|
||||
pika_hal_WIFI_config cfg = {0};
|
||||
cfg.mode = interface_id;
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_CONFIG, &cfg));
|
||||
obj_setPtr(self, "hal_wifi", hal_wifi);
|
||||
}
|
||||
|
||||
void _network_WLAN_active(PikaObj* self, int is_active) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
return;
|
||||
}
|
||||
if (is_active) {
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_ENABLE));
|
||||
return;
|
||||
}
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_DISABLE));
|
||||
return;
|
||||
}
|
||||
|
||||
int _network_WLAN_checkActive(PikaObj* self) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
return -1;
|
||||
}
|
||||
int is_active = 0;
|
||||
check_res(
|
||||
pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_GET_ACTIVE, &is_active));
|
||||
return is_active;
|
||||
}
|
||||
|
||||
void _network_WLAN_config(PikaObj* self, PikaDict* kwargs) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
return;
|
||||
}
|
||||
pika_hal_WIFI_config cfg = {0};
|
||||
if (pikaDict_isArgExist(kwargs, "ssid")) {
|
||||
strcpy(cfg.ap_ssid, pikaDict_getStr(kwargs, "ssid"));
|
||||
}
|
||||
if (pikaDict_isArgExist(kwargs, "password")) {
|
||||
strcpy(cfg.ap_password, pikaDict_getStr(kwargs, "password"));
|
||||
}
|
||||
if (pikaDict_isArgExist(kwargs, "channel")) {
|
||||
cfg.channel = pikaDict_getInt(kwargs, "channel") + 1;
|
||||
}
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_CONFIG, &cfg));
|
||||
}
|
||||
|
||||
Arg* _network_WLAN_checkConfig(PikaObj* self, char* param) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pika_hal_WIFI_config* cfg = hal_wifi->ioctl_config;
|
||||
if (strcmp(param, "ssid") == 0) {
|
||||
return arg_newStr(cfg->ap_ssid);
|
||||
} else if (strcmp(param, "password") == 0) {
|
||||
return arg_newStr(cfg->ap_password);
|
||||
} else if (strcmp(param, "channel") == 0) {
|
||||
return arg_newInt(cfg->channel - 1);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
_net_check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_CONFIG, &cfg));
|
||||
obj_setPtr(self, "hal_dev", hal_wifi);
|
||||
}
|
||||
|
||||
void _network_WLAN_connect(PikaObj* self, char* ssid, char* key) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
pika_dev* hal_wifi = _NET_OBJ_2DEV(self);
|
||||
if (hal_wifi == NULL) {
|
||||
return;
|
||||
}
|
||||
pika_hal_WIFI_connect_config conncfg = {0};
|
||||
strcpy(conncfg.ssid, ssid);
|
||||
strcpy(conncfg.password, key);
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_CONNECT, &conncfg));
|
||||
_net_check_res(
|
||||
pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_CONNECT, &conncfg));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -95,7 +33,7 @@ void _network_WLAN_connectWithBssid(PikaObj* self,
|
||||
char* ssid,
|
||||
char* key,
|
||||
char* bssid) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
pika_dev* hal_wifi = _NET_OBJ_2DEV(self);
|
||||
if (hal_wifi == NULL) {
|
||||
return;
|
||||
}
|
||||
@ -103,91 +41,33 @@ void _network_WLAN_connectWithBssid(PikaObj* self,
|
||||
strcpy(conncfg.ssid, ssid);
|
||||
strcpy(conncfg.password, key);
|
||||
strcpy(conncfg.bssid, bssid);
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_CONNECT, &conncfg));
|
||||
_net_check_res(
|
||||
pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_CONNECT, &conncfg));
|
||||
}
|
||||
|
||||
void _network_WLAN_disconnect(PikaObj* self) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
pika_dev* hal_wifi = _NET_OBJ_2DEV(self);
|
||||
if (hal_wifi == NULL) {
|
||||
return;
|
||||
}
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_DISCONNECT));
|
||||
}
|
||||
|
||||
int _network_WLAN_status(PikaObj* self) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
return -1;
|
||||
}
|
||||
PIKA_HAL_WIFI_STATUS status = 0;
|
||||
check_res(
|
||||
pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_GET_STATUS, &status));
|
||||
return status;
|
||||
_net_check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_DISCONNECT));
|
||||
}
|
||||
|
||||
int _network_WLAN_isconnected(PikaObj* self) {
|
||||
if (_network_WLAN_status(self) == PIKA_HAL_WIFI_STATUS_GOT_IP) {
|
||||
if (_network_NET_status(self) == PIKA_HAL_WIFI_STATUS_GOT_IP) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _network_WLAN_statusWithParam(PikaObj* self, char* param) {
|
||||
return _network_WLAN_status(self);
|
||||
}
|
||||
|
||||
PikaObj* _network_WLAN_checkIfconfig(PikaObj* self) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pika_hal_WIFI_ifconfig ifconfig = {0};
|
||||
check_res(
|
||||
pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_GET_IFCONFIG, &ifconfig));
|
||||
PikaObj* ifconfig_list = newNormalObj(New_PikaStdData_List);
|
||||
PikaStdData_List___init__(ifconfig_list);
|
||||
Arg* arg = arg_newStr(ifconfig.ip);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
arg = arg_newStr(ifconfig.netmask);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
arg = arg_newStr(ifconfig.gateway);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
arg = arg_newStr(ifconfig.dns);
|
||||
PikaStdData_List_append(ifconfig_list, arg);
|
||||
arg_deinit(arg);
|
||||
return ifconfig_list;
|
||||
}
|
||||
|
||||
void _network_WLAN_ifconfig(PikaObj* self,
|
||||
char* ip,
|
||||
char* mask,
|
||||
char* gateway,
|
||||
char* dns) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
return;
|
||||
}
|
||||
pika_hal_WIFI_ifconfig ifconfig = {0};
|
||||
strcpy(ifconfig.ip, ip);
|
||||
strcpy(ifconfig.netmask, mask);
|
||||
strcpy(ifconfig.gateway, gateway);
|
||||
strcpy(ifconfig.dns, dns);
|
||||
check_res(
|
||||
pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_SET_IFCONFIG, &ifconfig));
|
||||
return;
|
||||
}
|
||||
|
||||
PikaObj* _network_WLAN_scan(PikaObj* self) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
pika_dev* hal_wifi = _NET_OBJ_2DEV(self);
|
||||
if (hal_wifi == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pika_hal_WIFI_scan_result* result = NULL;
|
||||
check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_SCAN, &result));
|
||||
_net_check_res(pika_hal_ioctl(hal_wifi, PIKA_HAL_IOCTL_WIFI_SCAN, &result));
|
||||
if (NULL == result) {
|
||||
return NULL;
|
||||
}
|
||||
@ -224,10 +104,37 @@ PikaObj* _network_WLAN_scan(PikaObj* self) {
|
||||
return scan_list;
|
||||
}
|
||||
|
||||
void _network_WLAN_close(PikaObj* self) {
|
||||
pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi");
|
||||
if (hal_wifi == NULL) {
|
||||
void _network_WLAN_config(PikaObj* self, PikaDict* kwargs) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return;
|
||||
}
|
||||
check_res(pika_hal_close(hal_wifi));
|
||||
pika_hal_WIFI_config cfg = {0};
|
||||
if (pikaDict_isArgExist(kwargs, "ssid")) {
|
||||
strcpy(cfg.ap_ssid, pikaDict_getStr(kwargs, "ssid"));
|
||||
}
|
||||
if (pikaDict_isArgExist(kwargs, "password")) {
|
||||
strcpy(cfg.ap_password, pikaDict_getStr(kwargs, "password"));
|
||||
}
|
||||
if (pikaDict_isArgExist(kwargs, "channel")) {
|
||||
cfg.channel = pikaDict_getInt(kwargs, "channel") + 1;
|
||||
}
|
||||
_net_check_res(pika_hal_ioctl(hal_net, PIKA_HAL_IOCTL_CONFIG, &cfg));
|
||||
}
|
||||
|
||||
Arg* _network_WLAN_checkConfig(PikaObj* self, char* param) {
|
||||
pika_dev* hal_net = _NET_OBJ_2DEV(self);
|
||||
if (hal_net == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pika_hal_WIFI_config* cfg = hal_net->ioctl_config;
|
||||
if (strcmp(param, "ssid") == 0) {
|
||||
return arg_newStr(cfg->ap_ssid);
|
||||
} else if (strcmp(param, "password") == 0) {
|
||||
return arg_newStr(cfg->ap_password);
|
||||
} else if (strcmp(param, "channel") == 0) {
|
||||
return arg_newInt(cfg->channel - 1);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
#include "_network_common.h"
|
@ -0,0 +1,13 @@
|
||||
#ifndef _H_NETOWRK_COMMON_H_
|
||||
#define _H_NETOWRK_COMMON_H_
|
||||
#include "_network_NET.h"
|
||||
|
||||
#define _net_check_res(res) \
|
||||
if (res != 0) { \
|
||||
pika_platform_printf("_net_check_res failed: %d, at %s:%d:%s()\r\n", \
|
||||
res, __FILE__, __LINE__, __FUNCTION__); \
|
||||
}
|
||||
|
||||
#define _NET_OBJ_2DEV(_self) obj_getPtr((_self), "hal_dev");
|
||||
|
||||
#endif
|
@ -44,12 +44,15 @@ for root, apply_dirs, files in os.walk('.'):
|
||||
target_file = os.path.join(base_path, rel_path, file)
|
||||
print(f"Processing file: {src_file}")
|
||||
if os.path.exists(target_file):
|
||||
diff_command = ["git", "diff", "--no-index", target_file, src_file]
|
||||
diff_command = ["git", "diff",
|
||||
"--no-index", target_file, src_file]
|
||||
result = subprocess.run(diff_command, stdout=subprocess.PIPE)
|
||||
if result.stdout:
|
||||
diff_output = result.stdout.decode()
|
||||
# 确保使用UTF-8编码解码stdout
|
||||
diff_output = result.stdout.decode('utf-8')
|
||||
print(diff_output)
|
||||
with open("/tmp/base/changes.patch", "a") as patch_file:
|
||||
# 使用UTF-8编码打开文件进行写入
|
||||
with open("/tmp/base/changes.patch", "a", encoding='utf-8') as patch_file:
|
||||
patch_file.write(diff_output)
|
||||
else:
|
||||
print(f"No base file, skipped: {target_file}")
|
||||
@ -61,7 +64,7 @@ if not os.path.exists("/tmp/base/changes.patch"):
|
||||
exit()
|
||||
|
||||
# read the patch
|
||||
with open("/tmp/base/changes.patch") as patch_file:
|
||||
with open("/tmp/base/changes.patch", encoding='utf-8') as patch_file:
|
||||
patch_data = patch_file.read()
|
||||
|
||||
# split the patch into a list of patches
|
||||
@ -116,7 +119,7 @@ for patch in patches:
|
||||
for dir in search_dirs:
|
||||
file_name = os.path.basename(from_file)
|
||||
# find file
|
||||
#if is_found:
|
||||
# if is_found:
|
||||
# break
|
||||
|
||||
for root, apply_dirs, files in os.walk(dir):
|
||||
@ -133,11 +136,12 @@ for patch in patches:
|
||||
print(f"Applying patch: {patch}")
|
||||
# Strip the trailing whitespace for each line
|
||||
lines = [line for line in patch.split('\n')]
|
||||
with open("/tmp/base/temp.patch", 'w') as f:
|
||||
with open("/tmp/base/temp.patch", 'w', encoding='utf-8') as f:
|
||||
for line in lines:
|
||||
f.write(line + '\n')
|
||||
apply_patch_command = ["git", "apply", "/tmp/base/temp.patch"]
|
||||
result = subprocess.run(apply_patch_command, stdout=subprocess.PIPE, cwd=main_repo_path)
|
||||
result = subprocess.run(
|
||||
apply_patch_command, stdout=subprocess.PIPE, cwd=main_repo_path)
|
||||
# check the result
|
||||
if result.returncode != 0:
|
||||
fail_count += 1
|
||||
@ -146,7 +150,8 @@ for patch in patches:
|
||||
else:
|
||||
success_count += 1
|
||||
success_list.append(apply_file)
|
||||
print("\033[92mSuccessfully applied patch\033[0m", apply_file)
|
||||
print(
|
||||
"\033[92mSuccessfully applied patch\033[0m", apply_file)
|
||||
break
|
||||
|
||||
print("\n\n===========================================\n\n")
|
||||
@ -162,12 +167,15 @@ if fail_count > 0:
|
||||
print(file)
|
||||
|
||||
# setup remote url
|
||||
repo_url = input("Please enter your remote repository URL (default: '{}'): ".format(default_repo_url)) or default_repo_url
|
||||
subprocess.run(["git", "remote", "set-url", "origin", repo_url], cwd = main_repo_path)
|
||||
repo_url = input("Please enter your remote repository URL (default: '{}'): ".format(
|
||||
default_repo_url)) or default_repo_url
|
||||
subprocess.run(["git", "remote", "set-url", "origin",
|
||||
repo_url], cwd=main_repo_path)
|
||||
|
||||
# setup commit message
|
||||
commit_msg = input("Please enter your commit message (default: 'Apply patches'): ") or "Apply patches"
|
||||
subprocess.run(["git", "commit", "-a" ,"-m", commit_msg], cwd=main_repo_path)
|
||||
commit_msg = input(
|
||||
"Please enter your commit message (default: 'Apply patches'): ") or "Apply patches"
|
||||
subprocess.run(["git", "commit", "-a", "-m", commit_msg], cwd=main_repo_path)
|
||||
|
||||
# confirm push
|
||||
confirm = input("Are you sure you want to push to the repository ([Y]/N)? ")
|
||||
|
Loading…
x
Reference in New Issue
Block a user