[PHY] Added direct reception support

This commit is contained in:
jgromes 2021-06-14 20:59:38 +02:00
parent 5c0b4dbb10
commit 7690298d25
3 changed files with 136 additions and 29 deletions

View file

@ -140,6 +140,9 @@ invertIQ KEYWORD2
setOokThresholdType KEYWORD2 setOokThresholdType KEYWORD2
setOokPeakThresholdDecrement KEYWORD2 setOokPeakThresholdDecrement KEYWORD2
setOokFixedOrFloorThreshold KEYWORD2 setOokFixedOrFloorThreshold KEYWORD2
setDirectSyncWord KEYWORD2
setDirectAction KEYWORD2
readBit KEYWORD2
# RF69-specific # RF69-specific
setAESKey KEYWORD2 setAESKey KEYWORD2

View file

@ -3,6 +3,8 @@
PhysicalLayer::PhysicalLayer(float freqStep, size_t maxPacketLength) { PhysicalLayer::PhysicalLayer(float freqStep, size_t maxPacketLength) {
_freqStep = freqStep; _freqStep = freqStep;
_maxPacketLength = maxPacketLength; _maxPacketLength = maxPacketLength;
_bufferBitPos = 0;
_bufferWritePos = 0;
} }
int16_t PhysicalLayer::transmit(__FlashStringHelper* fstr, uint8_t addr) { int16_t PhysicalLayer::transmit(__FlashStringHelper* fstr, uint8_t addr) {
@ -181,3 +183,53 @@ int16_t PhysicalLayer::startDirect() {
state = setFrequencyDeviation(-1); state = setFrequencyDeviation(-1);
return(state); return(state);
} }
int16_t PhysicalLayer::available() {
return(_bufferWritePos);
}
uint8_t PhysicalLayer::read() {
_gotSync = false;
_syncBuffer = 0;
_bufferWritePos--;
return(_buffer[_bufferReadPos++]);
}
int16_t PhysicalLayer::setDirectSyncWord(uint32_t syncWord, uint8_t len) {
if((len > 32) || (len == 0)) {
return(ERR_INVALID_SYNC_WORD);
}
_directSyncWordMask = 0xFFFFFFFF >> (32 - len);
_directSyncWord = syncWord;
return(ERR_NONE);
}
void PhysicalLayer::updateDirectBuffer(uint8_t bit) {
// check sync word
if(!_gotSync) {
_syncBuffer <<= 1;
_syncBuffer |= bit;
if((_syncBuffer & _directSyncWordMask) == _directSyncWord) {
_gotSync = true;
_bufferWritePos = 0;
_bufferReadPos = 0;
_bufferBitPos = 0;
}
} else {
// save the bit
if(bit) {
_buffer[_bufferWritePos] |= 0x01 << _bufferBitPos;
} else {
_buffer[_bufferWritePos] &= ~(0x01 << _bufferBitPos);
}
_bufferBitPos++;
// check complete byte
if(_bufferBitPos == 8) {
_buffer[_bufferWritePos] = Module::flipBits(_buffer[_bufferWritePos]);
_bufferWritePos++;
_bufferBitPos = 0;
}
}
}

View file

@ -2,6 +2,7 @@
#define _RADIOLIB_PHYSICAL_LAYER_H #define _RADIOLIB_PHYSICAL_LAYER_H
#include "../../TypeDef.h" #include "../../TypeDef.h"
#include "../../Module.h"
/*! /*!
\class PhysicalLayer \class PhysicalLayer
@ -20,7 +21,7 @@ class PhysicalLayer {
\param freqStep Frequency step of the synthesizer in Hz. \param freqStep Frequency step of the synthesizer in Hz.
\param maxPacketLength Maximum length of packet that can be received by the module- \param maxPacketLength Maximum length of packet that can be received by the module.
*/ */
PhysicalLayer(float freqStep, size_t maxPacketLength); PhysicalLayer(float freqStep, size_t maxPacketLength);
@ -258,11 +259,62 @@ class PhysicalLayer {
*/ */
int16_t startDirect(); int16_t startDirect();
/*!
\brief Set sync word to be used to determine start of packet in direct reception mode.
\param syncWord Sync word bits.
\param len Sync word length in bits.
\returns \ref status_codes
*/
int16_t setDirectSyncWord(uint32_t syncWord, uint8_t len);
/*!
\brief Set interrupt service routine function to call when data bit is receveid in direct mode. Must be implemented in module class.
\param func Pointer to interrupt service routine.
*/
virtual void setDirectAction(void (*func)(void)) = 0;
/*!
\brief Function to read and process data bit in direct reception mode. Must be implemented in module class.
\param pin Pin on which to read.
*/
virtual void readBit(uint8_t pin) = 0;
/*!
\brief Get the number of direct mode bytes currently available in buffer.
\returns Number of available bytes.
*/
int16_t available();
/*!
\brief Get data from direct mode buffer.
\returns Byte from direct mode buffer.
*/
uint8_t read();
protected:
void updateDirectBuffer(uint8_t bit);
#ifndef RADIOLIB_GODMODE #ifndef RADIOLIB_GODMODE
private: private:
#endif #endif
float _freqStep; float _freqStep;
size_t _maxPacketLength; size_t _maxPacketLength;
uint8_t _bufferBitPos;
uint8_t _bufferWritePos;
uint8_t _bufferReadPos;
uint8_t _buffer[RADIOLIB_STATIC_ARRAY_SIZE];
uint32_t _syncBuffer;
uint32_t _directSyncWord;
uint32_t _directSyncWordMask;
bool _gotSync;
}; };
#endif #endif