- board_control successfully sends motor commands to board_motorctl - board_motorctl receives and applies motor commands note: control pcb currently switches to HTTP mode after startup for testing with data from ui - partially commented in code that has to be reworked - control: send commands via uart instead of to motor objects - board motorctl handled motor: add timeout when no target data received (e.g. control pcb offline / uart bugged) - board motorctl uart: receive motorCommands_t struct and apply data to target state of handled motors - types: fix issue with global motorstateStr variable
69 lines
1.7 KiB
C++
69 lines
1.7 KiB
C++
#pragma once
|
|
extern "C"
|
|
{
|
|
#include <stdio.h>
|
|
#include <esp_system.h>
|
|
#include <esp_event.h>
|
|
#include <nvs_flash.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "driver/gpio.h"
|
|
#include "esp_log.h"
|
|
#include "sdkconfig.h"
|
|
#include <string.h>
|
|
|
|
#include "freertos/queue.h"
|
|
#include "driver/uart.h"
|
|
}
|
|
#include "types.hpp"
|
|
|
|
//struct for testing uart
|
|
typedef struct {
|
|
uint32_t timestamp;
|
|
int id;
|
|
float value;
|
|
} uartData_test_t;
|
|
|
|
|
|
//unnecessary, using commands struct directly
|
|
typedef struct {
|
|
uint32_t timestamp;
|
|
motorCommands_t commands;
|
|
} uartData_motorCommands_t;
|
|
|
|
|
|
//===== uart_init =====
|
|
//should be run once at startup
|
|
void uart_init(void);
|
|
|
|
|
|
//============================
|
|
//====== uart_sendStruct =====
|
|
//============================
|
|
//send and struct via uart
|
|
template <typename T> void uart_sendStruct(T dataStruct) {
|
|
static const char * TAG = "uart-common";
|
|
//TODO check if initialized?
|
|
uint8_t dataSerial[sizeof(T)];
|
|
memcpy(dataSerial, &dataStruct, sizeof(T));
|
|
uart_write_bytes(UART_NUM_1, (const char *)dataSerial, sizeof(T));
|
|
ESP_LOGW(TAG, "sent data struct with len %d", sizeof(T));
|
|
//ESP_LOGW(TAG, "sent DATA: timestamp=%d, id=%d, value=%.1f", data.timestamp, data.id, data.value);
|
|
}
|
|
|
|
|
|
|
|
//==============================
|
|
//====== serialData2Struct =====
|
|
//==============================
|
|
//convert serial data (byte array) to given struct and return it
|
|
//note check whether serial data length actually matches size of struct is necessary before
|
|
template <typename T> T serialData2Struct(uint8_t *dataSerial){
|
|
static const char * TAG = "uart-common";
|
|
T dataStruct;
|
|
memcpy(&dataStruct, dataSerial, sizeof(T));
|
|
ESP_LOGW(TAG, "converted serial data len=%d to struct", sizeof(T));
|
|
return dataStruct;
|
|
}
|
|
|