meier/master #33
@ -209,43 +209,43 @@ void ObjectFactory::produce(){
|
||||
|
||||
SpiCookie* spiCookieSus1 = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1,
|
||||
std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE,
|
||||
spi::DEFAULT_MAX_1227_SPEED);
|
||||
SUS::SUS_MAX_1227_SPEED);
|
||||
SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2,
|
||||
std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE,
|
||||
spi::DEFAULT_MAX_1227_SPEED);
|
||||
SUS::SUS_MAX_1227_SPEED);
|
||||
SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3,
|
||||
std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE,
|
||||
spi::DEFAULT_MAX_1227_SPEED);
|
||||
SUS::SUS_MAX_1227_SPEED);
|
||||
SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4,
|
||||
std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE,
|
||||
spi::DEFAULT_MAX_1227_SPEED);
|
||||
SUS::SUS_MAX_1227_SPEED);
|
||||
SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5,
|
||||
std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE,
|
||||
spi::DEFAULT_MAX_1227_SPEED);
|
||||
SUS::SUS_MAX_1227_SPEED);
|
||||
SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6,
|
||||
std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE,
|
||||
spi::DEFAULT_MAX_1227_SPEED);
|
||||
SUS::SUS_MAX_1227_SPEED);
|
||||
SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7,
|
||||
std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE,
|
||||
spi::DEFAULT_MAX_1227_SPEED);
|
||||
SUS::SUS_MAX_1227_SPEED);
|
||||
SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpio::NO_GPIO,
|
||||
std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE,
|
||||
spi::DEFAULT_MAX_1227_SPEED);
|
||||
SUS::SUS_MAX_1227_SPEED);
|
||||
SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9,
|
||||
std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE,
|
||||
spi::DEFAULT_MAX_1227_SPEED);
|
||||
SUS::SUS_MAX_1227_SPEED);
|
||||
SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10,
|
||||
std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE,
|
||||
spi::DEFAULT_MAX_1227_SPEED);
|
||||
SUS::SUS_MAX_1227_SPEED);
|
||||
SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11,
|
||||
std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE,
|
||||
spi::DEFAULT_MAX_1227_SPEED);
|
||||
SUS::SUS_MAX_1227_SPEED);
|
||||
SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpioIds::CS_SUS_12,
|
||||
std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE,
|
||||
spi::DEFAULT_MAX_1227_SPEED);
|
||||
SUS::SUS_MAX_1227_SPEED);
|
||||
SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpioIds::CS_SUS_13,
|
||||
std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE,
|
||||
spi::DEFAULT_MAX_1227_SPEED);
|
||||
SUS::SUS_MAX_1227_SPEED);
|
||||
|
||||
SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1, gpioComIF,
|
||||
gpioIds::CS_SUS_1);
|
||||
|
@ -20,8 +20,7 @@ static constexpr spi::SpiModes DEFAULT_RM3100_MODE = spi::SpiModes::MODE_3;
|
||||
static constexpr uint32_t DEFAULT_L3G_SPEED = 3'900'000;
|
||||
static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3;
|
||||
|
||||
//static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000;
|
||||
static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 1000000;
|
||||
static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000;
|
||||
static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_0;
|
||||
|
||||
}
|
||||
|
@ -157,11 +157,47 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence)
|
||||
// thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ);
|
||||
// thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ);
|
||||
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::PERFORM_OPERATION);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_WRITE);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.4, DeviceHandlerIF::GET_WRITE);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.6, DeviceHandlerIF::SEND_READ);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.8, DeviceHandlerIF::GET_READ);
|
||||
if (length != 3) {
|
||||
sif::waring << "pollingSequenceInitDefault: Frequency changed. Make sure timing critical "
|
||||
<< "SUS sensors still produce correct values" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* The sun sensor will be shutdown as soon as the chip select is pulled high. Thus all
|
||||
* requests to a sun sensor must be performed consecutively. Another reason for calling multiple
|
||||
* device handler cycles is that some ADC conversions need a small delay before the results can
|
||||
* be read.
|
||||
* One sun sensor communication sequence also blocks the SPI bus. So other devices can not be
|
||||
* inserted between the device handler cycles of one SUS.
|
||||
*/
|
||||
|
||||
/* Write setup */
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.991, DeviceHandlerIF::PERFORM_OPERATION);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.992, DeviceHandlerIF::SEND_WRITE);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.993, DeviceHandlerIF::GET_WRITE);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.994, DeviceHandlerIF::SEND_READ);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.995, DeviceHandlerIF::GET_READ);
|
||||
|
||||
/* Request temperature */
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.996, DeviceHandlerIF::PERFORM_OPERATION);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.997, DeviceHandlerIF::SEND_WRITE);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.998, DeviceHandlerIF::GET_WRITE);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.999, DeviceHandlerIF::SEND_READ);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.9, DeviceHandlerIF::GET_READ);
|
||||
|
||||
/* Read temperature */
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.901, DeviceHandlerIF::PERFORM_OPERATION);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.902, DeviceHandlerIF::SEND_WRITE);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.903, DeviceHandlerIF::GET_WRITE);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.904, DeviceHandlerIF::SEND_READ);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.905, DeviceHandlerIF::GET_READ);
|
||||
|
||||
/* Request and read ADC conversions */
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.906, DeviceHandlerIF::PERFORM_OPERATION);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.907, DeviceHandlerIF::SEND_WRITE);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.908, DeviceHandlerIF::GET_WRITE);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.909, DeviceHandlerIF::SEND_READ);
|
||||
thisSequence->addSlot(objects::SUS_8, length * 0.91, DeviceHandlerIF::GET_READ);
|
||||
|
||||
// thisSequence->addSlot(objects::SUS_11, length * 0, DeviceHandlerIF::PERFORM_OPERATION);
|
||||
// thisSequence->addSlot(objects::SUS_11, length * 0.2, DeviceHandlerIF::SEND_WRITE);
|
||||
|
@ -9,6 +9,9 @@ SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCo
|
||||
if (comCookie == NULL) {
|
||||
sif::error << "SusHandler: Invalid com cookie" << std::endl;
|
||||
}
|
||||
if (gpioComIF == NULL) {
|
||||
sif::error << "SusHandler: Invalid GpioComIF" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
SusHandler::~SusHandler() {
|
||||
@ -16,13 +19,11 @@ SusHandler::~SusHandler() {
|
||||
|
||||
|
||||
void SusHandler::doStartUp(){
|
||||
if (internalState == InternalState::CONFIGURED) {
|
||||
#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1
|
||||
setMode(MODE_NORMAL);
|
||||
setMode(MODE_NORMAL);
|
||||
#else
|
||||
setMode(_MODE_TO_ON);
|
||||
setMode(_MODE_TO_ON);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void SusHandler::doShutDown(){
|
||||
@ -33,34 +34,26 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand(
|
||||
DeviceCommandId_t * id) {
|
||||
if (communicationStep == CommunicationStep::WRITE_SETUP) {
|
||||
*id = SUS::WRITE_SETUP;
|
||||
communicationStep = CommunicationStep::REQUEST_TEMP;
|
||||
// communicationStep = CommunicationStep::PERFORM_CONVERSIONS;
|
||||
communicationStep = CommunicationStep::REQUEST_TEMPERATURE;
|
||||
}
|
||||
else if (communicationStep == CommunicationStep::PERFORM_CONVERSIONS) {
|
||||
*id = SUS::PERFORM_CONVERSIONS;
|
||||
else if (communicationStep == CommunicationStep::REQUEST_TEMPERATURE) {
|
||||
*id = SUS::REQUEST_TEMPERATURE;
|
||||
communicationStep = CommunicationStep::READ_TEMPERATURE;
|
||||
}
|
||||
else if (communicationStep == CommunicationStep::READ_TEMPERATURE) {
|
||||
*id = SUS::READ_TEMPERATURE;
|
||||
communicationStep = CommunicationStep::READ_CHANNELS;
|
||||
}
|
||||
else if (communicationStep == CommunicationStep::READ_CHANNELS) {
|
||||
*id = SUS::READ_CHANNELS;
|
||||
communicationStep = CommunicationStep::WRITE_SETUP;
|
||||
// communicationStep = CommunicationStep::PERFORM_CONVERSIONS;
|
||||
}
|
||||
else if (communicationStep == CommunicationStep::REQUEST_TEMP) {
|
||||
*id = SUS::RQUEST_TEMP;
|
||||
communicationStep = CommunicationStep::READ_TEMP;
|
||||
}
|
||||
else if (communicationStep == CommunicationStep::READ_TEMP) {
|
||||
*id = SUS::READ_TEMP;
|
||||
communicationStep = CommunicationStep::PERFORM_CONVERSIONS;
|
||||
}
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
|
||||
ReturnValue_t SusHandler::buildTransitionDeviceCommand(
|
||||
DeviceCommandId_t * id){
|
||||
if (internalState == InternalState::SETUP) {
|
||||
*id = SUS::WRITE_SETUP;
|
||||
}
|
||||
else {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t SusHandler::buildCommandFromCommand(
|
||||
@ -68,59 +61,46 @@ ReturnValue_t SusHandler::buildCommandFromCommand(
|
||||
size_t commandDataLen) {
|
||||
switch(deviceCommand) {
|
||||
case(SUS::WRITE_SETUP): {
|
||||
/**
|
||||
* The sun sensor ADC is shutdown when CS is pulled high, so each time requesting a
|
||||
* measurement the setup has to be rewritten. There must also be a little delay between
|
||||
* the transmission of the setup byte and the first conversion. Thus the conversion
|
||||
* will be performed in an extra step.
|
||||
*/
|
||||
//TODO: Protect spi bus with mutex
|
||||
gpioComIF->pullLow(chipSelectId);
|
||||
cmdBuffer[0] = SUS::SETUP_DEFINITION;
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = 1;
|
||||
internalState = InternalState::CONFIGURED;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case(SUS::PERFORM_CONVERSIONS): {
|
||||
// gpioComIF->pullLow(chipSelectId);
|
||||
case(SUS::READ_CHANNELS): {
|
||||
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
|
||||
/**
|
||||
* The sun sensor ADC is shutdown when CS is pulled high so each time requesting a
|
||||
* measurement the setup has to be rewritten
|
||||
*/
|
||||
// cmdBuffer[0] = SUS::RESET_FIFO;
|
||||
cmdBuffer[0] = SUS::SETUP_DEFINITION;
|
||||
// wirte one dummy byte here
|
||||
// cmdBuffer[2] = SUS::CONVERT_TEMPERATURE;
|
||||
cmdBuffer[1] = SUS::CONVERT_DIFF_CHANNEL_0;
|
||||
cmdBuffer[2] = SUS::DUMMY_BYTE;
|
||||
cmdBuffer[3] = SUS::CONVERT_DIFF_CHANNEL_1;
|
||||
cmdBuffer[4] = SUS::DUMMY_BYTE;
|
||||
cmdBuffer[5] = SUS::CONVERT_DIFF_CHANNEL_2;
|
||||
cmdBuffer[6] = SUS::DUMMY_BYTE;
|
||||
cmdBuffer[7] = SUS::CONVERT_DIFF_CHANNEL_3;
|
||||
cmdBuffer[8] = SUS::DUMMY_BYTE;
|
||||
cmdBuffer[9] = SUS::CONVERT_DIFF_CHANNEL_4;
|
||||
cmdBuffer[10] = SUS::DUMMY_BYTE;
|
||||
cmdBuffer[11] = SUS::CONVERT_DIFF_CHANNEL_5;
|
||||
cmdBuffer[0] = SUS::CONVERT_DIFF_CHANNEL_0;
|
||||
cmdBuffer[1] = SUS::DUMMY_BYTE;
|
||||
cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_1;
|
||||
cmdBuffer[3] = SUS::DUMMY_BYTE;
|
||||
cmdBuffer[4] = SUS::CONVERT_DIFF_CHANNEL_2;
|
||||
cmdBuffer[5] = SUS::DUMMY_BYTE;
|
||||
cmdBuffer[6] = SUS::CONVERT_DIFF_CHANNEL_3;
|
||||
cmdBuffer[7] = SUS::DUMMY_BYTE;
|
||||
cmdBuffer[8] = SUS::CONVERT_DIFF_CHANNEL_4;
|
||||
cmdBuffer[9] = SUS::DUMMY_BYTE;
|
||||
cmdBuffer[10] = SUS::CONVERT_DIFF_CHANNEL_5;
|
||||
cmdBuffer[11] = SUS::DUMMY_BYTE;
|
||||
cmdBuffer[12] = SUS::DUMMY_BYTE;
|
||||
cmdBuffer[13] = SUS::DUMMY_BYTE;
|
||||
// cmdBuffer[0] = SUS::SETUP_DEFINITION;
|
||||
// cmdBuffer[1] = SUS::UNIPOLAR_CONFIG;
|
||||
// cmdBuffer[2] = SUS::CONVERT_TEMPERATURE;
|
||||
// cmdBuffer[26] = SUS::CONVERT_DIFF_CHANNEL_0_1;
|
||||
// cmdBuffer[28] = SUS::CONVERT_DIFF_CHANNEL_2_3;
|
||||
// cmdBuffer[30] = SUS::CONVERT_DIFF_CHANNEL_4_5;
|
||||
rawPacket = cmdBuffer;
|
||||
// rawPacketLen = SUS::SIZE_PERFORM_CONVERSIONS;
|
||||
rawPacketLen = 14;
|
||||
rawPacketLen = SUS::SIZE_READ_CHANNELS;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case(SUS::RQUEST_TEMP): {
|
||||
// gpioComIF->pullLow(chipSelectId);
|
||||
case(SUS::REQUEST_TEMPERATURE): {
|
||||
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
|
||||
// cmdBuffer[0] = SUS::RESET_FIFO;
|
||||
// cmdBuffer[1] = SUS::SETUP_DEFINITION;
|
||||
cmdBuffer[0] = SUS::CONVERT_TEMPERATURE;
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = 1;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case(SUS::READ_TEMP): {
|
||||
case(SUS::READ_TEMPERATURE): {
|
||||
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = 24;
|
||||
@ -134,12 +114,10 @@ ReturnValue_t SusHandler::buildCommandFromCommand(
|
||||
|
||||
void SusHandler::fillCommandAndReplyMap() {
|
||||
this->insertInCommandMap(SUS::WRITE_SETUP);
|
||||
// this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, &dataset, SUS::SIZE_PERFORM_CONVERSIONS);
|
||||
this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset, SUS::SIZE_PERFORM_CONVERSIONS);
|
||||
this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, nullptr, SUS::SIZE_PERFORM_CONVERSIONS);
|
||||
// this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset,
|
||||
// SUS::SIZE_PERFORM_CONVERSIONS);
|
||||
this->insertInCommandMap(SUS::RQUEST_TEMP);
|
||||
this->insertInCommandMap(SUS::REQUEST_TEMPERATURE);
|
||||
this->insertInCommandAndReplyMap(SUS::READ_CHANNELS, 1, &dataset, SUS::SIZE_READ_CHANNELS);
|
||||
this->insertInCommandAndReplyMap(SUS::READ_TEMPERATURE, 1, nullptr,
|
||||
SUS::SIZE_READ_TEMPERATURE);
|
||||
}
|
||||
|
||||
ReturnValue_t SusHandler::scanForReply(const uint8_t *start,
|
||||
@ -152,27 +130,42 @@ ReturnValue_t SusHandler::scanForReply(const uint8_t *start,
|
||||
ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) {
|
||||
switch (id) {
|
||||
case SUS::PERFORM_CONVERSIONS: {
|
||||
gpioComIF->pullHigh(chipSelectId);
|
||||
case SUS::READ_CHANNELS: {
|
||||
PoolReadGuard readSet(&dataset);
|
||||
dataset.temperatureCelcius = (*(packet + 25) << 8 | *(packet + 26)) * 0.125;
|
||||
dataset.diffScanChannel0_1 = (*(packet + 29) << 8 | *(packet + 30));
|
||||
dataset.diffScanChannel2_3 = (*(packet + 31) << 8 | *(packet + 32));
|
||||
dataset.diffScanChannel4_5 = (*(packet + 33) << 8 | *(packet + 34));
|
||||
dataset.ain0 = (*(packet + 1) << 8 | *(packet + 2));
|
||||
dataset.ain1 = (*(packet + 3) << 8 | *(packet + 4));
|
||||
dataset.ain2 = (*(packet + 5) << 8 | *(packet + 6));
|
||||
dataset.ain3 = (*(packet + 7) << 8 | *(packet + 8));
|
||||
dataset.ain4 = (*(packet + 9) << 8 | *(packet + 10));
|
||||
dataset.ain5 = (*(packet + 11) << 8 | *(packet + 12));
|
||||
#if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS
|
||||
sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", temperature: "
|
||||
<< dataset.temperatureCelcius << " °C" << std::endl;
|
||||
sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 0/1: "
|
||||
<< dataset.diffScanChannel0_1 << std::endl;
|
||||
sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 2/3: "
|
||||
<< dataset.diffScanChannel2_3 << std::endl;
|
||||
sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 4/5: "
|
||||
<< dataset.diffScanChannel4_5 << std::endl;
|
||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN0: "
|
||||
<< std::dec << dataset.ain0 << std::endl;
|
||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN1: "
|
||||
<< std::dec << dataset.ain1 << std::endl;
|
||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN2: "
|
||||
<< std::dec << dataset.ain2 << std::endl;
|
||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN3: "
|
||||
<< std::dec << dataset.ain3 << std::endl;
|
||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN4: "
|
||||
<< std::dec << dataset.ain4 << std::endl;
|
||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN5: "
|
||||
<< std::dec << dataset.ain5 << std::endl;
|
||||
#endif
|
||||
/**
|
||||
* Reading the channel conversion results is the last communication step in one SUS
|
||||
* sequence. SPI bus can now be released again.
|
||||
*/
|
||||
gpioComIF->pullHigh(chipSelectId);
|
||||
break;
|
||||
}
|
||||
case SUS::READ_TEMP: {
|
||||
// gpioComIF->pullHigh(chipSelectId);
|
||||
case SUS::READ_TEMPERATURE: {
|
||||
PoolReadGuard readSet(&dataset);
|
||||
dataset.temperatureCelcius = (*(packet + 22) << 8 | *(packet + 23)) * 0.125;
|
||||
#if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS
|
||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", temperature: "
|
||||
<< dataset.temperatureCelcius << " °C" << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -189,15 +182,18 @@ void SusHandler::setNormalDatapoolEntriesInvalid(){
|
||||
}
|
||||
|
||||
uint32_t SusHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){
|
||||
return 5000;
|
||||
return 1000;
|
||||
}
|
||||
|
||||
ReturnValue_t SusHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) {
|
||||
localDataPoolMap.emplace(SUS::TEMPERATURE_C, new PoolEntry<float>( { 0.0 }));
|
||||
localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_0_1, new PoolEntry<uint16_t>( { 0 }));
|
||||
localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_2_3, new PoolEntry<uint16_t>( { 0 }));
|
||||
localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_4_5, new PoolEntry<uint16_t>( { 0 }));
|
||||
localDataPoolMap.emplace(SUS::AIN0, new PoolEntry<uint16_t>( { 0 }));
|
||||
localDataPoolMap.emplace(SUS::AIN1, new PoolEntry<uint16_t>( { 0 }));
|
||||
localDataPoolMap.emplace(SUS::AIN2, new PoolEntry<uint16_t>( { 0 }));
|
||||
localDataPoolMap.emplace(SUS::AIN3, new PoolEntry<uint16_t>( { 0 }));
|
||||
localDataPoolMap.emplace(SUS::AIN4, new PoolEntry<uint16_t>( { 0 }));
|
||||
localDataPoolMap.emplace(SUS::AIN5, new PoolEntry<uint16_t>( { 0 }));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
@ -41,15 +41,10 @@ protected:
|
||||
private:
|
||||
|
||||
enum class CommunicationStep {
|
||||
PERFORM_CONVERSIONS,
|
||||
REQUEST_TEMP,
|
||||
READ_TEMP,
|
||||
WRITE_SETUP
|
||||
};
|
||||
|
||||
enum class InternalState {
|
||||
SETUP,
|
||||
CONFIGURED
|
||||
WRITE_SETUP,
|
||||
REQUEST_TEMPERATURE,
|
||||
READ_TEMPERATURE,
|
||||
READ_CHANNELS
|
||||
};
|
||||
|
||||
LinuxLibgpioIF* gpioComIF = nullptr;
|
||||
@ -59,7 +54,6 @@ private:
|
||||
SUS::SusDataset dataset;
|
||||
|
||||
uint8_t cmdBuffer[SUS::MAX_CMD_SIZE];
|
||||
InternalState internalState = InternalState::SETUP;
|
||||
CommunicationStep communicationStep = CommunicationStep::WRITE_SETUP;
|
||||
};
|
||||
|
||||
|
@ -3,6 +3,12 @@
|
||||
|
||||
namespace SUS {
|
||||
|
||||
/**
|
||||
* The MAX1227 in externally clocked mode did not properly work with frequencies higher than
|
||||
* 1 MHz.
|
||||
*/
|
||||
static const uint32_t SUS_MAX_1227_SPEED = 1000000;
|
||||
|
||||
static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending
|
||||
|
||||
/**
|
||||
@ -10,9 +16,9 @@ namespace SUS {
|
||||
* temperature sensor.
|
||||
*/
|
||||
static const DeviceCommandId_t WRITE_SETUP = 0x1;
|
||||
static const DeviceCommandId_t PERFORM_CONVERSIONS = 0x2;
|
||||
static const DeviceCommandId_t READ_TEMP = 0x3;
|
||||
static const DeviceCommandId_t RQUEST_TEMP = 0x4;
|
||||
static const DeviceCommandId_t READ_CHANNELS = 0x2;
|
||||
static const DeviceCommandId_t READ_TEMPERATURE = 0x3;
|
||||
static const DeviceCommandId_t REQUEST_TEMPERATURE = 0x4;
|
||||
|
||||
/**
|
||||
* @brief This is the configuration byte which will be written to the setup register after
|
||||
@ -47,21 +53,28 @@ namespace SUS {
|
||||
|
||||
static const uint8_t DUMMY_BYTE = 0x0;
|
||||
|
||||
static const uint8_t SUS_DATA_SET_ID = PERFORM_CONVERSIONS;
|
||||
static const uint8_t SUS_DATA_SET_ID = READ_CHANNELS;
|
||||
|
||||
static const uint8_t SIZE_PERFORM_CONVERSIONS = 34;
|
||||
/** Size of data replies */
|
||||
static const uint8_t SIZE_READ_CHANNELS = 13;
|
||||
static const uint8_t SIZE_READ_TEMPERATURE = 25;
|
||||
|
||||
static const uint8_t MAX_CMD_SIZE = SIZE_PERFORM_CONVERSIONS;
|
||||
static const uint8_t MAX_CMD_SIZE = SIZE_READ_TEMPERATURE;
|
||||
|
||||
static const uint8_t POOL_ENTRIES = 7;
|
||||
|
||||
|
||||
enum Max1227PoolIds: lp_id_t {
|
||||
TEMPERATURE_C,
|
||||
DIFF_SCAN_CHANNEL_0_1,
|
||||
DIFF_SCAN_CHANNEL_2_3,
|
||||
DIFF_SCAN_CHANNEL_4_5,
|
||||
AIN0,
|
||||
AIN1,
|
||||
AIN2,
|
||||
AIN3,
|
||||
AIN4,
|
||||
AIN5,
|
||||
};
|
||||
|
||||
class SusDataset: public StaticLocalDataSet<sizeof(float)> {
|
||||
class SusDataset: public StaticLocalDataSet<POOL_ENTRIES> {
|
||||
public:
|
||||
|
||||
SusDataset(HasLocalDataPoolIF* owner) :
|
||||
@ -73,9 +86,12 @@ public:
|
||||
}
|
||||
|
||||
lp_var_t<float> temperatureCelcius = lp_var_t<float>(sid.objectId, TEMPERATURE_C, this);
|
||||
lp_var_t<uint16_t> diffScanChannel0_1 = lp_var_t<uint16_t>(sid.objectId, DIFF_SCAN_CHANNEL_0_1, this);
|
||||
lp_var_t<uint16_t> diffScanChannel2_3 = lp_var_t<uint16_t>(sid.objectId, DIFF_SCAN_CHANNEL_2_3, this);
|
||||
lp_var_t<uint16_t> diffScanChannel4_5 = lp_var_t<uint16_t>(sid.objectId, DIFF_SCAN_CHANNEL_4_5, this);
|
||||
lp_var_t<uint16_t> ain0 = lp_var_t<uint16_t>(sid.objectId, AIN0, this);
|
||||
lp_var_t<uint16_t> ain1 = lp_var_t<uint16_t>(sid.objectId, AIN1, this);
|
||||
lp_var_t<uint16_t> ain2 = lp_var_t<uint16_t>(sid.objectId, AIN2, this);
|
||||
lp_var_t<uint16_t> ain3 = lp_var_t<uint16_t>(sid.objectId, AIN3, this);
|
||||
lp_var_t<uint16_t> ain4 = lp_var_t<uint16_t>(sid.objectId, AIN4, this);
|
||||
lp_var_t<uint16_t> ain5 = lp_var_t<uint16_t>(sid.objectId, AIN5, this);
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user