Decode reset status messages

pull/4/head
Paul Hollinsky 2018-10-09 13:38:54 -04:00
parent d50e6040b3
commit b3184eb1ed
5 changed files with 123 additions and 1 deletions

View File

@ -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 <iostream>
@ -33,6 +34,38 @@ std::shared_ptr<Message> Decoder::decodePacket(const std::shared_ptr<Packet>& 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<ResetStatusMessage>();
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: {

View File

@ -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 {

View File

@ -0,0 +1,35 @@
#ifndef __RESETSTATUSMESSAGE_H_
#define __RESETSTATUSMESSAGE_H_
#include "communication/message/include/main51message.h"
#include "communication/include/command.h"
#include <string>
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

View File

@ -152,6 +152,10 @@ bool Device::open() {
return false;
}
internalHandlerCallbackID = com->addMessageCallback(MessageCallback(MessageFilter(Network::Type::Internal), [this](std::shared_ptr<Message> 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> message) {
switch(message->network.getNetID()) {
case Network::NetID::Reset_Status:
latestResetStatus = std::dynamic_pointer_cast<ResetStatusMessage>(message);
break;
default:
break; //std::cout << "HandleInternalMessage got a message from " << message->network << " and it was unhandled!" << std::endl;
}
}

View File

@ -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> message);
std::unique_ptr<IDeviceSettings> settings;
protected:
uint16_t productId = 0;
bool online = false;
int messagePollingCallbackID = 0;
int internalHandlerCallbackID = 0;
std::shared_ptr<Communication> com;
neodevice_t& getWritableNeoDevice() { return data; }
private:
neodevice_t data;
std::shared_ptr<ResetStatusMessage> latestResetStatus;
size_t pollingMessageLimit = 20000;
moodycamel::ConcurrentQueue<std::shared_ptr<Message>> pollingContainer;