From 0a4a7de58e0f02ffc8374f42d974da904395a3b6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 3 Dec 2020 12:49:14 +0100 Subject: [PATCH 01/27] taken over source lis3mdl device --- mission/devices/MGMHandlerLIS3MDL.cpp | 205 ++++++++++++++++---------- mission/devices/MGMHandlerLIS3MDL.h | 34 ++++- 2 files changed, 158 insertions(+), 81 deletions(-) diff --git a/mission/devices/MGMHandlerLIS3MDL.cpp b/mission/devices/MGMHandlerLIS3MDL.cpp index 099f0da4..77b1a300 100644 --- a/mission/devices/MGMHandlerLIS3MDL.cpp +++ b/mission/devices/MGMHandlerLIS3MDL.cpp @@ -1,13 +1,18 @@ #include "MGMHandlerLIS3MDL.h" + MGMHandlerLIS3MDL::MGMHandlerLIS3MDL(object_id_t objectId, object_id_t deviceCommunication, CookieIF* comCookie): DeviceHandlerBase(objectId, deviceCommunication, comCookie) { - registers[0] = 0x00; - registers[1] = 0x00; - registers[2] = 0x00; - registers[3] = 0x00; - registers[4] = 0x00; +#if OBSW_ENHANCED_PRINTOUT == 1 + debugDivider = new PeriodicOperationDivider(10); +#endif + // Set to default values right away. + registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT; + registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT; + registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT; + registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT; + registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT; } @@ -29,18 +34,14 @@ void MGMHandlerLIS3MDL::doStartUp() { internalState = STATE_CHECK_REGISTERS; break; - case STATE_CHECK_REGISTERS: - if (setupMGM() == RETURN_OK) { - for (size_t i = 1; i <= MGMLIS3MDL::NR_OF_CTRL_REGISTERS; i++) { - if (registers[i - 1] != commandBuffer[i]) { - break; - } - } - setMode(_MODE_TO_ON); + case STATE_CHECK_REGISTERS: { + // Set up cached registers which will be used to configure the MGM. + if(commandExecuted) { + commandExecuted = false; + setMode(MODE_NORMAL); } - break; - + } default: break; } @@ -63,7 +64,7 @@ ReturnValue_t MGMHandlerLIS3MDL::buildTransitionDeviceCommand( break; case STATE_CHECK_REGISTERS: - *id = MGMLIS3MDL::READALL_MGM; + *id = MGMLIS3MDL::READ_CONFIG_AND_DATA; break; default: @@ -88,25 +89,33 @@ uint8_t MGMHandlerLIS3MDL::writeCommand(uint8_t command, bool continuousCom) { return command; } -ReturnValue_t MGMHandlerLIS3MDL::setupMGM() { +void MGMHandlerLIS3MDL::setupMgm() { - registers[0] = (1 << MGMLIS3MDL::TEMP_EN) | (1 << MGMLIS3MDL::OM1) - | (1 << MGMLIS3MDL::DO0) | (1 << MGMLIS3MDL::DO1) - | (1 << MGMLIS3MDL::DO2); - registers[1] = 0; - registers[2] = 0; - registers[3] = (1 << MGMLIS3MDL::OMZ1); - registers[4] = 0; - - return prepareCtrlRegisterWrite(); + registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT; + registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT; + registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT; + registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT; + registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT; + prepareCtrlRegisterWrite(); } ReturnValue_t MGMHandlerLIS3MDL::buildNormalDeviceCommand( DeviceCommandId_t *id) { - //defines CommandID of MGM in normal operation and build command from command - *id = MGMLIS3MDL::READALL_MGM; - return buildCommandFromCommand(*id, NULL, 0); + // Data/config register will be read in an alternating manner. + if(communicationStep == CommunicationStep::DATA) { + lastSentCommand = MGMLIS3MDL::READ_CONFIG_AND_DATA; + *id = MGMLIS3MDL::READ_CONFIG_AND_DATA; + communicationStep = CommunicationStep::TEMPERATURE; + return buildCommandFromCommand(*id, NULL, 0); + } + else { + lastSentCommand = MGMLIS3MDL::READ_TEMPERATURE; + *id = MGMLIS3MDL::READ_TEMPERATURE; + communicationStep = CommunicationStep::DATA; + return buildCommandFromCommand(*id, NULL, 0); + } + } ReturnValue_t MGMHandlerLIS3MDL::buildCommandFromCommand( @@ -114,13 +123,22 @@ ReturnValue_t MGMHandlerLIS3MDL::buildCommandFromCommand( size_t commandDataLen) { lastSentCommand = deviceCommand; switch(deviceCommand) { - case(MGMLIS3MDL::READALL_MGM): { + case(MGMLIS3MDL::READ_CONFIG_AND_DATA): { std::memset(commandBuffer, 0, sizeof(commandBuffer)); - commandBuffer[0] = readCommand(0, true); + commandBuffer[0] = readCommand(MGMLIS3MDL::CTRL_REG1, true); rawPacket = commandBuffer; - rawPacketLen = sizeof(commandBuffer); - return HasReturnvaluesIF::RETURN_OK; + rawPacketLen = MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1; + return RETURN_OK; + } + case(MGMLIS3MDL::READ_TEMPERATURE): { + std::memset(commandBuffer, 0, 3); + commandBuffer[0] = readCommand(MGMLIS3MDL::TEMP_LOWBYTE, true); + + rawPacket = commandBuffer; + rawPacketLen = 3; + return RETURN_OK; + } case(MGMLIS3MDL::IDENTIFY_DEVICE): { return identifyDevice(); } @@ -128,7 +146,8 @@ ReturnValue_t MGMHandlerLIS3MDL::buildCommandFromCommand( return enableTemperatureSensor(commandData, commandDataLen); } case(MGMLIS3MDL::SETUP_MGM): { - return setupMGM(); + setupMgm(); + return HasReturnvaluesIF::RETURN_OK; } case(MGMLIS3MDL::ACCURACY_OP_MODE_SET): { return setOperatingMode(commandData, commandDataLen); @@ -137,7 +156,6 @@ ReturnValue_t MGMHandlerLIS3MDL::buildCommandFromCommand( lastSentCommand = DeviceHandlerIF::NO_COMMAND; return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; } - } return HasReturnvaluesIF::RETURN_FAILED; } @@ -155,22 +173,33 @@ ReturnValue_t MGMHandlerLIS3MDL::identifyDevice() { ReturnValue_t MGMHandlerLIS3MDL::scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId, size_t *foundLen) { *foundLen = len; - if (len == MGMLIS3MDL::TOTAL_NR_OF_ADRESSES + 1) { + if (len == MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1) { *foundLen = len; - *foundId = MGMLIS3MDL::READALL_MGM; - //WHO AM I test - if (*(start + 16) != MGMLIS3MDL::DEVICE_ID) { + *foundId = MGMLIS3MDL::READ_CONFIG_AND_DATA; + // Check validity by checking config registers + if (start[1] != registers[0] or start[2] != registers[1] or + start[3] != registers[2] or start[4] != registers[3] or + start[5] != registers[4]) { return DeviceHandlerIF::INVALID_DATA; } + if(mode == _MODE_START_UP) { + commandExecuted = true; + } - } else if (len == MGMLIS3MDL::SETUP_REPLY) { + } + else if(len == MGMLIS3MDL::TEMPERATURE_REPLY_LEN) { + *foundLen = len; + *foundId = MGMLIS3MDL::READ_TEMPERATURE; + } + else if (len == MGMLIS3MDL::SETUP_REPLY_LEN) { *foundLen = len; *foundId = MGMLIS3MDL::SETUP_MGM; - } else if (len == SINGLE_COMMAND_ANSWER_LEN) { + } + else if (len == SINGLE_COMMAND_ANSWER_LEN) { *foundLen = len; *foundId = lastSentCommand; - } else { - + } + else { return DeviceHandlerIF::INVALID_DATA; } @@ -193,43 +222,53 @@ ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id, case MGMLIS3MDL::SETUP_MGM: { break; } - case MGMLIS3MDL::READALL_MGM: { + case MGMLIS3MDL::READ_CONFIG_AND_DATA: { // TODO: Store configuration and sensor values in new local datasets. - registers[0] = *(packet + 33); - registers[1] = *(packet + 34); - registers[2] = *(packet + 35); - registers[3] = *(packet + 36); - registers[4] = *(packet + 37); - uint8_t reg2_value = *(packet + 34); - uint8_t scale = getFullScale(®2_value); + uint8_t scale = getFullScale(registers[2]); float sensitivityFactor = getSensitivityFactor(scale); - int16_t x_value_raw; - int16_t y_value_raw; - int16_t z_value_raw; - int16_t temp_value_raw; - //size_t size = 2; - uint8_t *accessBuffer; - accessBuffer = const_cast(packet + 41); + int16_t mgmMeasurementRawX = packet[MGMLIS3MDL::X_HIGHBYTE_IDX] << 8 + | packet[MGMLIS3MDL::X_LOWBYTE_IDX] ; + int16_t mgmMeasurementRawY = packet[MGMLIS3MDL::Y_HIGHBYTE_IDX] << 8 + | packet[MGMLIS3MDL::Y_LOWBYTE_IDX] ; + int16_t mgmMeasurementRawZ = packet[MGMLIS3MDL::Z_HIGHBYTE_IDX] << 8 + | packet[MGMLIS3MDL::Z_LOWBYTE_IDX] ; - x_value_raw = *(accessBuffer + 1) << 8 | *(accessBuffer); - accessBuffer += 2; - y_value_raw = *(accessBuffer + 1) << 8 | *(accessBuffer); - accessBuffer += 2; - z_value_raw = *(accessBuffer + 1) << 8 | *(accessBuffer); - accessBuffer += 2; - - temp_value_raw = *(accessBuffer + 1) << 8 | *(accessBuffer); - - float x_value = static_cast(x_value_raw) * sensitivityFactor; - float y_value = static_cast(y_value_raw) * sensitivityFactor; - float z_value = static_cast(z_value_raw) * sensitivityFactor; - float temp_value = 25.0 + ((static_cast(temp_value_raw)) / 8.0); + // Target value in microtesla + float mgmX = static_cast(mgmMeasurementRawX) * sensitivityFactor + * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; + float mgmY = static_cast(mgmMeasurementRawY) * sensitivityFactor + * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; + float mgmZ = static_cast(mgmMeasurementRawZ) * sensitivityFactor + * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; +#if OBSW_ENHANCED_PRINTOUT == 1 + if(debugDivider->checkAndIncrement()) { + sif::info << "MGMHandlerLIS3: Magnetic field strength in" + " microtesla:" << std::endl; + // Set terminal to utf-8 if there is an issue with micro printout. + sif::info << "X: " << mgmX << " \xC2\xB5T" << std::endl; + sif::info << "Y: " << mgmY << " \xC2\xB5T" << std::endl; + sif::info << "Z: " << mgmZ << " \xC2\xB5T" << std::endl; + } +#endif break; } + case MGMLIS3MDL::READ_TEMPERATURE: { + int16_t tempValueRaw = packet[2] << 8 | packet[1]; + float tempValue = 25.0 + ((static_cast(tempValueRaw)) / 8.0); +#if OBSW_ENHANCED_PRINTOUT == 1 + if(debugDivider->check()) { + // Set terminal to utf-8 if there is an issue with micro printout. + sif::info << "MGMHandlerLIS3: Temperature: " << tempValue<< " °C" + << std::endl; + } +#endif + break; + } + default: { return DeviceHandlerIF::UNKNOW_DEVICE_REPLY; } @@ -238,12 +277,12 @@ ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id, return RETURN_OK; } -uint8_t MGMHandlerLIS3MDL::getFullScale(uint8_t *reg2) { +uint8_t MGMHandlerLIS3MDL::getFullScale(uint8_t ctrlRegister2) { bool FS0 = false; bool FS1 = false; - if ((*reg2 >> 5) == 1) + if ((ctrlRegister2 >> 5) == 1) FS0 = true; - if ((*reg2 >> 6) == 1) + if ((ctrlRegister2 >> 6) == 1) FS1 = true; if ((FS0 == true) && (FS1 == true)) return 16; @@ -333,7 +372,8 @@ void MGMHandlerLIS3MDL::fillCommandAndReplyMap() { * We dont read single registers, we just expect special * reply from he Readall_MGM */ - insertInCommandAndReplyMap(MGMLIS3MDL::READALL_MGM, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::READ_CONFIG_AND_DATA, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::READ_TEMPERATURE, 1); insertInCommandAndReplyMap(MGMLIS3MDL::SETUP_MGM, 1); insertInCommandAndReplyMap(MGMLIS3MDL::IDENTIFY_DEVICE, 1); insertInCommandAndReplyMap(MGMLIS3MDL::TEMP_SENSOR_ENABLE, 1); @@ -348,7 +388,7 @@ ReturnValue_t MGMHandlerLIS3MDL::prepareCtrlRegisterWrite() { commandBuffer[i + 1] = registers[i]; } rawPacket = commandBuffer; - rawPacketLen = MGMLIS3MDL::NR_OF_CTRL_REGISTERS; + rawPacketLen = MGMLIS3MDL::NR_OF_CTRL_REGISTERS + 1; // We dont have to check if this is working because we just did it return RETURN_OK; @@ -369,3 +409,16 @@ uint32_t MGMHandlerLIS3MDL::getTransitionDelayMs(Mode_t from, Mode_t to) { void MGMHandlerLIS3MDL::modeChanged(void) { internalState = STATE_NONE; } + +ReturnValue_t MGMHandlerLIS3MDL::initializeLocalDataPool( + LocalDataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { + localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_X, + new PoolEntry({0.0})); + localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y, + new PoolEntry({0.0})); + localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z, + new PoolEntry({0.0})); + localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, + new PoolEntry({0.0})); + return HasReturnvaluesIF::RETURN_OK; +} diff --git a/mission/devices/MGMHandlerLIS3MDL.h b/mission/devices/MGMHandlerLIS3MDL.h index eaac4381..0ff4d198 100644 --- a/mission/devices/MGMHandlerLIS3MDL.h +++ b/mission/devices/MGMHandlerLIS3MDL.h @@ -1,9 +1,14 @@ #ifndef MISSION_DEVICES_MGMLIS3MDLHANDLER_H_ #define MISSION_DEVICES_MGMLIS3MDLHANDLER_H_ -#include #include "devicedefinitions/MGMHandlerLIS3Definitions.h" -#include + +#include + +#include +#include + +#include /** * @brief Device handler object for the LIS3MDL 3-axis magnetometer @@ -14,6 +19,12 @@ */ class MGMHandlerLIS3MDL: public DeviceHandlerBase { public: + + enum class CommunicationStep { + DATA, + TEMPERATURE + }; + static const uint8_t INTERFACE_ID = CLASS_ID::MGM_LIS3MDL; static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::MGM_LIS3MDL; //Notifies a command to change the setup parameters @@ -44,8 +55,12 @@ protected: virtual void fillCommandAndReplyMap() override; virtual void modeChanged(void) override; void setNormalDatapoolEntriesInvalid() override; + ReturnValue_t initializeLocalDataPool(LocalDataPool &localDataPoolMap, + LocalDataPoolManager &poolManager) override; + private: + /*------------------------------------------------------------------------*/ /* Device specific commands and variables */ /*------------------------------------------------------------------------*/ @@ -68,7 +83,7 @@ private: * e.g.: +- 4 gauss. See p.25 datasheet. * @return The ReturnValue does not contain the sign of the value */ - uint8_t getFullScale(uint8_t *reg2); + uint8_t getFullScale(uint8_t ctrlReg2); /** * The 16 bit value needs to be divided by the full range of a 16bit value @@ -86,7 +101,7 @@ private: */ ReturnValue_t identifyDevice(); - virtual ReturnValue_t setupMGM(); + virtual void setupMgm(); /*------------------------------------------------------------------------*/ /* Non normal commands */ @@ -114,7 +129,7 @@ private: //Single SPIcommand has 2 bytes, first for adress, second for content size_t singleComandSize = 2; //has the size for all adresses of the lis3mdl + the continous write bit - uint8_t commandBuffer[MGMLIS3MDL::TOTAL_NR_OF_ADRESSES + 1]; + uint8_t commandBuffer[MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1]; /** * We want to save the registers we set, so we dont have to read the @@ -123,6 +138,9 @@ private: */ uint8_t registers[MGMLIS3MDL::NR_OF_CTRL_REGISTERS]; + uint8_t statusRegister = 0; + + /** * As this is a SPI Device, we get the Answer of the last sent command in * the next read cycle, so we could check the command for identification. @@ -142,6 +160,12 @@ private: }; InternalState internalState = STATE_NONE; + CommunicationStep communicationStep = CommunicationStep::DATA; + bool commandExecuted = false; + +#if OBSW_ENHANCED_PRINTOUT == 1 + PeriodicOperationDivider* debugDivider; +#endif }; From 08fa7d9e8b6ae22193fb38396a9c2b222008674d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 3 Dec 2020 12:57:44 +0100 Subject: [PATCH 02/27] device definition adaptions taken over --- .../MGMHandlerLIS3Definitions.h | 62 ++++++++++++++++--- 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/mission/devices/devicedefinitions/MGMHandlerLIS3Definitions.h b/mission/devices/devicedefinitions/MGMHandlerLIS3Definitions.h index 388b11e2..2518af15 100644 --- a/mission/devices/devicedefinitions/MGMHandlerLIS3Definitions.h +++ b/mission/devices/devicedefinitions/MGMHandlerLIS3Definitions.h @@ -1,6 +1,9 @@ #ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERLIS3DEFINITIONS_H_ #define MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERLIS3DEFINITIONS_H_ +#include +#include +#include #include namespace MGMLIS3MDL { @@ -12,11 +15,14 @@ enum opMode { LOW, MEDIUM, HIGH, ULTRA }; +static constexpr uint8_t GAUSS_TO_MICROTESLA_FACTOR = 100; + static const DeviceCommandId_t SETUP_MGM = 0x00; -static const DeviceCommandId_t READALL_MGM = 0x01; -static const DeviceCommandId_t IDENTIFY_DEVICE = 0x02; -static const DeviceCommandId_t TEMP_SENSOR_ENABLE = 0x03; -static const DeviceCommandId_t ACCURACY_OP_MODE_SET = 0x04; +static const DeviceCommandId_t READ_CONFIG_AND_DATA = 0x01; +static const DeviceCommandId_t READ_TEMPERATURE = 0x02; +static const DeviceCommandId_t IDENTIFY_DEVICE = 0x03; +static const DeviceCommandId_t TEMP_SENSOR_ENABLE = 0x04; +static const DeviceCommandId_t ACCURACY_OP_MODE_SET = 0x05; //Number of all control registers static const uint8_t NR_OF_CTRL_REGISTERS = 5; @@ -24,7 +30,9 @@ static const uint8_t NR_OF_CTRL_REGISTERS = 5; static const uint8_t NR_OF_REGISTERS = 19; //Total number of adresses for all registers static const uint8_t TOTAL_NR_OF_ADRESSES = 52; -static const uint8_t SETUP_REPLY = 6; +static const uint8_t NR_OF_DATA_AND_CFG_REGISTERS = 14; +static const uint8_t TEMPERATURE_REPLY_LEN = 3; +static const uint8_t SETUP_REPLY_LEN = 6; /*------------------------------------------------------------------------*/ /* Register adresses */ @@ -45,19 +53,26 @@ static const uint8_t CTRL_REG4 = 0b00100011; static const uint8_t CTRL_REG5 = 0b00100100; //Register adress to access status register +static const uint8_t STATUS_REG_IDX = 8; static const uint8_t STATUS_REG = 0b00100111; //Register adress to access low byte of x-axis +static const uint8_t X_LOWBYTE_IDX = 9; static const uint8_t X_LOWBYTE = 0b00101000; //Register adress to access high byte of x-axis +static const uint8_t X_HIGHBYTE_IDX = 10; static const uint8_t X_HIGHBYTE = 0b00101001; //Register adress to access low byte of y-axis +static const uint8_t Y_LOWBYTE_IDX = 11; static const uint8_t Y_LOWBYTE = 0b00101010; //Register adress to access high byte of y-axis +static const uint8_t Y_HIGHBYTE_IDX = 12; static const uint8_t Y_HIGHBYTE = 0b00101011; //Register adress to access low byte of z-axis +static const uint8_t Z_LOWBYTE_IDX = 13; static const uint8_t Z_LOWBYTE = 0b00101100; //Register adress to access high byte of z-axis +static const uint8_t Z_HIGHBYTE_IDX = 14; static const uint8_t Z_HIGHBYTE = 0b00101101; //Register adress to access low byte of temperature sensor @@ -66,7 +81,7 @@ static const uint8_t TEMP_LOWBYTE = 0b00101110; static const uint8_t TEMP_HIGHBYTE = 0b00101111; /*------------------------------------------------------------------------*/ -/* Initialize Setup Register set bits +/* Initialize Setup Register set bits */ /*------------------------------------------------------------------------*/ /* General transfer bits */ // Read=1 / Write=0 Bit @@ -84,6 +99,8 @@ static const uint8_t DO2 = 4; // Output data rate bit 4 static const uint8_t OM0 = 5; // XY operating mode bit 5 static const uint8_t OM1 = 6; // XY operating mode bit 6 static const uint8_t TEMP_EN = 7; // Temperature sensor enable enabled = 1 +static const uint8_t CTRL_REG1_DEFAULT = (1 << TEMP_EN) | (1 << OM1) | + (1 << DO0) | (1 << DO1) | (1 << DO2); /* CTRL_REG2 bits */ //reset configuration registers and user registers @@ -91,6 +108,7 @@ static const uint8_t SOFT_RST = 2; static const uint8_t REBOOT = 3; //reboot memory content static const uint8_t FSO = 5; //full-scale selection bit 5 static const uint8_t FS1 = 6; //full-scale selection bit 6 +static const uint8_t CTRL_REG2_DEFAULT = 0; /* CTRL_REG3 bits */ static const uint8_t MD0 = 0; //Operating mode bit 0 @@ -98,18 +116,48 @@ static const uint8_t MD1 = 1; //Operating mode bit 1 //SPI serial interface mode selection enabled = 3-wire-mode static const uint8_t SIM = 2; static const uint8_t LP = 5; //low-power mode +static const uint8_t CTRL_REG3_DEFAULT = 0; /* CTRL_REG4 bits */ //big/little endian data selection enabled = MSb at lower adress static const uint8_t BLE = 1; static const uint8_t OMZ0 = 2; //Z operating mode bit 2 static const uint8_t OMZ1 = 3; //Z operating mode bit 3 +static const uint8_t CTRL_REG4_DEFAULT = (1 << OMZ1); /* CTRL_REG5 bits */ static const uint8_t BDU = 6; //Block data update static const uint8_t FAST_READ = 7; //Fast read enabled = 1 +static const uint8_t CTRL_REG5_DEFAULT = 0; + +static const uint32_t MGM_DATA_SET_ID = 0; + +enum MgmPoolIds: lp_id_t { + FIELD_STRENGTH_X, + FIELD_STRENGTH_Y, + FIELD_STRENGTH_Z, + TEMPERATURE_CELCIUS +}; + +class MgmPrimaryDataset: public StaticLocalDataSet<3 * sizeof(float)> { +public: + MgmPrimaryDataset(HasLocalDataPoolIF* hkOwner): + StaticLocalDataSet(hkOwner, MGM_DATA_SET_ID) {} + + MgmPrimaryDataset(object_id_t mgmId): + StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {} + + lp_var_t angVelocityX = lp_var_t(sid.objectId, + FIELD_STRENGTH_X, this); + lp_var_t angVelocityY = lp_var_t(sid.objectId, + FIELD_STRENGTH_Y, this); + lp_var_t angVelocityZ = lp_var_t(sid.objectId, + FIELD_STRENGTH_Z, this); + lp_var_t temperature = lp_var_t(sid.objectId, + TEMPERATURE_CELCIUS, this); +}; + } - #endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERLIS3DEFINITIONS_H_ */ From c91497e4de8d89a5baaf25e4a672b49de3809e25 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Dec 2020 13:03:47 +0100 Subject: [PATCH 03/27] some fixes --- Makefile-Hosted | 2 +- {hosted => bsp_hosted}/InitMission.cpp | 0 {hosted => bsp_hosted}/InitMission.h | 0 {hosted => bsp_hosted}/ObjectFactory.cpp | 2 +- {hosted => bsp_hosted}/ObjectFactory.h | 0 {hosted => bsp_hosted}/boardconfig/etl_profile.h | 0 {hosted => bsp_hosted}/boardconfig/gcov.h | 0 {hosted => bsp_hosted}/boardconfig/print.c | 1 + bsp_hosted/boardconfig/print.h | 8 ++++++++ hosted/hosted.mk => bsp_hosted/bsp_hosted.mk | 3 ++- {hosted => bsp_hosted}/comIF/ArduinoComIF.cpp | 5 ++--- {hosted => bsp_hosted}/comIF/ArduinoComIF.h | 0 {hosted => bsp_hosted}/comIF/ArduinoCookie.cpp | 2 +- {hosted => bsp_hosted}/comIF/ArduinoCookie.h | 0 {hosted => bsp_hosted}/fsfwconfig/FSFWConfig.h | 0 {hosted => bsp_hosted}/fsfwconfig/OBSWConfig.h | 0 {hosted => bsp_hosted}/fsfwconfig/OBSWVersion.h | 0 .../fsfwconfig/events/subsystemIdRanges.h | 0 {hosted => bsp_hosted}/fsfwconfig/fsfwconfig.mk | 0 .../fsfwconfig/ipc/MissionMessageTypes.cpp | 2 +- .../fsfwconfig/ipc/MissionMessageTypes.h | 0 {hosted => bsp_hosted}/fsfwconfig/returnvalues/classIds.h | 0 {hosted => bsp_hosted}/main.cpp | 3 +-- fsfw | 2 +- hosted/boardconfig/print.h | 8 -------- 25 files changed, 19 insertions(+), 19 deletions(-) rename {hosted => bsp_hosted}/InitMission.cpp (100%) rename {hosted => bsp_hosted}/InitMission.h (100%) rename {hosted => bsp_hosted}/ObjectFactory.cpp (100%) rename {hosted => bsp_hosted}/ObjectFactory.h (100%) rename {hosted => bsp_hosted}/boardconfig/etl_profile.h (100%) rename {hosted => bsp_hosted}/boardconfig/gcov.h (100%) rename {hosted => bsp_hosted}/boardconfig/print.c (99%) create mode 100644 bsp_hosted/boardconfig/print.h rename hosted/hosted.mk => bsp_hosted/bsp_hosted.mk (76%) rename {hosted => bsp_hosted}/comIF/ArduinoComIF.cpp (99%) rename {hosted => bsp_hosted}/comIF/ArduinoComIF.h (100%) rename {hosted => bsp_hosted}/comIF/ArduinoCookie.cpp (83%) rename {hosted => bsp_hosted}/comIF/ArduinoCookie.h (100%) rename {hosted => bsp_hosted}/fsfwconfig/FSFWConfig.h (100%) rename {hosted => bsp_hosted}/fsfwconfig/OBSWConfig.h (100%) rename {hosted => bsp_hosted}/fsfwconfig/OBSWVersion.h (100%) rename {hosted => bsp_hosted}/fsfwconfig/events/subsystemIdRanges.h (100%) rename {hosted => bsp_hosted}/fsfwconfig/fsfwconfig.mk (100%) rename {hosted => bsp_hosted}/fsfwconfig/ipc/MissionMessageTypes.cpp (75%) rename {hosted => bsp_hosted}/fsfwconfig/ipc/MissionMessageTypes.h (100%) rename {hosted => bsp_hosted}/fsfwconfig/returnvalues/classIds.h (100%) rename {hosted => bsp_hosted}/main.cpp (95%) delete mode 100644 hosted/boardconfig/print.h diff --git a/Makefile-Hosted b/Makefile-Hosted index bb56fec5..9dff3677 100644 --- a/Makefile-Hosted +++ b/Makefile-Hosted @@ -15,7 +15,7 @@ CUSTOM_DEFINES := # Chip & board used for compilation # (can be overriden by adding CHIP=chip and BOARD=board to the command-line) -BOARD_FILE_ROOT = hosted +BOARD_FILE_ROOT = bsp_hosted BOARD = host OS_FSFW = host CUSTOM_DEFINES += -D$(OS_FSFW) diff --git a/hosted/InitMission.cpp b/bsp_hosted/InitMission.cpp similarity index 100% rename from hosted/InitMission.cpp rename to bsp_hosted/InitMission.cpp diff --git a/hosted/InitMission.h b/bsp_hosted/InitMission.h similarity index 100% rename from hosted/InitMission.h rename to bsp_hosted/InitMission.h diff --git a/hosted/ObjectFactory.cpp b/bsp_hosted/ObjectFactory.cpp similarity index 100% rename from hosted/ObjectFactory.cpp rename to bsp_hosted/ObjectFactory.cpp index 09c69082..798fa7ec 100644 --- a/hosted/ObjectFactory.cpp +++ b/bsp_hosted/ObjectFactory.cpp @@ -1,7 +1,7 @@ #include "ObjectFactory.h" -#include #include +#include #include #include diff --git a/hosted/ObjectFactory.h b/bsp_hosted/ObjectFactory.h similarity index 100% rename from hosted/ObjectFactory.h rename to bsp_hosted/ObjectFactory.h diff --git a/hosted/boardconfig/etl_profile.h b/bsp_hosted/boardconfig/etl_profile.h similarity index 100% rename from hosted/boardconfig/etl_profile.h rename to bsp_hosted/boardconfig/etl_profile.h diff --git a/hosted/boardconfig/gcov.h b/bsp_hosted/boardconfig/gcov.h similarity index 100% rename from hosted/boardconfig/gcov.h rename to bsp_hosted/boardconfig/gcov.h diff --git a/hosted/boardconfig/print.c b/bsp_hosted/boardconfig/print.c similarity index 99% rename from hosted/boardconfig/print.c rename to bsp_hosted/boardconfig/print.c index f409ee1b..f35f9447 100644 --- a/hosted/boardconfig/print.c +++ b/bsp_hosted/boardconfig/print.c @@ -1,4 +1,5 @@ #include "print.h" + #include void printChar(const char* character, bool errStream) { diff --git a/bsp_hosted/boardconfig/print.h b/bsp_hosted/boardconfig/print.h new file mode 100644 index 00000000..84798490 --- /dev/null +++ b/bsp_hosted/boardconfig/print.h @@ -0,0 +1,8 @@ +#ifndef BSP_HOSTED_BOARDCONFIG_PRINT_H_ +#define BSP_HOSTED_BOARDCONFIG_PRINT_H_ + +#include + +void printChar(const char* character, bool errStream); + +#endif /* BSP_HOSTED_BOARDCONFIG_PRINT_H_ */ diff --git a/hosted/hosted.mk b/bsp_hosted/bsp_hosted.mk similarity index 76% rename from hosted/hosted.mk rename to bsp_hosted/bsp_hosted.mk index 8bd29bc1..9595ffbf 100644 --- a/hosted/hosted.mk +++ b/bsp_hosted/bsp_hosted.mk @@ -7,4 +7,5 @@ CSRC += $(wildcard $(CURRENTPATH)/boardconfig/*.c) CXXSRC += $(wildcard $(CURRENTPATH)/comIF/*.cpp) CSRC += $(wildcard $(CURRENTPATH)/comIF/*.c) -INCLUDES += $(CURRENTPATH)/boardconfig \ No newline at end of file +INCLUDES += $(CURRENTPATH)/boardconfig +INCLUDES += $(CURRENTPATH)/fsfwconfig \ No newline at end of file diff --git a/hosted/comIF/ArduinoComIF.cpp b/bsp_hosted/comIF/ArduinoComIF.cpp similarity index 99% rename from hosted/comIF/ArduinoComIF.cpp rename to bsp_hosted/comIF/ArduinoComIF.cpp index 11555f55..047a60ae 100644 --- a/hosted/comIF/ArduinoComIF.cpp +++ b/bsp_hosted/comIF/ArduinoComIF.cpp @@ -1,6 +1,5 @@ -#include "ArduinoComIF.h" -#include "ArduinoCookie.h" - +#include +#include #include #include #include diff --git a/hosted/comIF/ArduinoComIF.h b/bsp_hosted/comIF/ArduinoComIF.h similarity index 100% rename from hosted/comIF/ArduinoComIF.h rename to bsp_hosted/comIF/ArduinoComIF.h diff --git a/hosted/comIF/ArduinoCookie.cpp b/bsp_hosted/comIF/ArduinoCookie.cpp similarity index 83% rename from hosted/comIF/ArduinoCookie.cpp rename to bsp_hosted/comIF/ArduinoCookie.cpp index 7d9a9f3c..bc698720 100644 --- a/hosted/comIF/ArduinoCookie.cpp +++ b/bsp_hosted/comIF/ArduinoCookie.cpp @@ -1,4 +1,4 @@ -#include "ArduinoCookie.h" +#include ArduinoCookie::ArduinoCookie(Protocol_t protocol, uint8_t address, const size_t maxReplySize) : diff --git a/hosted/comIF/ArduinoCookie.h b/bsp_hosted/comIF/ArduinoCookie.h similarity index 100% rename from hosted/comIF/ArduinoCookie.h rename to bsp_hosted/comIF/ArduinoCookie.h diff --git a/hosted/fsfwconfig/FSFWConfig.h b/bsp_hosted/fsfwconfig/FSFWConfig.h similarity index 100% rename from hosted/fsfwconfig/FSFWConfig.h rename to bsp_hosted/fsfwconfig/FSFWConfig.h diff --git a/hosted/fsfwconfig/OBSWConfig.h b/bsp_hosted/fsfwconfig/OBSWConfig.h similarity index 100% rename from hosted/fsfwconfig/OBSWConfig.h rename to bsp_hosted/fsfwconfig/OBSWConfig.h diff --git a/hosted/fsfwconfig/OBSWVersion.h b/bsp_hosted/fsfwconfig/OBSWVersion.h similarity index 100% rename from hosted/fsfwconfig/OBSWVersion.h rename to bsp_hosted/fsfwconfig/OBSWVersion.h diff --git a/hosted/fsfwconfig/events/subsystemIdRanges.h b/bsp_hosted/fsfwconfig/events/subsystemIdRanges.h similarity index 100% rename from hosted/fsfwconfig/events/subsystemIdRanges.h rename to bsp_hosted/fsfwconfig/events/subsystemIdRanges.h diff --git a/hosted/fsfwconfig/fsfwconfig.mk b/bsp_hosted/fsfwconfig/fsfwconfig.mk similarity index 100% rename from hosted/fsfwconfig/fsfwconfig.mk rename to bsp_hosted/fsfwconfig/fsfwconfig.mk diff --git a/hosted/fsfwconfig/ipc/MissionMessageTypes.cpp b/bsp_hosted/fsfwconfig/ipc/MissionMessageTypes.cpp similarity index 75% rename from hosted/fsfwconfig/ipc/MissionMessageTypes.cpp rename to bsp_hosted/fsfwconfig/ipc/MissionMessageTypes.cpp index b91abcd3..36ef1b73 100644 --- a/hosted/fsfwconfig/ipc/MissionMessageTypes.cpp +++ b/bsp_hosted/fsfwconfig/ipc/MissionMessageTypes.cpp @@ -1,5 +1,5 @@ +#include "MissionMessageTypes.h" #include -#include void messagetypes::clearMissionMessage(CommandMessage* message) { switch(message->getMessageType()) { diff --git a/hosted/fsfwconfig/ipc/MissionMessageTypes.h b/bsp_hosted/fsfwconfig/ipc/MissionMessageTypes.h similarity index 100% rename from hosted/fsfwconfig/ipc/MissionMessageTypes.h rename to bsp_hosted/fsfwconfig/ipc/MissionMessageTypes.h diff --git a/hosted/fsfwconfig/returnvalues/classIds.h b/bsp_hosted/fsfwconfig/returnvalues/classIds.h similarity index 100% rename from hosted/fsfwconfig/returnvalues/classIds.h rename to bsp_hosted/fsfwconfig/returnvalues/classIds.h diff --git a/hosted/main.cpp b/bsp_hosted/main.cpp similarity index 95% rename from hosted/main.cpp rename to bsp_hosted/main.cpp index e5ca6d02..50d1e7f2 100644 --- a/hosted/main.cpp +++ b/bsp_hosted/main.cpp @@ -1,7 +1,6 @@ +#include #include #include -#include - #include #ifdef WIN32 diff --git a/fsfw b/fsfw index ca34250e..81c00cd3 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit ca34250e8d74cec8a75bed284bf0ec9252019b65 +Subproject commit 81c00cd3dcdabf57142d488dd348e0cd335f55a8 diff --git a/hosted/boardconfig/print.h b/hosted/boardconfig/print.h deleted file mode 100644 index 8e7e2e5d..00000000 --- a/hosted/boardconfig/print.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef HOSTED_BOARDCONFIG_PRINT_H_ -#define HOSTED_BOARDCONFIG_PRINT_H_ - -#include - -void printChar(const char* character, bool errStream); - -#endif /* HOSTED_BOARDCONFIG_PRINT_H_ */ From 869bc657d9ca779b0ca5de8ccffebf9818e9a109 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Dec 2020 21:57:52 +0100 Subject: [PATCH 04/27] fsfw update --- fsfw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsfw b/fsfw index 81c00cd3..b232a8a2 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 81c00cd3dcdabf57142d488dd348e0cd335f55a8 +Subproject commit b232a8a2919841b331b43c84a7fb2ae80f93186f From dd127fece8bbf071ba68813dc315180127cd957c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Dec 2020 22:03:57 +0100 Subject: [PATCH 05/27] hosted build working again --- bsp_hosted/InitMission.cpp | 4 --- bsp_hosted/fsfwconfig/FSFWConfig.h | 1 - .../fsfwconfig/objects/systemObjectList.h | 36 +++++++++++++++++++ bsp_hosted/fsfwconfig/tmtc/apid.h | 19 ++++++++++ bsp_hosted/fsfwconfig/tmtc/pusIds.h | 23 ++++++++++++ fsfwconfig/tmtc/tmTcSize.h | 10 ------ mission/core/GenericFactory.cpp | 32 ++++++++--------- mission/devices/MGMHandlerLIS3MDL.h | 2 +- 8 files changed, 93 insertions(+), 34 deletions(-) create mode 100644 bsp_hosted/fsfwconfig/objects/systemObjectList.h create mode 100644 bsp_hosted/fsfwconfig/tmtc/apid.h create mode 100644 bsp_hosted/fsfwconfig/tmtc/pusIds.h delete mode 100644 fsfwconfig/tmtc/tmTcSize.h diff --git a/bsp_hosted/InitMission.cpp b/bsp_hosted/InitMission.cpp index 8bee1b2e..29101d08 100644 --- a/bsp_hosted/InitMission.cpp +++ b/bsp_hosted/InitMission.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -29,9 +28,6 @@ ServiceInterfaceStream sif::error("ERROR", true, false, true); ObjectManagerIF *objectManager = nullptr; -//Initialize Data Pool -DataPool dataPool(nullptr); - void InitMission::initMission() { sif::info << "Building global objects.." << std::endl; /* Instantiate global object manager and also create all objects */ diff --git a/bsp_hosted/fsfwconfig/FSFWConfig.h b/bsp_hosted/fsfwconfig/FSFWConfig.h index ea86152c..3433613c 100644 --- a/bsp_hosted/fsfwconfig/FSFWConfig.h +++ b/bsp_hosted/fsfwconfig/FSFWConfig.h @@ -1,7 +1,6 @@ #ifndef CONFIG_FSFWCONFIG_H_ #define CONFIG_FSFWCONFIG_H_ -#include #include //! Used to determine whether C++ ostreams are used diff --git a/bsp_hosted/fsfwconfig/objects/systemObjectList.h b/bsp_hosted/fsfwconfig/objects/systemObjectList.h new file mode 100644 index 00000000..3b5717fb --- /dev/null +++ b/bsp_hosted/fsfwconfig/objects/systemObjectList.h @@ -0,0 +1,36 @@ +#ifndef HOSTED_CONFIG_OBJECTS_SYSTEMOBJECTLIST_H_ +#define HOSTED_CONFIG_OBJECTS_SYSTEMOBJECTLIST_H_ + +#include + +// The objects will be instantiated in the ID order +namespace objects { + enum sourceObjects: uint32_t { + /* First Byte 0x50-0x52 reserved for PUS Services **/ + CCSDS_PACKET_DISTRIBUTOR = 0x50000100, + PUS_PACKET_DISTRIBUTOR = 0x50000200, + UDP_BRIDGE = 0x50000300, + UDP_POLLING_TASK = 0x50000400, + + PUS_SERVICE_3 = 0x51000300, + PUS_SERVICE_5 = 0x51000400, + PUS_SERVICE_6 = 0x51000500, + PUS_SERVICE_8 = 0x51000800, + PUS_SERVICE_23 = 0x51002300, + PUS_SERVICE_201 = 0x51020100, + + TIME_STAMPER = 0x52000001, + TM_FUNNEL = 0x52000002, + + /* Test Task */ + + TEST_TASK = 0x42694269, + DUMMY_INTERFACE = 0xCAFECAFE, + DUMMY_HANDLER = 0x4400AFFE, + + /* 0x49 ('I') for Communication Interfaces **/ + ARDUINO_COM_IF = 0x49000001 + }; +} + +#endif /* BSP_CONFIG_OBJECTS_SYSTEMOBJECTLIST_H_ */ diff --git a/bsp_hosted/fsfwconfig/tmtc/apid.h b/bsp_hosted/fsfwconfig/tmtc/apid.h new file mode 100644 index 00000000..ee2fc7c4 --- /dev/null +++ b/bsp_hosted/fsfwconfig/tmtc/apid.h @@ -0,0 +1,19 @@ +#ifndef FSFWCONFIG_TMTC_APID_H_ +#define FSFWCONFIG_TMTC_APID_H_ + +#include + +/** + * Application Process Definition: entity, uniquely identified by an + * application process ID (APID), capable of generating telemetry source + * packets and receiving telecommand packets + * + * SOURCE APID: 0x73 / 115 / s + * APID is a 11 bit number + */ +namespace apid { + static const uint16_t EIVE_OBSW = 0x65; +} + + +#endif /* FSFWCONFIG_TMTC_APID_H_ */ diff --git a/bsp_hosted/fsfwconfig/tmtc/pusIds.h b/bsp_hosted/fsfwconfig/tmtc/pusIds.h new file mode 100644 index 00000000..a2dd7575 --- /dev/null +++ b/bsp_hosted/fsfwconfig/tmtc/pusIds.h @@ -0,0 +1,23 @@ +#ifndef CONFIG_TMTC_PUSIDS_HPP_ +#define CONFIG_TMTC_PUSIDS_HPP_ + +namespace pus { +enum Ids{ + PUS_SERVICE_1 = 1, + PUS_SERVICE_2 = 2, + PUS_SERVICE_3 = 3, + PUS_SERVICE_3_PSB = 3, + PUS_SERVICE_5 = 5, + PUS_SERVICE_6 = 6, + PUS_SERVICE_8 = 8, + PUS_SERVICE_9 = 9, + PUS_SERVICE_17 = 17, + PUS_SERVICE_19 = 19, + PUS_SERVICE_20 = 20, + PUS_SERVICE_23 = 23, + PUS_SERVICE_200 = 200, + PUS_SERVICE_201 = 201, +}; +}; + +#endif /* CONFIG_TMTC_PUSIDS_HPP_ */ diff --git a/fsfwconfig/tmtc/tmTcSize.h b/fsfwconfig/tmtc/tmTcSize.h deleted file mode 100644 index c3c83d31..00000000 --- a/fsfwconfig/tmtc/tmTcSize.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef FSFWCONFIG_TMTC_TMTCSIZE_H_ -#define FSFWCONFIG_TMTC_TMTCSIZE_H_ - -#include - -namespace tmtcsize { -static const uint32_t MAX_TM_PACKET = 50; -} - -#endif /* FSFWCONFIG_TMTC_TMTCSIZE_H_ */ diff --git a/mission/core/GenericFactory.cpp b/mission/core/GenericFactory.cpp index 5305dc82..be0d65e5 100644 --- a/mission/core/GenericFactory.cpp +++ b/mission/core/GenericFactory.cpp @@ -24,32 +24,28 @@ void ObjectFactory::produceGenericObjects() { /* Framework objects */ new EventManager(objects::EVENT_MANAGER); new HealthTable(objects::HEALTH_TABLE); - new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER, 0, 0, 0); + new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER); new TimeStamper(objects::TIME_STAMPER); { - static constexpr uint8_t NUMBER_OF_POOLS = 5; - const uint16_t element_sizes[NUMBER_OF_POOLS] = {16, 32, 64, 128, 1024}; - const uint16_t n_elements[NUMBER_OF_POOLS] = {100, 50, 25, 15, 5}; - new PoolManager(objects::TC_STORE, element_sizes, - n_elements); + PoolManager::LocalPoolConfig poolCfg = { + {100, 16}, {50, 32}, {25, 64}, {15, 128}, {5, 1024} + }; + new PoolManager(objects::TC_STORE, poolCfg); } { - static constexpr uint8_t NUMBER_OF_POOLS = 5; - const uint16_t element_sizes[NUMBER_OF_POOLS] = {16, 32, 64, 128, 1024}; - const uint16_t n_elements[NUMBER_OF_POOLS] = {100, 50, 25, 15, 5}; - new PoolManager(objects::TM_STORE, element_sizes, - n_elements); + PoolManager::LocalPoolConfig poolCfg = { + {100, 16}, {50, 32}, {25, 64}, {15, 128}, {5, 1024} + }; + new PoolManager(objects::TM_STORE, poolCfg); } { - static constexpr uint8_t NUMBER_OF_POOLS = 6; - const uint16_t element_sizes[NUMBER_OF_POOLS] = {32, 64, 512, - 1024, 2048, 4096}; - const uint16_t n_elements[NUMBER_OF_POOLS] = {200, 100, 50, 25, 15, 5}; - new PoolManager(objects::IPC_STORE, element_sizes, - n_elements); + PoolManager::LocalPoolConfig poolCfg = { + {100, 16}, {50, 32}, {25, 64}, {15, 128}, {5, 1024} + }; + new PoolManager(objects::IPC_STORE, poolCfg); } new CCSDSDistributor(apid::EIVE_OBSW, objects::CCSDS_PACKET_DISTRIBUTOR); @@ -62,7 +58,7 @@ void ObjectFactory::produceGenericObjects() { /* PUS stack */ new Service1TelecommandVerification(objects::PUS_SERVICE_1_VERIFICATION, - apid::EIVE_OBSW, pus::PUS_SERVICE_1, objects::TM_FUNNEL); + apid::EIVE_OBSW, pus::PUS_SERVICE_1, objects::TM_FUNNEL, 20); new Service2DeviceAccess(objects::PUS_SERVICE_2_DEVICE_ACCESS, apid::EIVE_OBSW, pus::PUS_SERVICE_2, 3, 10); new Service5EventReporting(objects::PUS_SERVICE_5_EVENT_REPORTING, diff --git a/mission/devices/MGMHandlerLIS3MDL.h b/mission/devices/MGMHandlerLIS3MDL.h index 0ff4d198..4c06e001 100644 --- a/mission/devices/MGMHandlerLIS3MDL.h +++ b/mission/devices/MGMHandlerLIS3MDL.h @@ -28,7 +28,7 @@ public: static const uint8_t INTERFACE_ID = CLASS_ID::MGM_LIS3MDL; static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::MGM_LIS3MDL; //Notifies a command to change the setup parameters - static const Event CHANGE_OF_SETUP_PARAMETER = MAKE_EVENT(0, SEVERITY::LOW); + static const Event CHANGE_OF_SETUP_PARAMETER = MAKE_EVENT(0, severity::LOW); MGMHandlerLIS3MDL(uint32_t objectId, object_id_t deviceCommunication, CookieIF* comCookie); From 949f6418a083206225a698303484325b303f18c8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Dec 2020 22:15:07 +0100 Subject: [PATCH 06/27] tmtc update --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index 2f1c3d5e..4463efcf 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 2f1c3d5eb9c3858d99c4516f4f132425ea1a97b7 +Subproject commit 4463efcf7bfd2181a78eff66fca82c335aeea1d1 From 68d0fa95b0c8af712e4f6a66516ac0a97dbff252 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Dec 2020 22:18:25 +0100 Subject: [PATCH 07/27] indentation --- mission/devices/MGMHandlerLIS3MDL.cpp | 384 +++++++++++++------------- 1 file changed, 192 insertions(+), 192 deletions(-) diff --git a/mission/devices/MGMHandlerLIS3MDL.cpp b/mission/devices/MGMHandlerLIS3MDL.cpp index 77b1a300..50d0ce3c 100644 --- a/mission/devices/MGMHandlerLIS3MDL.cpp +++ b/mission/devices/MGMHandlerLIS3MDL.cpp @@ -3,7 +3,7 @@ MGMHandlerLIS3MDL::MGMHandlerLIS3MDL(object_id_t objectId, object_id_t deviceCommunication, CookieIF* comCookie): - DeviceHandlerBase(objectId, deviceCommunication, comCookie) { + DeviceHandlerBase(objectId, deviceCommunication, comCookie) { #if OBSW_ENHANCED_PRINTOUT == 1 debugDivider = new PeriodicOperationDivider(10); #endif @@ -74,34 +74,34 @@ ReturnValue_t MGMHandlerLIS3MDL::buildTransitionDeviceCommand( } uint8_t MGMHandlerLIS3MDL::readCommand(uint8_t command, bool continuousCom) { - command |= (1 << MGMLIS3MDL::RW_BIT); - if (continuousCom == true) { - command |= (1 << MGMLIS3MDL::MS_BIT); - } - return command; + command |= (1 << MGMLIS3MDL::RW_BIT); + if (continuousCom == true) { + command |= (1 << MGMLIS3MDL::MS_BIT); + } + return command; } uint8_t MGMHandlerLIS3MDL::writeCommand(uint8_t command, bool continuousCom) { - command &= ~(1 << MGMLIS3MDL::RW_BIT); - if (continuousCom == true) { - command |= (1 << MGMLIS3MDL::MS_BIT); - } - return command; + command &= ~(1 << MGMLIS3MDL::RW_BIT); + if (continuousCom == true) { + command |= (1 << MGMLIS3MDL::MS_BIT); + } + return command; } void MGMHandlerLIS3MDL::setupMgm() { - registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT; - registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT; - registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT; - registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT; - registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT; + registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT; + registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT; + registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT; + registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT; + registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT; - prepareCtrlRegisterWrite(); + prepareCtrlRegisterWrite(); } ReturnValue_t MGMHandlerLIS3MDL::buildNormalDeviceCommand( - DeviceCommandId_t *id) { + DeviceCommandId_t *id) { // Data/config register will be read in an alternating manner. if(communicationStep == CommunicationStep::DATA) { lastSentCommand = MGMLIS3MDL::READ_CONFIG_AND_DATA; @@ -120,7 +120,7 @@ ReturnValue_t MGMHandlerLIS3MDL::buildNormalDeviceCommand( ReturnValue_t MGMHandlerLIS3MDL::buildCommandFromCommand( DeviceCommandId_t deviceCommand, const uint8_t *commandData, - size_t commandDataLen) { + size_t commandDataLen) { lastSentCommand = deviceCommand; switch(deviceCommand) { case(MGMLIS3MDL::READ_CONFIG_AND_DATA): { @@ -139,24 +139,24 @@ ReturnValue_t MGMHandlerLIS3MDL::buildCommandFromCommand( rawPacketLen = 3; return RETURN_OK; } - case(MGMLIS3MDL::IDENTIFY_DEVICE): { - return identifyDevice(); - } - case(MGMLIS3MDL::TEMP_SENSOR_ENABLE): { - return enableTemperatureSensor(commandData, commandDataLen); - } - case(MGMLIS3MDL::SETUP_MGM): { - setupMgm(); - return HasReturnvaluesIF::RETURN_OK; - } - case(MGMLIS3MDL::ACCURACY_OP_MODE_SET): { - return setOperatingMode(commandData, commandDataLen); - } - default: - lastSentCommand = DeviceHandlerIF::NO_COMMAND; - return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; - } - return HasReturnvaluesIF::RETURN_FAILED; + case(MGMLIS3MDL::IDENTIFY_DEVICE): { + return identifyDevice(); + } + case(MGMLIS3MDL::TEMP_SENSOR_ENABLE): { + return enableTemperatureSensor(commandData, commandDataLen); + } + case(MGMLIS3MDL::SETUP_MGM): { + setupMgm(); + return HasReturnvaluesIF::RETURN_OK; + } + case(MGMLIS3MDL::ACCURACY_OP_MODE_SET): { + return setOperatingMode(commandData, commandDataLen); + } + default: + lastSentCommand = DeviceHandlerIF::NO_COMMAND; + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return HasReturnvaluesIF::RETURN_FAILED; } ReturnValue_t MGMHandlerLIS3MDL::identifyDevice() { @@ -171,93 +171,93 @@ ReturnValue_t MGMHandlerLIS3MDL::identifyDevice() { } ReturnValue_t MGMHandlerLIS3MDL::scanForReply(const uint8_t *start, - size_t len, DeviceCommandId_t *foundId, size_t *foundLen) { - *foundLen = len; - if (len == MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1) { - *foundLen = len; - *foundId = MGMLIS3MDL::READ_CONFIG_AND_DATA; - // Check validity by checking config registers - if (start[1] != registers[0] or start[2] != registers[1] or - start[3] != registers[2] or start[4] != registers[3] or - start[5] != registers[4]) { - return DeviceHandlerIF::INVALID_DATA; - } + size_t len, DeviceCommandId_t *foundId, size_t *foundLen) { + *foundLen = len; + if (len == MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1) { + *foundLen = len; + *foundId = MGMLIS3MDL::READ_CONFIG_AND_DATA; + // Check validity by checking config registers + if (start[1] != registers[0] or start[2] != registers[1] or + start[3] != registers[2] or start[4] != registers[3] or + start[5] != registers[4]) { + return DeviceHandlerIF::INVALID_DATA; + } if(mode == _MODE_START_UP) { commandExecuted = true; } - } - else if(len == MGMLIS3MDL::TEMPERATURE_REPLY_LEN) { - *foundLen = len; - *foundId = MGMLIS3MDL::READ_TEMPERATURE; - } - else if (len == MGMLIS3MDL::SETUP_REPLY_LEN) { - *foundLen = len; - *foundId = MGMLIS3MDL::SETUP_MGM; - } - else if (len == SINGLE_COMMAND_ANSWER_LEN) { - *foundLen = len; - *foundId = lastSentCommand; - } - else { - return DeviceHandlerIF::INVALID_DATA; - } + } + else if(len == MGMLIS3MDL::TEMPERATURE_REPLY_LEN) { + *foundLen = len; + *foundId = MGMLIS3MDL::READ_TEMPERATURE; + } + else if (len == MGMLIS3MDL::SETUP_REPLY_LEN) { + *foundLen = len; + *foundId = MGMLIS3MDL::SETUP_MGM; + } + else if (len == SINGLE_COMMAND_ANSWER_LEN) { + *foundLen = len; + *foundId = lastSentCommand; + } + else { + return DeviceHandlerIF::INVALID_DATA; + } - // Data with SPI Interface has always this answer - if (start[0] == 0b11111111) { - return RETURN_OK; - } - else { - return DeviceHandlerIF::INVALID_DATA; - } + // Data with SPI Interface has always this answer + if (start[0] == 0b11111111) { + return RETURN_OK; + } + else { + return DeviceHandlerIF::INVALID_DATA; + } } ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id, - const uint8_t *packet) { + const uint8_t *packet) { - switch (id) { - case MGMLIS3MDL::IDENTIFY_DEVICE: { - break; - } - case MGMLIS3MDL::SETUP_MGM: { - break; - } - case MGMLIS3MDL::READ_CONFIG_AND_DATA: { - // TODO: Store configuration and sensor values in new local datasets. + switch (id) { + case MGMLIS3MDL::IDENTIFY_DEVICE: { + break; + } + case MGMLIS3MDL::SETUP_MGM: { + break; + } + case MGMLIS3MDL::READ_CONFIG_AND_DATA: { + // TODO: Store configuration and sensor values in new local datasets. - uint8_t scale = getFullScale(registers[2]); - float sensitivityFactor = getSensitivityFactor(scale); + uint8_t scale = getFullScale(registers[2]); + float sensitivityFactor = getSensitivityFactor(scale); - int16_t mgmMeasurementRawX = packet[MGMLIS3MDL::X_HIGHBYTE_IDX] << 8 - | packet[MGMLIS3MDL::X_LOWBYTE_IDX] ; + int16_t mgmMeasurementRawX = packet[MGMLIS3MDL::X_HIGHBYTE_IDX] << 8 + | packet[MGMLIS3MDL::X_LOWBYTE_IDX] ; int16_t mgmMeasurementRawY = packet[MGMLIS3MDL::Y_HIGHBYTE_IDX] << 8 | packet[MGMLIS3MDL::Y_LOWBYTE_IDX] ; int16_t mgmMeasurementRawZ = packet[MGMLIS3MDL::Z_HIGHBYTE_IDX] << 8 | packet[MGMLIS3MDL::Z_LOWBYTE_IDX] ; - // Target value in microtesla - float mgmX = static_cast(mgmMeasurementRawX) * sensitivityFactor - * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; - float mgmY = static_cast(mgmMeasurementRawY) * sensitivityFactor - * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; - float mgmZ = static_cast(mgmMeasurementRawZ) * sensitivityFactor - * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; + // Target value in microtesla + float mgmX = static_cast(mgmMeasurementRawX) * sensitivityFactor + * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; + float mgmY = static_cast(mgmMeasurementRawY) * sensitivityFactor + * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; + float mgmZ = static_cast(mgmMeasurementRawZ) * sensitivityFactor + * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; #if OBSW_ENHANCED_PRINTOUT == 1 - if(debugDivider->checkAndIncrement()) { + if(debugDivider->checkAndIncrement()) { sif::info << "MGMHandlerLIS3: Magnetic field strength in" " microtesla:" << std::endl; // Set terminal to utf-8 if there is an issue with micro printout. sif::info << "X: " << mgmX << " \xC2\xB5T" << std::endl; sif::info << "Y: " << mgmY << " \xC2\xB5T" << std::endl; sif::info << "Z: " << mgmZ << " \xC2\xB5T" << std::endl; - } + } #endif - break; - } + break; + } - case MGMLIS3MDL::READ_TEMPERATURE: { - int16_t tempValueRaw = packet[2] << 8 | packet[1]; + case MGMLIS3MDL::READ_TEMPERATURE: { + int16_t tempValueRaw = packet[2] << 8 | packet[1]; float tempValue = 25.0 + ((static_cast(tempValueRaw)) / 8.0); #if OBSW_ENHANCED_PRINTOUT == 1 if(debugDivider->check()) { @@ -267,131 +267,131 @@ ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id, } #endif break; - } + } - default: { - return DeviceHandlerIF::UNKNOW_DEVICE_REPLY; - } + default: { + return DeviceHandlerIF::UNKNOW_DEVICE_REPLY; + } - } - return RETURN_OK; + } + return RETURN_OK; } uint8_t MGMHandlerLIS3MDL::getFullScale(uint8_t ctrlRegister2) { - bool FS0 = false; - bool FS1 = false; - if ((ctrlRegister2 >> 5) == 1) - FS0 = true; - if ((ctrlRegister2 >> 6) == 1) - FS1 = true; - if ((FS0 == true) && (FS1 == true)) - return 16; - else if ((FS0 == false) && (FS1 == true)) - return 12; - else if ((FS0 == true) && (FS1 == false)) - return 8; - else - return 4; + bool FS0 = false; + bool FS1 = false; + if ((ctrlRegister2 >> 5) == 1) + FS0 = true; + if ((ctrlRegister2 >> 6) == 1) + FS1 = true; + if ((FS0 == true) && (FS1 == true)) + return 16; + else if ((FS0 == false) && (FS1 == true)) + return 12; + else if ((FS0 == true) && (FS1 == false)) + return 8; + else + return 4; } float MGMHandlerLIS3MDL::getSensitivityFactor(uint8_t scale) { - return (float) scale / (INT16_MAX); + return (float) scale / (INT16_MAX); } ReturnValue_t MGMHandlerLIS3MDL::enableTemperatureSensor( - const uint8_t *commandData, size_t commandDataLen) { - triggerEvent(CHANGE_OF_SETUP_PARAMETER); - uint32_t size = 2; - commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1); - if (commandDataLen > 1) { - return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; - } - switch (*commandData) { - case (MGMLIS3MDL::ON): - commandBuffer[1] = registers[0] | (1 << 7); - break; + const uint8_t *commandData, size_t commandDataLen) { + triggerEvent(CHANGE_OF_SETUP_PARAMETER); + uint32_t size = 2; + commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1); + if (commandDataLen > 1) { + return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; + } + switch (*commandData) { + case (MGMLIS3MDL::ON): + commandBuffer[1] = registers[0] | (1 << 7); + break; - case (MGMLIS3MDL::OFF): - commandBuffer[1] = registers[0] & ~(1 << 7); - break; + case (MGMLIS3MDL::OFF): + commandBuffer[1] = registers[0] & ~(1 << 7); + break; - default: - return INVALID_COMMAND_PARAMETER; - break; - } - registers[0] = commandBuffer[1]; + default: + return INVALID_COMMAND_PARAMETER; + break; + } + registers[0] = commandBuffer[1]; - rawPacket = commandBuffer; - rawPacketLen = size; + rawPacket = commandBuffer; + rawPacketLen = size; - return RETURN_OK; + return RETURN_OK; } ReturnValue_t MGMHandlerLIS3MDL::setOperatingMode(const uint8_t *commandData, - size_t commandDataLen) { - triggerEvent(CHANGE_OF_SETUP_PARAMETER); - if (commandDataLen != 1) { - return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; - } + size_t commandDataLen) { + triggerEvent(CHANGE_OF_SETUP_PARAMETER); + if (commandDataLen != 1) { + return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; + } - switch (commandData[0]) { - case MGMLIS3MDL::LOW: - registers[0] = (registers[0] & (~(1 << MGMLIS3MDL::OM1))) & (~(1 << MGMLIS3MDL::OM0)); - registers[3] = (registers[3] & (~(1 << MGMLIS3MDL::OMZ1))) & (~(1 << MGMLIS3MDL::OMZ0)); - break; - case MGMLIS3MDL::MEDIUM: - registers[0] = (registers[0] & (~(1 << MGMLIS3MDL::OM1))) | (1 << MGMLIS3MDL::OM0); - registers[3] = (registers[3] & (~(1 << MGMLIS3MDL::OMZ1))) | (1 << MGMLIS3MDL::OMZ0); - break; + switch (commandData[0]) { + case MGMLIS3MDL::LOW: + registers[0] = (registers[0] & (~(1 << MGMLIS3MDL::OM1))) & (~(1 << MGMLIS3MDL::OM0)); + registers[3] = (registers[3] & (~(1 << MGMLIS3MDL::OMZ1))) & (~(1 << MGMLIS3MDL::OMZ0)); + break; + case MGMLIS3MDL::MEDIUM: + registers[0] = (registers[0] & (~(1 << MGMLIS3MDL::OM1))) | (1 << MGMLIS3MDL::OM0); + registers[3] = (registers[3] & (~(1 << MGMLIS3MDL::OMZ1))) | (1 << MGMLIS3MDL::OMZ0); + break; - case MGMLIS3MDL::HIGH: - registers[0] = (registers[0] | (1 << MGMLIS3MDL::OM1)) & (~(1 << MGMLIS3MDL::OM0)); - registers[3] = (registers[3] | (1 << MGMLIS3MDL::OMZ1)) & (~(1 << MGMLIS3MDL::OMZ0)); - break; + case MGMLIS3MDL::HIGH: + registers[0] = (registers[0] | (1 << MGMLIS3MDL::OM1)) & (~(1 << MGMLIS3MDL::OM0)); + registers[3] = (registers[3] | (1 << MGMLIS3MDL::OMZ1)) & (~(1 << MGMLIS3MDL::OMZ0)); + break; - case MGMLIS3MDL::ULTRA: - registers[0] = (registers[0] | (1 << MGMLIS3MDL::OM1)) | (1 << MGMLIS3MDL::OM0); - registers[3] = (registers[3] | (1 << MGMLIS3MDL::OMZ1)) | (1 << MGMLIS3MDL::OMZ0); - break; - default: - break; - } + case MGMLIS3MDL::ULTRA: + registers[0] = (registers[0] | (1 << MGMLIS3MDL::OM1)) | (1 << MGMLIS3MDL::OM0); + registers[3] = (registers[3] | (1 << MGMLIS3MDL::OMZ1)) | (1 << MGMLIS3MDL::OMZ0); + break; + default: + break; + } - return prepareCtrlRegisterWrite(); + return prepareCtrlRegisterWrite(); } void MGMHandlerLIS3MDL::fillCommandAndReplyMap() { - /* - * Regarding ArduinoBoard: - * Actually SPI answers directly, but as commanding ArduinoBoard the - * communication could be delayed - * SPI always has to be triggered, so there could be no periodic answer of - * the device, the device has to asked with a command, so periodic is zero. - * - * We dont read single registers, we just expect special - * reply from he Readall_MGM - */ - insertInCommandAndReplyMap(MGMLIS3MDL::READ_CONFIG_AND_DATA, 1); - insertInCommandAndReplyMap(MGMLIS3MDL::READ_TEMPERATURE, 1); - insertInCommandAndReplyMap(MGMLIS3MDL::SETUP_MGM, 1); - insertInCommandAndReplyMap(MGMLIS3MDL::IDENTIFY_DEVICE, 1); - insertInCommandAndReplyMap(MGMLIS3MDL::TEMP_SENSOR_ENABLE, 1); - insertInCommandAndReplyMap(MGMLIS3MDL::ACCURACY_OP_MODE_SET, 1); + /* + * Regarding ArduinoBoard: + * Actually SPI answers directly, but as commanding ArduinoBoard the + * communication could be delayed + * SPI always has to be triggered, so there could be no periodic answer of + * the device, the device has to asked with a command, so periodic is zero. + * + * We dont read single registers, we just expect special + * reply from he Readall_MGM + */ + insertInCommandAndReplyMap(MGMLIS3MDL::READ_CONFIG_AND_DATA, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::READ_TEMPERATURE, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::SETUP_MGM, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::IDENTIFY_DEVICE, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::TEMP_SENSOR_ENABLE, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::ACCURACY_OP_MODE_SET, 1); } ReturnValue_t MGMHandlerLIS3MDL::prepareCtrlRegisterWrite() { - commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1, true); + commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1, true); - for (size_t i = 0; i < MGMLIS3MDL::NR_OF_CTRL_REGISTERS; i++) { - commandBuffer[i + 1] = registers[i]; - } - rawPacket = commandBuffer; - rawPacketLen = MGMLIS3MDL::NR_OF_CTRL_REGISTERS + 1; + for (size_t i = 0; i < MGMLIS3MDL::NR_OF_CTRL_REGISTERS; i++) { + commandBuffer[i + 1] = registers[i]; + } + rawPacket = commandBuffer; + rawPacketLen = MGMLIS3MDL::NR_OF_CTRL_REGISTERS + 1; - // We dont have to check if this is working because we just did it - return RETURN_OK; + // We dont have to check if this is working because we just did it + return RETURN_OK; } void MGMHandlerLIS3MDL::setNormalDatapoolEntriesInvalid() { @@ -407,7 +407,7 @@ uint32_t MGMHandlerLIS3MDL::getTransitionDelayMs(Mode_t from, Mode_t to) { } void MGMHandlerLIS3MDL::modeChanged(void) { - internalState = STATE_NONE; + internalState = STATE_NONE; } ReturnValue_t MGMHandlerLIS3MDL::initializeLocalDataPool( From 269b8ee9b8e736eba0c52ec0ec0d24164f336f8e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Dec 2020 22:21:47 +0100 Subject: [PATCH 08/27] again, indentation.. --- mission/devices/MGMHandlerLIS3MDL.cpp | 610 +++++++++++++------------- mission/devices/MGMHandlerLIS3MDL.h | 25 +- 2 files changed, 317 insertions(+), 318 deletions(-) diff --git a/mission/devices/MGMHandlerLIS3MDL.cpp b/mission/devices/MGMHandlerLIS3MDL.cpp index 50d0ce3c..acc6d749 100644 --- a/mission/devices/MGMHandlerLIS3MDL.cpp +++ b/mission/devices/MGMHandlerLIS3MDL.cpp @@ -2,17 +2,17 @@ MGMHandlerLIS3MDL::MGMHandlerLIS3MDL(object_id_t objectId, - object_id_t deviceCommunication, CookieIF* comCookie): - DeviceHandlerBase(objectId, deviceCommunication, comCookie) { + object_id_t deviceCommunication, CookieIF* comCookie): + DeviceHandlerBase(objectId, deviceCommunication, comCookie) { #if OBSW_ENHANCED_PRINTOUT == 1 - debugDivider = new PeriodicOperationDivider(10); + debugDivider = new PeriodicOperationDivider(10); #endif - // Set to default values right away. - registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT; - registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT; - registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT; - registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT; - registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT; + // Set to default values right away. + registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT; + registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT; + registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT; + registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT; + registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT; } @@ -21,381 +21,381 @@ MGMHandlerLIS3MDL::~MGMHandlerLIS3MDL() { void MGMHandlerLIS3MDL::doStartUp() { - switch (internalState) { - case STATE_NONE: - internalState = STATE_FIRST_CONTACT; - break; + switch (internalState) { + case STATE_NONE: + internalState = STATE_FIRST_CONTACT; + break; - case STATE_FIRST_CONTACT: - internalState = STATE_SETUP; - break; + case STATE_FIRST_CONTACT: + internalState = STATE_SETUP; + break; - case STATE_SETUP: - internalState = STATE_CHECK_REGISTERS; - break; + case STATE_SETUP: + internalState = STATE_CHECK_REGISTERS; + break; - case STATE_CHECK_REGISTERS: { - // Set up cached registers which will be used to configure the MGM. - if(commandExecuted) { - commandExecuted = false; - setMode(MODE_NORMAL); - } - break; - } - default: - break; - } + case STATE_CHECK_REGISTERS: { + // Set up cached registers which will be used to configure the MGM. + if(commandExecuted) { + commandExecuted = false; + setMode(MODE_NORMAL); + } + break; + } + default: + break; + } } void MGMHandlerLIS3MDL::doShutDown() { - setMode(_MODE_POWER_DOWN); + setMode(_MODE_POWER_DOWN); } ReturnValue_t MGMHandlerLIS3MDL::buildTransitionDeviceCommand( - DeviceCommandId_t *id) { - switch (internalState) { - case STATE_FIRST_CONTACT: - *id = MGMLIS3MDL::IDENTIFY_DEVICE; - break; + DeviceCommandId_t *id) { + switch (internalState) { + case STATE_FIRST_CONTACT: + *id = MGMLIS3MDL::IDENTIFY_DEVICE; + break; - case STATE_SETUP: - *id = MGMLIS3MDL::SETUP_MGM; - break; + case STATE_SETUP: + *id = MGMLIS3MDL::SETUP_MGM; + break; - case STATE_CHECK_REGISTERS: - *id = MGMLIS3MDL::READ_CONFIG_AND_DATA; - break; + case STATE_CHECK_REGISTERS: + *id = MGMLIS3MDL::READ_CONFIG_AND_DATA; + break; - default: - break; - } - return buildCommandFromCommand(*id, NULL, 0); + default: + break; + } + return buildCommandFromCommand(*id, NULL, 0); } uint8_t MGMHandlerLIS3MDL::readCommand(uint8_t command, bool continuousCom) { - command |= (1 << MGMLIS3MDL::RW_BIT); - if (continuousCom == true) { - command |= (1 << MGMLIS3MDL::MS_BIT); - } - return command; + command |= (1 << MGMLIS3MDL::RW_BIT); + if (continuousCom == true) { + command |= (1 << MGMLIS3MDL::MS_BIT); + } + return command; } uint8_t MGMHandlerLIS3MDL::writeCommand(uint8_t command, bool continuousCom) { - command &= ~(1 << MGMLIS3MDL::RW_BIT); - if (continuousCom == true) { - command |= (1 << MGMLIS3MDL::MS_BIT); - } - return command; + command &= ~(1 << MGMLIS3MDL::RW_BIT); + if (continuousCom == true) { + command |= (1 << MGMLIS3MDL::MS_BIT); + } + return command; } void MGMHandlerLIS3MDL::setupMgm() { - registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT; - registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT; - registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT; - registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT; - registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT; + registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT; + registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT; + registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT; + registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT; + registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT; - prepareCtrlRegisterWrite(); + prepareCtrlRegisterWrite(); } ReturnValue_t MGMHandlerLIS3MDL::buildNormalDeviceCommand( - DeviceCommandId_t *id) { - // Data/config register will be read in an alternating manner. - if(communicationStep == CommunicationStep::DATA) { - lastSentCommand = MGMLIS3MDL::READ_CONFIG_AND_DATA; - *id = MGMLIS3MDL::READ_CONFIG_AND_DATA; - communicationStep = CommunicationStep::TEMPERATURE; - return buildCommandFromCommand(*id, NULL, 0); - } - else { - lastSentCommand = MGMLIS3MDL::READ_TEMPERATURE; - *id = MGMLIS3MDL::READ_TEMPERATURE; - communicationStep = CommunicationStep::DATA; - return buildCommandFromCommand(*id, NULL, 0); - } + DeviceCommandId_t *id) { + // Data/config register will be read in an alternating manner. + if(communicationStep == CommunicationStep::DATA) { + lastSentCommand = MGMLIS3MDL::READ_CONFIG_AND_DATA; + *id = MGMLIS3MDL::READ_CONFIG_AND_DATA; + communicationStep = CommunicationStep::TEMPERATURE; + return buildCommandFromCommand(*id, NULL, 0); + } + else { + lastSentCommand = MGMLIS3MDL::READ_TEMPERATURE; + *id = MGMLIS3MDL::READ_TEMPERATURE; + communicationStep = CommunicationStep::DATA; + return buildCommandFromCommand(*id, NULL, 0); + } } ReturnValue_t MGMHandlerLIS3MDL::buildCommandFromCommand( - DeviceCommandId_t deviceCommand, const uint8_t *commandData, - size_t commandDataLen) { - lastSentCommand = deviceCommand; - switch(deviceCommand) { - case(MGMLIS3MDL::READ_CONFIG_AND_DATA): { - std::memset(commandBuffer, 0, sizeof(commandBuffer)); - commandBuffer[0] = readCommand(MGMLIS3MDL::CTRL_REG1, true); + DeviceCommandId_t deviceCommand, const uint8_t *commandData, + size_t commandDataLen) { + lastSentCommand = deviceCommand; + switch(deviceCommand) { + case(MGMLIS3MDL::READ_CONFIG_AND_DATA): { + std::memset(commandBuffer, 0, sizeof(commandBuffer)); + commandBuffer[0] = readCommand(MGMLIS3MDL::CTRL_REG1, true); - rawPacket = commandBuffer; - rawPacketLen = MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1; - return RETURN_OK; - } - case(MGMLIS3MDL::READ_TEMPERATURE): { - std::memset(commandBuffer, 0, 3); - commandBuffer[0] = readCommand(MGMLIS3MDL::TEMP_LOWBYTE, true); + rawPacket = commandBuffer; + rawPacketLen = MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1; + return RETURN_OK; + } + case(MGMLIS3MDL::READ_TEMPERATURE): { + std::memset(commandBuffer, 0, 3); + commandBuffer[0] = readCommand(MGMLIS3MDL::TEMP_LOWBYTE, true); - rawPacket = commandBuffer; - rawPacketLen = 3; - return RETURN_OK; - } - case(MGMLIS3MDL::IDENTIFY_DEVICE): { - return identifyDevice(); - } - case(MGMLIS3MDL::TEMP_SENSOR_ENABLE): { - return enableTemperatureSensor(commandData, commandDataLen); - } - case(MGMLIS3MDL::SETUP_MGM): { - setupMgm(); - return HasReturnvaluesIF::RETURN_OK; - } - case(MGMLIS3MDL::ACCURACY_OP_MODE_SET): { - return setOperatingMode(commandData, commandDataLen); - } - default: - lastSentCommand = DeviceHandlerIF::NO_COMMAND; - return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; - } - return HasReturnvaluesIF::RETURN_FAILED; + rawPacket = commandBuffer; + rawPacketLen = 3; + return RETURN_OK; + } + case(MGMLIS3MDL::IDENTIFY_DEVICE): { + return identifyDevice(); + } + case(MGMLIS3MDL::TEMP_SENSOR_ENABLE): { + return enableTemperatureSensor(commandData, commandDataLen); + } + case(MGMLIS3MDL::SETUP_MGM): { + setupMgm(); + return HasReturnvaluesIF::RETURN_OK; + } + case(MGMLIS3MDL::ACCURACY_OP_MODE_SET): { + return setOperatingMode(commandData, commandDataLen); + } + default: + lastSentCommand = DeviceHandlerIF::NO_COMMAND; + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return HasReturnvaluesIF::RETURN_FAILED; } ReturnValue_t MGMHandlerLIS3MDL::identifyDevice() { - uint32_t size = 2; - commandBuffer[0] = readCommand(MGMLIS3MDL::IDENTIFY_DEVICE_REG_ADDR); - commandBuffer[1] = 0x00; + uint32_t size = 2; + commandBuffer[0] = readCommand(MGMLIS3MDL::IDENTIFY_DEVICE_REG_ADDR); + commandBuffer[1] = 0x00; - rawPacket = commandBuffer; - rawPacketLen = size; + rawPacket = commandBuffer; + rawPacketLen = size; - return RETURN_OK; + return RETURN_OK; } ReturnValue_t MGMHandlerLIS3MDL::scanForReply(const uint8_t *start, - size_t len, DeviceCommandId_t *foundId, size_t *foundLen) { - *foundLen = len; - if (len == MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1) { - *foundLen = len; - *foundId = MGMLIS3MDL::READ_CONFIG_AND_DATA; - // Check validity by checking config registers - if (start[1] != registers[0] or start[2] != registers[1] or - start[3] != registers[2] or start[4] != registers[3] or - start[5] != registers[4]) { - return DeviceHandlerIF::INVALID_DATA; - } - if(mode == _MODE_START_UP) { - commandExecuted = true; - } + size_t len, DeviceCommandId_t *foundId, size_t *foundLen) { + *foundLen = len; + if (len == MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1) { + *foundLen = len; + *foundId = MGMLIS3MDL::READ_CONFIG_AND_DATA; + // Check validity by checking config registers + if (start[1] != registers[0] or start[2] != registers[1] or + start[3] != registers[2] or start[4] != registers[3] or + start[5] != registers[4]) { + return DeviceHandlerIF::INVALID_DATA; + } + if(mode == _MODE_START_UP) { + commandExecuted = true; + } - } - else if(len == MGMLIS3MDL::TEMPERATURE_REPLY_LEN) { - *foundLen = len; - *foundId = MGMLIS3MDL::READ_TEMPERATURE; - } - else if (len == MGMLIS3MDL::SETUP_REPLY_LEN) { - *foundLen = len; - *foundId = MGMLIS3MDL::SETUP_MGM; - } - else if (len == SINGLE_COMMAND_ANSWER_LEN) { - *foundLen = len; - *foundId = lastSentCommand; - } - else { - return DeviceHandlerIF::INVALID_DATA; - } + } + else if(len == MGMLIS3MDL::TEMPERATURE_REPLY_LEN) { + *foundLen = len; + *foundId = MGMLIS3MDL::READ_TEMPERATURE; + } + else if (len == MGMLIS3MDL::SETUP_REPLY_LEN) { + *foundLen = len; + *foundId = MGMLIS3MDL::SETUP_MGM; + } + else if (len == SINGLE_COMMAND_ANSWER_LEN) { + *foundLen = len; + *foundId = lastSentCommand; + } + else { + return DeviceHandlerIF::INVALID_DATA; + } - // Data with SPI Interface has always this answer - if (start[0] == 0b11111111) { - return RETURN_OK; - } - else { - return DeviceHandlerIF::INVALID_DATA; - } + // Data with SPI Interface has always this answer + if (start[0] == 0b11111111) { + return RETURN_OK; + } + else { + return DeviceHandlerIF::INVALID_DATA; + } } ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id, - const uint8_t *packet) { + const uint8_t *packet) { - switch (id) { - case MGMLIS3MDL::IDENTIFY_DEVICE: { - break; - } - case MGMLIS3MDL::SETUP_MGM: { - break; - } - case MGMLIS3MDL::READ_CONFIG_AND_DATA: { - // TODO: Store configuration and sensor values in new local datasets. + switch (id) { + case MGMLIS3MDL::IDENTIFY_DEVICE: { + break; + } + case MGMLIS3MDL::SETUP_MGM: { + break; + } + case MGMLIS3MDL::READ_CONFIG_AND_DATA: { + // TODO: Store configuration and sensor values in new local datasets. - uint8_t scale = getFullScale(registers[2]); - float sensitivityFactor = getSensitivityFactor(scale); + uint8_t scale = getFullScale(registers[2]); + float sensitivityFactor = getSensitivityFactor(scale); - int16_t mgmMeasurementRawX = packet[MGMLIS3MDL::X_HIGHBYTE_IDX] << 8 - | packet[MGMLIS3MDL::X_LOWBYTE_IDX] ; - int16_t mgmMeasurementRawY = packet[MGMLIS3MDL::Y_HIGHBYTE_IDX] << 8 - | packet[MGMLIS3MDL::Y_LOWBYTE_IDX] ; - int16_t mgmMeasurementRawZ = packet[MGMLIS3MDL::Z_HIGHBYTE_IDX] << 8 - | packet[MGMLIS3MDL::Z_LOWBYTE_IDX] ; + int16_t mgmMeasurementRawX = packet[MGMLIS3MDL::X_HIGHBYTE_IDX] << 8 + | packet[MGMLIS3MDL::X_LOWBYTE_IDX] ; + int16_t mgmMeasurementRawY = packet[MGMLIS3MDL::Y_HIGHBYTE_IDX] << 8 + | packet[MGMLIS3MDL::Y_LOWBYTE_IDX] ; + int16_t mgmMeasurementRawZ = packet[MGMLIS3MDL::Z_HIGHBYTE_IDX] << 8 + | packet[MGMLIS3MDL::Z_LOWBYTE_IDX] ; - // Target value in microtesla - float mgmX = static_cast(mgmMeasurementRawX) * sensitivityFactor - * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; - float mgmY = static_cast(mgmMeasurementRawY) * sensitivityFactor - * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; - float mgmZ = static_cast(mgmMeasurementRawZ) * sensitivityFactor - * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; + // Target value in microtesla + float mgmX = static_cast(mgmMeasurementRawX) * sensitivityFactor + * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; + float mgmY = static_cast(mgmMeasurementRawY) * sensitivityFactor + * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; + float mgmZ = static_cast(mgmMeasurementRawZ) * sensitivityFactor + * MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR; #if OBSW_ENHANCED_PRINTOUT == 1 - if(debugDivider->checkAndIncrement()) { - sif::info << "MGMHandlerLIS3: Magnetic field strength in" - " microtesla:" << std::endl; - // Set terminal to utf-8 if there is an issue with micro printout. - sif::info << "X: " << mgmX << " \xC2\xB5T" << std::endl; - sif::info << "Y: " << mgmY << " \xC2\xB5T" << std::endl; - sif::info << "Z: " << mgmZ << " \xC2\xB5T" << std::endl; - } + if(debugDivider->checkAndIncrement()) { + sif::info << "MGMHandlerLIS3: Magnetic field strength in" + " microtesla:" << std::endl; + // Set terminal to utf-8 if there is an issue with micro printout. + sif::info << "X: " << mgmX << " \xC2\xB5T" << std::endl; + sif::info << "Y: " << mgmY << " \xC2\xB5T" << std::endl; + sif::info << "Z: " << mgmZ << " \xC2\xB5T" << std::endl; + } #endif - break; - } + break; + } - case MGMLIS3MDL::READ_TEMPERATURE: { - int16_t tempValueRaw = packet[2] << 8 | packet[1]; - float tempValue = 25.0 + ((static_cast(tempValueRaw)) / 8.0); + case MGMLIS3MDL::READ_TEMPERATURE: { + int16_t tempValueRaw = packet[2] << 8 | packet[1]; + float tempValue = 25.0 + ((static_cast(tempValueRaw)) / 8.0); #if OBSW_ENHANCED_PRINTOUT == 1 - if(debugDivider->check()) { - // Set terminal to utf-8 if there is an issue with micro printout. - sif::info << "MGMHandlerLIS3: Temperature: " << tempValue<< " °C" - << std::endl; - } + if(debugDivider->check()) { + // Set terminal to utf-8 if there is an issue with micro printout. + sif::info << "MGMHandlerLIS3: Temperature: " << tempValue<< " °C" + << std::endl; + } #endif - break; - } + break; + } - default: { - return DeviceHandlerIF::UNKNOW_DEVICE_REPLY; - } + default: { + return DeviceHandlerIF::UNKNOW_DEVICE_REPLY; + } - } - return RETURN_OK; + } + return RETURN_OK; } uint8_t MGMHandlerLIS3MDL::getFullScale(uint8_t ctrlRegister2) { - bool FS0 = false; - bool FS1 = false; - if ((ctrlRegister2 >> 5) == 1) - FS0 = true; - if ((ctrlRegister2 >> 6) == 1) - FS1 = true; - if ((FS0 == true) && (FS1 == true)) - return 16; - else if ((FS0 == false) && (FS1 == true)) - return 12; - else if ((FS0 == true) && (FS1 == false)) - return 8; - else - return 4; + bool FS0 = false; + bool FS1 = false; + if ((ctrlRegister2 >> 5) == 1) + FS0 = true; + if ((ctrlRegister2 >> 6) == 1) + FS1 = true; + if ((FS0 == true) && (FS1 == true)) + return 16; + else if ((FS0 == false) && (FS1 == true)) + return 12; + else if ((FS0 == true) && (FS1 == false)) + return 8; + else + return 4; } float MGMHandlerLIS3MDL::getSensitivityFactor(uint8_t scale) { - return (float) scale / (INT16_MAX); + return (float) scale / (INT16_MAX); } ReturnValue_t MGMHandlerLIS3MDL::enableTemperatureSensor( - const uint8_t *commandData, size_t commandDataLen) { - triggerEvent(CHANGE_OF_SETUP_PARAMETER); - uint32_t size = 2; - commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1); - if (commandDataLen > 1) { - return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; - } - switch (*commandData) { - case (MGMLIS3MDL::ON): - commandBuffer[1] = registers[0] | (1 << 7); - break; + const uint8_t *commandData, size_t commandDataLen) { + triggerEvent(CHANGE_OF_SETUP_PARAMETER); + uint32_t size = 2; + commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1); + if (commandDataLen > 1) { + return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; + } + switch (*commandData) { + case (MGMLIS3MDL::ON): + commandBuffer[1] = registers[0] | (1 << 7); + break; - case (MGMLIS3MDL::OFF): - commandBuffer[1] = registers[0] & ~(1 << 7); - break; + case (MGMLIS3MDL::OFF): + commandBuffer[1] = registers[0] & ~(1 << 7); + break; - default: - return INVALID_COMMAND_PARAMETER; - break; - } - registers[0] = commandBuffer[1]; + default: + return INVALID_COMMAND_PARAMETER; + break; + } + registers[0] = commandBuffer[1]; - rawPacket = commandBuffer; - rawPacketLen = size; + rawPacket = commandBuffer; + rawPacketLen = size; - return RETURN_OK; + return RETURN_OK; } ReturnValue_t MGMHandlerLIS3MDL::setOperatingMode(const uint8_t *commandData, - size_t commandDataLen) { - triggerEvent(CHANGE_OF_SETUP_PARAMETER); - if (commandDataLen != 1) { - return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; - } + size_t commandDataLen) { + triggerEvent(CHANGE_OF_SETUP_PARAMETER); + if (commandDataLen != 1) { + return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; + } - switch (commandData[0]) { - case MGMLIS3MDL::LOW: - registers[0] = (registers[0] & (~(1 << MGMLIS3MDL::OM1))) & (~(1 << MGMLIS3MDL::OM0)); - registers[3] = (registers[3] & (~(1 << MGMLIS3MDL::OMZ1))) & (~(1 << MGMLIS3MDL::OMZ0)); - break; - case MGMLIS3MDL::MEDIUM: - registers[0] = (registers[0] & (~(1 << MGMLIS3MDL::OM1))) | (1 << MGMLIS3MDL::OM0); - registers[3] = (registers[3] & (~(1 << MGMLIS3MDL::OMZ1))) | (1 << MGMLIS3MDL::OMZ0); - break; + switch (commandData[0]) { + case MGMLIS3MDL::LOW: + registers[0] = (registers[0] & (~(1 << MGMLIS3MDL::OM1))) & (~(1 << MGMLIS3MDL::OM0)); + registers[3] = (registers[3] & (~(1 << MGMLIS3MDL::OMZ1))) & (~(1 << MGMLIS3MDL::OMZ0)); + break; + case MGMLIS3MDL::MEDIUM: + registers[0] = (registers[0] & (~(1 << MGMLIS3MDL::OM1))) | (1 << MGMLIS3MDL::OM0); + registers[3] = (registers[3] & (~(1 << MGMLIS3MDL::OMZ1))) | (1 << MGMLIS3MDL::OMZ0); + break; - case MGMLIS3MDL::HIGH: - registers[0] = (registers[0] | (1 << MGMLIS3MDL::OM1)) & (~(1 << MGMLIS3MDL::OM0)); - registers[3] = (registers[3] | (1 << MGMLIS3MDL::OMZ1)) & (~(1 << MGMLIS3MDL::OMZ0)); - break; + case MGMLIS3MDL::HIGH: + registers[0] = (registers[0] | (1 << MGMLIS3MDL::OM1)) & (~(1 << MGMLIS3MDL::OM0)); + registers[3] = (registers[3] | (1 << MGMLIS3MDL::OMZ1)) & (~(1 << MGMLIS3MDL::OMZ0)); + break; - case MGMLIS3MDL::ULTRA: - registers[0] = (registers[0] | (1 << MGMLIS3MDL::OM1)) | (1 << MGMLIS3MDL::OM0); - registers[3] = (registers[3] | (1 << MGMLIS3MDL::OMZ1)) | (1 << MGMLIS3MDL::OMZ0); - break; - default: - break; - } + case MGMLIS3MDL::ULTRA: + registers[0] = (registers[0] | (1 << MGMLIS3MDL::OM1)) | (1 << MGMLIS3MDL::OM0); + registers[3] = (registers[3] | (1 << MGMLIS3MDL::OMZ1)) | (1 << MGMLIS3MDL::OMZ0); + break; + default: + break; + } - return prepareCtrlRegisterWrite(); + return prepareCtrlRegisterWrite(); } void MGMHandlerLIS3MDL::fillCommandAndReplyMap() { - /* - * Regarding ArduinoBoard: - * Actually SPI answers directly, but as commanding ArduinoBoard the - * communication could be delayed - * SPI always has to be triggered, so there could be no periodic answer of - * the device, the device has to asked with a command, so periodic is zero. - * - * We dont read single registers, we just expect special - * reply from he Readall_MGM - */ - insertInCommandAndReplyMap(MGMLIS3MDL::READ_CONFIG_AND_DATA, 1); - insertInCommandAndReplyMap(MGMLIS3MDL::READ_TEMPERATURE, 1); - insertInCommandAndReplyMap(MGMLIS3MDL::SETUP_MGM, 1); - insertInCommandAndReplyMap(MGMLIS3MDL::IDENTIFY_DEVICE, 1); - insertInCommandAndReplyMap(MGMLIS3MDL::TEMP_SENSOR_ENABLE, 1); - insertInCommandAndReplyMap(MGMLIS3MDL::ACCURACY_OP_MODE_SET, 1); + /* + * Regarding ArduinoBoard: + * Actually SPI answers directly, but as commanding ArduinoBoard the + * communication could be delayed + * SPI always has to be triggered, so there could be no periodic answer of + * the device, the device has to asked with a command, so periodic is zero. + * + * We dont read single registers, we just expect special + * reply from he Readall_MGM + */ + insertInCommandAndReplyMap(MGMLIS3MDL::READ_CONFIG_AND_DATA, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::READ_TEMPERATURE, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::SETUP_MGM, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::IDENTIFY_DEVICE, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::TEMP_SENSOR_ENABLE, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::ACCURACY_OP_MODE_SET, 1); } ReturnValue_t MGMHandlerLIS3MDL::prepareCtrlRegisterWrite() { - commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1, true); + commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1, true); - for (size_t i = 0; i < MGMLIS3MDL::NR_OF_CTRL_REGISTERS; i++) { - commandBuffer[i + 1] = registers[i]; - } - rawPacket = commandBuffer; - rawPacketLen = MGMLIS3MDL::NR_OF_CTRL_REGISTERS + 1; + for (size_t i = 0; i < MGMLIS3MDL::NR_OF_CTRL_REGISTERS; i++) { + commandBuffer[i + 1] = registers[i]; + } + rawPacket = commandBuffer; + rawPacketLen = MGMLIS3MDL::NR_OF_CTRL_REGISTERS + 1; - // We dont have to check if this is working because we just did it - return RETURN_OK; + // We dont have to check if this is working because we just did it + return RETURN_OK; } void MGMHandlerLIS3MDL::setNormalDatapoolEntriesInvalid() { - // TODO: use new distributed datapools here. + // TODO: use new distributed datapools here. } void MGMHandlerLIS3MDL::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { @@ -403,22 +403,22 @@ void MGMHandlerLIS3MDL::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { } uint32_t MGMHandlerLIS3MDL::getTransitionDelayMs(Mode_t from, Mode_t to) { - return 5000; + return 5000; } void MGMHandlerLIS3MDL::modeChanged(void) { - internalState = STATE_NONE; + internalState = STATE_NONE; } ReturnValue_t MGMHandlerLIS3MDL::initializeLocalDataPool( - LocalDataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { - localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_X, - new PoolEntry({0.0})); - localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y, - new PoolEntry({0.0})); - localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z, - new PoolEntry({0.0})); - localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, - new PoolEntry({0.0})); - return HasReturnvaluesIF::RETURN_OK; + LocalDataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { + localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_X, + new PoolEntry({0.0})); + localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y, + new PoolEntry({0.0})); + localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z, + new PoolEntry({0.0})); + localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, + new PoolEntry({0.0})); + return HasReturnvaluesIF::RETURN_OK; } diff --git a/mission/devices/MGMHandlerLIS3MDL.h b/mission/devices/MGMHandlerLIS3MDL.h index 4c06e001..ff95268c 100644 --- a/mission/devices/MGMHandlerLIS3MDL.h +++ b/mission/devices/MGMHandlerLIS3MDL.h @@ -3,13 +3,12 @@ #include "devicedefinitions/MGMHandlerLIS3Definitions.h" -#include +#include +#include #include #include -#include - /** * @brief Device handler object for the LIS3MDL 3-axis magnetometer * by STMicroeletronics @@ -20,10 +19,10 @@ class MGMHandlerLIS3MDL: public DeviceHandlerBase { public: - enum class CommunicationStep { - DATA, - TEMPERATURE - }; + enum class CommunicationStep { + DATA, + TEMPERATURE + }; static const uint8_t INTERFACE_ID = CLASS_ID::MGM_LIS3MDL; static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::MGM_LIS3MDL; @@ -31,7 +30,7 @@ public: static const Event CHANGE_OF_SETUP_PARAMETER = MAKE_EVENT(0, severity::LOW); MGMHandlerLIS3MDL(uint32_t objectId, object_id_t deviceCommunication, - CookieIF* comCookie); + CookieIF* comCookie); virtual ~MGMHandlerLIS3MDL(); protected: @@ -45,18 +44,18 @@ protected: DeviceCommandId_t deviceCommand, const uint8_t *commandData, size_t commandDataLen) override; virtual ReturnValue_t buildTransitionDeviceCommand( - DeviceCommandId_t *id) override; + DeviceCommandId_t *id) override; virtual ReturnValue_t buildNormalDeviceCommand( - DeviceCommandId_t *id) override; + DeviceCommandId_t *id) override; virtual ReturnValue_t scanForReply(const uint8_t *start, size_t len, - DeviceCommandId_t *foundId, size_t *foundLen) override; + DeviceCommandId_t *foundId, size_t *foundLen) override; virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override; virtual void fillCommandAndReplyMap() override; virtual void modeChanged(void) override; void setNormalDatapoolEntriesInvalid() override; ReturnValue_t initializeLocalDataPool(LocalDataPool &localDataPoolMap, - LocalDataPoolManager &poolManager) override; + LocalDataPoolManager &poolManager) override; private: @@ -164,7 +163,7 @@ private: bool commandExecuted = false; #if OBSW_ENHANCED_PRINTOUT == 1 - PeriodicOperationDivider* debugDivider; + PeriodicOperationDivider* debugDivider; #endif }; From 54c11f65037fd452fb923b215733c0d3ebad4a02 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Dec 2020 22:23:28 +0100 Subject: [PATCH 09/27] formatting --- mission/devices/MGMHandlerLIS3MDL.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/mission/devices/MGMHandlerLIS3MDL.cpp b/mission/devices/MGMHandlerLIS3MDL.cpp index acc6d749..3fa9e9ec 100644 --- a/mission/devices/MGMHandlerLIS3MDL.cpp +++ b/mission/devices/MGMHandlerLIS3MDL.cpp @@ -308,17 +308,16 @@ ReturnValue_t MGMHandlerLIS3MDL::enableTemperatureSensor( return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; } switch (*commandData) { - case (MGMLIS3MDL::ON): - commandBuffer[1] = registers[0] | (1 << 7); - break; - - case (MGMLIS3MDL::OFF): - commandBuffer[1] = registers[0] & ~(1 << 7); - break; - + case (MGMLIS3MDL::ON): { + commandBuffer[1] = registers[0] | (1 << 7); + break; + } + case (MGMLIS3MDL::OFF): { + commandBuffer[1] = registers[0] & ~(1 << 7); + break; + } default: return INVALID_COMMAND_PARAMETER; - break; } registers[0] = commandBuffer[1]; From df992638cca8b75a2db693a34cc1e9ce1637a129 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Dec 2020 22:50:15 +0100 Subject: [PATCH 10/27] stuff stored in local poo lnow --- mission/devices/MGMHandlerLIS3MDL.cpp | 17 +++++++++++++++-- mission/devices/MGMHandlerLIS3MDL.h | 2 +- .../MGMHandlerLIS3Definitions.h | 8 ++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/mission/devices/MGMHandlerLIS3MDL.cpp b/mission/devices/MGMHandlerLIS3MDL.cpp index 3fa9e9ec..1cc83bf8 100644 --- a/mission/devices/MGMHandlerLIS3MDL.cpp +++ b/mission/devices/MGMHandlerLIS3MDL.cpp @@ -3,7 +3,8 @@ MGMHandlerLIS3MDL::MGMHandlerLIS3MDL(object_id_t objectId, object_id_t deviceCommunication, CookieIF* comCookie): - DeviceHandlerBase(objectId, deviceCommunication, comCookie) { + DeviceHandlerBase(objectId, deviceCommunication, comCookie), + dataset(this) { #if OBSW_ENHANCED_PRINTOUT == 1 debugDivider = new PeriodicOperationDivider(10); #endif @@ -253,6 +254,13 @@ ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id, sif::info << "Z: " << mgmZ << " \xC2\xB5T" << std::endl; } #endif + ReturnValue_t result = dataset.read(20); + if(result == HasReturnvaluesIF::RETURN_OK) { + dataset.fieldStrengthX = mgmX; + dataset.fieldStrengthY = mgmY; + dataset.fieldStrengthZ = mgmZ; + dataset.commit(20); + } break; } @@ -266,6 +274,11 @@ ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id, << std::endl; } #endif + ReturnValue_t result = dataset.read(20); + if(result == HasReturnvaluesIF::RETURN_OK) { + dataset.temperature = tempValue; + dataset.commit(20); + } break; } @@ -371,7 +384,7 @@ void MGMHandlerLIS3MDL::fillCommandAndReplyMap() { * We dont read single registers, we just expect special * reply from he Readall_MGM */ - insertInCommandAndReplyMap(MGMLIS3MDL::READ_CONFIG_AND_DATA, 1); + insertInCommandAndReplyMap(MGMLIS3MDL::READ_CONFIG_AND_DATA, 1, &dataset); insertInCommandAndReplyMap(MGMLIS3MDL::READ_TEMPERATURE, 1); insertInCommandAndReplyMap(MGMLIS3MDL::SETUP_MGM, 1); insertInCommandAndReplyMap(MGMLIS3MDL::IDENTIFY_DEVICE, 1); diff --git a/mission/devices/MGMHandlerLIS3MDL.h b/mission/devices/MGMHandlerLIS3MDL.h index ff95268c..b400daee 100644 --- a/mission/devices/MGMHandlerLIS3MDL.h +++ b/mission/devices/MGMHandlerLIS3MDL.h @@ -18,7 +18,6 @@ */ class MGMHandlerLIS3MDL: public DeviceHandlerBase { public: - enum class CommunicationStep { DATA, TEMPERATURE @@ -59,6 +58,7 @@ protected: private: + MGMLIS3MDL::MgmPrimaryDataset dataset; /*------------------------------------------------------------------------*/ /* Device specific commands and variables */ diff --git a/mission/devices/devicedefinitions/MGMHandlerLIS3Definitions.h b/mission/devices/devicedefinitions/MGMHandlerLIS3Definitions.h index 2518af15..581e46e3 100644 --- a/mission/devices/devicedefinitions/MGMHandlerLIS3Definitions.h +++ b/mission/devices/devicedefinitions/MGMHandlerLIS3Definitions.h @@ -130,7 +130,7 @@ static const uint8_t BDU = 6; //Block data update static const uint8_t FAST_READ = 7; //Fast read enabled = 1 static const uint8_t CTRL_REG5_DEFAULT = 0; -static const uint32_t MGM_DATA_SET_ID = 0; +static const uint32_t MGM_DATA_SET_ID = READ_CONFIG_AND_DATA; enum MgmPoolIds: lp_id_t { FIELD_STRENGTH_X, @@ -147,11 +147,11 @@ public: MgmPrimaryDataset(object_id_t mgmId): StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {} - lp_var_t angVelocityX = lp_var_t(sid.objectId, + lp_var_t fieldStrengthX = lp_var_t(sid.objectId, FIELD_STRENGTH_X, this); - lp_var_t angVelocityY = lp_var_t(sid.objectId, + lp_var_t fieldStrengthY = lp_var_t(sid.objectId, FIELD_STRENGTH_Y, this); - lp_var_t angVelocityZ = lp_var_t(sid.objectId, + lp_var_t fieldStrengthZ = lp_var_t(sid.objectId, FIELD_STRENGTH_Z, this); lp_var_t temperature = lp_var_t(sid.objectId, TEMPERATURE_CELCIUS, this); From 1757c0fc37cc81d651f28d527ff61a6b2eb9adff Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Dec 2020 22:52:53 +0100 Subject: [PATCH 11/27] updated obsw config --- bsp_hosted/fsfwconfig/OBSWConfig.h | 7 ++++--- fsfwconfig/OBSWConfig.h | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bsp_hosted/fsfwconfig/OBSWConfig.h b/bsp_hosted/fsfwconfig/OBSWConfig.h index 9e11424b..edfa1bca 100644 --- a/bsp_hosted/fsfwconfig/OBSWConfig.h +++ b/bsp_hosted/fsfwconfig/OBSWConfig.h @@ -6,9 +6,10 @@ #ifndef CONFIG_OBSWCONFIG_H_ #define CONFIG_OBSWCONFIG_H_ -#define ADD_TEST_FOLDER 1 +#define OBSW_ADD_TEST_CODE 0 -// Define not used yet, PUS stack and TMTC tasks are always started -#define ADD_PUS_STACK 1 +// These defines should be disabled for mission code but are useful for +// debugging. +#define OBSW_ENHANCED_PRINTOUT 1 #endif /* CONFIG_OBSWCONFIG_H_ */ diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index 6d181093..d8784551 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -6,9 +6,10 @@ #ifndef FSFWCONFIG_OBSWCONFIG_H_ #define FSFWCONFIG_OBSWCONFIG_H_ -#define OBSW_ADD_TEST_CODE 0 +#define OBSW_ADD_TEST_CODE 0 -// Define not used yet, PUS stack and TMTC tasks are always started -#define ADD_PUS_STACK 1 +// These defines should be disabled for mission code but are useful for +// debugging. +#define OBSW_ENHANCED_PRINTOUT 1 #endif /* FSFWCONFIG_OBSWCONFIG_H_ */ From 3ae7675d7d443868219830fa7040c7ae359ec30c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 16 Dec 2020 14:05:38 +0100 Subject: [PATCH 12/27] fsfw update --- fsfw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsfw b/fsfw index b232a8a2..74c49e14 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit b232a8a2919841b331b43c84a7fb2ae80f93186f +Subproject commit 74c49e1481a4d40ad37eb6ad3d6404ae9b52629d From 8ce6b44c31f70d5279947e88667e4af9852df81a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 17:44:54 +0100 Subject: [PATCH 13/27] fsfw update --- fsfw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsfw b/fsfw index 74c49e14..086cbe1e 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 74c49e1481a4d40ad37eb6ad3d6404ae9b52629d +Subproject commit 086cbe1e3950cf6c904609352408a7fa48cc83ef From 1152e81a774fa022737e5692013b13ecfb03d2bf Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 17:45:42 +0100 Subject: [PATCH 14/27] tmtc update --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index 4463efcf..345a0252 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 4463efcf7bfd2181a78eff66fca82c335aeea1d1 +Subproject commit 345a02520ca885065bf6220d48319d2f1c310496 From f0f4464ec9054d93945804eee6959b2fa020c7cf Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 17:46:11 +0100 Subject: [PATCH 15/27] removed tmtc submodule, will be replaced --- .gitmodules | 3 --- tmtc | 1 - 2 files changed, 4 deletions(-) delete mode 160000 tmtc diff --git a/.gitmodules b/.gitmodules index 8b5921a8..6d834ef0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "etl"] path = etl url = https://github.com/ETLCPP/etl.git -[submodule "tmtc"] - path = tmtc - url = https://git.ksat-stuttgart.de/Robin.Mueller/tmtc.git [submodule "arduino"] path = arduino url = https://egit.irs.uni-stuttgart.de/eive/eive_arduino_interface.git diff --git a/tmtc b/tmtc deleted file mode 160000 index 345a0252..00000000 --- a/tmtc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 345a02520ca885065bf6220d48319d2f1c310496 From cc569bdec405426e73d76b5b0a108b7fa06707b9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 17:47:40 +0100 Subject: [PATCH 16/27] added new tmtc submodule --- .gitmodules | 3 +++ tmtc | 1 + 2 files changed, 4 insertions(+) create mode 160000 tmtc diff --git a/.gitmodules b/.gitmodules index 6d834ef0..dae431d4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "fsfw"] path = fsfw url = https://egit.irs.uni-stuttgart.de/eive/fsfw.git +[submodule "tmtc"] + path = tmtc + url = https://egit.irs.uni-stuttgart.de/eive/eive_tmtc.git diff --git a/tmtc b/tmtc new file mode 160000 index 00000000..1314992e --- /dev/null +++ b/tmtc @@ -0,0 +1 @@ +Subproject commit 1314992e326946ba281ce61846a07261cea37159 From 9613b11f590dd384286ad494fb3124dd625a4d2a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 18:04:04 +0100 Subject: [PATCH 17/27] tmtc update --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index 1314992e..b0f0b978 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 1314992e326946ba281ce61846a07261cea37159 +Subproject commit b0f0b9788e23360e97e9bdb4fc89473c1e48193d From 3bacafcab79159da1bf4fdebf5dfd69b53a123e2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 18:04:33 +0100 Subject: [PATCH 18/27] tmtc update --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index b0f0b978..673a3e8b 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit b0f0b9788e23360e97e9bdb4fc89473c1e48193d +Subproject commit 673a3e8ba47024b940f3a118ac8bcee81a85bc2a From aaf1b1600622a7aa23e18dcad727d3ceaa1c491c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 18:11:40 +0100 Subject: [PATCH 19/27] tmtc points to new commit --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index 673a3e8b..75b01009 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 673a3e8ba47024b940f3a118ac8bcee81a85bc2a +Subproject commit 75b01009f104aefe7dd1473f6c071339e67bcb37 From c5790f59b844bf865ad7667cf1a4f67a55b7e5a1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 18:16:49 +0100 Subject: [PATCH 20/27] tmtc update --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index 75b01009..46ddd4dd 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 75b01009f104aefe7dd1473f6c071339e67bcb37 +Subproject commit 46ddd4ddb3b8a2214b23636b02443665cbd602f2 From 9c216e1f4257a809307213eb9d22baa9e530d514 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 18:43:27 +0100 Subject: [PATCH 21/27] tmtc update --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index 46ddd4dd..5e110aab 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 46ddd4ddb3b8a2214b23636b02443665cbd602f2 +Subproject commit 5e110aabff1e9841d242a6b3eb221c1a51002968 From 97e6986fac430f97ba5d99ea1d9ac526e9d5b2d5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 19:38:09 +0100 Subject: [PATCH 22/27] tmtc update --- fsfwconfig/tmtc/apid.h | 2 +- tmtc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fsfwconfig/tmtc/apid.h b/fsfwconfig/tmtc/apid.h index ee2fc7c4..0799abc3 100644 --- a/fsfwconfig/tmtc/apid.h +++ b/fsfwconfig/tmtc/apid.h @@ -8,7 +8,7 @@ * application process ID (APID), capable of generating telemetry source * packets and receiving telecommand packets * - * SOURCE APID: 0x73 / 115 / s + * EIVE APID: 0x65 / 101 / e * APID is a 11 bit number */ namespace apid { diff --git a/tmtc b/tmtc index 5e110aab..e0c896e6 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 5e110aabff1e9841d242a6b3eb221c1a51002968 +Subproject commit e0c896e62d25286d00599ca57b71d0a3495ed95f From 2fa60a00e7cfe8a8476094390f7c189e6238d214 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 19:38:26 +0100 Subject: [PATCH 23/27] c++ include used --- fsfwconfig/tmtc/apid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsfwconfig/tmtc/apid.h b/fsfwconfig/tmtc/apid.h index 0799abc3..00aabee1 100644 --- a/fsfwconfig/tmtc/apid.h +++ b/fsfwconfig/tmtc/apid.h @@ -1,7 +1,7 @@ #ifndef FSFWCONFIG_TMTC_APID_H_ #define FSFWCONFIG_TMTC_APID_H_ -#include +#include /** * Application Process Definition: entity, uniquely identified by an From a60726e91cf533b84ed18ca0ccf74b1ff68dfc95 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 19:43:20 +0100 Subject: [PATCH 24/27] updated gitignore file --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index f6adc50a..0d0e490d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ _dep .project .cproject __pycache__ + +!misc/eclipse/**/.cproject +!misc/eclipse/**/.project \ No newline at end of file From ad79ea46fdb28772028e489640180f370380405e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 19:45:20 +0100 Subject: [PATCH 25/27] additional include for win compileation --- bsp_hosted/fsfwconfig/FSFWConfig.h | 1 + 1 file changed, 1 insertion(+) diff --git a/bsp_hosted/fsfwconfig/FSFWConfig.h b/bsp_hosted/fsfwconfig/FSFWConfig.h index 3433613c..8c6c754a 100644 --- a/bsp_hosted/fsfwconfig/FSFWConfig.h +++ b/bsp_hosted/fsfwconfig/FSFWConfig.h @@ -2,6 +2,7 @@ #define CONFIG_FSFWCONFIG_H_ #include +#include //! Used to determine whether C++ ostreams are used //! Those can lead to code bloat. From 8a91401c5254d0c24fff5c7e14835e9938ef6fd1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 19:47:21 +0100 Subject: [PATCH 26/27] deleted linux bsp arduino files --- bsp_linux/comIF/ArduinoComIF.cpp | 324 ------------------------------ bsp_linux/comIF/ArduinoComIF.h | 73 ------- bsp_linux/comIF/ArduinoCookie.cpp | 12 -- bsp_linux/comIF/ArduinoCookie.h | 25 --- 4 files changed, 434 deletions(-) delete mode 100644 bsp_linux/comIF/ArduinoComIF.cpp delete mode 100644 bsp_linux/comIF/ArduinoComIF.h delete mode 100644 bsp_linux/comIF/ArduinoCookie.cpp delete mode 100644 bsp_linux/comIF/ArduinoCookie.h diff --git a/bsp_linux/comIF/ArduinoComIF.cpp b/bsp_linux/comIF/ArduinoComIF.cpp deleted file mode 100644 index ffc59b47..00000000 --- a/bsp_linux/comIF/ArduinoComIF.cpp +++ /dev/null @@ -1,324 +0,0 @@ -#include "ArduinoCookie.h" -#include "ArduinoComIF.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -ArduinoCommInterface::ArduinoCommInterface(object_id_t setObjectId, - const char *serialDevice) : - spiMap(MAX_NUMBER_OF_SPI_DEVICES), rxBuffer( - MAX_PACKET_SIZE * MAX_NUMBER_OF_SPI_DEVICES*10, true), SystemObject(setObjectId) { - initialized = false; - serialPort = ::open("/dev/ttyUSB0", O_RDWR); - - if (serialPort < 0) { - //configuration error - printf("Error %i from open: %s\n", errno, strerror(errno)); - return; - } - - struct termios tty; - memset(&tty, 0, sizeof tty); - - // Read in existing settings, and handle any error - if (tcgetattr(serialPort, &tty) != 0) { - printf("Error %i from tcgetattr: %s\n", errno, strerror(errno)); - return; - } - - tty.c_cflag &= ~PARENB; // Clear parity bit, disabling parity - tty.c_cflag &= ~CSTOPB; // Clear stop field, only one stop bit used in communication - tty.c_cflag |= CS8; // 8 bits per byte - tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control - tty.c_lflag &= ~ICANON; //Disable Canonical Mode - tty.c_oflag &= ~OPOST; // Prevent special interpretation of output bytes (e.g. newline chars) - tty.c_oflag &= ~ONLCR; // Prevent conversion of newline to carriage return/line feed - tty.c_cc[VTIME] = 0; // Non Blocking - tty.c_cc[VMIN] = 0; - - cfsetispeed(&tty, B9600); //Baudrate - - if (tcsetattr(serialPort, TCSANOW, &tty) != 0) { - //printf("Error %i from tcsetattr: %s\n", errno, strerror(errno)); - return; - } - - initialized = true; - -} - -ArduinoCommInterface::~ArduinoCommInterface() { - ::close(serialPort); -} - -ReturnValue_t ArduinoCommInterface::open(Cookie **cookie, uint32_t address, - uint32_t maxReplyLen) { - //This is a hack, will be gone with https://egit.irs.uni-stuttgart.de/fsfw/fsfw/issues/19 - switch ((address >> 8) & 0xff) { - case 0: - *cookie = new ArduinoCookie(ArduinoCookie::SPI, address, maxReplyLen); - spiMap.insert(address, (ArduinoCookie*) *cookie); //Yes, I *do* know that it is an ArduinoSpiCookie, I just new'd it - break; - default: - return HasReturnvaluesIF::RETURN_FAILED; - } - return HasReturnvaluesIF::RETURN_OK; -} - -ReturnValue_t ArduinoCommInterface::reOpen(Cookie *cookie, uint32_t address, - uint32_t maxReplyLen) { - //too lazy right now will be irrelevant with https://egit.irs.uni-stuttgart.de/fsfw/fsfw/issues/19 - return HasReturnvaluesIF::RETURN_FAILED; -} - -void ArduinoCommInterface::close(Cookie *cookie) { - //too lazy as well, find the correct Map, delete it there, then the cookie... -} - -ReturnValue_t ArduinoCommInterface::sendMessage(Cookie *cookie, uint8_t *data, - uint32_t len) { - ArduinoCookie *arduinoCookie = dynamic_cast(cookie); - if (arduinoCookie == NULL) { - return INVALID_COOKIE_TYPE; - } - - return sendMessage(arduinoCookie->command, arduinoCookie->address, data, - len); -} - -ReturnValue_t ArduinoCommInterface::getSendSuccess(Cookie *cookie) { - return RETURN_OK; -} - -ReturnValue_t ArduinoCommInterface::requestReceiveMessage(Cookie *cookie) { - return RETURN_OK; -} - -ReturnValue_t ArduinoCommInterface::readReceivedMessage(Cookie *cookie, - uint8_t **buffer, uint32_t *size) { - - handleSerialPortRx(); - - ArduinoCookie *arduinoCookie = dynamic_cast(cookie); - if (arduinoCookie == NULL) { - return INVALID_COOKIE_TYPE; - } - - *buffer = arduinoCookie->replyBuffer; - *size = arduinoCookie->receivedDataLen; - return HasReturnvaluesIF::RETURN_OK; -} - -ReturnValue_t ArduinoCommInterface::setAddress(Cookie *cookie, - uint32_t address) { - //not implemented - return RETURN_FAILED; -} - -uint32_t ArduinoCommInterface::getAddress(Cookie *cookie) { - //not implemented - return 0; -} - -ReturnValue_t ArduinoCommInterface::setParameter(Cookie *cookie, - uint32_t parameter) { - //not implemented - return RETURN_FAILED; -} - -uint32_t ArduinoCommInterface::getParameter(Cookie *cookie) { - //not implemented - return 0; -} - -ReturnValue_t ArduinoCommInterface::sendMessage(uint8_t command, - uint8_t address, const uint8_t *data, size_t dataLen) { - if (dataLen > UINT16_MAX) { - return TOO_MUCH_DATA; - } - - //being conservative here - uint8_t sendBuffer[(dataLen + 6) * 2 + 2]; - - sendBuffer[0] = DleEncoder::STX; - - uint8_t *currentPosition = sendBuffer + 1; - size_t remainingLen = sizeof(sendBuffer) - 1; - uint32_t encodedLen; - - ReturnValue_t result = DleEncoder::encode(&command, 1, currentPosition, - remainingLen, &encodedLen, false); - if (result != RETURN_OK) { - return result; - } - currentPosition += encodedLen; - remainingLen -= encodedLen; //DleEncoder will never return encodedLen > remainingLen - - result = DleEncoder::encode(&address, 1, currentPosition, remainingLen, - &encodedLen, false); - if (result != RETURN_OK) { - return result; - } - currentPosition += encodedLen; - remainingLen -= encodedLen; //DleEncoder will never return encodedLen > remainingLen - - uint8_t temporaryBuffer[2]; - - //note to Lukas: yes we _could_ use Serialize here, but for 16 bit it is a bit too much... - temporaryBuffer[0] = dataLen >> 8; //we checked dataLen above - temporaryBuffer[1] = dataLen; - - result = DleEncoder::encode(temporaryBuffer, 2, currentPosition, - remainingLen, &encodedLen, false); - if (result != RETURN_OK) { - return result; - } - currentPosition += encodedLen; - remainingLen -= encodedLen; //DleEncoder will never return encodedLen > remainingLen - - //encoding the actual data - result = DleEncoder::encode(data, dataLen, currentPosition, remainingLen, - &encodedLen, false); - if (result != RETURN_OK) { - return result; - } - currentPosition += encodedLen; - remainingLen -= encodedLen; //DleEncoder will never return encodedLen > remainingLen - - uint16_t crc = CRC::crc16ccitt(&command, 1); - crc = CRC::crc16ccitt(&address, 1, crc); - //fortunately the length is still there - crc = CRC::crc16ccitt(temporaryBuffer, 2, crc); - crc = CRC::crc16ccitt(data, dataLen, crc); - - temporaryBuffer[0] = crc >> 8; - temporaryBuffer[1] = crc; - - result = DleEncoder::encode(temporaryBuffer, 2, currentPosition, - remainingLen, &encodedLen, false); - if (result != RETURN_OK) { - return result; - } - currentPosition += encodedLen; - remainingLen -= encodedLen; //DleEncoder will never return encodedLen > remainingLen - - if (remainingLen > 0) { - *currentPosition = DleEncoder::ETX; - } - remainingLen -= 1; - - encodedLen = sizeof(sendBuffer) - remainingLen; - - ssize_t writtenlen = write(serialPort, sendBuffer, encodedLen); - if (writtenlen < 0) { - //we could try to find out what happened... - return RETURN_FAILED; - } - if (writtenlen != encodedLen) { - //the OS failed us, we do not try to block until everything is written, as - //we can not block the whole system here - return RETURN_FAILED; - } - return RETURN_OK; -} - -void ArduinoCommInterface::handleSerialPortRx() { - uint32_t availableSpace = rxBuffer.availableWriteSpace(); - - uint8_t dataFromSerial[availableSpace]; - - ssize_t bytesRead = read(serialPort, dataFromSerial, - sizeof(dataFromSerial)); - - if (bytesRead < 0) { - return; - } - - rxBuffer.writeData(dataFromSerial, bytesRead); - - uint8_t dataReceivedSoFar[rxBuffer.maxSize()]; - - uint32_t dataLenReceivedSoFar = 0; - - rxBuffer.readData(dataReceivedSoFar, sizeof(dataReceivedSoFar), true, - &dataLenReceivedSoFar); - - //look for STX - size_t firstSTXinRawData = 0; - while ((firstSTXinRawData < dataLenReceivedSoFar) - && (dataReceivedSoFar[firstSTXinRawData] != DleEncoder::STX)) { - firstSTXinRawData++; - } - - if (dataReceivedSoFar[firstSTXinRawData] != DleEncoder::STX) { - //there is no STX in our data, throw it away... - rxBuffer.deleteData(dataLenReceivedSoFar); - return; - } - - uint8_t packet[MAX_PACKET_SIZE]; - uint32_t packetLen; - - uint32_t readSize; - - ReturnValue_t result = DleEncoder::decode( - dataReceivedSoFar + firstSTXinRawData, - dataLenReceivedSoFar - firstSTXinRawData, &readSize, packet, - sizeof(packet), &packetLen); - - size_t toDelete = firstSTXinRawData; - if (result == HasReturnvaluesIF::RETURN_OK) { - handlePacket(packet, packetLen); - - //after handling the packet, we can delete it from the raw stream, it has been copied to packet - toDelete += readSize; - } - - //remove Data which was processed - rxBuffer.deleteData(toDelete); -} - -void ArduinoCommInterface::handlePacket(uint8_t *packet, size_t packetLen) { - uint16_t crc = CRC::crc16ccitt(packet, packetLen); - if (crc != 0) { - //CRC error - return; - } - - uint8_t command = packet[0]; - uint8_t address = packet[1]; - - uint16_t size = (packet[2] << 8) + packet[3]; - - if (size != packetLen - 6) { - //Invalid Length - return; - } - - switch (command) { - case ArduinoCookie::SPI: { - ArduinoCookie **itsComplicated; - ReturnValue_t result = spiMap.find(address, &itsComplicated); - if (result != RETURN_OK) { - //we do no know this address - return; - } - ArduinoCookie *theActualCookie = *itsComplicated; - if (packetLen > theActualCookie->maxReplySize + 6) { - packetLen = theActualCookie->maxReplySize + 6; - } - memcpy(theActualCookie->replyBuffer, packet + 4, packetLen - 6); - theActualCookie->receivedDataLen = packetLen - 6; - } - break; - default: - return; - } -} diff --git a/bsp_linux/comIF/ArduinoComIF.h b/bsp_linux/comIF/ArduinoComIF.h deleted file mode 100644 index 9ab166de..00000000 --- a/bsp_linux/comIF/ArduinoComIF.h +++ /dev/null @@ -1,73 +0,0 @@ -//#ifndef MISSION_ARDUINOCOMMINTERFACE_H_ -//#define MISSION_ARDUINOCOMMINTERFACE_H_ -// -//#include -//#include -//#include -//#include -//#include -//#include -// -//#include "../../framework/objectmanager/SystemObject.h" -//#include "ArduinoCookie.h" -// -////Forward declaration, so users don't peek -//class ArduinoCookie; -// -//class ArduinoComIF: public SystemObject, -// public DeviceCommunicationIF { -//public: -// static const uint8_t MAX_NUMBER_OF_SPI_DEVICES = 8; -// static const uint8_t MAX_PACKET_SIZE = 64; -// -// static const uint8_t COMMAND_INVALID = -1; -// static const uint8_t COMMAND_SPI = 1; -// -// ArduinoComIF(object_id_t setObjectId, const char *serialDevice); -// virtual ~ArduinoComIF(); -// -// virtual ReturnValue_t open(Cookie **cookie, uint32_t address, -// uint32_t maxReplyLen); -// -// virtual ReturnValue_t reOpen(Cookie *cookie, uint32_t address, -// uint32_t maxReplyLen); -// -// virtual void close(Cookie *cookie); -// -// //SHOULDDO can data be const? -// virtual ReturnValue_t sendMessage(Cookie *cookie, uint8_t *data, -// uint32_t len); -// -// virtual ReturnValue_t getSendSuccess(Cookie *cookie); -// -// virtual ReturnValue_t requestReceiveMessage(Cookie *cookie); -// -// virtual ReturnValue_t readReceivedMessage(Cookie *cookie, uint8_t **buffer, -// uint32_t *size); -// -// virtual ReturnValue_t setAddress(Cookie *cookie, uint32_t address); -// -// virtual uint32_t getAddress(Cookie *cookie); -// -// virtual ReturnValue_t setParameter(Cookie *cookie, uint32_t parameter); -// -// virtual uint32_t getParameter(Cookie *cookie); -//private: -// //remembering if the initialization in the ctor worked -// //if not, all calls are disabled -// bool initialized; -// int serialPort; -// //used to know where to put the data if a reply is received -// FixedMap spiMap; -// -// SimpleRingBuffer rxBuffer; -// -// ReturnValue_t sendMessage(uint8_t command, uint8_t address, -// const uint8_t *data, size_t dataLen); -// -// void handleSerialPortRx(); -// -// void handlePacket(uint8_t *packet, size_t packetLen); -//}; -// -//#endif /* MISSION_ARDUINOCOMMINTERFACE_H_ */ diff --git a/bsp_linux/comIF/ArduinoCookie.cpp b/bsp_linux/comIF/ArduinoCookie.cpp deleted file mode 100644 index d7e81192..00000000 --- a/bsp_linux/comIF/ArduinoCookie.cpp +++ /dev/null @@ -1,12 +0,0 @@ -//#include -// -//ArduinoCookie::ArduinoCookie(Protocol_t protocol, uint8_t address, -// size_t maxReplySize) : -// command(protocol), address(address), receivedDataLen(0), maxReplySize( -// maxReplySize) { -// replyBuffer = new uint8_t[maxReplySize]; -//} -// -//ArduinoCookie::~ArduinoCookie() { -// delete[] replyBuffer; -//} diff --git a/bsp_linux/comIF/ArduinoCookie.h b/bsp_linux/comIF/ArduinoCookie.h deleted file mode 100644 index 64eed4ad..00000000 --- a/bsp_linux/comIF/ArduinoCookie.h +++ /dev/null @@ -1,25 +0,0 @@ -//#ifndef MISSION_ARDUINO_ARDUINOCOOKIE_H_ -//#define MISSION_ARDUINO_ARDUINOCOOKIE_H_ -// -//#include -// -//#include -//#include -// -//class ArduinoCookie: public Cookie { -//public: -// enum Protocol_t { -// INVALID = 0, SPI = 1 -// }; -// ArduinoCookie(Protocol_t protocol, uint8_t address, size_t maxReplySize); -// virtual ~ArduinoCookie(); -// -// uint8_t command; -// uint8_t address; -// uint8_t *replyBuffer; -// size_t receivedDataLen; -// size_t maxReplySize; -// -//}; -// -//#endif /* MISSION_ARDUINO_ARDUINOCOOKIE_H_ */ From 4f761a4ed0e8b5384e03f6f8cb23eee9ae5120ee Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Dec 2020 19:50:11 +0100 Subject: [PATCH 27/27] added eclipse project and launch files --- misc/eclipse/.cproject | 144 +++++++++++++++++++++++++ misc/eclipse/.project | 27 +++++ misc/eclipse/eive-mingw-debug.launch | 33 ++++++ misc/eclipse/eive-mingw-release.launch | 33 ++++++ 4 files changed, 237 insertions(+) create mode 100644 misc/eclipse/.cproject create mode 100644 misc/eclipse/.project create mode 100644 misc/eclipse/eive-mingw-debug.launch create mode 100644 misc/eclipse/eive-mingw-release.launch diff --git a/misc/eclipse/.cproject b/misc/eclipse/.cproject new file mode 100644 index 00000000..776ea205 --- /dev/null +++ b/misc/eclipse/.cproject @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/misc/eclipse/.project b/misc/eclipse/.project new file mode 100644 index 00000000..906c567f --- /dev/null +++ b/misc/eclipse/.project @@ -0,0 +1,27 @@ + + + eive_obsw + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/misc/eclipse/eive-mingw-debug.launch b/misc/eclipse/eive-mingw-debug.launch new file mode 100644 index 00000000..4ab7b736 --- /dev/null +++ b/misc/eclipse/eive-mingw-debug.launch @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/misc/eclipse/eive-mingw-release.launch b/misc/eclipse/eive-mingw-release.launch new file mode 100644 index 00000000..da2f47a9 --- /dev/null +++ b/misc/eclipse/eive-mingw-release.launch @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +