mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-29 10:17:30 +02:00
Test: Initial version of modem tests
This commit is contained in:
16
esp_modem/test/host_test/CMakeLists.txt
Normal file
16
esp_modem/test/host_test/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS ../..)
|
||||
|
||||
set(COMPONENTS main)
|
||||
project(host_modem_test)
|
||||
|
||||
|
||||
idf_component_get_property(esp_modem esp_modem COMPONENT_LIB)
|
||||
target_compile_definitions(${esp_modem} PRIVATE "-DCONFIG_COMPILER_CXX_EXCEPTIONS")
|
||||
target_compile_definitions(${esp_modem} PRIVATE "-DCONFIG_IDF_TARGET_LINUX")
|
||||
target_link_options(${esp_modem} INTERFACE -fsanitize=address)
|
||||
#set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
|
||||
#set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
|
@ -0,0 +1,3 @@
|
||||
idf_component_register(SRCS esp_event_mock.c
|
||||
INCLUDE_DIRS include
|
||||
REQUIRES esp_system_protocols_linux)
|
@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by david on 2/11/21.
|
||||
//
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_event.h"
|
||||
|
||||
|
||||
const char * WIFI_EVENT = "WIFI_EVENT";
|
||||
const char * IP_EVENT = "IP_EVENT";
|
||||
|
||||
esp_err_t esp_event_handler_register(const char * event_base, int32_t event_id, void* event_handler, void* event_handler_arg)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_event_handler_unregister(const char * event_base, int32_t event_id, void* event_handler)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
//
|
||||
// Created by david on 2/9/21.
|
||||
//
|
||||
|
||||
#ifndef MDNS_HOST_ESP_EVENT_H
|
||||
#define MDNS_HOST_ESP_EVENT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_netif_ip_addr.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
|
||||
typedef void * esp_event_base_t;
|
||||
typedef void * system_event_t;
|
||||
|
||||
extern const char * WIFI_EVENT;
|
||||
extern const char * IP_EVENT;
|
||||
|
||||
#define ESP_EVENT_ANY_BASE NULL /**< register handler for any event base */
|
||||
#define ESP_EVENT_ANY_ID -1 /**< register handler for any event id */
|
||||
|
||||
|
||||
typedef struct {
|
||||
int if_index; /*!< Interface index for which the event is received (left for legacy compilation) */
|
||||
esp_netif_t *esp_netif; /*!< Pointer to corresponding esp-netif object */
|
||||
esp_netif_ip6_info_t ip6_info; /*!< IPv6 address of the interface */
|
||||
int ip_index; /*!< IPv6 address index */
|
||||
} ip_event_got_ip6_t;
|
||||
|
||||
|
||||
esp_err_t esp_event_handler_register(const char * event_base, int32_t event_id, void* event_handler, void* event_handler_arg);
|
||||
|
||||
esp_err_t esp_event_handler_unregister(const char * event_base, int32_t event_id, void* event_handler);
|
||||
|
||||
#endif //MDNS_HOST_ESP_EVENT_H
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by david on 2/9/21.
|
||||
//
|
||||
|
||||
#ifndef MDNS_HOST_ESP_EVENT_BASE_H
|
||||
#define MDNS_HOST_ESP_EVENT_BASE_H
|
||||
|
||||
typedef enum {
|
||||
WIFI_EVENT_STA_CONNECTED, /**< ESP32 station connected to AP */
|
||||
WIFI_EVENT_STA_DISCONNECTED, /**< ESP32 station disconnected from AP */
|
||||
WIFI_EVENT_AP_START, /**< ESP32 soft-AP start */
|
||||
WIFI_EVENT_AP_STOP, /**< ESP32 soft-AP stop */
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
IP_EVENT_GOT_IP6
|
||||
} mdns_used_event_t;
|
||||
|
||||
#endif //MDNS_HOST_ESP_EVENT_BASE_H
|
@ -0,0 +1,3 @@
|
||||
idf_component_register(SRCS esp_netif_linux.c
|
||||
INCLUDE_DIRS include
|
||||
REQUIRES esp_system_protocols_linux)
|
@ -0,0 +1,68 @@
|
||||
//
|
||||
// Created by david on 2/7/21.
|
||||
//
|
||||
#include<stdio.h>
|
||||
|
||||
#include "esp_netif.h"
|
||||
#include "esp_err.h"
|
||||
#include<string.h> //strlen
|
||||
#include<sys/socket.h>
|
||||
#include<arpa/inet.h> //inet_addr
|
||||
#include <sys/types.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <net/if.h>
|
||||
|
||||
esp_netif_t *esp_netif_get_handle_from_ifkey(const char *if_key)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
esp_err_t esp_netif_get_ip_info(esp_netif_t *esp_netif, esp_netif_ip_info_t *ip_info)
|
||||
{
|
||||
ESP_IPADDR4_INIT(&ip_info->ip, 1,2,3,4);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_netif_dhcpc_get_status(esp_netif_t *esp_netif, esp_netif_dhcp_status_t *status)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_netif_get_ip6_linklocal(esp_netif_t *esp_netif, esp_ip6_addr_t *if_ip6)
|
||||
{
|
||||
|
||||
struct ifaddrs *addrs, *tmp;
|
||||
getifaddrs(&addrs);
|
||||
tmp = addrs;
|
||||
|
||||
while (tmp)
|
||||
{
|
||||
// if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET)
|
||||
// {
|
||||
// struct sockaddr_in *pAddr = (struct sockaddr_in *)tmp->ifa_addr;
|
||||
// printf("%s: %s\n", tmp->ifa_name, inet_ntoa(pAddr->sin_addr));
|
||||
// } else
|
||||
|
||||
if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET6) {
|
||||
char addr[64];
|
||||
struct sockaddr_in6 *pAddr = (struct sockaddr_in6 *)tmp->ifa_addr;
|
||||
inet_ntop(AF_INET6, &pAddr->sin6_addr, addr, sizeof(addr) );
|
||||
printf("%s: %s\n", tmp->ifa_name, addr);
|
||||
inet6_addr_to_ip6addr(if_ip6, &pAddr->sin6_addr);
|
||||
}
|
||||
|
||||
tmp = tmp->ifa_next;
|
||||
}
|
||||
|
||||
freeifaddrs(addrs);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
int esp_netif_get_netif_impl_index(esp_netif_t *esp_netif)
|
||||
{
|
||||
char * ifname = "enp1s0";
|
||||
uint32_t interfaceIndex = if_nametoindex(ifname);
|
||||
printf("%s: %d\n", ifname, interfaceIndex);
|
||||
return interfaceIndex;
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _HOST_ESP_NETIF_H_
|
||||
#define _HOST_ESP_NETIF_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_netif_ip_addr.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_event.h"
|
||||
|
||||
struct esp_netif_obj {};
|
||||
|
||||
typedef struct esp_netif_driver_base_s {
|
||||
esp_err_t (*post_attach)(esp_netif_t *netif, void* h);
|
||||
esp_netif_t *netif;
|
||||
} esp_netif_driver_base_t;
|
||||
|
||||
struct esp_netif_driver_ifconfig {
|
||||
void* handle;
|
||||
esp_err_t (*transmit)(void *h, void *buffer, size_t len);
|
||||
esp_err_t (*transmit_wrap)(void *h, void *buffer, size_t len, void *netstack_buffer);
|
||||
void (*driver_free_rx_buffer)(void *h, void* buffer);
|
||||
};
|
||||
|
||||
typedef struct esp_netif_obj esp_netif_t;
|
||||
|
||||
/** @brief Status of DHCP client or DHCP server */
|
||||
typedef enum {
|
||||
ESP_NETIF_DHCP_INIT = 0, /**< DHCP client/server is in initial state (not yet started) */
|
||||
ESP_NETIF_DHCP_STARTED, /**< DHCP client/server has been started */
|
||||
ESP_NETIF_DHCP_STOPPED, /**< DHCP client/server has been stopped */
|
||||
ESP_NETIF_DHCP_STATUS_MAX
|
||||
} esp_netif_dhcp_status_t;
|
||||
|
||||
|
||||
esp_netif_t *esp_netif_get_handle_from_ifkey(const char *if_key);
|
||||
|
||||
esp_err_t esp_netif_get_ip_info(esp_netif_t *esp_netif, esp_netif_ip_info_t *ip_info);
|
||||
|
||||
esp_err_t esp_netif_dhcpc_get_status(esp_netif_t *esp_netif, esp_netif_dhcp_status_t *status);
|
||||
|
||||
esp_err_t esp_netif_get_ip6_linklocal(esp_netif_t *esp_netif, esp_ip6_addr_t *if_ip6);
|
||||
int esp_netif_get_netif_impl_index(esp_netif_t *esp_netif);
|
||||
|
||||
void esp_netif_action_connected(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
|
||||
void esp_netif_action_disconnected(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
|
||||
|
||||
#endif // _HOST_ESP_NETIF_H_
|
@ -0,0 +1,182 @@
|
||||
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_NETIF_IP_ADDR_H_
|
||||
#define _ESP_NETIF_IP_ADDR_H_
|
||||
|
||||
#include <endian.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
#define esp_netif_htonl(x) ((uint32_t)(x))
|
||||
#else
|
||||
#define esp_netif_htonl(x) ((((x) & (uint32_t)0x000000ffUL) << 24) | \
|
||||
(((x) & (uint32_t)0x0000ff00UL) << 8) | \
|
||||
(((x) & (uint32_t)0x00ff0000UL) >> 8) | \
|
||||
(((x) & (uint32_t)0xff000000UL) >> 24))
|
||||
#endif
|
||||
|
||||
#define esp_netif_ip4_makeu32(a,b,c,d) (((uint32_t)((a) & 0xff) << 24) | \
|
||||
((uint32_t)((b) & 0xff) << 16) | \
|
||||
((uint32_t)((c) & 0xff) << 8) | \
|
||||
(uint32_t)((d) & 0xff))
|
||||
|
||||
// Access address in 16-bit block
|
||||
#define ESP_IP6_ADDR_BLOCK1(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[0]) >> 16) & 0xffff))
|
||||
#define ESP_IP6_ADDR_BLOCK2(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[0])) & 0xffff))
|
||||
#define ESP_IP6_ADDR_BLOCK3(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[1]) >> 16) & 0xffff))
|
||||
#define ESP_IP6_ADDR_BLOCK4(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[1])) & 0xffff))
|
||||
#define ESP_IP6_ADDR_BLOCK5(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[2]) >> 16) & 0xffff))
|
||||
#define ESP_IP6_ADDR_BLOCK6(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[2])) & 0xffff))
|
||||
#define ESP_IP6_ADDR_BLOCK7(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[3]) >> 16) & 0xffff))
|
||||
#define ESP_IP6_ADDR_BLOCK8(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[3])) & 0xffff))
|
||||
|
||||
#define IPSTR "%d.%d.%d.%d"
|
||||
#define esp_ip4_addr_get_byte(ipaddr, idx) (((const uint8_t*)(&(ipaddr)->addr))[idx])
|
||||
#define esp_ip4_addr1(ipaddr) esp_ip4_addr_get_byte(ipaddr, 0)
|
||||
#define esp_ip4_addr2(ipaddr) esp_ip4_addr_get_byte(ipaddr, 1)
|
||||
#define esp_ip4_addr3(ipaddr) esp_ip4_addr_get_byte(ipaddr, 2)
|
||||
#define esp_ip4_addr4(ipaddr) esp_ip4_addr_get_byte(ipaddr, 3)
|
||||
|
||||
|
||||
#define esp_ip4_addr1_16(ipaddr) ((uint16_t)esp_ip4_addr1(ipaddr))
|
||||
#define esp_ip4_addr2_16(ipaddr) ((uint16_t)esp_ip4_addr2(ipaddr))
|
||||
#define esp_ip4_addr3_16(ipaddr) ((uint16_t)esp_ip4_addr3(ipaddr))
|
||||
#define esp_ip4_addr4_16(ipaddr) ((uint16_t)esp_ip4_addr4(ipaddr))
|
||||
|
||||
#define IP2STR(ipaddr) esp_ip4_addr1_16(ipaddr), \
|
||||
esp_ip4_addr2_16(ipaddr), \
|
||||
esp_ip4_addr3_16(ipaddr), \
|
||||
esp_ip4_addr4_16(ipaddr)
|
||||
|
||||
#define IPV6STR "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x"
|
||||
|
||||
#define IPV62STR(ipaddr) ESP_IP6_ADDR_BLOCK1(&(ipaddr)), \
|
||||
ESP_IP6_ADDR_BLOCK2(&(ipaddr)), \
|
||||
ESP_IP6_ADDR_BLOCK3(&(ipaddr)), \
|
||||
ESP_IP6_ADDR_BLOCK4(&(ipaddr)), \
|
||||
ESP_IP6_ADDR_BLOCK5(&(ipaddr)), \
|
||||
ESP_IP6_ADDR_BLOCK6(&(ipaddr)), \
|
||||
ESP_IP6_ADDR_BLOCK7(&(ipaddr)), \
|
||||
ESP_IP6_ADDR_BLOCK8(&(ipaddr))
|
||||
|
||||
#define ESP_IPADDR_TYPE_V4 0U
|
||||
#define ESP_IPADDR_TYPE_V6 6U
|
||||
#define ESP_IPADDR_TYPE_ANY 46U
|
||||
|
||||
#define ESP_IP4TOUINT32(a,b,c,d) (((uint32_t)((a) & 0xffU) << 24) | \
|
||||
((uint32_t)((b) & 0xffU) << 16) | \
|
||||
((uint32_t)((c) & 0xffU) << 8) | \
|
||||
(uint32_t)((d) & 0xffU))
|
||||
|
||||
#define ESP_IP4TOADDR(a,b,c,d) esp_netif_htonl(ESP_IP4TOUINT32(a, b, c, d))
|
||||
|
||||
// new definitions
|
||||
#define ESP_IPADDR4_INIT(ipaddr, a,b,c,d) (ipaddr)->addr = ESP_IP4TOADDR(a,b,c,d)
|
||||
#define ESP_IP6TOADDR(a, b, c, d) { { { { a, b, c, d } , 0 } }, ESP_IPADDR_TYPE_V6 }
|
||||
|
||||
// TODO: use esp-netif instead of lwip API
|
||||
#define ip_2_ip6(ipaddr) (&((ipaddr)->u_addr.ip6))
|
||||
#define ip_2_ip4(ipaddr) (&((ipaddr)->u_addr.ip4))
|
||||
#define IP_SET_TYPE_VAL(ipaddr, iptype) do { (ipaddr).type = (iptype); }while(0)
|
||||
#define IP_GET_TYPE(ipaddr) ((ipaddr)->type)
|
||||
#define IP_IS_V6_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == ESP_IPADDR_TYPE_V6)
|
||||
#define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
|
||||
#define ip6_addr_copy(dest, src) do{(dest).addr[0] = (src).addr[0]; \
|
||||
(dest).addr[1] = (src).addr[1]; \
|
||||
(dest).addr[2] = (src).addr[2]; \
|
||||
(dest).addr[3] = (src).addr[3];}while(0)
|
||||
|
||||
#define ip_addr_copy(dest, src) do{ IP_SET_TYPE_VAL(dest, IP_GET_TYPE(&src)); if(IP_IS_V6_VAL(src)){ \
|
||||
ip6_addr_copy(*ip_2_ip6(&(dest)), *ip_2_ip6(&(src))); }else{ \
|
||||
ip4_addr_copy(*ip_2_ip4(&(dest)), *ip_2_ip4(&(src))); }}while(0)
|
||||
|
||||
|
||||
#define IP_MULTICAST(a) IN_CLASSD(a)
|
||||
|
||||
#define ip6_addr_ismulticast(ip6addr) (((ip6addr)->addr[0] & htonl(0xff000000UL)) == htonl(0xff000000UL))
|
||||
#define IP6_NO_ZONE 0
|
||||
#define ip6_addr_clear_zone(ip6addr) ((ip6addr)->zone = IP6_NO_ZONE)
|
||||
|
||||
#define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) {(target_in6addr)->s6_addr32[0] = (source_ip6addr)->addr[0]; \
|
||||
(target_in6addr)->s6_addr32[1] = (source_ip6addr)->addr[1]; \
|
||||
(target_in6addr)->s6_addr32[2] = (source_ip6addr)->addr[2]; \
|
||||
(target_in6addr)->s6_addr32[3] = (source_ip6addr)->addr[3];}
|
||||
|
||||
#define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr) {(target_ip6addr)->addr[0] = (source_in6addr)->s6_addr32[0]; \
|
||||
(target_ip6addr)->addr[1] = (source_in6addr)->s6_addr32[1]; \
|
||||
(target_ip6addr)->addr[2] = (source_in6addr)->s6_addr32[2]; \
|
||||
(target_ip6addr)->addr[3] = (source_in6addr)->s6_addr32[3]; \
|
||||
ip6_addr_clear_zone(target_ip6addr);}
|
||||
|
||||
|
||||
struct esp_ip6_addr {
|
||||
uint32_t addr[4];
|
||||
uint8_t zone;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct esp_ip4_addr {
|
||||
uint32_t addr;
|
||||
};
|
||||
|
||||
typedef struct esp_ip4_addr esp_ip4_addr_t;
|
||||
|
||||
typedef struct esp_ip6_addr esp_ip6_addr_t;
|
||||
|
||||
typedef struct _ip_addr {
|
||||
union {
|
||||
esp_ip6_addr_t ip6;
|
||||
esp_ip4_addr_t ip4;
|
||||
} u_addr;
|
||||
uint8_t type;
|
||||
} esp_ip_addr_t;
|
||||
|
||||
typedef enum {
|
||||
ESP_IP6_ADDR_IS_UNKNOWN,
|
||||
ESP_IP6_ADDR_IS_GLOBAL,
|
||||
ESP_IP6_ADDR_IS_LINK_LOCAL,
|
||||
ESP_IP6_ADDR_IS_SITE_LOCAL,
|
||||
ESP_IP6_ADDR_IS_UNIQUE_LOCAL,
|
||||
ESP_IP6_ADDR_IS_IPV4_MAPPED_IPV6
|
||||
} esp_ip6_addr_type_t;
|
||||
|
||||
typedef struct {
|
||||
esp_ip4_addr_t ip; /**< Interface IPV4 address */
|
||||
esp_ip4_addr_t netmask; /**< Interface IPV4 netmask */
|
||||
esp_ip4_addr_t gw; /**< Interface IPV4 gateway address */
|
||||
} esp_netif_ip_info_t;
|
||||
|
||||
typedef struct {
|
||||
esp_ip6_addr_t ip; /**< Interface IPV6 address */
|
||||
} esp_netif_ip6_info_t;
|
||||
|
||||
/**
|
||||
* @brief Get the IPv6 address type
|
||||
*
|
||||
* @param[in] ip6_addr IPv6 type
|
||||
*
|
||||
* @return IPv6 type in form of enum esp_ip6_addr_type_t
|
||||
*/
|
||||
esp_ip6_addr_type_t esp_netif_ip6_get_addr_type(esp_ip6_addr_t* ip6_addr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_ESP_NETIF_IP_ADDR_H_
|
@ -0,0 +1,22 @@
|
||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
#ifndef _ESP_NETIF_PPP_H_
|
||||
#define _ESP_NETIF_PPP_H_
|
||||
|
||||
#define NETIF_PP_PHASE_OFFSET 0x100
|
||||
|
||||
|
||||
#endif //_ESP_NETIF_PPP_H_
|
@ -0,0 +1,2 @@
|
||||
idf_component_register(INCLUDE_DIRS include
|
||||
REQUIRES esp_netif_linux esp_event_mock)
|
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
typedef int uart_port_t;
|
||||
typedef int uart_word_length_t;
|
||||
typedef int uart_stop_bits_t;
|
||||
typedef int uart_parity_t;
|
@ -0,0 +1,17 @@
|
||||
|
||||
|
||||
#include "esp_system_common_declares.h"
|
||||
|
||||
typedef int esp_err_t;
|
||||
|
||||
#define ESP_FAIL -1
|
||||
#define ESP_OK 0
|
||||
|
||||
#define ESP_ERR_NO_MEM 0x101
|
||||
#define ESP_ERR_INVALID_ARG 0x102
|
||||
#define ESP_ERR_INVALID_STATE 0x103
|
||||
#define ESP_ERR_INVALID_SIZE 0x104
|
||||
#define ESP_ERR_NOT_FOUND 0x105
|
||||
#define ESP_ERR_NOT_SUPPORTED 0x106
|
||||
#define ESP_ERR_TIMEOUT 0x107
|
||||
#define ESP_ERR_INVALID_RESPONSE 0x
|
@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by david on 2/10/21.
|
||||
//
|
||||
|
||||
#ifndef MDNS_HOST_ESP_LOG_H
|
||||
#define MDNS_HOST_ESP_LOG_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define ESP_LOG_INFO 1
|
||||
#define ESP_LOG_BUFFER_HEXDUMP(...)
|
||||
|
||||
#define ESP_LOGE(TAG, ...)
|
||||
//printf(TAG); printf("ERROR: " __VA_ARGS__); printf("\n")
|
||||
#define ESP_LOGW(TAG, ...)
|
||||
//printf(TAG); printf("WARN: "__VA_ARGS__); printf("\n")
|
||||
#define ESP_LOGI(TAG, ...)
|
||||
//printf(TAG); printf("INFO: "__VA_ARGS__); printf("\n")
|
||||
#define ESP_LOGD(TAG, ...)
|
||||
//printf(TAG); printf("DEBUG: "__VA_ARGS__); printf("\n")
|
||||
|
||||
#endif //MDNS_HOST_ESP_LOG_H
|
@ -0,0 +1,13 @@
|
||||
//
|
||||
// Created by david on 2/17/21.
|
||||
//
|
||||
|
||||
#ifndef MDNS_HOST_ESP_SYSTEM_COMMON_DECLARES_H
|
||||
#define MDNS_HOST_ESP_SYSTEM_COMMON_DECLARES_H
|
||||
|
||||
struct esp_netif_obj;
|
||||
|
||||
typedef struct esp_netif_obj esp_netif_t;
|
||||
|
||||
|
||||
#endif //MDNS_HOST_ESP_SYSTEM_COMMON_DECLARES_H
|
@ -0,0 +1,10 @@
|
||||
//
|
||||
// Created by david on 2/17/21.
|
||||
//
|
||||
|
||||
#ifndef MDNS_HOST_ENDIAN_H
|
||||
#define MDNS_HOST_ENDIAN_H
|
||||
|
||||
#include_next "endian.h"
|
||||
|
||||
#endif //MDNS_HOST_ENDIAN_H
|
10
esp_modem/test/host_test/main/CMakeLists.txt
Normal file
10
esp_modem/test/host_test/main/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
idf_component_register(SRCS "test_modem.cpp"
|
||||
INCLUDE_DIRS "$ENV{IDF_PATH}/tools/catch"
|
||||
REQUIRES esp_modem)
|
||||
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(${COMPONENT_LIB} PRIVATE Threads::Threads)
|
||||
|
||||
target_compile_features(${COMPONENT_LIB} PRIVATE cxx_std_17)
|
||||
target_compile_definitions(${COMPONENT_LIB} PRIVATE "-DCONFIG_IDF_TARGET_LINUX")
|
145
esp_modem/test/host_test/main/test_modem.cpp
Normal file
145
esp_modem/test/host_test/main/test_modem.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
#define CATCH_CONFIG_MAIN // This tells the catch header to generate a main
|
||||
#include <memory>
|
||||
#include <future>
|
||||
#include "catch.hpp"
|
||||
#include "cxx_include/esp_modem_terminal.hpp"
|
||||
#include "cxx_include/esp_modem_api.hpp"
|
||||
|
||||
using namespace esp_modem;
|
||||
|
||||
class LoopbackTerm : public Terminal {
|
||||
public:
|
||||
explicit LoopbackTerm(): loopback_data(), data_len(0) {}
|
||||
|
||||
~LoopbackTerm() override = default;
|
||||
|
||||
void start() override {
|
||||
status = status_t::STARTED;
|
||||
}
|
||||
|
||||
void stop() override {
|
||||
status = status_t::STOPPED;
|
||||
}
|
||||
|
||||
int write(uint8_t *data, size_t len) override {
|
||||
if (len > 2 && (data[len-1] == '\r' || data[len-1] == '+') ) {
|
||||
std::string command((char*)data, len);
|
||||
std::string response;
|
||||
if (command == "ATE1\r" || command == "ATE0\r" || command == "+++") {
|
||||
response = "OK\r\n";
|
||||
} else if (command == "ATO\r") {
|
||||
response = "ERROR\r\n";
|
||||
} else if (command.find("ATD") != std::string::npos) {
|
||||
response = "CONNECT\r\n";
|
||||
} else if (command.find("AT") != std::string::npos) {
|
||||
response = "OK\r\n";
|
||||
}
|
||||
if (!response.empty()) {
|
||||
data_len = response.length();
|
||||
loopback_data.resize(data_len);
|
||||
memcpy(&loopback_data[0], &response[0], data_len);
|
||||
auto ret = std::async(on_data, data_len);
|
||||
return len;
|
||||
}
|
||||
}
|
||||
loopback_data.resize(data_len + len);
|
||||
memcpy(&loopback_data[data_len], data, len);
|
||||
data_len += len;
|
||||
auto ret = std::async(on_data, data_len);
|
||||
return len;
|
||||
}
|
||||
|
||||
int read(uint8_t *data, size_t len) override {
|
||||
size_t read_len = std::min(data_len, len);
|
||||
if (read_len) {
|
||||
memcpy(data, &loopback_data[0], len);
|
||||
loopback_data.erase(loopback_data.begin(), loopback_data.begin() + read_len);
|
||||
data_len -= len;
|
||||
}
|
||||
return read_len;
|
||||
}
|
||||
|
||||
void set_data_cb(std::function<bool(size_t len)> f) override {
|
||||
on_data = std::move(f);
|
||||
}
|
||||
|
||||
private:
|
||||
enum class status_t {
|
||||
STARTED,
|
||||
STOPPED
|
||||
};
|
||||
status_t status;
|
||||
signal_group signal;
|
||||
std::vector<uint8_t> loopback_data;
|
||||
size_t data_len;
|
||||
};
|
||||
|
||||
TEST_CASE("DTE send/receive command", "[esp_modem]")
|
||||
{
|
||||
auto term = std::make_unique<LoopbackTerm>();
|
||||
auto dte = std::make_unique<DTE>(std::move(term));
|
||||
|
||||
const auto test_command = "Test\n";
|
||||
CHECK(term == nullptr);
|
||||
|
||||
dte->set_mode(esp_modem::modem_mode::COMMAND_MODE);
|
||||
|
||||
auto ret = dte->command(test_command, [&](uint8_t *data, size_t len) {
|
||||
std::string response((char*)data, len);
|
||||
CHECK(response == test_command);
|
||||
return command_result::OK;
|
||||
}, 1000);
|
||||
CHECK(ret == command_result::OK);
|
||||
}
|
||||
|
||||
TEST_CASE("DCE commands", "[esp_modem]")
|
||||
{
|
||||
auto term = std::make_unique<LoopbackTerm>();
|
||||
auto dte = std::make_shared<DTE>(std::move(term));
|
||||
CHECK(term == nullptr);
|
||||
|
||||
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("APN");
|
||||
esp_netif_t netif{};
|
||||
auto dce = create_SIM7600_dce(&dce_config, dte, &netif);
|
||||
CHECK(dce != nullptr);
|
||||
|
||||
const auto test_command = "Test\n";
|
||||
auto ret = dce->command(test_command, [&](uint8_t *data, size_t len) {
|
||||
std::string response((char*)data, len);
|
||||
CHECK(response == test_command);
|
||||
return command_result::OK;
|
||||
}, 1000);
|
||||
CHECK(ret == command_result::OK);
|
||||
}
|
||||
|
||||
TEST_CASE("DCE AT commands", "[esp_modem]")
|
||||
{
|
||||
auto term = std::make_unique<LoopbackTerm>();
|
||||
auto dte = std::make_shared<DTE>(std::move(term));
|
||||
CHECK(term == nullptr);
|
||||
|
||||
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("APN");
|
||||
esp_netif_t netif{};
|
||||
auto dce = create_SIM7600_dce(&dce_config, dte, &netif);
|
||||
CHECK(dce != nullptr);
|
||||
|
||||
CHECK(dce->set_echo(false) == command_result::OK);
|
||||
CHECK(dce->set_echo(true) == command_result::OK);
|
||||
CHECK(dce->resume_data_mode() == command_result::FAIL);
|
||||
}
|
||||
|
||||
TEST_CASE("DCE modes", "[esp_modem]")
|
||||
{
|
||||
auto term = std::make_unique<LoopbackTerm>();
|
||||
auto dte = std::make_shared<DTE>(std::move(term));
|
||||
CHECK(term == nullptr);
|
||||
|
||||
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("APN");
|
||||
esp_netif_t netif{};
|
||||
auto dce = create_SIM7600_dce(&dce_config, dte, &netif);
|
||||
CHECK(dce != nullptr);
|
||||
|
||||
CHECK(dce->set_mode(esp_modem::modem_mode::COMMAND_MODE) == false);
|
||||
CHECK(dce->set_mode(esp_modem::modem_mode::DATA_MODE) == true);
|
||||
CHECK(dce->set_mode(esp_modem::modem_mode::COMMAND_MODE) == true);
|
||||
}
|
5
esp_modem/test/host_test/sdkconfig.defaults
Normal file
5
esp_modem/test/host_test/sdkconfig.defaults
Normal file
@ -0,0 +1,5 @@
|
||||
CONFIG_IDF_TARGET="linux"
|
||||
CONFIG_COMPILER_CXX_EXCEPTIONS=y
|
||||
CONFIG_COMPILER_CXX_RTTI=y
|
||||
CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE=0
|
||||
CONFIG_COMPILER_STACK_CHECK_NONE=y
|
Reference in New Issue
Block a user