mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 09:28:40 +02:00
Start work on device settings communication
This commit is contained in:
+8
-3
@@ -133,11 +133,16 @@ bool Device::close() {
|
||||
}
|
||||
|
||||
bool Device::goOnline() {
|
||||
std::string serial;
|
||||
while(!com->getSerialNumberSync(serial, std::chrono::milliseconds(500))) {
|
||||
std::cout << "Serial number not here yet" << std::endl;
|
||||
}
|
||||
|
||||
if(!com->sendCommand(Communication::Command::EnableNetworkCommunication, true))
|
||||
return false;
|
||||
|
||||
if(!com->sendCommand(Communication::Command::RequestSerialNumber))
|
||||
return false;
|
||||
|
||||
// if(!com->sendCommand(Communication::Command::RequestSerialNumber))
|
||||
// return false;
|
||||
|
||||
return online = true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#include "device/include/idevicesettings.h"
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
uint16_t IDeviceSettings::CalculateGSChecksum(const std::vector<uint8_t>& settings) {
|
||||
uint16_t gs_crc = 0;
|
||||
const uint16_t* p = (const uint16_t*)settings.data();
|
||||
size_t words = settings.size();
|
||||
if(words % 2 == 1)
|
||||
return 0xFFFF; // Somehow settings is not word aligned
|
||||
words /= 2;
|
||||
|
||||
while(words--) {
|
||||
uint16_t temp = *p;
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
bool iBit = temp & 1;
|
||||
|
||||
int iCrcNxt;
|
||||
//CRCNXT = NXTBIT EXOR CRC_RG(15);
|
||||
if (gs_crc & (1 << 15))
|
||||
iCrcNxt = iBit ^ 1;
|
||||
else
|
||||
iCrcNxt = iBit;
|
||||
iCrcNxt = iCrcNxt & 0x01;
|
||||
|
||||
|
||||
// CRC_RG(15:1) = CRC_RG(14:0); // shift left by
|
||||
gs_crc = gs_crc << 1;
|
||||
gs_crc = gs_crc & 0xFFFE;// clear first bit
|
||||
|
||||
if (iCrcNxt)//CRC_RG(14:0) = CRC_RG(14:0) EXOR (4599hex);
|
||||
gs_crc = gs_crc ^ 0xa001;
|
||||
|
||||
temp >>= 1;
|
||||
}
|
||||
|
||||
p++;
|
||||
}
|
||||
return gs_crc;
|
||||
}
|
||||
|
||||
void IDeviceSettings::refresh() {
|
||||
std::vector<uint8_t> rxSettings;
|
||||
bool ret = com->getSettingsSync(rxSettings);
|
||||
if(ret) {
|
||||
if(rxSettings.size() < 6) // We need to at least have the header of GLOBAL_SETTINGS
|
||||
return;
|
||||
|
||||
constexpr size_t gs_size = 3 * sizeof(uint16_t);
|
||||
size_t rxLen = rxSettings.size() - gs_size;
|
||||
|
||||
uint16_t gs_version = rxSettings[0] | (rxSettings[1] << 8);
|
||||
uint16_t gs_len = rxSettings[2] | (rxSettings[3] << 8);
|
||||
uint16_t gs_chksum = rxSettings[4] | (rxSettings[5] << 8);
|
||||
rxSettings.erase(rxSettings.begin(), rxSettings.begin() + gs_size);
|
||||
|
||||
if(gs_version != 5) {
|
||||
std::cout << "gs_version was " << gs_version << " instead of 5.\nPlease update your firmware." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if(rxLen != gs_len) {
|
||||
std::cout << "rxLen was " << rxLen << " and gs_len was " << gs_len << " while reading settings" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if(gs_chksum != CalculateGSChecksum(rxSettings)) {
|
||||
std::cout << "Checksum mismatch while reading settings" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
settings = std::move(rxSettings);
|
||||
settingsLoaded = true;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <memory>
|
||||
#include <cstring>
|
||||
#include "device/include/neodevice.h"
|
||||
#include "device/include/idevicesettings.h"
|
||||
#include "communication/include/communication.h"
|
||||
#include "third-party/concurrentqueue/concurrentqueue.h"
|
||||
|
||||
@@ -50,6 +51,8 @@ public:
|
||||
enforcePollingMessageLimit();
|
||||
}
|
||||
|
||||
std::shared_ptr<IDeviceSettings> settings;
|
||||
|
||||
protected:
|
||||
uint16_t productId = 0;
|
||||
bool online = false;
|
||||
@@ -65,7 +68,7 @@ protected:
|
||||
|
||||
private:
|
||||
neodevice_t data;
|
||||
|
||||
|
||||
size_t pollingMessageLimit = 20000;
|
||||
moodycamel::ConcurrentQueue<std::shared_ptr<Message>> pollingContainer;
|
||||
void enforcePollingMessageLimit();
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
#ifndef __IDEVICESETTINGS_H_
|
||||
#define __IDEVICESETTINGS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "communication/include/communication.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class IDeviceSettings {
|
||||
public:
|
||||
static uint16_t CalculateGSChecksum(const std::vector<uint8_t>& settings);
|
||||
|
||||
IDeviceSettings(std::shared_ptr<Communication> com) : com(com) {
|
||||
refresh();
|
||||
}
|
||||
virtual void refresh();
|
||||
virtual void commit() = 0;
|
||||
virtual void* getStructure() { return settings.data(); }
|
||||
virtual bool setBaudrate(int baud) = 0;
|
||||
protected:
|
||||
bool settingsLoaded = false;
|
||||
std::vector<uint8_t> settings;
|
||||
std::shared_ptr<Communication> com;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* SetBaudrate in CAN_SETTINGS */
|
||||
enum
|
||||
{
|
||||
AUTO,
|
||||
USE_TQ
|
||||
};
|
||||
|
||||
/* Baudrate in CAN_SETTINGS/CANFD_SETTINGS */
|
||||
enum
|
||||
{
|
||||
BPS20,
|
||||
BPS33,
|
||||
BPS50,
|
||||
BPS62,
|
||||
BPS83,
|
||||
BPS100,
|
||||
BPS125,
|
||||
BPS250,
|
||||
BPS500,
|
||||
BPS800,
|
||||
BPS1000,
|
||||
BPS666,
|
||||
BPS2000,
|
||||
BPS4000,
|
||||
CAN_BPS5000,
|
||||
CAN_BPS6667,
|
||||
CAN_BPS8000,
|
||||
CAN_BPS10000,
|
||||
};
|
||||
|
||||
/* Mode in CAN_SETTINGS */
|
||||
enum
|
||||
{
|
||||
NORMAL = 0,
|
||||
DISABLE = 1,
|
||||
LOOPBACK = 2,
|
||||
LISTEN_ONLY = 3,
|
||||
LISTEN_ALL = 7
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Mode;
|
||||
uint8_t SetBaudrate;
|
||||
uint8_t Baudrate;
|
||||
uint8_t transceiver_mode;
|
||||
uint8_t TqSeg1;
|
||||
uint8_t TqSeg2;
|
||||
uint8_t TqProp;
|
||||
uint8_t TqSync;
|
||||
uint16_t BRP;
|
||||
uint8_t auto_baud;
|
||||
uint8_t innerFrameDelay25us;
|
||||
} CAN_SETTINGS;
|
||||
#define CAN_SETTINGS_SIZE 12
|
||||
|
||||
/* FDMode in CANFD_SETTINGS */
|
||||
enum
|
||||
{
|
||||
NO_CANFD,
|
||||
CANFD_ENABLED,
|
||||
CANFD_BRS_ENABLED,
|
||||
CANFD_ENABLED_ISO,
|
||||
CANFD_BRS_ENABLED_ISO
|
||||
};
|
||||
|
||||
typedef struct _CANFD_SETTINGS
|
||||
{
|
||||
uint8_t FDMode; /* mode, secondary baudrate for canfd */
|
||||
uint8_t FDBaudrate;
|
||||
uint8_t FDTqSeg1;
|
||||
uint8_t FDTqSeg2;
|
||||
uint8_t FDTqProp;
|
||||
uint8_t FDTqSync;
|
||||
uint16_t FDBRP;
|
||||
uint8_t FDTDC;
|
||||
uint8_t reserved;
|
||||
} CANFD_SETTINGS;
|
||||
#define CANFD_SETTINGS_SIZE 10
|
||||
|
||||
/* high_speed_auto_switch in SWCAN_SETTINGS */
|
||||
enum
|
||||
{
|
||||
SWCAN_AUTOSWITCH_DISABLED,
|
||||
SWCAN_AUTOSWITCH_NO_RESISTOR,
|
||||
SWCAN_AUTOSWITCH_WITH_RESISTOR,
|
||||
SWCAN_AUTOSWITCH_DISABLED_RESISTOR_ENABLED
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Mode;
|
||||
uint8_t SetBaudrate;
|
||||
uint8_t Baudrate;
|
||||
uint8_t transceiver_mode;
|
||||
uint8_t TqSeg1;
|
||||
uint8_t TqSeg2;
|
||||
uint8_t TqProp;
|
||||
uint8_t TqSync;
|
||||
uint16_t BRP;
|
||||
uint16_t high_speed_auto_switch;
|
||||
uint8_t auto_baud;
|
||||
uint8_t RESERVED;
|
||||
} SWCAN_SETTINGS;
|
||||
#define SWCAN_SETTINGS_SIZE 14
|
||||
|
||||
/* Baudrate in LIN_SETTINGS / ISO9141_KEYWORD2000_SETTINGS / UART_SETTINGS */
|
||||
enum
|
||||
{
|
||||
BPS5000,
|
||||
BPS10400,
|
||||
BPS33333,
|
||||
BPS50000,
|
||||
BPS62500,
|
||||
BPS71429,
|
||||
BPS83333,
|
||||
BPS100000,
|
||||
BPS117647
|
||||
};
|
||||
|
||||
/* MasterResistor in LIN_SETTINGS */
|
||||
enum
|
||||
{
|
||||
RESISTOR_ON,
|
||||
RESISTOR_OFF
|
||||
};
|
||||
|
||||
/* Mode in LIN_SETTINGS */
|
||||
enum
|
||||
{
|
||||
SLEEP_MODE,
|
||||
SLOW_MODE,
|
||||
NORMAL_MODE,
|
||||
FAST_MODE
|
||||
};
|
||||
|
||||
typedef struct _LIN_SETTINGS
|
||||
{
|
||||
uint32_t Baudrate; /* New products since FIREVNETEP should rely on this only */
|
||||
uint16_t spbrg; /* Precompiled to be 40Mhz/Baudrate/16 - 1. Only used in neoVI FIRE/FIREVNET(4dw) */
|
||||
uint8_t brgh; /* Must be zero */
|
||||
uint8_t numBitsDelay;
|
||||
uint8_t MasterResistor;
|
||||
uint8_t Mode;
|
||||
} LIN_SETTINGS;
|
||||
#define LIN_SETTINGS_SIZE 10
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t time_500us;
|
||||
uint16_t k;
|
||||
uint16_t l;
|
||||
} ISO9141_KEYWORD2000__INIT_STEP;
|
||||
#define ISO9141_KEYWORD2000__INIT_STEP_SIZE 6
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t Baudrate;
|
||||
uint16_t spbrg;
|
||||
uint16_t brgh;
|
||||
ISO9141_KEYWORD2000__INIT_STEP init_steps[16];
|
||||
uint8_t init_step_count;
|
||||
uint16_t p2_500us;
|
||||
uint16_t p3_500us;
|
||||
uint16_t p4_500us;
|
||||
uint16_t chksum_enabled;
|
||||
} ISO9141_KEYWORD2000_SETTINGS;
|
||||
#define ISO9141_KEYWORD2000_SETTINGS_SIZE 114
|
||||
|
||||
typedef struct _UART_SETTINGS
|
||||
{
|
||||
uint16_t Baudrate;
|
||||
uint16_t spbrg;
|
||||
uint16_t brgh;
|
||||
uint16_t parity;
|
||||
uint16_t stop_bits;
|
||||
uint8_t flow_control; /* 0- off, 1 - Simple CTS RTS */
|
||||
uint8_t reserved_1;
|
||||
union {
|
||||
uint32_t bOptions;
|
||||
struct
|
||||
{
|
||||
unsigned invert_tx : 1;
|
||||
unsigned invert_rx : 1;
|
||||
unsigned half_duplex : 1;
|
||||
unsigned reserved_bits : 13;
|
||||
unsigned reserved_bits2 : 16;
|
||||
};
|
||||
};
|
||||
} UART_SETTINGS;
|
||||
#define UART_SETTINGS_SIZE 16
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // End of the namespace
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,129 @@
|
||||
#ifndef __NEOVIFIRE2SETTINGS_H_
|
||||
#define __NEOVIFIRE2SETTINGS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "device/include/idevicesettings.h"
|
||||
|
||||
#pragma pack(push, 2)
|
||||
typedef struct {
|
||||
uint16_t perf_en;
|
||||
|
||||
CAN_SETTINGS can1;
|
||||
CANFD_SETTINGS canfd1;
|
||||
CAN_SETTINGS can2;
|
||||
CANFD_SETTINGS canfd2;
|
||||
CAN_SETTINGS can3;
|
||||
CANFD_SETTINGS canfd3;
|
||||
CAN_SETTINGS can4;
|
||||
CANFD_SETTINGS canfd4;
|
||||
CAN_SETTINGS can5;
|
||||
CANFD_SETTINGS canfd5;
|
||||
CAN_SETTINGS can6;
|
||||
CANFD_SETTINGS canfd6;
|
||||
CAN_SETTINGS can7;
|
||||
CANFD_SETTINGS canfd7;
|
||||
CAN_SETTINGS can8;
|
||||
CANFD_SETTINGS canfd8;
|
||||
|
||||
/* Native CAN are either LS1/LS2 or SW1/SW2 */
|
||||
SWCAN_SETTINGS swcan1;
|
||||
uint16_t network_enables;
|
||||
SWCAN_SETTINGS swcan2;
|
||||
uint16_t network_enables_2;
|
||||
|
||||
CAN_SETTINGS lsftcan1;
|
||||
CAN_SETTINGS lsftcan2;
|
||||
|
||||
LIN_SETTINGS lin1;
|
||||
uint16_t misc_io_initial_ddr;
|
||||
LIN_SETTINGS lin2;
|
||||
uint16_t misc_io_initial_latch;
|
||||
LIN_SETTINGS lin3;
|
||||
uint16_t misc_io_report_period;
|
||||
LIN_SETTINGS lin4;
|
||||
uint16_t misc_io_on_report_events;
|
||||
LIN_SETTINGS lin5;
|
||||
uint16_t misc_io_analog_enable;
|
||||
uint16_t ain_sample_period;
|
||||
uint16_t ain_threshold;
|
||||
|
||||
uint32_t pwr_man_timeout;
|
||||
uint16_t pwr_man_enable;
|
||||
|
||||
uint16_t network_enabled_on_boot;
|
||||
|
||||
uint16_t iso15765_separation_time_offset;
|
||||
|
||||
uint16_t iso_9141_kwp_enable_reserved;
|
||||
ISO9141_KEYWORD2000_SETTINGS iso9141_kwp_settings_1;
|
||||
uint16_t iso_parity_1;
|
||||
|
||||
ISO9141_KEYWORD2000_SETTINGS iso9141_kwp_settings_2;
|
||||
uint16_t iso_parity_2;
|
||||
|
||||
ISO9141_KEYWORD2000_SETTINGS iso9141_kwp_settings_3;
|
||||
uint16_t iso_parity_3;
|
||||
|
||||
ISO9141_KEYWORD2000_SETTINGS iso9141_kwp_settings_4;
|
||||
uint16_t iso_parity_4;
|
||||
|
||||
uint16_t iso_msg_termination_1;
|
||||
uint16_t iso_msg_termination_2;
|
||||
uint16_t iso_msg_termination_3;
|
||||
uint16_t iso_msg_termination_4;
|
||||
|
||||
uint16_t idle_wakeup_network_enables_1;
|
||||
uint16_t idle_wakeup_network_enables_2;
|
||||
|
||||
/* reserved for HSCAN6/7, LSFT2, etc.. */
|
||||
uint16_t network_enables_3;
|
||||
uint16_t idle_wakeup_network_enables_3;
|
||||
|
||||
uint16_t can_switch_mode;
|
||||
STextAPISettings text_api;
|
||||
uint64_t termination_enables;
|
||||
LIN_SETTINGS lin6;
|
||||
ETHERNET_SETTINGS ethernet;
|
||||
uint16_t slaveVnetA;
|
||||
uint16_t slaveVnetB;
|
||||
struct {
|
||||
uint32_t disableUsbCheckOnBoot : 1;
|
||||
uint32_t enableLatencyTest : 1;
|
||||
uint32_t busMessagesToAndroid : 1;
|
||||
uint32_t enablePcEthernetComm : 1;
|
||||
uint32_t enableDefaultLogger : 1;
|
||||
uint32_t enableDefaultUpload : 1;
|
||||
uint32_t reserved : 26;
|
||||
} flags;
|
||||
uint16_t digitalIoThresholdTicks;
|
||||
uint16_t digitalIoThresholdEnable;
|
||||
TIMESYNC_ICSHARDWARE_SETTINGS timeSync;
|
||||
} neovifire2_settings_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class NeoVIFIRE2Settings : public IDeviceSettings {
|
||||
public:
|
||||
void refresh() {
|
||||
IDeviceSettings::refresh();
|
||||
if(settingsLoaded) {
|
||||
if(settings.size() != sizeof(neovifire2_settings_t)) {
|
||||
std::cout << "Settings size was " << settings.size() << " but for a FIRE2 it should be " << sizeof(neovifire2_settings_t) << std::endl;
|
||||
settingsLoaded = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
neovifire2_settings_t* settingsStruct = (neovifire2_settings_t*)settings.data();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user