added hex string to int functions

This commit is contained in:
Jakob Meier 2021-02-25 18:15:57 +01:00
parent 4c09e973be
commit 1ef873098f
4 changed files with 73 additions and 28 deletions

View File

@ -129,7 +129,7 @@ void InitMission::initTasks(){
/* Polling Sequence Table Default */
FixedTimeslotTaskIF * PollingSequenceTableTaskDefault =
TaskFactory::instance()->createFixedTimeslotTask("PST_TASK_DEFAULT",
50, PeriodicTaskIF::MINIMUM_STACK_SIZE*4, 3.0,
50, PeriodicTaskIF::MINIMUM_STACK_SIZE*4, 4.0,
nullptr);
result = pst::pollingSequenceInitDefault(PollingSequenceTableTaskDefault);
if (result != HasReturnvaluesIF::RETURN_OK) {

View File

@ -17,7 +17,8 @@ debugging. */
#define P60DOCK_DEBUG 0
#define PDU1_DEBUG 0
#define PDU2_DEBUG 0
#define ACU_DEBUG 1
#define ACU_DEBUG 0
#define SYRLINKS_DEBUG 1
#include "OBSWVersion.h"

View File

@ -2,6 +2,7 @@
#include <fsfwconfig/OBSWConfig.h>
#include <fsfw/globalfunctions/CRC.h>
#include <fsfw/datapool/PoolReadHelper.h>
#include <fsfwconfig/OBSWConfig.h>
SyrlinksHkHandler::SyrlinksHkHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie) :
DeviceHandlerBase(objectId, comIF, comCookie), rxDataset(this), txDataset(this) {
@ -180,11 +181,11 @@ ReturnValue_t SyrlinksHkHandler::interpretDeviceReply(DeviceCommandId_t id,
std::string SyrlinksHkHandler::convertIntToHexString(uint16_t intValue) {
std::stringstream stream;
stream << std::hex << intValue;
stream << std::hex << std::uppercase << intValue;
return stream.str();
}
uint8_t SyrlinksHkHandler::convertHexStringToUint8(char* twoChars) {
uint8_t SyrlinksHkHandler::convertHexStringToUint8(const char* twoChars) {
uint8_t value;
std::string hexString(twoChars, 2);
std::stringstream stream;
@ -193,8 +194,33 @@ uint8_t SyrlinksHkHandler::convertHexStringToUint8(char* twoChars) {
return value;
}
uint16_t convertHexStringToUint16(char* fourChars) {
uint16_t SyrlinksHkHandler::convertHexStringToUint16(const char* fourChars) {
uint16_t value = 0;
value = convertHexStringToUint8(fourChars) << 8 | convertHexStringToUint8(fourChars+2);
return value;
}
uint32_t SyrlinksHkHandler::convertHexStringToUint32(const char* characters, uint8_t numberOfChars) {
uint32_t value = 0;
switch (numberOfChars) {
case 6:
value = convertHexStringToUint8(characters) << 16
| convertHexStringToUint8(characters + 2) << 8
| convertHexStringToUint8(characters + 4);
return value;
case 8:
value = convertHexStringToUint8(characters) << 24
| convertHexStringToUint8(characters + 2) << 16
| convertHexStringToUint8(characters + 4) << 8
| convertHexStringToUint8(characters + 4);
return value;
default:
sif::debug << "SyrlinksHkHandler::convertHexStringToUint32: Invalid number of characters. "
<< "Must be either 6 or 8" << std::endl;
return 0;
}
}
ReturnValue_t SyrlinksHkHandler::parseReplyStatus(const char* status) {
@ -231,13 +257,17 @@ ReturnValue_t SyrlinksHkHandler::parseReplyStatus(const char* status) {
ReturnValue_t SyrlinksHkHandler::verifyReply(const uint8_t* packet, uint8_t size) {
int result = 0;
/* Calculate crc of received packet */
/* Calculate crc from received packet */
uint16_t crc = CRC::crc16ccitt(packet, size - SYRLINKS::SIZE_CRC_AND_TERMINATION,
CRC_INITIAL_VALUE);
std::string recalculatedCrc = convertIntToHexString(crc);
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);
const char* startOfCrc = reinterpret_cast<const char*>(packet + size - SYRLINKS::SIZE_CRC_AND_TERMINATION);
const char* endOfCrc = reinterpret_cast<const char*>(packet + size - 1);
std::string replyCrc(startOfCrc, endOfCrc);
result = recalculatedCrc.compare(replyCrc);
if (result != 0) {
return RETURN_FAILED;
}
@ -247,22 +277,26 @@ ReturnValue_t SyrlinksHkHandler::verifyReply(const uint8_t* packet, uint8_t size
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);
rxDataset.rxStatus = convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
offset += 2;
rxDataset.rxSensitivity = convertHexStringToUint32(reinterpret_cast<const char*>(packet + offset), 6);
offset += 6;
rxDataset.rxFrequencyShift = convertHexStringToUint32(reinterpret_cast<const char*>(packet + offset), 6);
offset += 6;
rxDataset.rxIqPower = convertHexStringToUint16(reinterpret_cast<const char*>(packet + offset));
offset += 4;
rxDataset.rxAgcValue = convertHexStringToUint16(reinterpret_cast<const char*>(packet + offset));
offset += 4;
offset += 2; // reserved register
rxDataset.rxDemodEb= convertHexStringToUint32(reinterpret_cast<const char*>(packet + offset), 6);
offset += 6;
rxDataset.rxDemodN0= convertHexStringToUint32(reinterpret_cast<const char*>(packet + offset), 6);
offset += 6;
rxDataset.rxDataRate = convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
#if OBSW_VERBOSE_LEVEL >= 1 && SYRLINKS_DEBUG == 1
sif::info << "Syrlinks RX Status: " << std::hex << rxDataset.rxStatus << std::endl;
#endif
}
void SyrlinksHkHandler::parseTxStatusReply(const uint8_t* packet) {
@ -283,7 +317,7 @@ ReturnValue_t SyrlinksHkHandler::initializeLocalDataPool(localpool::DataPool& lo
LocalDataPoolManager& poolManager) {
localDataPoolMap.emplace(SYRLINKS::RX_STATUS, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(SYRLINKS::RX_SENSITIVITY, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(SYRLINKS::RX_SENSITIVITY, new PoolEntry<uint32_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 }));

View File

@ -95,7 +95,7 @@ private:
* will return 0xA5.
* @return The converted integer.
*/
uint8_t convertHexStringToUint8(char* twoChars);
uint8_t convertHexStringToUint8(const char* twoChars);
/**
* @brief This function converts a hex number represented by 4 chars to an uint16_t.
@ -104,7 +104,17 @@ private:
*
* @return The uint16_t result.
*/
uint16_t convertHexStringToUint16(char* fourChars);
uint16_t convertHexStringToUint16(const char* fourChars);
/**
* @brief Function converts a hex number represented by 6 or 8 characters to an uint32_t.
*
* @param characters Pointer to the hex characters array.
* @param numberOfChars Number of characters representing the hex value. Must be 6 or 8.
*
* @return The uint32_t value.
*/
uint32_t convertHexStringToUint32(const char* characters, uint8_t numberOfChars);
/**
* @brief This function parses the status reply