kopia lustrzana https://github.com/jgromes/RadioLib
[LR2021] Add FLRC, OQPSK and BPSK commands
rodzic
217ab3c243
commit
fa4ca41bdb
|
|
@ -155,6 +155,23 @@ class LR2021: public PhysicalLayer, public LRxxxx {
|
|||
int16_t getFskRxStats(uint16_t* packetRx, uint16_t* packetCrcError, uint16_t* lenError, uint16_t* preambleDet, uint16_t* syncOk, uint16_t* syncFail, uint16_t* timeout);
|
||||
int16_t getFskPacketStatus(uint16_t* packetLen, float* rssiAvg, float* rssiSync, bool* addrMatchNode, bool* addrMatchBroadcast, float* lqi);
|
||||
|
||||
// OQPSK commands
|
||||
int16_t setOqpskParams(uint8_t mode, uint8_t rxBw, uint8_t payloadLen, uint16_t preambleLen, bool addrFilt, bool fcsManual);
|
||||
int16_t getOqpskRxStats(uint16_t* packetRx, uint16_t* crcError, uint16_t* lenError);
|
||||
int16_t getOqpskPacketStatus(uint8_t* rxHeader, uint16_t* payloadLen, float* rssiAvg, float* rssiSync, float* lqi);
|
||||
int16_t setOqpskPacketLen(uint8_t len);
|
||||
int16_t setOqpskAddress(uint8_t longDestAddr[8], uint16_t shortDestAddr, uint16_t panId, uint8_t transId);
|
||||
|
||||
// BPSK commands
|
||||
int16_t setBpskModulationParams(uint32_t bitRate, uint8_t pulseShape, bool diff, uint8_t diffInit);
|
||||
int16_t setBpskPacketParams(uint8_t payloadLen, uint8_t mode, bool sigFoxControlMsg, uint8_t sigFoxRank);
|
||||
|
||||
// FLRC commands
|
||||
int16_t setFlrcModulationParams(uint8_t brBw, uint8_t cr, uint8_t pulseShape);
|
||||
int16_t setFlrcPacketParams(uint8_t agcPreambleLen, uint8_t syncWordLen, uint8_t syncWordTx, uint8_t syncMatch, bool fixedLength, uint8_t crc, uint16_t payloadLen);
|
||||
int16_t getFlrcRxStats(uint16_t* packetRx, uint16_t* packetCrcError, uint16_t* lenError);
|
||||
int16_t getFlrcPacketStatus(uint16_t* packetLen, float* rssiAvg, float* rssiSync, uint8_t* syncWordNum);
|
||||
int16_t setFlrcSyncWord(uint8_t syncWordNum, uint32_t syncWord);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
#include "LR2021.h"
|
||||
|
||||
#include "../LR11x0/LR_common.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_LR2021
|
||||
|
||||
int16_t LR2021::setFlrcModulationParams(uint8_t brBw, uint8_t cr, uint8_t pulseShape) {
|
||||
uint8_t buff[] = { brBw, (uint8_t)((cr << 4) | (pulseShape & 0x0F)) };
|
||||
return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_FLRC_MODULATION_PARAMS, true, buff, sizeof(buff)));
|
||||
}
|
||||
|
||||
int16_t LR2021::setFlrcPacketParams(uint8_t agcPreambleLen, uint8_t syncWordLen, uint8_t syncWordTx, uint8_t syncMatch, bool fixedLength, uint8_t crc, uint16_t payloadLen) {
|
||||
uint8_t buff[] = {
|
||||
(uint8_t)(((agcPreambleLen & 0x0F) << 2) | (syncWordLen / 2)),
|
||||
(uint8_t)(((syncWordTx & 0x03) << 6) | ((syncMatch & 0x07) << 3) | ((uint8_t)fixedLength << 2) | (crc & 0x03)),
|
||||
(uint8_t)((payloadLen >> 8) & 0xFF), (uint8_t)(payloadLen & 0xFF),
|
||||
};
|
||||
return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_FLRC_PACKET_PARAMS, true, buff, sizeof(buff)));
|
||||
}
|
||||
|
||||
int16_t LR2021::getFlrcRxStats(uint16_t* packetRx, uint16_t* packetCrcError, uint16_t* lenError) {
|
||||
uint8_t buff[14] = { 0 };
|
||||
int16_t state = this->SPIcommand(RADIOLIB_LR2021_CMD_GET_FLRC_RX_STATS, false, buff, sizeof(buff));
|
||||
if(packetRx) { *packetRx = ((uint16_t)(buff[0]) << 8) | (uint16_t)buff[1]; }
|
||||
if(packetCrcError) { *packetCrcError = ((uint16_t)(buff[2]) << 8) | (uint16_t)buff[3]; }
|
||||
if(lenError) { *lenError = ((uint16_t)(buff[4]) << 8) | (uint16_t)buff[5]; }
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t LR2021::getFlrcPacketStatus(uint16_t* packetLen, float* rssiAvg, float* rssiSync, uint8_t* syncWordNum) {
|
||||
uint8_t buff[5] = { 0 };
|
||||
int16_t state = this->SPIcommand(RADIOLIB_LR2021_CMD_GET_FLRC_PACKET_STATUS, false, buff, sizeof(buff));
|
||||
uint16_t raw = 0;
|
||||
if(packetLen) { *packetLen = ((uint16_t)(buff[0]) << 8) | (uint16_t)buff[1]; }
|
||||
if(rssiAvg) {
|
||||
raw = (uint16_t)buff[2] << 1;
|
||||
raw |= (buff[4] & 0x04) >> 2;
|
||||
*rssiAvg = (float)raw / -2.0f;
|
||||
}
|
||||
if(rssiSync) {
|
||||
raw = (uint16_t)buff[3] << 1;
|
||||
raw |= (buff[4] & 0x01);
|
||||
*rssiSync = (float)raw / -2.0f;
|
||||
}
|
||||
if(syncWordNum) { *syncWordNum = (buff[4] & 0xF0) >> 4; }
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t LR2021::setFlrcSyncWord(uint8_t syncWordNum, uint32_t syncWord) {
|
||||
uint8_t buff[] = {
|
||||
syncWordNum,
|
||||
(uint8_t)((syncWord >> 24) & 0xFF), (uint8_t)((syncWord >> 16) & 0xFF),
|
||||
(uint8_t)((syncWord >> 8) & 0xFF), (uint8_t)(syncWord & 0xFF),
|
||||
};
|
||||
return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_FLRC_SYNCWORD, true, buff, sizeof(buff)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#include "LR2021.h"
|
||||
|
||||
#include "../LR11x0/LR_common.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_LR2021
|
||||
|
||||
int16_t LR2021::setBpskModulationParams(uint32_t bitRate, uint8_t pulseShape, bool diff, uint8_t diffInit) {
|
||||
uint8_t buff[] = {
|
||||
(uint8_t)((bitRate >> 24) & 0xFF), (uint8_t)((bitRate >> 16) & 0xFF),
|
||||
(uint8_t)((bitRate >> 8) & 0xFF), (uint8_t)(bitRate & 0xFF),
|
||||
(uint8_t)((pulseShape << 4) | ((uint8_t)diff << 2) | (diffInit & 0x03)),
|
||||
};
|
||||
return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_BPSK_MODULATION_PARAMS, true, buff, sizeof(buff)));
|
||||
}
|
||||
|
||||
int16_t LR2021::setBpskPacketParams(uint8_t payloadLen, uint8_t mode, bool sigFoxControlMsg, uint8_t sigFoxRank) {
|
||||
uint8_t buff[] = {
|
||||
payloadLen,
|
||||
(uint8_t)((mode << 4) | ((uint8_t)sigFoxControlMsg << 2) | (sigFoxRank & 0x03)),
|
||||
};
|
||||
return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_BPSK_PACKET_PARAMS, true, buff, sizeof(buff)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
#include "LR2021.h"
|
||||
|
||||
#include "../LR11x0/LR_common.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_LR2021
|
||||
|
||||
int16_t LR2021::setOqpskParams(uint8_t mode, uint8_t rxBw, uint8_t payloadLen, uint16_t preambleLen, bool addrFilt, bool fcsManual) {
|
||||
uint8_t buff[] = {
|
||||
mode, rxBw, payloadLen,
|
||||
(uint8_t)((preambleLen >> 8) & 0xFF), (uint8_t)(preambleLen & 0xFF),
|
||||
(uint8_t)((uint8_t)addrFilt << 1 | (uint8_t)fcsManual),
|
||||
};
|
||||
return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_OQPSK_PARAMS, true, buff, sizeof(buff)));
|
||||
}
|
||||
|
||||
int16_t LR2021::getOqpskRxStats(uint16_t* packetRx, uint16_t* crcError, uint16_t* lenError) {
|
||||
uint8_t buff[6] = { 0 };
|
||||
int16_t state = this->SPIcommand(RADIOLIB_LR2021_CMD_GET_OQPSK_RX_STATS, false, buff, sizeof(buff));
|
||||
if(packetRx) { *packetRx = ((uint16_t)(buff[0]) << 8) | (uint16_t)buff[1]; }
|
||||
if(crcError) { *crcError = ((uint16_t)(buff[2]) << 8) | (uint16_t)buff[3]; }
|
||||
if(lenError) { *lenError = ((uint16_t)(buff[4]) << 8) | (uint16_t)buff[5]; }
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t LR2021::getOqpskPacketStatus(uint8_t* rxHeader, uint16_t* payloadLen, float* rssiAvg, float* rssiSync, float* lqi) {
|
||||
uint8_t buff[7] = { 0 };
|
||||
int16_t state = this->SPIcommand(RADIOLIB_LR2021_CMD_GET_OQPSK_RX_STATS, false, buff, sizeof(buff));
|
||||
if(rxHeader) { *rxHeader = buff[0]; }
|
||||
if(payloadLen) { *payloadLen = ((uint16_t)(buff[1]) << 8) | (uint16_t)buff[2]; }
|
||||
uint16_t raw = 0;
|
||||
if(rssiAvg) {
|
||||
raw = (uint16_t)buff[3] << 1;
|
||||
raw |= (buff[5] & 0x04) >> 2;
|
||||
*rssiAvg = (float)raw / -2.0f;
|
||||
}
|
||||
if(rssiSync) {
|
||||
raw = (uint16_t)buff[4] << 1;
|
||||
raw |= (buff[5] & 0x01);
|
||||
*rssiSync = (float)raw / -2.0f;
|
||||
}
|
||||
if(lqi) { *lqi = buff[6] * 4.0f; }
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t LR2021::setOqpskPacketLen(uint8_t len) {
|
||||
return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_OQPSK_PACKET_LEN, true, &len, sizeof(len)));
|
||||
}
|
||||
|
||||
int16_t LR2021::setOqpskAddress(uint8_t longDestAddr[8], uint16_t shortDestAddr, uint16_t panId, uint8_t transId) {
|
||||
uint8_t buff[] = {
|
||||
longDestAddr[7], longDestAddr[6], longDestAddr[5], longDestAddr[4],
|
||||
longDestAddr[3], longDestAddr[2], longDestAddr[1], longDestAddr[0],
|
||||
(uint8_t)((shortDestAddr >> 8) & 0xFF), (uint8_t)(shortDestAddr & 0xFF),
|
||||
(uint8_t)((panId >> 8) & 0xFF), (uint8_t)(panId & 0xFF), transId,
|
||||
};
|
||||
return(this->SPIcommand(RADIOLIB_LR2021_CMD_SET_OQPSK_ADDRESS, true, buff, sizeof(buff)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -409,11 +409,15 @@
|
|||
#define RADIOLIB_LR2021_FSK_BITRATE_BPS (0x00UL << 31) // 7 0 bitrate units: bits per second
|
||||
#define RADIOLIB_LR2021_FSK_BITRATE_FRACTIONAL (0x01UL << 31) // 7 0 fractional (1/256 bps)
|
||||
#define RADIOLIB_LR2021_FSK_SHAPING_NONE (0x00UL << 0) // 7 0 shaping filter: none
|
||||
#define RADIOLIB_LR2021_FSK_SHAPING_GAUSS_BT_2_0 (0x02UL << 0) // 7 0 Gaussian, BT = 2.0
|
||||
#define RADIOLIB_LR2021_FSK_SHAPING_GAUSS_BT_0_3 (0x04UL << 0) // 7 0 Gaussian, BT = 0.3
|
||||
#define RADIOLIB_LR2021_FSK_SHAPING_GAUSS_BT_0_5 (0x05UL << 0) // 7 0 Gaussian, BT = 0.5
|
||||
#define RADIOLIB_LR2021_FSK_SHAPING_GAUSS_BT_0_7 (0x06UL << 0) // 7 0 Gaussian, BT = 0.7
|
||||
#define RADIOLIB_LR2021_FSK_SHAPING_GAUSS_BT_1_0 (0x07UL << 0) // 7 0 Gaussian, BT = 1.0
|
||||
#define RADIOLIB_LR2021_FSK_BPSK_FLRC_SHAPING_GAUSS_BT_2_0 (0x02UL << 0) // 7 0 Gaussian, BT = 2.0
|
||||
#define RADIOLIB_LR2021_FSK_BPSK_FLRC_SHAPING_RRC_ROLLOFF_0_4 (0x03UL << 0) // 7 0 Root-Raised-Cosine with 0.4 roll-off
|
||||
#define RADIOLIB_LR2021_FSK_BPSK_FLRC_SHAPING_GAUSS_BT_0_3 (0x04UL << 0) // 7 0 Gaussian, BT = 0.3
|
||||
#define RADIOLIB_LR2021_FSK_BPSK_FLRC_SHAPING_GAUSS_BT_0_5 (0x05UL << 0) // 7 0 Gaussian, BT = 0.5
|
||||
#define RADIOLIB_LR2021_FSK_BPSK_FLRC_SHAPING_GAUSS_BT_0_7 (0x06UL << 0) // 7 0 Gaussian, BT = 0.7
|
||||
#define RADIOLIB_LR2021_FSK_BPSK_FLRC_SHAPING_GAUSS_BT_1_0 (0x07UL << 0) // 7 0 Gaussian, BT = 1.0
|
||||
#define RADIOLIB_LR2021_FSK_BPSK_FLRC_SHAPING_RRC_ROLLOFF_0_3 (0x08UL << 0) // 7 0 Root-Raised-Cosine with 0.3 roll-off
|
||||
#define RADIOLIB_LR2021_FSK_BPSK_FLRC_SHAPING_RRC_ROLLOFF_0_5 (0x09UL << 0) // 7 0 Root-Raised-Cosine with 0.5 roll-off
|
||||
#define RADIOLIB_LR2021_FSK_BPSK_FLRC_SHAPING_RRC_ROLLOFF_0_7 (0x0AUL << 0) // 7 0 Root-Raised-Cosine with 0.7 roll-off
|
||||
// TODO implement the other bandwidths as well (and figure out a way how to calculate it)
|
||||
#define RADIOLIB_LR2021_GFSK_RX_BW_4_8 (39) // 7 0 GFSK Rx bandwidth: 4.8 kHz
|
||||
#define RADIOLIB_LR2021_GFSK_RX_BW_5_8 (215) // 7 0 5.8 kHz
|
||||
|
|
@ -466,6 +470,27 @@
|
|||
#define RADIOLIB_LR2021_GFSK_WHITENING_TYPE_SX126X_LR11XX (0x00UL << 0) // 7 0 whitening type: compatible with SX126x and LR11x0
|
||||
#define RADIOLIB_LR2021_GFSK_WHITENING_TYPE_SX128X (0x01UL << 0) // 7 0 compatible with SX128x
|
||||
|
||||
// RADIOLIB_LR2021_CMD_SET_OQPSK_PARAMS
|
||||
#define RADIOLIB_LR2021_OQPSK_TYPE_15_4 (0x00UL << 0) // 7 0 OQPSK type: 802.15.4 PHY, 250 kbps bit rate
|
||||
|
||||
// RADIOLIB_LR2021_CMD_SET_BPSK_PACKET_PARAMS
|
||||
#define RADIOLIB_LR2021_BPSK_MODE_RAW (0x00UL << 0) // 7 0 encoding mode: raw
|
||||
#define RADIOLIB_LR2021_BPSK_MODE_SIGFOX (0x01UL << 0) // 7 0 SigFox PHY
|
||||
|
||||
// RADIOLIB_LR2021_CMD_SET_FLRC_MODULATION_PARAMS
|
||||
#define RADIOLIB_LR2021_FLRC_BR_2600 (0x00UL << 0) // 7 0 bitrate/bandwidth: 2600 kbps, 2666 kHz
|
||||
#define RADIOLIB_LR2021_FLRC_BR_2080 (0x01UL << 0) // 7 0 2080 kbps, 2222 kHz
|
||||
#define RADIOLIB_LR2021_FLRC_BR_1300 (0x02UL << 0) // 7 0 1300 kbps, 1333 kHz
|
||||
#define RADIOLIB_LR2021_FLRC_BR_1040 (0x03UL << 0) // 7 0 1040 kbps, 1333 kHz
|
||||
#define RADIOLIB_LR2021_FLRC_BR_650 (0x04UL << 0) // 7 0 650 kbps, 888 kHz
|
||||
#define RADIOLIB_LR2021_FLRC_BR_520 (0x05UL << 0) // 7 0 520 kbps, 769 kHz
|
||||
#define RADIOLIB_LR2021_FLRC_BR_325 (0x06UL << 0) // 7 0 325 kbps, 444 kHz
|
||||
#define RADIOLIB_LR2021_FLRC_BR_260 (0x07UL << 0) // 7 0 260 kbps, 444 kHz
|
||||
#define RADIOLIB_LR2021_FLRC_CR_1_2 (0x00UL << 0) // 7 0 coding rate: 1/2
|
||||
#define RADIOLIB_LR2021_FLRC_CR_3_4 (0x01UL << 0) // 7 0 3/4
|
||||
#define RADIOLIB_LR2021_FLRC_CR_1_0 (0x02UL << 0) // 7 0 1 (uncoded)
|
||||
#define RADIOLIB_LR2021_FLRC_CR_2_3 (0x03UL << 0) // 7 0 2/3
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue