added readout of some tx registers

This commit is contained in:
Jakob Meier 2021-02-27 11:07:42 +01:00
parent be7b895b17
commit f761789154
5 changed files with 145 additions and 20 deletions

View File

@ -125,37 +125,37 @@ void ObjectFactory::produce(){
new LinuxLibgpioIF(objects::GPIO_IF);
#if TE0720 == 0
/* Pin H2-11 on stack connector */
GpioConfig_t gpioConfigHeater0(std::string("gpiochip7"), 18,
GpioConfig_t gpioConfigHeater0(std::string("gpiochip7"), 15,
std::string("Heater0"), gpio::OUT, 0);
heaterGpiosCookie->addGpio(gpioIds::HEATER_0, gpioConfigHeater0);
/* Pin H2-12 on stack connector */
GpioConfig_t gpioConfigHeater1(std::string("gpiochip7"), 14,
GpioConfig_t gpioConfigHeater1(std::string("gpiochip7"), 11,
std::string("Heater1"), gpio::OUT, 0);
heaterGpiosCookie->addGpio(gpioIds::HEATER_1, gpioConfigHeater1);
/* Pin H2-13 on stack connector */
GpioConfig_t gpioConfigHeater2(std::string("gpiochip7"), 20,
GpioConfig_t gpioConfigHeater2(std::string("gpiochip7"), 17,
std::string("Heater2"), gpio::OUT, 0);
heaterGpiosCookie->addGpio(gpioIds::HEATER_2, gpioConfigHeater2);
GpioConfig_t gpioConfigHeater3(std::string("gpiochip7"), 16,
GpioConfig_t gpioConfigHeater3(std::string("gpiochip7"), 13,
std::string("Heater3"), gpio::OUT, 0);
heaterGpiosCookie->addGpio(gpioIds::HEATER_3, gpioConfigHeater3);
GpioConfig_t gpioConfigHeater4(std::string("gpiochip7"), 24,
GpioConfig_t gpioConfigHeater4(std::string("gpiochip7"), 21,
std::string("Heater4"), gpio::OUT, 0);
heaterGpiosCookie->addGpio(gpioIds::HEATER_4, gpioConfigHeater4);
GpioConfig_t gpioConfigHeater5(std::string("gpiochip7"), 26,
GpioConfig_t gpioConfigHeater5(std::string("gpiochip7"), 23,
std::string("Heater5"), gpio::OUT, 0);
heaterGpiosCookie->addGpio(gpioIds::HEATER_5, gpioConfigHeater5);
GpioConfig_t gpioConfigHeater6(std::string("gpiochip7"), 22,
GpioConfig_t gpioConfigHeater6(std::string("gpiochip7"), 19,
std::string("Heater6"), gpio::OUT, 0);
heaterGpiosCookie->addGpio(gpioIds::HEATER_6, gpioConfigHeater6);
GpioConfig_t gpioConfigHeater7(std::string("gpiochip7"), 28,
GpioConfig_t gpioConfigHeater7(std::string("gpiochip7"), 10,
std::string("Heater7"), gpio::OUT, 0);
heaterGpiosCookie->addGpio(gpioIds::HEATER_7, gpioConfigHeater7);
@ -163,10 +163,10 @@ void ObjectFactory::produce(){
pcduSwitches::TCS_BOARD_8V_HEATER_IN);
GpioCookie* solarArrayDeplCookie = new GpioCookie;
GpioConfig_t gpioConfigDeplSA1(std::string("gpiochip7"), 25,
GpioConfig_t gpioConfigDeplSA1(std::string("gpiochip7"), 22,
std::string("DeplSA1"), gpio::OUT, 0);
solarArrayDeplCookie->addGpio(gpioIds::DEPLSA1, gpioConfigDeplSA1);
GpioConfig_t gpioConfigDeplSA2(std::string("gpiochip7"), 23,
GpioConfig_t gpioConfigDeplSA2(std::string("gpiochip7"), 20,
std::string("DeplSA2"), gpio::OUT, 0);
solarArrayDeplCookie->addGpio(gpioIds::DEPLSA2, gpioConfigDeplSA2);
@ -175,8 +175,10 @@ void ObjectFactory::produce(){
solarArrayDeplCookie, objects::PCDU_HANDLER, pcduSwitches::DEPLOYMENT_MECHANISM,
gpioIds::DEPLSA1, gpioIds::DEPLSA2, 1000);
// UartCookie* syrlinksUartCookie = new UartCookie(
// std::string("/dev/ttyPS1"), 38400, SYRLINKS::MAX_REPLY_SIZE);
UartCookie* syrlinksUartCookie = new UartCookie(
std::string("/dev/ttyPS1"), 38400, SYRLINKS::MAX_REPLY_SIZE);
std::string("/dev/ttyUL0"), 38400, SYRLINKS::MAX_REPLY_SIZE);
syrlinksUartCookie->setParityEven();
SyrlinksHkHandler* syrlinksHkHandler = new SyrlinksHkHandler(objects::SYRLINKS_HK_HANDLER, objects::UART_COM_IF, syrlinksUartCookie);

View File

@ -68,7 +68,8 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap* mapToAdd) {
lineNum = mapToAddIter->second.lineNum;
lineHandle = gpiod_chip_get_line(chip, lineNum);
if (!lineHandle) {
sif::error << "LinuxLibgpioIF::configureGpios: Failed to open line" << std::endl;
sif::error << "LinuxLibgpioIF::configureGpios: Failed to open line for GPIO with id "
<< mapToAddIter->first << std::endl;
gpiod_chip_close(chip);
return RETURN_FAILED;
}

View File

@ -77,6 +77,20 @@ ReturnValue_t SyrlinksHkHandler::buildCommandFromCommand(
rawPacket = commandBuffer;
return RETURN_OK;
}
case(SYRLINKS::READ_TX_WAVEFORM): {
readTxWaveform.copy(reinterpret_cast<char*>(commandBuffer), readTxStatus.size(), 0);
rawPacketLen = readTxWaveform.size();
rememberCommandId = SYRLINKS::READ_TX_WAVEFORM;
rawPacket = commandBuffer;
return RETURN_OK;
}
case(SYRLINKS::READ_TX_AGC_VALUE): {
readTxAgcValue.copy(reinterpret_cast<char*>(commandBuffer), readTxStatus.size(), 0);
rawPacketLen = readTxAgcValue.size();
rememberCommandId = SYRLINKS::READ_TX_AGC_VALUE;
rawPacket = commandBuffer;
return RETURN_OK;
}
default:
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
@ -118,6 +132,7 @@ ReturnValue_t SyrlinksHkHandler::scanForReply(const uint8_t *start,
*foundId = SYRLINKS::READ_RX_STATUS_REGISTERS;
break;
case('R'):
getIdAndLenForReadResponse(foundId, foundLen);
if (rememberCommandId == SYRLINKS::READ_TX_STATUS) {
*foundLen = SYRLINKS::READ_TX_STATUS_REPLY_SIZE;
*foundId = SYRLINKS::READ_TX_STATUS;
@ -169,6 +184,24 @@ ReturnValue_t SyrlinksHkHandler::interpretDeviceReply(DeviceCommandId_t id,
}
parseTxStatusReply(packet);
break;
case(SYRLINKS::READ_TX_WAVEFORM):
result = verifyReply(packet, SYRLINKS::READ_TX_WAVEFORM_REPLY_SIZE);
if (result != RETURN_OK) {
sif::error << "SyrlinksHkHandler::interpretDeviceReply: Read tx waveform reply "
<< "has invalid crc" << std::endl;
return CRC_FAILURE;
}
parseTxWaveformReply(packet);
break;
case(SYRLINKS::READ_TX_AGC_VALUE):
result = verifyReply(packet, SYRLINKS::READ_TX_AGC_VALUE_REPLY_SIZE);
if (result != RETURN_OK) {
sif::error << "SyrlinksHkHandler::interpretDeviceReply: Read tx AGC reply "
<< "has invalid crc" << std::endl;
return CRC_FAILURE;
}
parseTxAgcValueReply(packet);
break;
default: {
sif::debug << "SyrlinksHkHandler::interpretDeviceReply: Unknown device reply id"
<< std::endl;
@ -179,19 +212,41 @@ ReturnValue_t SyrlinksHkHandler::interpretDeviceReply(DeviceCommandId_t id,
return RETURN_OK;
}
std::string SyrlinksHkHandler::convertIntToHexString(uint16_t intValue) {
void SyrlinksHkHandler::getIdAndLenForReadResponse(DeviceCommandId_t *foundId, size_t *foundLen) {
switch (rememberCommandId) {
case(SYRLINKS::READ_TX_STATUS):
*foundLen = SYRLINKS::READ_TX_STATUS_REPLY_SIZE;
*foundId = SYRLINKS::READ_TX_STATUS;
break;
case(SYRLINKS::READ_TX_WAVEFORM):
*foundLen = SYRLINKS::READ_TX_WAVEFORM_REPLY_SIZE;
*foundId = SYRLINKS::READ_TX_WAVEFORM;
break;
case(SYRLINKS::READ_TX_AGC_VALUE):
*foundLen = SYRLINKS::READ_TX_AGC_VALUE_REPLY_SIZE;
*foundId = SYRLINKS::READ_TX_AGC_VALUE;
break;
default:
sif::debug << "SyrlinksHkHandler::getIdAndLenForReadResponse: No command id remembered"
<< std::endl;
break;
}
rememberCommandId = SYRLINKS::NONE;
}
std::string SyrlinksHkHandler::convertUint16ToHexString(uint16_t intValue) {
std::stringstream stream;
stream << std::hex << std::uppercase << intValue;
stream << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << intValue;
return stream.str();
}
uint8_t SyrlinksHkHandler::convertHexStringToUint8(const char* twoChars) {
uint8_t value;
uint32_t value;
std::string hexString(twoChars, 2);
std::stringstream stream;
stream << std::hex << hexString;
stream >> value;
return value;
return static_cast<uint8_t>(value);
}
uint16_t SyrlinksHkHandler::convertHexStringToUint16(const char* fourChars) {
@ -260,7 +315,7 @@ ReturnValue_t SyrlinksHkHandler::verifyReply(const uint8_t* packet, uint8_t size
/* 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);
std::string recalculatedCrc = convertUint16ToHexString(crc);
const char* startOfCrc = reinterpret_cast<const char*>(packet + size - SYRLINKS::SIZE_CRC_AND_TERMINATION);
const char* endOfCrc = reinterpret_cast<const char*>(packet + size - 1);
@ -295,14 +350,44 @@ void SyrlinksHkHandler::parseRxStatusRegistersReply(const uint8_t* packet) {
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;
sif::info << "Syrlinks RX Status: 0x" << std::hex << (unsigned int)rxDataset.rxStatus.value << std::endl;
sif::info << "Syrlinks RX Sensitivity: " << rxDataset.rxSensitivity << std::endl;
sif::info << "Syrlinks RX Frequency Shift: " << rxDataset.rxFrequencyShift << std::endl;
sif::info << "Syrlinks RX IQ Power: " << rxDataset.rxIqPower << std::endl;
sif::info << "Syrlinks RX AGC Value: " << rxDataset.rxAgcValue << std::endl;
sif::info << "Syrlinks RX Demod Eb: " << rxDataset.rxDemodEb << std::endl;
sif::info << "Syrlinks RX Demod N0: " << rxDataset.rxDemodN0 << std::endl;
sif::info << "Syrlinks RX Datarate: " << (unsigned int)rxDataset.rxDataRate.value << std::endl;
#endif
}
void SyrlinksHkHandler::parseTxStatusReply(const uint8_t* packet) {
PoolReadHelper readHelper(&txDataset);
uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE;
rxDataset.rxStatus = *(packet + offset);
txDataset.txStatus = convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
#if OBSW_VERBOSE_LEVEL >= 1 && SYRLINKS_DEBUG == 1
sif::info << "Syrlinks TX Status: 0x" << std::hex << (unsigned int) txDataset.txStatus.value
<< std::endl;
#endif
}
void SyrlinksHkHandler::parseTxWaveformReply(const uint8_t* packet) {
PoolReadHelper readHelper(&txDataset);
uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE;
txDataset.txWaveform = convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
#if OBSW_VERBOSE_LEVEL >= 1 && SYRLINKS_DEBUG == 1
sif::info << "Syrlinks TX Waveform: 0x" << std::hex << (unsigned int) txDataset.txWaveform.value
<< std::endl;
#endif
}
void SyrlinksHkHandler::parseTxAgcValueReply(const uint8_t* packet) {
PoolReadHelper readHelper(&txDataset);
uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE;
txDataset.txAgcValue = convertHexStringToUint16(reinterpret_cast<const char*>(packet + offset));
#if OBSW_VERBOSE_LEVEL >= 1 && SYRLINKS_DEBUG == 1
sif::info << "Syrlinks TX AGC Value: " << txDataset.txAgcValue << std::endl;
#endif
}
void SyrlinksHkHandler::setNormalDatapoolEntriesInvalid(){
@ -325,6 +410,10 @@ ReturnValue_t SyrlinksHkHandler::initializeLocalDataPool(localpool::DataPool& lo
localDataPoolMap.emplace(SYRLINKS::RX_DEMOD_N0, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(SYRLINKS::RX_DATA_RATE, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(SYRLINKS::TX_STATUS, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(SYRLINKS::TX_WAVEFORM, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(SYRLINKS::TX_AGC_VALUE, new PoolEntry<uint16_t>( { 0 }));
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -65,6 +65,8 @@ private:
std::string setTxModeModulation = "<W04:0140:5D2A>";
std::string setTxModeCw = "<W04:1040:81CF>";
std::string readTxStatus = "<R02:40:7555>";
std::string readTxWaveform = "<R02:44:B991>";
std::string readTxAgcValue = "<R02:46:DFF3>";
/**
* In some cases it is not possible to extract from the received reply the information about
@ -77,6 +79,21 @@ private:
uint8_t commandBuffer[SYRLINKS::MAX_COMMAND_SIZE];
/**
* @brief This function gets the command id relating to a received read response 'R'.
*
* @param foundId Pointer to object where found id will be stored.
* @param foundLen Pointer to objet where reply length of the received response will be
* stored.
*/
void getIdAndLenForReadResponse(DeviceCommandId_t *foundId, size_t *foundLen);
/**
* This object is used to store the id of the next command to execute. This controls the
* read out of multiple registers which can not be fetched with one single command.
*/
DeviceCommandId_t nextCommand = SYRLINKS::READ_RX_STATUS_REGISTERS;
/**
* @brief This function converts an uint16_t into its hexadecimal string representation.
*
@ -84,7 +101,7 @@ private:
*
* @return An std::string object containing the hex representation of intValue.
*/
std::string convertIntToHexString(uint16_t intValue);
std::string convertUint16ToHexString(uint16_t intValue);
/**
* @brief This function converts a hex number represented by to chars to an 8-bit integer.
@ -149,6 +166,16 @@ private:
* @param packet Pointer to the received packet.
*/
void parseTxStatusReply(const uint8_t* packet);
/**
* @brief This function writes the received waveform configuration to the txDataset.
*/
void parseTxWaveformReply(const uint8_t* packet);
/**
* @brief This function writes the received AGC value to the txDataset.
*/
void parseTxAgcValueReply(const uint8_t* packet);
};
#endif /* MISSION_DEVICES_SYRLINKSHKHANDLER_H_ */

View File

@ -16,6 +16,8 @@ namespace SYRLINKS {
static const DeviceCommandId_t SET_TX_MODE_CW = 0x05;
static const DeviceCommandId_t ACK_REPLY = 0x06;
static const DeviceCommandId_t READ_TX_STATUS = 0x07;
static const DeviceCommandId_t READ_TX_WAVEFORM = 0x08;
static const DeviceCommandId_t READ_TX_AGC_VALUE = 0x09;
/** Size of a simple transmission success response */
static const uint8_t ACK_SIZE = 11;
@ -25,6 +27,8 @@ namespace SYRLINKS {
/** Size of reply to an rx status registers request */
static const uint8_t RX_STATUS_REGISTERS_REPLY_SIZE = 49;
static const uint8_t READ_TX_STATUS_REPLY_SIZE = 13;
static const uint8_t READ_TX_WAVEFORM_REPLY_SIZE = 13;
static const uint8_t READ_TX_AGC_VALUE_REPLY_SIZE = 15;
static const uint8_t RX_DATASET_ID = READ_RX_STATUS_REGISTERS;
static const uint8_t TX_DATASET_ID = READ_TX_STATUS;
@ -88,6 +92,8 @@ public:
}
lp_var_t<uint8_t> txStatus = lp_var_t<uint8_t>(sid.objectId, TX_STATUS, this);
lp_var_t<uint8_t> txWaveform = lp_var_t<uint8_t>(sid.objectId, TX_WAVEFORM, this);
lp_var_t<uint16_t> txAgcValue = lp_var_t<uint16_t>(sid.objectId, TX_AGC_VALUE, this);
};
}