syrlinks handler ready for testing

This commit is contained in:
2021-02-22 09:24:42 +01:00
parent 13c75ed9c2
commit 9bdc2096b0
18 changed files with 842 additions and 247 deletions

View File

@ -1,9 +1,10 @@
#include <mission/devices/SyrlinksHkHandler.h>
#include <fsfwconfig/OBSWConfig.h>
#include <fsfw/globalfunctions/CRC.h>
#include <fsfw/datapool/PoolReadHelper.h>
SyrlinksHkHandler::SyrlinksHkHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie) :
DeviceHandlerBase(objectId, comIF, comCookie), rxStatusRegistersSet(this) {
DeviceHandlerBase(objectId, comIF, comCookie), rxDataset(this), txDataset(this) {
if (comCookie == NULL) {
sif::error << "SyrlinksHkHandler: Invalid com cookie" << std::endl;
}
@ -25,7 +26,7 @@ void SyrlinksHkHandler::doShutDown(){
ReturnValue_t SyrlinksHkHandler::buildNormalDeviceCommand(
DeviceCommandId_t * id) {
*id = READ_RX_STATUS_REGISTERS;
*id = SYRLINKS::READ_RX_STATUS_REGISTERS;
return buildCommandFromCommand(*id, NULL, 0);
}
@ -39,33 +40,40 @@ ReturnValue_t SyrlinksHkHandler::buildCommandFromCommand(
size_t commandDataLen) {
switch(deviceCommand) {
case(SYRLINKS::RESET_UNIT): {
resetCommand.copy(rawPacket, resetCommand.size(), 0);
resetCommand.copy(reinterpret_cast<char*>(commandBuffer), resetCommand.size(), 0);
rawPacketLen = resetCommand.size();
rememberCommandId = SYRLINKS::RESET_UNIT;
rawPacket = commandBuffer;
return RETURN_OK;
}
case(SYRLINKS::SET_TX_MODE_STANDBY): {
setTxModeStandby.copy(rawPacket, setTxModeStandby.size(), 0);
setTxModeStandby.copy(reinterpret_cast<char*>(commandBuffer), setTxModeStandby.size(), 0);
rawPacketLen = setTxModeStandby.size();
rememberCommandId = SYRLINKS::SET_TX_MODE_STANDBY;
rawPacket = commandBuffer;
return RETURN_OK;
}
case(SYRLINKS::SET_TX_MODE_MODULATION): {
setTxModeModulation.copy(rawPacket, setTxModeModulation.size(), 0);
setTxModeModulation.copy(reinterpret_cast<char*>(commandBuffer), setTxModeModulation.size(), 0);
rawPacketLen = setTxModeModulation.size();
rememberCommandId = SYRLINKS::SET_TX_MODE_MODULATION;
rawPacket = commandBuffer;
return RETURN_OK;
}
case(SYRLINKS::SET_TX_MODE_CW): {
setTxModeCw.copy(rawPacket, setTxModeCw.size(), 0);
setTxModeCw.copy(reinterpret_cast<char*>(commandBuffer), setTxModeCw.size(), 0);
rawPacketLen = setTxModeCw.size();
rememberCommandId = SYRLINKS::SET_TX_MODE_CW;
rawPacket = commandBuffer;
return RETURN_OK;
}
case(SYRLINKS::READ_RX_STATUS_REGISTERS): {
readRxStatusRegCommand.copy(rawPacket, readRxStatusRegCommand.size(), 0);
readRxStatusRegCommand.copy(reinterpret_cast<char*>(commandBuffer), readRxStatusRegCommand.size(), 0);
rawPacketLen = readRxStatusRegCommand.size();
rememberCommandId = SYRLINKS::READ_RX_STATUS_REGISTERS;
rawPacket = commandBuffer;
return RETURN_OK;
}
case(SYRLINKS::READ_TX_STATUS): {
readTxStatus.copy(reinterpret_cast<char*>(commandBuffer), readTxStatus.size(), 0);
rawPacketLen = readTxStatus.size();
rememberCommandId = SYRLINKS::READ_TX_STATUS;
rawPacket = commandBuffer;
return RETURN_OK;
}
default:
@ -75,11 +83,17 @@ ReturnValue_t SyrlinksHkHandler::buildCommandFromCommand(
}
void SyrlinksHkHandler::fillCommandAndReplyMap() {
this->insertInCommandAndReplyMap(SYRLINKS::RESET_UNIT);
this->insertInCommandAndReplyMap(SYRLINKS::SET_TX_MODE_STANDBY);
this->insertInCommandAndReplyMap(SYRLINKS::SET_TX_MODE_MODULATION);
this->insertInCommandAndReplyMap(SYRLINKS::SET_TX_MODE_CW);
this->insertInCommandAndReplyMap(SYRLINKS::READ_RX_STATUS_REGISTERS, 1, &rxStatusRegistersSet,
this->insertInCommandAndReplyMap(SYRLINKS::RESET_UNIT, 1, nullptr, SYRLINKS::ACK_SIZE, false,
true, SYRLINKS::ACK_REPLY);
this->insertInCommandAndReplyMap(SYRLINKS::SET_TX_MODE_STANDBY, 1, nullptr, SYRLINKS::ACK_SIZE,
false, true, SYRLINKS::ACK_REPLY);
this->insertInCommandAndReplyMap(SYRLINKS::SET_TX_MODE_MODULATION, 1, nullptr,
SYRLINKS::ACK_SIZE, false, true, SYRLINKS::ACK_REPLY);
this->insertInCommandAndReplyMap(SYRLINKS::SET_TX_MODE_CW, 1, nullptr, SYRLINKS::ACK_SIZE,
false, true, SYRLINKS::ACK_REPLY);
this->insertInCommandAndReplyMap(SYRLINKS::READ_TX_STATUS, 1, &txDataset,
SYRLINKS::READ_TX_STATUS);
this->insertInCommandAndReplyMap(SYRLINKS::READ_RX_STATUS_REGISTERS, 1, &rxDataset,
SYRLINKS::RX_STATUS_REGISTERS_REPLY_SIZE);
}
@ -88,59 +102,33 @@ ReturnValue_t SyrlinksHkHandler::scanForReply(const uint8_t *start,
ReturnValue_t result = RETURN_OK;
switch(rememberCommandId) {
case(SYRLINKS::RESET_UNIT):
if (remainingSize != SYRLINKS::REQUEST_STATUS_REPLY_SIZE) {
result = REPLY_WRONG_SIZE;
break;
}
*foundLen = SYRLINKS::REQUEST_STATUS_REPLY_SIZE;
*foundId = SYRLINKS::RESET_UNIT;
rememberCommandId = SYRLINKS::NONE;
if(*start != '<') {
sif::error << "SyrlinksHkHandler::scanForReply: Missing start frame character" << std::endl;
return MISSING_START_FRAME_CHARACTER;
}
switch(*(start + 1)) {
case('A'):
*foundLen = SYRLINKS::ACK_SIZE;
*foundId = SYRLINKS::ACK_REPLY;
break;
case(SYRLINKS::SET_TX_MODE_STANDBY):
if (remainingSize != SYRLINKS::REQUEST_STATUS_REPLY_SIZE) {
result = REPLY_WRONG_SIZE;
}
*foundLen = SYRLINKS::REQUEST_STATUS_REPLY_SIZE;
rememberCommandId = SYRLINKS::NONE;
*foundId = SYRLINKS::SET_TX_MODE_STANDBY;
break;
case(SYRLINKS::SET_TX_MODE_MODULATION):
if (remainingSize != SYRLINKS::REQUEST_STATUS_REPLY_SIZE) {
result = REPLY_WRONG_SIZE;
}
*foundLen = SYRLINKS::REQUEST_STATUS_REPLY_SIZE;
*foundId = SYRLINKS::SET_TX_MODE_MODULATION;
rememberCommandId = SYRLINKS::NONE;
break;
case(SYRLINKS::SET_TX_MODE_CW):
if (remainingSize != SYRLINKS::REQUEST_STATUS_REPLY_SIZE) {
result = REPLY_WRONG_SIZE;
}
*foundLen = SYRLINKS::REQUEST_STATUS_REPLY_SIZE;
*foundId = SYRLINKS::SET_TX_MODE_CW;
rememberCommandId = SYRLINKS::NONE;
break;
case(SYRLINKS::READ_RX_STATUS_REGISTERS):
if (remainingSize != SYRLINKS::RX_STATUS_REGISTERS_REPLY_SIZE) {
result = REPLY_WRONG_SIZE;
}
case('E'):
*foundLen = SYRLINKS::RX_STATUS_REGISTERS_REPLY_SIZE;
*foundId = SYRLINKS::READ_RX_STATUS_REGISTERS;
rememberCommandId = SYRLINKS::NONE;
break;
case('R'):
if (rememberCommandId == SYRLINKS::READ_TX_STATUS) {
*foundLen = SYRLINKS::READ_TX_STATUS_REPLY_SIZE;
*foundId = SYRLINKS::READ_TX_STATUS;
rememberCommandId = SYRLINKS::NONE;
}
break;
default:
sif::error << "SyrlinksHkHandler::scanForReply: Unknown reply identifier" << std::endl;
result = IGNORE_REPLY_DATA;
break;
}
if (result == REPLY_WRONG_SIZE) {
sif::debug << "SyrlinksHkHandler::scanForReply: Received reply with invalid length"
<< std::endl;
return result;
}
return result;
}
@ -150,53 +138,44 @@ ReturnValue_t SyrlinksHkHandler::interpretDeviceReply(DeviceCommandId_t id,
ReturnValue_t result;
switch (id) {
case (SYRLINKS::RESET_UNIT):
case (SYRLINKS::SET_TX_MODE_STANDBY):
case (SYRLINKS::SET_TX_MODE_MODULATION):
case (SYRLINKS::SET_TX_MODE_CW):
result = verifyTansmissionStatusReply(packet);
case (SYRLINKS::ACK_REPLY):
result = verifyReply(packet, SYRLINKS::ACK_SIZE);
if (result != RETURN_OK) {
sif::debug << "SyrlinksHkHandler::interpretDeviceReply: Status reply has invalid crc"
<< std::endl;
sif::error << "SyrlinksHkHandler::interpretDeviceReply: Acknowledgement reply has "
"invalid crc" << std::endl;
return CRC_FAILURE;
}
result = parseReplyStatus(static_cast<char*>(packet + SYRLINKS::MESSAGE_HEADER_SIZE));
result = parseReplyStatus(reinterpret_cast<const char*>(packet + SYRLINKS::MESSAGE_HEADER_SIZE));
if (result != RETURN_OK) {
return result;
}
break;
case(SYRLINKS::READ_RX_STATUS_REGISTERS):
result = verifyReadRxStatusRegistersReply(packet);
result = verifyReply(packet, SYRLINKS::RX_STATUS_REGISTERS_REPLY_SIZE);
if (result != RETURN_OK) {
sif::debug << "SyrlinksHkHandler::interpretDeviceReply: Read rx status registers reply "
sif::error << "SyrlinksHkHandler::interpretDeviceReply: Read rx status registers reply "
<< "has invalid crc" << std::endl;
return CRC_FAILURE;
}
parseRxStatusRegistersReply(packet);
break;
case(SYRLINKS::READ_TX_STATUS):
result = verifyReply(packet, SYRLINKS::READ_TX_STATUS_REPLY_SIZE);
if (result != RETURN_OK) {
sif::error << "SyrlinksHkHandler::interpretDeviceReply: Read tx status reply "
<< "has invalid crc" << std::endl;
return CRC_FAILURE;
}
parseTxStatusReply(packet);
break;
default: {
sif::debug << "SyrlinksHkHandler::interpretDeviceReply: Unknown device reply id"
<< std::endl;
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t SyrlinksHkHandler::verifyTansmissionStatusReply() {
int result = 0;
uint16_t crc = CRC::crc16ccitt(packet,
SYRLINKS::REQUEST_STATUS_REPLY_SIZE - SYRLINKS::SIZE_CRC_AND_TERMINATION,
CRC_INITIAL_VALUE);
std::string recalculatedCrc = convertIntToHexString(crc);
const char* replyCrc = packet + SYRLINKS::REQUEST_STATUS_REPLY_SIZE
- SYRLINKS::SIZE_CRC_AND_TERMINATION;
size_t startPosition = 0;
result = recalculatedCrc.compare(startPosition, SYRLINKS_CRC_FIELD_SIZE, replyCrc);
if (result != 0) {
return RETURN_FAILED;
}
return RETURN_OK;
return RETURN_OK;
}
std::string SyrlinksHkHandler::convertIntToHexString(uint16_t intValue) {
@ -205,7 +184,7 @@ std::string SyrlinksHkHandler::convertIntToHexString(uint16_t intValue) {
return stream.str();
}
ReturnValue_t SyrlinksHkHandler::parseReplyStatus(char* status) {
ReturnValue_t SyrlinksHkHandler::parseReplyStatus(const char* status) {
switch (*status) {
case '0':
return RETURN_OK;
@ -231,29 +210,54 @@ ReturnValue_t SyrlinksHkHandler::parseReplyStatus(char* status) {
sif::debug << "SyrlinksHkHandler::parseReplyStatus: Bad CRC" << std::endl;
return BAD_CRC_ACK;
default:
sif::debug << "SyrlinksHkHandler::parseReplyStatus: Status reply holds invalid status "
<< "id" << std::endl;
sif::debug << "SyrlinksHkHandler::parseReplyStatus: Status reply contains an invalid "
<< "status id" << std::endl;
return RETURN_FAILED;
}
}
ReturnValue_t SyrlinksHkHandler::verifyReadRxStatusRegistersReply(uint8_t* packet) {
ReturnValue_t SyrlinksHkHandler::verifyReply(const uint8_t* packet, uint8_t size) {
int result = 0;
/* Calculate crc of received packet */
uint16_t crc = CRC::crc16ccitt(packet,
SYRLINKS::RX_STATUS_REGISTERS_REPLY_SIZE - SYRLINKS::SIZE_CRC_AND_TERMINATION,
uint16_t crc = CRC::crc16ccitt(packet, size - SYRLINKS::SIZE_CRC_AND_TERMINATION,
CRC_INITIAL_VALUE);
std::string recalculatedCrc = convertIntToHexString(crc);
const char* replyCrc = packet + SYRLINKS::RX_STATUS_REGISTERS_REPLY_SIZE
- SYRLINKS::SIZE_CRC_AND_TERMINATION;
const char* replyCrc = reinterpret_cast<const char*>(packet) + size - SYRLINKS::SIZE_CRC_AND_TERMINATION;
size_t startPosition = 0;
result = recalculatedCrc.compare(startPosition, SYRLINKS_CRC_FIELD_SIZE, replyCrc);
result = recalculatedCrc.compare(startPosition, SYRLINKS::CRC_FIELD_SIZE, replyCrc);
if (result != 0) {
return RETURN_FAILED;
}
return RETURN_OK;
}
void SyrlinksHkHandler::parseRxStatusRegistersReply(const uint8_t* packet) {
PoolReadHelper readHelper(&rxDataset);
uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE;
rxDataset.rxStatus = *(packet + offset);
packet += 1;
rxDataset.rxSensitivity = *(packet + offset) << 16 | *(packet + offset + 1) << 8 | *(packet + offset + 2);
packet += 3;
rxDataset.rxFrequencyShift = *(packet + offset) << 16 | *(packet + offset + 1) << 8 | *(packet + offset + 2);
packet += 3;
rxDataset.rxIqPower = *(packet + offset) << 8 | *(packet + offset + 1);
packet += 2;
rxDataset.rxAgcValue = *(packet + offset + 1) << 8 | *(packet + offset);
packet += 2;
packet += 1; // reserved register
rxDataset.rxDemodEb= *(packet + offset) << 16 | *(packet + offset + 1) << 8 | *(packet + offset + 2);
packet += 3;
rxDataset.rxDemodN0= *(packet + offset) << 16 | *(packet + offset + 1) << 8 | *(packet + offset + 2);
packet += 3;
rxDataset.rxDataRate = *(packet + offset);
}
void SyrlinksHkHandler::parseTxStatusReply(const uint8_t* packet) {
PoolReadHelper readHelper(&txDataset);
uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE;
rxDataset.rxStatus = *(packet + offset);
}
void SyrlinksHkHandler::setNormalDatapoolEntriesInvalid(){
}
@ -264,7 +268,20 @@ uint32_t SyrlinksHkHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo)
ReturnValue_t SyrlinksHkHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) {
localDataPoolMap.emplace(TMP1075::TEMPERATURE_C_TMP1075_1, new PoolEntry<float>( { 0.0 }));
localDataPoolMap.emplace(SYRLINKS::RX_STATUS, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(SYRLINKS::RX_SENSITIVITY, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(SYRLINKS::RX_FREQUENCY_SHIFT, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(SYRLINKS::RX_IQ_POWER, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(SYRLINKS::RX_AGC_VALUE, new PoolEntry<uint16_t>( { 0 }));
localDataPoolMap.emplace(SYRLINKS::RX_DEMOD_EB, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(SYRLINKS::RX_DEMOD_N0, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(SYRLINKS::RX_DATA_RATE, new PoolEntry<uint8_t>( { 0 }));
return HasReturnvaluesIF::RETURN_OK;
}
void SyrlinksHkHandler::setModeNormal() {
mode = MODE_NORMAL;
}

View File

@ -3,7 +3,7 @@
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
#include <mission/devices/devicedefinitions/SyrlinksDefinitions.h>
#include <cstring.h>
#include <string.h>
/**
* @brief This is the device handler for the syrlinks transceiver. It handles the command
@ -20,6 +20,11 @@ public:
CookieIF * comCookie);
virtual ~SyrlinksHkHandler();
/**
* @brief Sets mode to MODE_NORMAL. Can be used for debugging.
*/
void setModeNormal();
protected:
void doStartUp() override;
void doShutDown() override;
@ -49,6 +54,7 @@ private:
static const ReturnValue_t UNKNOWN_COMMAND_ID_ACK = MAKE_RETURN_CODE(0xA5);
static const ReturnValue_t BAD_CRC_ACK = MAKE_RETURN_CODE(0xA6);
static const ReturnValue_t REPLY_WRONG_SIZE = MAKE_RETURN_CODE(0xA7);
static const ReturnValue_t MISSING_START_FRAME_CHARACTER = MAKE_RETURN_CODE(0xA8);
static const uint8_t CRC_INITIAL_VALUE = 0x0;
@ -58,29 +64,18 @@ private:
/** W - write, 04 - 4 bytes in data field, 01 - value, 40 register to write value */
std::string setTxModeModulation = "<W04:0140:5D2A>";
std::string setTxModeCw = "<W04:1040:81CF>";
SYRLINKS::RxStatusRegistersDataset rxStatusRegistersSet;
static const uint8_t MAX_CMD_LEN = 3;
uint8_t rememberRequestedSize = 0;
uint8_t rememberCommandId = SYRLINKS::NONE;
uint8_t cmdBuffer[MAX_CMD_LEN];
CommunicationStep communicationStep =
CommunicationStep::START_ADC_CONVERSION;
std::string readTxStatus = "<R02:40:7555>";
/**
* @brief This function verifies the checksum of a status reply packet of the syrlinks.
*
* @param packet Pointer to the received status reply.
*
* @return RETURN_OK if successful, otherwise RETURN_FAILURE.
*
* @details A status reply only contains one byte of payload data giving information about
* the transmission status.
* In some cases it is not possible to extract from the received reply the information about
* the associated command. This variable is thus used to remember the command id.
*/
ReturnValue_t verifyTansmissionStatusReply(const uint8_t* packet);
DeviceCommandId_t rememberCommandId = SYRLINKS::NONE;
SYRLINKS::RxDataset rxDataset;
SYRLINKS::TxDataset txDataset;
uint8_t commandBuffer[SYRLINKS::MAX_COMMAND_SIZE];
/**
* @brief This function converts an uint16_t into its hexadecimal string representation.
@ -89,7 +84,7 @@ private:
*
* @return An std::string object containing the hex representation of intValue.
*/
std::string SyrlinksHkHandler::convertIntToHexString(uint16_t intValue);
std::string convertIntToHexString(uint16_t intValue);
/**
* @brief This function parses the status reply
@ -98,17 +93,32 @@ private:
* @details Some commands reply with a status message giving information about the preceding
* command transmission and/or execution was successful.
*/
ReturnValue_t parseReplyStatus(char* status);
ReturnValue_t parseReplyStatus(const char* status);
/**
* @brief Function verifies the received reply from the syrlinks by recalculating and
* comparing the crc.
*
* @param packet Pointer to the received reply.
* @param size Size of the whole packet including the crc and the packet termination
* character '>'.
*
* @return RETURN_OK if successful, otherwise RETURN_FAILED.
*/
ReturnValue_t verifyReadRxStatusRegistersReply(uint8_t* packet)
ReturnValue_t verifyReply(const uint8_t* packet, uint8_t size);
/**
* @brief This function extracts the data from a rx status registers reply and writes the
* information to the status registers dataset.
* @param packet Pointer to the reply packet.
*/
void parseRxStatusRegistersReply(const uint8_t* packet);
/**
* @brief This function writes the read tx status register to the txStatusDataset.
* @param packet Pointer to the received packet.
*/
void parseTxStatusReply(const uint8_t* packet);
};
#endif /* MISSION_DEVICES_SYRLINKSHKHANDLER_H_ */

View File

@ -1,58 +0,0 @@
#include "crc_ccitt_Syrlinks.h"
#include <math.h>
#include <cstdint>
static const uint16_t crc_table[256] = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
};
// CRC implementation
uint16_t Calculate_CRC_Syrlinks(uint8_t const input[], uint32_t length)
{
uint16_t crc = 0x0000;
uint8_t *data = (uint8_t *)input;
unsigned int tbl_idx;
while (length--) {
tbl_idx = ((crc >> 8) ^ *data) & 0xff;
crc = (crc_table[tbl_idx] ^ (crc << 8)) & 0xffff;
data++;
}
return crc & 0xffff;
} /* Calculate_CRC() */

View File

@ -1,23 +0,0 @@
#ifndef CRC_CCITT_Syrlinks_H_
#define CRC_CCITT_Syrlinks_H_
#include <stdint.h>
/**
* @brief With this function the CRC16-CCITT over a data packet can be calculated.
*
* @param input Pointer to data over which the crc shall be calculated.
* @param length Size of data packet.
*
* @return The 16-bit wide crc calculated over the data packet.
*
* @details Wide: 16 bits
* Generator polynomial: 0x1021
* Bit order: MSB
* Initial value: 0
* @author Bucher, J. Meier
*/
uint16_t Calculate_CRC_Syrlinks(uint8_t const input[], uint32_t length);
#endif /* CRC_H_ */

View File

@ -1,10 +1,3 @@
/*
* SyrlinksDefinitions.h
*
* Created on: 18.02.2021
* Author: jakob
*/
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_SYRLINKSDEFINITIONS_H_
#define MISSION_DEVICES_DEVICEDEFINITIONS_SYRLINKSDEFINITIONS_H_
@ -21,34 +14,57 @@ namespace SYRLINKS {
static const DeviceCommandId_t SET_TX_MODE_MODULATION = 0x04;
/** Sends out a single carrier wave for testing purpose */
static const DeviceCommandId_t SET_TX_MODE_CW = 0x05;
static const DeviceCommandId_t ACK_REPLY = 0x06;
static const DeviceCommandId_t READ_TX_STATUS = 0x07;
/** Size of a simple transmission success response */
static const uint8_t REQUEST_STATUS_REPLY_SIZE = 11;
static const uint8_t ACK_SIZE = 11;
static const uint8_t SIZE_CRC_AND_TERMINATION = 5;
/** The size of the header with the message identifier and the payload size field */
static const uint8_t MESSAGE_HEADER_SIZE = 5;
/** Size of reply to an rx status registers request */
static const uint8_t RX_STATUS_REGISTERS_REPLY_SIZE = 39;
static const uint8_t RX_STATUS_REGISTERS_REPLY_SIZE = 30;
static const uint8_t READ_TX_STATUS_REPLY_SIZE = 13;
static const uint8_t RX_STATUS_REGISTERS_SET_ID = READ_RX_STATUS_REGISTERS;
static const uint8_t RX_DATASET_ID = READ_RX_STATUS_REGISTERS;
static const uint8_t TX_DATASET_ID = READ_TX_STATUS;
class RxStatusRegistersDataset: public StaticLocalDataSet<sizeof(float)> {
static const size_t MAX_REPLY_SIZE = RX_STATUS_REGISTERS_REPLY_SIZE;
static const size_t MAX_COMMAND_SIZE = 15;
static const size_t CRC_FIELD_SIZE = 4;
static const uint8_t RX_DATASET_SIZE = 8;
static const uint8_t TX_DATASET_SIZE = 1;
enum SyrlinksPoolIds: lp_id_t {
RX_STATUS,
RX_SENSITIVITY,
RX_FREQUENCY_SHIFT,
RX_IQ_POWER,
RX_AGC_VALUE,
RX_DEMOD_EB,
RX_DEMOD_N0,
RX_DATA_RATE,
TX_STATUS,
TX_CONV_DIFF,
TX_CONV_FILTER,
TX_WAVEFORM,
TX_PCM_INDEX,
TX_AGC_VALUE,
};
class RxDataset: public StaticLocalDataSet<RX_DATASET_SIZE> {
public:
RxStatusRegistersDataset(HasLocalDataPoolIF* owner) :
StaticLocalDataSet(owner, RX_STATUS_REGISTERS_SET_ID) {
RxDataset(HasLocalDataPoolIF* owner) :
StaticLocalDataSet(owner, RX_DATASET_ID) {
}
RxStatusRegistersDataset(object_id_t objectId) :
StaticLocalDataSet(sid_t(objectId, RX_STATUS_REGISTERS_SET_ID)) {
RxDataset(object_id_t objectId) :
StaticLocalDataSet(sid_t(objectId, RX_DATASET_ID)) {
}
lp_var_t<uint8_t> fpgaVersion = lp_var_t<uint8_t>(sid.objectId, FPGA_VERSION, this);
lp_var_t<uint8_t> fpgaBuild = lp_var_t<uint8_t>(sid.objectId, FPGA_BUILD, this);
lp_var_t<uint32_t> hardwareId = lp_var_t<uint32_t>(sid.objectId, HARDWARE_ID, this);
lp_var_t<uint8_t> fpgaType = lp_var_t<uint8_t>(sid.objectId, FPGA_TYPE, this);
lp_var_t<uint8_t> lclStatus = lp_var_t<uint8_t>(sid.objectId, LCL_STATUS, this);
lp_var_t<uint8_t> fpgaOption = lp_var_t<uint8_t>(sid.objectId, FPGA_OPTION, this);
lp_var_t<uint8_t> rxStatus = lp_var_t<uint8_t>(sid.objectId, RX_STATUS, this);
lp_var_t<uint32_t> rxSensitivity = lp_var_t<uint32_t>(sid.objectId, RX_SENSITIVITY, this);
lp_var_t<uint32_t> rxFrequencyShift = lp_var_t<uint32_t>(sid.objectId, RX_FREQUENCY_SHIFT, this);
@ -56,13 +72,22 @@ public:
lp_var_t<uint16_t> rxAgcValue = lp_var_t<uint16_t>(sid.objectId, RX_AGC_VALUE, this);
lp_var_t<uint32_t> rxDemodEb = lp_var_t<uint32_t>(sid.objectId, RX_DEMOD_EB, this);
lp_var_t<uint32_t> rxDemodN0 = lp_var_t<uint32_t>(sid.objectId, RX_DEMOD_N0, this);
lp_var_t<uint8_t> rxDataRate = lp_var_t<uint8_t>(sid.objectId, RX_DEMOD_N0, this);
lp_var_t<uint8_t> rxDataRate = lp_var_t<uint8_t>(sid.objectId, RX_DATA_RATE, this);
};
class TxDataset: public StaticLocalDataSet<TX_DATASET_SIZE> {
public:
TxDataset(HasLocalDataPoolIF* owner) :
StaticLocalDataSet(owner, TX_DATASET_ID) {
}
TxDataset(object_id_t objectId) :
StaticLocalDataSet(sid_t(objectId, TX_DATASET_ID)) {
}
lp_var_t<uint8_t> txStatus = lp_var_t<uint8_t>(sid.objectId, TX_STATUS, this);
lp_var_t<uint8_t> txConvDiff = lp_var_t<uint8_t>(sid.objectId, TX_CONV_DIFF, this);
lp_var_t<uint16_t> txConvFilter = lp_var_t<uint16_t>(sid.objectId, TX_CONV_FILTER, this);
lp_var_t<uint8_t> txWaveform = lp_var_t<uint8_t>(sid.objectId, TX_WAVEFORM, this);
lp_var_t<uint8_t> txPcmIndex = lp_var_t<uint8_t>(sid.objectId, TX_PCM_INDEX, this);
lp_var_t<uint16_t> txAgcValue = lp_var_t<uint16_t>(sid.objectId, TX_AGC_VALUE, this);
};
}