Files
ip2-wireless-mcu-code/main/mcu-code.cpp
T
Nanokloon a9353e5c10
Build / build (push) Failing after 10m33s
v0.0.1
2026-09-29 21:03:15 +02:00

76 lines
2.0 KiB
C++

#include <cstring>
#include "peripherals/uart_serial.h"
#include "peripherals/usb_serial.h"
#include "peripherals/wireless_comms.h"
///
/// So i lost all the code from the previous version of this due to messing with git.
/// I only have a binary file to flash onto the esp for that
/// so this is my attempt at reimplementation asap
///
/// Nicholas - 23/08/2026 @ 21:36
///
const char *test = "amai zeg\n";
#define NODE_NUMBER 1
#define TOTAL_NUMBER_OF_NODES 4
// testing if the release packaging works
uint8_t node_mac[ESP_NOW_ETH_ALEN] = {0xDE, 0xD5, 0xEC, 0x00, 0x00, 0x02};
uint8_t peer_mac[ESP_NOW_ETH_ALEN] = {0xDE, 0xD5, 0xEC, 0x00, 0x00, 0x01};
uint8_t peer_list[TOTAL_NUMBER_OF_NODES][ESP_NOW_ETH_ALEN];
typedef struct communications {
uart_serial uart;
wireless_comms *wireless;
} communications;
void main_task(void *pvParameter) {
auto comms = reinterpret_cast<communications *>(pvParameter);
uart_serial uart = comms->uart;
char data;
while (true) {
if (usb_serial::read_byte(&data)) {
wireless_comms::send_byte(data);
uart.write_byte(&data);
}
if (uart.read_byte(&data)) {
ESP_LOGI("uart", "received data");
wireless_comms::send_byte(data);
usb_serial::write_byte(&data);
}
}
}
extern "C" void app_main(void) {
esp_log_level_set("*", ESP_LOG_NONE);
usb_serial::init();
uart_serial uart(UART_NUM_0, GPIO_NUM_18, GPIO_NUM_19, 9600);
wireless_comms wireless;
//usb_serial::write(test,strlen(test));
communications comms = {.uart = uart, .wireless = &wireless};
/*
uint8_t peer_gen[ESP_NOW_ETH_ALEN] = {0xDE, 0xD5, 0xEC, 0x00, 0x00, 0x00};
for(int i=2;i<TOTAL_NUMBER_OF_NODES;i++) {
peer_gen[ESP_NOW_ETH_ALEN-1] = i;
memcpy(peer_list[i],peer_gen,ESP_NOW_ETH_ALEN);
test_comms.add_peer(peer_gen);
}*/
wireless_comms::add_peer(peer_mac);
//test_comms.add_peer(peer_mac);
wireless.create_rtos_task(uart);
wireless_comms::send_byte('e');
const char testchar = 'e';
uart.write_byte(&testchar);
xTaskCreate(main_task, "main_task", 4096, &comms, 5,NULL);
}