WIP add super basic gps handler
This commit is contained in:
45
main.cpp
45
main.cpp
@@ -72,9 +72,13 @@ class cmd_holder {
|
||||
};
|
||||
|
||||
static bool updated_main_buf = false;
|
||||
static buffer<uint8_t, 512> main_buffer;
|
||||
static bool print_main_buf = false;
|
||||
static buffer<uint8_t, 512> main_buffer{};
|
||||
static gps_data gps;
|
||||
|
||||
void print_buf(void) { main_buffer.print(); }
|
||||
void print_gps(void) { gps.print(); }
|
||||
void print_buf_toggle(void) { print_main_buf = !print_main_buf; }
|
||||
|
||||
class cmd_handler {
|
||||
public:
|
||||
@@ -135,12 +139,15 @@ class cmd_handler {
|
||||
void print_help_() const { commands.print_help(); }
|
||||
|
||||
private:
|
||||
static constexpr cmd_holder<6> commands{
|
||||
static constexpr cmd_holder<8> commands{
|
||||
std::make_tuple("ver", "Prints current version.", &print_version),
|
||||
std::make_tuple("error", "Set LogLevel to Error.", &loglevel_error),
|
||||
std::make_tuple("info", "Set LogLevel to Info.", &loglevel_info),
|
||||
std::make_tuple("debug", "Set LogLevel to Debug.", &loglevel_debug),
|
||||
std::make_tuple("buf", "Prints gps uart buffer", &print_buf),
|
||||
std::make_tuple("gps", "Prints captured gps data", &print_gps),
|
||||
std::make_tuple("buf", "Prints uart2 buffer", &print_buf),
|
||||
std::make_tuple("buft", "toggles continous printing of uart2 buffer",
|
||||
&print_buf_toggle),
|
||||
std::make_tuple("help", "Prints available commands", &print_help)};
|
||||
|
||||
array_t symbols;
|
||||
@@ -178,7 +185,6 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
|
||||
if (value == '\r') {
|
||||
cmd_handler::get().queue_execution();
|
||||
HAL_GPIO_TogglePin(LED_PORT, LED2_PIN);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -195,7 +201,6 @@ void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) {
|
||||
|
||||
HAL_GPIO_WritePin(LED_PORT, LED1_PIN, GPIO_PIN_SET);
|
||||
if (main_buffer.copy_from(gps_interface::new_rx_buf, Size)) {
|
||||
log::debug("Copied to main buff");
|
||||
updated_main_buf = true;
|
||||
}
|
||||
HAL_GPIO_WritePin(LED_PORT, LED1_PIN, GPIO_PIN_RESET);
|
||||
@@ -282,6 +287,11 @@ int main(void) {
|
||||
if (!MX_SPI1_Init()) {
|
||||
// toggle status led or something
|
||||
}
|
||||
HAL_GPIO_WritePin(LoRa_CS_GPIO_Port, LoRa_CS_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(LoRa_RESET_GPIO_Port, LoRa_RESET_Pin, GPIO_PIN_SET);
|
||||
HAL_Delay(10);
|
||||
|
||||
log::debug("SPI1 Initialized.");
|
||||
|
||||
if (!gps_interface::init()) {
|
||||
log::error("UART2 Initialization failed, needed for GPS");
|
||||
@@ -289,11 +299,6 @@ int main(void) {
|
||||
log::debug("Uart2 Initialized");
|
||||
}
|
||||
|
||||
HAL_GPIO_WritePin(LoRa_CS_GPIO_Port, LoRa_CS_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(LoRa_RESET_GPIO_Port, LoRa_RESET_Pin, GPIO_PIN_SET);
|
||||
HAL_Delay(1000);
|
||||
|
||||
log::debug("SPI1 Initialized.");
|
||||
log::debug("Initialization done.");
|
||||
|
||||
char OP_Mode = 0x01;
|
||||
@@ -308,6 +313,8 @@ int main(void) {
|
||||
|
||||
// RF95_Init();
|
||||
|
||||
HAL_GPIO_WritePin(LED_PORT, LED2_PIN, GPIO_PIN_RESET);
|
||||
|
||||
while (1) {
|
||||
cmd_handler::get().run();
|
||||
|
||||
@@ -317,12 +324,20 @@ int main(void) {
|
||||
// RF95_receive(LoRa_buff);
|
||||
// HAL_Delay(100);
|
||||
// HAL_GPIO_WritePin(LED_PORT, LED1_PIN, GPIO_PIN_SET);
|
||||
HAL_Delay(100);
|
||||
// HAL_Delay(100);
|
||||
|
||||
// if (updated_main_buf) {
|
||||
// log::debug("Printing main buf");
|
||||
// updated_main_buf = !main_buffer.print();
|
||||
// }
|
||||
if (gps.is_valid()) {
|
||||
HAL_GPIO_WritePin(LED_PORT, LED2_PIN, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
if (updated_main_buf) {
|
||||
updated_main_buf = false;
|
||||
gps.extract_gps_data(main_buffer);
|
||||
|
||||
if (print_main_buf) {
|
||||
updated_main_buf = !main_buffer.print();
|
||||
}
|
||||
}
|
||||
|
||||
// std::string_view msg{reinterpret_cast<char *>(LoRa_buff)};
|
||||
// log::info("Received Message");
|
||||
|
||||
Reference in New Issue
Block a user