Files
firmware/src/platform/portduino/SimRadio.h

84 lines
2.3 KiB
C
Raw Normal View History

#pragma once
#include "MeshPacketQueue.h"
2023-01-21 14:34:29 +01:00
#include "RadioInterface.h"
#include "api/WiFiServerAPI.h"
#include <RadioLib.h>
class SimRadio : public RadioInterface
{
2023-01-21 14:34:29 +01:00
enum PendingISR { ISR_NONE = 0, ISR_RX, ISR_TX, TRANSMIT_DELAY_COMPLETED };
/**
* Debugging counts
*/
uint32_t rxBad = 0, rxGood = 0, txGood = 0;
2023-01-21 14:34:29 +01:00
MeshPacketQueue txQueue = MeshPacketQueue(MAX_TX_QUEUE);
public:
SimRadio();
/** MeshService needs this to find our active instance
*/
static SimRadio *instance;
2023-01-21 18:39:58 +01:00
virtual ErrorCode send(meshtastic_MeshPacket *p) override;
/** can we detect a LoRa preamble on the current channel? */
virtual bool isChannelActive();
/** are we actively receiving a packet (only called during receiving state)
* This method is only public to facilitate debugging. Do not call.
*/
virtual bool isActivelyReceiving();
/** Attempt to cancel a previously sent packet. Returns true if a packet was found we could cancel */
virtual bool cancelSending(NodeNum from, PacketId id) override;
2023-01-21 14:34:29 +01:00
/**
* Start waiting to receive a message
*
* External functions can call this method to wake the device from sleep.
*/
2023-01-21 18:39:58 +01:00
virtual void startReceive(meshtastic_MeshPacket *p);
2023-01-21 18:39:58 +01:00
meshtastic_QueueStatus getQueueStatus() override;
2023-01-21 14:34:29 +01:00
protected:
/// are _trying_ to receive a packet currently (note - we might just be waiting for one)
bool isReceiving = false;
2023-01-21 14:34:29 +01:00
private:
void setTransmitDelay();
/** random timer with certain min. and max. settings */
void startTransmitTimer(bool withDelay = true);
/** timer scaled to SNR of to be flooded packet */
void startTransmitTimerSNR(float snr);
void handleTransmitInterrupt();
2023-01-21 18:39:58 +01:00
void handleReceiveInterrupt(meshtastic_MeshPacket *p);
void onNotify(uint32_t notification);
// start an immediate transmit
2023-01-21 18:39:58 +01:00
virtual void startSend(meshtastic_MeshPacket *txp);
// derive packet length
2023-01-21 18:39:58 +01:00
size_t getPacketLength(meshtastic_MeshPacket *p);
2023-01-21 14:34:29 +01:00
int16_t readData(uint8_t *str, size_t len);
2023-01-21 14:34:29 +01:00
protected:
/** Could we send right now (i.e. either not actively receiving or transmitting)? */
virtual bool canSendImmediately();
/**
* If a send was in progress finish it and return the buffer to the pool */
void completeSending();
};
extern SimRadio *simRadio;