diff --git a/communication/decoder.cpp b/communication/decoder.cpp index a9f22b6..154ec38 100644 --- a/communication/decoder.cpp +++ b/communication/decoder.cpp @@ -1,6 +1,7 @@ #include "communication/include/decoder.h" #include "communication/include/communication.h" #include "communication/message/include/serialnumbermessage.h" +#include "communication/message/include/resetstatusmessage.h" #include "communication/include/command.h" #include "device/include/device.h" #include @@ -33,6 +34,38 @@ std::shared_ptr Decoder::decodePacket(const std::shared_ptr& pa msg->data.push_back(data->data[i]); return msg; } + case Network::Type::Internal: { + switch(packet->network.getNetID()) { + case Network::NetID::Reset_Status: { + if(packet->data.size() < sizeof(HardwareResetStatusPacket)) + break; + + HardwareResetStatusPacket* data = (HardwareResetStatusPacket*)packet->data.data(); + auto msg = std::make_shared(); + msg->network = packet->network; + msg->mainLoopTime = data->main_loop_time_25ns * 25; + msg->maxMainLoopTime = data->max_main_loop_time_25ns * 25; + msg->busVoltage = data->busVoltage; + msg->deviceTemperature = data->deviceTemperature; + msg->justReset = data->status.just_reset; + msg->comEnabled = data->status.com_enabled; + msg->cmRunning = data->status.cm_is_running; + msg->cmChecksumFailed = data->status.cm_checksum_failed; + msg->cmLicenseFailed = data->status.cm_license_failed; + msg->cmVersionMismatch = data->status.cm_version_mismatch; + msg->cmBootOff = data->status.cm_boot_off; + msg->hardwareFailure = data->status.hardware_failure; + msg->usbComEnabled = data->status.usbComEnabled; + msg->linuxComEnabled = data->status.linuxComEnabled; + msg->cmTooBig = data->status.cm_too_big; + msg->hidUsbState = data->status.hidUsbState; + msg->fpgaUsbState = data->status.fpgaUsbState; + return msg; + } + default: + break; + } + } default: switch(packet->network.getNetID()) { case Network::NetID::Main51: { diff --git a/communication/include/decoder.h b/communication/include/decoder.h index 0e5a57c..fa6cb72 100644 --- a/communication/include/decoder.h +++ b/communication/include/decoder.h @@ -54,6 +54,40 @@ private: } timestamp; }; + union CoreMiniStatusBits_t { + struct { + unsigned just_reset : 1; + unsigned com_enabled : 1; + unsigned cm_is_running : 1; + unsigned cm_checksum_failed : 1; + unsigned cm_license_failed : 1; + unsigned cm_version_mismatch : 1; + unsigned cm_boot_off : 1; + unsigned hardware_failure : 1;//to check SRAM failure (for now) + unsigned isPassiveConnect : 1;///< Always zero. Set to one when neoVI connection is passive,i.e. no async traffic + unsigned usbComEnabled : 1;///< Set to one when USB Host PC has enabled communication. + unsigned linuxComEnabled : 1;///< Set to one when Android (Linux) has enabled communication. + unsigned cm_too_big : 1; + unsigned hidUsbState : 1; + unsigned fpgaUsbState : 1; + unsigned reserved : 2; + }; + uint32_t dword; + }; + + struct HardwareResetStatusPacket { + uint16_t main_loop_time_25ns; + uint16_t max_main_loop_time_25ns; + CoreMiniStatusBits_t status; + uint8_t histo[6];//!< Can hold histogram performance data. + uint16_t spi1Kbps;//!< Spi1's kbps throughput. + uint16_t initBits;//!< Bitfield with init states of drivers, 1 is succes, 0 is fail. + uint16_t cpuMipsH; + uint16_t cpuMipsL; + uint16_t busVoltage; + uint16_t deviceTemperature; + } CoreMiniMsgResetStatus; + // struct CoreMiniMsg { // CANMessage toCANMessage(Network netid); // union { diff --git a/communication/message/include/resetstatusmessage.h b/communication/message/include/resetstatusmessage.h new file mode 100644 index 0000000..e67b36f --- /dev/null +++ b/communication/message/include/resetstatusmessage.h @@ -0,0 +1,35 @@ +#ifndef __RESETSTATUSMESSAGE_H_ +#define __RESETSTATUSMESSAGE_H_ + +#include "communication/message/include/main51message.h" +#include "communication/include/command.h" +#include + +namespace icsneo { + +class ResetStatusMessage : public Message { +public: + ResetStatusMessage() : Message() {} + virtual ~ResetStatusMessage() = default; + uint16_t mainLoopTime; + uint16_t maxMainLoopTime; + bool justReset; + bool comEnabled; + bool cmRunning; + bool cmChecksumFailed; + bool cmLicenseFailed; + bool cmVersionMismatch; + bool cmBootOff; + bool hardwareFailure; + bool usbComEnabled; + bool linuxComEnabled; + bool cmTooBig; + bool hidUsbState; + bool fpgaUsbState; + uint16_t busVoltage; + uint16_t deviceTemperature; +}; + +} + +#endif \ No newline at end of file diff --git a/device/device.cpp b/device/device.cpp index 30cf0f1..7f094cb 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -152,6 +152,10 @@ bool Device::open() { return false; } + internalHandlerCallbackID = com->addMessageCallback(MessageCallback(MessageFilter(Network::Type::Internal), [this](std::shared_ptr message) { + handleInternalMessage(message); + })); + return true; } @@ -159,7 +163,8 @@ bool Device::close() { if(!com) return false; - settings = nullptr; + if(internalHandlerCallbackID) + com->removeMessageCallback(internalHandlerCallbackID); return com->close(); } @@ -178,4 +183,14 @@ bool Device::goOffline() { online = false; return true; +} + +void Device::handleInternalMessage(std::shared_ptr message) { + switch(message->network.getNetID()) { + case Network::NetID::Reset_Status: + latestResetStatus = std::dynamic_pointer_cast(message); + break; + default: + break; //std::cout << "HandleInternalMessage got a message from " << message->network << " and it was unhandled!" << std::endl; + } } \ No newline at end of file diff --git a/device/include/device.h b/device/include/device.h index c1184bf..51cac76 100644 --- a/device/include/device.h +++ b/device/include/device.h @@ -11,6 +11,7 @@ #include "communication/include/packetizer.h" #include "communication/include/encoder.h" #include "communication/include/decoder.h" +#include "communication/message/include/resetstatusmessage.h" #include "third-party/concurrentqueue/concurrentqueue.h" namespace icsneo { @@ -54,18 +55,22 @@ public: enforcePollingMessageLimit(); } + void handleInternalMessage(std::shared_ptr message); + std::unique_ptr settings; protected: uint16_t productId = 0; bool online = false; int messagePollingCallbackID = 0; + int internalHandlerCallbackID = 0; std::shared_ptr com; neodevice_t& getWritableNeoDevice() { return data; } private: neodevice_t data; + std::shared_ptr latestResetStatus; size_t pollingMessageLimit = 20000; moodycamel::ConcurrentQueue> pollingContainer;