Compare commits

...

94 Commits

Author SHA1 Message Date
David Rebbe 3b84dcbc5c simple go example 2024-12-17 00:55:40 -05:00
David Rebbe 7b1b3bfe18 added icsneo zig example 2024-12-13 14:22:36 -05:00
David Rebbe 683391a2b9 experimental rust code to make sure it actually works. 2024-12-12 22:46:19 -05:00
David Rebbe dae24a7370 implemented validation for device and message checks 2024-12-12 14:29:22 -05:00
David Rebbe 0dc20db1ad fixed compiler error 2024-12-12 13:07:09 -05:00
David Rebbe 1790fb038a fixed icsneopy 2024-12-12 13:06:46 -05:00
David Rebbe 1216c4c674 add icsneo_message_get_type_name to example 2024-12-12 12:40:36 -05:00
David Rebbe 7c4a3d3077 added icsneo_message_get_type_name 2024-12-12 12:39:19 -05:00
David Rebbe 780e0245b8 another merge conflict fix 2024-12-12 12:38:58 -05:00
David Rebbe 09a4334cb2 Fixed merge conflicts 2024-12-12 12:38:43 -05:00
David Rebbe 894d51953c Merge remote-tracking branch 'origin/master' into icsneo_api 2024-12-12 10:31:18 -05:00
David Rebbe 44bf7688f4 Added RTC functions to example 2024-12-12 10:18:06 -05:00
David Rebbe 351e462167 added Doxygen config for icsneo
Signed-off-by: David Rebbe <drebbe@intrepidcs.com>
2024-12-11 14:26:01 -05:00
David Rebbe 24d2f84dbb temporary change for system tests 2024-12-11 10:53:36 -05:00
David Rebbe 68fe63c566 add support to use system tests outside fetchcontent 2024-12-11 09:49:21 -05:00
David Rebbe bfd9802860 fixed type mismatch 2024-12-11 09:48:44 -05:00
David Rebbe 992e83d8ea initial rust skeleton project. Probably doesn't work. 2024-12-10 20:52:10 -05:00
David Rebbe cb346d25ff more compiler fixes 2024-12-10 17:53:29 -05:00
David Rebbe 398d8cbb16 fixed pointer compare bug 2024-12-10 17:35:48 -05:00
David Rebbe 2d99a30fe1 revert cmake options to original 2024-12-10 17:31:22 -05:00
David Rebbe b5c38dc5b9 fixed more compiler errors 2024-12-10 17:28:35 -05:00
David Rebbe 7e362ec6ff removed a cmake warning 2024-12-10 17:27:35 -05:00
David Rebbe bad0c70ad5 renamed old c api to be less confusing for now 2024-12-10 16:58:10 -05:00
David Rebbe 02c04143d0 libicsneoc fixes 2024-12-10 16:11:45 -05:00
David Rebbe fadeaec512 filtered out tx messages 2024-12-10 15:21:54 -05:00
David Rebbe e9b0cdae56 added getter and setters for baudrates 2024-12-10 15:02:30 -05:00
David Rebbe bac4d86c57 added icsneo_message_is_transmit 2024-12-10 14:19:45 -05:00
David Rebbe f58f478ddb Added descriptions to BusMessage members. 2024-12-10 14:08:14 -05:00
David Rebbe 675842cf9c updated can DLC related stuff 2024-12-10 14:02:18 -05:00
David Rebbe 14cf054635 added icsneo_can_message_free 2024-12-09 11:22:46 -05:00
David Rebbe b75305d1d3 added icsneo_can_message_set_extended, icsneo_can_message_set_canfd, and icsneo_can_message_set_baudrate_switch 2024-12-09 10:47:15 -05:00
David Rebbe d8ee35c36d added icsneo_can_message_set_dlc_on_wire and icsneo_can_message_set_remote 2024-12-09 10:25:23 -05:00
David Rebbe c8de60f40d added icsneo_can_message_set_arbid 2024-12-09 10:17:35 -05:00
David Rebbe 528ffedeb7 added icsneo_message_set_netid and icsneo_message_set_data 2024-12-09 10:04:49 -05:00
David Rebbe 1ca9f0fdb4 added icsneo_message_get_netid and icsneo_get_netid_name 2024-12-09 09:38:01 -05:00
David Rebbe bfd8a023c6 add bus name string to example 2024-12-09 07:52:39 -05:00
David Rebbe 76fd1177de fixed calls around safe_str_copy 2024-12-09 07:52:26 -05:00
David Rebbe 7e616536ef fixed unsafe warnings and added icsneo_get_bus_type_name 2024-12-09 07:33:49 -05:00
David Rebbe b0575fe658 Added icsneo_can_messages_create, untested. 2024-12-08 07:42:16 -05:00
David Rebbe 2a63bbf13f simplified initialization and cleanup. 2024-12-08 07:24:26 -05:00
David Rebbe b514a55749 added icsneo_device_transmit_messages, not tested yet. 2024-12-08 07:05:21 -05:00
David Rebbe 21964fafe4 moved _icsneo_netid_t enum 2024-12-08 06:50:01 -05:00
David Rebbe 13326d3f02 fixed compiler error with pcap 2024-12-08 06:43:00 -05:00
David Rebbe 9dcee2ae04 done renaming enum 2024-12-05 17:18:04 -05:00
David Rebbe ff7b567831 more renaming 2024-12-05 17:12:25 -05:00
David Rebbe 632057dc70 more renaming in progress 2024-12-05 17:08:08 -05:00
David Rebbe faa92ca4fa in progress rename of enum 2024-12-05 16:38:47 -05:00
David Rebbe cc0f257cee added icsneo_device_supports_tc10 2024-12-05 16:23:36 -05:00
David Rebbe 7e4c0cdc43 commonize the naming of the functions 2024-12-05 16:19:32 -05:00
David Rebbe a2feff5dbd rename icsneo_error_code 2024-12-05 16:11:53 -05:00
David Rebbe 9acd669feb add icsneo_is_online_supported 2024-12-05 16:10:32 -05:00
David Rebbe 82502db319 fixed naming 2024-12-05 15:14:32 -05:00
David Rebbe 36065fab05 python bindings build now. 2024-12-05 14:59:05 -05:00
David Rebbe 721c8b22d3 removed static_assert for now 2024-12-05 14:44:25 -05:00
David Rebbe dafcbac251 icsneopy fixes 2024-12-05 13:59:28 -05:00
David Rebbe 86992b2612 revert c++20 feature 2024-12-05 13:59:10 -05:00
David Rebbe 4308958f66 more renaming 2024-12-05 13:07:42 -05:00
David Rebbe d3c7a92f57 fixed some naming issues. 2024-12-05 12:01:39 -05:00
David Rebbe 3cdf9a341f memory optimizations 2024-12-05 11:42:55 -05:00
David Rebbe 875bf45421 added icsneo_device_load_default_settings 2024-12-04 23:18:26 -05:00
David Rebbe dee031710f added rtc functions 2024-12-04 23:08:49 -05:00
David Rebbe b44bf07d1b implemented can getter methods. 2024-12-04 15:35:57 -05:00
David Rebbe 6ca173813e update comment 2024-12-04 12:36:50 -05:00
David Rebbe 6a17e98488 remove check that isn't needed 2024-12-04 12:36:04 -05:00
David Rebbe b88f8dbb05 added icsneo_get_events, icsneo_device_get_events, and icsneo_event_get_description 2024-12-04 12:32:42 -05:00
David Rebbe 360610c0ac updated example to use msg type and bus type functions 2024-12-04 00:33:14 -05:00
David Rebbe a7738f192f added icsneo_message_get_type and icsneo_message_get_bus_type 2024-12-04 00:24:26 -05:00
David Rebbe 55f90f5602 updated bus message classes for getBusType() 2024-12-04 00:08:22 -05:00
David Rebbe 4901168068 renamed RawMessage to InternalMessage 2024-12-03 23:59:19 -05:00
David Rebbe dc54bc6868 renamed Frame to BusMessage 2024-12-03 23:57:46 -05:00
David Rebbe e3ff239da7 moved and renamed network type to icsneo_msg_bus_type_t 2024-12-03 23:56:17 -05:00
David Rebbe 63fd8c2f3a fixed messages 2024-12-03 21:39:47 -05:00
David Rebbe fde2f670b5 fixed sleep on linux 2024-12-03 20:39:54 -05:00
David Rebbe 802be13e74 add timestamp resolution to example. 2024-12-03 18:11:44 -05:00
David Rebbe 7dee139217 added icsneo_message_get_type. Not done. 2024-12-03 18:06:09 -05:00
David Rebbe fbeea2f79d added timeout to get messages and copied messages over. 2024-12-03 17:34:09 -05:00
David Rebbe a97f3bf297 re-order how we open the device 2024-12-03 16:02:28 -05:00
David Rebbe fc72d87c76 updated example 2024-12-03 16:02:07 -05:00
David Rebbe 76afcb410d updated cmakelists with some options disabled for now. 2024-12-03 15:40:52 -05:00
David Rebbe 29486df894 update c23 warning 2024-12-03 15:38:34 -05:00
David Rebbe 983552657b add timestamp and get_messages, untested. 2024-11-25 23:40:49 -05:00
David Rebbe 32815943d5 add icsneo_get_message_count 2024-11-25 22:16:45 -05:00
David Rebbe a7be396ed9 added message polling limit functions 2024-11-25 22:14:58 -05:00
David Rebbe 64f038f781 added icsneo_device_type_from_type 2024-11-25 21:07:48 -05:00
David Rebbe 79293216af added icsneo_error_code 2024-11-25 21:00:10 -05:00
David Rebbe e4f69dfcc3 Added more icsneo functions 2024-11-25 20:51:24 -05:00
David Rebbe a6f8684a0c updated documentation 2024-11-25 20:38:49 -05:00
David Rebbe 8e3b12cdd0 added enum size check 2024-11-25 20:22:25 -05:00
David Rebbe b0f504a731 update devicetype enum names 2024-11-25 19:20:21 -05:00
David Rebbe 00c7e05b5d fixed compiler issue 2024-11-25 18:33:26 -05:00
David Rebbe 21a587db75 icsneo compiles, I'm sure everything else is broke. 2024-11-25 18:15:59 -05:00
David Rebbe ca10478752 in progress 2024-11-25 07:44:05 -05:00
David Rebbe d86a6d5ca1 forgot pragma in header 2024-11-23 18:08:04 -05:00
David Rebbe ee341139c0 first commit, open and close work. 2024-11-23 17:57:14 -05:00
180 changed files with 8592 additions and 2383 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@ third-party/concurrentqueue/tests
examples/csharp/bin
examples/csharp/obj
test/system
.venv

View File

@ -10,8 +10,10 @@ option(LIBICSNEO_BUILD_UNIT_TESTS "Build unit tests." OFF)
option(LIBICSNEO_BUILD_SYSTEM_TESTS "Build system tests." OFF)
option(LIBICSNEO_BUILD_DOCS "Build documentation. Don't use in Visual Studio." OFF)
option(LIBICSNEO_BUILD_EXAMPLES "Build examples." ON)
option(LIBICSNEO_BUILD_ICSNEOC "Build dynamic C library" ON)
option(LIBICSNEO_BUILD_ICSNEOC_STATIC "Build static C library" ON)
option(LIBICSNEO_BUILD_ICSNEO "Build dynamic C library" ON)
option(LIBICSNEO_BUILD_ICSNEO_STATIC "Build static C library" ON)
option(LIBICSNEO_BUILD_ICSNEOC "Build dynamic C legacy library" ON)
option(LIBICSNEO_BUILD_ICSNEOC_STATIC "Build static C legacy library" ON)
option(LIBICSNEO_BUILD_ICSNEOLEGACY "Build icsnVC40 compatibility library" ON)
option(LIBICSNEO_BUILD_ICSNEOLEGACY_STATIC "Build static icsnVC40 compatibility library" ON)
set(LIBICSNEO_NPCAP_INCLUDE_DIR "" CACHE STRING "Npcap include directory; set to build with Npcap")
@ -28,6 +30,7 @@ option(LIBICSNEO_ENABLE_TCP "Enable devices which communicate over TCP" OFF)
option(LIBICSNEO_ENABLE_FTD3XX "Enable devices which communicate over USB FTD3XX" ON)
option(LIBICSNEO_ENABLE_BINDINGS_PYTHON "Enable Python library" OFF)
option(LIBICSNEO_ENABLE_BINDINGS_RUST "Enable Rust library" OFF)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
@ -332,6 +335,7 @@ endif()
configure_file(api/icsneocpp/buildinfo.h.template ${CMAKE_CURRENT_BINARY_DIR}/generated/buildinfo.h)
configure_file(api/icsneoc/version.rc.template ${CMAKE_CURRENT_BINARY_DIR}/generated/icsneoc/version.rc)
configure_file(api/icsneo/version.rc.template ${CMAKE_CURRENT_BINARY_DIR}/generated/icsneo/version.rc)
foreach(EXTINC ${LIBICSNEO_EXTENSION_INCLUDES})
message("Including " ${EXTINC})
@ -432,6 +436,42 @@ if(LIBICSNEO_ENABLE_RAW_ETHERNET)
endif(WIN32)
endif(LIBICSNEO_ENABLE_RAW_ETHERNET)
if(LIBICSNEO_BUILD_ICSNEO)
add_library(icsneo SHARED api/icsneo/icsneo.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated/icsneo/version.rc)
target_include_directories(icsneo
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_link_libraries(icsneo PRIVATE icsneocpp)
target_compile_definitions(icsneo
PRIVATE
ICSNEO_EXPORTS _CRT_SECURE_NO_WARNINGS
PUBLIC
ICSNEO_IMPORTS _CRT_SECURE_NO_WARNINGS
INTERFACE
ICSNEO_IMPORTS _CRT_SECURE_NO_WARNINGS
)
target_compile_features(icsneo PRIVATE cxx_auto_type cxx_constexpr cxx_lambdas cxx_nullptr cxx_range_for cxx_rvalue_references cxx_sizeof_member cxx_strong_enums)
endif()
if(LIBICSNEO_BUILD_ICSNEO_STATIC)
add_library(icsneo-static STATIC api/icsneo/icsneo.cpp)
target_include_directories(icsneo-static
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_link_libraries(icsneo-static PUBLIC icsneocpp)
target_compile_features(icsneo-static PUBLIC cxx_auto_type cxx_constexpr cxx_lambdas cxx_nullptr cxx_range_for cxx_rvalue_references cxx_sizeof_member cxx_strong_enums)
target_compile_definitions(icsneo-static PUBLIC ICSNEO_BUILD_STATIC)
endif()
if(LIBICSNEO_BUILD_ICSNEOC)
add_library(icsneoc SHARED api/icsneoc/icsneoc.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated/icsneoc/version.rc)
target_include_directories(icsneoc
@ -544,12 +584,13 @@ if(LIBICSNEO_BUILD_SYSTEM_TESTS)
FetchContent_Declare(
SystemTests
GIT_REPOSITORY $ENV{LIBICSNEO_SYSTEM_TESTS}
GIT_TAG main
GIT_TAG icsneo_api
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test/system
)
FetchContent_MakeAvailable(SystemTests)
else()
message("System test repo not defined!")
message(WARNING "LIBICSNEO_SYSTEM_TESTS env variable not defined, attempting to use ${CMAKE_CURRENT_SOURCE_DIR}/test/system anyways...")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/system)
endif()
endif()

1329
api/icsneo/icsneo.cpp 100644

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,51 @@
#define VER_FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@
#define VER_FILEVERSION_STR "v@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@@BUILD_METADATA_PLUS@ @BUILD_GIT_INFO@"
#define VER_PRODUCTVERSION VER_FILEVERSION
#define VER_PRODUCTVERSION_STR VER_FILEVERSION_STR
#ifndef DEBUG
#define VER_DEBUG 0
#else
#define VER_DEBUG VS_FF_DEBUG
#endif
#include <windows.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
PRODUCTVERSION VER_PRODUCTVERSION
FILEFLAGSMASK (VS_FF_DEBUG)
FILEFLAGS (VER_DEBUG)
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904E4"
BEGIN
VALUE "CompanyName", "Intrepid Control Systems, Inc."
VALUE "FileDescription", "Intrepid Control Systems Open Device Communication C API"
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", "icsneo.dll"
VALUE "LegalCopyright", "Intrepid Control Systems, Inc. (C) 2018-2024"
VALUE "OriginalFilename", "icsneo.dll"
VALUE "ProductName", "libicsneo"
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
END
END
BLOCK "VarFileInfo"
BEGIN
/* The following line should only be modified for localized versions. */
/* It consists of any number of WORD,WORD pairs, with each pair */
/* describing a language,codepage combination supported by the file. */
/* */
/* For example, a file might have values "0x409,1252" indicating that it */
/* supports English language (0x409) in the Windows ANSI codepage (1252). */
VALUE "Translation", 0x409, 1252
END
END

View File

@ -274,10 +274,10 @@ bool icsneo_removeMessageCallback(const neodevice_t* device, int id) {
return device->device->removeMessageCallback(id);
}
neonetid_t icsneo_getNetworkByNumber(const neodevice_t* device, neonettype_t type, unsigned int number) {
icsneo_netid_t icsneo_getNetworkByNumber(const neodevice_t* device, icsneo_msg_bus_type_t type, unsigned int number) {
if(!icsneo_isValidNeoDevice(device))
return false;
return neonetid_t(device->device->getNetworkByNumber(icsneo::Network::Type(type), size_t(number)).getNetID());
return icsneo_netid_t(device->device->getNetworkByNumber(icsneo_msg_bus_type_t(type), size_t(number)).getNetID());
}
bool icsneo_getProductName(const neodevice_t* device, char* str, size_t* maxLength) {
@ -306,14 +306,14 @@ bool icsneo_getProductName(const neodevice_t* device, char* str, size_t* maxLeng
return true;
}
bool icsneo_getProductNameForType(devicetype_t type, char* str, size_t* maxLength) {
bool icsneo_getProductNameForType(icsneo_devicetype_t type, char* str, size_t* maxLength) {
// TAG String copy function
if(maxLength == nullptr) {
EventManager::GetInstance().add(APIEvent::Type::RequiredParameterNull, APIEvent::Severity::Error);
return false;
}
std::string output = DeviceType(type).getGenericProductName();
std::string output = DeviceType(type).getProductName();
if(str == nullptr) {
*maxLength = output.length();
@ -430,28 +430,28 @@ bool icsneo_settingsApplyStructureTemporary(const neodevice_t* device, const voi
return icsneo_settingsWriteStructure(device, structure, structureSize) && icsneo_settingsApplyTemporary(device);
}
int64_t icsneo_getBaudrate(const neodevice_t* device, neonetid_t netid) {
int64_t icsneo_getBaudrate(const neodevice_t* device, icsneo_netid_t netid) {
if(!icsneo_isValidNeoDevice(device))
return -1;
return device->device->settings->getBaudrateFor(netid);
}
bool icsneo_setBaudrate(const neodevice_t* device, neonetid_t netid, int64_t newBaudrate) {
bool icsneo_setBaudrate(const neodevice_t* device, icsneo_netid_t netid, int64_t newBaudrate) {
if(!icsneo_isValidNeoDevice(device))
return false;
return device->device->settings->setBaudrateFor(netid, newBaudrate);
}
int64_t icsneo_getFDBaudrate(const neodevice_t* device, neonetid_t netid) {
int64_t icsneo_getFDBaudrate(const neodevice_t* device, icsneo_netid_t netid) {
if(!icsneo_isValidNeoDevice(device))
return -1;
return device->device->settings->getFDBaudrateFor(netid);
}
bool icsneo_setFDBaudrate(const neodevice_t* device, neonetid_t netid, int64_t newBaudrate) {
bool icsneo_setFDBaudrate(const neodevice_t* device, icsneo_netid_t netid, int64_t newBaudrate) {
if(!icsneo_isValidNeoDevice(device))
return false;
@ -462,7 +462,7 @@ bool icsneo_transmit(const neodevice_t* device, const neomessage_t* message) {
if(!icsneo_isValidNeoDevice(device))
return false;
if(auto frame = std::dynamic_pointer_cast<icsneo::Frame>(CreateMessageFromNeoMessage(message)))
if(auto frame = std::dynamic_pointer_cast<icsneo::BusMessage>(CreateMessageFromNeoMessage(message)))
return device->device->transmit(frame);
return false;
@ -608,7 +608,7 @@ size_t icsneo_getEventLimit(void) {
return icsneo::GetEventLimit();
}
bool icsneo_getSupportedDevices(devicetype_t* devices, size_t* count) {
bool icsneo_getSupportedDevices(icsneo_devicetype_t* devices, size_t* count) {
if(count == nullptr) {
EventManager::GetInstance().add(APIEvent::Type::RequiredParameterNull, APIEvent::Severity::Error);
return false;
@ -628,7 +628,7 @@ bool icsneo_getSupportedDevices(devicetype_t* devices, size_t* count) {
}
for(size_t i = 0; i < len; i++)
devices[i] = supported[i];
devices[i] = supported[i].getDeviceType();
*count = len;
return true;
@ -671,28 +671,28 @@ bool icsneo_setDigitalIO(const neodevice_t* device, neoio_t type, uint32_t numbe
return device->device->setDigitalIO(static_cast<icsneo::IO>(type), number, value);
}
bool icsneo_isTerminationSupportedFor(const neodevice_t* device, neonetid_t netid) {
bool icsneo_isTerminationSupportedFor(const neodevice_t* device, icsneo_netid_t netid) {
if(!icsneo_isValidNeoDevice(device))
return false;
return device->device->settings->isTerminationSupportedFor(Network(netid));
}
bool icsneo_canTerminationBeEnabledFor(const neodevice_t* device, neonetid_t netid) {
bool icsneo_canTerminationBeEnabledFor(const neodevice_t* device, icsneo_netid_t netid) {
if(!icsneo_isValidNeoDevice(device))
return false;
return device->device->settings->canTerminationBeEnabledFor(Network(netid));
}
bool icsneo_isTerminationEnabledFor(const neodevice_t* device, neonetid_t netid) {
bool icsneo_isTerminationEnabledFor(const neodevice_t* device, icsneo_netid_t netid) {
if(!icsneo_isValidNeoDevice(device))
return false;
return device->device->settings->isTerminationEnabledFor(Network(netid)).value_or(false);
}
bool icsneo_setTerminationFor(const neodevice_t* device, neonetid_t netid, bool enabled) {
bool icsneo_setTerminationFor(const neodevice_t* device, icsneo_netid_t netid, bool enabled) {
if(!icsneo_isValidNeoDevice(device))
return false;
@ -733,13 +733,13 @@ int icsneo_getDeviceStatus(const neodevice_t* device, void* status, size_t* size
std::shared_ptr<Message> msg = device->device->com->waitForMessageSync([&]() {
return device->device->com->sendCommand(Command::RequestStatusUpdate);
}, std::make_shared<MessageFilter>(Network::NetID::DeviceStatus), std::chrono::milliseconds(100));
}, std::make_shared<MessageFilter>(icsneo_netid_device_status), std::chrono::milliseconds(100));
if(!msg) // Did not receive a message
return false;
auto rawMessage = std::static_pointer_cast<RawMessage>(msg);
if(!rawMessage || (rawMessage->network.getNetID() != Network::NetID::DeviceStatus))
auto rawMessage = std::static_pointer_cast<InternalMessage>(msg);
if(!rawMessage || (rawMessage->network.getNetID() != icsneo_netid_device_status))
return false;
if(*size < rawMessage->data.size())

View File

@ -81,23 +81,23 @@ static bool NeoMessageToSpyMessage(const neodevice_t* device, const neomessage_t
copyStatusData();
};
switch (Network::Type(frame.type))
switch (frame.type)
{
case Network::Type::CAN:
case Network::Type::SWCAN:
case Network::Type::LSFTCAN:
case icsneo_msg_bus_type_can:
case icsneo_msg_bus_type_swcan:
case icsneo_msg_bus_type_lsftcan:
oldmsg.Protocol = frame.status.canfdFDF ? SPY_PROTOCOL_CANFD : SPY_PROTOCOL_CAN;
oldmsg.NumberBytesData = static_cast<uint8_t>(std::min(frame.length, (size_t)255));
oldmsg.NumberBytesHeader = 4;
copyFrameData();
break;
case Network::Type::Ethernet:
case icsneo_msg_bus_type_ethernet:
oldmsg.Protocol = SPY_PROTOCOL_ETHERNET;
oldmsg.NumberBytesData = static_cast<uint8_t>(frame.length & 0xFF);
oldmsg.NumberBytesHeader = static_cast<uint8_t>(frame.length >> 8);
copyFrameData();
break;
case Network::Type::LIN:
case icsneo_msg_bus_type_lin:
{
const neomessage_lin_t& linFrame = *reinterpret_cast<const neomessage_lin_t*>(&frame);
icsSpyMessageJ1850& linSpyMsg = *reinterpret_cast<icsSpyMessageJ1850*>(&oldmsg);

View File

@ -1,3 +1,18 @@
if(LIBICSNEO_ENABLE_BINDINGS_PYTHON)
add_subdirectory(python)
endif()
if(LIBICSNEO_ENABLE_BINDINGS_RUST)
include(FetchContent)
FetchContent_Declare(
Corrosion
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
GIT_TAG v0.5 # Optionally specify a commit hash, version tag or branch here
)
FetchContent_MakeAvailable(Corrosion)
corrosion_import_crate(MANIFEST_PATH ${CMAKE_SOURCE_DIR}/bindings/rust/icsneors/Cargo.toml)
else()
message(STATUS "Not building rust bindings")
endif()

View File

@ -7,7 +7,7 @@
namespace icsneo {
void init_canmessage(pybind11::module_& m) {
pybind11::class_<CANMessage, std::shared_ptr<CANMessage>, Frame>(m, "CANMessage")
pybind11::class_<CANMessage, std::shared_ptr<CANMessage>, BusMessage>(m, "CANMessage")
.def(pybind11::init())
.def_readwrite("arbid", &CANMessage::arbid)
.def_readwrite("dlcOnWire", &CANMessage::dlcOnWire)

View File

@ -11,7 +11,7 @@ void init_ethernetmessage(pybind11::module_& m) {
.def("to_string", &MACAddress::toString)
.def("__repr__", &MACAddress::toString);
pybind11::class_<EthernetMessage, std::shared_ptr<EthernetMessage>, Frame>(m, "EthernetMessage")
pybind11::class_<EthernetMessage, std::shared_ptr<EthernetMessage>, BusMessage>(m, "EthernetMessage")
.def(pybind11::init())
.def_readwrite("preemptionEnabled", &EthernetMessage::preemptionEnabled)
.def_readwrite("preemptionFlags", &EthernetMessage::preemptionFlags)

View File

@ -9,7 +9,7 @@ namespace icsneo {
void init_messagefilter(pybind11::module_& m) {
pybind11::class_<MessageFilter, std::shared_ptr<MessageFilter>>(m, "MessageFilter")
.def(pybind11::init())
.def(pybind11::init<Network::NetID>());
.def(pybind11::init<_icsneo_netid_t>());
}
} // namespace icsneo

View File

@ -30,7 +30,7 @@ void init_linmessage(pybind11::module_& m) {
.def_readwrite("BusRecovered", &LINStatusFlags::BusRecovered)
.def_readwrite("BreakOnly", &LINStatusFlags::BreakOnly);
pybind11::class_<LINMessage, std::shared_ptr<LINMessage>, Frame> linMessage(m, "LINMessage");
pybind11::class_<LINMessage, std::shared_ptr<LINMessage>, BusMessage> linMessage(m, "LINMessage");
pybind11::enum_<LINMessage::Type>(linMessage, "Type")
.value("NOT_SET", LINMessage::Type::NOT_SET)

View File

@ -7,7 +7,7 @@
namespace icsneo {
void init_mdiomessage(pybind11::module_& m) {
pybind11::class_<MDIOMessage, std::shared_ptr<MDIOMessage>, Frame> mdioMessage(m, "MDIOMessage");
pybind11::class_<MDIOMessage, std::shared_ptr<MDIOMessage>, BusMessage> mdioMessage(m, "MDIOMessage");
pybind11::enum_<MDIOMessage::Clause>(mdioMessage, "Clause")
.value("Clause45", MDIOMessage::Clause::Clause45)
.value("Clause22", MDIOMessage::Clause::Clause22);

View File

@ -9,12 +9,12 @@ namespace icsneo {
void init_message(pybind11::module_& m) {
pybind11::class_<Message, std::shared_ptr<Message>> message(m, "Message");
pybind11::enum_<Message::Type>(message, "Type")
.value("Frame", Message::Type::Frame)
.value("BusMessage", Message::Type::BusMessage)
.value("CANErrorCount", Message::Type::CANErrorCount)
.value("LINHeaderOnly", Message::Type::LINHeaderOnly)
.value("LINBreak", Message::Type::LINBreak)
.value("Invalid", Message::Type::Invalid)
.value("RawMessage", Message::Type::RawMessage)
.value("InternalMessage", Message::Type::InternalMessage)
.value("ReadSettings", Message::Type::ReadSettings)
.value("ResetStatus", Message::Type::ResetStatus)
.value("DeviceVersion", Message::Type::DeviceVersion)
@ -37,14 +37,14 @@ void init_message(pybind11::module_& m) {
message.def_readonly("type", &Message::type);
message.def_readwrite("timestamp", &Message::timestamp);
pybind11::class_<RawMessage, std::shared_ptr<RawMessage>, Message>(m, "RawMessage")
.def_readwrite("network", &RawMessage::network)
.def_readwrite("data", &RawMessage::data);
pybind11::class_<InternalMessage, std::shared_ptr<InternalMessage>, Message>(m, "InternalMessage")
.def_readwrite("network", &InternalMessage::network)
.def_readwrite("data", &InternalMessage::data);
pybind11::class_<Frame, std::shared_ptr<Frame>, RawMessage>(m, "Frame")
.def_readwrite("description", &Frame::description)
.def_readwrite("transmitted", &Frame::transmitted)
.def_readwrite("error", &Frame::error);
pybind11::class_<BusMessage, std::shared_ptr<BusMessage>, InternalMessage>(m, "BusMessage")
.def_readwrite("description", &BusMessage::description)
.def_readwrite("transmitted", &BusMessage::transmitted)
.def_readwrite("error", &BusMessage::error);
}
} // namespace icsneo

View File

@ -9,184 +9,186 @@ namespace icsneo {
void init_network(pybind11::module_& m) {
pybind11::class_<Network> network(m, "Network");
pybind11::enum_<Network::NetID>(network, "NetID")
.value("Device", Network::NetID::Device)
.value("HSCAN", Network::NetID::HSCAN)
.value("MSCAN", Network::NetID::MSCAN)
.value("SWCAN", Network::NetID::SWCAN)
.value("LSFTCAN", Network::NetID::LSFTCAN)
.value("FordSCP", Network::NetID::FordSCP)
.value("J1708", Network::NetID::J1708)
.value("Aux", Network::NetID::Aux)
.value("J1850VPW", Network::NetID::J1850VPW)
.value("ISO9141", Network::NetID::ISO9141)
.value("DiskData", Network::NetID::DiskData)
.value("Main51", Network::NetID::Main51)
.value("RED", Network::NetID::RED)
.value("SCI", Network::NetID::SCI)
.value("ISO9141_2", Network::NetID::ISO9141_2)
.value("ISO14230", Network::NetID::ISO14230)
.value("LIN", Network::NetID::LIN)
.value("OP_Ethernet1", Network::NetID::OP_Ethernet1)
.value("OP_Ethernet2", Network::NetID::OP_Ethernet2)
.value("OP_Ethernet3", Network::NetID::OP_Ethernet3)
.value("RED_EXT_MEMORYREAD", Network::NetID::RED_EXT_MEMORYREAD)
.value("RED_INT_MEMORYREAD", Network::NetID::RED_INT_MEMORYREAD)
.value("RED_DFLASH_READ", Network::NetID::RED_DFLASH_READ)
.value("NeoMemorySDRead", Network::NetID::NeoMemorySDRead)
.value("CAN_ERRBITS", Network::NetID::CAN_ERRBITS)
.value("NeoMemoryWriteDone", Network::NetID::NeoMemoryWriteDone)
.value("RED_WAVE_CAN1_LOGICAL", Network::NetID::RED_WAVE_CAN1_LOGICAL)
.value("RED_WAVE_CAN2_LOGICAL", Network::NetID::RED_WAVE_CAN2_LOGICAL)
.value("RED_WAVE_LIN1_LOGICAL", Network::NetID::RED_WAVE_LIN1_LOGICAL)
.value("RED_WAVE_LIN2_LOGICAL", Network::NetID::RED_WAVE_LIN2_LOGICAL)
.value("RED_WAVE_LIN1_ANALOG", Network::NetID::RED_WAVE_LIN1_ANALOG)
.value("RED_WAVE_LIN2_ANALOG", Network::NetID::RED_WAVE_LIN2_ANALOG)
.value("RED_WAVE_MISC_ANALOG", Network::NetID::RED_WAVE_MISC_ANALOG)
.value("RED_WAVE_MISCDIO2_LOGICAL", Network::NetID::RED_WAVE_MISCDIO2_LOGICAL)
.value("RED_NETWORK_COM_ENABLE_EX", Network::NetID::RED_NETWORK_COM_ENABLE_EX)
.value("RED_NEOVI_NETWORK", Network::NetID::RED_NEOVI_NETWORK)
.value("RED_READ_BAUD_SETTINGS", Network::NetID::RED_READ_BAUD_SETTINGS)
.value("RED_OLDFORMAT", Network::NetID::RED_OLDFORMAT)
.value("RED_SCOPE_CAPTURE", Network::NetID::RED_SCOPE_CAPTURE)
.value("RED_HARDWARE_EXCEP", Network::NetID::RED_HARDWARE_EXCEP)
.value("RED_GET_RTC", Network::NetID::RED_GET_RTC)
.value("ISO9141_3", Network::NetID::ISO9141_3)
.value("HSCAN2", Network::NetID::HSCAN2)
.value("HSCAN3", Network::NetID::HSCAN3)
.value("OP_Ethernet4", Network::NetID::OP_Ethernet4)
.value("OP_Ethernet5", Network::NetID::OP_Ethernet5)
.value("ISO9141_4", Network::NetID::ISO9141_4)
.value("LIN2", Network::NetID::LIN2)
.value("LIN3", Network::NetID::LIN3)
.value("LIN4", Network::NetID::LIN4)
.value("RED_App_Error", Network::NetID::RED_App_Error)
.value("CGI", Network::NetID::CGI)
.value("Reset_Status", Network::NetID::Reset_Status)
.value("FB_Status", Network::NetID::FB_Status)
.value("App_Signal_Status", Network::NetID::App_Signal_Status)
.value("Read_Datalink_Cm_Tx_Msg", Network::NetID::Read_Datalink_Cm_Tx_Msg)
.value("Read_Datalink_Cm_Rx_Msg", Network::NetID::Read_Datalink_Cm_Rx_Msg)
.value("Logging_Overflow", Network::NetID::Logging_Overflow)
.value("ReadSettings", Network::NetID::ReadSettings)
.value("HSCAN4", Network::NetID::HSCAN4)
.value("HSCAN5", Network::NetID::HSCAN5)
.value("RS232", Network::NetID::RS232)
.value("UART", Network::NetID::UART)
.value("UART2", Network::NetID::UART2)
.value("UART3", Network::NetID::UART3)
.value("UART4", Network::NetID::UART4)
.value("SWCAN2", Network::NetID::SWCAN2)
.value("Ethernet_DAQ", Network::NetID::Ethernet_DAQ)
.value("Data_To_Host", Network::NetID::Data_To_Host)
.value("TextAPI_To_Host", Network::NetID::TextAPI_To_Host)
.value("SPI1", Network::NetID::SPI1)
.value("OP_Ethernet6", Network::NetID::OP_Ethernet6)
.value("Red_VBat", Network::NetID::Red_VBat)
.value("OP_Ethernet7", Network::NetID::OP_Ethernet7)
.value("OP_Ethernet8", Network::NetID::OP_Ethernet8)
.value("OP_Ethernet9", Network::NetID::OP_Ethernet9)
.value("OP_Ethernet10", Network::NetID::OP_Ethernet10)
.value("OP_Ethernet11", Network::NetID::OP_Ethernet11)
.value("FlexRay1a", Network::NetID::FlexRay1a)
.value("FlexRay1b", Network::NetID::FlexRay1b)
.value("FlexRay2a", Network::NetID::FlexRay2a)
.value("FlexRay2b", Network::NetID::FlexRay2b)
.value("LIN5", Network::NetID::LIN5)
.value("FlexRay", Network::NetID::FlexRay)
.value("FlexRay2", Network::NetID::FlexRay2)
.value("OP_Ethernet12", Network::NetID::OP_Ethernet12)
.value("I2C", Network::NetID::I2C)
.value("MOST25", Network::NetID::MOST25)
.value("MOST50", Network::NetID::MOST50)
.value("MOST150", Network::NetID::MOST150)
.value("Ethernet", Network::NetID::Ethernet)
.value("GMFSA", Network::NetID::GMFSA)
.value("TCP", Network::NetID::TCP)
.value("HSCAN6", Network::NetID::HSCAN6)
.value("HSCAN7", Network::NetID::HSCAN7)
.value("LIN6", Network::NetID::LIN6)
.value("LSFTCAN2", Network::NetID::LSFTCAN2)
.value("LogicalDiskInfo", Network::NetID::LogicalDiskInfo)
.value("WiVICommand", Network::NetID::WiVICommand)
.value("ScriptStatus", Network::NetID::ScriptStatus)
.value("EthPHYControl", Network::NetID::EthPHYControl)
.value("ExtendedCommand", Network::NetID::ExtendedCommand)
.value("ExtendedData", Network::NetID::ExtendedData)
.value("FlexRayControl", Network::NetID::FlexRayControl)
.value("CoreMiniPreLoad", Network::NetID::CoreMiniPreLoad)
.value("HW_COM_Latency_Test", Network::NetID::HW_COM_Latency_Test)
.value("DeviceStatus", Network::NetID::DeviceStatus)
.value("UDP", Network::NetID::UDP)
.value("ForwardedMessage", Network::NetID::ForwardedMessage)
.value("I2C2", Network::NetID::I2C2)
.value("I2C3", Network::NetID::I2C3)
.value("I2C4", Network::NetID::I2C4)
.value("Ethernet2", Network::NetID::Ethernet2)
.value("A2B1", Network::NetID::A2B1)
.value("A2B2", Network::NetID::A2B2)
.value("Ethernet3", Network::NetID::Ethernet3)
.value("WBMS", Network::NetID::WBMS)
.value("DWCAN9", Network::NetID::DWCAN9)
.value("DWCAN10", Network::NetID::DWCAN10)
.value("DWCAN11", Network::NetID::DWCAN11)
.value("DWCAN12", Network::NetID::DWCAN12)
.value("DWCAN13", Network::NetID::DWCAN13)
.value("DWCAN14", Network::NetID::DWCAN14)
.value("DWCAN15", Network::NetID::DWCAN15)
.value("DWCAN16", Network::NetID::DWCAN16)
.value("LIN7", Network::NetID::LIN7)
.value("LIN8", Network::NetID::LIN8)
.value("SPI2", Network::NetID::SPI2)
.value("MDIO1", Network::NetID::MDIO1)
.value("MDIO2", Network::NetID::MDIO2)
.value("MDIO3", Network::NetID::MDIO3)
.value("MDIO4", Network::NetID::MDIO4)
.value("MDIO5", Network::NetID::MDIO5)
.value("MDIO6", Network::NetID::MDIO6)
.value("MDIO7", Network::NetID::MDIO7)
.value("MDIO8", Network::NetID::MDIO8)
.value("OP_Ethernet13", Network::NetID::OP_Ethernet13)
.value("OP_Ethernet14", Network::NetID::OP_Ethernet14)
.value("OP_Ethernet15", Network::NetID::OP_Ethernet15)
.value("OP_Ethernet16", Network::NetID::OP_Ethernet16)
.value("SPI3", Network::NetID::SPI3)
.value("SPI4", Network::NetID::SPI4)
.value("SPI5", Network::NetID::SPI5)
.value("SPI6", Network::NetID::SPI6)
.value("SPI7", Network::NetID::SPI7)
.value("SPI8", Network::NetID::SPI8)
.value("LIN9", Network::NetID::LIN9)
.value("LIN10", Network::NetID::LIN10)
.value("LIN11", Network::NetID::LIN11)
.value("LIN12", Network::NetID::LIN12)
.value("LIN13", Network::NetID::LIN13)
.value("LIN14", Network::NetID::LIN14)
.value("LIN15", Network::NetID::LIN15)
.value("LIN16", Network::NetID::LIN16)
.value("Any", Network::NetID::Any)
.value("Invalid", Network::NetID::Invalid);
pybind11::enum_<_icsneo_netid_t>(network, "icsneo_netid_t")
.value("Device", _icsneo_netid_t::icsneo_netid_device)
.value("HSCAN", _icsneo_netid_t::icsneo_netid_hscan)
.value("MSCAN", _icsneo_netid_t::icsneo_netid_mscan)
.value("SWCAN", _icsneo_netid_t::icsneo_netid_swcan)
.value("LSFTCAN", _icsneo_netid_t::icsneo_netid_lsftcan)
.value("FordSCP", _icsneo_netid_t::icsneo_netid_fordscp)
.value("J1708", _icsneo_netid_t::icsneo_netid_j1708)
.value("Aux", _icsneo_netid_t::icsneo_netid_aux)
.value("J1850VPW", _icsneo_netid_t::icsneo_netid_j1850vpw)
.value("ISO9141", _icsneo_netid_t::icsneo_netid_iso9141)
.value("DiskData", _icsneo_netid_t::icsneo_netid_disk_data)
.value("Main51", _icsneo_netid_t::icsneo_netid_main51)
.value("RED", _icsneo_netid_t::icsneo_netid_red)
.value("SCI", _icsneo_netid_t::icsneo_netid_sci)
.value("ISO9141_2", _icsneo_netid_t::icsneo_netid_iso9141_2)
.value("ISO14230", _icsneo_netid_t::icsneo_netid_iso14230)
.value("LIN", _icsneo_netid_t::icsneo_netid_lin)
.value("OP_Ethernet1", _icsneo_netid_t::icsneo_netid_op_ethernet1)
.value("OP_Ethernet2", _icsneo_netid_t::icsneo_netid_op_ethernet2)
.value("OP_Ethernet3", _icsneo_netid_t::icsneo_netid_op_ethernet3)
.value("RED_EXT_MEMORYREAD", _icsneo_netid_t::icsneo_netid_red_ext_memoryread)
.value("RED_INT_MEMORYREAD", _icsneo_netid_t::icsneo_netid_red_int_memoryread)
.value("RED_DFLASH_READ", _icsneo_netid_t::icsneo_netid_red_dflash_read)
.value("NeoMemorySDRead", _icsneo_netid_t::icsneo_netid_neo_memory_sdread)
.value("CAN_ERRBITS", _icsneo_netid_t::icsneo_netid_can_errbits)
.value("NeoMemoryWriteDone", _icsneo_netid_t::icsneo_netid_neo_memory_write_done)
.value("RED_WAVE_CAN1_LOGICAL", _icsneo_netid_t::icsneo_netid_red_wave_can1_logical)
.value("RED_WAVE_CAN2_LOGICAL", _icsneo_netid_t::icsneo_netid_red_wave_can2_logical)
.value("RED_WAVE_LIN1_LOGICAL", _icsneo_netid_t::icsneo_netid_red_wave_lin1_logical)
.value("RED_WAVE_LIN2_LOGICAL", _icsneo_netid_t::icsneo_netid_red_wave_lin2_logical)
.value("RED_WAVE_LIN1_ANALOG", _icsneo_netid_t::icsneo_netid_red_wave_lin1_analog)
.value("RED_WAVE_LIN2_ANALOG", _icsneo_netid_t::icsneo_netid_red_wave_lin2_analog)
.value("RED_WAVE_MISC_ANALOG", _icsneo_netid_t::icsneo_netid_red_wave_misc_analog)
.value("RED_WAVE_MISCDIO2_LOGICAL", _icsneo_netid_t::icsneo_netid_red_wave_miscdio2_logical)
.value("RED_NETWORK_COM_ENABLE_EX", _icsneo_netid_t::icsneo_netid_red_network_com_enable_ex)
.value("RED_NEOVI_NETWORK", _icsneo_netid_t::icsneo_netid_red_neovi_network)
.value("RED_READ_BAUD_SETTINGS", _icsneo_netid_t::icsneo_netid_red_read_baud_settings)
.value("RED_OLDFORMAT", _icsneo_netid_t::icsneo_netid_red_oldformat)
.value("RED_SCOPE_CAPTURE", _icsneo_netid_t::icsneo_netid_red_scope_capture)
.value("RED_HARDWARE_EXCEP", _icsneo_netid_t::icsneo_netid_red_hardware_excep)
.value("RED_GET_RTC", _icsneo_netid_t::icsneo_netid_red_get_rtc)
.value("ISO9141_3", _icsneo_netid_t::icsneo_netid_iso9141_3)
.value("HSCAN2", _icsneo_netid_t::icsneo_netid_hscan2)
.value("HSCAN3", _icsneo_netid_t::icsneo_netid_hscan3)
.value("OP_Ethernet4", _icsneo_netid_t::icsneo_netid_op_ethernet4)
.value("OP_Ethernet5", _icsneo_netid_t::icsneo_netid_op_ethernet5)
.value("ISO9141_4", _icsneo_netid_t::icsneo_netid_iso9141_4)
.value("LIN2", _icsneo_netid_t::icsneo_netid_lin2)
.value("LIN3", _icsneo_netid_t::icsneo_netid_lin3)
.value("LIN4", _icsneo_netid_t::icsneo_netid_lin4)
.value("RED_App_Error", _icsneo_netid_t::icsneo_netid_red_app_error)
.value("CGI", _icsneo_netid_t::icsneo_netid_cgi)
.value("Reset_Status", _icsneo_netid_t::icsneo_netid_reset_status)
.value("FB_Status", _icsneo_netid_t::icsneo_netid_fb_status)
.value("App_Signal_Status", _icsneo_netid_t::icsneo_netid_app_signal_status)
.value("Read_Datalink_Cm_Tx_Msg", _icsneo_netid_t::icsneo_netid_read_datalink_cm_tx_msg)
.value("Read_Datalink_Cm_Rx_Msg", _icsneo_netid_t::icsneo_netid_read_datalink_cm_rx_msg)
.value("Logging_Overflow", _icsneo_netid_t::icsneo_netid_logging_overflow)
.value("ReadSettings", _icsneo_netid_t::icsneo_netid_read_settings)
.value("HSCAN4", _icsneo_netid_t::icsneo_netid_hscan4)
.value("HSCAN5", _icsneo_netid_t::icsneo_netid_hscan5)
.value("RS232", _icsneo_netid_t::icsneo_netid_rs232)
.value("UART", _icsneo_netid_t::icsneo_netid_uart)
.value("UART2", _icsneo_netid_t::icsneo_netid_uart2)
.value("UART3", _icsneo_netid_t::icsneo_netid_uart3)
.value("UART4", _icsneo_netid_t::icsneo_netid_uart4)
.value("SWCAN2", _icsneo_netid_t::icsneo_netid_swcan2)
.value("Ethernet_DAQ", _icsneo_netid_t::icsneo_netid_ethernet_daq)
.value("Data_To_Host", _icsneo_netid_t::icsneo_netid_data_to_host)
.value("TextAPI_To_Host", _icsneo_netid_t::icsneo_netid_textapi_to_host)
.value("SPI1", _icsneo_netid_t::icsneo_netid_spi1)
.value("OP_Ethernet6", _icsneo_netid_t::icsneo_netid_op_ethernet6)
.value("Red_VBat", _icsneo_netid_t::icsneo_netid_red_vbat)
.value("OP_Ethernet7", _icsneo_netid_t::icsneo_netid_op_ethernet7)
.value("OP_Ethernet8", _icsneo_netid_t::icsneo_netid_op_ethernet8)
.value("OP_Ethernet9", _icsneo_netid_t::icsneo_netid_op_ethernet9)
.value("OP_Ethernet10", _icsneo_netid_t::icsneo_netid_op_ethernet10)
.value("OP_Ethernet11", _icsneo_netid_t::icsneo_netid_op_ethernet11)
.value("FlexRay1a", _icsneo_netid_t::icsneo_netid_flexray1a)
.value("FlexRay1b", _icsneo_netid_t::icsneo_netid_flexray1b)
.value("FlexRay2a", _icsneo_netid_t::icsneo_netid_flexray2a)
.value("FlexRay2b", _icsneo_netid_t::icsneo_netid_flexray2b)
.value("LIN5", _icsneo_netid_t::icsneo_netid_lin5)
.value("FlexRay", _icsneo_netid_t::icsneo_netid_flexray)
.value("FlexRay2", _icsneo_netid_t::icsneo_netid_flexray2)
.value("OP_Ethernet12", _icsneo_netid_t::icsneo_netid_op_ethernet12)
.value("I2C", _icsneo_netid_t::icsneo_netid_i2c)
.value("MOST25", _icsneo_netid_t::icsneo_netid_most25)
.value("MOST50", _icsneo_netid_t::icsneo_netid_most50)
.value("MOST150", _icsneo_netid_t::icsneo_netid_most150)
.value("Ethernet", _icsneo_netid_t::icsneo_netid_ethernet)
.value("GMFSA", _icsneo_netid_t::icsneo_netid_gmfsa)
.value("TCP", _icsneo_netid_t::icsneo_netid_tcp)
.value("HSCAN6", _icsneo_netid_t::icsneo_netid_hscan6)
.value("HSCAN7", _icsneo_netid_t::icsneo_netid_hscan7)
.value("LIN6", _icsneo_netid_t::icsneo_netid_lin6)
.value("LSFTCAN2", _icsneo_netid_t::icsneo_netid_lsftcan2)
.value("LogicalDiskInfo", _icsneo_netid_t::icsneo_netid_logical_disk_info)
.value("WiVICommand", _icsneo_netid_t::icsneo_netid_wivi_command)
.value("ScriptStatus", _icsneo_netid_t::icsneo_netid_script_status)
.value("EthPHYControl", _icsneo_netid_t::icsneo_netid_eth_phy_control)
.value("ExtendedCommand", _icsneo_netid_t::icsneo_netid_extended_command)
.value("ExtendedData", _icsneo_netid_t::icsneo_netid_extended_data)
.value("FlexRayControl", _icsneo_netid_t::icsneo_netid_flexray_control)
.value("CoreMiniPreLoad", _icsneo_netid_t::icsneo_netid_coremini_preload)
.value("HW_COM_Latency_Test", _icsneo_netid_t::icsneo_netid_hw_com_latency_test)
.value("DeviceStatus", _icsneo_netid_t::icsneo_netid_device_status)
.value("UDP", _icsneo_netid_t::icsneo_netid_udp)
.value("ForwardedMessage", _icsneo_netid_t::icsneo_netid_forwarded_message)
.value("I2C2", _icsneo_netid_t::icsneo_netid_i2c2)
.value("I2C3", _icsneo_netid_t::icsneo_netid_i2c3)
.value("I2C4", _icsneo_netid_t::icsneo_netid_i2c4)
.value("Ethernet2", _icsneo_netid_t::icsneo_netid_ethernet2)
.value("A2B1", _icsneo_netid_t::icsneo_netid_a2b1)
.value("A2B2", _icsneo_netid_t::icsneo_netid_a2b2)
.value("Ethernet3", _icsneo_netid_t::icsneo_netid_ethernet3)
.value("WBMS", _icsneo_netid_t::icsneo_netid_wbms)
.value("DWCAN9", _icsneo_netid_t::icsneo_netid_dwcan9)
.value("DWCAN10", _icsneo_netid_t::icsneo_netid_dwcan10)
.value("DWCAN11", _icsneo_netid_t::icsneo_netid_dwcan11)
.value("DWCAN12", _icsneo_netid_t::icsneo_netid_dwcan12)
.value("DWCAN13", _icsneo_netid_t::icsneo_netid_dwcan13)
.value("DWCAN14", _icsneo_netid_t::icsneo_netid_dwcan14)
.value("DWCAN15", _icsneo_netid_t::icsneo_netid_dwcan15)
.value("DWCAN16", _icsneo_netid_t::icsneo_netid_dwcan16)
.value("LIN7", _icsneo_netid_t::icsneo_netid_lin7)
.value("LIN8", _icsneo_netid_t::icsneo_netid_lin8)
.value("SPI2", _icsneo_netid_t::icsneo_netid_spi2)
.value("MDIO1", _icsneo_netid_t::icsneo_netid_mdio1)
.value("MDIO2", _icsneo_netid_t::icsneo_netid_mdio2)
.value("MDIO3", _icsneo_netid_t::icsneo_netid_mdio3)
.value("MDIO4", _icsneo_netid_t::icsneo_netid_mdio4)
.value("MDIO5", _icsneo_netid_t::icsneo_netid_mdio5)
.value("MDIO6", _icsneo_netid_t::icsneo_netid_mdio6)
.value("MDIO7", _icsneo_netid_t::icsneo_netid_mdio7)
.value("MDIO8", _icsneo_netid_t::icsneo_netid_mdio8)
.value("OP_Ethernet13", _icsneo_netid_t::icsneo_netid_op_ethernet13)
.value("OP_Ethernet14", _icsneo_netid_t::icsneo_netid_op_ethernet14)
.value("OP_Ethernet15", _icsneo_netid_t::icsneo_netid_op_ethernet15)
.value("OP_Ethernet16", _icsneo_netid_t::icsneo_netid_op_ethernet16)
.value("SPI3", _icsneo_netid_t::icsneo_netid_spi3)
.value("SPI4", _icsneo_netid_t::icsneo_netid_spi4)
.value("SPI5", _icsneo_netid_t::icsneo_netid_spi5)
.value("SPI6", _icsneo_netid_t::icsneo_netid_spi6)
.value("SPI7", _icsneo_netid_t::icsneo_netid_spi7)
.value("SPI8", _icsneo_netid_t::icsneo_netid_spi8)
.value("LIN9", _icsneo_netid_t::icsneo_netid_lin9)
.value("LIN10", _icsneo_netid_t::icsneo_netid_lin10)
.value("LIN11", _icsneo_netid_t::icsneo_netid_lin11)
.value("LIN12", _icsneo_netid_t::icsneo_netid_lin12)
.value("LIN13", _icsneo_netid_t::icsneo_netid_lin13)
.value("LIN14", _icsneo_netid_t::icsneo_netid_lin14)
.value("LIN15", _icsneo_netid_t::icsneo_netid_lin15)
.value("LIN16", _icsneo_netid_t::icsneo_netid_lin16)
.value("Any", _icsneo_netid_t::icsneo_netid_any)
.value("Invalid", _icsneo_netid_t::icsneo_netid_invalid);
pybind11::enum_<Network::Type>(network, "Type")
.value("Invalid", Network::Type::Invalid)
.value("Internal", Network::Type::Internal)
.value("CAN", Network::Type::CAN)
.value("LIN", Network::Type::LIN)
.value("FlexRay", Network::Type::FlexRay)
.value("MOST", Network::Type::MOST)
.value("Ethernet", Network::Type::Ethernet)
.value("LSFTCAN", Network::Type::LSFTCAN)
.value("SWCAN", Network::Type::SWCAN)
.value("ISO9141", Network::Type::ISO9141)
.value("I2C", Network::Type::I2C)
.value("A2B", Network::Type::A2B)
.value("SPI", Network::Type::SPI)
.value("MDIO", Network::Type::MDIO)
.value("Any", Network::Type::Any)
.value("Other", Network::Type::Other);
network.def(pybind11::init<_icsneo_netid_t>());
pybind11::enum_<_icsneo_msg_bus_type_t>(network, "icsneo_msg_bus_type_t")
.value("Invalid", icsneo_msg_bus_type_invalid)
.value("Internal", icsneo_msg_bus_type_internal)
.value("CAN", icsneo_msg_bus_type_can)
.value("LIN", icsneo_msg_bus_type_lin)
.value("FlexRay", icsneo_msg_bus_type_flexray)
.value("MOST", icsneo_msg_bus_type_most)
.value("Ethernet", icsneo_msg_bus_type_ethernet)
.value("LSFTCAN", icsneo_msg_bus_type_lsftcan)
.value("SWCAN", icsneo_msg_bus_type_swcan)
.value("ISO9141", icsneo_msg_bus_type_iso9141)
.value("I2C", icsneo_msg_bus_type_i2c)
.value("A2B", icsneo_msg_bus_type_a2b)
.value("SPI", icsneo_msg_bus_type_spi)
.value("MDIO", icsneo_msg_bus_type_mdio)
.value("Any", icsneo_msg_bus_type_any)
.value("Other", icsneo_msg_bus_type_other);
network
.def(pybind11::init<Network::NetID>())
.def(pybind11::init<_icsneo_msg_bus_type_t>())
.def("__repr__", [](Network& self) { return Network::GetNetIDString(self.getNetID()); })
.def_static("get_net_id_string", &Network::GetNetIDString, pybind11::arg("netid"), pybind11::arg("expand") = true)
.def("get_net_id", &Network::getNetID)

View File

@ -27,7 +27,7 @@ void init_device(pybind11::module_& m) {
.def("set_polling_message_limit", &Device::setPollingMessageLimit)
.def("add_message_callback", &Device::addMessageCallback)
.def("remove_message_callback", &Device::removeMessageCallback)
.def("transmit", pybind11::overload_cast<std::shared_ptr<Frame>>(&Device::transmit))
.def("transmit", pybind11::overload_cast<std::shared_ptr<BusMessage>>(&Device::transmit))
.def("get_supported_rx_networks", &Device::getSupportedRXNetworks, pybind11::return_value_policy::reference)
.def("get_supported_tx_networks", &Device::getSupportedTXNetworks, pybind11::return_value_policy::reference)
.def("get_rtc", &Device::getRTC)

View File

@ -2,74 +2,69 @@
#include <pybind11/stl.h>
#include <pybind11/functional.h>
#include "icsneo/device/devicetype.h"
#include <icsneo/device/devicetype.h>
#include <icsneo/icsneotypes.h>
namespace icsneo {
void init_devicetype(pybind11::module_& m) {
pybind11::class_<DeviceType> deviceType(m, "DeviceType");
pybind11::enum_<DeviceType::Enum>(deviceType, "Enum")
.value("Unknown", DeviceType::Enum::Unknown)
.value("BLUE", DeviceType::Enum::BLUE)
.value("ECU_AVB", DeviceType::Enum::ECU_AVB)
.value("RADSupermoon", DeviceType::Enum::RADSupermoon)
.value("DW_VCAN", DeviceType::Enum::DW_VCAN)
.value("RADMoon2", DeviceType::Enum::RADMoon2)
.value("RADMars", DeviceType::Enum::RADMars)
.value("VCAN4_1", DeviceType::Enum::VCAN4_1)
.value("FIRE", DeviceType::Enum::FIRE)
.value("RADPluto", DeviceType::Enum::RADPluto)
.value("VCAN4_2EL", DeviceType::Enum::VCAN4_2EL)
.value("RADIO_CANHUB", DeviceType::Enum::RADIO_CANHUB)
.value("NEOECU12", DeviceType::Enum::NEOECU12)
.value("OBD2_LCBADGE", DeviceType::Enum::OBD2_LCBADGE)
.value("RADMoonDuo", DeviceType::Enum::RADMoonDuo)
.value("FIRE3", DeviceType::Enum::FIRE3)
.value("VCAN3", DeviceType::Enum::VCAN3)
.value("RADJupiter", DeviceType::Enum::RADJupiter)
.value("VCAN4_IND", DeviceType::Enum::VCAN4_IND)
.value("RADGigastar", DeviceType::Enum::RADGigastar)
.value("RED2", DeviceType::Enum::RED2)
.value("EtherBADGE", DeviceType::Enum::EtherBADGE)
.value("RAD_A2B", DeviceType::Enum::RAD_A2B)
.value("RADEpsilon", DeviceType::Enum::RADEpsilon)
.value("RADGalaxy2", DeviceType::Enum::RADGalaxy2)
.value("RADMoon3", DeviceType::Enum::RADMoon3)
.value("RADComet", DeviceType::Enum::RADComet)
.value("FIRE3_FlexRay", DeviceType::Enum::FIRE3_FlexRay)
.value("Connect", DeviceType::Enum::Connect)
.value("RADComet3", DeviceType::Enum::RADComet3)
.value("RADMoonT1S", DeviceType::Enum::RADMoonT1S)
.value("RADGigastar2", DeviceType::Enum::RADGigastar2)
.value("RED", DeviceType::Enum::RED)
.value("ECU", DeviceType::Enum::ECU)
.value("IEVB", DeviceType::Enum::IEVB)
.value("Pendant", DeviceType::Enum::Pendant)
.value("OBD2_PRO", DeviceType::Enum::OBD2_PRO)
.value("ECUChip_UART", DeviceType::Enum::ECUChip_UART)
.value("PLASMA", DeviceType::Enum::PLASMA)
.value("DONT_REUSE0", DeviceType::Enum::DONT_REUSE0)
.value("NEOAnalog", DeviceType::Enum::NEOAnalog)
.value("CT_OBD", DeviceType::Enum::CT_OBD)
.value("DONT_REUSE1", DeviceType::Enum::DONT_REUSE1)
.value("DONT_REUSE2", DeviceType::Enum::DONT_REUSE2)
.value("ION", DeviceType::Enum::ION)
.value("RADStar", DeviceType::Enum::RADStar)
.value("DONT_REUSE3", DeviceType::Enum::DONT_REUSE3)
.value("VCAN4_4", DeviceType::Enum::VCAN4_4)
.value("VCAN4_2", DeviceType::Enum::VCAN4_2)
.value("CMProbe", DeviceType::Enum::CMProbe)
.value("EEVB", DeviceType::Enum::EEVB)
.value("VCANrf", DeviceType::Enum::VCANrf)
.value("FIRE2", DeviceType::Enum::FIRE2)
.value("Flex", DeviceType::Enum::Flex)
.value("RADGalaxy", DeviceType::Enum::RADGalaxy)
.value("RADStar2", DeviceType::Enum::RADStar2)
.value("VividCAN", DeviceType::Enum::VividCAN)
.value("OBD2_SIM", DeviceType::Enum::OBD2_SIM);
deviceType.def(pybind11::init<DeviceType::Enum>());
deviceType.def("get_device_type", &DeviceType::getDeviceType);
deviceType.def("get_generic_product_name", &DeviceType::getGenericProductName);
deviceType.def(
"get_generic_product_name", [](DeviceType &self) -> std::string {
return self.getGenericProductName(self.getDeviceType());
});
pybind11::enum_<_icsneo_devicetype_t>(m, "icsneo_devicetype_t")
.value("unknown", icsneo_devicetype_unknown)
.value("blue", icsneo_devicetype_blue)
.value("ecu_avb", icsneo_devicetype_ecu_avb)
.value("rad_supermoon", icsneo_devicetype_rad_supermoon)
.value("dw_vcan", icsneo_devicetype_dw_vcan)
.value("rad_moon2", icsneo_devicetype_rad_moon2)
.value("rad_mars", icsneo_devicetype_rad_mars)
.value("vcan41", icsneo_devicetype_vcan41)
.value("fire", icsneo_devicetype_fire)
.value("rad_pluto", icsneo_devicetype_rad_pluto)
.value("vcan42_el", icsneo_devicetype_vcan42_el)
.value("radio_canhub", icsneo_devicetype_radio_canhub)
.value("neo_ecu12", icsneo_devicetype_neo_ecu12)
.value("obd2_lc_badge", icsneo_devicetype_obd2_lc_badge)
.value("rad_moon_duo", icsneo_devicetype_rad_moon_duo)
.value("fire3", icsneo_devicetype_fire3)
.value("vcan3", icsneo_devicetype_vcan3)
.value("rad_jupiter", icsneo_devicetype_rad_jupiter)
.value("vcan4_industrial", icsneo_devicetype_vcan4_industrial)
.value("rad_gigastar", icsneo_devicetype_rad_gigastar)
.value("red2", icsneo_devicetype_red2)
.value("etherbadge", icsneo_devicetype_etherbadge)
.value("rad_a2b", icsneo_devicetype_rad_a2b)
.value("rad_epsilon", icsneo_devicetype_rad_epsilon)
.value("rad_moon3", icsneo_devicetype_rad_moon3)
.value("rad_comet", icsneo_devicetype_rad_comet)
.value("fire3_flexray", icsneo_devicetype_fire3_flexray)
.value("connect", icsneo_devicetype_connect)
.value("rad_comet3", icsneo_devicetype_rad_comet3)
.value("rad_moon_t1s", icsneo_devicetype_rad_moon_t1s)
.value("rad_gigastar2", icsneo_devicetype_rad_gigastar2)
.value("red", icsneo_devicetype_red)
.value("ecu", icsneo_devicetype_ecu)
.value("ievb", icsneo_devicetype_ievb)
.value("pendant", icsneo_devicetype_pendant)
.value("obd2_pro", icsneo_devicetype_obd2_pro)
.value("plasma", icsneo_devicetype_plasma)
.value("ion", icsneo_devicetype_ion)
.value("rad_star", icsneo_devicetype_rad_star)
.value("vcan44", icsneo_devicetype_vcan44)
.value("vcan42", icsneo_devicetype_vcan42)
.value("cm_probe", icsneo_devicetype_cm_probe)
.value("eevb", icsneo_devicetype_eevb)
.value("fire2", icsneo_devicetype_fire2)
.value("flex", icsneo_devicetype_flex)
.value("rad_galaxy", icsneo_devicetype_rad_galaxy)
.value("rad_star2", icsneo_devicetype_rad_star2)
.value("vividcan", icsneo_devicetype_vividcan)
.value("obd2_sim", icsneo_devicetype_obd2_sim);
}
} // namespace icsneo

View File

@ -0,0 +1,21 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# RustRover
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

View File

@ -0,0 +1,18 @@
[package]
name = "icsneors"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[features]
static = []
[dependencies]
[build-dependencies]
bindgen = "0.71.1"
path-clean = "1.0.1"
cmake = "0.1.52"
which = "7.0.0"

View File

@ -0,0 +1,197 @@
use cmake::Config;
use path_clean::{clean, PathClean};
use std::{env, path::PathBuf};
fn libicsneo_path() -> PathBuf {
// Get the path of libicsneo
let path = std::env::var("LIBICSNEO_PATH")
.unwrap_or(format!("{}/../../../", env!("CARGO_MANIFEST_DIR")));
let libicsneo_path = std::path::PathBuf::from(clean(&path));
libicsneo_path
}
fn libicsneo_include_path() -> PathBuf {
let path = libicsneo_path().join("include");
path.clean()
}
fn libicsneo_header_path() -> PathBuf {
let path = libicsneo_include_path().join("icsneo").join("icsneo.h");
path.clean()
}
// Detects the cargo build profile, true = release, otherwise false
fn is_release_build() -> bool {
let profile = std::env::var("PROFILE").unwrap();
match profile.as_str() {
"debug" => return false,
"release" => return true,
_ => return false,
}
}
// returns the cmake build string that is normally passed to -DCMAKE_BUILD_TYPE=
fn cmake_build_config_type() -> String {
let build_config_type = if is_release_build() {
"Release"
} else {
if cfg!(target_os = "windows") {
// Rust runtime is linked with /MD on windows MSVC... MSVC takes Debug and forces /MDd
// https://www.reddit.com/r/rust/comments/dvmzo2/cargo_external_c_library_windows_debugrelease_hell/
"RelWithDebInfo"
} else {
"Debug"
}
};
build_config_type.to_string()
}
// Build libicsneo through cmake, returns the build directory
fn build_libicsneo() -> PathBuf {
let libicsneo_path = libicsneo_path();
// Check to make sure CMakeLists.txt exists
if !libicsneo_path.join("CMakeLists.txt").exists() {
panic!("CMakeLists.txt not found at {}", libicsneo_path.display());
}
let build_config_type = cmake_build_config_type();
// Run cmake on libicsneo
let mut config = Config::new(libicsneo_path.clone());
let config = config
.build_target("ALL_BUILD")
// .define("LIBICSNEO_BUILD_ICSNEOC_STATIC:BOOL", "ON")
// .define("LIBICSNEO_BUILD_EXAMPLES:BOOL", "OFF")
// .define("LIBICSNEO_BUILD_ICSNEOLEGACY:BOOL", "OFF")
.profile(&build_config_type);
// Lets use ninja if it exists
let config = match which::which("ninja") {
Ok(_) => config.generator("Ninja Multi-Config").build_target("all"),
Err(_e) => config,
};
config.build()
}
fn setup_linker_libs(build_path: &PathBuf) {
let build_config_type = cmake_build_config_type();
// output for lib path
println!(
"cargo:warning=build search path: {:?}",
build_path
.join(format!("build/{build_config_type}"))
.display()
);
// icsneo lib/dll linker search path
println!(
"cargo:rustc-link-search=native={}",
build_path
.join(format!("build/{build_config_type}"))
.display()
);
// fatfs linker search path and addition
println!(
"cargo:rustc-link-search=native={}/build/third-party/fatfs/{build_config_type}",
build_path.display()
);
// libicsneo libraries
println!("cargo:rustc-link-lib=fatfs");
println!("cargo:rustc-link-lib=static=icsneocpp");
if cfg!(feature = "static") {
println!("cargo:rustc-link-lib=static=icsneo-static");
} else {
println!("cargo:rustc-link-lib=dylib=icsneo");
}
// Platform specific libraries
match env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() {
"windows" => {
// FTD3xx linker search path and addition
println!(
"cargo:rustc-link-search=native={}/build/_deps/ftdi3xx-src",
build_path.display()
);
println!("cargo:rustc-link-lib=FTD3XX");
}
"linux" => {}
"macos" => {
println!("cargo:rustc-link-lib=static=icsneo-static");
println!("cargo:rustc-link-lib=framework=IOKit");
println!("cargo:rustc-link-lib=framework=CoreFoundation");
}
target_os => panic!("Target OS not supported: {target_os}"),
}
}
fn prepare_git_submodule() {
// We don't need to checkout the submodule if we are using a custom libicsneo path
if std::env::var("LIBICSNEO_PATH").is_ok() {
println!("cargo:warning=Using custom LIBICSNEO_PATH, skipping checking out submodules");
return;
}
let libicsneo_path = libicsneo_path();
// This seems to not be needed when including this as a dependency? Why?
// checkout the submodule if needed
let output = std::process::Command::new("git")
.args(["submodule", "update", "--init"])
.current_dir(libicsneo_path)
.output()
.expect("Failed to fetch git submodules!");
// Make sure git was successful!
if !output.status.success() {
println!("cargo:warning=git return code: {}", output.status);
let stdout = std::str::from_utf8(&output.stdout).unwrap();
for line in stdout.split("\n") {
println!("cargo:warning=git stdout: {}", line);
}
let stderr = std::str::from_utf8(&output.stderr).unwrap();
for line in stderr.split("\n") {
println!("cargo:warning=git stderr: {}", line);
}
}
}
fn generate_bindings() {
let header = libicsneo_header_path();
let bindings = bindgen::Builder::default()
.header(header.to_str().unwrap())
.default_enum_style(bindgen::EnumVariation::Rust {
non_exhaustive: false,
})
.clang_args(&[format!("-I{}", libicsneo_include_path().display()).as_str()])
.blocklist_file("stdint.h")
.blocklist_file("stdbool.h")
.use_core()
.formatter(bindgen::Formatter::Rustfmt)
.derive_default(true)
.derive_debug(true)
.derive_partialeq(true)
.derive_copy(true)
.default_alias_style(bindgen::AliasVariation::NewType)
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
//.clang_args(clang_args())
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
println!("cargo:warning=out_path: {:?}", out_path.display());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings");
let out_path = std::path::PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
fn main() {
let header = libicsneo_header_path();
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed={}", header.to_str().unwrap());
println!("cargo:rerun-if-env-changed=LIBMSVC_PATH");
prepare_git_submodule();
generate_bindings();
// We can skip building if its for docs.rs
if std::env::var("DOCS_RS").is_err() {
let build_directory = build_libicsneo();
setup_linker_libs(&build_directory);
}
}

View File

@ -0,0 +1,43 @@
// Suppress the flurry of warnings caused by using "C" naming conventions
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
pub unsafe fn find_devices() {
let mut devices: [*mut icsneo_device_t; 255] = [std::ptr::null_mut(); 255];
let mut device_count: u32 = 255;
let res = icsneo_device_find_all(devices.as_mut_ptr(), &mut device_count as *mut u32, std::ptr::null_mut());
if res.0 != _icsneo_error_t::icsneo_error_success as u32 {
return;
}
println!("Found {} devices", device_count);
for i in 0..device_count as usize {
let device = devices[i];
let res = icsneo_device_is_valid(device);
if res.0 != _icsneo_error_t::icsneo_error_success as u32 {
return;
}
let mut description_length: u32 = 255;
let mut description: [::core::ffi::c_char; 255] = [0i8; 255];
let res = icsneo_device_get_description(device, description.as_mut_ptr(), &mut description_length);
if res.0 != _icsneo_error_t::icsneo_error_success as u32 {
return;
}
let description_str = std::ffi::CStr::from_ptr(description.as_ptr()).to_str().unwrap().to_string();
println!("\t{}: {}", i, description_str);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
unsafe { find_devices(); }
}
}

View File

@ -100,7 +100,7 @@ bool Communication::sendCommand(ExtendedCommand cmd, std::vector<uint8_t> argume
}
bool Communication::getSettingsSync(std::vector<uint8_t>& data, std::chrono::milliseconds timeout) {
static const std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(Network::NetID::ReadSettings);
static const std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_read_settings);
std::shared_ptr<Message> msg = waitForMessageSync([this]() {
return sendCommand(Command::ReadSettings, { 0, 0, 0, 1 /* Get Global Settings */, 0, 1 /* Subversion 1 */ });
}, filter, timeout);

View File

@ -54,7 +54,7 @@ uint64_t Decoder::GetUInt64FromLEBytes(const uint8_t* bytes) {
bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Packet>& packet) {
switch(packet->network.getType()) {
case Network::Type::Ethernet: {
case icsneo_msg_bus_type_ethernet: {
result = HardwareEthernetPacket::DecodeToMessage(packet->data, report);
if(!result) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
@ -68,9 +68,9 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
eth.network = packet->network;
return true;
}
case Network::Type::CAN:
case Network::Type::SWCAN:
case Network::Type::LSFTCAN: {
case icsneo_msg_bus_type_can:
case icsneo_msg_bus_type_swcan:
case icsneo_msg_bus_type_lsftcan: {
if(packet->data.size() < 24) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
return false;
@ -87,7 +87,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
result->timestamp *= timestampResolution;
switch(result->type) {
case Message::Type::Frame: {
case Message::Type::BusMessage: {
CANMessage& can = *static_cast<CANMessage*>(result.get());
can.network = packet->network;
break;
@ -105,7 +105,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
return true;
}
case Network::Type::FlexRay: {
case icsneo_msg_bus_type_flexray: {
if(packet->data.size() < 24) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
return false;
@ -124,7 +124,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
fr.network = packet->network;
return true;
}
case Network::Type::ISO9141: {
case icsneo_msg_bus_type_iso9141: {
if(packet->data.size() < sizeof(HardwareISO9141Packet)) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
return false;
@ -141,7 +141,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
iso.network = packet->network;
return true;
}
case Network::Type::I2C: {
case icsneo_msg_bus_type_i2c: {
if(packet->data.size() < sizeof(HardwareI2CPacket)) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
return false;
@ -155,7 +155,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
return true;
}
case Network::Type::A2B: {
case icsneo_msg_bus_type_a2b: {
result = HardwareA2BPacket::DecodeToMessage(packet->data);
if(!result) {
@ -168,7 +168,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
msg.timestamp *= timestampResolution;
return true;
}
case Network::Type::LIN: {
case icsneo_msg_bus_type_lin: {
result = HardwareLINPacket::DecodeToMessage(packet->data);
if(!result) {
@ -180,7 +180,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
msg.network = packet->network;
return true;
}
case Network::Type::MDIO: {
case icsneo_msg_bus_type_mdio: {
result = HardwareMDIOPacket::DecodeToMessage(packet->data);
if(!result) {
@ -192,9 +192,9 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
msg.network = packet->network;
return true;
}
case Network::Type::Internal: {
case icsneo_msg_bus_type_internal: {
switch(packet->network.getNetID()) {
case Network::NetID::Reset_Status: {
case _icsneo_netid_t::icsneo_netid_reset_status: {
// We can deal with not having the last two fields (voltage and temperature)
if(packet->data.size() < (sizeof(HardwareResetStatusPacket) - (sizeof(uint16_t) * 2))) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
@ -225,12 +225,12 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
result = msg;
return true;
}
case Network::NetID::Device: {
case _icsneo_netid_t::icsneo_netid_device: {
// These are neoVI network messages
// They come in as CAN but we will handle them in the device rather than
// passing them onto the user.
if(packet->data.size() < 24) {
auto rawmsg = std::make_shared<RawMessage>(Network::NetID::Device);
auto rawmsg = std::make_shared<InternalMessage>(_icsneo_netid_t::icsneo_netid_device);
result = rawmsg;
rawmsg->data = packet->data;
return true;
@ -244,7 +244,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
// Timestamps are in (resolution) ns increments since 1/1/2007 GMT 00:00:00.0000
// The resolution depends on the device
auto* raw = dynamic_cast<RawMessage*>(result.get());
auto* raw = dynamic_cast<InternalMessage*>(result.get());
if(raw == nullptr) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
return false; // A nullptr was returned, the packet was malformed
@ -253,12 +253,12 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
raw->network = packet->network;
return true;
}
case Network::NetID::DeviceStatus: {
case _icsneo_netid_t::icsneo_netid_device_status: {
// Just pass along the data, the device needs to handle this itself
result = std::make_shared<RawMessage>(packet->network, packet->data);
result = std::make_shared<InternalMessage>(packet->network, packet->data);
return true;
}
case Network::NetID::RED_INT_MEMORYREAD: {
case _icsneo_netid_t::icsneo_netid_red_int_memoryread: {
if(packet->data.size() != 512 + sizeof(uint16_t)) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
return false; // Should get enough data for a start address and sector
@ -270,7 +270,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
msg->data.insert(msg->data.end(), packet->data.begin() + 2, packet->data.end());
return true;
}
case Network::NetID::NeoMemorySDRead: {
case _icsneo_netid_t::icsneo_netid_neo_memory_sdread: {
if(packet->data.size() != 512 + sizeof(uint32_t)) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
return false; // Should get enough data for a start address and sector
@ -282,7 +282,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
msg->data.insert(msg->data.end(), packet->data.begin() + 4, packet->data.end());
return true;
}
case Network::NetID::ExtendedCommand: {
case _icsneo_netid_t::icsneo_netid_extended_command: {
if(packet->data.size() < sizeof(ExtendedResponseMessage::PackedGenericResponse))
break; // Handle as a raw message, might not be a generic response
@ -308,12 +308,12 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
result = TC10StatusMessage::DecodeToMessage(packet->data);
return true;
default:
// No defined handler, treat this as a RawMessage
// No defined handler, treat this as a InternalMessage
break;
}
break;
}
case Network::NetID::ExtendedData: {
case _icsneo_netid_t::icsneo_netid_extended_data: {
if(packet->data.size() < sizeof(ExtendedDataMessage::ExtendedDataHeader))
break;
const auto& header = *reinterpret_cast<ExtendedDataMessage::ExtendedDataHeader*>(packet->data.data());
@ -328,7 +328,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
std::copy(packet->data.begin() + sizeof(header), packet->data.begin() + sizeof(header) + numRead, extDataMsg->data.begin());
extDataMsg->network = Network(static_cast<uint16_t>(Network::NetID::ExtendedData), false);
extDataMsg->network = Network(static_cast<uint16_t>(_icsneo_netid_t::icsneo_netid_extended_data), false);
return true;
}
default:
@ -336,7 +336,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
}
break;
}
case Network::NetID::FlexRayControl: {
case _icsneo_netid_t::icsneo_netid_flexray_control: {
auto frResult = std::make_shared<FlexRayControlMessage>(*packet);
if(!frResult->decoded) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
@ -345,7 +345,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
result = frResult;
return true;
}
case Network::NetID::Main51: {
case _icsneo_netid_t::icsneo_netid_main51: {
switch((Command)packet->data[0]) {
case Command::RequestSerialNumber: {
auto msg = std::make_shared<SerialNumberMessage>();
@ -397,7 +397,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
return true;
}
}
case Network::NetID::RED_OLDFORMAT: {
case _icsneo_netid_t::icsneo_netid_red_oldformat: {
/* So-called "old format" messages are a "new style, long format" wrapper around the old short messages.
* They consist of a 16-bit LE length first, then the 8-bit length and netid combo byte, then the payload
* with no checksum. The upper-nibble length of the combo byte should be ignored completely, using the
@ -412,7 +412,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
packet->data.resize(length);
return decode(result, packet);
}
case Network::NetID::RED_App_Error: {
case _icsneo_netid_t::icsneo_netid_red_app_error: {
result = AppErrorMessage::DecodeToMessage(packet->data, report);
if(!result) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::EventWarning);
@ -420,7 +420,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
}
return true;
}
case Network::NetID::ReadSettings: {
case _icsneo_netid_t::icsneo_netid_read_settings: {
auto msg = std::make_shared<ReadSettingsMessage>();
msg->response = ReadSettingsMessage::Response(packet->data[0]);
@ -439,7 +439,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
result = msg;
return true;
}
case Network::NetID::LogicalDiskInfo: {
case _icsneo_netid_t::icsneo_netid_logical_disk_info: {
result = LogicalDiskInfoPacket::DecodeToMessage(packet->data);
if(!result) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::EventWarning);
@ -447,7 +447,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
}
return true;
}
case Network::NetID::WiVICommand: {
case _icsneo_netid_t::icsneo_netid_wivi_command: {
result = WiVI::CommandPacket::DecodeToMessage(packet->data);
if(!result) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::EventWarning);
@ -455,7 +455,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
}
return true;
}
case Network::NetID::EthPHYControl: {
case _icsneo_netid_t::icsneo_netid_eth_phy_control: {
result = HardwareEthernetPhyRegisterPacket::DecodeToMessage(packet->data, report);
if(!result) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::EventWarning);
@ -463,7 +463,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
}
return true;
}
case Network::NetID::ScriptStatus: {
case _icsneo_netid_t::icsneo_netid_script_status: {
result = ScriptStatus::DecodeToMessage(packet->data);
if(!result) {
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::EventWarning);
@ -471,7 +471,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
}
return true;
}
case Network::NetID::DiskData: {
case _icsneo_netid_t::icsneo_netid_disk_data: {
result = std::make_shared<DiskDataMessage>(std::move(packet->data));
return true;
}
@ -483,6 +483,6 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
}
// For the moment other types of messages will automatically be decoded as raw messages
result = std::make_shared<RawMessage>(packet->network, packet->data);
result = std::make_shared<InternalMessage>(packet->network, packet->data);
return true;
}

View File

@ -23,15 +23,15 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
result.clear();
switch(message->type) {
case Message::Type::Frame: {
auto frame = std::dynamic_pointer_cast<Frame>(message);
case Message::Type::BusMessage: {
auto frame = std::dynamic_pointer_cast<BusMessage>(message);
// Frame uses frame->data as the buffer unless directed otherwise
// BusMessage uses frame->data as the buffer unless directed otherwise
buffer = &frame->data;
netid = uint16_t(frame->network.getNetID());
switch(frame->network.getType()) {
case Network::Type::Ethernet: {
case icsneo_msg_bus_type_ethernet: {
auto ethmsg = std::dynamic_pointer_cast<EthernetMessage>(message);
if(!ethmsg) {
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
@ -43,10 +43,10 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
return false;
break;
} // End of Network::Type::Ethernet
case Network::Type::CAN:
case Network::Type::SWCAN:
case Network::Type::LSFTCAN: {
} // End of icsneo_msg_bus_type_ethernet
case icsneo_msg_bus_type_can:
case icsneo_msg_bus_type_swcan:
case icsneo_msg_bus_type_lsftcan: {
auto canmsg = std::dynamic_pointer_cast<CANMessage>(message);
if(!canmsg) {
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
@ -63,8 +63,8 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
return false; // The CANMessage was malformed
break;
} // End of Network::Type::CAN
case Network::Type::ISO9141: {
} // End of icsneo_msg_bus_type_can
case icsneo_msg_bus_type_iso9141: {
auto isomsg = std::dynamic_pointer_cast<ISO9141Message>(message);
if(!isomsg) {
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
@ -74,8 +74,8 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
// Skip the normal message wrapping at the bottom since we need to send multiple
// packets to the device. This function just encodes them back to back into `result`
return HardwareISO9141Packet::EncodeFromMessage(*isomsg, result, report, packetizer);
} // End of Network::Type::ISO9141
case Network::Type::A2B: {
} // End of icsneo_msg_bus_type_iso9141
case icsneo_msg_bus_type_a2b: {
auto a2bmsg = std::dynamic_pointer_cast<A2BMessage>(message);
if(!a2bmsg) {
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
@ -86,8 +86,8 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
return false;
}
break;
} // End of Network::Type::A2B
case Network::Type::I2C: {
} // End of icsneo_msg_bus_type_a2b
case icsneo_msg_bus_type_i2c: {
auto i2cmsg = std::dynamic_pointer_cast<I2CMessage>(message);
if(!i2cmsg) {
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
@ -98,8 +98,8 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
return false;
}
break;
} // End of Network::Type::I2C
case Network::Type::LIN: {
} // End of icsneo_msg_bus_type_i2c
case icsneo_msg_bus_type_lin: {
auto linmsg = std::dynamic_pointer_cast<LINMessage>(message);
if(!linmsg) {
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
@ -110,8 +110,8 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
return false;
}
break;
} // End of Network::Type::LIN
case Network::Type::MDIO: {
} // End of icsneo_msg_bus_type_lin
case icsneo_msg_bus_type_mdio: {
auto mdiomsg = std::dynamic_pointer_cast<MDIOMessage>(message);
if(!mdiomsg) {
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
@ -122,7 +122,7 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
return false;
}
break;
} // End of Network::Type::MDIO
} // End of icsneo_msg_bus_type_mdio
default:
report(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error);
return false;
@ -130,18 +130,18 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
break;
}
case Message::Type::RawMessage: {
auto raw = std::dynamic_pointer_cast<RawMessage>(message);
case Message::Type::InternalMessage: {
auto raw = std::dynamic_pointer_cast<InternalMessage>(message);
// Raw message uses raw->data as the buffer unless directed otherwise
buffer = &raw->data;
netid = uint16_t(raw->network.getNetID());
switch(raw->network.getNetID()) {
case Network::NetID::Device:
case _icsneo_netid_t::icsneo_netid_device:
shortFormat = true;
break;
case Network::NetID::RED_OLDFORMAT: {
case _icsneo_netid_t::icsneo_netid_red_oldformat: {
// See the decoder for an explanation
// We expect the network byte to be populated already in data, but not the length
uint16_t length = uint16_t(raw->data.size()) - 1;
@ -162,7 +162,7 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
}
buffer = &m51msg->data;
netid = uint16_t(Network::NetID::Main51);
netid = uint16_t(_icsneo_netid_t::icsneo_netid_main51);
if(!m51msg->forceShortFormat) {
// Main51 can be sent as a long message without setting the NetID to RED first
@ -172,7 +172,7 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
size += 1; // Even though we are not including the NetID bytes, the device expects them to be counted in the length
size += 1; // Main51 Command
m51msg->data.insert(m51msg->data.begin(), {
(uint8_t)Network::NetID::Main51, // 0x0B for long message
(uint8_t)_icsneo_netid_t::icsneo_netid_main51, // 0x0B for long message
(uint8_t)size, // Size, little endian 16-bit
(uint8_t)(size >> 8),
(uint8_t)m51msg->command
@ -223,7 +223,7 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
uint16_t size = static_cast<uint16_t>(buffer->size()) + 1 + 1 + 2 + 2 + 1;
buffer->insert(buffer->begin(), {
(uint8_t)Network::NetID::RED, // 0x0C for long message
(uint8_t)_icsneo_netid_t::icsneo_netid_red, // 0x0C for long message
(uint8_t)size, // Size, little endian 16-bit
(uint8_t)(size >> 8),
(uint8_t)netid, // NetID, little endian 16-bit
@ -238,12 +238,12 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result, Command cmd, std::vector<uint8_t> arguments) {
std::shared_ptr<Message> msg;
if(cmd == Command::UpdateLEDState) {
/* NetID::Device is a super old command type.
/* _icsneo_netid_t::Device is a super old command type.
* It has a leading 0x00 byte, a byte for command, and a byte for an argument.
* In this case, command 0x06 is SetLEDState.
* This old command type is not really used anywhere else.
*/
auto canmsg = std::make_shared<RawMessage>(Network::NetID::Device);
auto canmsg = std::make_shared<InternalMessage>(_icsneo_netid_t::icsneo_netid_device);
msg = canmsg;
if(arguments.empty()) {
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);

View File

@ -21,10 +21,10 @@ std::shared_ptr<Message> AppErrorMessage::DecodeToMessage(const std::vector<uint
}
auto appErr = std::make_shared<AppErrorMessage>();
appErr->errorType = data->error_type;
appErr->errorNetID = static_cast<Network::NetID>(data->network_id);
appErr->errorNetID = static_cast<_icsneo_netid_t>(data->network_id);
appErr->timestamp10us = data->uiTimeStamp10uS;
appErr->timestamp10usMSB = data->uiTimeStamp10uSMSB;
appErr->network = Network::NetID::RED_App_Error;
appErr->network = _icsneo_netid_t::icsneo_netid_red_app_error;
return appErr;
}

View File

@ -102,17 +102,17 @@ bool A2BWAVOutput::callIfMatch(const std::shared_ptr<Message>& message) const {
return false;
}
if(message->type != Message::Type::Frame) {
if(message->type != Message::Type::BusMessage) {
return false;
}
const auto& frameMsg = std::dynamic_pointer_cast<Frame>(message);
const auto& frameMsg = std::dynamic_pointer_cast<BusMessage>(message);
if(!frameMsg) {
return false;
}
if(frameMsg->network.getType() != Network::Type::A2B)
if(frameMsg->network.getType() != icsneo_msg_bus_type_a2b)
return false;
const auto& a2bMsg = std::dynamic_pointer_cast<A2BMessage>(frameMsg);

View File

@ -14,13 +14,13 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
neomsg.timestamp = message->timestamp;
switch (message->type)
{
case Message::Type::Frame: {
case Message::Type::BusMessage: {
neomessage_frame_t& frame = *(neomessage_frame_t*)&neomsg;
auto framemsg = std::static_pointer_cast<Frame>(message);
auto framemsg = std::static_pointer_cast<BusMessage>(message);
const auto netType = framemsg->network.getType();
frame.netid = (neonetid_t)framemsg->network.getNetID();
frame.type = (neonettype_t)netType;
frame.netid = (icsneo_netid_t)framemsg->network.getNetID();
frame.type = (icsneo_msg_bus_type_t)netType;
frame.description = framemsg->description;
frame.length = framemsg->data.size();
frame.data = framemsg->data.data();
@ -29,9 +29,9 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
frame.status.transmitMessage = framemsg->transmitted;
switch(netType) {
case Network::Type::CAN:
case Network::Type::SWCAN:
case Network::Type::LSFTCAN: {
case icsneo_msg_bus_type_can:
case icsneo_msg_bus_type_swcan:
case icsneo_msg_bus_type_lsftcan: {
neomessage_can_t& can = *(neomessage_can_t*)&neomsg;
auto canmsg = std::static_pointer_cast<CANMessage>(message);
can.arbid = canmsg->arbid;
@ -44,7 +44,7 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
can.status.canfdESI = canmsg->errorStateIndicator;
break;
}
case Network::Type::Ethernet: {
case icsneo_msg_bus_type_ethernet: {
neomessage_eth_t& eth = *(neomessage_eth_t*)&neomsg;
auto ethmsg = std::static_pointer_cast<EthernetMessage>(message);
eth.preemptionFlags = ethmsg->preemptionFlags;
@ -55,7 +55,7 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
//eth.status.xyz = ethmsg->noPadding;
break;
}
case Network::Type::LIN: {
case icsneo_msg_bus_type_lin: {
neomessage_lin_t& lin = *(neomessage_lin_t*)&neomsg;
auto linmsg = std::static_pointer_cast<LINMessage>(message);
if(!linmsg) { break; }
@ -108,8 +108,8 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
canerror.transmitErrorCount = canerrormsg->transmitErrorCount;
canerror.receiveErrorCount = canerrormsg->receiveErrorCount;
canerror.status.canBusOff = canerrormsg->busOff;
canerror.netid = (neonetid_t)canerrormsg->network.getNetID();
canerror.type = (neonettype_t)canerrormsg->network.getType();
canerror.netid = (icsneo_netid_t)canerrormsg->network.getNetID();
canerror.type = (icsneo_msg_bus_type_t)canerrormsg->network.getType();
break;
}
default:
@ -120,12 +120,12 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
std::shared_ptr<Message> icsneo::CreateMessageFromNeoMessage(const neomessage_t* neomessage) {
switch((Message::Type)neomessage->messageType) {
case Message::Type::Frame: {
case Message::Type::BusMessage: {
const Network network = ((neomessage_frame_t*)neomessage)->netid;
switch(network.getType()) {
case Network::Type::CAN:
case Network::Type::SWCAN:
case Network::Type::LSFTCAN: {
case icsneo_msg_bus_type_can:
case icsneo_msg_bus_type_swcan:
case icsneo_msg_bus_type_lsftcan: {
neomessage_can_t& can = *(neomessage_can_t*)neomessage;
auto canmsg = std::make_shared<CANMessage>();
canmsg->network = network;
@ -140,7 +140,7 @@ std::shared_ptr<Message> icsneo::CreateMessageFromNeoMessage(const neomessage_t*
canmsg->errorStateIndicator = can.status.canfdESI;
return canmsg;
}
case Network::Type::Ethernet: {
case icsneo_msg_bus_type_ethernet: {
neomessage_eth_t& eth = *(neomessage_eth_t*)neomessage;
auto ethmsg = std::make_shared<EthernetMessage>();
ethmsg->network = network;
@ -148,7 +148,7 @@ std::shared_ptr<Message> icsneo::CreateMessageFromNeoMessage(const neomessage_t*
ethmsg->data.insert(ethmsg->data.end(), eth.data, eth.data + eth.length);
return ethmsg;
}
case Network::Type::LIN: {
case icsneo_msg_bus_type_lin: {
neomessage_lin_t& lin = *(neomessage_lin_t*)neomessage;
auto linmsg = std::make_shared<LINMessage>();
linmsg->network = network;

View File

@ -3,7 +3,7 @@
using namespace icsneo;
static std::optional<uint8_t> CAN_DLCToLength(uint8_t length, bool fd) {
std::optional<uint8_t> icsneo::CAN_DLCToLength(uint8_t length, bool fd) {
if (length <= 8)
return length;
@ -29,8 +29,7 @@ static std::optional<uint8_t> CAN_DLCToLength(uint8_t length, bool fd) {
return std::nullopt;
}
static std::optional<uint8_t> CAN_LengthToDLC(size_t dataLength, bool fd)
{
std::optional<uint8_t> icsneo::CAN_LengthToDLC(size_t dataLength, bool fd) {
if (dataLength <= 8)
return uint8_t(dataLength);
@ -69,7 +68,7 @@ std::shared_ptr<Message> HardwareCANPacket::DecodeToMessage(const std::vector<ui
return msg;
} else { // CAN Frame
} else { // CAN BusMessage
auto msg = std::make_shared<CANMessage>();
// Arb ID
@ -104,7 +103,7 @@ std::shared_ptr<Message> HardwareCANPacket::DecodeToMessage(const std::vector<ui
// Data
// The first 8 bytes are always in the standard place
if((data->dlc.RTR && data->header.IDE) || (!data->header.IDE && data->header.SRR)) { // Remote Request Frame
if((data->dlc.RTR && data->header.IDE) || (!data->header.IDE && data->header.SRR)) { // Remote Request BusMessage
msg->data.resize(length); // This data will be all zeros, but the length will be set
msg->isRemote = true;
} else {
@ -197,7 +196,7 @@ bool HardwareCANPacket::EncodeFromMessage(const CANMessage& message, std::vector
// Status and DLC bits
if(message.isCANFD) {
result.push_back(0x0F); // FD Frame
result.push_back(0x0F); // FD BusMessage
uint8_t fdStatusByte = *dlc;
if(message.baudrateSwitch)
fdStatusByte |= 0x80; // BRS status bit

View File

@ -30,10 +30,10 @@ bool HardwareISO9141Packet::EncodeFromMessage(const ISO9141Message& message, std
currentSize = (uint8_t)(bytesToSend - currentStart);
packet.insert(packet.begin(), {
(uint8_t)Network::NetID::RED, // 0x0C for long message
(uint8_t)_icsneo_netid_t::icsneo_netid_red, // 0x0C for long message
(uint8_t)0, // Size, little endian 16-bit, filled later
(uint8_t)0,
(uint8_t)message.network.getNetID(), // NetID, little endian 16-bit
(uint8_t)message.network.getNetID(), // _icsneo_netid_t, little endian 16-bit
(uint8_t)(uint16_t(message.network.getNetID()) >> 8)
});
packet.push_back(uint8_t(message.network.getNetID()) + uint8_t((currentSize + (firstPacket ? 6 : 3)) << 4));

View File

@ -113,7 +113,7 @@ bool HardwareLiveDataPacket::EncodeFromMessage(LiveDataMessage& message, std::ve
return false;
}
header->netid = static_cast<uint8_t>(Network::NetID::Main51);
header->netid = static_cast<uint8_t>(_icsneo_netid_t::icsneo_netid_main51);
header->fullLength = fullSize;
header->command = static_cast<uint8_t>(Command::Extended);
header->extendedCommand = static_cast<uint16_t>(ExtendedCommand::LiveData);

View File

@ -54,7 +54,7 @@ bool Packetizer::input(RingBuffer& bytes) {
if(packetLength == 0) {
state = ReadState::ParseLongStylePacketHeader;
break;
} else if(packetLength == 0xA && packet.network == Network::NetID::DiskData) {
} else if(packetLength == 0xA && packet.network == _icsneo_netid_t::icsneo_netid_disk_data) {
state = ReadState::ParseDiskDataHeader;
break;
}
@ -159,7 +159,7 @@ bool Packetizer::input(RingBuffer& bytes) {
processedPackets.push_back(std::make_shared<Packet>(packet));
bytes.pop(packetLength);
if(packet.network == Network::NetID::DiskData && (packetLength - headerSize) % 2 == 0) {
if(packet.network == _icsneo_netid_t::icsneo_netid_disk_data && (packetLength - headerSize) % 2 == 0) {
bytes.pop_front();
}
} else {

View File

@ -389,7 +389,7 @@ bool Device::goOnline() {
updateLEDState();
std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(Network::NetID::Reset_Status);
std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_reset_status);
filter->includeInternalInAny = true;
// Wait until communication is enabled or 5 seconds, whichever comes first
@ -432,7 +432,7 @@ bool Device::goOffline() {
updateLEDState();
std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(Network::NetID::Reset_Status);
std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_reset_status);
filter->includeInternalInAny = true;
// Wait until communication is disabled or 5 seconds, whichever comes first
@ -457,7 +457,7 @@ int8_t Device::prepareScriptLoad() {
return false;
}
static std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(Network::NetID::CoreMiniPreLoad);
static std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_coremini_preload);
if(!com->sendCommand(Command::CoreMiniPreload))
return false;
@ -472,7 +472,7 @@ int8_t Device::prepareScriptLoad() {
return false;
}
const auto resp = std::static_pointer_cast<RawMessage>(generic);
const auto resp = std::static_pointer_cast<InternalMessage>(generic);
retVal = (int8_t)resp->data[0];
}
@ -488,7 +488,7 @@ bool Device::startScript(Disk::MemoryType memType)
uint8_t location = static_cast<uint8_t>(memType);
std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(Network::NetID::Device);
std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_device);
filter->includeInternalInAny = true;
const auto response = com->waitForMessageSync([&]() {
@ -510,7 +510,7 @@ bool Device::stopScript()
return false;
}
std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(Network::NetID::Device);
std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_device);
filter->includeInternalInAny = true;
const auto response = com->waitForMessageSync([&]() {
@ -597,7 +597,7 @@ bool Device::uploadCoremini(std::istream& stream, Disk::MemoryType memType) {
}
bool Device::eraseScriptMemory(Disk::MemoryType memType, uint64_t amount) {
static std::shared_ptr<MessageFilter> NeoEraseDone = std::make_shared<MessageFilter>(Network::NetID::NeoMemoryWriteDone);
static std::shared_ptr<MessageFilter> NeoEraseDone = std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_neo_memory_write_done);
if(!supportsEraseMemory()) {
return true;
@ -735,7 +735,7 @@ std::optional<CoreminiHeader> Device::readCoreminiHeader(Disk::MemoryType memTyp
return ret;
}
bool Device::transmit(std::shared_ptr<Frame> frame) {
bool Device::transmit(std::shared_ptr<BusMessage> frame) {
if(!isOpen()) {
report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error);
return false;
@ -768,7 +768,7 @@ bool Device::transmit(std::shared_ptr<Frame> frame) {
return com->sendPacket(packet);
}
bool Device::transmit(std::vector<std::shared_ptr<Frame>> frames) {
bool Device::transmit(std::vector<std::shared_ptr<BusMessage>> frames) {
for(auto& frame : frames) {
if(!transmit(frame))
return false;
@ -780,7 +780,7 @@ void Device::setWriteBlocks(bool blocks) {
com->setWriteBlocks(blocks);
}
size_t Device::getNetworkCountByType(Network::Type type) const {
size_t Device::getNetworkCountByType(icsneo_msg_bus_type_t type) const {
size_t count = 0;
for(const auto& net : getSupportedRXNetworks())
if(net.getType() == type)
@ -789,7 +789,7 @@ size_t Device::getNetworkCountByType(Network::Type type) const {
}
// Indexed starting at one
Network Device::getNetworkByNumber(Network::Type type, size_t index) const {
Network Device::getNetworkByNumber(icsneo_msg_bus_type_t type, size_t index) const {
size_t count = 0;
for(const auto& net : getSupportedRXNetworks()) {
if(net.getType() == type) {
@ -798,7 +798,7 @@ Network Device::getNetworkByNumber(Network::Type type, size_t index) const {
return net;
}
}
return Network::NetID::Invalid;
return _icsneo_netid_t::icsneo_netid_invalid;
}
std::shared_ptr<HardwareInfo> Device::getHardwareInfo(std::chrono::milliseconds timeout) {
@ -1718,11 +1718,11 @@ void Device::handleInternalMessage(std::shared_ptr<Message> message) {
case Message::Type::ResetStatus:
latestResetStatus = std::static_pointer_cast<ResetStatusMessage>(message);
break;
case Message::Type::RawMessage: {
auto rawMessage = std::static_pointer_cast<RawMessage>(message);
case Message::Type::InternalMessage: {
auto rawMessage = std::static_pointer_cast<InternalMessage>(message);
switch(rawMessage->network.getNetID()) {
case Network::NetID::Device: {
// Device is not guaranteed to be a CANMessage, it might be a RawMessage
case _icsneo_netid_t::icsneo_netid_device: {
// Device is not guaranteed to be a CANMessage, it might be a InternalMessage
// if it couldn't be decoded to a CANMessage. We only care about the
// CANMessage decoding right now.
auto canmsg = std::dynamic_pointer_cast<CANMessage>(message);
@ -1730,7 +1730,7 @@ void Device::handleInternalMessage(std::shared_ptr<Message> message) {
handleNeoVIMessage(std::move(canmsg));
break;
}
case Network::NetID::DeviceStatus:
case _icsneo_netid_t::icsneo_netid_device_status:
// Device Status format is unique per device, so the devices need to decode it themselves
handleDeviceStatus(rawMessage);
break;
@ -1817,7 +1817,7 @@ std::optional<EthPhyMessage> Device::sendEthPhyMsg(const EthPhyMessage& message,
HardwareEthernetPhyRegisterPacket::EncodeFromMessage(message, bytes, report);
std::shared_ptr<Message> response = com->waitForMessageSync(
[this, bytes](){ return com->sendCommand(Command::PHYControlRegisters, bytes); },
std::make_shared<MessageFilter>(Network::NetID::EthPHYControl), timeout);
std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_eth_phy_control), timeout);
if(!response) {
report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error);
@ -1888,14 +1888,14 @@ std::optional<bool> Device::SetRootDirectoryEntryFlags(uint8_t mask, uint8_t val
std::optional<std::chrono::time_point<std::chrono::system_clock>> Device::getRTC()
{
static const std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(Network::NetID::RED_GET_RTC);
static const std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_red_get_rtc);
std::shared_ptr<Message> generic = com->waitForMessageSync([this]() {
return com->sendCommand(Command::GetRTC);
}, filter, std::chrono::milliseconds(3000));
if(!generic) // Did not receive a message
return std::nullopt;
auto rawMes = std::dynamic_pointer_cast<RawMessage>(generic);
auto rawMes = std::dynamic_pointer_cast<InternalMessage>(generic);
if(!rawMes)
return std::nullopt;
@ -2023,7 +2023,7 @@ bool Device::readBinaryFile(std::ostream& stream, uint16_t binaryIndex) {
std::vector<uint8_t> arguments(sizeof(ExtendedDataMessage::ExtendedDataHeader));
ExtendedDataMessage::ExtendedDataHeader& parameters = *reinterpret_cast<ExtendedDataMessage::ExtendedDataHeader*>(arguments.data());
auto filter = std::make_shared<MessageFilter>(Network::NetID::ExtendedData);
auto filter = std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_extended_data);
for(size_t offset = 0; offset < *size; offset+=ExtendedDataMessage::MaxExtendedDataBufferSize) {
parameters.subCommand = ExtendedDataSubCommand::GenericBinaryRead;
@ -3260,13 +3260,13 @@ std::optional<uint64_t> Device::getVSADiskSize() {
return diskSize;
}
bool Device::requestTC10Wake(Network::NetID network) {
bool Device::requestTC10Wake(_icsneo_netid_t network) {
if(!supportsTC10()) {
report(APIEvent::Type::NotSupported, APIEvent::Severity::Error);
return false;
}
std::vector<uint8_t> args(sizeof(network));
*(Network::NetID*)args.data() = network;
*(_icsneo_netid_t*)args.data() = network;
auto msg = com->waitForMessageSync([&] {
return com->sendCommand(ExtendedCommand::RequestTC10Wake, args);
}, std::make_shared<MessageFilter>(Message::Type::ExtendedResponse), std::chrono::milliseconds(1000));
@ -3285,13 +3285,13 @@ bool Device::requestTC10Wake(Network::NetID network) {
return resp->response == ExtendedResponse::OK;
}
bool Device::requestTC10Sleep(Network::NetID network) {
bool Device::requestTC10Sleep(_icsneo_netid_t network) {
if(!supportsTC10()) {
report(APIEvent::Type::NotSupported, APIEvent::Severity::Error);
return false;
}
std::vector<uint8_t> args(sizeof(network));
*(Network::NetID*)args.data() = network;
*(_icsneo_netid_t*)args.data() = network;
auto msg = com->waitForMessageSync([&] {
return com->sendCommand(ExtendedCommand::RequestTC10Sleep, args);
}, std::make_shared<MessageFilter>(Message::Type::ExtendedResponse), std::chrono::milliseconds(1000));
@ -3310,13 +3310,13 @@ bool Device::requestTC10Sleep(Network::NetID network) {
return typed->response == ExtendedResponse::OK;
}
std::optional<TC10StatusMessage> Device::getTC10Status(Network::NetID network) {
std::optional<TC10StatusMessage> Device::getTC10Status(_icsneo_netid_t network) {
if(!supportsTC10()) {
report(APIEvent::Type::NotSupported, APIEvent::Severity::Error);
return std::nullopt;
}
std::vector<uint8_t> args(sizeof(network));
*(Network::NetID*)args.data() = network;
*(_icsneo_netid_t*)args.data() = network;
auto msg = com->waitForMessageSync([&] {
return com->sendCommand(ExtendedCommand::GetTC10Status, args);
}, std::make_shared<MessageFilter>(Message::Type::TC10Status), std::chrono::milliseconds(1000));

View File

@ -1,5 +1,6 @@
#include "icsneo/device/extensions/flexray/controller.h"
#include "icsneo/device/device.h"
#include "icsneo/icsneotypes.h"
using namespace icsneo;
@ -610,7 +611,7 @@ uint16_t FlexRay::Controller::CalculateCycleFilter(uint8_t baseCycle, uint8_t cy
}
std::pair<bool, uint32_t> FlexRay::Controller::readRegister(ERAYRegister reg, std::chrono::milliseconds timeout) const {
static const std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(icsneo::Network::NetID::FlexRayControl);
static const std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_flexray_control);
if(timeout.count() <= 20)
return {false, 0}; // Out of time!

View File

@ -2,6 +2,9 @@
#include "icsneo/device/device.h"
#include "icsneo/communication/message/flexray/flexraymessage.h"
#include <chrono>
#include <memory>
using namespace icsneo;
FlexRay::Extension::Extension(Device& device, const std::vector<Network>& controllerNetworks) : DeviceExtension(device) {
@ -45,8 +48,8 @@ void FlexRay::Extension::handleMessage(const std::shared_ptr<Message>& message)
}
}
bool FlexRay::Extension::transmitHook(const std::shared_ptr<Frame>& frame, bool& success) {
if(!frame || frame->network.getType() != Network::Type::FlexRay)
bool FlexRay::Extension::transmitHook(const std::shared_ptr<BusMessage>& frame, bool& success) {
if(!frame || frame->network.getType() != icsneo_msg_bus_type_flexray)
return true; // Don't hook non-FlexRay messages
success = false;

View File

@ -403,7 +403,7 @@ int64_t IDeviceSettings::getBaudrateFor(Network net) const {
}
switch(net.getType()) {
case Network::Type::CAN: {
case icsneo_msg_bus_type_can: {
const CAN_SETTINGS* cfg = getCANSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::CANSettingsNotAvailable, APIEvent::Severity::Error);
@ -417,7 +417,7 @@ int64_t IDeviceSettings::getBaudrateFor(Network net) const {
}
return baudrate;
}
case Network::Type::SWCAN: {
case icsneo_msg_bus_type_swcan: {
const SWCAN_SETTINGS* cfg = getSWCANSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::SWCANSettingsNotAvailable, APIEvent::Severity::Error);
@ -431,7 +431,7 @@ int64_t IDeviceSettings::getBaudrateFor(Network net) const {
}
return baudrate;
}
case Network::Type::LSFTCAN: {
case icsneo_msg_bus_type_lsftcan: {
const CAN_SETTINGS* cfg = getLSFTCANSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::LSFTCANSettingsNotAvailable, APIEvent::Severity::Error);
@ -445,7 +445,7 @@ int64_t IDeviceSettings::getBaudrateFor(Network net) const {
}
return baudrate;
}
case Network::Type::LIN: {
case icsneo_msg_bus_type_lin: {
const LIN_SETTINGS* cfg = getLINSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
@ -477,7 +477,7 @@ bool IDeviceSettings::setBaudrateFor(Network net, int64_t baudrate) {
}
switch(net.getType()) {
case Network::Type::CAN: {
case icsneo_msg_bus_type_can: {
if(baudrate > 1000000) { // This is an FD baudrate. Use setFDBaudrateFor instead.
report(APIEvent::Type::CANFDSettingsNotAvailable, APIEvent::Severity::Error);
return false;
@ -499,7 +499,7 @@ bool IDeviceSettings::setBaudrateFor(Network net, int64_t baudrate) {
cfg->SetBaudrate = AUTO; // Device will use the baudrate value to set the TQ values
return true;
}
case Network::Type::LSFTCAN: {
case icsneo_msg_bus_type_lsftcan: {
CAN_SETTINGS* cfg = getMutableLSFTCANSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::LSFTCANSettingsNotAvailable, APIEvent::Severity::Error);
@ -516,7 +516,7 @@ bool IDeviceSettings::setBaudrateFor(Network net, int64_t baudrate) {
cfg->SetBaudrate = AUTO; // Device will use the baudrate value to set the TQ values
return true;
}
case Network::Type::SWCAN: {
case icsneo_msg_bus_type_swcan: {
SWCAN_SETTINGS* cfg = getMutableSWCANSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::SWCANSettingsNotAvailable, APIEvent::Severity::Error);
@ -533,7 +533,7 @@ bool IDeviceSettings::setBaudrateFor(Network net, int64_t baudrate) {
cfg->SetBaudrate = AUTO; // Device will use the baudrate value to set the TQ values
return true;
}
case Network::Type::LIN: {
case icsneo_msg_bus_type_lin: {
LIN_SETTINGS* cfg = getMutableLINSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
@ -566,7 +566,7 @@ int64_t IDeviceSettings::getFDBaudrateFor(Network net) const {
}
switch(net.getType()) {
case Network::Type::CAN: {
case icsneo_msg_bus_type_can: {
const CANFD_SETTINGS* cfg = getCANFDSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::CANFDSettingsNotAvailable, APIEvent::Severity::Error);
@ -604,7 +604,7 @@ bool IDeviceSettings::setFDBaudrateFor(Network net, int64_t baudrate) {
}
switch(net.getType()) {
case Network::Type::CAN: {
case icsneo_msg_bus_type_can: {
CANFD_SETTINGS* cfg = getMutableCANFDSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::CANFDSettingsNotAvailable, APIEvent::Severity::Error);
@ -771,7 +771,7 @@ std::optional<bool> IDeviceSettings::isCommanderResistorEnabledFor(Network net)
}
switch(net.getType()) {
case Network::Type::LIN: {
case icsneo_msg_bus_type_lin: {
const LIN_SETTINGS* cfg = getLINSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
@ -803,7 +803,7 @@ bool IDeviceSettings::setCommanderResistorFor(Network net, bool resistor_on) {
}
switch(net.getType()) {
case Network::Type::LIN: {
case icsneo_msg_bus_type_lin: {
LIN_SETTINGS* cfg = getMutableLINSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
@ -831,7 +831,7 @@ std::optional<LINMode> IDeviceSettings::getLINModeFor(Network net) const {
}
switch(net.getType()) {
case Network::Type::LIN: {
case icsneo_msg_bus_type_lin: {
const LIN_SETTINGS* cfg = getLINSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
@ -863,7 +863,7 @@ bool IDeviceSettings::setLINModeFor(Network net, LINMode mode) {
}
switch(net.getType()) {
case Network::Type::LIN: {
case icsneo_msg_bus_type_lin: {
LIN_SETTINGS* cfg = getMutableLINSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
@ -891,7 +891,7 @@ std::optional<uint8_t> IDeviceSettings::getLINCommanderResponseTimeFor(Network n
}
switch(net.getType()) {
case Network::Type::LIN: {
case icsneo_msg_bus_type_lin: {
const LIN_SETTINGS* cfg = getLINSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
@ -923,7 +923,7 @@ bool IDeviceSettings::setLINCommanderResponseTimeFor(Network net, uint8_t bits)
}
switch(net.getType()) {
case Network::Type::LIN: {
case icsneo_msg_bus_type_lin: {
LIN_SETTINGS* cfg = getMutableLINSettingsFor(net);
if(cfg == nullptr) {
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);

View File

@ -6,7 +6,7 @@ neodevice_t::neodevice_t() : device(nullptr), handle(0), type(0) {
memset(serial, 0, sizeof(serial));
}
neodevice_t::neodevice_t(const icsneo::FoundDevice& found, devicetype_t inType)
neodevice_t::neodevice_t(const icsneo::FoundDevice& found, icsneo_devicetype_t inType)
: device(nullptr), handle(found.handle), type(inType) {
static_assert(sizeof(found.serial) == sizeof(serial), "Serial sizes should match!");
memcpy(serial, found.serial, sizeof(serial));

View File

@ -34,7 +34,7 @@ std::optional<uint64_t> ExtExtractorDiskReadDriver::readLogicalDiskAligned(Commu
std::optional<uint64_t> ExtExtractorDiskReadDriver::attemptReadLogicalDiskAligned(Communication& com, device_eventhandler_t report,
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout, MemoryType) {
static std::shared_ptr<MessageFilter> NeoMemorySDRead = std::make_shared<MessageFilter>(Network::NetID::NeoMemorySDRead);
static std::shared_ptr<MessageFilter> NeoMemorySDRead = std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_neo_memory_sdread);
uint64_t sector = pos / SectorSize;
@ -67,7 +67,7 @@ std::optional<uint64_t> ExtExtractorDiskReadDriver::attemptReadLogicalDiskAligne
cv.notify_all();
}
}
}, std::make_shared<MessageFilter>(Network::NetID::DiskData)));
}, std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_disk_data)));
if(!com.sendCommand(ExtendedCommand::Extract, {
uint8_t(sector & 0xff),

View File

@ -9,7 +9,7 @@ using namespace icsneo::Disk;
std::optional<uint64_t> NeoMemoryDiskDriver::readLogicalDiskAligned(Communication& com, device_eventhandler_t report,
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout, MemoryType memType) {
const auto filter = std::make_shared<MessageFilter>((memType == MemoryType::SD ? Network::NetID::NeoMemorySDRead : Network::NetID::RED_INT_MEMORYREAD));
const auto filter = std::make_shared<MessageFilter>((memType == MemoryType::SD ? _icsneo_netid_t::icsneo_netid_neo_memory_sdread : _icsneo_netid_t::icsneo_netid_red_int_memoryread));
filter->includeInternalInAny = true;
if(pos % SectorSize != 0)
@ -61,7 +61,7 @@ std::optional<uint64_t> NeoMemoryDiskDriver::readLogicalDiskAligned(Communicatio
std::optional<uint64_t> NeoMemoryDiskDriver::writeLogicalDiskAligned(Communication& com, device_eventhandler_t report,
uint64_t pos, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout, MemoryType memType) {
static std::shared_ptr<MessageFilter> NeoMemoryDone = std::make_shared<MessageFilter>(Network::NetID::NeoMemoryWriteDone);
static std::shared_ptr<MessageFilter> NeoMemoryDone = std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_neo_memory_write_done);
if(pos % SectorSize != 0)
return std::nullopt;

View File

@ -8,7 +8,7 @@ using namespace icsneo::Disk;
std::optional<uint64_t> PlasionDiskReadDriver::readLogicalDiskAligned(Communication& com, device_eventhandler_t report,
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout, MemoryType) {
static std::shared_ptr<MessageFilter> NeoMemorySDRead = std::make_shared<MessageFilter>(Network::NetID::NeoMemorySDRead);
static std::shared_ptr<MessageFilter> NeoMemorySDRead = std::make_shared<MessageFilter>(_icsneo_netid_t::icsneo_netid_neo_memory_sdread);
if(amount > getBlockSizeBounds().second)
return std::nullopt;

View File

@ -22,7 +22,7 @@ void VSAExtendedMessage::appendPacket(std::shared_ptr<Packet> packet) const
{
packet->data.insert(packet->data.end(), payload.begin(), payload.end());
// Set the network if not already set (Happens in AA0F records)
if(packet->network.getNetID() == Network::NetID::Invalid) {
if(packet->network.getNetID() == _icsneo_netid_t::icsneo_netid_invalid) {
packet->network = network;
}
}
@ -31,7 +31,7 @@ void VSAExtendedMessage::truncatePacket(std::shared_ptr<Packet> packet)
{
static constexpr auto EthernetLengthOffset = 26u;
switch(packet->network.getType()) {
case Network::Type::Ethernet:
case icsneo_msg_bus_type_ethernet:
{
const auto& packetLength = *reinterpret_cast<uint16_t*>(packet->data.data() + EthernetLengthOffset);
const size_t ethernetFrameSize = packetLength - (sizeof(uint16_t) * 2);

2
docs/conf.py 100644 → 100755
View File

@ -7,6 +7,7 @@ import subprocess
subprocess.call('cd ..; doxygen docs/icsneocpp/Doxyfile', shell=True)
subprocess.call('cd ..; doxygen docs/icsneoc/Doxyfile', shell=True)
subprocess.call('cd ..; doxygen docs/icsneo/Doxyfile', shell=True)
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
@ -26,6 +27,7 @@ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
breathe_projects = {
'icsneocpp': 'icsneocpp/doxygen/xml',
'icsneoc': 'icsneoc/doxygen/xml',
'icsneo': 'icsneoc/doxygen/xml',
}
breathe_default_project = 'icsneocpp'

2862
docs/icsneo/Doxyfile 100644

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
=====
C API
=====
.. doxygenfile:: icsneo.h
:project: icsneo
.. doxygenfile:: icsneotypes.h
:project: icsneo

View File

@ -0,0 +1,43 @@
==========
C Examples
==========
A variety of examples can be found within ``examples/c``, see below for an
example that uses the polling API to receive CAN frames.
.. code-block:: c
size_t deviceCount = 10; // Pre-set to the size of your buffer before the icsneo_findAllDevices() call
neodevice_t devices[10];
icsneo_findAllDevices(devices, &deviceCount);
printf("We found %ull devices\n", deviceCount);
for(size_t i = 0; i < deviceCount; i++) {
neodevice_t* myDevice = &devices[i];
char desc[ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION];
size_t sz = ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION;
icsneo_describeDevice(myDevice, desc, &sz);
printf("Found %s\n", desc); // "Found neoVI FIRE 2 CY2345"
}
neodevice_t* myDevice = &devices[0];
if(!icsneo_openDevice(myDevice)) {
neoevent_t error;
if(icsneo_getLastError(&error))
printf("Error! %s\n", error.description);
}
icsneo_goOnline(myDevice); // Start receiving messages
icsneo_enableMessagePolling(myDevice); // Allow the use of icsneo_getMessages() later
sleep(5);
neomessage_t messages[50];
size_t messageCount = 50;
icsneo_getMessages(myDevice, messages, &messageCount, 0 /* non-blocking */);
printf("We got %ull messages!\n", messageCount);
for(size_t i = 0; i < messageCount; i++) {
if(messages[i].type == ICSNEO_NETWORK_TYPE_CAN) {
// A message of type CAN should be interperated a neomessage_can_t, so we can cast safely
neomessage_can_t* canmsg = (neomessage_can_t*)&messages[i];
// canmsg->arbid is valid here
// canmsg->data is an uint8_t*, you can check canmsg->length for the length of the payload
// canmsg->timestamp is the time recorded by the hardware in nanoseconds since (1/1/2007 12:00:00 GMT)
}
}
icsneo_closeDevice(myDevice);

View File

@ -0,0 +1,9 @@
icsneo
=======
.. toctree::
:maxdepth: 2
installation
examples
api

View File

@ -0,0 +1,7 @@
============
Installation
============
The installation steps for the C API are the same as the C++ API as the C API is
a wrapper for the C++ library. The ``LIBICSNEO_BUILD_ICSNEO`` CMake option is
default ``ON`` but note that the C API depends on this flag to build.

View File

@ -36,9 +36,9 @@ the arbitration ID.
std::cout << "We got " << messages.size() << " messages!" << std::endl;
for(auto& msg : messages) {
switch(msg->network.getType()) {
case icsneo::Network::Type::CAN:
case icsneo::Network::Type::SWCAN:
case icsneo::Network::Type::LSFTCAN: {
case icsneo_msg_bus_type_can:
case icsneo_msg_bus_type_swcan:
case icsneo_msg_bus_type_lsftcan: {
// A message of type CAN is guaranteed to be a CANMessage, so we can static cast safely
auto canmsg = std::static_pointer_cast<icsneo::CANMessage>(msg);
// canmsg->arbid is valid here

View File

@ -13,3 +13,4 @@ communication library. The source code for libicsneo can be found on GitHub:
icsneocpp/index
icsneopy/index
icsneoc/index
icsneo/index

View File

@ -1,5 +1,6 @@
option(LIBICSNEO_BUILD_C_INTERACTIVE_EXAMPLE "Build the command-line interactive C example." ON)
option(LIBICSNEO_BUILD_C_SIMPLE_EXAMPLE "Build the command-line simple C example." ON)
option(LIBICSNEO_BUILD_C_OLD_INTERACTIVE_EXAMPLE "Build the command-line interactive C example." ON)
option(LIBICSNEO_BUILD_C_OLD_SIMPLE_EXAMPLE "Build the command-line simple C example." ON)
option(LIBICSNEO_BUILD_C_LEGACY_EXAMPLE "Build the command-line simple C example." ON)
option(LIBICSNEO_BUILD_CPP_SIMPLE_EXAMPLE "Build the simple C++ example." ON)
option(LIBICSNEO_BUILD_CPP_INTERACTIVE_EXAMPLE "Build the command-line interactive C++ example." ON)
@ -15,16 +16,20 @@ option(LIBICSNEO_BUILD_CPP_APP_ERROR_EXAMPLE "Build the app error example." ON)
# option(LIBICSNEO_BUILD_CSHARP_INTERACTIVE_EXAMPLE "Build the command-line interactive C# example." OFF)
# option(LIBICSNEO_BUILD_JAVA_INTERACTIVE_EXAMPLE "Build the command-line interactive Java example." OFF)
if(LIBICSNEO_BUILD_C_INTERACTIVE_EXAMPLE)
add_subdirectory(c/interactive)
endif()
if(LIBICSNEO_BUILD_C_SIMPLE_EXAMPLE)
add_subdirectory(c/simple)
endif()
if(LIBICSNEO_BUILD_C_LEGACY_EXAMPLE)
add_subdirectory(c/legacy)
if(LIBICSNEO_BUILD_C_OLD_INTERACTIVE_EXAMPLE)
add_subdirectory(c_old/interactive)
endif()
if(LIBICSNEO_BUILD_C_OLD_SIMPLE_EXAMPLE)
add_subdirectory(c_old/simple)
endif()
if(LIBICSNEO_BUILD_C_OLD_LEGACY_EXAMPLE)
add_subdirectory(c_old/legacy)
endif()
if(LIBICSNEO_BUILD_CPP_SIMPLE_EXAMPLE)

View File

@ -1,5 +1,2 @@
add_executable(libicsneoc-simple-lin-example lin/main.c)
if(UNIX)
target_link_libraries(libicsneoc-simple-lin-example ${CMAKE_DL_LIBS})
endif()
target_link_libraries(libicsneoc-simple-lin-example icsneoc)
add_executable(libicsneo-simple-example src/main.c)
target_link_libraries(libicsneo-simple-example icsneo)

View File

@ -0,0 +1,424 @@
#include <icsneo/icsneo.h>
#include <stdio.h>
#include <time.h>
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#else
#include <unistd.h>
#endif
/**
* @brief Sleeps for a specified number of milliseconds.
*
* Sleeps for a specified number of milliseconds using Sleep() on Windows and sleep() on *nix.
*
* @param ms The number of milliseconds to sleep.
*/
void sleep_ms(uint32_t ms) {
#if defined(_WIN32) || defined(_WIN64)
Sleep(ms);
#else
sleep(ms / 1000);
#endif
}
/**
* @brief Prints an error message with the given string and error code.
*
* If the error code is not icsneo_error_success, prints the error string for the given error code
* and returns the error code.
*
* @param message The message to print.
* @param error The error code to print.
* @return error as int
*/
int print_error_code(const char* message, icsneo_error_t error) {
char error_str[256] = {0};
uint32_t error_length = 256;
icsneo_error_t res = icsneo_get_error_code(error, error_str, &error_length);
if (res != icsneo_error_success) {
printf("%s: Failed to get string for error code %d with error code %d\n", message, error, res);
return res;
}
printf("%s: \"%s\" (%u)\n", message, error_str, error);
return (int)error;
}
/**
* @brief Processes a list of messages from a device.
*
* This function iterates over a given array of messages received from a specified device.
* For each message in the array, it retrieves and prints the message type and bus type.
* If an error occurs while retrieving these details, an error message is printed.
*
* @param device A pointer to the icsneo_device_t structure representing the device.
* @param messages An array of pointers to icsneo_message_t structures containing the messages to process.
* @param messages_count The number of messages in the messages array.
*
* @return An icsneo_error_t value indicating success or failure of the message processing.
*/
int process_messages(icsneo_device_t* device, icsneo_message_t** messages, uint32_t messages_count);
/**
* @brief Prints device and global events for a given device.
*
* This function retrieves and prints all current events associated with the specified device,
* as well as any global events not tied to a specific device. For each event, it retrieves
* and prints a description. If retrieving events or their descriptions fails, an error
* message is printed. The function also prints a summary of the count of device-specific
* and global events processed.
*
* @param device A pointer to the icsneo_device_t structure representing the device to get events from.
* @param device_description A description of the device used in the output.
*/
void print_device_events(icsneo_device_t* device, const char* device_description);
/**
* @brief Transmits a series of CAN messages from a device.
*
* This function creates and transmits 100 CAN messages with incrementing payload data.
* Each message is configured with specific attributes such as network ID, arbitration
* ID, CANFD status, extended status, and baudrate switch. After successfully transmitting
* each message, it is freed from memory.
*
* @param device A pointer to the icsneo_device_t structure representing the device to transmit messages from.
*
* @return An icsneo_error_t value indicating success or failure of the message transmission process.
*/
int transmit_can_messages(icsneo_device_t* device);
/**
* @brief Get the RTC (Real time clock) of a device and print it.
*
* @param[in] device The device to get the RTC of.
* @param[in] description A description of the device for printing purpose.
*
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
*/
icsneo_error_t get_and_print_rtc(icsneo_device_t* device, const char* description);
int main(int argc, char* argv[]) {
(void)argc;
(void)argv;
icsneo_device_t* devices[255] = {0};
uint32_t devices_count = 255;
icsneo_error_t res = icsneo_device_find_all(devices, &devices_count, NULL);
if (res != icsneo_error_success) {
return print_error_code("Failed to find devices", res);
};
printf("Found %u devices\n", devices_count);
// Loop over each device
for (uint32_t i = 0; i < devices_count; i++) {
icsneo_device_t* device = devices[i];
// Get description of the device
const char description[255] = {0};
uint32_t description_length = 255;
res = icsneo_device_get_description(device, description, &description_length);
if (res != icsneo_error_success) {
print_device_events(device, description);
return print_error_code("Failed to get device description", res);
};
// Get timestamp resolution of the device
uint32_t timestamp_resolution = 0;
res = icsneo_device_get_timestamp_resolution(device, &timestamp_resolution);
if (res != icsneo_error_success) {
print_device_events(device, description);
return print_error_code("Failed to get timestamp resolution", res);
}
printf("%s timestamp resolution: %uns\n", description, timestamp_resolution);
// Get/Set open options
icsneo_open_options_t options = icsneo_open_options_none;
res = icsneo_device_get_open_options(device, &options);
if (res != icsneo_error_success) {
print_device_events(device, description);
return print_error_code("Failed to get open options", res);
}
// Disable Syncing RTC
options &= ~icsneo_open_options_sync_rtc;
res = icsneo_device_set_open_options(device, options);
if (res != icsneo_error_success) {
print_device_events(device, description);
return print_error_code("Failed to set open options", res);
}
// Open the device
printf("Opening device: %s...\n", description);
res = icsneo_device_open(device);
if (res != icsneo_error_success) {
print_device_events(device, description);
return print_error_code("Failed to open device", res);
};
// Get RTC
res = get_and_print_rtc(device, description);
if (res != icsneo_error_success) {
print_device_events(device, description);
return print_error_code("Failed to get RTC", res);
}
// Set RTC
time_t current_time = time(NULL);
res = icsneo_device_set_rtc(device, (int64_t*)&current_time);
if (res != icsneo_error_success) {
print_device_events(device, description);
return print_error_code("Failed to set RTC", res);
}
// Get RTC
res = get_and_print_rtc(device, description);
if (res != icsneo_error_success) {
print_device_events(device, description);
return print_error_code("Failed to get RTC", res);
}
// Get/Set baudrate for HSCAN
uint64_t baudrate = 0;
res = icsneo_device_get_baudrate(device, icsneo_netid_hscan, &baudrate);
res += icsneo_device_set_baudrate(device, icsneo_netid_hscan, baudrate, true);
if (res != icsneo_error_success) {
print_device_events(device, description);
return print_error_code("Failed to transmit CAN messages", res);
};
printf("HSCAN baudrate: %llu\n", baudrate);
// Get/Set CAN FD baudrate for HSCAN
res = icsneo_device_get_canfd_baudrate(device, icsneo_netid_hscan, &baudrate);
res += icsneo_device_set_canfd_baudrate(device, icsneo_netid_hscan, baudrate, true);
if (res != icsneo_error_success) {
print_device_events(device, description);
return print_error_code("Failed to transmit CAN messages", res);
};
printf("HSCAN CANFD baudrate: %llu\n", baudrate);
// Transmit CAN messages
res = transmit_can_messages(device);
if (res != icsneo_error_success) {
print_device_events(device, description);
return print_error_code("Failed to transmit CAN messages", res);
}
// Wait for the bus to collect some messages, requires an active bus to get messages
printf("Waiting 1 second for messages...\n");
sleep_ms(1000);
// Get the messages
icsneo_message_t* messages[20000] = {0};
uint32_t message_count = 20000;
printf("Getting messages from device with timeout of 3000ms on %s...\n", description);
res = icsneo_device_get_messages(device, messages, &message_count, 3000);
if (res != icsneo_error_success) {
print_device_events(device, description);
return print_error_code("Failed to get messages from device", res);
};
// Process the messages
res = process_messages(device, messages, message_count);
if (res != icsneo_error_success) {
print_device_events(device, description);
return print_error_code("Failed to process messages", res);
}
// Finally, close the device.
printf("Closing device: %s...\n", description);
res = icsneo_device_close(device);
if (res != icsneo_error_success) {
print_device_events(device, description);
return print_error_code("Failed to close device", res);
};
// Print device events
print_device_events(device, description);
}
return 0;
}
icsneo_error_t get_and_print_rtc(icsneo_device_t* device, const char* description) {
time_t unix_epoch = 0;
icsneo_error_t res = icsneo_device_get_rtc(device, &unix_epoch);
if (res != icsneo_error_success) {
return res;
}
char rtc_time[32] = {0};
strftime(rtc_time, sizeof(rtc_time), "%Y-%m-%d %H:%M:%S", localtime(&unix_epoch));
printf("RTC: %lld %s\n", unix_epoch, rtc_time);
return icsneo_error_success;
}
void print_device_events(icsneo_device_t* device, const char* device_description) {
// Get device events
icsneo_event_t* events[1024] = {0};
uint32_t events_count = 1024;
icsneo_error_t res = icsneo_device_get_events(device, events, &events_count);
if (res != icsneo_error_success) {
(void)print_error_code("Failed to get device events", res);
return;
}
// Loop over each event and describe it.
for (uint32_t i = 0; i < events_count; i++) {
const char event_description[255] = {0};
uint32_t event_description_length = 255;
res = icsneo_event_get_description(events[i], event_description, &event_description_length);
if (res != icsneo_error_success) {
print_error_code("Failed to get event description", res);
continue;
}
printf("\t%s: Event %u: %s\n", device_description, i, event_description);
}
// Get global events
icsneo_event_t* global_events[1024] = {0};
uint32_t global_events_count = 1024;
res = icsneo_get_events(global_events, &global_events_count);
if (res != icsneo_error_success) {
(void)print_error_code("Failed to get global events", res);
return;
}
// Loop over each event and describe it.
for (uint32_t i = 0; i < global_events_count; i++) {
const char event_description[255] = {0};
uint32_t event_description_length = 255;
res = icsneo_event_get_description(global_events[i], event_description, &event_description_length);
if (res != icsneo_error_success) {
print_error_code("Failed to get global event description", res);
continue;
}
printf("\t%s: Global Event %u: %s\n", device_description, i, event_description);
}
printf("%s: Received %u events and %u global events\n", device_description, events_count, global_events_count);
}
int process_messages(icsneo_device_t* device, icsneo_message_t** messages, uint32_t messages_count) {
// Print the type and bus type of each message
uint32_t tx_count = 0;
for (uint32_t i = 0; i < messages_count; i++) {
icsneo_message_t* message = messages[i];
// Get the message type
icsneo_msg_type_t msg_type = 0;
icsneo_error_t res = icsneo_message_get_type(device, message, &msg_type);
if (res != icsneo_error_success) {
return print_error_code("Failed to get message type", res);
}
// Get the message type name
char msg_type_name[128] = {0};
uint32_t msg_type_name_length = 128;
res = icsneo_message_get_type_name(msg_type, msg_type_name, &msg_type_name_length);
if (res != icsneo_error_success) {
return print_error_code("Failed to get message type name", res);
}
// Check if the message is a bus message, ignore otherwise
if (msg_type != icsneo_msg_type_bus) {
printf("Ignoring message type: %u (%s)\n", msg_type, msg_type_name);
continue;
}
icsneo_msg_bus_type_t bus_type = 0;
res = icsneo_message_get_bus_type(device, message, &bus_type);
if (res != icsneo_error_success) {
return print_error_code("Failed to get message bus type", res);
}
const char bus_name[128] = {0};
uint32_t bus_name_length = 128;
res = icsneo_get_bus_type_name(&bus_type, bus_name, &bus_name_length);
if (res != icsneo_error_success) {
return print_error_code("Failed to get message bus type name", res);
}
bool is_tx = false;
res = icsneo_message_is_transmit(device, message, &is_tx);
if (res != icsneo_error_success) {
return print_error_code("Failed to get message is transmit", res);
}
if (is_tx) {
tx_count++;
continue;
}
printf("\t%d) Message type: %u bus type: %s (%u)\n", i, msg_type, bus_name, bus_type);
if (bus_type == icsneo_msg_bus_type_can) {
uint32_t arbid = 0;
int32_t dlc = 0;
icsneo_netid_t netid = 0;
bool is_remote = false;
bool is_canfd = false;
bool is_extended = false;
bool is_tx = false;
uint8_t data[64] = {0};
uint32_t data_length = 64;
const char netid_name[128] = {0};
uint32_t netid_name_length = 128;
uint32_t result = icsneo_message_get_netid(device, message, &netid);
result += icsneo_get_netid_name(netid, netid_name, &netid_name_length);
result += icsneo_can_message_get_arbid(device, message, &arbid);
result += icsneo_can_message_get_dlc(device, message, &dlc);
result += icsneo_can_message_is_remote(device, message, &is_remote);
result += icsneo_can_message_is_canfd(device, message, &is_canfd);
result += icsneo_can_message_is_extended(device, message, &is_extended);
result += icsneo_message_get_data(device, message, data, &data_length);
result += icsneo_message_is_transmit(device, message, &is_tx);
if (result != icsneo_error_success) {
printf("\tFailed get get CAN parameters (error: %u) for index %u\n", result, i);
continue;
}
printf("\t NetID: %s (0x%x)\tArbID: 0x%x\t DLC: %u\t TX: %d\t Remote: %d\t CANFD: %d\t Extended: %d\t Data length: %u\n", netid_name, netid, arbid, dlc, is_tx, is_remote, is_canfd, is_extended, data_length);
printf("\t Data: [");
for (uint32_t x = 0; x < data_length; x++) {
printf(" 0x%x", data[x]);
}
printf(" ]\n");
// Lets transmit the message back with an Arbitration ID 1 higher than the original.
result = icsneo_can_message_set_arbid(device, message, arbid + 1);
if (result != icsneo_error_success) {
printf("\tFailed to set CAN Arbitration ID (error: %u) for index %u\n", result, i);
continue;
}
uint32_t tx_msg_count = 1;
result = icsneo_device_transmit_messages(device, &message, &tx_msg_count);
if (result != icsneo_error_success) {
printf("\tFailed to transmit CAN message (error: %u) for index %u\n", result, i);
continue;
}
continue;
}
}
printf("Received %u messages total, %u were TX messages\n", messages_count, tx_count);
return icsneo_error_success;
}
int transmit_can_messages(icsneo_device_t* device) {
uint64_t counter = 0;
for (uint32_t i = 0; i < 100; i++) {
// Create the message
icsneo_message_t* message = NULL;
uint32_t message_count = 1;
icsneo_error_t res = icsneo_can_messages_create(device, &message, message_count);
if (res != icsneo_error_success) {
return print_error_code("Failed to create messages", res);
}
// Set the message attributes
res = icsneo_message_set_netid(device, message, icsneo_netid_hscan);
res += icsneo_can_message_set_arbid(device, message, 0x10);
res += icsneo_can_message_set_canfd(device, message, true);
res += icsneo_can_message_set_extended(device, message, true);
res += icsneo_can_message_set_baudrate_switch(device, message, true);
// Create the payload
uint8_t data[8] = {0};
data[0] = (uint8_t)(counter >> 56);
data[1] = (uint8_t)(counter >> 48);
data[2] = (uint8_t)(counter >> 40);
data[3] = (uint8_t)(counter >> 32);
data[4] = (uint8_t)(counter >> 24);
data[5] = (uint8_t)(counter >> 16);
data[6] = (uint8_t)(counter >> 8);
data[7] = (uint8_t)(counter >> 0);
res += icsneo_message_set_data(device, message, data, sizeof(data));
res += icsneo_can_message_set_dlc(device, message, -1);
if (res != icsneo_error_success) {
return print_error_code("Failed to modify message", res);
}
res = icsneo_device_transmit_messages(device, &message, &message_count);
res += icsneo_can_message_free(device, message);
if (res != icsneo_error_success) {
return print_error_code("Failed to transmit messages", res);
}
counter++;
}
return icsneo_error_success;
}

View File

@ -0,0 +1,5 @@
add_executable(libicsneoc-simple-lin-example lin/main.c)
if(UNIX)
target_link_libraries(libicsneoc-simple-lin-example ${CMAKE_DL_LIBS})
endif()
target_link_libraries(libicsneoc-simple-lin-example icsneoc)

View File

@ -79,7 +79,7 @@ void example0(const std::shared_ptr<icsneo::Device>& rada2b) {
true /* true if we want 16 bit channels in the message, false for 32 bit. This should match the RAD-A2B device setting */
);
msg->txmsg = true;
msg->network = icsneo::Network(icsneo::Network::NetID::A2B2);
msg->network = icsneo::Network(_icsneo_netid_t::icsneo_netid_a2b2);
// Load the WAV audio data into the desired channel, break if we fail to load
if(!msg->loadAudioBuffer(wavStream, channelMap)) {
@ -192,7 +192,7 @@ void example3(const std::shared_ptr<icsneo::Device>& rada2b) {
std::shared_ptr<icsneo::A2BMessage> a2bmsgPtr = std::make_shared<icsneo::A2BMessage>(numFrames, icsneo::A2BMessage::TDMMode::TDM4, true);
icsneo::A2BMessage& a2bmsg = *a2bmsgPtr.get();
a2bmsg.network = icsneo::Network(icsneo::Network::NetID::A2B2);
a2bmsg.network = icsneo::Network(_icsneo_netid_t::icsneo_netid_a2b2);
a2bmsg.txmsg = true;
for(size_t frame = 0; frame < a2bmsg.getNumFrames(); frame++) {
@ -245,9 +245,9 @@ void example3(const std::shared_ptr<icsneo::Device>& rada2b) {
*/
void example4(const std::shared_ptr<icsneo::Device>& rada2b) {
std::shared_ptr<icsneo::I2CMessage> msg = std::make_shared<icsneo::I2CMessage>();
std::shared_ptr<icsneo::MessageFilter> msgFilter = std::make_shared<icsneo::MessageFilter>(icsneo::Network::NetID::I2C2);
std::shared_ptr<icsneo::MessageFilter> msgFilter = std::make_shared<icsneo::MessageFilter>(_icsneo_netid_t::icsneo_netid_i2c2);
msg->network = icsneo::Network(icsneo::Network::NetID::I2C2);
msg->network = icsneo::Network(_icsneo_netid_t::icsneo_netid_i2c2);
msg->controlBytes.resize(1);
msg->controlBytes[0] = static_cast<uint8_t>(0x17u); // Register address for A2B INTTYPE
msg->dataBytes.resize(1, 0);
@ -259,9 +259,9 @@ void example4(const std::shared_ptr<icsneo::Device>& rada2b) {
auto handler = rada2b->addMessageCallback(std::make_shared<icsneo::MessageCallback>(
[] (std::shared_ptr<icsneo::Message> newMsg) {
if(newMsg->type == icsneo::Message::Type::Frame) {
const auto& frame = std::dynamic_pointer_cast<icsneo::Frame>(newMsg);
if(frame && frame->network.getNetID() == icsneo::Network::NetID::I2C2) {
if(newMsg->type == icsneo::Message::Type::BusMessage) {
const auto& frame = std::dynamic_pointer_cast<icsneo::BusMessage>(newMsg);
if(frame && frame->network.getNetID() == _icsneo_netid_t::icsneo_netid_i2c2) {
const auto& i2cMessage = std::dynamic_pointer_cast<icsneo::I2CMessage>(frame);
if(!i2cMessage) {
@ -392,11 +392,11 @@ int main(int argc, char** argv) {
const auto& txNetworks = dev->getSupportedTXNetworks();
const auto& rxNetworks = dev->getSupportedRXNetworks();
if(std::none_of(txNetworks.begin(), txNetworks.end(), [](const icsneo::Network& net) { return net.getType() == icsneo::Network::Type::A2B; })) {
if(std::none_of(txNetworks.begin(), txNetworks.end(), [](const icsneo::Network& net) { return net.getType() == icsneo_msg_bus_type_a2b; })) {
return false;
}
if(std::none_of(rxNetworks.begin(), rxNetworks.end(), [](const icsneo::Network& net) { return net.getType() == icsneo::Network::Type::A2B; })) {
if(std::none_of(rxNetworks.begin(), rxNetworks.end(), [](const icsneo::Network& net) { return net.getType() == icsneo_msg_bus_type_a2b; })) {
return false;
}

View File

@ -40,7 +40,7 @@ int main() {
// Add your error handling here
auto handler = device->addMessageCallback(std::make_shared<icsneo::MessageCallback>(filter, [](std::shared_ptr<icsneo::Message> message) {
auto msg = std::static_pointer_cast<icsneo::AppErrorMessage>(message);
if(icsneo::Network::NetID::RED_App_Error == msg->network.getNetID()) {
if(_icsneo_netid_t::icsneo_netid_red_app_error == msg->network.getNetID()) {
std::cout << std::endl << "App error reported:" << std::endl;
std::cout << msg->getAppErrorString() << std::endl << std::endl;
}
@ -58,7 +58,7 @@ int main() {
// Prepare a CAN message
std::cout << std::endl << "Transmitting a CAN frame... ";
auto txMessage = std::make_shared<icsneo::CANMessage>();
txMessage->network = icsneo::Network::NetID::HSCAN;
txMessage->network = _icsneo_netid_t::icsneo_netid_hscan;
txMessage->arbid = 0x22;
txMessage->data.insert(txMessage->data.end(), {0xaa, 0xbb, 0xcc});
// The DLC will come from the length of the data vector

View File

@ -184,11 +184,11 @@ std::shared_ptr<icsneo::Device> selectDevice(const std::vector<std::shared_ptr<i
void printMessage(const std::shared_ptr<icsneo::Message>& message) {
switch(message->type) {
case icsneo::Message::Type::Frame: {
// A message of type Frame is guaranteed to be a Frame, so we can static cast safely
auto frame = std::static_pointer_cast<icsneo::Frame>(message);
case icsneo::Message::Type::BusMessage: {
// A message of type BusMessage is guaranteed to be a BusMessage, so we can static cast safely
auto frame = std::static_pointer_cast<icsneo::BusMessage>(message);
switch(frame->network.getType()) {
case icsneo::Network::Type::CAN: {
case icsneo_msg_bus_type_can: {
// A message of type CAN is guaranteed to be a CANMessage, so we can static cast safely
auto canMessage = std::static_pointer_cast<icsneo::CANMessage>(message);
@ -214,10 +214,10 @@ void printMessage(const std::shared_ptr<icsneo::Message>& message) {
std::cout << std::dec << '(' << canMessage->timestamp << " ns since 1/1/2007)\n";
break;
}
case icsneo::Network::Type::Ethernet: {
case icsneo_msg_bus_type_ethernet: {
auto ethMessage = std::static_pointer_cast<icsneo::EthernetMessage>(message);
std::cout << "\t\t" << ethMessage->network << " Frame - " << std::dec
std::cout << "\t\t" << ethMessage->network << " BusMessage - " << std::dec
<< ethMessage->data.size() << " bytes on wire\n";
std::cout << "\t\t Timestamped:\t"<< ethMessage->timestamp << " ns since 1/1/2007\n";
@ -235,7 +235,7 @@ void printMessage(const std::shared_ptr<icsneo::Message>& message) {
std::cout << std::dec << std::endl;
break;
}
case icsneo::Network::Type::ISO9141: {
case icsneo_msg_bus_type_iso9141: {
// Note that the default settings on some devices have ISO9141 disabled by default in favor of LIN
// and that this example loads the device defaults at the very end.
// A message of type ISO9414 is guaranteed to be an ISO9141Message, so we can static cast safely
@ -264,7 +264,7 @@ void printMessage(const std::shared_ptr<icsneo::Message>& message) {
break;
}
break;
} // end of icsneo::Message::Type::Frame
} // end of icsneo::Message::Type::BusMessage
case icsneo::Message::Type::CANErrorCount: {
// A message of type CANErrorCount is guaranteed to be a CANErrorCount, so we can static cast safely
auto cec = std::static_pointer_cast<icsneo::CANErrorCountMessage>(message);
@ -508,7 +508,7 @@ int main() {
std::cout << "Transmitting a normal CAN frame..." << std::endl;
auto msg = std::make_shared<icsneo::CANMessage>();
msg->network = icsneo::Network::NetID::HSCAN;
msg->network = _icsneo_netid_t::icsneo_netid_hscan;
msg->arbid = 0x120;
msg->data.insert(msg->data.end(), {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff});
msg->isExtended = false;
@ -525,7 +525,7 @@ int main() {
/** Example of CAN FD
std::cout << "Transmitting an extended CAN FD frame... " << std::endl;
auto txMessage = std::make_shared<icsneo::CANMessage>();
txMessage->network = icsneo::Network::NetID::HSCAN;
txMessage->network = icsneo_netid_hscan;
txMessage->arbid = 0x1C5001C5;
txMessage->data.insert(txMessage->data.end(), {0xaa, 0xbb, 0xcc});
// The DLC will come from the length of the data vector
@ -565,7 +565,7 @@ int main() {
selectedDevice = selectDevice(devices);
// Attempt to set baudrate and apply settings
if(selectedDevice->settings->setBaudrateFor(icsneo::Network::NetID::HSCAN, 250000) && selectedDevice->settings->apply()) {
if(selectedDevice->settings->setBaudrateFor(_icsneo_netid_t::icsneo_netid_hscan, 250000) && selectedDevice->settings->apply()) {
std::cout << "Successfully set HS CAN baudrate for " << selectedDevice->describe() << " to 250k!" << std::endl;
} else {
std::cout << "Failed to set HS CAN baudrate for " << selectedDevice->describe() << " to 250k!" << std::endl << std::endl;
@ -586,7 +586,7 @@ int main() {
selectedDevice = selectDevice(devices);
// Attempt to set baudrate and apply settings
if(selectedDevice->settings->setBaudrateFor(icsneo::Network::NetID::LSFTCAN, 250000) && selectedDevice->settings->apply()) {
if(selectedDevice->settings->setBaudrateFor(_icsneo_netid_t::icsneo_netid_lsftcan, 250000) && selectedDevice->settings->apply()) {
std::cout << "Successfully set LSFT CAN baudrate for " << selectedDevice->describe() << " to 250k!" << std::endl;
} else {
std::cout << "Failed to set LSFT CAN baudrate for " << selectedDevice->describe() << " to 250k!" << std::endl << std::endl;
@ -790,7 +790,7 @@ int main() {
selectedDevice = selectDevice(devices);
std::cout << "Termination is ";
const auto val = selectedDevice->settings->isTerminationEnabledFor(icsneo::Network::NetID::HSCAN);
const auto val = selectedDevice->settings->isTerminationEnabledFor(_icsneo_netid_t::icsneo_netid_hscan);
if(!val.has_value()) {
std::cout << "not available at this time: " << icsneo::GetLastError() << std::endl << std::endl;
break;
@ -807,7 +807,7 @@ int main() {
}
// Attempt to set termination and apply settings
if(selectedDevice->settings->setTerminationFor(icsneo::Network::NetID::HSCAN, selection2 == '1') && selectedDevice->settings->apply()) {
if(selectedDevice->settings->setTerminationFor(_icsneo_netid_t::icsneo_netid_hscan, selection2 == '1') && selectedDevice->settings->apply()) {
std::cout << "Successfully set HS CAN termination for " << selectedDevice->describe() << std::endl;
} else {
std::cout << "Failed to set HS CAN termination for " << selectedDevice->describe() << std::endl;

View File

@ -33,27 +33,27 @@ int main() {
int64_t baud = 19200;
std::cout << "Enable LIN commander resistor... ";
ret = device->settings->setCommanderResistorFor(icsneo::Network::NetID::LIN, true);
ret = device->settings->setCommanderResistorFor(_icsneo_netid_t::icsneo_netid_lin, true);
std::cout << (ret ? "OK" : "FAIL") << std::endl;
std::cout << "Disable LIN2 commander resistor... ";
ret = device->settings->setCommanderResistorFor(icsneo::Network::NetID::LIN2, false);
ret = device->settings->setCommanderResistorFor(_icsneo_netid_t::icsneo_netid_lin2, false);
std::cout << (ret ? "OK" : "FAIL") << std::endl;
std::cout << "Setting LIN to operate at " << baud << "bit/s... ";
ret = device->settings->setBaudrateFor(icsneo::Network::NetID::LIN, baud);
ret = device->settings->setBaudrateFor(_icsneo_netid_t::icsneo_netid_lin, baud);
std::cout << (ret ? "OK" : "FAIL") << std::endl;
std::cout << "Setting LIN2 to operate at " << baud << "bit/s... ";
ret = device->settings->setBaudrateFor(icsneo::Network::NetID::LIN2, baud);
ret = device->settings->setBaudrateFor(_icsneo_netid_t::icsneo_netid_lin2, baud);
std::cout << (ret ? "OK" : "FAIL") << std::endl;
std::cout << "Setting LIN mode to NORMAL... ";
ret = device->settings->setLINModeFor(icsneo::Network::NetID::LIN, NORMAL_MODE);
ret = device->settings->setLINModeFor(_icsneo_netid_t::icsneo_netid_lin, NORMAL_MODE);
std::cout << (ret ? "OK" : "FAIL") << std::endl;
std::cout << "Setting LIN2 mode to NORMAL... ";
ret = device->settings->setLINModeFor(icsneo::Network::NetID::LIN2, NORMAL_MODE);
ret = device->settings->setLINModeFor(_icsneo_netid_t::icsneo_netid_lin2, NORMAL_MODE);
std::cout << (ret ? "OK" : "FAIL") << std::endl;
std::cout << "Applying settings... ";
@ -61,14 +61,14 @@ int main() {
std::cout << (ret ? "OK" : "FAIL") << std::endl;
std::cout << "Getting LIN Baudrate... ";
int64_t readBaud = device->settings->getBaudrateFor(icsneo::Network::NetID::LIN);
int64_t readBaud = device->settings->getBaudrateFor(_icsneo_netid_t::icsneo_netid_lin);
if(readBaud < 0)
std::cout << "FAIL" << std::endl;
else
std::cout << "OK, " << (readBaud) << "bit/s" << std::endl;
std::cout << "Getting LIN2 Baudrate... ";
readBaud = device->settings->getBaudrateFor(icsneo::Network::NetID::LIN2);
readBaud = device->settings->getBaudrateFor(_icsneo_netid_t::icsneo_netid_lin2);
if(readBaud < 0)
std::cout << "FAIL" << std::endl;
else
@ -96,9 +96,9 @@ int main() {
std::cout << "OK" << std::endl << std::endl;
auto handler = device->addMessageCallback(std::make_shared<icsneo::MessageCallback>([&](std::shared_ptr<icsneo::Message> message) {
if(icsneo::Message::Type::Frame == message->type) {
auto frame = std::static_pointer_cast<icsneo::Frame>(message);
if(icsneo::Network::Type::LIN == frame->network.getType()) {
if(icsneo::Message::Type::BusMessage == message->type) {
auto frame = std::static_pointer_cast<icsneo::BusMessage>(message);
if(icsneo_msg_bus_type_lin == frame->network.getType()) {
auto msg = std::static_pointer_cast<icsneo::LINMessage>(message);
std::cout << msg->network << " RX frame | ID: 0x" << std::hex << static_cast<int>(msg->ID) << " | ";
std::cout << "Protected ID: 0x" << static_cast<int>(msg->protectedID) << "\n" << "Data: ";
@ -115,7 +115,7 @@ int main() {
// We can transmit messages
std::cout << "Transmitting a LIN responder data frame... ";
auto lin_r = std::make_shared<icsneo::LINMessage>();
lin_r->network = icsneo::Network::NetID::LIN2;
lin_r->network = _icsneo_netid_t::icsneo_netid_lin2;
lin_r->ID = 0x11;
lin_r->linMsgType = icsneo::LINMessage::Type::LIN_UPDATE_RESPONDER;
lin_r->data = {0xaa, 0xbb, 0xcc, 0xdd, 0x11, 0x22, 0x33, 0x44};
@ -124,7 +124,7 @@ int main() {
std::cout << "Transmitting a LIN commander header... ";
auto lin_c = std::make_shared<icsneo::LINMessage>();
lin_c->network = icsneo::Network::NetID::LIN;
lin_c->network = _icsneo_netid_t::icsneo_netid_lin;
lin_c->ID = 0x11;
lin_c->linMsgType = icsneo::LINMessage::Type::LIN_HEADER_ONLY;
ret = device->transmit(lin_c);
@ -134,7 +134,7 @@ int main() {
std::cout << "Transmitting a LIN commander frame with responder data... ";
auto lin_d = std::make_shared<icsneo::LINMessage>();
lin_d->network = icsneo::Network::NetID::LIN;
lin_d->network = _icsneo_netid_t::icsneo_netid_lin;
lin_d->ID = 0x22;
lin_d->isEnhancedChecksum = true;
lin_d->linMsgType = icsneo::LINMessage::Type::LIN_COMMANDER_MSG;

View File

@ -92,9 +92,9 @@ int main()
auto handler = device->addMessageCallback(std::make_shared<icsneo::MessageCallback>([&](std::shared_ptr<icsneo::Message> message)
{
if(icsneo::Message::Type::Frame == message->type) {
auto frame = std::static_pointer_cast<icsneo::Frame>(message);
if(icsneo::Network::Type::MDIO == frame->network.getType()) {
if(icsneo::Message::Type::BusMessage == message->type) {
auto frame = std::static_pointer_cast<icsneo::BusMessage>(message);
if(icsneo_msg_bus_type_mdio == frame->network.getType()) {
auto msg = std::static_pointer_cast<icsneo::MDIOMessage>(message);
std::cout << msg->network << " " << ((msg->isTXMsg)? "TX" : "RX") << " frame\n";
std::cout << "Clause: " << ((msg->clause == icsneo::MDIOMessage::Clause::Clause22) ? "22" : "45") << "\n";
@ -117,7 +117,7 @@ int main()
// We can transmit messages to read the PHY ID of BCM89810 PHY
std::cout << "\tTransmitting a MDIO request to read ID on BCM89810...\n";
auto mdio_r = std::make_shared<icsneo::MDIOMessage>();
mdio_r->network = icsneo::Network::NetID::MDIO1;
mdio_r->network = _icsneo_netid_t::icsneo_netid_mdio1;
mdio_r->phyAddress = 0x00u;
mdio_r->regAddress = 0x02u;
mdio_r->direction = icsneo::MDIOMessage::Direction::Read;
@ -128,7 +128,7 @@ int main()
// We can transmit messages to write to arbitrary register
std::cout << "\tTransmitting a MDIO request to write register on BCM89810...\n";
mdio_r = std::make_shared<icsneo::MDIOMessage>();
mdio_r->network = icsneo::Network::NetID::MDIO1;
mdio_r->network = _icsneo_netid_t::icsneo_netid_mdio1;
mdio_r->phyAddress = 0x00u;
mdio_r->regAddress = 0x1Bu;
mdio_r->data = {0xAA, 0xAF};
@ -140,7 +140,7 @@ int main()
// We can transmit messages to read back to arbitrary register
std::cout << "\tTransmitting a MDIO request to read register on BCM89810...\n";
mdio_r = std::make_shared<icsneo::MDIOMessage>();
mdio_r->network = icsneo::Network::NetID::MDIO1;
mdio_r->network = _icsneo_netid_t::icsneo_netid_mdio1;
mdio_r->phyAddress = 0x00u;
mdio_r->regAddress = 0x1Bu;
mdio_r->direction = icsneo::MDIOMessage::Direction::Read;
@ -154,7 +154,7 @@ int main()
// We can transmit messages to read the PHY ID of BCM89810 PHY
std::cout << "\tTransmitting a MDIO request to read ID on 88Q2112...\n";
mdio_r = std::make_shared<icsneo::MDIOMessage>();
mdio_r->network = icsneo::Network::NetID::MDIO1;
mdio_r->network = _icsneo_netid_t::icsneo_netid_mdio1;
mdio_r->phyAddress = 0x06u;
mdio_r->devAddress = 0x01u;
mdio_r->regAddress = 0x0002u;
@ -166,7 +166,7 @@ int main()
// We can transmit messages to write to arbitrary register
std::cout << "\tTransmitting a MDIO request to write register on 88Q2112...\n";
mdio_r = std::make_shared<icsneo::MDIOMessage>();
mdio_r->network = icsneo::Network::NetID::MDIO1;
mdio_r->network = _icsneo_netid_t::icsneo_netid_mdio1;
mdio_r->phyAddress = 0x06u;
mdio_r->devAddress = 0x01u;
mdio_r->regAddress = 0x0902u;
@ -179,7 +179,7 @@ int main()
// We can transmit messages to read back to arbitrary register
std::cout << "\tTransmitting a MDIO request to read register on 88Q2112...\n";
mdio_r = std::make_shared<icsneo::MDIOMessage>();
mdio_r->network = icsneo::Network::NetID::MDIO1;
mdio_r->network = _icsneo_netid_t::icsneo_netid_mdio1;
mdio_r->phyAddress = 0x06u;
mdio_r->devAddress = 0x01u;
mdio_r->regAddress = 0x0902u;

View File

@ -15,7 +15,7 @@ int main() {
std::cout<< "Supported devices:" << std::endl;
for(auto& dev : icsneo::GetSupportedDevices())
std::cout << '\t' << dev.getGenericProductName() << std::endl;
std::cout << '\t' << dev.getProductName() << std::endl;
std::cout << "\nFinding devices... " << std::flush;
auto devices = icsneo::FindAllDevices(); // This is type std::vector<std::shared_ptr<icsneo::Device>>
@ -38,38 +38,38 @@ int main() {
std::cout << "OK" << std::endl;
std::cout << "\tGetting HSCAN Baudrate... ";
int64_t baud = device->settings->getBaudrateFor(icsneo::Network::NetID::HSCAN);
int64_t baud = device->settings->getBaudrateFor(_icsneo_netid_t::icsneo_netid_hscan);
if(baud < 0)
std::cout << "FAIL" << std::endl;
else
std::cout << "OK, " << (baud/1000) << "kbit/s" << std::endl;
std::cout << "\tSetting HSCAN to operate at 125kbit/s... ";
ret = device->settings->setBaudrateFor(icsneo::Network::NetID::HSCAN, 125000);
ret = device->settings->setBaudrateFor(_icsneo_netid_t::icsneo_netid_hscan, 125000);
std::cout << (ret ? "OK" : "FAIL") << std::endl;
// Changes to the settings do not take affect until you call settings->apply()!
// When you get the baudrate here, you're reading what the device is currently operating on
std::cout << "\tGetting HSCAN Baudrate... (expected to be unchanged) ";
baud = device->settings->getBaudrateFor(icsneo::Network::NetID::HSCAN);
baud = device->settings->getBaudrateFor(_icsneo_netid_t::icsneo_netid_hscan);
if(baud < 0)
std::cout << "FAIL" << std::endl;
else
std::cout << "OK, " << (baud/1000) << "kbit/s" << std::endl;
std::cout << "\tGetting HSCANFD Baudrate... ";
baud = device->settings->getFDBaudrateFor(icsneo::Network::NetID::HSCAN);
baud = device->settings->getFDBaudrateFor(_icsneo_netid_t::icsneo_netid_hscan);
if(baud < 0)
std::cout << "FAIL" << std::endl;
else
std::cout << "OK, " << (baud/1000) << "kbit/s" << std::endl;
std::cout << "\tSetting HSCANFD to operate at 8Mbit/s... ";
ret = device->settings->setFDBaudrateFor(icsneo::Network::NetID::HSCAN, 8000000);
ret = device->settings->setFDBaudrateFor(_icsneo_netid_t::icsneo_netid_hscan, 8000000);
std::cout << (ret ? "OK" : "FAIL") << std::endl;
std::cout << "\tGetting HSCANFD Baudrate... (expected to be unchanged) ";
baud = device->settings->getFDBaudrateFor(icsneo::Network::NetID::HSCAN);
baud = device->settings->getFDBaudrateFor(_icsneo_netid_t::icsneo_netid_hscan);
if(baud < 0)
std::cout << "FAIL" << std::endl;
else
@ -84,14 +84,14 @@ int main() {
// Now that we have applied, we expect that our operating baudrates have changed
std::cout << "\tGetting HSCAN Baudrate... ";
baud = device->settings->getBaudrateFor(icsneo::Network::NetID::HSCAN);
baud = device->settings->getBaudrateFor(_icsneo_netid_t::icsneo_netid_hscan);
if(baud < 0)
std::cout << "FAIL" << std::endl;
else
std::cout << "OK, " << (baud/1000) << "kbit/s" << std::endl;
std::cout << "\tGetting HSCANFD Baudrate... ";
baud = device->settings->getFDBaudrateFor(icsneo::Network::NetID::HSCAN);
baud = device->settings->getFDBaudrateFor(_icsneo_netid_t::icsneo_netid_hscan);
if(baud < 0)
std::cout << "FAIL" << std::endl;
else
@ -155,7 +155,7 @@ int main() {
// We can transmit messages
std::cout << "\n\tTransmitting an extended CAN FD frame... ";
auto txMessage5 = std::make_shared<icsneo::CANMessage>();
txMessage5->network = icsneo::Network::NetID::HSCAN;
txMessage5->network = _icsneo_netid_t::icsneo_netid_hscan;
txMessage5->arbid = 0x1C5001C5;
txMessage5->data.insert(txMessage5->data.end(), {0xaa, 0xbb, 0xcc});
// The DLC will come from the length of the data vector
@ -169,11 +169,11 @@ int main() {
// MessageCallbacks are powerful, and can filter on things like ArbID for you. See the documentation
auto handler = device->addMessageCallback(std::make_shared<icsneo::MessageCallback>([](std::shared_ptr<icsneo::Message> message) {
switch(message->type) {
case icsneo::Message::Type::Frame: {
// A message of type Frame is guaranteed to be a Frame, so we can static cast safely
auto frame = std::static_pointer_cast<icsneo::Frame>(message);
case icsneo::Message::Type::BusMessage: {
// A message of type BusMessage is guaranteed to be a BusMessage, so we can static cast safely
auto frame = std::static_pointer_cast<icsneo::BusMessage>(message);
switch(frame->network.getType()) {
case icsneo::Network::Type::CAN: {
case icsneo_msg_bus_type_can: {
// A message of type CAN is guaranteed to be a CANMessage, so we can static cast safely
auto canMessage = std::static_pointer_cast<icsneo::CANMessage>(message);
@ -199,10 +199,10 @@ int main() {
std::cout << std::dec << '(' << canMessage->timestamp << " ns since 1/1/2007)\n";
break;
}
case icsneo::Network::Type::Ethernet: {
case icsneo_msg_bus_type_ethernet: {
auto ethMessage = std::static_pointer_cast<icsneo::EthernetMessage>(message);
std::cout << "\t\t" << ethMessage->network << " Frame - " << std::dec
std::cout << "\t\t" << ethMessage->network << " BusMessage - " << std::dec
<< ethMessage->data.size() << " bytes on wire\n";
std::cout << "\t\t Timestamped:\t"<< ethMessage->timestamp << " ns since 1/1/2007\n";
@ -220,7 +220,7 @@ int main() {
std::cout << std::dec << std::endl;
break;
}
case icsneo::Network::Type::ISO9141: {
case icsneo_msg_bus_type_iso9141: {
// Note that the default settings on some devices have ISO9141 disabled by default in favor of LIN
// and that this example loads the device defaults at the very end.
// A message of type ISO9414 is guaranteed to be an ISO9141Message, so we can static cast safely
@ -249,7 +249,7 @@ int main() {
break;
}
break;
} // end of icsneo::Message::Type::Frame
} // end of icsneo::Message::Type::BusMessage
case icsneo::Message::Type::CANErrorCount: {
// A message of type CANErrorCount is guaranteed to be a CANErrorCount, so we can static cast safely
auto cec = std::static_pointer_cast<icsneo::CANErrorCountMessage>(message);
@ -290,7 +290,7 @@ int main() {
// We can transmit messages
std::cout << "\tTransmitting an extended CAN FD frame... ";
auto txMessage = std::make_shared<icsneo::CANMessage>();
txMessage->network = icsneo::Network::NetID::HSCAN;
txMessage->network = _icsneo_netid_t::icsneo_netid_hscan;
txMessage->arbid = 0x1C5001C5;
txMessage->data.insert(txMessage->data.end(), {0xaa, 0xbb, 0xcc});
// The DLC will come from the length of the data vector
@ -301,7 +301,7 @@ int main() {
std::cout << "\tTransmitting an ethernet frame on OP (BR) Ethernet 2... ";
auto ethTxMessage = std::make_shared<icsneo::EthernetMessage>();
ethTxMessage->network = icsneo::Network::NetID::OP_Ethernet2;
ethTxMessage->network = _icsneo_netid_t::icsneo_netid_op_ethernet2;
ethTxMessage->data.insert(ethTxMessage->data.end(), {
0x00, 0xFC, 0x70, 0x00, 0x01, 0x02, /* Destination MAC */
0x00, 0xFC, 0x70, 0x00, 0x01, 0x01, /* Source MAC */

View File

@ -16,13 +16,13 @@ void onEvent(std::shared_ptr<icsneo::APIEvent> event) {
std::cout << event->describe() << std::endl;
}
std::vector<std::shared_ptr<icsneo::Frame>> constructRandomFrames(size_t frameCount, MessageType frameType) {
std::vector<std::shared_ptr<icsneo::BusMessage>> constructRandomFrames(size_t frameCount, MessageType frameType) {
static constexpr size_t ClassicCANSize = 8;
static constexpr size_t CANFDSize = 64;
static constexpr size_t ShortEthSize = 500;
static constexpr size_t LongEthSize = 1500;
std::vector<std::shared_ptr<icsneo::Frame>> frames;
std::vector<std::shared_ptr<icsneo::BusMessage>> frames;
std::random_device randDev;
std::mt19937 randEngine(randDev());
std::uniform_int_distribution randByteDist(0,255);
@ -36,7 +36,7 @@ std::vector<std::shared_ptr<icsneo::Frame>> constructRandomFrames(size_t frameCo
// Short Ethernet
{
auto frame = std::make_shared<icsneo::EthernetMessage>();
frame->network = icsneo::Network::NetID::Ethernet;
frame->network = _icsneo_netid_t::icsneo_netid_ethernet;
frames.push_back(frame);
frame->data.resize(ShortEthSize);
std::generate(frame->data.begin(), frame->data.end(), randByteGen);
@ -46,7 +46,7 @@ std::vector<std::shared_ptr<icsneo::Frame>> constructRandomFrames(size_t frameCo
// Long Ethernet
{
auto frame = std::make_shared<icsneo::EthernetMessage>();
frame->network = icsneo::Network::NetID::Ethernet;
frame->network = _icsneo_netid_t::icsneo_netid_ethernet;
frames.push_back(frame);
frame->data.resize(LongEthSize);
std::generate(frame->data.begin(), frame->data.end(), randByteGen);
@ -56,7 +56,7 @@ std::vector<std::shared_ptr<icsneo::Frame>> constructRandomFrames(size_t frameCo
// Classic CAN
{
auto frame = std::make_shared<icsneo::CANMessage>();
frame->network = icsneo::Network::NetID::HSCAN2;
frame->network = _icsneo_netid_t::icsneo_netid_hscan2;
frames.push_back(frame);
frame->data.resize(ClassicCANSize);
@ -67,7 +67,7 @@ std::vector<std::shared_ptr<icsneo::Frame>> constructRandomFrames(size_t frameCo
// CAN FD
{
auto frame = std::make_shared<icsneo::CANMessage>();
frame->network = icsneo::Network::NetID::HSCAN3;
frame->network = _icsneo_netid_t::icsneo_netid_hscan3;
frames.push_back(frame);
frame->data.resize(CANFDSize);
std::generate(frame->data.begin(), frame->data.end(), randByteGen);
@ -166,13 +166,13 @@ int main(int argc, char* argv[]) {
uint64_t canFrameCount = 0;
uint64_t ethFrameCount = 0;
rxDevice->addMessageCallback(std::make_shared<icsneo::MessageCallback>([&](std::shared_ptr<icsneo::Message> msg) {
if(msg->type != icsneo::Message::Type::Frame) {
if(msg->type != icsneo::Message::Type::BusMessage) {
return;
}
const auto frame = std::static_pointer_cast<icsneo::Frame>(msg);
if(frame->network.getType() == icsneo::Network::Type::CAN) {
const auto frame = std::static_pointer_cast<icsneo::BusMessage>(msg);
if(frame->network.getType() == icsneo_msg_bus_type_can) {
++canFrameCount;
} else if(frame->network.getType() == icsneo::Network::Type::Ethernet) {
} else if(frame->network.getType() == icsneo_msg_bus_type_ethernet) {
++ethFrameCount;
}
}));
@ -200,7 +200,7 @@ int main(int argc, char* argv[]) {
const uint8_t NumFrameTypes = 4;
const size_t FrameCountPerType = 2500;
std::vector<std::shared_ptr<icsneo::Frame>> frames;
std::vector<std::shared_ptr<icsneo::BusMessage>> frames;
for(uint8_t i = 0; i < NumFrameTypes; i++) {
std::cout << "info: transmitting " << FrameCountPerType << " random " << MessageTypeLabels[i] << " frames" << std::endl;
auto tempFrames = constructRandomFrames(FrameCountPerType, static_cast<MessageType>(i));
@ -216,10 +216,10 @@ int main(int argc, char* argv[]) {
size_t currentMessage = 0;
rxDevice->addMessageCallback(std::make_shared<icsneo::MessageCallback>([&](std::shared_ptr<icsneo::Message> msg) {
if(msg->type != icsneo::Message::Type::Frame) {
if(msg->type != icsneo::Message::Type::BusMessage) {
return;
}
auto frame = std::static_pointer_cast<icsneo::Frame>(msg);
auto frame = std::static_pointer_cast<icsneo::BusMessage>(msg);
if(frames[currentMessage]->data == frame->data) {
currentMessage++;
}

View File

@ -0,0 +1,3 @@
module simple
go 1.23.4

View File

@ -0,0 +1,49 @@
package main
// #cgo CFLAGS: -I../../../../include
// #cgo LDFLAGS: -L../../../../build -licsneo -lstdc++
// #include "icsneo/icsneo.h"
import "C"
import (
"fmt"
"unsafe"
)
func main() {
findDevices()
}
func findDevices() {
// Get all devices attached to host
devices := [255]*C.icsneo_device_t{nil}
devicesCount := 255
res := C.icsneo_device_find_all(&devices[0], (*C.uint)(unsafe.Pointer(&devicesCount)), nil)
if res != C.icsneo_error_success {
printError(res)
return
}
println("Found", devicesCount, "device(s):")
// Iterate through all the devices
for i, device := range devices[:devicesCount] {
description := make([]byte, 255)
descriptionLength := 255
res := C.icsneo_device_get_description(device, (*C.char)(unsafe.Pointer(&description[0])), (*C.uint)(unsafe.Pointer(&descriptionLength)))
if res != C.icsneo_error_success {
printError(res)
continue
}
fmt.Printf("\t%d. %s\n", i+1, string(description[:descriptionLength]))
}
}
func printError(err C.icsneo_error_t) C.icsneo_error_t {
buffer := make([]byte, 255)
bufferLength := 255
res := C.icsneo_get_error_code(err, (*C.char)(unsafe.Pointer(&buffer[0])), (*C.uint)(unsafe.Pointer(&bufferLength)))
if res != C.icsneo_error_success {
println("icsneo_get_error_code failed, original error:", err)
return res
}
println("Error:", string(buffer[:bufferLength]))
return res
}

View File

@ -0,0 +1,22 @@
# This file is for zig-specific build artifacts.
# If you have OS-specific or editor-specific files to ignore,
# such as *.swp or .DS_Store, put those in your global
# ~/.gitignore and put this in your ~/.gitconfig:
#
# [core]
# excludesfile = ~/.gitignore
#
# Cheers!
# -andrewrk
.zig-cache/
zig-out/
/release/
/debug/
/build/
/build-*/
/docgen_tmp/
# Although this was renamed to .zig-cache, let's leave it here for a few
# releases to make it less annoying to work with multiple branches.
zig-cache/

View File

@ -0,0 +1,97 @@
const std = @import("std");
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{ .default_target = .{ .abi = .msvc } });
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{
.name = "simple",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
// This declares intent for the library to be installed into the standard
// location when the user invokes the "install" step (the default step when
// running `zig build`).
b.installArtifact(lib);
const exe = b.addExecutable(.{
.name = "simple",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
// Add support for icsneo
exe.linkLibC();
exe.addIncludePath(b.path("../../../../include"));
exe.addLibraryPath(b.path("../../../../build"));
exe.linkSystemLibrary("icsneo");
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
// step when running `zig build`).
b.installArtifact(exe);
// This *creates* a Run step in the build graph, to be executed when another
// step is evaluated that depends on it. The next line below will establish
// such a dependency.
const run_cmd = b.addRunArtifact(exe);
// By making the run step depend on the install step, it will be run from the
// installation directory rather than directly from within the cache directory.
// This is not necessary, however, if the application depends on other installed
// files, this ensures they will be present and in the expected location.
run_cmd.step.dependOn(b.getInstallStep());
// This allows the user to pass arguments to the application in the build
// command itself, like this: `zig build run -- arg1 arg2 etc`
if (b.args) |args| {
run_cmd.addArgs(args);
}
// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build run`
// This will evaluate the `run` step rather than the default, which is "install".
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const lib_unit_tests = b.addTest(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const exe_unit_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&run_exe_unit_tests.step);
}

View File

@ -0,0 +1,72 @@
.{
// This is the default name used by packages depending on this one. For
// example, when a user runs `zig fetch --save <url>`, this field is used
// as the key in the `dependencies` table. Although the user can choose a
// different name, most users will stick with this provided value.
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "simple",
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
// This field is optional.
// This is currently advisory only; Zig does not yet do anything
// with this value.
//.minimum_zig_version = "0.11.0",
// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.dependencies = .{
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
//.example = .{
// // When updating this field to a new URL, be sure to delete the corresponding
// // `hash`, otherwise you are communicating that you expect to find the old hash at
// // the new URL.
// .url = "https://example.com/foo.tar.gz",
//
// // This is computed from the file contents of the directory of files that is
// // obtained after fetching `url` and applying the inclusion rules given by
// // `paths`.
// //
// // This field is the source of truth; packages do not come from a `url`; they
// // come from a `hash`. `url` is just one of many possible mirrors for how to
// // obtain a package matching this `hash`.
// //
// // Uses the [multihash](https://multiformats.io/multihash/) format.
// .hash = "...",
//
// // When this is provided, the package is found in a directory relative to the
// // build root. In this case the package's hash is irrelevant and therefore not
// // computed. This field and `url` are mutually exclusive.
// .path = "foo",
//
// // When this is set to `true`, a package is declared to be lazily
// // fetched. This makes the dependency only get fetched if it is
// // actually used.
// .lazy = false,
//},
},
// Specifies the set of files and directories that are included in this package.
// Only files and directories listed here are included in the `hash` that
// is computed for this package. Only files listed here will remain on disk
// when using the zig package manager. As a rule of thumb, one should list
// files required for compilation plus any license(s).
// Paths are relative to the build root. Use the empty string (`""`) to refer to
// the build root itself.
// A directory listed here means that all files within, recursively, are included.
.paths = .{
"build.zig",
"build.zig.zon",
"src",
// For example...
//"LICENSE",
//"README.md",
},
}

View File

@ -0,0 +1,34 @@
const std = @import("std");
const print = @import("std").debug.print;
const ics = @cImport({
@cInclude("icsneo/icsneo.h");
});
pub fn find_all() !void {
// Find devices connected to host.
const MAX_DEVICE_COUNT: u32 = 255;
var device_buffer: [MAX_DEVICE_COUNT]?*ics.icsneo_device_t = undefined;
var devices_count: u32 = MAX_DEVICE_COUNT;
var res: ics.icsneo_error_t = ics.icsneo_device_find_all(&device_buffer, &devices_count, null);
if (res != ics.icsneo_error_success) {
print("Failed to find device(s) with error: {}\n", .{res});
}
// Lets just take a slice of the entire device buffer
const devices = device_buffer[0..devices_count];
print("Found {} devices!\n", .{devices.len});
// Lets display all the devices we found.
for (devices, 1..) |device, i| {
var description: [128]u8 = [_:0]u8{'a'} ** 128;
var description_length: u32 = 128;
res = ics.icsneo_device_get_description(device, &description, &description_length);
if (res != ics.icsneo_error_success) {
print("Failed to find devices with error: {}\n", .{res});
}
print("\t{}. {s}\n", .{ i, description });
}
}
pub fn main() !void {
try find_all();
}

View File

@ -0,0 +1,13 @@
//! By convention, root.zig is the root source file when making a library. If
//! you are making an executable, the convention is to delete this file and
//! start with main.zig instead.
const std = @import("std");
const testing = std.testing;
export fn add(a: i32, b: i32) i32 {
return a + b;
}
test "basic add functionality" {
try testing.expect(add(3, 7) == 10);
}

View File

@ -20,8 +20,10 @@ enum class PCMType : uint8_t {
using ChannelMap = std::unordered_map<uint8_t, uint8_t>;
class A2BMessage : public Frame {
class A2BMessage : public BusMessage {
public:
const icsneo_msg_bus_type_t getBusType() const final { return icsneo_msg_bus_type_a2b; }
static constexpr size_t maxAudioBufferSize = 2048;
enum class TDMMode : uint8_t {

View File

@ -64,11 +64,11 @@ enum class AppErrorType : uint16_t {
AppNoError = 255
};
class AppErrorMessage : public RawMessage {
class AppErrorMessage : public InternalMessage {
public:
AppErrorMessage() : RawMessage(Message::Type::AppError, Network::NetID::RED_App_Error) {}
AppErrorMessage() : InternalMessage(Message::Type::AppError, _icsneo_netid_t::icsneo_netid_red_app_error) {}
uint16_t errorType;
Network::NetID errorNetID;
_icsneo_netid_t errorNetID;
uint32_t timestamp10us;
uint32_t timestamp10usMSB;

View File

@ -7,8 +7,10 @@
namespace icsneo {
class CANMessage : public Frame {
class CANMessage : public BusMessage {
public:
const icsneo_msg_bus_type_t getBusType() const final { return icsneo_msg_bus_type_can; }
uint32_t arbid;
uint8_t dlcOnWire;
bool isRemote = false; // Not allowed if CAN FD

View File

@ -7,9 +7,9 @@
namespace icsneo {
class DiskDataMessage : public RawMessage {
class DiskDataMessage : public InternalMessage {
public:
DiskDataMessage(std::vector<uint8_t>&& d) : RawMessage(Network::NetID::DiskData) {
DiskDataMessage(std::vector<uint8_t>&& d) : InternalMessage(_icsneo_netid_t::icsneo_netid_disk_data) {
data = std::move(d);
}
};

View File

@ -31,8 +31,10 @@ struct MACAddress {
}
};
class EthernetMessage : public Frame {
class EthernetMessage : public BusMessage {
public:
const icsneo_msg_bus_type_t getBusType() const final { return icsneo_msg_bus_type_ethernet; }
bool preemptionEnabled = false;
uint8_t preemptionFlags = 0;
bool fcsAvailable = false;

View File

@ -9,7 +9,7 @@
namespace icsneo {
class ExtendedDataMessage : public Frame {
class ExtendedDataMessage : public InternalMessage {
public:
#pragma pack(push, 2)
struct ExtendedDataHeader {

View File

@ -13,8 +13,8 @@ namespace icsneo {
class CANMessageFilter : public MessageFilter {
public:
CANMessageFilter() : MessageFilter(Network::Type::CAN), arbid(INVALID_ARBID) { messageType = Message::Type::Frame; }
CANMessageFilter(uint32_t arbid) : MessageFilter(Network::Type::CAN), arbid(arbid) { messageType = Message::Type::Frame; }
CANMessageFilter() : MessageFilter(icsneo_msg_bus_type_can), arbid(INVALID_ARBID) { messageType = Message::Type::BusMessage; }
CANMessageFilter(uint32_t arbid) : MessageFilter(icsneo_msg_bus_type_can), arbid(arbid) { messageType = Message::Type::BusMessage; }
bool match(const std::shared_ptr<Message>& message) const {
if(!MessageFilter::match(message))

View File

@ -13,11 +13,11 @@ class MessageFilter {
public:
MessageFilter() {}
MessageFilter(Message::Type type) : includeInternalInAny(neomessagetype_t(type) & 0x8000), messageType(type) {}
MessageFilter(Network::NetID netid) : MessageFilter(Network::GetTypeOfNetID(netid, false), netid) {} // Messages on the communication layer are never encoded as VNET ID + common ID, so skip the expansion step
MessageFilter(Network::Type type, Network::NetID net = Network::NetID::Any) : networkType(type), netid(net) {
// If a Network::Type::Internal is used, we want to also get internal Message::Types
MessageFilter(_icsneo_netid_t netid) : MessageFilter(Network::GetTypeOfNetID(netid, false), netid) {} // Messages on the communication layer are never encoded as VNET ID + common ID, so skip the expansion step
MessageFilter(icsneo_msg_bus_type_t type, _icsneo_netid_t net = _icsneo_netid_t::icsneo_netid_any) : networkType(type), netid(net) {
// If a icsneo_msg_bus_type_internal is used, we want to also get internal Message::Types
// The NetID we want may be in there
includeInternalInAny = (networkType == Network::Type::Internal);
includeInternalInAny = (networkType == icsneo_msg_bus_type_internal);
}
virtual ~MessageFilter() = default;
// When getting "all" types of messages, include the ones marked as "internal only"
@ -27,14 +27,14 @@ public:
if(!matchMessageType(message->type))
return false;
if(message->type == Message::Type::Frame || message->type == Message::Type::Main51 ||
message->type == Message::Type::RawMessage || message->type == Message::Type::ReadSettings) {
const auto frame = std::static_pointer_cast<RawMessage>(message);
if(message->type == Message::Type::BusMessage || message->type == Message::Type::Main51 ||
message->type == Message::Type::InternalMessage || message->type == Message::Type::ReadSettings) {
const auto frame = std::static_pointer_cast<InternalMessage>(message);
if(!matchNetworkType(frame->network.getType()))
return false;
if(!matchNetID(frame->network.getNetID()))
return false;
} else if (netid != Network::NetID::Any || networkType != Network::Type::Any) {
} else if (netid != _icsneo_netid_t::icsneo_netid_any || networkType != icsneo_msg_bus_type_any) {
return false; // Filtering on a NetID or Type, but this message doesn't have one
}
return true;
@ -48,16 +48,16 @@ protected:
return messageType == mtype;
}
Network::Type networkType = Network::Type::Any;
bool matchNetworkType(Network::Type mtype) const {
if(networkType == Network::Type::Any && (mtype != Network::Type::Internal || includeInternalInAny))
icsneo_msg_bus_type_t networkType = icsneo_msg_bus_type_any;
bool matchNetworkType(icsneo_msg_bus_type_t mtype) const {
if(networkType == icsneo_msg_bus_type_any && (mtype != icsneo_msg_bus_type_internal || includeInternalInAny))
return true;
return networkType == mtype;
}
Network::NetID netid = Network::NetID::Any;
bool matchNetID(Network::NetID mnetid) const {
if(netid == Network::NetID::Any)
_icsneo_netid_t netid = _icsneo_netid_t::icsneo_netid_any;
bool matchNetID(_icsneo_netid_t mnetid) const {
if(netid == _icsneo_netid_t::icsneo_netid_any)
return true;
return netid == mnetid;
}

View File

@ -7,9 +7,9 @@
namespace icsneo {
class FlashMemoryMessage : public RawMessage {
class FlashMemoryMessage : public InternalMessage {
public:
FlashMemoryMessage() : RawMessage(Message::Type::RawMessage, Network::NetID::RED_INT_MEMORYREAD) {}
FlashMemoryMessage() : InternalMessage(Message::Type::InternalMessage, _icsneo_netid_t::icsneo_netid_red_int_memoryread) {}
uint16_t startAddress = 0;
};

View File

@ -10,8 +10,9 @@
namespace icsneo {
class FlexRayMessage : public Frame {
class FlexRayMessage : public BusMessage {
public:
const icsneo_msg_bus_type_t getBusType() const final { return icsneo_msg_bus_type_flexray; }
uint16_t slotid = 0;
double tsslen = 0;
double framelen = 0;

View File

@ -8,8 +8,10 @@
namespace icsneo {
class I2CMessage : public Frame {
class I2CMessage : public BusMessage {
public:
const icsneo_msg_bus_type_t getBusType() const final { return icsneo_msg_bus_type_i2c; }
enum class DeviceMode : uint8_t {
Target = 0,
Controller = 1

View File

@ -8,8 +8,9 @@
namespace icsneo {
class ISO9141Message : public Frame {
class ISO9141Message : public BusMessage {
public:
const icsneo_msg_bus_type_t getBusType() const final { return icsneo_msg_bus_type_iso9141; }
std::array<uint8_t, 3> header;
bool isInit = false;
bool isBreak = false;

View File

@ -34,8 +34,10 @@ struct LINStatusFlags {
bool BreakOnly = false;
};
class LINMessage : public Frame {
class LINMessage : public BusMessage {
public:
const icsneo_msg_bus_type_t getBusType() const final { return icsneo_msg_bus_type_lin; }
enum class Type : uint8_t {
NOT_SET = 0,
LIN_COMMANDER_MSG,

View File

@ -8,9 +8,9 @@
#include "icsneo/communication/livedata.h"
namespace icsneo {
class LiveDataMessage : public RawMessage {
class LiveDataMessage : public InternalMessage {
public:
LiveDataMessage() : RawMessage(Message::Type::LiveData, Network::NetID::ExtendedCommand) {}
LiveDataMessage() : InternalMessage(Message::Type::LiveData, _icsneo_netid_t::icsneo_netid_extended_command) {}
LiveDataHandle handle;
LiveDataCommand cmd;
};

View File

@ -8,9 +8,9 @@
namespace icsneo {
class Main51Message : public RawMessage {
class Main51Message : public InternalMessage {
public:
Main51Message() : RawMessage(Message::Type::Main51, Network::NetID::Main51) {}
Main51Message() : InternalMessage(Message::Type::Main51, _icsneo_netid_t::icsneo_netid_main51) {}
Command command = Command(0);
bool forceShortFormat = false; // Necessary for EnableNetworkCom and EnableNetworkComEx
};

View File

@ -7,8 +7,10 @@
namespace icsneo {
class MDIOMessage : public Frame {
class MDIOMessage : public BusMessage {
public:
const icsneo_msg_bus_type_t getBusType() const final { return icsneo_msg_bus_type_mdio; }
enum class Clause : uint8_t {
Clause45 = 0,
Clause22 = 1

View File

@ -7,14 +7,48 @@ typedef uint16_t neomessagetype_t;
#ifdef __cplusplus
#include "icsneo/communication/network.h"
#include "icsneo/icsneotypes.h"
#include <vector>
#include <sstream>
#include <string>
namespace icsneo {
class Message {
class AbstractMessage {
public:
virtual const icsneo_msg_type_t getMsgType() const = 0;
};
class Message : public AbstractMessage {
public:
virtual const icsneo_msg_type_t getMsgType() const { return icsneo_msg_type_device; }
/**
* @brief Get the string representation of the message type
*
* @return String representation of the message type
*
* @see AbstractMessage::getMsgType()
*/
static std::string getMsgTypeName(icsneo_msg_type_t msg_type) {
switch (msg_type) {
case icsneo_msg_type_device:
return "Device";
case icsneo_msg_type_internal:
return "Internal";
case icsneo_msg_type_bus:
return "Bus";
// Don't default here so we can rely on the compiler to warn us about missing cases
};
std::stringstream ss;
ss << "Unknown (" << (int)msg_type << ")";
return ss.str();
}
enum class Type : neomessagetype_t {
Frame = 0,
BusMessage = 0,
CANErrorCount = 0x100,
@ -23,7 +57,7 @@ public:
// Past 0x8000 are all for internal use only
Invalid = 0x8000,
RawMessage = 0x8001,
InternalMessage = 0x8001,
ReadSettings = 0x8002,
ResetStatus = 0x8003,
DeviceVersion = 0x8004,
@ -49,22 +83,32 @@ public:
uint64_t timestamp = 0;
};
class RawMessage : public Message {
class InternalMessage : public Message {
public:
RawMessage(Message::Type type = Message::Type::RawMessage) : Message(type) {}
RawMessage(Message::Type type, Network net) : Message(type), network(net) {}
RawMessage(Network net) : Message(Message::Type::RawMessage), network(net) {}
RawMessage(Network net, std::vector<uint8_t> d) : Message(Message::Type::RawMessage), network(net), data(d) {}
InternalMessage(Message::Type type = Message::Type::InternalMessage) : Message(type) {}
InternalMessage(Message::Type type, Network net) : Message(type), network(net) {}
InternalMessage(Network net) : Message(Message::Type::InternalMessage), network(net) {}
InternalMessage(Network net, std::vector<uint8_t> d) : Message(Message::Type::InternalMessage), network(net), data(d) {}
virtual const icsneo_msg_type_t getMsgType() const { return icsneo_msg_type_internal; }
Network network;
std::vector<uint8_t> data;
};
class Frame : public RawMessage {
class BusMessage : public InternalMessage {
public:
Frame() : RawMessage(Message::Type::Frame) {}
BusMessage() : InternalMessage(Message::Type::BusMessage) {}
const icsneo_msg_type_t getMsgType() const final { return icsneo_msg_type_bus; }
virtual const icsneo_msg_bus_type_t getBusType() const = 0;
// Description ID of the message. This is used for filtering / tracking in firmware and driver.
// This is equivalent to icsSpyMessage::DescriptionID
uint16_t description = 0;
// weather the message was originally transmitted on the bus. This is equivalent to
// SPY_STATUS_TX_MSG bit field in icsSpyMessage::StatusBitField
bool transmitted = false;
bool error = false;
};

View File

@ -115,7 +115,7 @@ typedef struct {
uint8_t _reserved1[16];
uint64_t timestamp;
uint64_t _reservedTimestamp;
uint8_t _reserved2[sizeof(size_t) * 2 + 7 + sizeof(neonetid_t) + sizeof(neonettype_t)];
uint8_t _reserved2[sizeof(size_t) * 2 + 7 + sizeof(icsneo_netid_t) + sizeof(icsneo_msg_bus_type_t)];
neomessagetype_t messageType;
uint8_t _reserved3[12];
} neomessage_t; // 72 bytes total
@ -128,8 +128,8 @@ typedef struct {
const uint8_t* data;
size_t length;
uint8_t header[4];
neonetid_t netid;
neonettype_t type;
icsneo_netid_t netid;
icsneo_msg_bus_type_t type;
uint8_t _reserved0;
uint16_t description;
neomessagetype_t messageType;
@ -143,8 +143,8 @@ typedef struct {
const uint8_t* data;
size_t length;
uint32_t arbid;
neonetid_t netid;
neonettype_t type;
icsneo_netid_t netid;
icsneo_msg_bus_type_t type;
uint8_t dlcOnWire;
uint16_t description;
neomessagetype_t messageType;
@ -159,8 +159,8 @@ typedef struct {
uint8_t transmitErrorCount;
uint8_t receiveErrorCount;
uint8_t _reserved3[5];
neonetid_t netid;
neonettype_t type;
icsneo_netid_t netid;
icsneo_msg_bus_type_t type;
neomessagetype_t messageType;
uint8_t _reserved4[12];
} neomessage_can_error_t;
@ -173,8 +173,8 @@ typedef struct {
size_t length;
uint8_t preemptionFlags;
uint8_t _reservedHeader[3];
neonetid_t netid;
neonettype_t type;
icsneo_netid_t netid;
icsneo_msg_bus_type_t type;
uint8_t _reserved0;
uint16_t description;
neomessagetype_t messageType;
@ -199,8 +199,8 @@ typedef struct {
const uint8_t* data;
size_t length;
uint8_t header[4];
neonetid_t netid;
neonettype_t type;
icsneo_netid_t netid;
icsneo_msg_bus_type_t type;
neomessage_linstatus_t linStatus;
uint16_t description;
neomessagetype_t messageType;

View File

@ -7,9 +7,9 @@
namespace icsneo {
class NeoReadMemorySDMessage : public RawMessage {
class NeoReadMemorySDMessage : public InternalMessage {
public:
NeoReadMemorySDMessage() : RawMessage(Message::Type::RawMessage, Network::NetID::NeoMemorySDRead) {}
NeoReadMemorySDMessage() : InternalMessage(Message::Type::InternalMessage, _icsneo_netid_t::icsneo_netid_neo_memory_sdread) {}
uint32_t startAddress = 0;
};

View File

@ -8,9 +8,9 @@
namespace icsneo {
class ReadSettingsMessage : public RawMessage {
class ReadSettingsMessage : public InternalMessage {
public:
ReadSettingsMessage() : RawMessage(Message::Type::ReadSettings, Network::NetID::ReadSettings) {}
ReadSettingsMessage() : InternalMessage(Message::Type::ReadSettings, _icsneo_netid_t::icsneo_netid_read_settings) {}
enum class Response : uint8_t {
OK = 0,

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,9 @@ namespace icsneo {
typedef uint16_t icscm_bitfield;
std::optional<uint8_t> CAN_DLCToLength(uint8_t length, bool fd);
std::optional<uint8_t> CAN_LengthToDLC(size_t dataLength, bool fd);
struct HardwareCANPacket {
static std::shared_ptr<Message> DecodeToMessage(const std::vector<uint8_t>& bytestream);
static bool EncodeFromMessage(const CANMessage& message, std::vector<uint8_t>& bytestream, const device_eventhandler_t& report);

View File

@ -53,7 +53,7 @@
#define ICSNEO_FINDABLE_DEVICE_BASE(className, type) \
static constexpr DeviceType::Enum DEVICE_TYPE = type; \
static constexpr icsneo_devicetype_t DEVICE_TYPE = type; \
className(const FoundDevice& dev) : className(neodevice_t(dev, DEVICE_TYPE), dev.makeDriver) {}
// Devices which are discernable by the first two characters of their serial
@ -91,7 +91,7 @@ public:
std::string getSerial() const { return data.serial; }
uint32_t getSerialNumber() const { return Device::SerialStringToNum(getSerial()); }
const neodevice_t& getNeoDevice() const { return data; }
virtual std::string getProductName() const { return getType().getGenericProductName(); }
virtual std::string getProductName() const { return getType().getProductName(); }
std::string describe() const;
friend std::ostream& operator<<(std::ostream& os, const Device& device) {
os << device.describe();
@ -212,8 +212,8 @@ public:
int addMessageCallback(const std::shared_ptr<MessageCallback>& cb) { return com->addMessageCallback(cb); }
bool removeMessageCallback(int id) { return com->removeMessageCallback(id); }
bool transmit(std::shared_ptr<Frame> frame);
bool transmit(std::vector<std::shared_ptr<Frame>> frames);
bool transmit(std::shared_ptr<BusMessage> frame);
bool transmit(std::vector<std::shared_ptr<BusMessage>> frames);
void setWriteBlocks(bool blocks);
@ -226,8 +226,8 @@ public:
return std::find(supportedTXNetworks.begin(), supportedTXNetworks.end(), net) != supportedTXNetworks.end();
}
virtual size_t getNetworkCountByType(Network::Type) const;
virtual Network getNetworkByNumber(Network::Type, size_t) const;
virtual size_t getNetworkCountByType(icsneo_msg_bus_type_t) const;
virtual Network getNetworkByNumber(icsneo_msg_bus_type_t, size_t) const;
std::shared_ptr<HardwareInfo> getHardwareInfo(std::chrono::milliseconds timeout = std::chrono::milliseconds(100));
@ -728,11 +728,11 @@ public:
virtual bool supportsTC10() const { return false; }
bool requestTC10Wake(Network::NetID network);
bool requestTC10Wake(_icsneo_netid_t network);
bool requestTC10Sleep(Network::NetID network);
bool requestTC10Sleep(_icsneo_netid_t network);
std::optional<TC10StatusMessage> getTC10Status(Network::NetID network);
std::optional<TC10StatusMessage> getTC10Status(_icsneo_netid_t network);
protected:
bool online = false;
@ -835,7 +835,7 @@ protected:
void handleInternalMessage(std::shared_ptr<Message> message);
virtual void handleDeviceStatus(const std::shared_ptr<RawMessage>&) {}
virtual void handleDeviceStatus(const std::shared_ptr<InternalMessage>&) {}
neodevice_t& getWritableNeoDevice() { return data; }

View File

@ -1,88 +1,22 @@
#ifndef __DEVICETYPE_H_
#define __DEVICETYPE_H_
#pragma once
// Hold the length of the longest name, so that C applications can allocate memory accordingly
// Currently the longest is "Intrepid Ethernet Evaluation Board"
#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
#include <stdint.h>
typedef uint32_t devicetype_t;
#else
#include <ostream>
#include <icsneo/icsneotypes.h>
#ifdef __cplusplus
#include <cstdint>
typedef uint32_t devicetype_t;
#include <string>
namespace icsneo {
class DeviceType {
public:
// 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 {
Unknown = (0x00000000),
BLUE = (0x00000001),
ECU_AVB = (0x00000002),
RADSupermoon = (0x00000003),
DW_VCAN = (0x00000004),
RADMoon2 = (0x00000005),
RADMars = (0x00000006),
VCAN4_1 = (0x00000007),
FIRE = (0x00000008),
RADPluto = (0x00000009),
VCAN4_2EL = (0x0000000a),
RADIO_CANHUB = (0x0000000b),
NEOECU12 = (0x0000000c),
OBD2_LCBADGE = (0x0000000d),
RADMoonDuo = (0x0000000e),
FIRE3 = (0x0000000f),
VCAN3 = (0x00000010),
RADJupiter = (0x00000011),
VCAN4_IND = (0x00000012),
RADGigastar = (0x00000013),
RED2 = (0x00000014),
EtherBADGE = (0x00000016),
RAD_A2B = (0x00000017),
RADEpsilon = (0x00000018),
RADGalaxy2 = (0x00000021),
RADMoon3 = (0x00000023),
RADComet = (0x00000024),
FIRE3_FlexRay = (0x00000025),
Connect = (0x00000026),
RADComet3 = (0x00000027),
RADMoonT1S = (0x00000028),
RADGigastar2 = (0x00000029),
RED = (0x00000040),
ECU = (0x00000080),
IEVB = (0x00000100),
Pendant = (0x00000200),
OBD2_PRO = (0x00000400),
ECUChip_UART = (0x00000800),
PLASMA = (0x00001000),
DONT_REUSE0 = (0x00002000), // Previously FIRE_VNET
NEOAnalog = (0x00004000),
CT_OBD = (0x00008000),
DONT_REUSE1 = (0x00010000), // Previously PLASMA_1_12
DONT_REUSE2 = (0x00020000), // Previously PLASMA_1_13
ION = (0x00040000),
RADStar = (0x00080000),
DONT_REUSE3 = (0x00100000), // Previously ION3
VCAN4_4 = (0x00200000),
VCAN4_2 = (0x00400000),
CMProbe = (0x00800000),
EEVB = (0x01000000),
VCANrf = (0x02000000),
FIRE2 = (0x04000000),
Flex = (0x08000000),
RADGalaxy = (0x10000000),
RADStar2 = (0x20000000),
VividCAN = (0x40000000),
OBD2_SIM = (0x80000000)
};
/**
* Get the generic product name for this device type.
*
@ -90,201 +24,133 @@ public:
* as the product name may change based on device-specific factors, such as serial
* number.
*/
static const char* GetGenericProductName(DeviceType::Enum type) {
template<typename T>
static std::string getGenericProductName(T deviceType) {
// Adding something? Make sure you update DEVICE_TYPE_LONGEST_NAME at the top!
switch(type) {
case Unknown:
switch(static_cast<icsneo_devicetype_t>(deviceType)) {
case icsneo_devicetype_unknown:
return "Unknown";
case BLUE:
case icsneo_devicetype_blue:
return "neoVI BLUE";
case ECU_AVB:
case icsneo_devicetype_ecu_avb:
return "neoECU AVB/TSN";
case RADSupermoon:
case icsneo_devicetype_rad_supermoon:
return "RAD-Supermoon";
case DW_VCAN:
case icsneo_devicetype_dw_vcan:
return "DW_VCAN";
case RADMoon2:
case icsneo_devicetype_rad_moon2:
return "RAD-Moon 2";
case RADMars:
case icsneo_devicetype_rad_mars:
return "RAD-Mars";
case VCAN4_1:
case icsneo_devicetype_vcan41:
return "ValueCAN 4-1";
case FIRE:
case icsneo_devicetype_fire:
return "neoVI FIRE";
case RADPluto:
case icsneo_devicetype_rad_pluto:
return "RAD-Pluto";
case VCAN4_2EL:
case icsneo_devicetype_vcan42_el:
return "ValueCAN 4-2EL";
case RADIO_CANHUB:
case icsneo_devicetype_radio_canhub:
return "RAD-IO2 CANHub";
case NEOECU12:
case icsneo_devicetype_neo_ecu12:
return "neoECU 12";
case OBD2_LCBADGE:
case icsneo_devicetype_obd2_lc_badge:
return "neoOBD2 LC BADGE";
case RADMoonDuo:
case icsneo_devicetype_rad_moon_duo:
return "RAD-Moon Duo";
case FIRE3:
case icsneo_devicetype_fire3:
return "neoVI FIRE 3";
case VCAN3:
case icsneo_devicetype_vcan3:
return "ValueCAN 3";
case RADJupiter:
case icsneo_devicetype_rad_jupiter:
return "RAD-Jupiter";
case VCAN4_IND:
case icsneo_devicetype_vcan4_industrial:
return "ValueCAN 4 Industrial";
case RADGigastar:
case icsneo_devicetype_rad_gigastar:
return "RAD-Gigastar";
case RED2:
case icsneo_devicetype_red2:
return "neoVI RED 2";
case EtherBADGE:
case icsneo_devicetype_etherbadge:
return "EtherBADGE";
case RAD_A2B:
case icsneo_devicetype_rad_a2b:
return "RAD-A2B";
case RADEpsilon:
case icsneo_devicetype_rad_epsilon:
return "RAD-Epsilon";
case RADMoon3:
case icsneo_devicetype_rad_moon3:
return "RAD-Moon 3";
case RADComet:
case icsneo_devicetype_rad_comet:
return "RAD-Comet";
case RED:
case icsneo_devicetype_red:
return "neoVI RED";
case ECU:
case icsneo_devicetype_ecu:
return "neoECU";
case IEVB:
case icsneo_devicetype_ievb:
return "IEVB";
case Pendant:
case icsneo_devicetype_pendant:
return "Pendant";
case OBD2_PRO:
case icsneo_devicetype_obd2_pro:
return "neoOBD2 PRO";
case ECUChip_UART:
case icsneo_devicetype_ecuchip_uart:
return "neoECU Chip UART";
case PLASMA:
case icsneo_devicetype_plasma:
return "neoVI PLASMA";
case NEOAnalog:
case icsneo_devicetype_neo_analog:
return "NEOAnalog";
case CT_OBD:
case icsneo_devicetype_ct_obd:
return "CT_OBD";
case ION:
case icsneo_devicetype_ion:
return "neoVI ION";
case RADStar:
case icsneo_devicetype_rad_star:
return "RAD-Star";
case VCAN4_4:
case icsneo_devicetype_vcan44:
return "ValueCAN 4-4";
case VCAN4_2:
case icsneo_devicetype_vcan42:
return "ValueCAN 4-2";
case CMProbe:
case icsneo_devicetype_cm_probe:
return "CMProbe";
case EEVB:
case icsneo_devicetype_eevb:
return "Intrepid Ethernet Evaluation Board";
case VCANrf:
case icsneo_devicetype_vcan_rf:
return "ValueCAN.rf";
case FIRE2:
case icsneo_devicetype_fire2:
return "neoVI FIRE 2";
case Flex:
case icsneo_devicetype_flex:
return "neoVI Flex";
case RADGalaxy:
case icsneo_devicetype_rad_galaxy:
return "RAD-Galaxy";
case RADGalaxy2:
case icsneo_devicetype_rad_galaxy2:
return "RAD-Galaxy 2";
case RADStar2:
case icsneo_devicetype_rad_star2:
return "RAD-Star 2";
case VividCAN:
case icsneo_devicetype_vividcan:
return "VividCAN";
case OBD2_SIM:
case icsneo_devicetype_obd2_sim:
return "neoOBD2 SIM";
case FIRE3_FlexRay:
case icsneo_devicetype_fire3_flexray:
return "neoVI FIRE3 FlexRay";
case RADComet3:
case icsneo_devicetype_rad_comet3:
return "RAD-Comet 3";
case RADMoonT1S:
case icsneo_devicetype_rad_moon_t1s:
return "RAD-Moon T1S";
case Connect:
case icsneo_devicetype_connect:
return "neoVI Connect";
case RADGigastar2:
case icsneo_devicetype_rad_gigastar2:
return "RAD-Gigastar 2";
case DONT_REUSE0:
case DONT_REUSE1:
case DONT_REUSE2:
case DONT_REUSE3:
// Intentionally don't use default so that the compiler throws a warning when something is added
return "Unknown neoVI";
// Intentionally don't use default so that the compiler throws a warning when something is added
}
return "Unknown neoVI";
}
DeviceType() { value = DeviceType::Enum::Unknown; }
DeviceType(devicetype_t netid) { value = (DeviceType::Enum)netid; }
DeviceType(DeviceType::Enum netid) { value = netid; }
DeviceType::Enum getDeviceType() const { return value; }
std::string getGenericProductName() const { return GetGenericProductName(getDeviceType()); }
operator devicetype_t() const { return getDeviceType(); }
DeviceType(icsneo_devicetype_t device_type) { deviceType = device_type; }
icsneo_devicetype_t getDeviceType() const { return deviceType; }
// Returns the generic name of the device - This doesn't include the serial.
std::string getProductName() const { return DeviceType::getGenericProductName(getDeviceType()); }
private:
DeviceType::Enum value;
icsneo_devicetype_t deviceType;
};
}
}; // namespace icsneo
#endif // __cplusplus
#ifdef __ICSNEOC_H_ // We are using the C API, so we want C-compatible defines
#define ICSNEO_DEVICETYPE_UNKNOWN ((devicetype_t)0x00000000)
#define ICSNEO_DEVICETYPE_BLUE ((devicetype_t)0x00000001)
#define ICSNEO_DEVICETYPE_ECU_AVB ((devicetype_t)0x00000002)
#define ICSNEO_DEVICETYPE_RADSUPERMOON ((devicetype_t)0x00000003)
#define ICSNEO_DEVICETYPE_DW_VCAN ((devicetype_t)0x00000004)
#define ICSNEO_DEVICETYPE_RADMOON2 ((devicetype_t)0x00000005)
#define ICSNEO_DEVICETYPE_RADMARS ((devicetype_t)0x00000006)
#define ICSNEO_DEVICETYPE_VCAN4_1 ((devicetype_t)0x00000007)
#define ICSNEO_DEVICETYPE_FIRE ((devicetype_t)0x00000008)
#define ICSNEO_DEVICETYPE_RADPLUTO ((devicetype_t)0x00000009)
#define ICSNEO_DEVICETYPE_VCAN4_2EL ((devicetype_t)0x0000000a)
#define ICSNEO_DEVICETYPE_RADIO_CANHUB ((devicetype_t)0x0000000b)
#define ICSNEO_DEVICETYPE_NEOECU12 ((devicetype_t)0x0000000c)
#define ICSNEO_DEVICETYPE_OBD2_LCBADGE ((devicetype_t)0x0000000d)
#define ICSNEO_DEVICETYPE_RADMOONDUO ((devicetype_t)0x0000000e)
#define ICSNEO_DEVICETYPE_FIRE3 ((devicetype_t)0x0000000f)
#define ICSNEO_DEVICETYPE_VCAN3 ((devicetype_t)0x00000010)
#define ICSNEO_DEVICETYPE_RADJUPITER ((devicetype_t)0x00000011)
#define ICSNEO_DEVICETYPE_VCAN4_IND ((devicetype_t)0x00000012)
#define ICSNEO_DEVICETYPE_RADGIGASTAR ((devicetype_t)0x00000013)
#define ICSNEO_DEVICETYPE_RED2 ((devicetype_t)0x00000014)
#define ICSNEO_DEVICETYPE_ETHERBADGE ((devicetype_t)0x00000016)
#define ICSNEO_DEVICETYPE_RAD_A2B ((devicetype_t)0x00000017)
#define ICSNEO_DEVICETYPE_RADEPSILON ((devicetype_t)0x00000018)
#define ICSNEO_DEVICETYPE_RADGALAXY2 ((devicetype_t)0x00000021)
#define ICSNEO_DEVICETYPE_RADMoon3 ((devicetype_t)0x00000023)
#define ICSNEO_DEVICETYPE_RADCOMET ((devicetype_t)0x00000024)
#define ICSNEO_DEVICETYPE_FIRE3FLEXRAY ((devicetype_t)0x00000025)
#define ICSNEO_DEVICETYPE_CONNECT ((devicetype_t)0x00000026)
#define ICSNEO_DEVICETYPE_RADCOMET3 ((devicetype_t)0x00000027)
#define ICSNEO_DEVICETYPE_RADMOONT1S ((devicetype_t)0x00000028)
#define ICSNEO_DEVICETYPE_RADGIGASTAR2 ((devicetype_t)0x00000029)
#define ICSNEO_DEVICETYPE_RED ((devicetype_t)0x00000040)
#define ICSNEO_DEVICETYPE_ECU ((devicetype_t)0x00000080)
#define ICSNEO_DEVICETYPE_IEVB ((devicetype_t)0x00000100)
#define ICSNEO_DEVICETYPE_PENDANT ((devicetype_t)0x00000200)
#define ICSNEO_DEVICETYPE_OBD2_PRO ((devicetype_t)0x00000400)
#define ICSNEO_DEVICETYPE_ECUCHIP_UART ((devicetype_t)0x00000800)
#define ICSNEO_DEVICETYPE_PLASMA ((devicetype_t)0x00001000)
#define ICSNEO_DEVICETYPE_DONT_REUSE0 ((devicetype_t)0x00002000) // Previously FIRE_VNET
#define ICSNEO_DEVICETYPE_NEOANALOG ((devicetype_t)0x00004000)
#define ICSNEO_DEVICETYPE_CT_OBD ((devicetype_t)0x00008000)
#define ICSNEO_DEVICETYPE_DONT_REUSE1 ((devicetype_t)0x00010000) // Previously PLASMA_1_12
#define ICSNEO_DEVICETYPE_DONT_REUSE2 ((devicetype_t)0x00020000) // Previously PLASMA_1_13
#define ICSNEO_DEVICETYPE_ION ((devicetype_t)0x00040000)
#define ICSNEO_DEVICETYPE_RADSTAR ((devicetype_t)0x00080000)
#define ICSNEO_DEVICETYPE_DONT_REUSE3 ((devicetype_t)0x00100000) // Previously ION3
#define ICSNEO_DEVICETYPE_VCAN4_4 ((devicetype_t)0x00200000)
#define ICSNEO_DEVICETYPE_VCAN4_2 ((devicetype_t)0x00400000)
#define ICSNEO_DEVICETYPE_CMPROBE ((devicetype_t)0x00800000)
#define ICSNEO_DEVICETYPE_EEVB ((devicetype_t)0x01000000)
#define ICSNEO_DEVICETYPE_VCANRF ((devicetype_t)0x02000000)
#define ICSNEO_DEVICETYPE_FIRE2 ((devicetype_t)0x04000000)
#define ICSNEO_DEVICETYPE_FLEX ((devicetype_t)0x08000000)
#define ICSNEO_DEVICETYPE_RADGALAXY ((devicetype_t)0x10000000)
#define ICSNEO_DEVICETYPE_RADSTAR2 ((devicetype_t)0x20000000)
#define ICSNEO_DEVICETYPE_VIVIDCAN ((devicetype_t)0x40000000)
#define ICSNEO_DEVICETYPE_OBD2_SIM ((devicetype_t)0x80000000)
#endif
#endif
#endif // __cplusplus

View File

@ -33,7 +33,7 @@ public:
virtual void handleMessage(const std::shared_ptr<Message>&) {}
// Return true to continue transmitting, success should be written to if false is returned
virtual bool transmitHook(const std::shared_ptr<Frame>& frame, bool& success) { (void)frame; (void)success; return true; }
virtual bool transmitHook(const std::shared_ptr<BusMessage>& frame, bool& success) { (void)frame; (void)success; return true; }
protected:
Device& device;

View File

@ -25,7 +25,7 @@ public:
void onGoOffline() override;
void handleMessage(const std::shared_ptr<Message>& message) override;
bool transmitHook(const std::shared_ptr<Frame>& frame, bool& success) override;
bool transmitHook(const std::shared_ptr<BusMessage>& frame, bool& success) override;
std::shared_ptr<Controller> getController(uint8_t index) const {
if(index >= controllers.size())

Some files were not shown because too many files have changed in this diff Show More