Merge branch 'master' of Lustra:InfiniteWalrus/libicsneo

pull/4/head
Paul Hollinsky 2018-10-25 13:55:41 -04:00
commit 7e6282a7ad
6 changed files with 406 additions and 204 deletions

View File

@ -269,3 +269,12 @@ bool icsneo_transmitMessages(const neodevice_t* device, const neomessage_t* mess
} }
return true; return true;
} }
bool icsneo_describeDevice(const neodevice_t* device, char* str, size_t* maxLength) {
if(!icsneo_isValidNeoDevice(device))
return false;
*maxLength = device->device->describe().copy(str, *maxLength);
str[*maxLength] = '\0';
return true;
}

View File

@ -67,6 +67,12 @@ bool Device::SerialStringIsNumeric(const std::string& serial) {
return isdigit(serial[0]) && isdigit(serial[1]); return isdigit(serial[0]) && isdigit(serial[1]);
} }
std::string Device::describe() const {
std::stringstream ss;
ss << getType() << ' ' << getSerial();
return ss.str();
}
void Device::enableMessagePolling() { void Device::enableMessagePolling() {
if(messagePollingCallbackID != 0) // We are already polling if(messagePollingCallbackID != 0) // We are already polling
return; return;

View File

@ -1,9 +1,15 @@
#ifndef __NETWORKID_H_ #ifndef __NETWORKID_H_
#define __NETWORKID_H_ #define __NETWORKID_H_
#ifndef __cplusplus
#define CONSTEXPR const
#else
#include <cstdint> #include <cstdint>
#include <ostream> #include <ostream>
#define CONSTEXPR constexpr
namespace icsneo { namespace icsneo {
class Network { class Network {
@ -115,16 +121,16 @@ public:
Any = 0xfffe, // Never actually set as type, but used as flag for filtering Any = 0xfffe, // Never actually set as type, but used as flag for filtering
Invalid = 0xffff Invalid = 0xffff
}; };
enum class Type { enum class Type : uint8_t {
Invalid, Invalid = 0,
Internal, // Used for statuses that don't actually need to be transferred to the client application Internal = 1, // Used for statuses that don't actually need to be transferred to the client application
CAN, CAN = 2,
LIN, LIN = 3,
FlexRay, FlexRay = 4,
MOST, MOST = 5,
Ethernet, Ethernet = 6,
Other, Any = 0xFE, // Never actually set as type, but used as flag for filtering
Any // Never actually set as type, but used as flag for filtering Other = 0xFF
}; };
static const char* GetTypeString(Type type) { static const char* GetTypeString(Type type) {
switch(type) { switch(type) {
@ -413,3 +419,123 @@ private:
} }
#endif #endif
#ifdef __ICSNEOC_H_
CONSTEXPR uint16_t ICSNEO_NETID_DEVICE = 0;
CONSTEXPR uint16_t ICSNEO_NETID_HSCAN = 1;
CONSTEXPR uint16_t ICSNEO_NETID_MSCAN = 2;
CONSTEXPR uint16_t ICSNEO_NETID_SWCAN = 3;
CONSTEXPR uint16_t ICSNEO_NETID_LSFTCAN = 4;
CONSTEXPR uint16_t ICSNEO_NETID_FORDSCP = 5;
CONSTEXPR uint16_t ICSNEO_NETID_J1708 = 6;
CONSTEXPR uint16_t ICSNEO_NETID_AUX = 7;
CONSTEXPR uint16_t ICSNEO_NETID_J1850VPW = 8;
CONSTEXPR uint16_t ICSNEO_NETID_ISO = 9;
CONSTEXPR uint16_t ICSNEO_NETID_ISOPIC = 10;
CONSTEXPR uint16_t ICSNEO_NETID_MAIN51 = 11;
CONSTEXPR uint16_t ICSNEO_NETID_RED = 12;
CONSTEXPR uint16_t ICSNEO_NETID_SCI = 13;
CONSTEXPR uint16_t ICSNEO_NETID_ISO2 = 14;
CONSTEXPR uint16_t ICSNEO_NETID_ISO14230 = 15;
CONSTEXPR uint16_t ICSNEO_NETID_LIN = 16;
CONSTEXPR uint16_t ICSNEO_NETID_OP_ETHERNET1 = 17;
CONSTEXPR uint16_t ICSNEO_NETID_OP_ETHERNET2 = 18;
CONSTEXPR uint16_t ICSNEO_NETID_OP_ETHERNET3 = 19;
// START Device Command Returns
// When we send a command, the device returns on one of these, depending on command
CONSTEXPR uint16_t ICSNEO_NETID_RED_EXT_MEMORYREAD = 20;
CONSTEXPR uint16_t ICSNEO_NETID_RED_INT_MEMORYREAD = 21;
CONSTEXPR uint16_t ICSNEO_NETID_RED_DFLASH_READ = 22;
CONSTEXPR uint16_t ICSNEO_NETID_RED_SDCARD_READ = 23;
CONSTEXPR uint16_t ICSNEO_NETID_CAN_ERRBITS = 24;
CONSTEXPR uint16_t ICSNEO_NETID_RED_DFLASH_WRITE_DONE = 25;
CONSTEXPR uint16_t ICSNEO_NETID_RED_WAVE_CAN1_LOGICAL = 26;
CONSTEXPR uint16_t ICSNEO_NETID_RED_WAVE_CAN2_LOGICAL = 27;
CONSTEXPR uint16_t ICSNEO_NETID_RED_WAVE_LIN1_LOGICAL = 28;
CONSTEXPR uint16_t ICSNEO_NETID_RED_WAVE_LIN2_LOGICAL = 29;
CONSTEXPR uint16_t ICSNEO_NETID_RED_WAVE_LIN1_ANALOG = 30;
CONSTEXPR uint16_t ICSNEO_NETID_RED_WAVE_LIN2_ANALOG = 31;
CONSTEXPR uint16_t ICSNEO_NETID_RED_WAVE_MISC_ANALOG = 32;
CONSTEXPR uint16_t ICSNEO_NETID_RED_WAVE_MISCDIO2_LOGICAL = 33;
CONSTEXPR uint16_t ICSNEO_NETID_RED_NETWORK_COM_ENABLE_EX = 34;
CONSTEXPR uint16_t ICSNEO_NETID_RED_NEOVI_NETWORK = 35;
CONSTEXPR uint16_t ICSNEO_NETID_RED_READ_BAUD_SETTINGS = 36;
CONSTEXPR uint16_t ICSNEO_NETID_RED_OLDFORMAT = 37;
CONSTEXPR uint16_t ICSNEO_NETID_RED_SCOPE_CAPTURE = 38;
CONSTEXPR uint16_t ICSNEO_NETID_RED_HARDWARE_EXCEP = 39;
CONSTEXPR uint16_t ICSNEO_NETID_RED_GET_RTC = 40;
// END Device Command Returns
CONSTEXPR uint16_t ICSNEO_NETID_ISO3 = 41;
CONSTEXPR uint16_t ICSNEO_NETID_HSCAN2 = 42;
CONSTEXPR uint16_t ICSNEO_NETID_HSCAN3 = 44;
CONSTEXPR uint16_t ICSNEO_NETID_OP_ETHERNET4 = 45;
CONSTEXPR uint16_t ICSNEO_NETID_OP_ETHERNET5 = 46;
CONSTEXPR uint16_t ICSNEO_NETID_ISO4 = 47;
CONSTEXPR uint16_t ICSNEO_NETID_LIN2 = 48;
CONSTEXPR uint16_t ICSNEO_NETID_LIN3 = 49;
CONSTEXPR uint16_t ICSNEO_NETID_LIN4 = 50;
//CONSTEXPR uint16_t ICSNEO_NETID_MOST = 51; Old and unused
CONSTEXPR uint16_t ICSNEO_NETID_RED_APP_ERROR = 52;
CONSTEXPR uint16_t ICSNEO_NETID_CGI = 53;
CONSTEXPR uint16_t ICSNEO_NETID_RESET_STATUS = 54;
CONSTEXPR uint16_t ICSNEO_NETID_FB_STATUS = 55;
CONSTEXPR uint16_t ICSNEO_NETID_APP_SIGNAL_STATUS = 56;
CONSTEXPR uint16_t ICSNEO_NETID_READ_DATALINK_CM_TX_MSG = 57;
CONSTEXPR uint16_t ICSNEO_NETID_READ_DATALINK_CM_RX_MSG = 58;
CONSTEXPR uint16_t ICSNEO_NETID_LOGGING_OVERFLOW = 59;
CONSTEXPR uint16_t ICSNEO_NETID_READ_SETTINGS_EX = 60;
CONSTEXPR uint16_t ICSNEO_NETID_HSCAN4 = 61;
CONSTEXPR uint16_t ICSNEO_NETID_HSCAN5 = 62;
CONSTEXPR uint16_t ICSNEO_NETID_RS232 = 63;
CONSTEXPR uint16_t ICSNEO_NETID_UART = 64;
CONSTEXPR uint16_t ICSNEO_NETID_UART2 = 65;
CONSTEXPR uint16_t ICSNEO_NETID_UART3 = 66;
CONSTEXPR uint16_t ICSNEO_NETID_UART4 = 67;
CONSTEXPR uint16_t ICSNEO_NETID_SWCAN2 = 68;
CONSTEXPR uint16_t ICSNEO_NETID_ETHERNET_DAQ = 69;
CONSTEXPR uint16_t ICSNEO_NETID_DATA_TO_HOST = 70;
CONSTEXPR uint16_t ICSNEO_NETID_TEXTAPI_TO_HOST = 71;
CONSTEXPR uint16_t ICSNEO_NETID_OP_ETHERNET6 = 73;
CONSTEXPR uint16_t ICSNEO_NETID_RED_VBAT = 74;
CONSTEXPR uint16_t ICSNEO_NETID_OP_ETHERNET7 = 75;
CONSTEXPR uint16_t ICSNEO_NETID_OP_ETHERNET8 = 76;
CONSTEXPR uint16_t ICSNEO_NETID_OP_ETHERNET9 = 77;
CONSTEXPR uint16_t ICSNEO_NETID_OP_ETHERNET10 = 78;
CONSTEXPR uint16_t ICSNEO_NETID_OP_ETHERNET11 = 79;
CONSTEXPR uint16_t ICSNEO_NETID_FLEXRAY1A = 80;
CONSTEXPR uint16_t ICSNEO_NETID_FLEXRAY1B = 81;
CONSTEXPR uint16_t ICSNEO_NETID_FLEXRAY2A = 82;
CONSTEXPR uint16_t ICSNEO_NETID_FLEXRAY2B = 83;
CONSTEXPR uint16_t ICSNEO_NETID_LIN5 = 84;
CONSTEXPR uint16_t ICSNEO_NETID_FLEXRAY = 85;
CONSTEXPR uint16_t ICSNEO_NETID_FLEXRAY2 = 86;
CONSTEXPR uint16_t ICSNEO_NETID_OP_ETHERNET12 = 87;
CONSTEXPR uint16_t ICSNEO_NETID_MOST25 = 90;
CONSTEXPR uint16_t ICSNEO_NETID_MOST50 = 91;
CONSTEXPR uint16_t ICSNEO_NETID_MOST150 = 92;
CONSTEXPR uint16_t ICSNEO_NETID_ETHERNET = 93;
CONSTEXPR uint16_t ICSNEO_NETID_GMFSA = 94;
CONSTEXPR uint16_t ICSNEO_NETID_TCP = 95;
CONSTEXPR uint16_t ICSNEO_NETID_HSCAN6 = 96;
CONSTEXPR uint16_t ICSNEO_NETID_HSCAN7 = 97;
CONSTEXPR uint16_t ICSNEO_NETID_LIN6 = 98;
CONSTEXPR uint16_t ICSNEO_NETID_LSFTCAN2 = 99;
CONSTEXPR uint16_t ICSNEO_NETID_HW_COM_LATENCY_TEST = 512;
CONSTEXPR uint16_t ICSNEO_NETID_DEVICE_STATUS = 513;
CONSTEXPR uint16_t ICSNEO_NETID_ANY = 0xfffe; // Never actually set as type, but used as flag for filtering
CONSTEXPR uint16_t ICSNEO_NETID_INVALID = 0xffff;
CONSTEXPR uint8_t ICSNEO_NETWORK_TYPE_INVALID = 0;
CONSTEXPR uint8_t ICSNEO_NETWORK_TYPE_INTERNAL = 1; // Used for statuses that don't actually need to be transferred to the client application
CONSTEXPR uint8_t ICSNEO_NETWORK_TYPE_CAN = 2;
CONSTEXPR uint8_t ICSNEO_NETWORK_TYPE_LIN = 3;
CONSTEXPR uint8_t ICSNEO_NETWORK_TYPE_FLEXRAY = 4;
CONSTEXPR uint8_t ICSNEO_NETWORK_TYPE_MOST = 5;
CONSTEXPR uint8_t ICSNEO_NETWORK_TYPE_ETHERNET = 6;
CONSTEXPR uint8_t ICSNEO_NETWORK_TYPE_ANY = 0xFE; // Never actually set as type, but used as flag for filtering
CONSTEXPR uint8_t ICSNEO_NETWORK_TYPE_OTHER = 0xFF;
#endif
#endif

View File

@ -37,6 +37,11 @@ public:
std::string getSerial() const { return data.serial; } std::string getSerial() const { return data.serial; }
uint32_t getSerialNumber() const { return Device::SerialStringToNum(getSerial()); } uint32_t getSerialNumber() const { return Device::SerialStringToNum(getSerial()); }
const neodevice_t& getNeoDevice() const { return data; } const neodevice_t& getNeoDevice() const { return data; }
std::string describe() const;
friend std::ostream& operator<<(std::ostream& os, const Device& device) {
os << device.describe();
return os;
}
virtual bool open(); virtual bool open();
virtual bool close(); virtual bool close();

View File

@ -3,15 +3,21 @@
// Hold the length of the longest name, so that C applications can allocate memory accordingly // Hold the length of the longest name, so that C applications can allocate memory accordingly
// Currently the longest is "Intrepid Ethernet Evaluation Board" // Currently the longest is "Intrepid Ethernet Evaluation Board"
#define DEVICE_TYPE_LONGEST_NAME (35 + 1) // Add 1 so that if someone forgets, they still have space for null terminator #define ICSNEO_DEVICETYPE_LONGEST_NAME (35 + 1) // Add 1 so that if someone forgets, they still have space for null terminator
#define ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION (ICSNEO_DEVICETYPE_LONGEST_NAME + 7) // 6 character serial, plus space
#ifndef __cplusplus #ifndef __cplusplus
#include <stdint.h> #include <stdint.h>
#define CONSTEXPR const
typedef uint32_t devicetype_t; typedef uint32_t devicetype_t;
#else #else
#include <ostream> #include <ostream>
#include <cstdint> #include <cstdint>
#define CONSTEXPR constexpr
typedef uint32_t devicetype_t; typedef uint32_t devicetype_t;
namespace icsneo { namespace icsneo {
@ -19,6 +25,7 @@ namespace icsneo {
class DeviceType { class DeviceType {
public: public:
// This enum used to be a bitfield, but has since become an enum as we have more than 32 devices // This enum used to be a bitfield, but has since become an enum as we have more than 32 devices
// Adding something? Make sure you update the type string and C-compatible defines below!
enum Enum : devicetype_t { enum Enum : devicetype_t {
Unknown = (0x00000000), Unknown = (0x00000000),
BLUE = (0x00000001), BLUE = (0x00000001),
@ -161,4 +168,46 @@ private:
#endif // __cplusplus #endif // __cplusplus
#ifdef __ICSNEOC_H_ // We are using the C API, so we want C-compatible defines
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_UNKNOWN = 0x00000000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_BLUE = 0x00000001;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_ECU_AVB = 0x00000002;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_RADSUPERMOON = 0x00000003;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_DW_VCAN = 0x00000004;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_RADMOON2 = 0x00000005;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_RADGIGALOG = 0x00000006;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_VCAN4_1 = 0x00000007;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_FIRE = 0x00000008;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_RADPLUTO = 0x00000009;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_VCAN4_2EL = 0x0000000a;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_RADIO_CANHUB = 0x0000000b;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_VCAN3 = 0x00000010;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_RED = 0x00000040;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_ECU = 0x00000080;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_IEVB = 0x00000100;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_PENDANT = 0x00000200;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_OBD2_PRO = 0x00000400;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_ECUCHIP_UART = 0x00000800;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_PLASMA = 0x00001000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_DONT_REUSE0 = 0x00002000; // Previously FIRE_VNET
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_NEOANALOG = 0x00004000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_CT_OBD = 0x00008000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_DONT_REUSE1 = 0x00010000; // Previously PLASMA_1_12
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_DONT_REUSE2 = 0x00020000; // Previously PLASMA_1_13
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_ION = 0x00040000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_RADSTAR = 0x00080000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_DONT_REUSE3 = 0x00100000; // Previously ION3
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_VCAN4_4 = 0x00200000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_VCAN4_2 = 0x00400000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_CMPROBE = 0x00800000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_EEVB = 0x01000000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_VCANRF = 0x02000000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_FIRE2 = 0x04000000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_FLEX = 0x08000000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_RADGALAXY = 0x10000000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_RADSTAR2 = 0x20000000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_VIVIDCAN = 0x40000000;
CONSTEXPR devicetype_t ICSNEO_DEVICETYPE_OBD2_SIM = 0x80000000;
#endif
#endif #endif

View File

@ -5,6 +5,7 @@
#include "icsneo/device/neodevice.h" // For neodevice_t #include "icsneo/device/neodevice.h" // For neodevice_t
#include "icsneo/communication/message/neomessage.h" // For neomessage_t and friends #include "icsneo/communication/message/neomessage.h" // For neomessage_t and friends
#include "icsneo/platform/dynamiclib.h" // Dynamic library loading and exporting #include "icsneo/platform/dynamiclib.h" // Dynamic library loading and exporting
#include "icsneo/communication/network.h" // Network type and netID defines
#ifndef ICSNEOC_DYNAMICLOAD #ifndef ICSNEOC_DYNAMICLOAD
@ -60,6 +61,8 @@ extern bool DLLExport icsneo_transmit(const neodevice_t* device, const neomessag
extern bool DLLExport icsneo_transmitMessages(const neodevice_t* device, const neomessage_t* messages, size_t count); extern bool DLLExport icsneo_transmitMessages(const neodevice_t* device, const neomessage_t* messages, size_t count);
extern bool DLLExport icsneo_describeDevice(const neodevice_t* device, char* str, size_t* maxLength);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif #endif
@ -138,6 +141,9 @@ fn_icsneo_transmit icsneo_transmit;
typedef bool(*fn_icsneo_transmitMessages)(const neodevice_t* device, const neomessage_t* messages, size_t count); typedef bool(*fn_icsneo_transmitMessages)(const neodevice_t* device, const neomessage_t* messages, size_t count);
fn_icsneo_transmitMessages icsneo_transmitMessages; fn_icsneo_transmitMessages icsneo_transmitMessages;
typedef bool(*fn_icsneo_describeDevice)(const neodevice_t* device, char* str, size_t* maxLength);
fn_icsneo_describeDevice icsneo_describeDevice;
#define ICSNEO_IMPORT(func) func = (fn_##func)icsneo_dynamicLibraryGetFunction(icsneo_libraryHandle, #func) #define ICSNEO_IMPORT(func) func = (fn_##func)icsneo_dynamicLibraryGetFunction(icsneo_libraryHandle, #func)
#define ICSNEO_IMPORTASSERT(func) if((ICSNEO_IMPORT(func)) == NULL) return 3 #define ICSNEO_IMPORTASSERT(func) if((ICSNEO_IMPORT(func)) == NULL) return 3
void* icsneo_libraryHandle = NULL; void* icsneo_libraryHandle = NULL;
@ -176,6 +182,7 @@ int icsneo_init() {
ICSNEO_IMPORTASSERT(icsneo_setBaudrate); ICSNEO_IMPORTASSERT(icsneo_setBaudrate);
ICSNEO_IMPORTASSERT(icsneo_transmit); ICSNEO_IMPORTASSERT(icsneo_transmit);
ICSNEO_IMPORTASSERT(icsneo_transmitMessages); ICSNEO_IMPORTASSERT(icsneo_transmitMessages);
ICSNEO_IMPORTASSERT(icsneo_describeDevice);
icsneo_initialized = true; icsneo_initialized = true;
return 0; return 0;