uas-ugv/main/ugv_comms.hh

73 lines
1.5 KiB
C++
Raw Normal View History

2019-01-17 22:34:34 -08:00
#pragma once
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include <freertos/task.h>
#include "messages.pb.h"
2019-01-23 18:37:45 -08:00
#ifdef COMMS_SX127X
2019-01-17 22:34:34 -08:00
#include "sx127x_driver.h"
2019-01-23 18:37:45 -08:00
#else
#include "e32_driver.hh"
#endif
2019-01-17 22:34:34 -08:00
namespace ugv {
namespace comms {
2019-05-15 21:21:17 -07:00
namespace messages = ugv::messages;
namespace config = ugv::config;
2019-01-17 22:34:34 -08:00
class CommsClass {
public:
2019-04-25 20:51:29 -07:00
static constexpr int MAX_PACKET_LEN = 128;
2019-02-09 18:10:52 -08:00
static constexpr TickType_t PACKET_RX_TIMEOUT = pdMS_TO_TICKS(200);
2019-01-23 18:37:45 -08:00
2019-01-17 22:34:34 -08:00
CommsClass();
void Init();
void Lock(TickType_t ticks_to_wait = pdMS_TO_TICKS(1000));
void Unlock();
int32_t ReadRssi();
uint8_t ReadLnaGain();
public:
2019-05-15 21:21:17 -07:00
SemaphoreHandle_t mutex;
TickType_t last_packet_tick;
int32_t last_packet_rssi;
int8_t last_packet_snr;
messages::UGV_Status status;
messages::DriveHeadingData drive_heading;
2019-05-15 21:21:17 -07:00
messages::TargetLocation* new_target;
config::Config* new_config;
2019-01-17 22:34:34 -08:00
private:
2019-01-23 18:37:45 -08:00
#ifdef COMMS_SX127X
sx127x_hndl lora;
#else
e32::E32_Driver lora;
#endif
2019-01-17 22:34:34 -08:00
TaskHandle_t task_handle;
void RunTask();
2019-01-23 18:37:45 -08:00
#ifdef COMMS_SX127X
2019-01-17 22:34:34 -08:00
void HandlePacket(sx127x_rx_packet_t* packet);
2019-01-23 18:37:45 -08:00
#endif
void HandlePacket(const uint8_t* data, size_t size);
2019-01-17 22:34:34 -08:00
void HandleCommand(const messages::GroundCommand& command);
2019-05-09 10:23:27 -07:00
esp_err_t SendPacket(const uint8_t* data, size_t size);
2019-01-23 18:37:45 -08:00
esp_err_t SendPacket(const std::string& str);
esp_err_t SendPacket(const google::protobuf::MessageLite& message);
2019-01-17 22:34:34 -08:00
static void CommsTask(void* arg);
};
} // namespace comms
} // namespace ugv