forked from xuos/xiuos
wifi adapter on XIUOS/aiit-arm32-board
it is OK
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
SRC_DIR :=wifi_demo
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -18,136 +18,179 @@
|
||||
* @date 2021.04.22
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <user_api.h>
|
||||
#include <xs_adapter_manager.h>
|
||||
#include <xs_adapter_at_wifi.h>
|
||||
#include <at_agent.h>
|
||||
#include <adapter.h>
|
||||
|
||||
void SendWiftMsg(int argc, char *argv[])
|
||||
{
|
||||
char wifi_msg[128];
|
||||
int len;
|
||||
if (argc >= 1) {
|
||||
memset(wifi_msg, 0, 128);
|
||||
strncpy(wifi_msg, argv[1], strlen(argv[1]));
|
||||
strncpy(wifi_msg, argv[1], (len = strlen(argv[1])));
|
||||
printf("SendWiftMsg(%s).\n", wifi_msg);
|
||||
}
|
||||
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
at_adapter->parent.done.NetAiitSend(&at_adapter->parent, wifi_msg, strlen(wifi_msg), true, 1000, 0, NULL, NULL, NULL);
|
||||
AdapterDeviceSend(adapter, wifi_msg, len);
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(0), SendWiftMsg, SendWiftMsg, SendWiftMsg);
|
||||
|
||||
void RecvWifiMsg()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
while (1) {
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
if (EOK == at_adapter->parent.done.NetAiitReceive(&at_adapter->parent, wifi_recv_msg, 128, 40000, true, NULL)) {
|
||||
if (EOK == AdapterDeviceRecv(adapter, wifi_recv_msg, 128)) {
|
||||
printf("wifi_recv_msg (%s)\n", wifi_recv_msg);
|
||||
} else {
|
||||
printf("wifi_recv_msg failed .\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), RecvWifiMsg, RecvWifiMsg, RecvWifiMsg);
|
||||
|
||||
void SetUpWifi()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
int baud_rate = BAUD_RATE_57600;
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
AdapterDeviceOpen(adapter);
|
||||
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
|
||||
if (EOK == AdapterDeviceSetUp(adapter)) {
|
||||
printf("SetUpWifi success \n");
|
||||
} else {
|
||||
printf("SetUpWifi failed \n");
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), SetUpWifi, SetUpWifi, SetUpWifi);
|
||||
|
||||
void SetDownWifi()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
if (EOK == AdapterDeviceSetDown(adapter)) {
|
||||
printf("SetDownWifi success \n");
|
||||
} else {
|
||||
printf("SetDownWifi failed \n");
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), SetDownWifi, SetDownWifi, SetDownWifi);
|
||||
|
||||
void SetAddrWifi()
|
||||
{
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
if(EOK != at_adapter->atdone.ATOperateAddr(at_adapter, IpTint("10.10.100.222"), IpTint("255.255.255.0"), IpTint("255.255.255.0")))
|
||||
printf("WifiSetAddr failed \n");
|
||||
}
|
||||
|
||||
void DhcpWifi()
|
||||
{
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
if(EOK == AdapterDeviceSetAddr(adapter, "192.168.66.253", "255.255.255.0", "192.168.66.1")){
|
||||
printf("SetAddrWifi success \n");
|
||||
} else {
|
||||
printf("SetAddrWifi failed \n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
if(EOK != at_adapter->atdone.ATOperateDHCP(at_adapter,1))
|
||||
printf("WifiDHCP failed \n");
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), SetAddrWifi, SetAddrWifi, SetAddrWifi);
|
||||
|
||||
void PingWifi()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
struct PingResult result;
|
||||
//www.baidu.com
|
||||
char *ip_str = "36.152.44.95";
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
at_adapter->atdone.ATPing(at_adapter, ip_str, &result);
|
||||
}
|
||||
|
||||
void SetUpWifi()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
struct PingResult result;
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
if (EOK == at_adapter->atdone.ATOperateUp(at_adapter)) {
|
||||
printf("WifiSetUp success (%s)\n", result.ip_addr.ipv4);
|
||||
if (EOK == AdapterDevicePing(adapter, ip_str)) {
|
||||
printf("PingWifi success \n");
|
||||
} else {
|
||||
printf("WifiSetUp failed \n");
|
||||
printf("PingWifi failed \n");
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), PingWifi, PingWifi, PingWifi);
|
||||
|
||||
void NetstatWifi()
|
||||
{
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
if (EOK != at_adapter->atdone.ATNetstat(at_adapter))
|
||||
printf("WifiNetstat failed \n");
|
||||
if (EOK == AdapterDeviceNetstat(adapter)) {
|
||||
printf("NetstatWifi success \n");
|
||||
} else {
|
||||
printf("NetstatWifi failed \n");
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), NetstatWifi, NetstatWifi, NetstatWifi);
|
||||
|
||||
int ConnectWifi()
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
|
||||
const char *ip = "192.168.66.33";
|
||||
const char *port = "12345";
|
||||
enum NetRoleType net_role = CLIENT;
|
||||
enum IpType ip_type = IPV4;
|
||||
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
if (EOK == AdapterDeviceConnect(adapter, net_role, ip, port, ip_type)) {
|
||||
printf("ConnectWifi success \n");
|
||||
} else {
|
||||
printf("ConnectWifi failed \n");
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), ConnectWifi, ConnectWifi, ConnectWifi);
|
||||
|
||||
void AtTestCmdWifi(int argc, char *argv[])
|
||||
{
|
||||
@@ -159,21 +202,22 @@ void AtTestCmdWifi(int argc, char *argv[])
|
||||
}
|
||||
|
||||
strcat(cmd,"\r");
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
// AdapterDeviceOpen(adapter);
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, NULL, "+++");
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "+++");
|
||||
UserTaskDelay(100);
|
||||
|
||||
ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, NULL, "a");
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "a");
|
||||
|
||||
UserTaskDelay(2500);
|
||||
|
||||
ATOrderSend(at_adapter->agent,REPLY_TIME_OUT, NULL,cmd);
|
||||
ATOrderSend(adapter->agent,REPLY_TIME_OUT, NULL,cmd);
|
||||
UserTaskDelay(2500);
|
||||
|
||||
ATOrderSend(at_adapter->agent,REPLY_TIME_OUT, NULL,"AT+Z\r");
|
||||
ATOrderSend(adapter->agent,REPLY_TIME_OUT, NULL,"AT+Z\r");
|
||||
UserTaskDelay(5000);
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(0), AtTestCmdWifi, AtTestCmdWifi, AtTestCmdWifi);
|
||||
|
||||
@@ -14,12 +14,10 @@
|
||||
#include <user_api.h>
|
||||
|
||||
extern int SensorFrameworkInit(void);
|
||||
extern int RegisterAdapterEthernet(void);
|
||||
extern int RegisterAdapterWifi(void);
|
||||
extern int RegisterAdapterZigbee(void);
|
||||
extern int RegisterAdapterNBIoT(void);
|
||||
extern int RegisterAdapterBluetooth(void);
|
||||
extern int LoraSx12xxSpiDeviceInit();
|
||||
extern int AdapterFrameworkInit(void);
|
||||
|
||||
extern int Adapter4GInit(void);
|
||||
extern int AdapterWifiInit(void);
|
||||
|
||||
extern int D124VoiceInit(void);
|
||||
extern int Hs300xTemperatureInit(void);
|
||||
@@ -54,6 +52,10 @@ static struct InitDesc framework[] =
|
||||
{ "perception_framework", SensorFrameworkInit },
|
||||
#endif
|
||||
|
||||
#ifdef SUPPORT_CONNECTION_FRAMEWORK
|
||||
{ "connection_framework", AdapterFrameworkInit },
|
||||
#endif
|
||||
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
|
||||
@@ -87,27 +89,11 @@ static struct InitDesc perception_desc[] =
|
||||
|
||||
static struct InitDesc connection_desc[] =
|
||||
{
|
||||
#ifdef CONNECTION_COMMUNICATION_ETHERNET
|
||||
{ "ethernet adpter", RegisterAdapterEthernet },
|
||||
#ifdef ADAPTER_4G
|
||||
{ "4G adpter", Adapter4GInit},
|
||||
#endif
|
||||
|
||||
#ifdef CONNECTION_COMMUNICATION_WIFI
|
||||
{ "wifi adpter", RegisterAdapterWifi },
|
||||
#endif
|
||||
|
||||
#ifdef CONNECTION_COMMUNICATION_LORA
|
||||
{ "lora adpter", LoraSx12xxSpiDeviceInit},
|
||||
#endif
|
||||
|
||||
#ifdef CONNECTION_COMMUNICATION_ZIGBEE
|
||||
{ "zigbee adpter", RegisterAdapterZigbee},
|
||||
#endif
|
||||
|
||||
#ifdef CONNECTION_COMMUNICATION_NB_IOT
|
||||
{ "NB-IoT adpter", RegisterAdapterNBIoT},
|
||||
#endif
|
||||
#ifdef CONNECTION_COMMUNICATION_BLUETOOTH
|
||||
{ "bluetooth adpter", RegisterAdapterBluetooth},
|
||||
#ifdef ADAPTER_WIFI
|
||||
{ "Wifi adpter", AdapterWifiInit},
|
||||
#endif
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
@@ -132,6 +118,8 @@ static int PerceptionFrameworkInit(struct InitDesc sub_desc[])
|
||||
printf("initialize perception_framework success.\n");
|
||||
AppInitDesc(perception_desc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +129,21 @@ static int PerceptionFrameworkInit(struct InitDesc sub_desc[])
|
||||
*/
|
||||
static int ConnectionFrameworkInit(struct InitDesc sub_desc[])
|
||||
{
|
||||
return AppInitDesc(connection_desc);
|
||||
int i = 0;
|
||||
int ret = 0;
|
||||
for ( i = 0; sub_desc[i].fn != NULL; i++ ) {
|
||||
if (0 == strncmp(sub_desc[i].fn_name, "connection_framework", strlen("connection_framework"))) {
|
||||
ret = sub_desc[i].fn();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == ret) {
|
||||
printf("initialize connection_framework success.\n");
|
||||
AppInitDesc(connection_desc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +156,7 @@ int FrameworkInit()
|
||||
PerceptionFrameworkInit(framework);
|
||||
#endif
|
||||
|
||||
#ifdef CONNECTION_ADAPTER
|
||||
#ifdef SUPPORT_CONNECTION_FRAMEWORK
|
||||
ConnectionFrameworkInit(framework);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user