added experemental PPPoS

This commit is contained in:
Bogdan Pilyugin 2025-02-17 18:47:04 +02:00
parent 490fd3bfa4
commit 915e6aa7c5
6 changed files with 130 additions and 8 deletions

View File

@ -25,6 +25,7 @@ idf_component_register(
"src/MQTT.c"
"src/CronTimers.c"
"src/SerialPort.c"
src/PPPoS.c
src/sdcard.c
src/FileBlockHandler.c
src/OTA.c

View File

@ -54,6 +54,9 @@ typedef int mqtt_app_err_t;
#define MQTT1 0
#define MQTT2 1
#if CONFIG_WEBGUIAPP_MQTT_ENABLE
typedef struct
{
char topic[CONFIG_WEBGUIAPP_MQTT_MAX_TOPIC_LENGTH];
@ -86,4 +89,6 @@ void SystemDataHandler(char *data, uint32_t len, int idx);
mqtt_app_err_t PublicTestMQTT(int idx);
esp_err_t ExternalServiceMQTTSend(char *servname, char *data, int len, int idx);
#endif
#endif /* MAIN_INCLUDE_MQTT_H_ */

View File

@ -30,7 +30,7 @@
#define REAST_API_DEBUG_MODE 0
#define EXPECTED_MAX_DATA_SIZE (4096 * 2)
#define EXPECTED_MAX_DATA_SIZE (4096 * 1)
#define VAR_MAX_NAME_LENGTH (32)
#define VAR_MAX_VALUE_LENGTH (EXPECTED_MAX_DATA_SIZE - 512)
@ -112,6 +112,7 @@ typedef struct
}UART_DATA_SEND_STRUCT;
void InitSerialPort(void);
void InitPPPSerial();
void InitSysSDCard();
esp_err_t TransmitSerialPort(char *data, int ln);

100
src/PPPoS.c Normal file
View File

@ -0,0 +1,100 @@
/*
* PPPoS.c
*
* Created on: Feb 10, 2025
* Author: bogd
*/
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include "freertos/projdefs.h"
#include "lwip/opt.h"
#include "lwip/sys.h"
#include "lwip/netif.h"
#include "netif/ppp/pppapi.h"
#include "netif/ppp/pppos.h"
#include "driver/uart.h"
#include "esp_netif.h"
#include <esp_log.h>
#define TAG "pppos"
// UART configuration
#define UART_PORT_NUM UART_NUM_2
#define UART_BAUD_RATE 115200
#define UART_RX_PIN 18
#define UART_TX_PIN 17
#define UART_BUF_SIZE 12000
// PPP configuration
static ppp_pcb *ppp;
static struct netif ppp_netif;
// Function to handle PPP link status changes
static void ppp_link_status_cb(ppp_pcb *pcb, int err_code, void *ctx)
{
struct netif *pppif = (struct netif *)ctx;
if (err_code == PPPERR_NONE)
{
ESP_LOGI(TAG, "PPP connection established");
ESP_LOGI(TAG, "~~~~~~~~~~~");
ESP_LOGI(TAG, "IP address: %s", ip4addr_ntoa(netif_ip4_addr(pppif)));
ESP_LOGI(TAG, "Gateway: %s", ip4addr_ntoa(netif_ip4_gw(pppif)));
ESP_LOGI(TAG, "Netmask: %s", ip4addr_ntoa(netif_ip4_netmask(pppif)));
ESP_LOGI(TAG, "~~~~~~~~~~~");
return;
}
ESP_LOGI(TAG, "PPP connection lost");
}
// Function to output PPP data over UART
static u32_t pppos_output_cb(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx)
{
uart_write_bytes(UART_PORT_NUM, (const char *)data, len);
return len;
}
static void uart_init()
{
uart_config_t uart_config = { .baud_rate = UART_BAUD_RATE, .data_bits = UART_DATA_8_BITS, .parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE };
uart_param_config(UART_PORT_NUM, &uart_config);
uart_set_pin(UART_PORT_NUM, UART_TX_PIN, UART_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
uart_driver_install(UART_PORT_NUM, UART_BUF_SIZE * 2, 0, 0, NULL, 0);
}
static uint8_t data[UART_BUF_SIZE];
static void pppos_task(void *arg)
{
while (1)
{
int len = uart_read_bytes(UART_PORT_NUM, data, UART_BUF_SIZE, pdMS_TO_TICKS(10));
if (len > 0)
{
pppos_input(ppp, data, len);
}
vTaskDelay(pdMS_TO_TICKS(10));
}
}
void InitPPPSerial()
{
uart_init();
// Create PPPoS interface
ppp = pppapi_pppos_create(&ppp_netif, pppos_output_cb, ppp_link_status_cb, &ppp_netif);
if (ppp == NULL)
{
ESP_LOGE(TAG, "Failed to create PPPoS interface");
return;
}
// Set PPP as the default interface
pppapi_set_default(ppp);
// Connect PPP
pppapi_connect(ppp, 0);
xTaskCreate(pppos_task, "pppos_task", 4096 , (void *)0, 7, NULL);
}

View File

@ -37,15 +37,22 @@
#include "webguiapp.h"
#include "driver/gpio.h"
#include "lwip/opt.h"
#include "lwip/sys.h"
#include "lwip/netif.h"
#include "netif/ppp/pppapi.h"
#include "netif/ppp/pppos.h"
#include "esp_netif.h"
#define TAG "serial_port"
#define UART_READ_TOUT (80) // 3.5T * 8 = 28 ticks, TOUT=3 -> ~24..33 ticks
#define PATTERN_CHR_NUM (3) /*!< Set the number of consecutive and identical characters received by receiver which defines a UART pattern*/
#define UART_TX_QUEUE_SIZE (5)
#define UART_RX_QUEUE_SIZE (5)
#define UART_DEBUG_MODE 0
#define UART_DEBUG_MODE 1
#ifdef CONFIG_WEBGUIAPP_UART_TRANSPORT_ENABLE
#if CONFIG_WEBGUIAPP_UART_TRANSPORT_ENABLE
QueueHandle_t UARTtxQueueHandle;
static StaticQueue_t xStaticUARTtxQueue;
@ -54,8 +61,10 @@ uint8_t UARTtxQueueStorageArea[UART_TX_QUEUE_SIZE * sizeof(UART_DATA_SEND_STRUCT
static QueueHandle_t uart_event_queue;
static char rxbuf[CONFIG_WEBGUIAPP_UART_BUF_SIZE];
esp_err_t TransmitSerialPort(char *data, int ln)
{
return ESP_OK;
UART_DATA_SEND_STRUCT DSS;
char *buf = malloc(ln);
if (!buf)
@ -108,7 +117,7 @@ void serial_RX_task(void *arg)
if (xQueueReceive(uart_event_queue, (void *)&event, portMAX_DELAY))
{
#if UART_DEBUG_MODE == 1
ESP_LOGI(TAG, "uart[%d] event:%d", CONFIG_UART_PORT_NUM, event.type);
ESP_LOGI(TAG, "uart[%d] event:%d", CONFIG_WEBGUIAPP_UART_PORT_NUM, event.type);
#endif
switch (event.type)
{
@ -127,7 +136,7 @@ void serial_RX_task(void *arg)
#if UART_DEBUG_MODE == 1
ESP_LOGI(TAG, "read of %d bytes: %s", buffered_size, rxbuf);
#endif
if (GetSysConf()->serialSettings.Flags.IsBridgeEnabled)
{
ExternalServiceMQTTSend(EXTERNAL_SERVICE_NAME, rxbuf, buffered_size, 0);
@ -135,6 +144,7 @@ void serial_RX_task(void *arg)
}
else
ReceiveHandlerAPI();
}
}
break;
@ -304,8 +314,11 @@ void InitSerialPort(void)
UARTtxQueueHandle = NULL;
UARTtxQueueHandle = xQueueCreateStatic(UART_TX_QUEUE_SIZE, sizeof(UART_DATA_SEND_STRUCT), UARTtxQueueStorageArea, &xStaticUARTtxQueue);
xTaskCreate(serial_TX_task, "serial_tx", 1024 * 2, (void *)0, 7, NULL);
xTaskCreate(serial_RX_task, "serial_rx", 1024 * 4, (void *)0, 12, NULL);
xTaskCreate(serial_TX_task, "serial_tx", 4096 * 2, (void *)0, 7, NULL);
xTaskCreate(serial_RX_task, "serial_rx", 4096 * 4, (void *)0, 12, NULL);
ESP_LOGI(TAG, "Serial port initialized on UART%d with baudrate %d", CONFIG_WEBGUIAPP_UART_PORT_NUM, GetSysConf()->serialSettings.BaudRate);
}

View File

@ -73,6 +73,7 @@ static void InitSysIO(void);
static void InitSysSPI(void);
static void InitSysI2C(void);
esp_err_t spi_device_polling_transmit_synchronized(spi_device_handle_t handle,
spi_transaction_t *trans_desc)
{
@ -178,7 +179,8 @@ esp_err_t WebGuiAppInit(void)
#if CONFIG_WEBGUIAPP_UART_TRANSPORT_ENABLE
InitSerialPort();
#endif
InitPPPSerial();
return ESP_OK;
}