sync LAN support for network

This commit is contained in:
lyon1998 2023-12-28 00:14:01 +08:00
parent 07065ac3cf
commit 2a90b21d35
11 changed files with 304 additions and 6 deletions

View 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;
}
}

View 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));
}

View File

@ -24,7 +24,8 @@ void _network_WLAN_connect(PikaObj* self, char* ssid, char* key) {
pika_hal_WIFI_connect_config conncfg = {0};
strcpy(conncfg.ssid, ssid);
strcpy(conncfg.password, key);
_net_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;
}
@ -40,7 +41,8 @@ void _network_WLAN_connectWithBssid(PikaObj* self,
strcpy(conncfg.ssid, ssid);
strcpy(conncfg.password, key);
strcpy(conncfg.bssid, bssid);
_net_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) {
@ -102,7 +104,6 @@ PikaObj* _network_WLAN_scan(PikaObj* self) {
return scan_list;
}
void _network_WLAN_config(PikaObj* self, PikaDict* kwargs) {
pika_dev* hal_net = _NET_OBJ_2DEV(self);
if (hal_net == NULL) {

View File

@ -0,0 +1 @@
#include "_network_common.h"

View 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

View 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;
}
}

View 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));
}

View File

@ -0,0 +1 @@
#include "_network_common.h"

View 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

View File

@ -612,6 +612,19 @@ char* Lexer_getTokenStream(Args* outBuffs, char* sStmt) {
*/
if (('>' == c0) || ('<' == c0) || ('*' == c0) || ('/' == c0)) {
if (c0 == c1) {
/* >>=, <<=, **=, //= */
if ('=' == c2) {
char sContent[4] = {0};
sContent[0] = c0;
sContent[1] = c1;
sContent[2] = '=';
aTokenStream = Lexer_setSymbel(aTokenStream, sStmt, i,
&iSymbolStartIndex);
aTokenStream = Lexer_setToken(aTokenStream,
TOKEN_operator, sContent);
i = i + 2;
continue;
}
char content[3] = {0};
content[0] = c0;
content[1] = c1;
@ -624,11 +637,11 @@ char* Lexer_getTokenStream(Args* outBuffs, char* sStmt) {
}
}
/*
>=, <=, *=, /=, +=, -=, !=, ==, %=
>=, <=, *=, /=, +=, -=, !=, ==, %=, |=, ^=, &=
*/
if (('>' == c0) || ('<' == c0) || ('*' == c0) || ('/' == c0) ||
('+' == c0) || ('-' == c0) || ('!' == c0) || ('=' == c0) ||
('%' == c0) || ('^' == c0)) {
('%' == c0) || ('|' == c0) || ('&' == c0) || ('^' == c0)) {
if ('=' == c1) {
char content[3] = {0};
content[0] = c0;

View File

@ -2,4 +2,4 @@
#define PIKA_VERSION_MINOR 13
#define PIKA_VERSION_MICRO 1
#define PIKA_EDIT_TIME "2023/12/27 22:37:14"
#define PIKA_EDIT_TIME "2023/12/28 00:13:54"