From 9fd27801f6c3906e24e398b17be55cedd6d0c721 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 30 Sep 2020 21:49:00 +0200 Subject: [PATCH] integrating first device handlers --- config/events/subsystemIdRanges.h | 23 +- config/returnvalues/classIds.h | 6 +- fsfw | 2 +- hosted/config/events/subsystemIdRanges.h | 24 +- mission/devices/MGMHandlerLIS3MDL.cpp | 398 +++++++++++++++++++++++ mission/devices/MGMHandlerLIS3MDL.h | 243 ++++++++++++++ mission/devices/MGMRM3100Handler.cpp | 55 ++++ mission/devices/MGMRM3100Handler.h | 62 ++++ 8 files changed, 774 insertions(+), 39 deletions(-) create mode 100644 mission/devices/MGMHandlerLIS3MDL.cpp create mode 100644 mission/devices/MGMHandlerLIS3MDL.h create mode 100644 mission/devices/MGMRM3100Handler.cpp create mode 100644 mission/devices/MGMRM3100Handler.h diff --git a/config/events/subsystemIdRanges.h b/config/events/subsystemIdRanges.h index b1c18cbc..d6c21479 100644 --- a/config/events/subsystemIdRanges.h +++ b/config/events/subsystemIdRanges.h @@ -11,23 +11,12 @@ namespace SUBSYSTEM_ID { enum: uint8_t { SUBSYSTE_ID_START = FW_SUBSYSTEM_ID_RANGE, - /** - * 80-105: PUS Services - */ - PUS_SERVICE_2 = 82, - PUS_SERVICE_3 = 83, - PUS_SERVICE_5 = 85, - PUS_SERVICE_6 = 86, - PUS_SERVICE_8 = 88, - PUS_SERVICE_23 = 91, - DUMMY_DEVICE = 90, - /** - * 105-115: AOCS - */ - GPS_DEVICE = 105, - - SPI_COM_IF = 128, - I2C_COM_IF = 138 + PUS_SERVICE_2, + PUS_SERVICE_3, + PUS_SERVICE_5, + PUS_SERVICE_6, + PUS_SERVICE_8, + PUS_SERVICE_23, }; } diff --git a/config/returnvalues/classIds.h b/config/returnvalues/classIds.h index a024e3d7..3fe99a7d 100644 --- a/config/returnvalues/classIds.h +++ b/config/returnvalues/classIds.h @@ -16,11 +16,7 @@ namespace CLASS_ID { enum { MISSION_CLASS_ID_START = FW_CLASS_ID_COUNT, - RS232_CHANNEL, //!< RS232 - I2C_CHANNEL, //!< I2C - SPI_CHANNEL, //!< SPI - GPS_HANDLER, //!< GPS - PUS_SERVICE_3 //!< HKS + MGM_LIS3MDL }; } diff --git a/fsfw b/fsfw index e4d75514..916a374c 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit e4d75514d3f073991869c695c11b4b5a862cfe21 +Subproject commit 916a374c19549744f6413799ca7bb0a66c5b54e0 diff --git a/hosted/config/events/subsystemIdRanges.h b/hosted/config/events/subsystemIdRanges.h index b1c18cbc..2255b345 100644 --- a/hosted/config/events/subsystemIdRanges.h +++ b/hosted/config/events/subsystemIdRanges.h @@ -11,23 +11,15 @@ namespace SUBSYSTEM_ID { enum: uint8_t { SUBSYSTE_ID_START = FW_SUBSYSTEM_ID_RANGE, - /** - * 80-105: PUS Services - */ - PUS_SERVICE_2 = 82, - PUS_SERVICE_3 = 83, - PUS_SERVICE_5 = 85, - PUS_SERVICE_6 = 86, - PUS_SERVICE_8 = 88, - PUS_SERVICE_23 = 91, - DUMMY_DEVICE = 90, - /** - * 105-115: AOCS - */ - GPS_DEVICE = 105, + PUS_SERVICE_2, + PUS_SERVICE_3, + PUS_SERVICE_5, + PUS_SERVICE_6, + PUS_SERVICE_8, + PUS_SERVICE_23, + MGM_LIS3MDL, - SPI_COM_IF = 128, - I2C_COM_IF = 138 + DUMMY_DEVICE, }; } diff --git a/mission/devices/MGMHandlerLIS3MDL.cpp b/mission/devices/MGMHandlerLIS3MDL.cpp new file mode 100644 index 00000000..e023686e --- /dev/null +++ b/mission/devices/MGMHandlerLIS3MDL.cpp @@ -0,0 +1,398 @@ +#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; + +} + +MGMHandlerLIS3MDL::~MGMHandlerLIS3MDL() { +} + +uint8_t MGMHandlerLIS3MDL::readCommand(uint8_t command, bool continuousCom) { + command |= (1 << RW_BIT); + if (continuousCom == true) { + command |= (1 << MS_BIT); + } + return command; +} + +uint8_t MGMHandlerLIS3MDL::writeCommand(uint8_t command, bool continuousCom) { + command &= ~(1 << RW_BIT); + if (continuousCom == true) { + command |= (1 << MS_BIT); + } + return command; +} + +ReturnValue_t MGMHandlerLIS3MDL::setupMGM() { + + registers[0] = (1 << TEMP_EN) | (1 << OM1) | (1 << DO0) | (1 << DO1) + | (1 << DO2); + registers[1] = 0; + registers[2] = 0; + registers[3] = (1 << OMZ1); + registers[4] = 0; + + return prepareRegisterWrite(); + +} + +ReturnValue_t MGMHandlerLIS3MDL::buildNormalDeviceCommand( + DeviceCommandId_t *id) { //defines CommandID of MGM in normal operation and build command from command + *id = READALL_MGM; + + return buildCommandFromCommand(*id, NULL, 0); + +} + +ReturnValue_t MGMHandlerLIS3MDL::buildCommandFromCommand( + DeviceCommandId_t deviceCommand, const uint8_t *commandData, + size_t commandDataLen) { + lastSentCommand = deviceCommand; + switch(deviceCommand) { + case(READALL_MGM): { + if (commandDataLen == 0) { + for (size_t i = 0; i < sizeof(commandBuffer); i++) { + commandBuffer[i] = 0; + } + commandBuffer[0] = readCommand(0, true); + + rawPacket = commandBuffer; + rawPacketLen = sizeof(commandBuffer); + return RETURN_OK; + } + case(IDENTIFY_DEVICE): { + return identifyDevice(); + } + case(TEMP_SENSOR_ENABLE): { + return enableTemperatureSensor(commandData, commandDataLen); + } + case(SETUP_MGM): { + return setupMGM(); + } + case(ACCURACY_OP_MODE_SET): { + return setOperatingMode(commandData, commandDataLen); + } + default: + lastSentCommand = NO_COMMAND; + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + } + return HasReturnvaluesIF::RETURN_FAILED; +} + +ReturnValue_t MGMHandlerLIS3MDL::buildTransitionDeviceCommand( + DeviceCommandId_t *id) { + switch (internalState) { + case STATE_FIRST_CONTACT: + *id = IDENTIFY_DEVICE; + break; + + case STATE_SETUP: + *id = SETUP_MGM; + break; + + case STATE_CHECK_REGISTERS: + *id = READALL_MGM; + break; + + default: + break; + } + return buildCommandFromCommand(*id, NULL, 0); + +} + +ReturnValue_t MGMHandlerLIS3MDL::scanForReply(const uint8_t *start, + uint32_t len, DeviceCommandId_t *foundId, uint32_t *foundLen) { + *foundLen = len; + if (len == TOTAL_NR_OF_ADRESSES + 1) { + *foundLen = len; + *foundId = READALL_MGM; + //WHO AM I test + if (*(start + 16) != DEVICEID) { + return DeviceHandlerIF::INVALID_DATA; + } + + } else if (len == SETUP_REPLY) { + *foundLen = len; + *foundId = SETUP_MGM; + } else if (len == SINGLE_COMMAND_ANSWER_LEN) { + *foundLen = len; + *foundId = lastSentCommand; + } else { + + return DeviceHandlerIF::INVALID_DATA; + } + + if (start[0] == 0b11111111) { //Data with SPI Interface has always this answer + return RETURN_OK; + } else { + return DeviceHandlerIF::INVALID_DATA; + } + +} +ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) { + + switch (id) { + case IDENTIFY_DEVICE: { + break; + } + case SETUP_MGM: { + break; + } + case READALL_MGM: { + //DataSet mySet; + + 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); + float sensitivity = getSensitivity(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 = (uint8_t*) (packet + 41); + + 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 = (float) x_value_raw * sensitivity; + float y_value = (float) y_value_raw * sensitivity; + float z_value = (float) z_value_raw * sensitivity; + float temp_value = 25.0 + (((float) temp_value_raw) / 8.0); + +// PoolVector mgm_measurement(mgmMagneticPoolId, &mySet, +// PoolVariableIF::VAR_WRITE); +// PoolVariable mgm_temperature(mgmTempPoolId, &mySet, +// PoolVariableIF::VAR_WRITE); + +// mgm_measurement[0] = x_value; +// mgm_measurement[1] = y_value; +// mgm_measurement[2] = z_value; +// +// mgm_temperature = temp_value; +// handleDeviceTM(&mySet, id); + + break; + } + + default: { + return DeviceHandlerIF::UNKNOW_DEVICE_REPLY; + } + + } + return RETURN_OK; +} + +uint8_t MGMHandlerLIS3MDL::getFullScale(uint8_t *reg2) { + bool FS0 = false; + bool FS1 = false; + if ((*reg2 >> 5) == 1) + FS0 = true; + if ((*reg2 >> 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::getSensitivity(uint8_t scale) { + + return (float) scale / (INT16_MAX); + +} +ReturnValue_t MGMHandlerLIS3MDL::identifyDevice() { + uint32_t size = 2; + commandBuffer[0] = readCommand(IDENTIFYDEVICE); + commandBuffer[1] = 0x00; + + rawPacket = commandBuffer; + rawPacketLen = size; + + return RETURN_OK; +} + +ReturnValue_t MGMHandlerLIS3MDL::enableTemperatureSensor( + const uint8_t *commandData, size_t commandDataLen) { + triggerEvent(CHANGE_OF_SETUP_PARAMETER); + uint32_t size = 2; + commandBuffer[0] = writeCommand(CTRL_REG1); + if (commandDataLen > 1) { + return INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS; + } + switch (*commandData) { + case (ON): + commandBuffer[1] = registers[0] | (1 << 7); + break; + + case (OFF): + commandBuffer[1] = registers[0] & ~(1 << 7); + break; + + default: + return INVALID_COMMAND_PARAMETER; + break; + } + registers[0] = commandBuffer[1]; + + rawPacket = commandBuffer; + rawPacketLen = size; + + return RETURN_OK; +} + +void MGMHandlerLIS3MDL::doStartUp() { + switch (internalState) { + case STATE_NONE: + internalState = STATE_FIRST_CONTACT; + break; + + case STATE_FIRST_CONTACT: + internalState = STATE_SETUP; + break; + + case STATE_SETUP: + internalState = STATE_CHECK_REGISTERS; + break; + + case STATE_CHECK_REGISTERS: + if (setupMGM() == RETURN_OK) { + for (size_t i = 1; i <= NR_OF_CTRL_REGISTERS; i++) { + if (registers[i - 1] != commandBuffer[i]) { + break; + } + } + setMode(_MODE_TO_ON); + } + + break; + + default: + break; + } + +} + +void MGMHandlerLIS3MDL::doShutDown() { + setMode(_MODE_POWER_DOWN); +} + +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; + } + + switch (commandData[0]) { + case LOW: + registers[0] = (registers[0] & (~(1 << OM1))) & (~(1 << OM0)); + registers[3] = (registers[3] & (~(1 << OMZ1))) & (~(1 << OMZ0)); + break; + case MEDIUM: + registers[0] = (registers[0] & (~(1 << OM1))) | (1 << OM0); + registers[3] = (registers[3] & (~(1 << OMZ1))) | (1 << OMZ0); + break; + + case HIGH: + registers[0] = (registers[0] | (1 << OM1)) & (~(1 << OM0)); + registers[3] = (registers[3] | (1 << OM1)) & (~(1 << OM0)); + break; + + case ULTRA: + registers[0] = (registers[0] | (1 << OM1)) | (1 << OM0); + registers[3] = (registers[3] | (1 << OM1)) | (1 << OM0); + break; + default: + break; + } + + return prepareRegisterWrite(); +} + +void MGMHandlerLIS3MDL::fillCommandAndReplyMap() { + /*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(READALL_MGM, 1, 0); + insertInCommandAndReplyMap(SETUP_MGM, 1, 0); + insertInCommandAndReplyMap(IDENTIFY_DEVICE, 1, 0); + insertInCommandAndReplyMap(TEMP_SENSOR_ENABLE, 1, 0); + insertInCommandAndReplyMap(ACCURACY_OP_MODE_SET, 1, 0); +} + +ReturnValue_t MGMHandlerLIS3MDL::prepareRegisterWrite() { + + commandBuffer[0] = writeCommand(CTRL_REG1, true); + + for (size_t i = 1; i <= NR_OF_CTRL_REGISTERS; i++) { + commandBuffer[i] = registers[i]; + } + rawPacket = commandBuffer; + rawPacketLen = NR_OF_CTRL_REGISTERS; + + // We dont have to check if this is working because we just did it + return RETURN_OK; +} + +void MGMHandlerLIS3MDL::setNormalDatapoolEntriesInvalid() { +// DataSet mySet; +// PoolVector mgmMeasurements(mgmMagneticPoolId, &mySet, +// PoolVariableIF::VAR_WRITE); +// PoolVariable mgmTemperature(mgmTempPoolId, &mySet, +// PoolVariableIF::VAR_WRITE); +// +// mgmMeasurements[0] = 0; +// mgmMeasurements[1] = 0; +// mgmMeasurements[2] = 0; +// +// mgmTemperature = 999; + +// mySet.commit(PoolVariableIF::INVALID); + +} + +void MGMHandlerLIS3MDL::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { + +} + +uint32_t MGMHandlerLIS3MDL::getTransitionDelayMs(Mode_t from, Mode_t to) { + return 5000; +} + +void MGMHandlerLIS3MDL::modeChanged(void) { + internalState = STATE_NONE; +} diff --git a/mission/devices/MGMHandlerLIS3MDL.h b/mission/devices/MGMHandlerLIS3MDL.h new file mode 100644 index 00000000..40ea27ef --- /dev/null +++ b/mission/devices/MGMHandlerLIS3MDL.h @@ -0,0 +1,243 @@ +#ifndef MISSION_DEVICEHANDLING_MGMLIS3MDLHANDLER_H_ +#define MISSION_DEVICEHANDLING_MGMLIS3MDLHANDLER_H_ + +#include + + +/** + * @brief Device handler object for the LIS3MDL 3-axis magnetometer + * by STMicroeletronics + * @details + * Datasheet can be found online by googling LIS3MDL. + * @author L. Loidold, R. Mueller + */ +class MGMHandlerLIS3MDL: public DeviceHandlerBase { +public: + + enum set { + ON, OFF + }; + enum opMode { + LOW, MEDIUM, HIGH, ULTRA + }; + + static const uint8_t INTERFACE_ID = CLASS_ID::MGM_LIS3MDL; + + + 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; + + // This Command is needed to use for lastSentCommand, if there is no + // command set, you have to set this. + static const DeviceCommandId_t NO_COMMAND = 0xffffffff; + + 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); + + MGMHandlerLIS3MDL(uint32_t objectId, object_id_t deviceCommunication, + CookieIF* comCookie); + virtual ~MGMHandlerLIS3MDL(); + +protected: + + /** DeviceHandlerBase overrides */ + virtual void doShutDown(); + virtual void doStartUp(); + virtual void doTransition(Mode_t modeFrom, Submode_t subModeFrom); + virtual uint32_t getTransitionDelayMs(Mode_t from, Mode_t to); + virtual ReturnValue_t buildCommandFromCommand( + DeviceCommandId_t deviceCommand, const uint8_t *commandData, + size_t commandDataLen); + virtual ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id); + virtual ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id); + virtual ReturnValue_t scanForReply(const uint8_t *start, uint32_t len, + DeviceCommandId_t *foundId, uint32_t *foundLen); + virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet); + virtual void fillCommandAndReplyMap(); + virtual void modeChanged(void); + void setNormalDatapoolEntriesInvalid(); + +private: + /*------------------------------------------------------------------------*/ + /* Device specific commands and variables */ + /*------------------------------------------------------------------------*/ + /** + * Sets the read bit for the command + * @param single command to set the read-bit at + * @param boolean to select a continuous read bit, default = false + */ + uint8_t readCommand(uint8_t command, bool continuousCom = false); + + /** + * Sets the write bit for the command + * @param single command to set the write-bit at + * @param boolean to select a continuous write bit, default = false + */ + uint8_t writeCommand(uint8_t command, bool continuousCom = false); + + /** + * This Method gets the full scale for the measurement range + * e.g.: +- 4 gauss + * + * @return The ReturnValue does not contain the sign of the value + */ + uint8_t getFullScale(uint8_t *reg2); + + /** + * after detecting the fullScale the 16bit Value for the data is + * devided with the fullScale to the sensitivity of the scale + * + * @param scale is the return value of the getFulscale Method + */ + float getSensitivity(uint8_t scale); + + /** + * This Command detects the device ID + */ + ReturnValue_t identifyDevice(); + + virtual ReturnValue_t setupMGM(); + + /*------------------------------------------------------------------------*/ + /* Non normal commands */ + /*------------------------------------------------------------------------*/ + /** + * Enables/Disables the integrated Temperaturesensor + * @param commandData On or Off + * @param length of the commandData: has to be 1 + */ + virtual ReturnValue_t enableTemperatureSensor(const uint8_t *commandData, + size_t commandDataLen); + + /** + * Sets the accuracy of the measurement of the axis. The noise is changing. + * @param commandData LOW, MEDIUM, HIGH, ULTRA + * @param length of the command, has to be 1 + */ + virtual ReturnValue_t setOperatingMode(const uint8_t *commandData, + size_t commandDataLen); + + static const uint8_t NR_OF_CTRL_REGISTERS = 5; //Number of all control registers + static const uint8_t NR_OF_REGISTERS = 19; //Number of registers in the MGM + static const uint8_t TOTAL_NR_OF_ADRESSES = 52; //Total number of adresses for all registers + static const uint8_t SETUP_REPLY = 6; + static const uint8_t SINGLE_COMMAND_ANSWER_LEN = 2; //Length a sindgle command SPI answer + //static const uint8_t LIS3MDL_IDENTIFIER = 0b00111101; //Identifier for Device + + /*------------------------------------------------------------------------*/ + /* Register adresses */ + /*------------------------------------------------------------------------*/ + // Register adress returns identifier of device with default 0b00111101 + static const uint8_t IDENTIFYDEVICE = 0b00001111; + static const uint8_t DEVICEID = 0b00111101; // Identifier for Device + + //Register adress to access register 1 + static const uint8_t CTRL_REG1 = 0b00100000; + //Register adress to access register 2 + static const uint8_t CTRL_REG2 = 0b00100001; + //Register adress to access register 3 + static const uint8_t CTRL_REG3 = 0b00100010; + //Register adress to access register 4 + static const uint8_t CTRL_REG4 = 0b00100011; + //Register adress to access register 5 + static const uint8_t CTRL_REG5 = 0b00100100; + + //Register adress to access status register + static const uint8_t STATUS_REG = 0b00100111; + + //Register adress to access low byte of x-axis + static const uint8_t X_LOWBYTE = 0b00101000; + //Register adress to access high byte of x-axis + static const uint8_t X_HIGHBYTE = 0b00101001; + //Register adress to access low byte of y-axis + static const uint8_t Y_LOWBYTE = 0b00101010; + //Register adress to access high byte of y-axis + static const uint8_t Y_HIGHBYTE = 0b00101011; + //Register adress to access low byte of z-axis + static const uint8_t Z_LOWBYTE = 0b00101100; + //Register adress to access high byte of z-axis + static const uint8_t Z_HIGHBYTE = 0b00101101; + + //Register adress to access low byte of temperature sensor + static const uint8_t TEMP_LOWBYTE = 0b00101110; + //Register adress to access high byte of temperature sensor + static const uint8_t TEMP_HIGHBYTE = 0b00101111; + + /*------------------------------------------------------------------------*/ + /* Initialize Setup Register set bits + /*------------------------------------------------------------------------*/ + //general transfer bits + static const uint8_t RW_BIT = 7; //Read=1 / Write=0 Bit + static const uint8_t MS_BIT = 6; //Continous Read/Write Bit, increment adress + + //CTRL_REG1 bits + static const uint8_t ST = 0; //Self test enable bit, enabled = 1 + static const uint8_t FAST_ODR = 1; //Enable rates higher than 80 Hz enabled = 1 + static const uint8_t DO0 = 2; //Output data rate bit 2 + static const uint8_t DO1 = 3; //Output data rate bit 3 + 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 + + //CTRL_REG2 bits + static const uint8_t SOFT_RST = 2; //reset configuration registers and user registers + 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 + + //CTRL_REG3 bits + static const uint8_t MD0 = 0; //Operating mode bit 0 + static const uint8_t MD1 = 1; //Operating mode bit 1 + static const uint8_t SIM = 2; //SPI serial interface mode selection enabled = 3-wire-mode + static const uint8_t LP = 5; //low-power mode + + //CTRL_REG4 bits + static const uint8_t BLE = 1; //big/little endian data selection enabled = MSb at lower adress + static const uint8_t OMZ0 = 2; //Z operating mode bit 2 + static const uint8_t OMZ1 = 3; //Z operating mode bit 3 + + //CTRL_REG5 bits + static const uint8_t BDU = 6; //Block data update + static const uint8_t FAST_READ = 7; //Fast read enabled = 1 + + //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[TOTAL_NR_OF_ADRESSES + 1]; + + /** + * We want to save the registers we set, so we dont have to read the registers + * when we want to change something + * --> everytime we change set a register we have to save it + */ + uint8_t registers[NR_OF_CTRL_REGISTERS]; + + /** + * 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. + */ + DeviceCommandId_t lastSentCommand = 0xffffffff; + + /** + * We always update all registers together, so this method updates + * the rawpacket and rawpacketLen, so we just manipulate the local + * saved register + * + */ + ReturnValue_t prepareRegisterWrite(); + + enum InternalState { + STATE_NONE, STATE_FIRST_CONTACT, STATE_SETUP, STATE_CHECK_REGISTERS + }; + + InternalState internalState = STATE_NONE; + +}; + +#endif /* MISSION_DEVICEHANDLING_MGMLIS3MDLHANDLER_H_ */ diff --git a/mission/devices/MGMRM3100Handler.cpp b/mission/devices/MGMRM3100Handler.cpp new file mode 100644 index 00000000..80b5ec10 --- /dev/null +++ b/mission/devices/MGMRM3100Handler.cpp @@ -0,0 +1,55 @@ +///* +// * MGMRM3100Handler.cpp +// * +// * Created on: 28.05.2020 +// * Author: lukas +// */ +// +//#include +//#include +//#include +//#include +//#include +//#include +// +//MGMRM3100Handler::MGMRM3100Handler(DeviceCommunicationIF *commInterface, object_id_t setOjectId, +// uint32_t address, uint32_t maxReplyLen, datapool::opus_variable_id mgmMeasurement, datapool::opus_variable_id mgmTemperature) +// :NotDeviceHandlerBase(commInterface, setOjectId , address, maxReplyLen),internalState(STATE_NONE), +// mgmMagneticPoolId(mgmMeasurement),mgmTempPoolId(mgmTemperature){ +//} +// +//MGMRM3100Handler::~MGMRM3100Handler() { +//} +// +//ReturnValue_t MGMRM3100Handler::buildTransitionDeviceCommand( +// DeviceCommandId_t *id) { +// return RETURN_OK; +//} +// +//void MGMRM3100Handler::doStartUp() { +//} +// +//void MGMRM3100Handler::doShutDown() { +//} +// +//ReturnValue_t MGMRM3100Handler::buildNormalDeviceCommand( +// DeviceCommandId_t *id) { +// return RETURN_OK; +//} +// +//ReturnValue_t MGMRM3100Handler::buildCommandFromCommand( +// DeviceCommandId_t deviceCommand, const uint8_t *commandData, +// size_t commandDataLen) { +// return RETURN_OK; +//} +// +//ReturnValue_t MGMRM3100Handler::scanForReply( +// const uint8_t *start, uint32_t len, DeviceCommandId_t *foundId, +// uint32_t *foundLen) { +// return RETURN_OK; +//} +// +//ReturnValue_t MGMRM3100Handler::interpretDeviceReply( +// DeviceCommandId_t id, const uint8_t *packet) { +// return RETURN_OK; +//} diff --git a/mission/devices/MGMRM3100Handler.h b/mission/devices/MGMRM3100Handler.h new file mode 100644 index 00000000..91943a86 --- /dev/null +++ b/mission/devices/MGMRM3100Handler.h @@ -0,0 +1,62 @@ +///* +// * MGMRM3100Handler.h +// * +// * Created on: 28.05.2020 +// * Author: lukas +// */ +// +//#ifndef MISSION_DEVICEHANDLING_MGMRM3100HANDLER_H_ +//#define MISSION_DEVICEHANDLING_MGMRM3100HANDLER_H_ +// +//#include +//#include +//#include +//#include +//#include +//#include +//#include +// +//using namespace std; +// +//class MGMRM3100Handler: public NotDeviceHandlerBase { +//public: +// +// MGMRM3100Handler(DeviceCommunicationIF *comInterface, +// object_id_t setObjectId, uint32_t address, uint32_t maxReplyLen, +// datapool::opus_variable_id mgmMeasurement, +// datapool::opus_variable_id mgmTemperature); +// virtual ~MGMRM3100Handler(); +// +//protected: +// //These are the commands the Device has to implement +// virtual ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id); +// virtual void doStartUp(); +// virtual void doShutDown(); +// virtual ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id); +// virtual ReturnValue_t buildCommandFromCommand( +// DeviceCommandId_t deviceCommand, const uint8_t *commandData, +// size_t commandDataLen); +// virtual ReturnValue_t scanForReply(const uint8_t *start, uint32_t len, +// DeviceCommandId_t *foundId, uint32_t *foundLen); +// virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, +// const uint8_t *packet); +// +//private: +// /** +// * Magnetic field data pool id +// */ +// datapool::opus_variable_id mgmMagneticPoolId; +// +// /* +// * Temperature value pool id +// */ +// +// datapool::opus_variable_id mgmTempPoolId; +// +// enum InternalState { +// STATE_NONE, STATE_FIRST_CONTACT, STATE_SETUP, STATE_CHECK_REGISTERS +// } internalState; +// +//}; +// +//#endif /* MISSION_DEVICEHANDLING_MGMRM3100HANDLER_H_ */