You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

69 lines
1.4 KiB

#pragma once
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include <freertos/task.h>
#include "messages.pb.h"
#ifdef COMMS_SX127X
#include "sx127x_driver.h"
#else
#include "e32_driver.hh"
#endif
namespace ugv {
namespace comms {
namespace messages = uas::ugv::messages;
class CommsClass {
public:
static constexpr int MAX_PACKET_LEN = 128;
static constexpr TickType_t PACKET_RX_TIMEOUT = pdMS_TO_TICKS(200);
CommsClass();
void Init();
void Lock(TickType_t ticks_to_wait = pdMS_TO_TICKS(1000));
void Unlock();
int32_t ReadRssi();
uint8_t ReadLnaGain();
public:
SemaphoreHandle_t mutex;
messages::Location location;
messages::UGV_State ugv_state;
TickType_t last_packet_tick;
int32_t last_packet_rssi;
int8_t last_packet_snr;
private:
#ifdef COMMS_SX127X
sx127x_hndl lora;
#else
e32::E32_Driver lora;
int packet_len;
#endif
TaskHandle_t task_handle;
void RunTask();
#ifdef COMMS_SX127X
void HandlePacket(sx127x_rx_packet_t* packet);
#endif
void HandlePacket(const uint8_t* data, size_t size);
void HandleCommand(const messages::GroundCommand& command);
esp_err_t SendPacket(const char* data, size_t size);
esp_err_t SendPacket(const std::string& str);
esp_err_t SendPacket(const google::protobuf::MessageLite& message);
static void CommsTask(void* arg);
};
} // namespace comms
} // namespace ugv