add logging structure

This commit is contained in:
2023-02-17 15:18:10 +01:00
parent 514670e897
commit b78396e8e5
5 changed files with 157 additions and 29 deletions
+21 -22
View File
@@ -1,7 +1,7 @@
#include <stm32f1xx_hal.h>
#include "logging.hpp"
#include "spi.hpp"
#include "uart_handler.hpp"
// STM32VL-Discovery green led - PC9
#define BTN_PORT GPIOA
@@ -11,12 +11,6 @@
#define BTN_PIN GPIO_PIN_0
#define LED_PORT_CLK_ENABLE __HAL_RCC_GPIOC_CLK_ENABLE
constexpr auto UART_PORT = GPIOA_BASE;
#define UARTPORT GPIOA
#define UARTTX_PIN GPIO_PIN_9
#define UARTRX_PIN GPIO_PIN_10
#define LoRa_RESET_Pin GPIO_PIN_3
#define LoRa_RESET_GPIO_Port GPIOA
#define LoRa_CS_Pin GPIO_PIN_4
@@ -73,19 +67,17 @@ extern "C" {
#include <stdio.h>
}
using uart_interface =
uart_handler<UARTTX_PIN, UARTRX_PIN, UART_PORT, USART1_BASE>;
int main(void) {
HAL_Init();
HAL_SYSTICK_Config(1);
initGPIO();
if (!uart_interface::init()) {
if (!log::init<uart_logger>()) {
// toggle status led or something
}
uart_interface::write("UART Initialized.");
log::set_loglevel(LogLevel::DEBUG);
log::info("logging Initialized");
log::info("running PentaTrack v0.1.3");
if (!MX_SPI1_Init()) {
// toggle status led or something
@@ -95,28 +87,35 @@ int main(void) {
HAL_GPIO_WritePin(LoRa_RESET_GPIO_Port, LoRa_RESET_Pin, GPIO_PIN_SET);
HAL_Delay(10);
uart_interface::write("SPI1 Initialized.");
uart_interface::write("Initialization done.");
log::debug("SPI1 Initialized.");
log::debug("Initialization done.");
char OP_Mode = 0x01;
char buff = 0x7F & OP_Mode;
char res = 0;
HAL_GPIO_WritePin(LoRa_CS_GPIO_Port, LoRa_CS_Pin, GPIO_PIN_RESET);
auto result = HAL_SPI_Transmit(&hspi1, (uint8_t *)&buff, 1, 100);
[[maybe_unused]] auto result =
HAL_SPI_Transmit(&hspi1, (uint8_t *)&buff, 1, 100);
HAL_SPI_Receive(&hspi1, (uint8_t *)&res, 1, 100);
HAL_GPIO_WritePin(LoRa_CS_GPIO_Port, LoRa_CS_Pin, GPIO_PIN_SET);
RF95_Init();
// RF95_Init();
int i = 0;
while (1) {
RF95_setModeRx_Continuous();
// RF95_setModeRx_Continuous();
HAL_GPIO_WritePin(LED_PORT, LED1_PIN, GPIO_PIN_RESET);
RF95_receive(LoRa_buff);
HAL_GPIO_WritePin(LED_PORT, LED2_PIN, GPIO_PIN_RESET);
// RF95_receive(LoRa_buff);
HAL_Delay(500);
HAL_GPIO_WritePin(LED_PORT, LED1_PIN, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED_PORT, LED2_PIN, GPIO_PIN_SET);
HAL_Delay(500);
std::string_view msg{reinterpret_cast<char *>(LoRa_buff)};
uart_interface::write("Received Message:");
uart_interface::write(msg);
// std::string_view msg{reinterpret_cast<char *>(LoRa_buff)};
// log::info("Received Message");
// log::debug("Received Message");
// log::debug(msg);
// std::string_view foo{"Das ist ein test"};
// strcpy((char *)LoRa_buff, foo.data());