Completed AT command library

This commit is contained in:
David Cermak
2021-04-19 11:28:53 +02:00
parent 26bde89834
commit 9e8ffbc760
20 changed files with 335 additions and 65 deletions

View File

@ -1,11 +1,19 @@
//
// Created by david on 2/11/21.
// 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.
#include "esp_err.h"
#include "esp_event.h"
const char * WIFI_EVENT = "WIFI_EVENT";
const char * IP_EVENT = "IP_EVENT";
@ -14,7 +22,6 @@ esp_err_t esp_event_handler_register(const char * event_base, int32_t event_id,
return ESP_OK;
}
esp_err_t esp_event_handler_unregister(const char * event_base, int32_t event_id, void* event_handler)
{
return ESP_OK;

View File

@ -1,16 +1,24 @@
//
// Created by david on 2/9/21.
// 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 MDNS_HOST_ESP_EVENT_H
#define MDNS_HOST_ESP_EVENT_H
#include <stdint.h>
#include "esp_netif_ip_addr.h"
#include "esp_netif.h"
#include "esp_err.h"
typedef void * esp_event_base_t;
typedef void * system_event_t;
extern const char * WIFI_EVENT;
@ -19,7 +27,6 @@ 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 */
@ -27,7 +34,6 @@ typedef struct {
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);

View File

@ -1,6 +1,15 @@
//
// Created by david on 2/9/21.
// 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 MDNS_HOST_ESP_EVENT_BASE_H
#define MDNS_HOST_ESP_EVENT_BASE_H
@ -14,4 +23,6 @@ typedef enum {
IP_EVENT_GOT_IP6
} mdns_used_event_t;
typedef void * esp_event_base_t;
#endif //MDNS_HOST_ESP_EVENT_BASE_H

View File

@ -1,16 +1,24 @@
//
// Created by david on 2/7/21.
//
#include<stdio.h>
// 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
#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>
// 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.
#include<stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <net/if.h>
#include "esp_netif.h"
#include "esp_err.h"
esp_netif_t *esp_netif_get_handle_from_ifkey(const char *if_key)
{
@ -31,19 +39,12 @@ esp_err_t esp_netif_dhcpc_get_status(esp_netif_t *esp_netif, esp_netif_dhcp_stat
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;

View File

@ -15,12 +15,14 @@
#define _HOST_ESP_NETIF_H_
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include "esp_netif_ip_addr.h"
#include "esp_err.h"
#include "esp_event.h"
#include "esp_event_base.h"
struct esp_netif_obj {};
typedef struct esp_netif_obj esp_netif_t;
typedef struct esp_netif_driver_base_s {
esp_err_t (*post_attach)(esp_netif_t *netif, void* h);
@ -34,8 +36,6 @@ struct esp_netif_driver_ifconfig {
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) */

View File

@ -1,3 +1,16 @@
//
// 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.
#pragma once
typedef int uart_port_t;

View File

@ -1,6 +1,15 @@
//
// 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
#include "esp_system_common_declares.h"
// 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.
typedef int esp_err_t;
@ -14,4 +23,3 @@ typedef int esp_err_t;
#define ESP_ERR_NOT_FOUND 0x105
#define ESP_ERR_NOT_SUPPORTED 0x106
#define ESP_ERR_TIMEOUT 0x107
#define ESP_ERR_INVALID_RESPONSE 0x

View File

@ -1,6 +1,15 @@
//
// Created by david on 2/10/21.
// 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 MDNS_HOST_ESP_LOG_H
#define MDNS_HOST_ESP_LOG_H

View File

@ -1,13 +0,0 @@
//
// 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

View File

@ -1,6 +1,15 @@
//
// Created by david on 2/17/21.
// 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 MDNS_HOST_ENDIAN_H
#define MDNS_HOST_ENDIAN_H

View File

@ -42,8 +42,12 @@ public:
return len;
}
}
if (len > 2 && data[0] == 0xf9 && data[2] == 0xef) { // Simple CMUX responder
data[2] = 0xff; // turn the request into a reply -> implements CMUX loopback
if (len > 2 && data[0] == 0xf9) { // Simple CMUX responder
// turn the request into a reply -> implements CMUX loopback
if (data[2] == 0x3f) // SABM command
data[2] = 0x73;
else if (data[2] == 0xef) // Generic request
data[2] = 0xff; // generic reply
}
loopback_data.resize(data_len + len);
memcpy(&loopback_data[data_len], data, len);
@ -82,7 +86,7 @@ TEST_CASE("DTE send/receive command", "[esp_modem]")
const auto test_command = "Test\n";
CHECK(term == nullptr);
dte->set_mode(esp_modem::modem_mode::COMMAND_MODE);
CHECK(dte->set_mode(esp_modem::modem_mode::COMMAND_MODE) == true);
auto ret = dte->command(test_command, [&](uint8_t *data, size_t len) {
std::string response((char*)data, len);