mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-09-22 08:58:38 +02:00
Compare commits
59
Commits
1.2.0
...
87f45e060e
@@ -5,3 +5,6 @@ KERNEL=="ttyACM?", ATTRS{idVendor}=="093c", GROUP="users", MODE="0666"
|
||||
|
||||
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="093c", KERNEL=="ttyUSB*", \
|
||||
RUN+="/bin/sh -c 'echo $id:1.0>/sys/bus/usb/drivers/ftdi_sio/unbind'"
|
||||
|
||||
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="093c", DRIVER=="usbhid", \
|
||||
RUN+="/bin/sh -c 'echo $id:1.0>/sys/bus/usb/drivers/usbhid/unbind'"
|
||||
|
||||
+45
-7
@@ -11,6 +11,8 @@ option(LIBICSNEO_BUILD_DOCS "Build documentation. Don't use in Visual Studio." O
|
||||
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_ICSNEOC2 "Build dynamic C2 library" ON)
|
||||
option(LIBICSNEO_BUILD_ICSNEOC2_STATIC "Build static C2 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")
|
||||
@@ -170,10 +172,6 @@ if(LIBICSNEO_ENABLE_TCP)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
|
||||
# Extensions
|
||||
set(LIBICSNEO_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
foreach(EXT_PATH ${LIBICSNEO_EXTENSION_DIRS})
|
||||
@@ -289,6 +287,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/icsneoc2/version.rc.template ${CMAKE_CURRENT_BINARY_DIR}/generated/icsneoc2/version.rc)
|
||||
|
||||
foreach(EXTINC ${LIBICSNEO_EXTENSION_INCLUDES})
|
||||
message("Including " ${EXTINC})
|
||||
@@ -360,7 +359,7 @@ if(LIBICSNEO_ENABLE_DXX)
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(libredxx
|
||||
GIT_REPOSITORY https://github.com/Zeranoe/libredxx.git
|
||||
GIT_TAG e1fe2bd6ba6079b17037379d78f3f18024b389d7
|
||||
GIT_TAG e823a96c39a64ab41b7d1632dbe8f86bb854df83
|
||||
)
|
||||
set(LIBREDXX_DISABLE_INSTALL ON)
|
||||
FetchContent_MakeAvailable(libredxx)
|
||||
@@ -392,7 +391,7 @@ endif()
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(icspb
|
||||
GIT_REPOSITORY ${LIBICSNEO_ICSPB_REPO}
|
||||
GIT_TAG 48df5dd7fd0c38034f82a2f94e0eada404d5e2b9
|
||||
GIT_TAG 3339fa6b83a6b3e7704d41f5c2f2175cfc761a1f
|
||||
)
|
||||
FetchContent_MakeAvailable(icspb)
|
||||
target_link_libraries(icsneocpp PRIVATE icspb::icspb)
|
||||
@@ -426,6 +425,38 @@ if(LIBICSNEO_BUILD_ICSNEOC_STATIC)
|
||||
target_compile_options(icsneoc-static PRIVATE ${LIBICSNEO_COMPILER_WARNINGS})
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_ICSNEOC2)
|
||||
add_library(icsneoc2 SHARED api/icsneoc2/icsneoc2.cpp api/icsneoc2/icsneoc2settings.cpp api/icsneoc2/icsneoc2messages.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated/icsneoc2/version.rc)
|
||||
target_include_directories(icsneoc2
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:>
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
||||
target_link_libraries(icsneoc2 PRIVATE icsneocpp)
|
||||
target_compile_features(icsneoc2 PRIVATE cxx_auto_type cxx_constexpr cxx_lambdas cxx_nullptr cxx_range_for cxx_rvalue_references cxx_sizeof_member cxx_strong_enums)
|
||||
target_compile_options(icsneoc2 PRIVATE ${LIBICSNEO_COMPILER_WARNINGS})
|
||||
if(WIN32)
|
||||
set_target_properties(icsneoc2 PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_ICSNEOC2_STATIC)
|
||||
add_library(icsneoc2-static STATIC api/icsneoc2/icsneoc2.cpp api/icsneoc2/icsneoc2settings.cpp api/icsneoc2/icsneoc2messages.cpp)
|
||||
target_include_directories(icsneoc2-static
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:>
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
||||
target_link_libraries(icsneoc2-static PUBLIC icsneocpp)
|
||||
target_compile_features(icsneoc2-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(icsneoc2-static PUBLIC ICSNEOC2_BUILD_STATIC)
|
||||
target_compile_options(icsneoc2-static PRIVATE ${LIBICSNEO_COMPILER_WARNINGS})
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_ICSNEOLEGACY)
|
||||
add_library(icsneolegacy SHARED
|
||||
api/icsneolegacy/icsneolegacy.cpp
|
||||
@@ -467,6 +498,10 @@ endif()
|
||||
|
||||
add_subdirectory(bindings)
|
||||
|
||||
if(LIBICSNEO_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
|
||||
# googletest
|
||||
if(LIBICSNEO_BUILD_UNIT_TESTS)
|
||||
include(FetchContent)
|
||||
@@ -475,6 +510,7 @@ if(LIBICSNEO_BUILD_UNIT_TESTS)
|
||||
GIT_TAG 6986c2b575f77135401a4e1c65a7a42f20e18fef
|
||||
)
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
include(GoogleTest)
|
||||
|
||||
add_executable(libicsneo-unit-tests
|
||||
test/unit/main.cpp
|
||||
@@ -489,6 +525,7 @@ if(LIBICSNEO_BUILD_UNIT_TESTS)
|
||||
test/unit/livedataencoderdecodertest.cpp
|
||||
test/unit/ringbuffertest.cpp
|
||||
test/unit/apperrordecodertest.cpp
|
||||
test/unit/icsneoc2.cpp
|
||||
test/unit/windowsstrings.cpp
|
||||
test/unit/periodictest.cpp
|
||||
)
|
||||
@@ -497,12 +534,13 @@ if(LIBICSNEO_BUILD_UNIT_TESTS)
|
||||
|
||||
target_link_libraries(libicsneo-unit-tests gtest gtest_main)
|
||||
target_link_libraries(libicsneo-unit-tests icsneocpp)
|
||||
target_link_libraries(libicsneo-unit-tests icsneoc2-static)
|
||||
|
||||
target_include_directories(libicsneo-unit-tests PUBLIC ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_test(NAME libicsneo-unit-test-suite COMMAND libicsneo-unit-tests)
|
||||
gtest_discover_tests(libicsneo-unit-tests TEST_PREFIX "unit/" PROPERTIES LABELS "unit")
|
||||
endif()
|
||||
|
||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2018-2025 Intrepid Control Systems, Inc.
|
||||
Copyright (c) 2018-2026 Intrepid Control Systems, Inc.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
@@ -8,7 +8,8 @@ each of the respective APIs.
|
||||
|
||||
- [C++](https://libicsneo.readthedocs.io/en/latest/icsneocpp/)
|
||||
- [Python](https://libicsneo.readthedocs.io/en/latest/icsneopy/)
|
||||
- [C](https://libicsneo.readthedocs.io/en/latest/icsneoc/)
|
||||
- [C](https://libicsneo.readthedocs.io/en/latest/icsneoc/) (deprecated, use C2)
|
||||
- [C2](https://libicsneo.readthedocs.io/en/latest/icsneoc2/)
|
||||
|
||||
## Hardware Support
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ BEGIN
|
||||
VALUE "FileDescription", "Intrepid Control Systems Open Device Communication C API"
|
||||
VALUE "FileVersion", VER_FILEVERSION_STR
|
||||
VALUE "InternalName", "icsneoc.dll"
|
||||
VALUE "LegalCopyright", "Intrepid Control Systems, Inc. (C) 2018-2025"
|
||||
VALUE "LegalCopyright", "Intrepid Control Systems, Inc. (C) 2018-2026"
|
||||
VALUE "OriginalFilename", "icsneoc.dll"
|
||||
VALUE "ProductName", "libicsneo"
|
||||
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,53 @@
|
||||
// This header is for internal icsneoc2 use only, it should not be included by users of the API.
|
||||
#pragma once
|
||||
|
||||
#include "icsneo/icsneoc2.h"
|
||||
#include "icsneo/device/device.h"
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/communication/message/scriptstatusmessage.h"
|
||||
#include "icsneo/api/event.h"
|
||||
#include "icsneo/disk/diskdetails.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
typedef struct icsneoc2_message_t {
|
||||
std::shared_ptr<Message> message;
|
||||
} icsneoc2_message_t;
|
||||
|
||||
typedef struct icsneoc2_event_t {
|
||||
APIEvent event;
|
||||
} icsneoc2_event_t;
|
||||
|
||||
typedef struct icsneoc2_device_info_t {
|
||||
std::shared_ptr<Device> device;
|
||||
icsneoc2_device_info_t* next;
|
||||
} icsneoc2_device_info_t;
|
||||
|
||||
typedef struct icsneoc2_device_t {
|
||||
std::shared_ptr<Device> device;
|
||||
} icsneoc2_device_t;
|
||||
|
||||
typedef struct icsneoc2_disk_details_t {
|
||||
std::shared_ptr<DiskDetails> details;
|
||||
} icsneoc2_disk_details_t;
|
||||
|
||||
typedef struct icsneoc2_script_status_t {
|
||||
std::shared_ptr<ScriptStatusMessage> status;
|
||||
} icsneoc2_script_status_t;
|
||||
|
||||
/**
|
||||
* Safely copies a std::string to a char array.
|
||||
*
|
||||
* @param dest The buffer to copy the string into
|
||||
* @param dest_size* The size of the buffer. Will be modified to the length of the string without the null terminator.
|
||||
* @param src The string to copy
|
||||
*
|
||||
* @return true if the string was successfully copied, false otherwise
|
||||
*
|
||||
* @note This function always null terminates the buffer, even if the string is too long.
|
||||
* In the case of truncation, dest_size will reflect the truncated length (not including the null terminator).
|
||||
*/
|
||||
bool safe_str_copy(char* dest, size_t* dest_size, std::string_view src);
|
||||
@@ -0,0 +1,417 @@
|
||||
#include "icsneo/icsneoc2messages.h" // TODO: Remove this after the complete refactor
|
||||
|
||||
#include "icsneo/icsneoc2.h"
|
||||
#include "icsneoc2_internal.h"
|
||||
|
||||
#include "icsneo/icsneocpp.h"
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/communication/message/canmessage.h"
|
||||
#include "icsneo/communication/message/canerrormessage.h"
|
||||
#include "icsneo/communication/message/linmessage.h"
|
||||
#include "icsneo/communication/message/ethernetmessage.h"
|
||||
#include "icsneo/communication/packet/canpacket.h"
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_valid(icsneoc2_message_t* message, bool* is_valid) {
|
||||
if(!message || !is_valid) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
|
||||
*is_valid = (bool)message->message;
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_transmit(icsneoc2_message_t* message, bool* value) {
|
||||
if(!message || !value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
// We can static cast here because we are relying on the type being correct at this point
|
||||
auto frame = std::dynamic_pointer_cast<Frame>(message->message);
|
||||
if(!frame) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
*value = frame->transmitted;
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_error(icsneoc2_message_t* message, bool* value) {
|
||||
if(!message || !value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto frame = std::dynamic_pointer_cast<Frame>(message->message);
|
||||
if(!frame) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
*value = frame->error;
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_netid_get(icsneoc2_message_t* message, icsneoc2_netid_t* netid) {
|
||||
if(!message || !netid) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto raw = std::dynamic_pointer_cast<RawMessage>(message->message);
|
||||
if(!raw) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
*netid = static_cast<icsneoc2_netid_t>(raw->network.getNetID());
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_netid_name_get(icsneoc2_netid_t netid, char* value, size_t* value_length) {
|
||||
if(!value || !value_length) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto netid_str = std::string(Network::GetNetIDString(static_cast<Network::NetID>(netid), true));
|
||||
// Copy the string into value
|
||||
return safe_str_copy(value, value_length, netid_str) ? icsneoc2_error_success : icsneoc2_error_string_copy_failed;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_netid_set(icsneoc2_message_t* message, icsneoc2_netid_t netid) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto raw = std::dynamic_pointer_cast<RawMessage>(message->message);
|
||||
if(!raw) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
raw->network = Network(static_cast<neonetid_t>(netid), true);
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_data_set(icsneoc2_message_t* message, uint8_t* data, size_t data_length) {
|
||||
if(!message || !data) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
// Make sure the message has the data field (RawMessage or Frame)
|
||||
auto raw_message = std::dynamic_pointer_cast<RawMessage>(message->message);
|
||||
if(!raw_message) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
raw_message->data.resize(data_length);
|
||||
std::copy(data, data + data_length, raw_message->data.begin());
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_data_get(icsneoc2_message_t* message, uint8_t* data, size_t* data_length) {
|
||||
if(!message || !data_length) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
// Make sure the message has the data field (RawMessage or Frame)
|
||||
auto raw_message = std::dynamic_pointer_cast<RawMessage>(message->message);
|
||||
if(!raw_message) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(!data) {
|
||||
*data_length = raw_message->data.size();
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
if(*data_length < raw_message->data.size()) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
std::copy(raw_message->data.begin(), raw_message->data.begin() + raw_message->data.size(), data);
|
||||
*data_length = raw_message->data.size();
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_can_create(icsneoc2_message_t** message) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
try {
|
||||
*message = new icsneoc2_message_t;
|
||||
// Initialize the internal message as a CANMessage so that all icsneoc2_message_can_*_set
|
||||
// functions work correctly on user-created transmit messages.
|
||||
(*message)->message = std::make_shared<CANMessage>();
|
||||
} catch(const std::bad_alloc&) {
|
||||
return icsneoc2_error_out_of_memory;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_free(icsneoc2_message_t* message) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
delete message;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_can_props_set(icsneoc2_message_t* message, const uint64_t* arb_id, const uint64_t* flags) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto can_msg = std::dynamic_pointer_cast<CANMessage>(message->message);
|
||||
if(!can_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(arb_id) {
|
||||
can_msg->arbid = static_cast<uint32_t>(*arb_id);
|
||||
}
|
||||
if(flags) {
|
||||
can_msg->isRemote = (*flags & ICSNEOC2_MESSAGE_CAN_FLAGS_RTR);
|
||||
can_msg->isExtended = (*flags & ICSNEOC2_MESSAGE_CAN_FLAGS_IDE);
|
||||
can_msg->isCANFD = (*flags & ICSNEOC2_MESSAGE_CAN_FLAGS_FDF);
|
||||
can_msg->baudrateSwitch = (*flags & ICSNEOC2_MESSAGE_CAN_FLAGS_BRS);
|
||||
can_msg->errorStateIndicator = (*flags & ICSNEOC2_MESSAGE_CAN_FLAGS_ESI);
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_can_props_get(icsneoc2_message_t* message, uint64_t* arb_id, uint64_t* flags) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto can_msg = std::dynamic_pointer_cast<CANMessage>(message->message);
|
||||
if(!can_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(arb_id) {
|
||||
*arb_id = can_msg->arbid;
|
||||
}
|
||||
if(flags) {
|
||||
*flags = 0;
|
||||
if(can_msg->isRemote) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_RTR;
|
||||
}
|
||||
if(can_msg->isExtended) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_IDE;
|
||||
}
|
||||
if(can_msg->isCANFD) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_FDF;
|
||||
}
|
||||
if(can_msg->baudrateSwitch) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_BRS;
|
||||
}
|
||||
if(can_msg->errorStateIndicator) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_ESI;
|
||||
}
|
||||
if(can_msg->txAborted) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_TX_ABORTED;
|
||||
}
|
||||
if(can_msg->txLostArb) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_TX_LOST_ARB;
|
||||
}
|
||||
if(can_msg->txError) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_TX_ERROR;
|
||||
}
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_network_type_get(icsneoc2_message_t* message, icsneoc2_network_type_t* network_type) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto raw = std::dynamic_pointer_cast<RawMessage>(message->message);
|
||||
if(!raw) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
*network_type = (icsneoc2_network_type_t)raw->network.getType();
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_raw(icsneoc2_message_t* message, bool* is_raw) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*is_raw = std::dynamic_pointer_cast<RawMessage>(message->message) != nullptr;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_frame(icsneoc2_message_t* message, bool* is_frame) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*is_frame = std::dynamic_pointer_cast<Frame>(message->message) != nullptr;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_can(icsneoc2_message_t* message, bool* is_can) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*is_can = std::dynamic_pointer_cast<CANMessage>(message->message) != nullptr;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_can_error(icsneoc2_message_t* message, bool* is_can_error) {
|
||||
if(!message || !is_can_error) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*is_can_error = std::dynamic_pointer_cast<CANErrorMessage>(message->message) != nullptr;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_can_error_props_get(
|
||||
icsneoc2_message_t *message, uint8_t *tx_err_count, uint8_t *rx_err_count,
|
||||
icsneoc2_can_error_code_t *error_code,
|
||||
icsneoc2_can_error_code_t *data_error_code,
|
||||
icsneoc2_message_can_error_flags_t *flags) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto can_err = std::dynamic_pointer_cast<CANErrorMessage>(message->message);
|
||||
if(!can_err) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(tx_err_count) {
|
||||
*tx_err_count = can_err->transmitErrorCount;
|
||||
}
|
||||
if(rx_err_count) {
|
||||
*rx_err_count = can_err->receiveErrorCount;
|
||||
}
|
||||
if(error_code) {
|
||||
*error_code = static_cast<icsneoc2_can_error_code_t>(can_err->errorCode);
|
||||
}
|
||||
if(data_error_code) {
|
||||
*data_error_code = static_cast<icsneoc2_can_error_code_t>(can_err->dataErrorCode);
|
||||
}
|
||||
if(flags) {
|
||||
*flags = 0;
|
||||
if(can_err->busOff) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_BUS_OFF;
|
||||
}
|
||||
if(can_err->errorPassive) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_ERROR_PASSIVE;
|
||||
}
|
||||
if(can_err->errorWarn) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_ERROR_WARN;
|
||||
}
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_lin(icsneoc2_message_t* message, bool* is_lin) {
|
||||
if(!message || !is_lin) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*is_lin = std::dynamic_pointer_cast<LINMessage>(message->message) != nullptr;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_lin_create(icsneoc2_message_t** message, uint8_t id) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
try {
|
||||
*message = new icsneoc2_message_t;
|
||||
(*message)->message = std::make_shared<LINMessage>(id);
|
||||
} catch(const std::bad_alloc&) {
|
||||
return icsneoc2_error_out_of_memory;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_lin_props_get(const icsneoc2_message_t* message,
|
||||
uint8_t* id, uint8_t* protected_id, uint8_t* checksum,
|
||||
icsneoc2_lin_msg_type_t* msg_type, bool* is_enhanced_checksum) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto lin_msg = std::dynamic_pointer_cast<LINMessage>(message->message);
|
||||
if(!lin_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(id) {
|
||||
*id = lin_msg->ID;
|
||||
}
|
||||
if(protected_id) {
|
||||
*protected_id = lin_msg->protectedID;
|
||||
}
|
||||
if(checksum) {
|
||||
*checksum = lin_msg->checksum;
|
||||
}
|
||||
if(msg_type) {
|
||||
*msg_type = static_cast<icsneoc2_lin_msg_type_t>(lin_msg->linMsgType);
|
||||
}
|
||||
if(is_enhanced_checksum) {
|
||||
*is_enhanced_checksum = lin_msg->isEnhancedChecksum;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_lin_props_set(icsneoc2_message_t* message,
|
||||
const uint8_t* id, const uint8_t* checksum,
|
||||
const icsneoc2_lin_msg_type_t* msg_type, const bool* is_enhanced_checksum) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto lin_msg = std::dynamic_pointer_cast<LINMessage>(message->message);
|
||||
if(!lin_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(id) {
|
||||
lin_msg->ID = *id & 0x3Fu;
|
||||
lin_msg->protectedID = lin_msg->calcProtectedID(lin_msg->ID);
|
||||
}
|
||||
if(checksum) {
|
||||
lin_msg->checksum = *checksum;
|
||||
}
|
||||
if(msg_type) {
|
||||
lin_msg->linMsgType = static_cast<LINMessage::Type>(*msg_type);
|
||||
}
|
||||
if(is_enhanced_checksum) {
|
||||
lin_msg->isEnhancedChecksum = *is_enhanced_checksum;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_lin_err_flags_get(const icsneoc2_message_t* message, icsneoc2_lin_err_flags_t* err_flags) {
|
||||
if(!message || !err_flags) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto lin_msg = std::dynamic_pointer_cast<LINMessage>(message->message);
|
||||
if(!lin_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
*err_flags = 0;
|
||||
if(lin_msg->errFlags.ErrRxBreakOnly) *err_flags |= ICSNEOC2_LIN_ERR_RX_BREAK_ONLY;
|
||||
if(lin_msg->errFlags.ErrRxBreakSyncOnly) *err_flags |= ICSNEOC2_LIN_ERR_RX_BREAK_SYNC_ONLY;
|
||||
if(lin_msg->errFlags.ErrTxRxMismatch) *err_flags |= ICSNEOC2_LIN_ERR_TX_RX_MISMATCH;
|
||||
if(lin_msg->errFlags.ErrRxBreakNotZero) *err_flags |= ICSNEOC2_LIN_ERR_RX_BREAK_NOT_ZERO;
|
||||
if(lin_msg->errFlags.ErrRxBreakTooShort) *err_flags |= ICSNEOC2_LIN_ERR_RX_BREAK_TOO_SHORT;
|
||||
if(lin_msg->errFlags.ErrRxSyncNot55) *err_flags |= ICSNEOC2_LIN_ERR_RX_SYNC_NOT_55;
|
||||
if(lin_msg->errFlags.ErrRxDataLenOver8) *err_flags |= ICSNEOC2_LIN_ERR_RX_DATA_LEN_OVER_8;
|
||||
if(lin_msg->errFlags.ErrFrameSync) *err_flags |= ICSNEOC2_LIN_ERR_FRAME_SYNC;
|
||||
if(lin_msg->errFlags.ErrFrameMessageID) *err_flags |= ICSNEOC2_LIN_ERR_FRAME_MESSAGE_ID;
|
||||
if(lin_msg->errFlags.ErrFrameResponderData) *err_flags |= ICSNEOC2_LIN_ERR_FRAME_RESPONDER_DATA;
|
||||
if(lin_msg->errFlags.ErrChecksumMatch) *err_flags |= ICSNEOC2_LIN_ERR_CHECKSUM_MATCH;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_lin_status_flags_get(const icsneoc2_message_t* message, icsneoc2_lin_status_flags_t* status_flags) {
|
||||
if(!message || !status_flags) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto lin_msg = std::dynamic_pointer_cast<LINMessage>(message->message);
|
||||
if(!lin_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
*status_flags = 0;
|
||||
if(lin_msg->statusFlags.TxChecksumEnhanced) *status_flags |= ICSNEOC2_LIN_STATUS_TX_CHECKSUM_ENHANCED;
|
||||
if(lin_msg->statusFlags.TxCommander) *status_flags |= ICSNEOC2_LIN_STATUS_TX_COMMANDER;
|
||||
if(lin_msg->statusFlags.TxResponder) *status_flags |= ICSNEOC2_LIN_STATUS_TX_RESPONDER;
|
||||
if(lin_msg->statusFlags.TxAborted) *status_flags |= ICSNEOC2_LIN_STATUS_TX_ABORTED;
|
||||
if(lin_msg->statusFlags.UpdateResponderOnce) *status_flags |= ICSNEOC2_LIN_STATUS_UPDATE_RESPONDER_ONCE;
|
||||
if(lin_msg->statusFlags.HasUpdatedResponderOnce) *status_flags |= ICSNEOC2_LIN_STATUS_HAS_UPDATED_RESPONDER_ONCE;
|
||||
if(lin_msg->statusFlags.BusRecovered) *status_flags |= ICSNEOC2_LIN_STATUS_BUS_RECOVERED;
|
||||
if(lin_msg->statusFlags.BreakOnly) *status_flags |= ICSNEOC2_LIN_STATUS_BREAK_ONLY;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_lin_calc_checksum(icsneoc2_message_t* message) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto lin_msg = std::dynamic_pointer_cast<LINMessage>(message->message);
|
||||
if(!lin_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
LINMessage::calcChecksum(*lin_msg);
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
@@ -0,0 +1,684 @@
|
||||
#include "icsneo/icsneoc2.h"
|
||||
#include "icsneo/icsneoc2settings.h"
|
||||
#include "icsneo/device/device.h"
|
||||
#include "icsneo/device/devicefinder.h"
|
||||
#include "icsneo/icsneocpp.h"
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/communication/message/canmessage.h"
|
||||
#include "icsneo/communication/message/linmessage.h"
|
||||
#include "icsneo/communication/message/ethernetmessage.h"
|
||||
#include "icsneo/communication/packet/canpacket.h"
|
||||
#include "icsneo/communication/io.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
#include "icsneoc2_internal.h"
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_apply_defaults(icsneoc2_device_t* device, bool save) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!device->device->settings->applyDefaults(!save)) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_apply(icsneoc2_device_t* device) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!device->device->settings->apply()) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_refresh(icsneoc2_device_t* device) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!device->device->settings->refresh()) {
|
||||
return icsneoc2_error_get_settings_failure;
|
||||
}
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_baudrate_get(icsneoc2_device_t* device, icsneoc2_netid_t netid, int64_t* baudrate) {
|
||||
if(!baudrate) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
auto baudrate_value = device->device->settings->getBaudrateFor(Network(netid));
|
||||
if(baudrate_value < 0) {
|
||||
*baudrate = 0;
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
*baudrate = baudrate_value;
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_baudrate_set(icsneoc2_device_t* device, icsneoc2_netid_t netid, int64_t baudrate) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!device->device->settings->setBaudrateFor(Network(netid), baudrate)) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_canfd_baudrate_get(icsneoc2_device_t* device, icsneoc2_netid_t netid, int64_t* baudrate) {
|
||||
if(!baudrate) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
*baudrate = device->device->settings->getFDBaudrateFor(Network(netid));
|
||||
if(*baudrate < 0) {
|
||||
*baudrate = 0;
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_canfd_baudrate_set(icsneoc2_device_t* device, icsneoc2_netid_t netid, int64_t baudrate) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!device->device->settings->setFDBaudrateFor(Network(netid), baudrate)) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_termination_is_supported(icsneoc2_device_t* device, icsneoc2_netid_t netid, bool* supported) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!supported) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*supported = device->device->settings->isTerminationSupportedFor(Network(static_cast<Network::NetID>(netid)));
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_termination_can_enable(icsneoc2_device_t* device, icsneoc2_netid_t netid, bool* can_enable) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!can_enable) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*can_enable = device->device->settings->canTerminationBeEnabledFor(Network(static_cast<Network::NetID>(netid)));
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_termination_is_enabled(icsneoc2_device_t* device, icsneoc2_netid_t netid, bool* enabled) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!enabled) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*enabled = device->device->settings->isTerminationEnabledFor(Network(static_cast<Network::NetID>(netid))).value_or(false);
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_termination_set(icsneoc2_device_t* device, icsneoc2_netid_t netid, bool enable) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!device->device->settings->setTerminationFor(Network(static_cast<Network::NetID>(netid)), enable)) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_commander_resistor_enabled(icsneoc2_device_t* device, icsneoc2_netid_t netid, bool* enabled) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!enabled) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*enabled = device->device->settings->isCommanderResistorEnabledFor(Network(static_cast<Network::NetID>(netid))).value_or(false);
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_commander_resistor_set(icsneoc2_device_t* device, icsneoc2_netid_t netid, bool enable) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!device->device->settings->setCommanderResistorFor(Network(static_cast<Network::NetID>(netid)), enable)) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_lin_mode_get(icsneoc2_device_t* device, icsneoc2_netid_t netid, icsneoc2_lin_mode_t* value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(auto result = device->device->settings->getLINModeFor(network); result.has_value()) {
|
||||
*value = static_cast<icsneoc2_lin_mode_t>(result.value());
|
||||
return icsneoc2_error_success;
|
||||
} else {
|
||||
*value = 0;
|
||||
return icsneoc2_error_get_settings_failure;
|
||||
}
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_lin_mode_set(icsneoc2_device_t* device, icsneoc2_netid_t netid, icsneoc2_lin_mode_t value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(!device->device->settings->setLINModeFor(network, static_cast<LINMode>(value))) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_lin_commander_response_time_get(icsneoc2_device_t* device, icsneoc2_netid_t netid, uint8_t* value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(auto result = device->device->settings->getLINCommanderResponseTimeFor(network); result.has_value()) {
|
||||
*value = result.value();
|
||||
return icsneoc2_error_success;
|
||||
} else {
|
||||
*value = 0;
|
||||
return icsneoc2_error_get_settings_failure;
|
||||
}
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_lin_commander_response_time_set(icsneoc2_device_t* device, icsneoc2_netid_t netid, uint8_t value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(!device->device->settings->setLINCommanderResponseTimeFor(network, value)) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_phy_enable_get(icsneoc2_device_t* device, uint8_t index, bool* value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
if(auto result = device->device->settings->getPhyEnable(index); result.has_value()) {
|
||||
*value = result.value();
|
||||
return icsneoc2_error_success;
|
||||
} else {
|
||||
*value = false;
|
||||
return icsneoc2_error_get_settings_failure;
|
||||
}
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_phy_enable_set(icsneoc2_device_t* device, uint8_t index, bool value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!device->device->settings->setPhyEnable(index, value)) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_phy_mode_get(icsneoc2_device_t* device, uint8_t index, icsneoc2_ae_link_mode_t* value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
if(auto result = device->device->settings->getPhyMode(index); result.has_value()) {
|
||||
*value = static_cast<icsneoc2_ae_link_mode_t>(result.value());
|
||||
return icsneoc2_error_success;
|
||||
} else {
|
||||
*value = 0;
|
||||
return icsneoc2_error_get_settings_failure;
|
||||
}
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_phy_mode_set(icsneoc2_device_t* device, uint8_t index, icsneoc2_ae_link_mode_t value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!device->device->settings->setPhyMode(index, static_cast<AELinkMode>(value))) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_phy_speed_get(icsneoc2_device_t* device, uint8_t index, icsneoc2_eth_phy_link_mode_t* value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
if(auto result = device->device->settings->getPhySpeed(index); result.has_value()) {
|
||||
*value = static_cast<icsneoc2_eth_phy_link_mode_t>(result.value());
|
||||
return icsneoc2_error_success;
|
||||
} else {
|
||||
*value = 0;
|
||||
return icsneoc2_error_get_settings_failure;
|
||||
}
|
||||
}
|
||||
icsneoc2_error_t icsneoc2_settings_phy_speed_set(icsneoc2_device_t* device, uint8_t index, icsneoc2_eth_phy_link_mode_t value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!device->device->settings->setPhySpeed(index, static_cast<EthPhyLinkMode>(value))) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_phy_role_for_get(icsneoc2_device_t* device, icsneoc2_netid_t netid, icsneoc2_ae_link_mode_t* value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(auto result = device->device->settings->getPhyRoleFor(network); result.has_value()) {
|
||||
*value = static_cast<icsneoc2_ae_link_mode_t>(result.value());
|
||||
return icsneoc2_error_success;
|
||||
} else {
|
||||
*value = 0;
|
||||
return icsneoc2_error_get_settings_failure;
|
||||
}
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_phy_role_for_set(icsneoc2_device_t* device, icsneoc2_netid_t netid, icsneoc2_ae_link_mode_t value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(!device->device->settings->setPhyRoleFor(network, static_cast<AELinkMode>(value))) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_phy_link_mode_for_get(icsneoc2_device_t* device, icsneoc2_netid_t netid, icsneoc2_eth_phy_link_mode_t* value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(auto result = device->device->settings->getPhyLinkModeFor(network); result.has_value()) {
|
||||
*value = static_cast<icsneoc2_eth_phy_link_mode_t>(result.value());
|
||||
return icsneoc2_error_success;
|
||||
} else {
|
||||
*value = 0;
|
||||
return icsneoc2_error_get_settings_failure;
|
||||
}
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_phy_link_mode_for_set(icsneoc2_device_t* device, icsneoc2_netid_t netid, icsneoc2_eth_phy_link_mode_t value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(!device->device->settings->setPhyLinkModeFor(network, static_cast<EthPhyLinkMode>(value))) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_phy_enable_for_get(icsneoc2_device_t* device, icsneoc2_netid_t netid, bool* value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(auto result = device->device->settings->getPhyEnableFor(network); result.has_value()) {
|
||||
*value = result.value();
|
||||
return icsneoc2_error_success;
|
||||
} else {
|
||||
*value = false;
|
||||
return icsneoc2_error_get_settings_failure;
|
||||
}
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_phy_enable_for_set(icsneoc2_device_t* device, icsneoc2_netid_t netid, bool value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(!device->device->settings->setPhyEnableFor(network, value)) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_supported_phy_link_modes_for(icsneoc2_device_t* device, icsneoc2_netid_t netid, icsneoc2_eth_phy_link_mode_t** link_modes, size_t* link_modes_count) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!link_modes || !link_modes_count) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
auto modes = device->device->settings->getSupportedPhyLinkModesFor(network);
|
||||
*link_modes_count = std::minmax(modes.size(), *link_modes_count).first;
|
||||
memcpy(*link_modes, modes.data(), *link_modes_count * sizeof(icsneoc2_eth_phy_link_mode_t));
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_t1s_is_plca_enabled_for(icsneoc2_device_t* device, icsneoc2_netid_t netid, bool* value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(auto result = device->device->settings->isT1SPLCAEnabledFor(network); result.has_value()) {
|
||||
*value = result.value();
|
||||
return icsneoc2_error_success;
|
||||
} else {
|
||||
*value = false;
|
||||
return icsneoc2_error_get_settings_failure;
|
||||
}
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_t1s_plca_enabled_for_set(icsneoc2_device_t* device, icsneoc2_netid_t netid, bool value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(!device->device->settings->setT1SPLCAFor(network, value)) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_t1s_local_id_get(icsneoc2_device_t* device, icsneoc2_netid_t netid, uint8_t* value){
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(auto result = device->device->settings->getT1SLocalIDFor(network); result.has_value()) {
|
||||
*value = result.value();
|
||||
return icsneoc2_error_success;
|
||||
} else {
|
||||
*value = 0;
|
||||
return icsneoc2_error_get_settings_failure;
|
||||
}
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_t1s_local_id_set(icsneoc2_device_t* device, icsneoc2_netid_t netid, uint8_t value){
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(!device->device->settings->setT1SLocalIDFor(network, value)) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_t1s_max_nodes_get(icsneoc2_device_t* device, icsneoc2_netid_t netid, uint8_t* value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(auto result = device->device->settings->getT1SMaxNodesFor(network); result.has_value()) {
|
||||
*value = result.value();
|
||||
return icsneoc2_error_success;
|
||||
} else {
|
||||
*value = 0;
|
||||
return icsneoc2_error_get_settings_failure;
|
||||
}
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_t1s_max_nodes_set(icsneoc2_device_t* device, icsneoc2_netid_t netid, uint8_t value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(!device->device->settings->setT1SMaxNodesFor(network, value)) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_t1s_tx_opp_timer_get(icsneoc2_device_t* device, icsneoc2_netid_t netid, uint8_t* value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(auto result = device->device->settings->getT1STxOppTimerFor(network); result.has_value()) {
|
||||
*value = result.value();
|
||||
return icsneoc2_error_success;
|
||||
} else {
|
||||
*value = 0;
|
||||
return icsneoc2_error_get_settings_failure;
|
||||
}
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_t1s_tx_opp_timer_set(icsneoc2_device_t* device, icsneoc2_netid_t netid, uint8_t value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(!device->device->settings->setT1STxOppTimerFor(network, value)) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_t1s_max_burst_timer_for_get(icsneoc2_device_t* device, icsneoc2_netid_t netid, uint8_t* value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(auto result = device->device->settings->getT1SMaxBurstFor(network); result.has_value()) {
|
||||
*value = result.value();
|
||||
return icsneoc2_error_success;
|
||||
} else {
|
||||
*value = 0;
|
||||
return icsneoc2_error_get_settings_failure;
|
||||
}
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_t1s_max_burst_timer_for_set(icsneoc2_device_t* device, icsneoc2_netid_t netid, uint8_t value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
auto network = Network(static_cast<Network::NetID>(netid));
|
||||
if(!device->device->settings->setT1SMaxBurstFor(network, value)) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_misc_io_analog_output_enabled_set(icsneoc2_device_t* device, uint8_t pin, uint8_t value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!device->device->settings->setMiscIOAnalogOutputEnabled(pin, value)) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_misc_io_analog_output_set(icsneoc2_device_t* device, uint8_t pin, icsneoc2_misc_io_analog_voltage_t value) {
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
if(!device->device->settings->setMiscIOAnalogOutput(pin, static_cast<MiscIOAnalogVoltage>(value))) {
|
||||
return icsneoc2_error_set_settings_failure;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_disabled_get(icsneoc2_device_t* device, bool* value) {
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
*value = device->device->settings->disabled;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_settings_readonly_get(icsneoc2_device_t* device, bool* value) {
|
||||
if(!value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
// Make sure the device is valid
|
||||
auto res = icsneoc2_device_is_valid(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return res;
|
||||
}
|
||||
*value = device->device->settings->readonly;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
@@ -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", "icsneoc2.dll"
|
||||
VALUE "LegalCopyright", "Intrepid Control Systems, Inc. (C) 2018-2026"
|
||||
VALUE "OriginalFilename", "icsneoc2.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
|
||||
@@ -9,7 +9,7 @@ else()
|
||||
FetchContent_Declare(
|
||||
pybind11
|
||||
GIT_REPOSITORY https://github.com/pybind/pybind11.git
|
||||
GIT_TAG v2.13.6
|
||||
GIT_TAG v3.0.3
|
||||
)
|
||||
FetchContent_MakeAvailable(pybind11)
|
||||
endif()
|
||||
@@ -22,6 +22,7 @@ pybind11_add_module(icsneopy
|
||||
icsneopy/device/devicetype.cpp
|
||||
icsneopy/communication/network.cpp
|
||||
icsneopy/communication/io.cpp
|
||||
icsneopy/communication/livedata.cpp
|
||||
icsneopy/communication/message/message.cpp
|
||||
icsneopy/communication/message/canmessage.cpp
|
||||
icsneopy/communication/message/canerrormessage.cpp
|
||||
@@ -34,11 +35,13 @@ pybind11_add_module(icsneopy
|
||||
icsneopy/communication/message/spimessage.cpp
|
||||
icsneopy/communication/message/scriptstatusmessage.cpp
|
||||
icsneopy/communication/message/ethphymessage.cpp
|
||||
icsneopy/communication/message/livedatamessage.cpp
|
||||
icsneopy/communication/message/callback/messagecallback.cpp
|
||||
icsneopy/communication/message/filter/messagefilter.cpp
|
||||
icsneopy/core/macseccfg.cpp
|
||||
icsneopy/flexray/flexray.cpp
|
||||
icsneopy/disk/diskdriver.cpp
|
||||
icsneopy/disk/diskdetails.cpp
|
||||
icsneopy/device/chipid.cpp
|
||||
icsneopy/device/versionreport.cpp
|
||||
icsneopy/device/device.cpp
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/api/event.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_event(pybind11::module_& m) {
|
||||
pybind11::class_<APIEvent, std::shared_ptr<APIEvent>> apiEvent(m, "APIEvent");
|
||||
pybind11::enum_<APIEvent::Type>(apiEvent, "Type")
|
||||
pybind11::classh<APIEvent> apiEvent(m, "APIEvent");
|
||||
pybind11::native_enum<APIEvent::Type>(apiEvent, "Type", "enum.IntEnum")
|
||||
.value("Any", APIEvent::Type::Any)
|
||||
.value("InvalidNeoDevice", APIEvent::Type::InvalidNeoDevice)
|
||||
.value("RequiredParameterNull", APIEvent::Type::RequiredParameterNull)
|
||||
@@ -132,13 +133,15 @@ void init_event(pybind11::module_& m) {
|
||||
.value("DXXErrorArg", APIEvent::Type::DXXErrorArg)
|
||||
.value("NoErrorFound", APIEvent::Type::NoErrorFound)
|
||||
.value("TooManyEvents", APIEvent::Type::TooManyEvents)
|
||||
.value("Unknown", APIEvent::Type::Unknown);
|
||||
.value("Unknown", APIEvent::Type::Unknown)
|
||||
.finalize();
|
||||
|
||||
pybind11::enum_<APIEvent::Severity>(apiEvent, "Severity")
|
||||
pybind11::native_enum<APIEvent::Severity>(apiEvent, "Severity", "enum.IntEnum")
|
||||
.value("Any", APIEvent::Severity::Any)
|
||||
.value("EventInfo", APIEvent::Severity::EventInfo)
|
||||
.value("EventWarning", APIEvent::Severity::EventWarning)
|
||||
.value("Error", APIEvent::Severity::Error);
|
||||
.value("Error", APIEvent::Severity::Error)
|
||||
.finalize();
|
||||
|
||||
apiEvent
|
||||
.def("get_type", &APIEvent::getType)
|
||||
@@ -147,7 +150,7 @@ void init_event(pybind11::module_& m) {
|
||||
.def("describe", &APIEvent::describe)
|
||||
.def("__repr__", &APIEvent::describe);
|
||||
|
||||
pybind11::class_<EventFilter, std::shared_ptr<EventFilter>>(m, "EventFilter")
|
||||
pybind11::classh<EventFilter>(m, "EventFilter")
|
||||
.def(pybind11::init())
|
||||
.def(pybind11::init<APIEvent::Type>())
|
||||
.def(pybind11::init<APIEvent::Severity>())
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_eventcallback(pybind11::module_& m) {
|
||||
pybind11::class_<EventCallback>(m, "EventCallback")
|
||||
pybind11::classh<EventCallback>(m, "EventCallback")
|
||||
.def(pybind11::init<EventCallback::fn_eventCallback, EventFilter>())
|
||||
.def(pybind11::init<EventCallback::fn_eventCallback>());
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_eventmanager(pybind11::module_& m) {
|
||||
pybind11::class_<EventManager>(m, "EventManager")
|
||||
pybind11::classh<EventManager>(m, "EventManager")
|
||||
.def_static("get_instance", &EventManager::GetInstance, pybind11::return_value_policy::reference)
|
||||
.def("add_event_callback", &EventManager::addEventCallback)
|
||||
.def("remove_event_callback", &EventManager::removeEventCallback)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_version(pybind11::module_& m) {
|
||||
pybind11::class_<neoversion_t>(m, "NeoVersion")
|
||||
pybind11::classh<neoversion_t>(m, "NeoVersion")
|
||||
.def_readonly("major", &neoversion_t::major)
|
||||
.def_readonly("minor", &neoversion_t::minor)
|
||||
.def_readonly("patch", &neoversion_t::patch)
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/communication/livedata.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_livedata(pybind11::module_& m) {
|
||||
// LiveDataValue struct
|
||||
pybind11::classh<LiveDataValue>(m, "LiveDataValue")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("value", &LiveDataValue::value);
|
||||
|
||||
// LiveDataArgument struct
|
||||
pybind11::classh<LiveDataArgument>(m, "LiveDataArgument")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("object_type", &LiveDataArgument::objectType)
|
||||
.def_readwrite("object_index", &LiveDataArgument::objectIndex)
|
||||
.def_readwrite("signal_index", &LiveDataArgument::signalIndex)
|
||||
.def_readwrite("value_type", &LiveDataArgument::valueType);
|
||||
|
||||
// LiveDataCommand enum
|
||||
pybind11::native_enum<LiveDataCommand>(m, "LiveDataCommand", "enum.IntEnum")
|
||||
.value("STATUS", LiveDataCommand::STATUS)
|
||||
.value("SUBSCRIBE", LiveDataCommand::SUBSCRIBE)
|
||||
.value("UNSUBSCRIBE", LiveDataCommand::UNSUBSCRIBE)
|
||||
.value("RESPONSE", LiveDataCommand::RESPONSE)
|
||||
.value("CLEAR_ALL", LiveDataCommand::CLEAR_ALL)
|
||||
.value("SET_VALUE", LiveDataCommand::SET_VALUE)
|
||||
.finalize();
|
||||
|
||||
// LiveDataStatus enum
|
||||
pybind11::native_enum<LiveDataStatus>(m, "LiveDataStatus", "enum.IntEnum")
|
||||
.value("SUCCESS", LiveDataStatus::SUCCESS)
|
||||
.value("ERR_UNKNOWN_COMMAND", LiveDataStatus::ERR_UNKNOWN_COMMAND)
|
||||
.value("ERR_HANDLE", LiveDataStatus::ERR_HANDLE)
|
||||
.value("ERR_DUPLICATE", LiveDataStatus::ERR_DUPLICATE)
|
||||
.value("ERR_FULL", LiveDataStatus::ERR_FULL)
|
||||
.finalize();
|
||||
|
||||
// LiveDataObjectType enum
|
||||
pybind11::enum_<LiveDataObjectType>(m, "LiveDataObjectType")
|
||||
.value("MISC", LiveDataObjectType::MISC)
|
||||
.value("SNA", LiveDataObjectType::SNA)
|
||||
.export_values();
|
||||
|
||||
// LiveDataValueType enum
|
||||
pybind11::native_enum<LiveDataValueType>(m, "LiveDataValueType", "enum.IntEnum")
|
||||
.value("GPS_LATITUDE", LiveDataValueType::GPS_LATITUDE)
|
||||
.value("GPS_LONGITUDE", LiveDataValueType::GPS_LONGITUDE)
|
||||
.value("GPS_ALTITUDE", LiveDataValueType::GPS_ALTITUDE)
|
||||
.value("GPS_SPEED", LiveDataValueType::GPS_SPEED)
|
||||
.value("GPS_VALID", LiveDataValueType::GPS_VALID)
|
||||
.value("GPS_ENABLE", LiveDataValueType::GPS_ENABLE)
|
||||
.value("MANUAL_TRIGGER", LiveDataValueType::MANUAL_TRIGGER)
|
||||
.value("TIME_SINCE_MSG", LiveDataValueType::TIME_SINCE_MSG)
|
||||
.value("GPS_ACCURACY", LiveDataValueType::GPS_ACCURACY)
|
||||
.value("GPS_BEARING", LiveDataValueType::GPS_BEARING)
|
||||
.value("GPS_TIME", LiveDataValueType::GPS_TIME)
|
||||
.value("GPS_TIME_VALID", LiveDataValueType::GPS_TIME_VALID)
|
||||
.value("DAQ_ENABLE", LiveDataValueType::DAQ_ENABLE)
|
||||
.finalize();
|
||||
|
||||
// LiveDataUtil namespace functions
|
||||
m.def("get_new_handle", &LiveDataUtil::getNewHandle,
|
||||
"Generate a new unique LiveData handle");
|
||||
|
||||
m.def("livedata_value_to_double", &LiveDataUtil::liveDataValueToDouble,
|
||||
pybind11::arg("val"),
|
||||
"Convert LiveDataValue to double (32.32 fixed-point to floating-point)");
|
||||
|
||||
m.def("livedata_double_to_value", &LiveDataUtil::liveDataDoubleToValue,
|
||||
pybind11::arg("d"),
|
||||
"Convert double to LiveDataValue (32.32 fixed-point format). Returns LiveDataValue or None on failure.");
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_messagecallback(pybind11::module_& m) {
|
||||
pybind11::class_<MessageCallback, std::shared_ptr<MessageCallback>>(m, "MessageCallback")
|
||||
pybind11::classh<MessageCallback>(m, "MessageCallback")
|
||||
.def(pybind11::init<MessageCallback::fn_messageCallback, std::shared_ptr<MessageFilter>>());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/communication/message/canerrormessage.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_errorcodes(pybind11::module_& m) {
|
||||
pybind11::enum_<CANErrorCode>(m, "CANErrorCode")
|
||||
pybind11::native_enum<CANErrorCode>(m, "CANErrorCode", "enum.IntEnum")
|
||||
.value("NoError", CANErrorCode::NoError)
|
||||
.value("StuffError", CANErrorCode::StuffError)
|
||||
.value("FormError", CANErrorCode::FormError)
|
||||
@@ -15,12 +16,13 @@ void init_errorcodes(pybind11::module_& m) {
|
||||
.value("Bit1Error", CANErrorCode::Bit1Error)
|
||||
.value("Bit0Error", CANErrorCode::Bit0Error)
|
||||
.value("CRCError", CANErrorCode::CRCError)
|
||||
.value("NoChange", CANErrorCode::NoChange);
|
||||
.value("NoChange", CANErrorCode::NoChange)
|
||||
.finalize();
|
||||
}
|
||||
|
||||
void init_canerrormessage(pybind11::module_& m) {
|
||||
init_errorcodes(m);
|
||||
pybind11::class_<CANErrorMessage, std::shared_ptr<CANErrorMessage>, Message>(m, "CANErrorMessage")
|
||||
pybind11::classh<CANErrorMessage, Message>(m, "CANErrorMessage")
|
||||
.def_readonly("network", &CANErrorMessage::network)
|
||||
.def_readonly("transmitErrorCount", &CANErrorMessage::transmitErrorCount)
|
||||
.def_readonly("receiveErrorCount", &CANErrorMessage::receiveErrorCount)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_canmessage(pybind11::module_& m) {
|
||||
pybind11::class_<CANMessage, std::shared_ptr<CANMessage>, Frame>(m, "CANMessage")
|
||||
pybind11::classh<CANMessage, Frame>(m, "CANMessage")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("arbid", &CANMessage::arbid)
|
||||
.def_readwrite("dlcOnWire", &CANMessage::dlcOnWire)
|
||||
@@ -15,7 +15,10 @@ void init_canmessage(pybind11::module_& m) {
|
||||
.def_readwrite("isExtended", &CANMessage::isExtended)
|
||||
.def_readwrite("isCANFD", &CANMessage::isCANFD)
|
||||
.def_readwrite("baudrateSwitch", &CANMessage::baudrateSwitch)
|
||||
.def_readwrite("errorStateIndicator", &CANMessage::errorStateIndicator);
|
||||
.def_readwrite("errorStateIndicator", &CANMessage::errorStateIndicator)
|
||||
.def_readwrite("txAborted", &CANMessage::txAborted)
|
||||
.def_readwrite("txLostArb", &CANMessage::txLostArb)
|
||||
.def_readwrite("txError", &CANMessage::txError);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -7,17 +7,28 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_ethernetmessage(pybind11::module_& m) {
|
||||
pybind11::class_<MACAddress>(m, "MACAddress")
|
||||
pybind11::classh<MACAddress>(m, "MACAddress")
|
||||
.def("to_string", &MACAddress::toString)
|
||||
.def("__repr__", &MACAddress::toString);
|
||||
|
||||
pybind11::class_<EthernetMessage, std::shared_ptr<EthernetMessage>, Frame>(m, "EthernetMessage")
|
||||
pybind11::classh<EthernetMessage, Frame>(m, "EthernetMessage")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("preemptionEnabled", &EthernetMessage::preemptionEnabled)
|
||||
.def_readwrite("preemptionFlags", &EthernetMessage::preemptionFlags)
|
||||
.def_readwrite("fcs", &EthernetMessage::fcs)
|
||||
.def_readwrite("frameTooShort", &EthernetMessage::frameTooShort)
|
||||
.def_readwrite("noPadding", &EthernetMessage::noPadding)
|
||||
.def_readwrite("fcsVerified", &EthernetMessage::fcsVerified)
|
||||
.def_readwrite("txAborted", &EthernetMessage::txAborted)
|
||||
.def_readwrite("crcError", &EthernetMessage::crcError)
|
||||
.def_readwrite("isT1S", &EthernetMessage::isT1S)
|
||||
.def_readwrite("isT1SSymbol", &EthernetMessage::isT1SSymbol)
|
||||
.def_readwrite("isT1SBurst", &EthernetMessage::isT1SBurst)
|
||||
.def_readwrite("txCollision", &EthernetMessage::txCollision)
|
||||
.def_readwrite("isT1SWake", &EthernetMessage::isT1SWake)
|
||||
.def_readwrite("t1sNodeId", &EthernetMessage::t1sNodeId)
|
||||
.def_readwrite("t1sBurstCount", &EthernetMessage::t1sBurstCount)
|
||||
.def_readwrite("t1sSymbolType", &EthernetMessage::t1sSymbolType)
|
||||
.def("get_destination_mac", &EthernetMessage::getDestinationMAC, pybind11::return_value_policy::reference)
|
||||
.def("get_source_mac", &EthernetMessage::getSourceMAC, pybind11::return_value_policy::reference)
|
||||
.def("get_ether_type", &EthernetMessage::getEtherType);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_ethernetstatusmessage(pybind11::module_& m) {
|
||||
pybind11::class_<EthernetStatusMessage, std::shared_ptr<EthernetStatusMessage>, Message> ethernetStatusMessage(m, "EthernetStatusMessage");
|
||||
pybind11::classh<EthernetStatusMessage, Message> ethernetStatusMessage(m, "EthernetStatusMessage");
|
||||
|
||||
pybind11::enum_<EthernetStatusMessage::LinkSpeed>(ethernetStatusMessage, "LinkSpeed")
|
||||
.value("LinkSpeedAuto", EthernetStatusMessage::LinkSpeed::LinkSpeedAuto)
|
||||
|
||||
@@ -7,7 +7,17 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_ethphymessage(pybind11::module_& m) {
|
||||
pybind11::class_<PhyMessage, std::shared_ptr<PhyMessage>>(m, "PhyMessage")
|
||||
pybind11::classh<Clause22Message>(m, "Clause22Message")
|
||||
.def_readwrite("phyAddr", &Clause22Message::phyAddr)
|
||||
.def_readwrite("page", &Clause22Message::page)
|
||||
.def_readwrite("regAddr", &Clause22Message::regAddr)
|
||||
.def_readwrite("regVal", &Clause22Message::regVal);
|
||||
pybind11::classh<Clause45Message>(m, "Clause45Message")
|
||||
.def_readwrite("port", &Clause45Message::port)
|
||||
.def_readwrite("device", &Clause45Message::device)
|
||||
.def_readwrite("regAddr", &Clause45Message::regAddr)
|
||||
.def_readwrite("regVal", &Clause45Message::regVal);
|
||||
pybind11::classh<PhyMessage>(m, "PhyMessage")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("Enabled", &PhyMessage::Enabled)
|
||||
.def_readwrite("WriteEnable", &PhyMessage::WriteEnable)
|
||||
@@ -16,19 +26,7 @@ void init_ethphymessage(pybind11::module_& m) {
|
||||
.def_readwrite("BusIndex", &PhyMessage::BusIndex)
|
||||
.def_readwrite("Clause22", &PhyMessage::Clause22)
|
||||
.def_readwrite("Clause45", &PhyMessage::Clause45);
|
||||
pybind11::class_<Clause22Message>(m, "Clause22Message")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("phyAddr", &Clause22Message::phyAddr)
|
||||
.def_readwrite("page", &Clause22Message::page)
|
||||
.def_readwrite("regAddr", &Clause22Message::regAddr)
|
||||
.def_readwrite("regVal", &Clause22Message::regVal);
|
||||
pybind11::class_<Clause45Message>(m, "Clause45Message")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("port", &Clause45Message::port)
|
||||
.def_readwrite("device", &Clause45Message::device)
|
||||
.def_readwrite("regAddr", &Clause45Message::regAddr)
|
||||
.def_readwrite("regVal", &Clause45Message::regVal);
|
||||
pybind11::class_<EthPhyMessage, std::shared_ptr<EthPhyMessage>, Message>(m, "EthPhyMessage")
|
||||
pybind11::classh<EthPhyMessage, Message>(m, "EthPhyMessage")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("messages", &EthPhyMessage::messages);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_messagefilter(pybind11::module_& m) {
|
||||
pybind11::class_<MessageFilter, std::shared_ptr<MessageFilter>>(m, "MessageFilter")
|
||||
pybind11::classh<MessageFilter>(m, "MessageFilter")
|
||||
.def(pybind11::init())
|
||||
.def(pybind11::init<Message::Type>())
|
||||
.def(pybind11::init<Network::NetID>());
|
||||
|
||||
@@ -7,40 +7,40 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_gptpstatusmessage(pybind11::module_& m) {
|
||||
pybind11::class_<GPTPStatus, std::shared_ptr<GPTPStatus>, Message> gptpStatus(m, "GPTPStatus");
|
||||
pybind11::classh<GPTPStatus, Message> gptpStatus(m, "GPTPStatus");
|
||||
|
||||
pybind11::class_<GPTPStatus::Timestamp>(gptpStatus, "Timestamp")
|
||||
pybind11::classh<GPTPStatus::Timestamp>(gptpStatus, "Timestamp")
|
||||
.def_readonly("seconds", &GPTPStatus::Timestamp::seconds)
|
||||
.def_readonly("nanoseconds", &GPTPStatus::Timestamp::nanoseconds)
|
||||
.def("to_seconds", &GPTPStatus::Timestamp::toSeconds, pybind11::call_guard<pybind11::gil_scoped_release>());
|
||||
|
||||
pybind11::class_<GPTPStatus::ScaledNanoSeconds>(gptpStatus, "ScaledNanoSeconds")
|
||||
pybind11::classh<GPTPStatus::ScaledNanoSeconds>(gptpStatus, "ScaledNanoSeconds")
|
||||
.def_readonly("nanoseconds_msb", &GPTPStatus::ScaledNanoSeconds::nanosecondsMSB)
|
||||
.def_readonly("nanoseconds_lsb", &GPTPStatus::ScaledNanoSeconds::nanosecondsLSB)
|
||||
.def_readonly("fractional_nanoseconds", &GPTPStatus::ScaledNanoSeconds::fractionalNanoseconds);
|
||||
|
||||
pybind11::class_<GPTPStatus::PortID>(gptpStatus, "PortID")
|
||||
pybind11::classh<GPTPStatus::PortID>(gptpStatus, "PortID")
|
||||
.def_readonly("clock_identity", &GPTPStatus::PortID::clockIdentity)
|
||||
.def_readonly("port_number", &GPTPStatus::PortID::portNumber);
|
||||
|
||||
pybind11::class_<GPTPStatus::ClockQuality>(gptpStatus, "ClockQuality")
|
||||
pybind11::classh<GPTPStatus::ClockQuality>(gptpStatus, "ClockQuality")
|
||||
.def_readonly("clock_class", &GPTPStatus::ClockQuality::clockClass)
|
||||
.def_readonly("clock_accuracy", &GPTPStatus::ClockQuality::clockAccuracy)
|
||||
.def_readonly("offset_scaled_log_variance", &GPTPStatus::ClockQuality::offsetScaledLogVariance);
|
||||
|
||||
pybind11::class_<GPTPStatus::SystemID>(gptpStatus, "SystemID")
|
||||
pybind11::classh<GPTPStatus::SystemID>(gptpStatus, "SystemID")
|
||||
.def_readonly("priority1", &GPTPStatus::SystemID::priority1)
|
||||
.def_readonly("clock_quality", &GPTPStatus::SystemID::clockQuality)
|
||||
.def_readonly("priority2", &GPTPStatus::SystemID::priority2)
|
||||
.def_readonly("clock_id", &GPTPStatus::SystemID::clockID);
|
||||
|
||||
pybind11::class_<GPTPStatus::PriorityVector>(gptpStatus, "PriorityVector")
|
||||
pybind11::classh<GPTPStatus::PriorityVector>(gptpStatus, "PriorityVector")
|
||||
.def_readonly("sys_id", &GPTPStatus::PriorityVector::sysID)
|
||||
.def_readonly("steps_removed", &GPTPStatus::PriorityVector::stepsRemoved)
|
||||
.def_readonly("port_id", &GPTPStatus::PriorityVector::portID)
|
||||
.def_readonly("port_number", &GPTPStatus::PriorityVector::portNumber);
|
||||
|
||||
pybind11::class_<GPTPStatus::ParentDS>(gptpStatus, "ParentDS")
|
||||
pybind11::classh<GPTPStatus::ParentDS>(gptpStatus, "ParentDS")
|
||||
.def_readonly("parent_port_identity", &GPTPStatus::ParentDS::parentPortIdentity)
|
||||
.def_readonly("cumulative_rate_ratio", &GPTPStatus::ParentDS::cumulativeRateRatio)
|
||||
.def_readonly("grandmaster_identity", &GPTPStatus::ParentDS::grandmasterIdentity)
|
||||
@@ -50,7 +50,7 @@ void init_gptpstatusmessage(pybind11::module_& m) {
|
||||
.def_readonly("gm_priority1", &GPTPStatus::ParentDS::gmPriority1)
|
||||
.def_readonly("gm_priority2", &GPTPStatus::ParentDS::gmPriority2);
|
||||
|
||||
pybind11::class_<GPTPStatus::CurrentDS>(gptpStatus, "CurrentDS")
|
||||
pybind11::classh<GPTPStatus::CurrentDS>(gptpStatus, "CurrentDS")
|
||||
.def_readonly("steps_removed", &GPTPStatus::CurrentDS::stepsRemoved)
|
||||
.def_readonly("offset_from_master", &GPTPStatus::CurrentDS::offsetFromMaster)
|
||||
.def_readonly("lastgm_phase_change", &GPTPStatus::CurrentDS::lastgmPhaseChange)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_linmessage(pybind11::module_& m) {
|
||||
pybind11::class_<LINErrorFlags>(m, "LINErrorFlags")
|
||||
pybind11::classh<LINErrorFlags>(m, "LINErrorFlags")
|
||||
.def_readwrite("ErrRxBreakOnly", &LINErrorFlags::ErrRxBreakOnly)
|
||||
.def_readwrite("ErrRxBreakSyncOnly", &LINErrorFlags::ErrRxBreakSyncOnly)
|
||||
.def_readwrite("ErrTxRxMismatch", &LINErrorFlags::ErrTxRxMismatch)
|
||||
@@ -20,7 +20,7 @@ void init_linmessage(pybind11::module_& m) {
|
||||
.def_readwrite("ErrFrameResponderData", &LINErrorFlags::ErrFrameResponderData)
|
||||
.def_readwrite("ErrChecksumMatch", &LINErrorFlags::ErrChecksumMatch);
|
||||
|
||||
pybind11::class_<LINStatusFlags>(m, "LINStatusFlags")
|
||||
pybind11::classh<LINStatusFlags>(m, "LINStatusFlags")
|
||||
.def_readwrite("TxChecksumEnhanced", &LINStatusFlags::TxChecksumEnhanced)
|
||||
.def_readwrite("TxCommander", &LINStatusFlags::TxCommander)
|
||||
.def_readwrite("TxResponder", &LINStatusFlags::TxResponder)
|
||||
@@ -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::classh<LINMessage, Frame> linMessage(m, "LINMessage");
|
||||
|
||||
pybind11::enum_<LINMessage::Type>(linMessage, "Type")
|
||||
.value("NOT_SET", LINMessage::Type::NOT_SET)
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/chrono.h>
|
||||
|
||||
#include "icsneo/communication/message/livedatamessage.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_livedatamessage(pybind11::module_& m) {
|
||||
// LiveDataMessage base class
|
||||
pybind11::classh<LiveDataMessage, RawMessage>(m, "LiveDataMessage")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("handle", &LiveDataMessage::handle)
|
||||
.def_readwrite("cmd", &LiveDataMessage::cmd);
|
||||
|
||||
// LiveDataCommandMessage (for subscribe/unsubscribe)
|
||||
pybind11::classh<LiveDataCommandMessage, LiveDataMessage>(m, "LiveDataCommandMessage")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("update_period", &LiveDataCommandMessage::updatePeriod)
|
||||
.def_readwrite("expiration_time", &LiveDataCommandMessage::expirationTime)
|
||||
.def_readwrite("args", &LiveDataCommandMessage::args)
|
||||
.def("append_signal_arg", &LiveDataCommandMessage::appendSignalArg,
|
||||
pybind11::arg("value_type"),
|
||||
"Append a signal argument to the command message");
|
||||
|
||||
// LiveDataValueMessage (received values)
|
||||
pybind11::classh<LiveDataValueMessage, LiveDataMessage>(m, "LiveDataValueMessage")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("num_args", &LiveDataValueMessage::numArgs)
|
||||
.def_readwrite("values", &LiveDataValueMessage::values);
|
||||
|
||||
// LiveDataStatusMessage (status responses)
|
||||
pybind11::classh<LiveDataStatusMessage, LiveDataMessage>(m, "LiveDataStatusMessage")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("requested_command", &LiveDataStatusMessage::requestedCommand)
|
||||
.def_readwrite("status", &LiveDataStatusMessage::status);
|
||||
|
||||
// LiveDataSetValueMessage (for setting values)
|
||||
pybind11::classh<LiveDataSetValueMessage, LiveDataMessage>(m, "LiveDataSetValueMessage")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("args", &LiveDataSetValueMessage::args)
|
||||
.def_readwrite("values", &LiveDataSetValueMessage::values)
|
||||
.def("append_set_value", &LiveDataSetValueMessage::appendSetValue,
|
||||
pybind11::arg("value_type"),
|
||||
pybind11::arg("value"),
|
||||
"Append a value to set in the message");
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_mdiomessage(pybind11::module_& m) {
|
||||
pybind11::class_<MDIOMessage, std::shared_ptr<MDIOMessage>, Frame> mdioMessage(m, "MDIOMessage");
|
||||
pybind11::classh<MDIOMessage, Frame> mdioMessage(m, "MDIOMessage");
|
||||
pybind11::enum_<MDIOMessage::Clause>(mdioMessage, "Clause")
|
||||
.value("Clause45", MDIOMessage::Clause::Clause45)
|
||||
.value("Clause22", MDIOMessage::Clause::Clause22);
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/communication/message/message.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_message(pybind11::module_& m) {
|
||||
pybind11::class_<Message, std::shared_ptr<Message>> message(m, "Message");
|
||||
pybind11::enum_<Message::Type>(message, "Type")
|
||||
// Using py::smart_holder for safer lifetime management
|
||||
pybind11::classh<Message> message(m, "Message");
|
||||
pybind11::native_enum<Message::Type>(message, "Type", "enum.IntEnum")
|
||||
.value("Frame", Message::Type::Frame)
|
||||
.value("CANErrorCount", Message::Type::CANErrorCount)
|
||||
.value("CANError", Message::Type::CANError)
|
||||
@@ -34,17 +36,18 @@ void init_message(pybind11::module_& m) {
|
||||
.value("TC10Status", Message::Type::TC10Status)
|
||||
.value("AppError", Message::Type::AppError)
|
||||
.value("GPTPStatus", Message::Type::GPTPStatus)
|
||||
.value("EthernetStatus", Message::Type::EthernetStatus);
|
||||
.value("EthernetStatus", Message::Type::EthernetStatus)
|
||||
.finalize();
|
||||
|
||||
message.def(pybind11::init<Message::Type>());
|
||||
message.def_readonly("type", &Message::type);
|
||||
message.def_readwrite("timestamp", &Message::timestamp);
|
||||
|
||||
pybind11::class_<RawMessage, std::shared_ptr<RawMessage>, Message>(m, "RawMessage")
|
||||
pybind11::classh<RawMessage, Message>(m, "RawMessage")
|
||||
.def_readwrite("network", &RawMessage::network)
|
||||
.def_readwrite("data", &RawMessage::data);
|
||||
|
||||
pybind11::class_<Frame, std::shared_ptr<Frame>, RawMessage>(m, "Frame")
|
||||
pybind11::classh<Frame, RawMessage>(m, "Frame")
|
||||
.def_readwrite("description", &Frame::description)
|
||||
.def_readwrite("transmitted", &Frame::transmitted)
|
||||
.def_readwrite("error", &Frame::error);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_scriptstatusmessage(pybind11::module_& m) {
|
||||
pybind11::class_<ScriptStatusMessage, std::shared_ptr<ScriptStatusMessage>, Message>(m, "ScriptStatusMessage")
|
||||
pybind11::classh<ScriptStatusMessage, Message>(m, "ScriptStatusMessage")
|
||||
.def_readonly("isEncrypted", &ScriptStatusMessage::isEncrypted)
|
||||
.def_readonly("isCoreminiRunning", &ScriptStatusMessage::isCoreminiRunning)
|
||||
.def_readonly("sectorOverflows", &ScriptStatusMessage::sectorOverflows)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_spimessage(pybind11::module_& m) {
|
||||
pybind11::class_<SPIMessage, std::shared_ptr<SPIMessage>, Frame> spiMessage(m, "SPIMessage");
|
||||
pybind11::classh<SPIMessage, Frame> spiMessage(m, "SPIMessage");
|
||||
pybind11::enum_<SPIMessage::Direction>(spiMessage, "Direction")
|
||||
.value("Write", SPIMessage::Direction::Write)
|
||||
.value("Read", SPIMessage::Direction::Read);
|
||||
|
||||
@@ -17,7 +17,7 @@ void init_tc10statusmessage(pybind11::module_& m) {
|
||||
.value("SleepFailed", TC10SleepStatus::SleepFailed)
|
||||
.value("SleepAborted", TC10SleepStatus::SleepAborted);
|
||||
|
||||
pybind11::class_<TC10StatusMessage, std::shared_ptr<TC10StatusMessage>, Message>(m, "TC10StatusMessage")
|
||||
pybind11::classh<TC10StatusMessage, Message>(m, "TC10StatusMessage")
|
||||
.def_readonly("wakeStatus", &TC10StatusMessage::wakeStatus)
|
||||
.def_readonly("sleepStatus", &TC10StatusMessage::sleepStatus);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/communication/network.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_network(pybind11::module_& m) {
|
||||
pybind11::class_<Network> network(m, "Network");
|
||||
pybind11::classh<Network> network(m, "Network");
|
||||
|
||||
pybind11::enum_<Network::NetID>(network, "NetID")
|
||||
pybind11::native_enum<Network::NetID>(network, "NetID", "enum.IntEnum")
|
||||
.value("Device", Network::NetID::Device)
|
||||
.value("DWCAN_01", Network::NetID::DWCAN_01)
|
||||
.value("DWCAN_08", Network::NetID::DWCAN_08)
|
||||
@@ -166,9 +167,10 @@ void init_network(pybind11::module_& m) {
|
||||
.value("LIN_15", Network::NetID::LIN_15)
|
||||
.value("LIN_16", Network::NetID::LIN_16)
|
||||
.value("Any", Network::NetID::Any)
|
||||
.value("Invalid", Network::NetID::Invalid);
|
||||
.value("Invalid", Network::NetID::Invalid)
|
||||
.finalize();
|
||||
|
||||
pybind11::enum_<Network::Type>(network, "Type")
|
||||
pybind11::native_enum<Network::Type>(network, "Type", "enum.Enum")
|
||||
.value("Invalid", Network::Type::Invalid)
|
||||
.value("Internal", Network::Type::Internal)
|
||||
.value("CAN", Network::Type::CAN)
|
||||
@@ -185,7 +187,8 @@ void init_network(pybind11::module_& m) {
|
||||
.value("MDIO", Network::Type::MDIO)
|
||||
.value("AutomotiveEthernet", Network::Type::AutomotiveEthernet)
|
||||
.value("Any", Network::Type::Any)
|
||||
.value("Other", Network::Type::Other);
|
||||
.value("Other", Network::Type::Other)
|
||||
.finalize();
|
||||
|
||||
network
|
||||
.def(pybind11::init<Network::NetID>())
|
||||
|
||||
@@ -35,17 +35,17 @@ void init_macsecconfig(pybind11::module_ & m)
|
||||
.value("GCM_AES_128_XPN", MACsecCipherSuite::GcmAes128Xpn)
|
||||
.value("GCM_AES_256_XPN", MACsecCipherSuite::GcmAes256Xpn);
|
||||
|
||||
pybind11::class_<MACsecVLANTag, std::shared_ptr<MACsecVLANTag>>(m, "MACsecVLANTag")
|
||||
pybind11::classh<MACsecVLANTag>(m, "MACsecVLANTag")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("vid", &MACsecVLANTag::vid)
|
||||
.def_readwrite("pri_cfi", &MACsecVLANTag::priCfi);
|
||||
|
||||
pybind11::class_<MACsecMPLSOuter, std::shared_ptr<MACsecMPLSOuter>>(m, "MACsecMPLSOuter")
|
||||
pybind11::classh<MACsecMPLSOuter>(m, "MACsecMPLSOuter")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("mpls_label", &MACsecMPLSOuter::mplsLabel)
|
||||
.def_readwrite("exp", &MACsecMPLSOuter::exp);
|
||||
|
||||
pybind11::class_<MACsecTci, std::shared_ptr<MACsecTci>>(m, "MACsecTci")
|
||||
pybind11::classh<MACsecTci>(m, "MACsecTci")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("es", &MACsecTci::es)
|
||||
.def_readwrite("sc", &MACsecTci::sc)
|
||||
@@ -53,7 +53,7 @@ void init_macsecconfig(pybind11::module_ & m)
|
||||
.def_readwrite("e", &MACsecTci::e)
|
||||
.def_readwrite("c", &MACsecTci::c);
|
||||
|
||||
pybind11::class_<MACsecRxRule, std::shared_ptr<MACsecRxRule>>(m, "MACsecRxRule")
|
||||
pybind11::classh<MACsecRxRule>(m, "MACsecRxRule")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("key_mac_da", &MACsecRxRule::keyMacDa)
|
||||
.def_readwrite("mask_mac_da", &MACsecRxRule::maskMacDa)
|
||||
@@ -85,7 +85,7 @@ void init_macsecconfig(pybind11::module_ & m)
|
||||
.def_readwrite("mask_express", &MACsecRxRule::maskExpress)
|
||||
.def_readwrite("is_mpls", &MACsecRxRule::isMpls);
|
||||
|
||||
pybind11::class_<MACsecTxSecY, std::shared_ptr<MACsecTxSecY>>(m, "MACsecTxSecY")
|
||||
pybind11::classh<MACsecTxSecY>(m, "MACsecTxSecY")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("enable_control_port", &MACsecTxSecY::enableControlPort)
|
||||
.def_readwrite("cipher", &MACsecTxSecY::cipher)
|
||||
@@ -99,7 +99,7 @@ void init_macsecconfig(pybind11::module_ & m)
|
||||
.def_readwrite("auxiliary_policy", &MACsecTxSecY::auxiliaryPolicy)
|
||||
.def_readwrite("sci", &MACsecTxSecY::sci);
|
||||
|
||||
pybind11::class_<MACsecRxSecY, std::shared_ptr<MACsecRxSecY>>(m, "MACsecRxSecY")
|
||||
pybind11::classh<MACsecRxSecY>(m, "MACsecRxSecY")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("enable_control_port", &MACsecRxSecY::enableControlPort)
|
||||
.def_readwrite("frame_validation", &MACsecRxSecY::frameValidation)
|
||||
@@ -112,7 +112,7 @@ void init_macsecconfig(pybind11::module_ & m)
|
||||
.def_readwrite("is_control_packet", &MACsecRxSecY::isControlPacket)
|
||||
.def_readwrite("sci", &MACsecRxSecY::sci);
|
||||
|
||||
pybind11::class_<MACsecTxSa, std::shared_ptr<MACsecTxSa>>(m, "MACsecTxSa")
|
||||
pybind11::classh<MACsecTxSa>(m, "MACsecTxSa")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("sak", &MACsecTxSa::sak)
|
||||
.def_readwrite("hash_key", &MACsecTxSa::hashKey)
|
||||
@@ -121,7 +121,7 @@ void init_macsecconfig(pybind11::module_ & m)
|
||||
.def_readwrite("next_pn", &MACsecTxSa::nextPn)
|
||||
.def_readwrite("an", &MACsecTxSa::an);
|
||||
|
||||
pybind11::class_<MACsecRxSa, std::shared_ptr<MACsecRxSa>>(m, "MACsecRxSa")
|
||||
pybind11::classh<MACsecRxSa>(m, "MACsecRxSa")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("sak", &MACsecRxSa::sak)
|
||||
.def_readwrite("hash_key", &MACsecRxSa::hashKey)
|
||||
@@ -129,7 +129,7 @@ void init_macsecconfig(pybind11::module_ & m)
|
||||
.def_readwrite("ssci", &MACsecRxSa::ssci)
|
||||
.def_readwrite("next_pn", &MACsecRxSa::nextPn);
|
||||
|
||||
pybind11::class_<MACsecConfig, std::shared_ptr<MACsecConfig>>(m, "MACsecConfig")
|
||||
pybind11::classh<MACsecConfig>(m, "MACsecConfig")
|
||||
.def(pybind11::init<icsneo::DeviceType>())
|
||||
.def("add_rx_secy", &MACsecConfig::addRxSecY, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("add_tx_secY", &MACsecConfig::addTxSecY, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/device/chipid.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_chipid(pybind11::module_& m) {
|
||||
pybind11::enum_<ChipID>(m, "ChipID")
|
||||
pybind11::native_enum<ChipID>(m, "ChipID", "enum.IntEnum")
|
||||
.value("neoVIFIRE_MCHIP", ChipID::neoVIFIRE_MCHIP)
|
||||
.value("neoVIFIRE_LCHIP", ChipID::neoVIFIRE_LCHIP)
|
||||
.value("neoVIFIRE_UCHIP", ChipID::neoVIFIRE_UCHIP)
|
||||
@@ -102,7 +103,7 @@ void init_chipid(pybind11::module_& m) {
|
||||
.value("neoOBD2Dev_MCHIP", ChipID::neoOBD2Dev_MCHIP)
|
||||
.value("neoOBD2Dev_SCHIP", ChipID::neoOBD2Dev_SCHIP)
|
||||
.value("neoOBD2SIMDoIP_MCHIP", ChipID::neoOBD2SIMDoIP_MCHIP)
|
||||
.value("SFPModule_MCHIP", ChipID::SFPModule_MCHIP)
|
||||
.value("SFPModule_88q2112_MCHIP", ChipID::SFPModule_88q2112_MCHIP)
|
||||
.value("RADEpsilonT_MCHIP", ChipID::RADEpsilonT_MCHIP)
|
||||
.value("RADEpsilonExpress_MCHIP", ChipID::RADEpsilonExpress_MCHIP)
|
||||
.value("RADProxima_MCHIP", ChipID::RADProxima_MCHIP)
|
||||
@@ -110,7 +111,7 @@ void init_chipid(pybind11::module_& m) {
|
||||
.value("RAD_GALAXY_2_ZMPCHIP_ID", ChipID::RAD_GALAXY_2_ZMPCHIP_ID)
|
||||
.value("NewDevice59_MCHIP", ChipID::NewDevice59_MCHIP)
|
||||
.value("RADMoon2_Z7010_ZYNQ", ChipID::RADMoon2_Z7010_ZYNQ)
|
||||
.value("neoVIFIRE2_CORE_SG4", ChipID::neoVIFIRE2_CORE_SG4)
|
||||
.value("neoVIFIRE2_Core_SG4", ChipID::neoVIFIRE2_Core_SG4)
|
||||
.value("RADBMS_MCHIP", ChipID::RADBMS_MCHIP)
|
||||
.value("RADMoon2_ZL_MCHIP", ChipID::RADMoon2_ZL_MCHIP)
|
||||
.value("RADGigastar_USBZ_Z7010_ZYNQ", ChipID::RADGigastar_USBZ_Z7010_ZYNQ)
|
||||
@@ -125,12 +126,17 @@ void init_chipid(pybind11::module_& m) {
|
||||
.value("RADGigastar_FFG_ZYNQ", ChipID::RADGigastar_FFG_ZYNQ)
|
||||
.value("VEM_02_FR_FCHIP", ChipID::VEM_02_FR_FCHIP)
|
||||
.value("Connect_ZCHIP", ChipID::Connect_ZCHIP)
|
||||
.value("SFPModule_88q2221_MCHIP", ChipID::SFPModule_88q2221_MCHIP)
|
||||
.value("RADGALAXY2_SYSMON_CHIP", ChipID::RADGALAXY2_SYSMON_CHIP)
|
||||
.value("SFPModule_88q3244_MCHIP", ChipID::SFPModule_88q3244_MCHIP)
|
||||
.value("RADCOMET3_ZCHIP", ChipID::RADCOMET3_ZCHIP)
|
||||
.value("Connect_LINUX", ChipID::Connect_LINUX)
|
||||
.value("SFPModule_lan8670_MCHIP", ChipID::SFPModule_lan8670_MCHIP)
|
||||
.value("RADGigastar2_ZYNQ", ChipID::RADGigastar2_ZYNQ)
|
||||
.value("SFPModule_ent11100_MCHIP", ChipID::SFPModule_ent11100_MCHIP)
|
||||
.value("RADGemini_MCHIP", ChipID::RADGemini_MCHIP)
|
||||
.value("Invalid", ChipID::Invalid);
|
||||
.value("Invalid", ChipID::Invalid)
|
||||
.finalize();
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
|
||||
#include "icsneo/device/device.h"
|
||||
#include "icsneo/device/extensions/deviceextension.h"
|
||||
#include "icsneo/disk/diskdetails.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_device(pybind11::module_& m) {
|
||||
pybind11::class_<Device, std::shared_ptr<Device>>(m, "Device")
|
||||
pybind11::classh<Device>(m, "Device")
|
||||
.def("__repr__", &Device::describe)
|
||||
.def("add_message_callback", &Device::addMessageCallback, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("clear_script", &Device::clearScript, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
@@ -31,6 +32,8 @@ void init_device(pybind11::module_& m) {
|
||||
.def("get_script_status", &Device::getScriptStatus, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_serial_number", &Device::getSerialNumber)
|
||||
.def("get_serial", &Device::getSerial)
|
||||
.def("get_pcb_serial", &Device::getPCBSerial, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_mac_address", &Device::getMACAddress, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.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_tc10_status", &Device::getTC10Status, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
@@ -52,11 +55,21 @@ void init_device(pybind11::module_& m) {
|
||||
.def("start_script", &Device::startScript, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("stop_script", &Device::stopScript, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("supports_tc10", &Device::supportsTC10)
|
||||
.def("supports_live_data", &Device::supportsLiveData)
|
||||
.def("subscribe_live_data", &Device::subscribeLiveData, pybind11::arg("message"), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("unsubscribe_live_data", &Device::unsubscribeLiveData, pybind11::arg("handle"), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("clear_all_live_data", &Device::clearAllLiveData, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_value_live_data", &Device::setValueLiveData, pybind11::arg("message"), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("transmit", pybind11::overload_cast<std::shared_ptr<Frame>>(&Device::transmit), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("upload_coremini", [](Device& device, std::string& path, Disk::MemoryType memType) { std::ifstream ifs(path, std::ios::binary); return device.uploadCoremini(ifs, memType); }, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("write_macsec_config", &Device::writeMACsecConfig, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("send_eth_phy_msg", &Device::sendEthPhyMsg, pybind11::arg("message"), pybind11::arg("timeout") = std::chrono::milliseconds(50), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_chip_versions", &Device::getChipVersions, pybind11::arg("refreshComponents") = true, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("supports_disk_formatting", &Device::supportsDiskFormatting, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_disk_count", &Device::getDiskCount, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_disk_details", &Device::getDiskDetails, pybind11::arg("timeout") = std::chrono::milliseconds(100), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("force_disk_config_update", &Device::forceDiskConfigUpdate, pybind11::arg("config"), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("format_disk", [](Device& device, const DiskDetails& config) -> bool { return device.formatDisk(config); }, pybind11::arg("config"), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def_readonly("settings", &Device::settings);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/device/devicetype.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_devicetype(pybind11::module_& m) {
|
||||
pybind11::class_<DeviceType> deviceType(m, "DeviceType");
|
||||
pybind11::enum_<DeviceType::Enum>(deviceType, "Enum")
|
||||
pybind11::classh<DeviceType> deviceType(m, "DeviceType");
|
||||
pybind11::native_enum<DeviceType::Enum>(deviceType, "Enum", "enum.IntEnum")
|
||||
.value("Unknown", DeviceType::Enum::Unknown)
|
||||
.value("BLUE", DeviceType::Enum::BLUE)
|
||||
.value("ECU_AVB", DeviceType::Enum::ECU_AVB)
|
||||
@@ -70,7 +71,8 @@ void init_devicetype(pybind11::module_& m) {
|
||||
.value("RADGalaxy", DeviceType::Enum::RADGalaxy)
|
||||
.value("RADStar2", DeviceType::Enum::RADStar2)
|
||||
.value("VividCAN", DeviceType::Enum::VividCAN)
|
||||
.value("OBD2_SIM", DeviceType::Enum::OBD2_SIM);
|
||||
.value("OBD2_SIM", DeviceType::Enum::OBD2_SIM)
|
||||
.finalize();
|
||||
deviceType.def(pybind11::init<DeviceType::Enum>());
|
||||
deviceType.def("get_device_type", &DeviceType::getDeviceType);
|
||||
deviceType.def("get_generic_product_name", &DeviceType::getGenericProductName);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_deviceextension(pybind11::module_& m) {
|
||||
pybind11::class_<DeviceExtension, std::shared_ptr<DeviceExtension>>(m, "DeviceExtension")
|
||||
pybind11::classh<DeviceExtension>(m, "DeviceExtension")
|
||||
.def("get_name", &DeviceExtension::getName);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,35 +12,117 @@ namespace icsneo {
|
||||
|
||||
struct DeviceSettingsNamespace {
|
||||
using EthLinkMode = AELinkMode;
|
||||
using LinkSpeed = EthLinkSpeed;
|
||||
};
|
||||
|
||||
void init_idevicesettings(pybind11::module_& m) {
|
||||
pybind11::class_<DeviceSettingsNamespace> settings(m, "Settings");
|
||||
pybind11::classh<DeviceSettingsNamespace> settings(m, "Settings");
|
||||
|
||||
pybind11::enum_<DeviceSettingsNamespace::EthLinkMode>(settings, "EthernetLinkMode")
|
||||
.value("Auto", DeviceSettingsNamespace::EthLinkMode::AE_LINK_AUTO)
|
||||
.value("Slave", DeviceSettingsNamespace::EthLinkMode::AE_LINK_SLAVE)
|
||||
.value("Master", DeviceSettingsNamespace::EthLinkMode::AE_LINK_MASTER);
|
||||
|
||||
pybind11::enum_<DeviceSettingsNamespace::LinkSpeed>(settings, "EthernetLinkSpeed")
|
||||
.value("Speed10M", DeviceSettingsNamespace::LinkSpeed::ETH_SPEED_10)
|
||||
.value("Speed100M", DeviceSettingsNamespace::LinkSpeed::ETH_SPEED_100)
|
||||
.value("Speed1G", DeviceSettingsNamespace::LinkSpeed::ETH_SPEED_1000)
|
||||
.value("Speed2_5G", DeviceSettingsNamespace::LinkSpeed::ETH_SPEED_2500)
|
||||
.value("Speed5G", DeviceSettingsNamespace::LinkSpeed::ETH_SPEED_5000)
|
||||
.value("Speed10G", DeviceSettingsNamespace::LinkSpeed::ETH_SPEED_10000);
|
||||
pybind11::enum_<EthPhyLinkMode>(settings, "PhyLinkMode")
|
||||
.value("ETH_LINK_MODE_AUTO_NEGOTIATION", ETH_LINK_MODE_AUTO_NEGOTIATION)
|
||||
.value("ETH_LINK_MODE_10MBPS_HALFDUPLEX", ETH_LINK_MODE_10MBPS_HALFDUPLEX)
|
||||
.value("ETH_LINK_MODE_10MBPS_FULLDUPLEX", ETH_LINK_MODE_10MBPS_FULLDUPLEX)
|
||||
.value("ETH_LINK_MODE_100MBPS_HALFDUPLEX", ETH_LINK_MODE_100MBPS_HALFDUPLEX)
|
||||
.value("ETH_LINK_MODE_100MBPS_FULLDUPLEX", ETH_LINK_MODE_100MBPS_FULLDUPLEX)
|
||||
.value("ETH_LINK_MODE_1GBPS_HALFDUPLEX", ETH_LINK_MODE_1GBPS_HALFDUPLEX)
|
||||
.value("ETH_LINK_MODE_1GBPS_FULLDUPLEX", ETH_LINK_MODE_1GBPS_FULLDUPLEX)
|
||||
.value("ETH_LINK_MODE_2_5GBPS_FULLDUPLEX", ETH_LINK_MODE_2_5GBPS_FULLDUPLEX)
|
||||
.value("ETH_LINK_MODE_5GBPS_FULLDUPLEX", ETH_LINK_MODE_5GBPS_FULLDUPLEX)
|
||||
.value("ETH_LINK_MODE_10GBPS_FULLDUPLEX", ETH_LINK_MODE_10GBPS_FULLDUPLEX);
|
||||
|
||||
pybind11::class_<IDeviceSettings, std::shared_ptr<IDeviceSettings>>(m, "IDeviceSettings")
|
||||
pybind11::enum_<LINMode>(settings, "LINMode")
|
||||
.value("Sleep", LINMode::SLEEP_MODE)
|
||||
.value("Slow", LINMode::SLOW_MODE)
|
||||
.value("Normal", LINMode::NORMAL_MODE)
|
||||
.value("Fast", LINMode::FAST_MODE);
|
||||
|
||||
pybind11::enum_<MiscIOAnalogVoltage>(settings, "MiscIOAnalogVoltage")
|
||||
.value("V0", MiscIOAnalogVoltage::V0)
|
||||
.value("V1", MiscIOAnalogVoltage::V1)
|
||||
.value("V2", MiscIOAnalogVoltage::V2)
|
||||
.value("V3", MiscIOAnalogVoltage::V3)
|
||||
.value("V4", MiscIOAnalogVoltage::V4)
|
||||
.value("V5", MiscIOAnalogVoltage::V5);
|
||||
|
||||
pybind11::classh<IDeviceSettings>(m, "IDeviceSettings")
|
||||
.def("apply", &IDeviceSettings::apply, pybind11::arg("temporary") = 0, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("apply_defaults", &IDeviceSettings::applyDefaults, pybind11::arg("temporary") = 0, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("refresh", &IDeviceSettings::refresh, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// Baudrate methods
|
||||
.def("get_baudrate", &IDeviceSettings::getBaudrateFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_baudrate", &IDeviceSettings::setBaudrateFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_fd_baudrate", &IDeviceSettings::getFDBaudrateFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_fd_baudrate", &IDeviceSettings::setFDBaudrateFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// Termination methods
|
||||
.def("is_termination_supported", &IDeviceSettings::isTerminationSupportedFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("can_termination_be_enabled", &IDeviceSettings::canTerminationBeEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("is_termination_enabled", &IDeviceSettings::isTerminationEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_termination", &IDeviceSettings::setTerminationFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_termination_groups", &IDeviceSettings::getTerminationGroups, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// LIN methods
|
||||
.def("is_commander_resistor_enabled", &IDeviceSettings::isCommanderResistorEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_commander_resistor", &IDeviceSettings::setCommanderResistorFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_lin_mode", &IDeviceSettings::getLINModeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_lin_mode", &IDeviceSettings::setLINModeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_lin_commander_response_time", &IDeviceSettings::getLINCommanderResponseTimeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_lin_commander_response_time", &IDeviceSettings::setLINCommanderResponseTimeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// Ethernet PHY methods (index-based for switch devices)
|
||||
.def("get_phy_enable", &IDeviceSettings::getPhyEnable, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_phy_mode", &IDeviceSettings::getPhyMode, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_phy_speed", &IDeviceSettings::getPhySpeed, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_phy_enable", &IDeviceSettings::setPhyEnable, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_phy_mode", &IDeviceSettings::setPhyMode, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_phy_speed", &IDeviceSettings::setPhySpeed, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("refresh", &IDeviceSettings::refresh, pybind11::call_guard<pybind11::gil_scoped_release>());
|
||||
|
||||
// Ethernet PHY methods (network-based for multi-interface devices)
|
||||
.def("get_phy_enable_for", &IDeviceSettings::getPhyEnableFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_phy_role_for", &IDeviceSettings::getPhyRoleFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_phy_link_mode_for", &IDeviceSettings::getPhyLinkModeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_phy_enable_for", &IDeviceSettings::setPhyEnableFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_phy_role_for", &IDeviceSettings::setPhyRoleFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_phy_link_mode_for", &IDeviceSettings::setPhyLinkModeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_supported_phy_link_modes_for", &IDeviceSettings::getSupportedPhyLinkModesFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// 10BASE-T1S methods
|
||||
.def("is_t1s_plca_enabled", &IDeviceSettings::isT1SPLCAEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_plca", &IDeviceSettings::setT1SPLCAFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_local_id", &IDeviceSettings::getT1SLocalIDFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_local_id", &IDeviceSettings::setT1SLocalIDFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_max_nodes", &IDeviceSettings::getT1SMaxNodesFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_max_nodes", &IDeviceSettings::setT1SMaxNodesFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_tx_opp_timer", &IDeviceSettings::getT1STxOppTimerFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_tx_opp_timer", &IDeviceSettings::setT1STxOppTimerFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_max_burst", &IDeviceSettings::getT1SMaxBurstFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_max_burst", &IDeviceSettings::setT1SMaxBurstFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_burst_timer", &IDeviceSettings::getT1SBurstTimerFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_burst_timer", &IDeviceSettings::setT1SBurstTimerFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_local_id_alternate", &IDeviceSettings::getT1SLocalIDAlternateFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_local_id_alternate", &IDeviceSettings::setT1SLocalIDAlternateFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("is_t1s_termination_enabled", &IDeviceSettings::isT1STerminationEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_termination", &IDeviceSettings::setT1STerminationFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("is_t1s_bus_decoding_beacons_enabled", &IDeviceSettings::isT1SBusDecodingBeaconsEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_bus_decoding_beacons", &IDeviceSettings::setT1SBusDecodingBeaconsFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("is_t1s_bus_decoding_all_enabled", &IDeviceSettings::isT1SBusDecodingAllEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_bus_decoding_all", &IDeviceSettings::setT1SBusDecodingAllFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_multi_id_enable_mask", &IDeviceSettings::getT1SMultiIDEnableMaskFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_multi_id_enable_mask", &IDeviceSettings::setT1SMultiIDEnableMaskFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_multi_id", &IDeviceSettings::getT1SMultiIDFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_multi_id", &IDeviceSettings::setT1SMultiIDFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
.def("set_misc_io_analog_output_enabled", &IDeviceSettings::setMiscIOAnalogOutputEnabled, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_misc_io_analog_output", &IDeviceSettings::setMiscIOAnalogOutput, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// Status properties
|
||||
.def_readonly("disabled", &IDeviceSettings::disabled)
|
||||
.def_readonly("readonly", &IDeviceSettings::readonly);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_versionreport(pybind11::module_& m) {
|
||||
pybind11::class_<VersionReport>(m, "VersionReport")
|
||||
pybind11::classh<VersionReport>(m, "VersionReport")
|
||||
.def_readonly("id", &VersionReport::id)
|
||||
.def_readonly("name", &VersionReport::name)
|
||||
.def_readonly("major", &VersionReport::major)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
#include "icsneo/disk/diskdetails.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_diskdetails(pybind11::module_& m) {
|
||||
pybind11::enum_<DiskLayout>(m, "DiskLayout")
|
||||
.value("Spanned", DiskLayout::Spanned)
|
||||
.value("RAID0", DiskLayout::RAID0);
|
||||
|
||||
pybind11::classh<DiskInfo>(m, "DiskInfo")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("present", &DiskInfo::present)
|
||||
.def_readwrite("initialized", &DiskInfo::initialized)
|
||||
.def_readwrite("formatted", &DiskInfo::formatted)
|
||||
.def_readwrite("sectors", &DiskInfo::sectors)
|
||||
.def_readwrite("bytes_per_sector", &DiskInfo::bytesPerSector)
|
||||
.def("size", &DiskInfo::size);
|
||||
|
||||
pybind11::classh<DiskDetails>(m, "DiskDetails")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("layout", &DiskDetails::layout)
|
||||
.def_readwrite("full_format", &DiskDetails::fullFormat)
|
||||
.def_readwrite("disks", &DiskDetails::disks);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -13,7 +13,7 @@ struct DiskNamespace {
|
||||
};
|
||||
|
||||
void init_diskdriver(pybind11::module_& m) {
|
||||
pybind11::class_<DiskNamespace> disk(m, "Disk");
|
||||
pybind11::classh<DiskNamespace> disk(m, "Disk");
|
||||
pybind11::enum_<Disk::Access>(disk, "Access")
|
||||
.value("None", Disk::Access::None)
|
||||
.value("EntireCard", Disk::Access::EntireCard)
|
||||
|
||||
@@ -23,8 +23,8 @@ struct ClusterNamespace {
|
||||
using SPPType = icsneo::FlexRay::Cluster::SPPType;
|
||||
};
|
||||
|
||||
void init_extension(pybind11::class_<FlexRayNamespace>& c) {
|
||||
pybind11::class_<MessageBuffer, std::shared_ptr<MessageBuffer>>(c, "MessageBuffer")
|
||||
void init_extension(pybind11::classh<FlexRayNamespace>& c) {
|
||||
pybind11::classh<MessageBuffer>(c, "MessageBuffer")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("is_dynamic", &MessageBuffer::isDynamic)
|
||||
.def_readwrite("is_sync", &MessageBuffer::isSync)
|
||||
@@ -39,7 +39,7 @@ void init_extension(pybind11::class_<FlexRayNamespace>& c) {
|
||||
.def_readwrite("cycle_repetition", &MessageBuffer::cycleRepetition)
|
||||
.def_readwrite("continuous_mode", &MessageBuffer::continuousMode);
|
||||
|
||||
auto controller = pybind11::class_<Controller, std::shared_ptr<Controller>>(c, "Controller")
|
||||
auto controller = pybind11::classh<Controller>(c, "Controller")
|
||||
.def("get_network", &Controller::getNetwork)
|
||||
.def("get_configuration", &Controller::getConfiguration)
|
||||
.def("set_configuration", &Controller::setConfiguration)
|
||||
@@ -59,11 +59,12 @@ void init_extension(pybind11::class_<FlexRayNamespace>& c) {
|
||||
.def("freeze", &Controller::freeze)
|
||||
.def("trigger_mts", &Controller::triggerMTS);
|
||||
|
||||
pybind11::class_<Controller::Configuration>(controller, "Configuration")
|
||||
pybind11::classh<Controller::Configuration>(controller, "Configuration")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("accept_startup_range_microticks", &Controller::Configuration::AcceptStartupRangeMicroticks)
|
||||
.def_readwrite("allow_passive_to_active_cycle_pairs", &Controller::Configuration::AllowPassiveToActiveCyclePairs)
|
||||
.def_readwrite("cluster_drift_damping", &Controller::Configuration::ClusterDriftDamping)
|
||||
.def_readwrite("allow_halt_due_to_clock", &Controller::Configuration::AllowHaltDueToClock)
|
||||
.def_readwrite("channel_a", &Controller::Configuration::ChannelA)
|
||||
.def_readwrite("channel_b", &Controller::Configuration::ChannelB)
|
||||
.def_readwrite("decoding_correction_microticks", &Controller::Configuration::DecodingCorrectionMicroticks)
|
||||
@@ -74,6 +75,7 @@ void init_extension(pybind11::class_<FlexRayNamespace>& c) {
|
||||
.def_readwrite("extern_offset_correction_microticks", &Controller::Configuration::ExternOffsetCorrectionMicroticks)
|
||||
.def_readwrite("extern_rate_correction_microticks", &Controller::Configuration::ExternRateCorrectionMicroticks)
|
||||
.def_readwrite("key_slot_id", &Controller::Configuration::KeySlotID)
|
||||
.def_readwrite("key_slot_only_enabled", &Controller::Configuration::KeySlotOnlyEnabled)
|
||||
.def_readwrite("key_slot_used_for_startup", &Controller::Configuration::KeySlotUsedForStartup)
|
||||
.def_readwrite("key_slot_used_for_sync", &Controller::Configuration::KeySlotUsedForSync)
|
||||
.def_readwrite("latest_tx_minislot", &Controller::Configuration::LatestTxMinislot)
|
||||
@@ -93,7 +95,7 @@ void init_extension(pybind11::class_<FlexRayNamespace>& c) {
|
||||
.def_readwrite("wakeup_on_channel_b", &Controller::Configuration::WakeupOnChannelB);
|
||||
|
||||
// Dummy class for cluster namespace
|
||||
pybind11::class_<ClusterNamespace> cluster(c, "Cluster");
|
||||
pybind11::classh<ClusterNamespace> cluster(c, "Cluster");
|
||||
|
||||
pybind11::enum_<Cluster::SpeedType>(cluster, "SpeedType")
|
||||
.value("FLEXRAY_BAUDRATE_10M", Cluster::SpeedType::FLEXRAY_BAUDRATE_10M)
|
||||
@@ -107,13 +109,14 @@ void init_extension(pybind11::class_<FlexRayNamespace>& c) {
|
||||
.value("FLEXRAY_SPP_6", Cluster::SPPType::FLEXRAY_SPP_6)
|
||||
.value("FLEXRAY_SPP_5_ALT", Cluster::SPPType::FLEXRAY_SPP_5_ALT);
|
||||
|
||||
pybind11::class_<Cluster::Configuration>(cluster, "Configuration")
|
||||
pybind11::classh<Cluster::Configuration>(cluster, "Configuration")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("speed", &Cluster::Configuration::Speed)
|
||||
.def_readwrite("strobe_point_position", &Cluster::Configuration::StrobePointPosition)
|
||||
.def_readwrite("action_point_offset", &Cluster::Configuration::ActionPointOffset)
|
||||
.def_readwrite("casr_x_low_max", &Cluster::Configuration::CASRxLowMax)
|
||||
.def_readwrite("cold_start_attempts", &Cluster::Configuration::ColdStartAttempts)
|
||||
.def_readwrite("cycle_duration_micro_sec", &Cluster::Configuration::CycleDurationMicroSec)
|
||||
.def_readwrite("dynamic_slot_idle_phase_minislots", &Cluster::Configuration::DynamicSlotIdlePhaseMinislots)
|
||||
.def_readwrite("listen_noise_macroticks", &Cluster::Configuration::ListenNoiseMacroticks)
|
||||
.def_readwrite("macroticks_per_cycle", &Cluster::Configuration::MacroticksPerCycle)
|
||||
@@ -143,7 +146,7 @@ void init_extension(pybind11::class_<FlexRayNamespace>& c) {
|
||||
} // namespace FlexRay
|
||||
|
||||
void init_flexraymessage(pybind11::module_& m) {
|
||||
pybind11::class_<FlexRayMessage, std::shared_ptr<FlexRayMessage>, Frame>(m, "FlexRayMessage")
|
||||
pybind11::classh<FlexRayMessage, Frame>(m, "FlexRayMessage")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("slotid", &FlexRayMessage::slotid)
|
||||
.def_readwrite("tsslen", &FlexRayMessage::tsslen)
|
||||
@@ -159,14 +162,15 @@ void init_flexraymessage(pybind11::module_& m) {
|
||||
.def_readwrite("sync_frame", &FlexRayMessage::sync)
|
||||
.def_readwrite("startup_frame", &FlexRayMessage::startup)
|
||||
.def_readwrite("dynamic_frame", &FlexRayMessage::dynamic)
|
||||
.def_readwrite("cycle", &FlexRayMessage::cycle);
|
||||
.def_readwrite("cycle", &FlexRayMessage::cycle)
|
||||
.def_readwrite("cycle_repetition", &FlexRayMessage::cycleRepetition);
|
||||
|
||||
//// TODO: Eliminate FlexRayControlMessage class references in controller class and eliminate getStatus function in bindings
|
||||
}
|
||||
|
||||
void init_flexray(pybind11::module_& m) {
|
||||
// Dummy class to act as FlexRay namespace
|
||||
pybind11::class_<FlexRayNamespace> flexray(m, "FlexRay");
|
||||
pybind11::classh<FlexRayNamespace> flexray(m, "FlexRay");
|
||||
|
||||
pybind11::enum_<FlexRayNamespace::Symbol>(flexray, "Symbol")
|
||||
.value("None", FlexRayNamespace::Symbol::None)
|
||||
|
||||
@@ -25,6 +25,7 @@ void init_ethernetstatusmessage(pybind11::module_&);
|
||||
void init_macsecconfig(pybind11::module_&);
|
||||
void init_scriptstatusmessage(pybind11::module_&);
|
||||
void init_diskdriver(pybind11::module_&);
|
||||
void init_diskdetails(pybind11::module_&);
|
||||
void init_deviceextension(pybind11::module_&);
|
||||
void init_chipid(pybind11::module_&);
|
||||
void init_versionreport(pybind11::module_&);
|
||||
@@ -35,6 +36,8 @@ void init_version(pybind11::module_&);
|
||||
void init_flexray(pybind11::module_& m);
|
||||
void init_idevicesettings(pybind11::module_&);
|
||||
void init_ethphymessage(pybind11::module_&);
|
||||
void init_livedata(pybind11::module_&);
|
||||
void init_livedatamessage(pybind11::module_&);
|
||||
|
||||
PYBIND11_MODULE(icsneopy, m) {
|
||||
pybind11::options options;
|
||||
@@ -48,6 +51,7 @@ PYBIND11_MODULE(icsneopy, m) {
|
||||
init_devicetype(m);
|
||||
init_network(m);
|
||||
init_io(m);
|
||||
init_livedata(m);
|
||||
init_message(m);
|
||||
init_canmessage(m);
|
||||
init_canerrormessage(m);
|
||||
@@ -60,9 +64,11 @@ PYBIND11_MODULE(icsneopy, m) {
|
||||
init_macsecconfig(m);
|
||||
init_scriptstatusmessage(m);
|
||||
init_spimessage(m);
|
||||
init_livedatamessage(m);
|
||||
init_messagefilter(m);
|
||||
init_messagecallback(m);
|
||||
init_diskdriver(m);
|
||||
init_diskdetails(m);
|
||||
init_flexray(m);
|
||||
init_ethphymessage(m);
|
||||
init_chipid(m);
|
||||
|
||||
@@ -326,11 +326,15 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||
case ExtendedCommand::GenericBinaryInfo:
|
||||
result = GenericBinaryStatusPacket::DecodeToMessage(packet->data);
|
||||
return true;
|
||||
case ExtendedCommand::SoftwareUpdate: {
|
||||
result = std::make_shared<ExtendedResponseMessage>(ExtendedCommand::SoftwareUpdate, ExtendedResponse::OperationPending, packet->data);
|
||||
return true;
|
||||
}
|
||||
case ExtendedCommand::GenericReturn: {
|
||||
if(packet->data.size() < sizeof(ExtendedResponseMessage::PackedGenericResponse))
|
||||
break;
|
||||
const auto& packedResp = *reinterpret_cast<ExtendedResponseMessage::PackedGenericResponse*>(packet->data.data());
|
||||
result = std::make_shared<ExtendedResponseMessage>(packedResp.command, packedResp.returnCode);
|
||||
result = std::make_shared<ExtendedResponseMessage>(packedResp.command, packedResp.returnCode, packet->data);
|
||||
return true;
|
||||
}
|
||||
case ExtendedCommand::LiveData:
|
||||
|
||||
@@ -56,6 +56,7 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
|
||||
|
||||
break;
|
||||
}
|
||||
case Network::Type::Internal:
|
||||
case Network::Type::CAN:
|
||||
case Network::Type::SWCAN:
|
||||
case Network::Type::LSFTCAN: {
|
||||
|
||||
@@ -19,7 +19,8 @@ double liveDataValueToDouble(const LiveDataValue& val) {
|
||||
return val.value * liveDataFixedPointToDouble;
|
||||
}
|
||||
|
||||
bool liveDataDoubleToValue(const double& dFloat, LiveDataValue& value) {
|
||||
std::optional<LiveDataValue> liveDataDoubleToValue(const double& dFloat) {
|
||||
LiveDataValue value;
|
||||
union {
|
||||
struct
|
||||
{
|
||||
@@ -56,23 +57,23 @@ bool liveDataDoubleToValue(const double& dFloat, LiveDataValue& value) {
|
||||
value.value = CminiFixedPt.ValueLarge;
|
||||
|
||||
if(dFloat == (double)0.0)
|
||||
return true;
|
||||
return value;
|
||||
|
||||
//check if double can be stored as 32.32
|
||||
// 0x1 0000 0000 0000 0000 * CM_FIXED_POINT_TO_DOUBLEVALUE = 0x1 0000 0000
|
||||
if(dFloat > INT32_MAX_DOUBLE || dFloat < INT32_MIN_DOUBLE) {
|
||||
EventManager::GetInstance().add(APIEvent::Type::FixedPointOverflow, APIEvent::Severity::Error);
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Use absolute value for minimum fixed point check
|
||||
double absFloat = (dFloat < 0.0) ? -dFloat : dFloat;
|
||||
if(absFloat < MIN_FIXED_POINT_DOUBLE) {
|
||||
EventManager::GetInstance().add(APIEvent::Type::FixedPointPrecision, APIEvent::Severity::Error);
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return true;
|
||||
return value;
|
||||
}
|
||||
|
||||
} // namespace LiveDataUtil
|
||||
|
||||
@@ -7,31 +7,6 @@
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
// copied.. TODO
|
||||
static std::optional<uint8_t> CAN_LengthToDLC(size_t dataLength, bool fd) {
|
||||
if(dataLength <= 8)
|
||||
return uint8_t(dataLength);
|
||||
|
||||
if(fd) {
|
||||
if(dataLength <= 12)
|
||||
return uint8_t(0x9);
|
||||
if(dataLength <= 16)
|
||||
return uint8_t(0xA);
|
||||
if(dataLength <= 20)
|
||||
return uint8_t(0xB);
|
||||
if(dataLength <= 24)
|
||||
return uint8_t(0xC);
|
||||
if(dataLength <= 32)
|
||||
return uint8_t(0xD);
|
||||
if(dataLength <= 48)
|
||||
return uint8_t(0xE);
|
||||
if(dataLength <= 64)
|
||||
return uint8_t(0xF);
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
static std::vector<uint8_t> EncodeFromMessageEthernet(std::shared_ptr<Frame> frame, const device_eventhandler_t& report) {
|
||||
auto ethmsg = std::dynamic_pointer_cast<EthernetMessage>(frame);
|
||||
if(!ethmsg) {
|
||||
@@ -104,6 +79,7 @@ static std::vector<uint8_t> EncodeFromMessageCAN(std::shared_ptr<Frame> frame, c
|
||||
canpacket->header.BRS = canmsg->baudrateSwitch ? 1 : 0;
|
||||
canpacket->header.ESI = canmsg->errorStateIndicator ? 1 : 0;
|
||||
canpacket->dlc.RTR = 0;
|
||||
canpacket->timestamp.IsExtended = 1;
|
||||
|
||||
} else {
|
||||
canpacket->header.EDL = 0;
|
||||
@@ -126,10 +102,71 @@ static std::vector<uint8_t> EncodeFromMessageCAN(std::shared_ptr<Frame> frame, c
|
||||
return encoded;
|
||||
}
|
||||
|
||||
static std::vector<uint8_t> EncodeFromMessageLIN(std::shared_ptr<Frame> /* frame */, const device_eventhandler_t& report) {
|
||||
// TODO
|
||||
report(APIEvent::Type::UnsupportedTXNetwork, APIEvent::Severity::Error);
|
||||
return {};
|
||||
static std::vector<uint8_t> EncodeFromMessageLIN(std::shared_ptr<Frame> frame, const device_eventhandler_t& report) {
|
||||
auto linmsg = std::dynamic_pointer_cast<LINMessage>(frame);
|
||||
if(!linmsg) {
|
||||
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
|
||||
return {};
|
||||
}
|
||||
if(linmsg->linMsgType == LINMessage::Type::NOT_SET) {
|
||||
report(APIEvent::Type::RequiredParameterNull, APIEvent::Severity::Error);
|
||||
return {};
|
||||
}
|
||||
|
||||
size_t dataLen = std::min<size_t>(8, linmsg->data.size());
|
||||
std::vector<uint8_t> encoded;
|
||||
encoded.resize(sizeof(TransmitMessage));
|
||||
|
||||
TransmitMessage* const msg = (TransmitMessage*)encoded.data();
|
||||
HardwareLINPacket* const linpacket = (HardwareLINPacket*)(msg->commonHeader);
|
||||
memset(linpacket, 0, sizeof(HardwareLINPacket));
|
||||
|
||||
// Protected ID and ID
|
||||
linmsg->protectedID = linmsg->calcProtectedID(linmsg->ID);
|
||||
linpacket->CoreMiniBitsLIN.ID = linmsg->protectedID & 0x3F;
|
||||
|
||||
// LIN message type flags
|
||||
switch(linmsg->linMsgType) {
|
||||
case LINMessage::Type::LIN_COMMANDER_MSG:
|
||||
linpacket->CoreMiniBitsLIN.TXCommander = 1;
|
||||
break;
|
||||
case LINMessage::Type::LIN_HEADER_ONLY:
|
||||
linpacket->CoreMiniBitsLIN.TXCommander = 1;
|
||||
break;
|
||||
case LINMessage::Type::LIN_UPDATE_RESPONDER:
|
||||
linpacket->CoreMiniBitsLIN.TXResponder = 1;
|
||||
break;
|
||||
case LINMessage::Type::LIN_BREAK_ONLY:
|
||||
linpacket->CoreMiniBitsLIN.BreakOnly = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Enhanced checksum
|
||||
linpacket->CoreMiniBitsLIN.TxChkSumEnhanced = linmsg->isEnhancedChecksum ? 1 : 0;
|
||||
|
||||
// Data and checksum
|
||||
bool hasData = (linmsg->linMsgType == LINMessage::Type::LIN_COMMANDER_MSG ||
|
||||
linmsg->linMsgType == LINMessage::Type::LIN_UPDATE_RESPONDER) && dataLen > 0;
|
||||
|
||||
if(hasData) {
|
||||
// len includes data bytes + 1 checksum byte
|
||||
linpacket->CoreMiniBitsLIN.len = static_cast<uint16_t>(dataLen + 1);
|
||||
std::copy(linmsg->data.begin(), linmsg->data.begin() + dataLen, linpacket->data);
|
||||
// Checksum goes after data: in data[dataLen] if < 8, otherwise in LINByte9
|
||||
if(dataLen < 8)
|
||||
linpacket->data[dataLen] = linmsg->checksum;
|
||||
else
|
||||
linpacket->CoreMiniBitsLIN.LINByte9 = linmsg->checksum;
|
||||
} else {
|
||||
linpacket->CoreMiniBitsLIN.len = 0;
|
||||
}
|
||||
|
||||
// Description/stats and network
|
||||
linpacket->stats = linmsg->description;
|
||||
|
||||
return encoded;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> TransmitMessage::EncodeFromMessage(std::shared_ptr<Frame> frame, uint32_t client_id, const device_eventhandler_t& report) {
|
||||
@@ -139,6 +176,7 @@ std::vector<uint8_t> TransmitMessage::EncodeFromMessage(std::shared_ptr<Frame> f
|
||||
case Network::Type::AutomotiveEthernet:
|
||||
result = EncodeFromMessageEthernet(frame, report);
|
||||
break;
|
||||
case Network::Type::Internal:
|
||||
case Network::Type::CAN:
|
||||
result = EncodeFromMessageCAN(frame, report);
|
||||
break;
|
||||
@@ -150,6 +188,8 @@ std::vector<uint8_t> TransmitMessage::EncodeFromMessage(std::shared_ptr<Frame> f
|
||||
return result;
|
||||
}
|
||||
// common fields
|
||||
if(result.empty())
|
||||
return result;
|
||||
TransmitMessage* const msg = (TransmitMessage*)result.data();
|
||||
msg->options.clientId = client_id;
|
||||
msg->options.networkId = static_cast<uint32_t>(frame->network.getNetID());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -120,7 +119,12 @@ std::shared_ptr<Message> HardwareCANPacket::DecodeToMessage(const std::vector<ui
|
||||
}
|
||||
|
||||
msg->transmitted = data->eid.TXMSG;
|
||||
// Set the generic frame error state
|
||||
msg->error = data->eid.TXAborted || data->eid.TXError || data->eid.TXLostArb;
|
||||
// Set specific error states for CANError
|
||||
msg->txAborted = data->eid.TXAborted;
|
||||
msg->txLostArb = data->eid.TXLostArb;
|
||||
msg->txError = data->eid.TXError;
|
||||
msg->description = data->stats;
|
||||
|
||||
return msg;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "icsneo/communication/packet/ethernetpacket.h"
|
||||
#include <algorithm> // for std::copy
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
using namespace icsneo;
|
||||
@@ -10,16 +10,17 @@ std::shared_ptr<EthernetMessage> HardwareEthernetPacket::DecodeToMessage(const s
|
||||
// Make sure we have enough to read the packet length first
|
||||
if(bytestream.size() < sizeof(HardwareEthernetPacket))
|
||||
return nullptr;
|
||||
// packet->Length will also encompass the two uint16_t's at the end of the struct, make sure that at least they are here
|
||||
if(packet->Length < 4)
|
||||
return nullptr;
|
||||
const size_t fcsSize = packet->header.FCS_AVAIL ? 4 : 0;
|
||||
// Ensure Length is sufficient for FCS extraction to avoid invalid iterator arithmetic
|
||||
if(packet->Length < fcsSize)
|
||||
return nullptr;
|
||||
const size_t bytestreamExpectedSize = sizeof(HardwareEthernetPacket) + packet->Length;
|
||||
const size_t bytestreamActualSize = bytestream.size();
|
||||
if(bytestreamActualSize < bytestreamExpectedSize)
|
||||
return nullptr;
|
||||
auto messagePtr = std::make_shared<EthernetMessage>();
|
||||
EthernetMessage& message = *messagePtr;
|
||||
// Standard Ethernet fields
|
||||
message.transmitted = packet->eid.TXMSG;
|
||||
if(message.transmitted)
|
||||
message.description = packet->stats;
|
||||
@@ -27,12 +28,28 @@ std::shared_ptr<EthernetMessage> HardwareEthernetPacket::DecodeToMessage(const s
|
||||
if(message.preemptionEnabled)
|
||||
message.preemptionFlags = (uint8_t)((rawWords[0] & 0x03F8) >> 4);
|
||||
message.frameTooShort = packet->header.RUNT_FRAME;
|
||||
message.noPadding = !packet->header.ENABLE_PADDING;
|
||||
message.fcsVerified = packet->header.FCS_VERIFIED;
|
||||
message.txAborted = packet->eid.TXAborted;
|
||||
message.crcError = packet->header.CRC_ERROR;
|
||||
|
||||
if(message.frameTooShort)
|
||||
message.error = true;
|
||||
// This timestamp is raw off the device (in timestampResolution increments)
|
||||
// Decoder will fix as it has information about the timestampResolution increments
|
||||
message.timestamp = packet->timestamp.TS;
|
||||
|
||||
// Check if this is a T1S packet and populate T1S-specific fields
|
||||
message.isT1S = packet->header.T1S_ETHERNET;
|
||||
if(message.isT1S) {
|
||||
message.isT1SSymbol = packet->eid.T1S_SYMBOL;
|
||||
message.isT1SBurst = packet->eid.T1S_BURST;
|
||||
message.txCollision = packet->t1s_status.TXCollision;
|
||||
message.isT1SWake = packet->t1s_status.T1SWake;
|
||||
message.t1sNodeId = packet->t1s_node.T1S_NODE_ID;
|
||||
message.t1sBurstCount = packet->t1s_node.T1S_BURST_COUNT;
|
||||
}
|
||||
|
||||
const std::vector<uint8_t>::const_iterator databegin = bytestream.begin() + sizeof(HardwareEthernetPacket);
|
||||
const std::vector<uint8_t>::const_iterator dataend = databegin + packet->Length - fcsSize;
|
||||
message.data.insert(message.data.begin(), databegin, dataend);
|
||||
|
||||
+29
-1
@@ -144,7 +144,7 @@ typedef union _MACSecSa
|
||||
{
|
||||
uint8_t index; /*!< SA index */
|
||||
uint8_t
|
||||
sak[32]; /*!< 256b SAK: Define the encryption key to be used to encrypte this packet. The lower 128 bits are used for 128-bit ciphers. */
|
||||
sak[32]; /*!< SAK: All 32 bytes are written to the firmware. For AES-128 the firmware requires bytes [0..15] == bytes [16..31] (mirrored); serialize() handles this automatically. */
|
||||
uint8_t hashKey[16]; /*!< 128b Hash Key: Key used for authentication. */
|
||||
uint8_t salt[12]; /*!< 96b Salt value: Salt value used in XPN ciphers. */
|
||||
uint32_t ssci; /*!< 32b SSCI value: Short Secure Channel Identifier, used in XPN ciphers. */
|
||||
@@ -740,6 +740,34 @@ std::vector<uint8_t> MACsecConfig::serialize() const {
|
||||
}
|
||||
}
|
||||
|
||||
// AES-128 SAK normalization: the firmware expects the 16-byte SAK mirrored
|
||||
// into both halves of the 32-byte hardware SAK field. Callers only populate
|
||||
// bytes [0..15]; copy them into [16..31] here, transparent to all callers.
|
||||
for(uint8_t i = 0; i < static_cast<uint8_t>(rxSecY.size()); i++) {
|
||||
if(rxSecY[i].cipher == MACsecCipherSuite::GcmAes128 || rxSecY[i].cipher == MACsecCipherSuite::GcmAes128Xpn) {
|
||||
uint8_t primaryIdx = rxSecYSaIndices[i].first;
|
||||
if(primaryIdx < maxSa)
|
||||
memcpy(hwSettings->macsec.rx.sa[primaryIdx].sak + 16, hwSettings->macsec.rx.sa[primaryIdx].sak, 16);
|
||||
if(rxSecYRekey[i]) {
|
||||
uint8_t rekeyIdx = rxSecYSaIndices[i].second;
|
||||
if(rekeyIdx < maxSa)
|
||||
memcpy(hwSettings->macsec.rx.sa[rekeyIdx].sak + 16, hwSettings->macsec.rx.sa[rekeyIdx].sak, 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(uint8_t i = 0; i < static_cast<uint8_t>(txSecY.size()); i++) {
|
||||
if(txSecY[i].cipher == MACsecCipherSuite::GcmAes128 || txSecY[i].cipher == MACsecCipherSuite::GcmAes128Xpn) {
|
||||
uint8_t primaryIdx = txSecYSaIndices[i].first;
|
||||
if(primaryIdx < maxSa)
|
||||
memcpy(hwSettings->macsec.tx.sa[primaryIdx].sak + 16, hwSettings->macsec.tx.sa[primaryIdx].sak, 16);
|
||||
if(txSecYRekey[i]) {
|
||||
uint8_t rekeyIdx = txSecYSaIndices[i].second;
|
||||
if(rekeyIdx < maxSa)
|
||||
memcpy(hwSettings->macsec.tx.sa[rekeyIdx].sak + 16, hwSettings->macsec.tx.sa[rekeyIdx].sak, 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(rxRule.size() == 0) {
|
||||
MACsecRxRule defaultRule;
|
||||
MACSecRule_t* hwRxRule = &hwSettings->macsec.rx.rule[0];
|
||||
|
||||
+48
-22
@@ -1,4 +1,5 @@
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
#include "icsneo/communication/message/filter/main51messagefilter.h"
|
||||
#include "icsneo/communication/message/extendedresponsemessage.h"
|
||||
@@ -181,12 +182,11 @@ bool Device::getMessages(std::vector<std::shared_ptr<Message>>& container, size_
|
||||
if(container.size() < limit)
|
||||
container.resize(limit);
|
||||
|
||||
size_t actuallyRead;
|
||||
if(timeout != std::chrono::milliseconds(0))
|
||||
actuallyRead = pollingContainer.wait_dequeue_bulk_timed(container.data(), limit, timeout);
|
||||
else
|
||||
actuallyRead = pollingContainer.try_dequeue_bulk(container.data(), limit);
|
||||
|
||||
size_t actuallyRead = 0;
|
||||
if(pollingContainer.wait_dequeue_timed(container.front(), timeout)) {
|
||||
actuallyRead = 1; // Account for the first message we already dequeued
|
||||
actuallyRead += pollingContainer.try_dequeue_bulk(container.data() + 1, limit - 1);
|
||||
}
|
||||
if(container.size() > actuallyRead)
|
||||
container.resize(actuallyRead);
|
||||
|
||||
@@ -395,7 +395,7 @@ bool Device::open(OpenFlags flags, OpenStatusHandler handler) {
|
||||
if(heartbeatCV.wait_for(recvLk, std::chrono::milliseconds(3500), [&](){ return receivedMessage; })) {
|
||||
receivedMessage = false;
|
||||
} else {
|
||||
if(!stopHeartbeatThread && !isDisconnected()) {
|
||||
if(!stopHeartbeatThread) {
|
||||
close();
|
||||
report(APIEvent::Type::DeviceDisconnected, APIEvent::Severity::Error);
|
||||
}
|
||||
@@ -563,24 +563,27 @@ bool Device::goOnline() {
|
||||
if(supportsNetworkMutex()) {
|
||||
assignedClientId = com->getClientIDSync();
|
||||
if(assignedClientId) {
|
||||
std::set<Network::NetID> nets;
|
||||
for(auto&& net : getSupportedTXNetworks()) {
|
||||
nets.insert(net.getNetID());
|
||||
}
|
||||
// firmware supports clientid/mutex
|
||||
networkMutexCallbackHandle = lockAllNetworks(std::numeric_limits<uint32_t>::max(), std::numeric_limits<uint32_t>::max(), NetworkMutexType::Shared, [this](std::shared_ptr<Message> message) {
|
||||
auto netMutexMsg = std::static_pointer_cast<NetworkMutexMessage>(message);
|
||||
if(netMutexMsg->networks.size() && netMutexMsg->event.has_value()) {
|
||||
switch(*netMutexMsg->event) {
|
||||
case NetworkMutexEvent::Acquired:
|
||||
lockedNetworks.emplace(*netMutexMsg->networks.begin());
|
||||
break;
|
||||
case NetworkMutexEvent::Released: {
|
||||
auto it = lockedNetworks.find(*netMutexMsg->networks.begin());
|
||||
if (it != lockedNetworks.end())
|
||||
lockedNetworks.erase(it);
|
||||
break;
|
||||
}
|
||||
networkMutexCallbackHandle = lockNetworks(nets, std::numeric_limits<uint32_t>::max(), std::numeric_limits<uint32_t>::max(), NetworkMutexType::Shared, [this](std::shared_ptr<Message> message) {
|
||||
auto netMutexMsg = std::static_pointer_cast<NetworkMutexMessage>(message);
|
||||
if(netMutexMsg->networks.size() && netMutexMsg->event.has_value()) {
|
||||
switch(*netMutexMsg->event) {
|
||||
case NetworkMutexEvent::Acquired:
|
||||
lockedNetworks.emplace(*netMutexMsg->networks.begin());
|
||||
break;
|
||||
case NetworkMutexEvent::Released: {
|
||||
auto it = lockedNetworks.find(*netMutexMsg->networks.begin());
|
||||
if (it != lockedNetworks.end())
|
||||
lockedNetworks.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,6 +613,11 @@ bool Device::goOffline() {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(assignedClientId.has_value()) {
|
||||
unlockAllNetworks();
|
||||
assignedClientId.reset();
|
||||
}
|
||||
|
||||
if(!enableNetworkCommunication(false))
|
||||
return false;
|
||||
|
||||
@@ -2246,6 +2254,24 @@ bool Device::setRTC(const std::chrono::time_point<std::chrono::system_clock>& ti
|
||||
return m51msg->data.front();
|
||||
}
|
||||
|
||||
std::optional<std::vector<uint8_t>> Device::getPCBSerial() {
|
||||
auto serialMsg = com->getSerialNumberSync();
|
||||
if(!serialMsg || !serialMsg->hasPCBSerial) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return std::vector<uint8_t>(serialMsg->pcbSerial, serialMsg->pcbSerial + sizeof(serialMsg->pcbSerial));
|
||||
}
|
||||
|
||||
std::optional<std::vector<uint8_t>> Device::getMACAddress() {
|
||||
auto serialMsg = com->getSerialNumberSync();
|
||||
if(!serialMsg || !serialMsg->hasMacAddress) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return std::vector<uint8_t>(serialMsg->macAddress, serialMsg->macAddress + sizeof(serialMsg->macAddress));
|
||||
}
|
||||
|
||||
std::optional<std::set<SupportedFeature>> Device::getSupportedFeatures() {
|
||||
auto timeout = std::chrono::milliseconds(100);
|
||||
std::shared_ptr<Message> msg = com->waitForMessageSync(
|
||||
@@ -3809,7 +3835,7 @@ bool Device::formatDisk(const DiskDetails& config, const DiskFormatProgress& han
|
||||
return com->sendCommand(ExtendedCommand::DiskFormatProgress, {});
|
||||
},
|
||||
std::make_shared<ExtendedResponseFilter>(ExtendedCommand::DiskFormatProgress),
|
||||
std::chrono::milliseconds(200)
|
||||
std::chrono::milliseconds(1000)
|
||||
);
|
||||
|
||||
if(!response) {
|
||||
|
||||
@@ -945,4 +945,18 @@ template<typename T> bool IDeviceSettings::applyStructure(const T& newStructure)
|
||||
|
||||
memcpy(settings.data(), &newStructure, structSize);
|
||||
return apply();
|
||||
}
|
||||
|
||||
bool IDeviceSettings::setMiscIOAnalogOutputEnabled(uint8_t pin, bool enabled) {
|
||||
(void)pin;
|
||||
(void)enabled;
|
||||
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IDeviceSettings::setMiscIOAnalogOutput(uint8_t pin, MiscIOAnalogVoltage voltage) {
|
||||
(void)pin;
|
||||
(void)voltage;
|
||||
report(APIEvent::Type::SettingNotAvaiableDevice, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
+3
-1
@@ -7,12 +7,13 @@ 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/icsneoc2/Doxyfile', shell=True)
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
||||
|
||||
project = 'libicsneo'
|
||||
copyright = '2024-2025, Intrepid Control Systems, Inc.'
|
||||
copyright = '2024-2026, Intrepid Control Systems, Inc.'
|
||||
author = 'Intrepid Control Systems, Inc.'
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
@@ -26,6 +27,7 @@ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
breathe_projects = {
|
||||
'icsneocpp': 'icsneocpp/doxygen/xml',
|
||||
'icsneoc': 'icsneoc/doxygen/xml',
|
||||
'icsneoc2': 'icsneoc2/doxygen/xml',
|
||||
}
|
||||
|
||||
breathe_default_project = 'icsneocpp'
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
doxygen
|
||||
@@ -1,5 +1,5 @@
|
||||
icsneoc
|
||||
=======
|
||||
icsneoc (deprecated, use icsneoc2)
|
||||
============================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
doxygen
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
======
|
||||
C2 API
|
||||
======
|
||||
|
||||
.. doxygenfile:: icsneoc2.h
|
||||
:project: icsneoc2
|
||||
.. doxygenfile:: icsneoc2messages.h
|
||||
:project: icsneoc2
|
||||
.. doxygenfile:: icsneoc2settings.h
|
||||
:project: icsneoc2
|
||||
.. doxygenfile:: icsneoc2types.h
|
||||
:project: icsneoc2
|
||||
@@ -0,0 +1,51 @@
|
||||
=================
|
||||
icsneoc2 Examples
|
||||
=================
|
||||
|
||||
Simple
|
||||
======
|
||||
|
||||
:download:`Download example <../../examples/c2/simple/src/main.c>`
|
||||
|
||||
.. literalinclude:: ../../examples/c2/simple/src/main.c
|
||||
:language: c
|
||||
|
||||
Disk Format
|
||||
===========
|
||||
|
||||
:download:`Download example <../../examples/c2/diskformat/src/main.c>`
|
||||
|
||||
.. literalinclude:: ../../examples/c2/diskformat/src/main.c
|
||||
:language: c
|
||||
|
||||
Read Messages
|
||||
=============
|
||||
|
||||
:download:`Download example <../../examples/c2/read_messages/src/main.c>`
|
||||
|
||||
.. literalinclude:: ../../examples/c2/read_messages/src/main.c
|
||||
:language: c
|
||||
|
||||
Device Info
|
||||
===========
|
||||
|
||||
:download:`Download example <../../examples/c2/device_info/src/main.c>`
|
||||
|
||||
.. literalinclude:: ../../examples/c2/device_info/src/main.c
|
||||
:language: c
|
||||
|
||||
LIN
|
||||
===
|
||||
|
||||
:download:`Download example <../../examples/c2/lin/src/main.c>`
|
||||
|
||||
.. literalinclude:: ../../examples/c2/lin/src/main.c
|
||||
:language: c
|
||||
|
||||
LIN Transmit
|
||||
============
|
||||
|
||||
:download:`Download example <../../examples/c2/lin_transmit/src/main.c>`
|
||||
|
||||
.. literalinclude:: ../../examples/c2/lin_transmit/src/main.c
|
||||
:language: c
|
||||
@@ -0,0 +1,9 @@
|
||||
icsneoc2
|
||||
========
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
installation
|
||||
examples
|
||||
api
|
||||
@@ -0,0 +1,7 @@
|
||||
============
|
||||
Installation
|
||||
============
|
||||
|
||||
The installation steps for the C2 API are the same as the C++ API as the C2 API is
|
||||
a wrapper for the C++ library. The ``LIBICSNEO_BUILD_ICSNEOC2`` CMake option is
|
||||
default ``ON`` but note that the C2 API depends on this flag to build.
|
||||
@@ -0,0 +1 @@
|
||||
doxygen
|
||||
@@ -6,7 +6,7 @@ Prerequisites
|
||||
=============
|
||||
|
||||
- Python 3.8 or higher
|
||||
- icsneopy library installed
|
||||
- icsneopy installed (see :doc:`installation`)
|
||||
- CAN hardware device connected
|
||||
|
||||
:download:`Download complete example <../../examples/python/can/can_complete_example.py>`
|
||||
|
||||
@@ -8,7 +8,7 @@ Prerequisites
|
||||
=============
|
||||
|
||||
- Python 3.8 or higher
|
||||
- icsneopy library installed
|
||||
- icsneopy installed (see :doc:`installation`)
|
||||
- Intrepid Control Systems Device
|
||||
|
||||
:download:`Download complete example <../../examples/python/ethernet/ethernet_complete_example.py>`
|
||||
|
||||
@@ -27,6 +27,15 @@ Complete CAN Example
|
||||
:language: python
|
||||
|
||||
|
||||
LiveData Subscription and Monitoring
|
||||
=====================================
|
||||
|
||||
:download:`Download example <../../examples/python/livedata/livedata_example.py>`
|
||||
|
||||
.. literalinclude:: ../../examples/python/livedata/livedata_example.py
|
||||
:language: python
|
||||
|
||||
|
||||
Transmit Ethernet frames on Ethernet 01
|
||||
========================================
|
||||
|
||||
@@ -74,3 +83,19 @@ Device Firmware/Chip Versions
|
||||
|
||||
.. literalinclude:: ../../examples/python/device/chip_versions.py
|
||||
:language: python
|
||||
|
||||
SPI Example for 10BASE-T1S
|
||||
=============================
|
||||
|
||||
:download:`Download example <../../examples/python/spi/spi_example.py>`
|
||||
|
||||
.. literalinclude:: ../../examples/python/spi/spi_example.py
|
||||
:language: python
|
||||
|
||||
Analog Output Control
|
||||
=====================
|
||||
|
||||
:download:`Download example <../../examples/python/analog_out/analog_out_basic.py>`
|
||||
|
||||
.. literalinclude:: ../../examples/python/analog_out/analog_out_basic.py
|
||||
:language: python
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
=======================
|
||||
FlexRay Getting Started
|
||||
=======================
|
||||
|
||||
Prerequisites
|
||||
=============
|
||||
|
||||
- icsneopy installed (see :doc:`installation`)
|
||||
- FlexRay hardware device connected (e.g., Fire3 Flexray)
|
||||
- Proper FlexRay bus termination (100Ω on each channel end)
|
||||
|
||||
Physical Hardware Setup for Two-Node Testing
|
||||
---------------------------------------------
|
||||
|
||||
For testing the basic transmit and receive examples with a single device:
|
||||
|
||||
- Hardware: Device with dual FlexRay controllers (e.g., neoVI FIRE 3 Flexray)
|
||||
- Connection: FLEXRAY_01 Channel A looped to FLEXRAY_02 Channel A
|
||||
- Termination: 100Ω termination resistors on both ends of the loopback
|
||||
- Cable: Use proper FlexRay twisted pair cable (impedance matched)
|
||||
|
||||
.. note::
|
||||
The basic transmit/receive examples are configured for this loopback setup
|
||||
where both controllers act as coldstart nodes. For use on an existing
|
||||
FlexRay network, see the passive monitoring configuration notes in the
|
||||
receive example.
|
||||
|
||||
FlexRay Coldstart
|
||||
-----------------
|
||||
|
||||
FlexRay networks require at least one "coldstart node" to initialize the network timing.
|
||||
The coldstart node is responsible for starting the FlexRay communication cycle.
|
||||
|
||||
For a complete standalone coldstart example, see the Additional Examples section below.
|
||||
|
||||
Basic Setup
|
||||
===========
|
||||
|
||||
1. Import the library and find FlexRay device:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import icsneopy
|
||||
|
||||
devices = icsneopy.find_all_devices()
|
||||
|
||||
# Find a device with FlexRay support
|
||||
device = None
|
||||
for dev in devices:
|
||||
if dev.get_extension("FlexRay"):
|
||||
device = dev
|
||||
break
|
||||
|
||||
if not device:
|
||||
raise RuntimeError("No FlexRay-capable device found")
|
||||
|
||||
2. Configure FlexRay controller:
|
||||
|
||||
.. literalinclude:: ../../examples/python/flexray/flexray_transmit_basic.py
|
||||
:language: python
|
||||
:lines: 12-111
|
||||
|
||||
3. Open device and go online:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
if not device.open():
|
||||
raise RuntimeError("Failed to open device")
|
||||
|
||||
if not device.go_online():
|
||||
raise RuntimeError("Failed to go online")
|
||||
|
||||
Transmitting FlexRay Frames
|
||||
============================
|
||||
|
||||
This example demonstrates a coldstart node that initiates a FlexRay network
|
||||
and transmits simulated sensor data continuously in slot 1.
|
||||
|
||||
**Hardware Setup**: FLEXRAY_01 looped to FLEXRAY_02
|
||||
|
||||
**Usage**:
|
||||
1. Start the receive example first
|
||||
2. Start this transmit example second
|
||||
3. Network will initialize and frames will be transmitted
|
||||
|
||||
.. literalinclude:: ../../examples/python/flexray/flexray_transmit_basic.py
|
||||
:language: python
|
||||
:lines: 113-170
|
||||
|
||||
Key Configuration Parameters:
|
||||
|
||||
- **slotid**: The FlexRay slot ID for transmission (1-2047 for static segment)
|
||||
- **cycle**: The FlexRay cycle number (0-63)
|
||||
- **cycle_repetition**: How often the frame repeats (1 = every cycle, 2 = every other cycle)
|
||||
- **channel**: Transmission channel (A, B, or AB for both)
|
||||
- **key_slot_id**: Must be unique per node on the network
|
||||
- **key_slot_used_for_startup**: True for coldstart nodes
|
||||
- **key_slot_used_for_sync**: True to provide synchronization frames
|
||||
|
||||
Receiving FlexRay Frames
|
||||
=========================
|
||||
|
||||
This example demonstrates receiving FlexRay frames on FLEXRAY_02 Channel A.
|
||||
|
||||
**Hardware Setup**: FLEXRAY_01 looped to FLEXRAY_02
|
||||
|
||||
**Configuration Note**: This example is configured with coldstart capability
|
||||
for two-node loopback testing. For passive monitoring on an existing FlexRay
|
||||
network:
|
||||
|
||||
1. Set ``key_slot_used_for_startup = False`` in the controller configuration
|
||||
2. Remove the ``controller.set_allow_coldstart(True)`` call
|
||||
3. Ensure all cluster parameters match the existing network
|
||||
4. The node will sync and receive without transmitting
|
||||
|
||||
**Usage**:
|
||||
1. Start this receive example first
|
||||
2. Start the transmit example second
|
||||
3. Frames from slot 1 will be displayed with hex and decimal payload views
|
||||
|
||||
.. literalinclude:: ../../examples/python/flexray/flexray_receive_basic.py
|
||||
:language: python
|
||||
:lines: 103-170
|
||||
|
||||
FlexRay Coldstart Configuration
|
||||
================================
|
||||
|
||||
To use the Coldstart example, ensure the following:
|
||||
|
||||
Set the Flexray network in neoVI Explorer to Coldstart.
|
||||
|
||||
No other nodes should be present on the network during testing.
|
||||
|
||||
Nothing connected to Fire3 FlexRay bus.
|
||||
|
||||
Critical Coldstart Settings
|
||||
----------------------------
|
||||
|
||||
.. literalinclude:: ../../examples/python/flexray/flexray_coldstart.py
|
||||
:language: python
|
||||
:lines: 40-48
|
||||
|
||||
Configuration Example:
|
||||
|
||||
.. literalinclude:: ../../examples/python/flexray/flexray_coldstart.py
|
||||
:language: python
|
||||
:lines: 20-64
|
||||
|
||||
Setting Coldstart on Controller:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
controller.set_allow_coldstart(True)
|
||||
controller.set_start_when_going_online(True)
|
||||
|
||||
Cleanup and Resource Management
|
||||
================================
|
||||
|
||||
Always close the device when finished:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
try:
|
||||
# Your FlexRay operations here
|
||||
pass
|
||||
finally:
|
||||
device.close()
|
||||
|
||||
See the basic transmit and receive examples for complete implementations.
|
||||
|
||||
Additional Examples
|
||||
===================
|
||||
|
||||
Transmit Basic
|
||||
--------------
|
||||
|
||||
Complete working example with coldstart node transmitting simulated sensor data.
|
||||
|
||||
All example files are available for download:
|
||||
|
||||
**Transmit Basic** - Coldstart node transmitting simulated sensor data
|
||||
|
||||
:download:`flexray_transmit_basic.py <../../examples/python/flexray/flexray_transmit_basic.py>`
|
||||
|
||||
**Receive Basic** - Receiving and displaying FlexRay frames with formatted output
|
||||
|
||||
:download:`flexray_receive_basic.py <../../examples/python/flexray/flexray_receive_basic.py>`
|
||||
|
||||
**Coldstart** - Standalone coldstart example demonstrating network initialization
|
||||
|
||||
:download:`flexray_coldstart.py <../../examples/python/flexray/flexray_coldstart.py>`
|
||||
@@ -5,8 +5,10 @@ icsneopy
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
installation
|
||||
can_getting_started
|
||||
ethernet_getting_started
|
||||
flexray_getting_started
|
||||
examples
|
||||
api
|
||||
radepsilon
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
============
|
||||
Installation
|
||||
============
|
||||
|
||||
icsneopy is available on PyPI at https://pypi.org/project/icsneopy/ and can be installed with pip:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install icsneopy
|
||||
|
||||
Pre-release
|
||||
===========
|
||||
|
||||
For the latest features, install with the ``--pre`` flag to include pre-release versions:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install --pre icsneopy
|
||||
|
||||
Upgrading
|
||||
=========
|
||||
|
||||
To upgrade an existing installation:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install --pre --upgrade icsneopy
|
||||
|
||||
Linux udev Rules
|
||||
================
|
||||
|
||||
Linux users may want to install the included udev rules to run icsneopy-based
|
||||
applications without root. The rules file can be found in the libicsneo source
|
||||
repository at https://github.com/intrepidcs/libicsneo/.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
sudo cp 99-intrepidcs.rules /etc/udev/rules.d/
|
||||
@@ -13,3 +13,4 @@ communication library. The source code for libicsneo can be found on GitHub:
|
||||
icsneocpp/index
|
||||
icsneopy/index
|
||||
icsneoc/index
|
||||
icsneoc2/index
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
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_LEGACY_EXAMPLE "Build the command-line simple C example." ON)
|
||||
option(LIBICSNEO_BUILD_C2_SIMPLE_EXAMPLE "Build the simple C2 example." ON)
|
||||
option(LIBICSNEO_BUILD_C2_READ_MESSAGES_EXAMPLE "Build the C2 read messages example." ON)
|
||||
option(LIBICSNEO_BUILD_C2_DISKFORMAT_EXAMPLE "Build the C2 disk format example." ON)
|
||||
option(LIBICSNEO_BUILD_C2_RECONNECT_EXAMPLE "Build the C2 reconnect example." ON)
|
||||
option(LIBICSNEO_BUILD_C2_DEVICE_INFO_EXAMPLE "Build the C2 device info example." ON)
|
||||
option(LIBICSNEO_BUILD_C2_LIN_EXAMPLE "Build the C2 LIN example." ON)
|
||||
option(LIBICSNEO_BUILD_C2_LIN_TRANSMIT_EXAMPLE "Build the C2 LIN transmit 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)
|
||||
option(LIBICSNEO_BUILD_CPP_A2B_EXAMPLE "Build the A2B example." ON)
|
||||
@@ -14,6 +21,9 @@ option(LIBICSNEO_BUILD_CPP_APP_ERROR_EXAMPLE "Build the macsec example" ON)
|
||||
option(LIBICSNEO_BUILD_CPP_FLEXRAY_EXAMPLE "Build the FlexRay example." ON)
|
||||
option(LIBICSNEO_BUILD_CPP_SPI_EXAMPLE "Build the SPI example." ON)
|
||||
option(LIBICSNEO_BUILD_CPP_MUTEX_EXAMPLE "Build the NetworkMutex example." ON)
|
||||
option(LIBICSNEO_BUILD_CPP_ANALOG_OUT_EXAMPLE "Build the analog output example." ON)
|
||||
option(LIBICSNEO_BUILD_CPP_DISKFORMAT_EXAMPLE "Build the disk format example." ON)
|
||||
option(LIBICSNEO_BUILD_CPP_T1S_EXAMPLE "Build the T1S example." ON)
|
||||
|
||||
add_compile_options(${LIBICSNEO_COMPILER_WARNINGS})
|
||||
|
||||
@@ -29,6 +39,34 @@ if(LIBICSNEO_BUILD_C_LEGACY_EXAMPLE)
|
||||
add_subdirectory(c/legacy)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_C2_SIMPLE_EXAMPLE)
|
||||
add_subdirectory(c2/simple)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_C2_READ_MESSAGES_EXAMPLE)
|
||||
add_subdirectory(c2/read_messages)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_C2_DISKFORMAT_EXAMPLE)
|
||||
add_subdirectory(c2/diskformat)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_C2_RECONNECT_EXAMPLE)
|
||||
add_subdirectory(c2/reconnect)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_C2_DEVICE_INFO_EXAMPLE)
|
||||
add_subdirectory(c2/device_info)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_C2_LIN_EXAMPLE)
|
||||
add_subdirectory(c2/lin)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_C2_LIN_TRANSMIT_EXAMPLE)
|
||||
add_subdirectory(c2/lin_transmit)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_CPP_SIMPLE_EXAMPLE)
|
||||
add_subdirectory(cpp/simple)
|
||||
endif()
|
||||
@@ -80,3 +118,15 @@ endif()
|
||||
if(LIBICSNEO_BUILD_CPP_MUTEX_EXAMPLE)
|
||||
add_subdirectory(cpp/mutex)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_CPP_ANALOG_OUT_EXAMPLE)
|
||||
add_subdirectory(cpp/analog_out)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_CPP_DISKFORMAT_EXAMPLE)
|
||||
add_subdirectory(cpp/diskformat)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_CPP_T1S_EXAMPLE)
|
||||
add_subdirectory(cpp/t1s)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
add_executable(libicsneoc2-device-info-example src/main.c)
|
||||
target_link_libraries(libicsneoc2-device-info-example icsneoc2-static)
|
||||
|
||||
if(WIN32)
|
||||
target_compile_definitions(libicsneoc2-device-info-example PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
@@ -0,0 +1,127 @@
|
||||
#include <icsneo/icsneoc2.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
int print_error_code(const char* message, icsneoc2_error_t error) {
|
||||
char error_str[64];
|
||||
size_t error_str_len = sizeof(error_str);
|
||||
icsneoc2_error_t res = icsneoc2_error_code_get(error, error_str, &error_str_len);
|
||||
if(res != icsneoc2_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;
|
||||
}
|
||||
|
||||
int main() {
|
||||
icsneoc2_error_t res;
|
||||
|
||||
/* ===== Device Selection ===== */
|
||||
printf("Searching for devices...\n");
|
||||
icsneoc2_device_info_t* found_devices = NULL;
|
||||
res = icsneoc2_device_enumerate(0, &found_devices);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("Failed to enumerate devices", res);
|
||||
}
|
||||
if(!found_devices) {
|
||||
printf("No devices found.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Count and display devices */
|
||||
int device_count = 0;
|
||||
for(icsneoc2_device_info_t* cur = found_devices; cur; cur = icsneoc2_device_info_next(cur)) {
|
||||
char desc[128] = {0};
|
||||
size_t desc_len = sizeof(desc);
|
||||
icsneoc2_device_info_description_get(cur, desc, &desc_len);
|
||||
|
||||
char serial[32] = {0};
|
||||
size_t serial_len = sizeof(serial);
|
||||
icsneoc2_device_info_serial_get(cur, serial, &serial_len);
|
||||
|
||||
printf(" [%d] %s (Serial: %s)\n", device_count + 1, desc, serial);
|
||||
device_count++;
|
||||
}
|
||||
|
||||
int device_choice;
|
||||
printf("Select device (1-%d): ", device_count);
|
||||
if(scanf("%d", &device_choice) != 1 || device_choice < 1 || device_choice > device_count) {
|
||||
printf("Invalid selection.\n");
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Find the selected device_info node */
|
||||
icsneoc2_device_info_t* selected_info = found_devices;
|
||||
for(int i = 1; i < device_choice; i++) {
|
||||
selected_info = icsneoc2_device_info_next(selected_info);
|
||||
}
|
||||
|
||||
/* Open the selected device */
|
||||
icsneoc2_device_t* device = NULL;
|
||||
res = icsneoc2_device_create(selected_info, &device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("Failed to create device from device info", res);
|
||||
}
|
||||
res = icsneoc2_device_open(device, icsneoc2_open_options_default);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_device_free(device);
|
||||
return print_error_code("Failed to open device", res);
|
||||
}
|
||||
|
||||
char description[128] = {0};
|
||||
size_t description_length = sizeof(description);
|
||||
icsneoc2_device_description_get(device, description, &description_length);
|
||||
printf("\nOpened device: %s\n\n", description);
|
||||
|
||||
/* ===== Serial Number ===== */
|
||||
char serial[32] = {0};
|
||||
size_t serial_len = sizeof(serial);
|
||||
res = icsneoc2_device_serial_get(device, serial, &serial_len);
|
||||
if(res == icsneoc2_error_success) {
|
||||
printf("Serial: %s\n", serial);
|
||||
} else {
|
||||
print_error_code("Failed to get serial", res);
|
||||
}
|
||||
|
||||
/* ===== PCB Serial Number ===== */
|
||||
uint8_t pcbsn[16] = {0};
|
||||
size_t pcbsn_len = sizeof(pcbsn);
|
||||
res = icsneoc2_device_pcb_serial_get(device, pcbsn, &pcbsn_len);
|
||||
if(res == icsneoc2_error_success) {
|
||||
printf("PCB Serial: ");
|
||||
for(size_t i = 0; i < pcbsn_len; i++) {
|
||||
printf("%c", pcbsn[i]);
|
||||
}
|
||||
printf("\n");
|
||||
} else {
|
||||
print_error_code("Failed to get PCB serial (device may not support it)", res);
|
||||
}
|
||||
|
||||
/* ===== MAC Address ===== */
|
||||
uint8_t mac[6] = {0};
|
||||
size_t mac_len = sizeof(mac);
|
||||
res = icsneoc2_device_mac_address_get(device, mac, &mac_len);
|
||||
if(res == icsneoc2_error_success) {
|
||||
printf("MAC: ");
|
||||
for(size_t i = 0; i < mac_len; i++) {
|
||||
if(i > 0) printf(":");
|
||||
printf("%02X", mac[i]);
|
||||
}
|
||||
printf("\n");
|
||||
} else {
|
||||
print_error_code("Failed to get MAC address (device may not support it)", res);
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
printf("\nClosing device... ");
|
||||
res = icsneoc2_device_close(device);
|
||||
printf("%s\n", res == icsneoc2_error_success ? "OK" : "FAIL");
|
||||
|
||||
icsneoc2_device_free(device);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
add_executable(libicsneoc2-diskformat-example src/main.c)
|
||||
target_link_libraries(libicsneoc2-diskformat-example icsneoc2-static)
|
||||
|
||||
if(WIN32)
|
||||
target_compile_definitions(libicsneoc2-diskformat-example PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
@@ -0,0 +1,183 @@
|
||||
#include <icsneo/icsneoc2.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
/**
|
||||
* Prints an error message with the given string and error code.
|
||||
*
|
||||
* @param message The message to print.
|
||||
* @param error The error code to print.
|
||||
* @return error as int
|
||||
*/
|
||||
static int print_error_code(const char* message, icsneoc2_error_t error) {
|
||||
char error_str[64];
|
||||
size_t error_str_len = sizeof(error_str);
|
||||
icsneoc2_error_code_get(error, error_str, &error_str_len);
|
||||
printf("%s: \"%s\" (%u)\n", message, error_str, error);
|
||||
return (int)error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Progress callback invoked periodically during disk formatting.
|
||||
*
|
||||
* @param sectors_formatted Number of sectors formatted so far.
|
||||
* @param total_sectors Total number of sectors to format.
|
||||
* @param user_data Unused opaque pointer.
|
||||
* @return icsneoc2_disk_format_directive_continue to keep formatting.
|
||||
*/
|
||||
static icsneoc2_disk_format_directive_t format_progress(uint64_t sectors_formatted, uint64_t total_sectors, void* user_data) {
|
||||
(void)user_data;
|
||||
double pct = total_sectors > 0 ? (100.0 * (double)sectors_formatted / (double)total_sectors) : 0.0;
|
||||
printf("\r Progress: %" PRIu64 " / %" PRIu64 " sectors (%d%%)", sectors_formatted, total_sectors, (int)pct);
|
||||
fflush(stdout);
|
||||
return icsneoc2_disk_format_directive_continue;
|
||||
}
|
||||
|
||||
int main() {
|
||||
/* Open the first available device (no online needed for formatting) */
|
||||
printf("Opening first available device...\n");
|
||||
icsneoc2_device_t* device = NULL;
|
||||
icsneoc2_error_t res = icsneoc2_device_open_first(0, ICSNEOC2_OPEN_OPTIONS_NONE, &device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to open first device", res);
|
||||
}
|
||||
|
||||
/* Get a description of the opened device */
|
||||
char description[255] = {0};
|
||||
size_t description_length = sizeof(description);
|
||||
res = icsneoc2_device_description_get(device, description, &description_length);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_device_free(device);
|
||||
return print_error_code("\tFailed to get device description", res);
|
||||
}
|
||||
printf("\tOpened device: %s\n", description);
|
||||
|
||||
/* Check disk formatting support */
|
||||
bool supported = false;
|
||||
res = icsneoc2_device_supports_disk_formatting(device, &supported);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_error_code("\tFailed to check disk formatting support", res);
|
||||
icsneoc2_device_close(device);
|
||||
icsneoc2_device_free(device);
|
||||
return -1;
|
||||
}
|
||||
if(!supported) {
|
||||
printf("\terror: %s does not support disk formatting\n", description);
|
||||
icsneoc2_device_close(device);
|
||||
icsneoc2_device_free(device);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t disk_count = 0;
|
||||
icsneoc2_device_disk_count_get(device, &disk_count);
|
||||
printf("\tDisk count: %zu\n", disk_count);
|
||||
|
||||
/* Query disk details */
|
||||
printf("\tQuerying disk details... ");
|
||||
fflush(stdout);
|
||||
icsneoc2_disk_details_t* details = NULL;
|
||||
res = icsneoc2_device_disk_details_get(device, &details);
|
||||
if(res != icsneoc2_error_success) {
|
||||
printf("FAIL\n");
|
||||
print_error_code("\tFailed to get disk details", res);
|
||||
icsneoc2_device_close(device);
|
||||
icsneoc2_device_free(device);
|
||||
return -1;
|
||||
}
|
||||
printf("OK\n");
|
||||
|
||||
/* Display current state */
|
||||
icsneoc2_disk_layout_t layout = 0;
|
||||
icsneoc2_disk_details_layout_get(details, &layout);
|
||||
printf("\t Layout : %s\n", layout == icsneoc2_disk_layout_raid0 ? "RAID0" : "Spanned");
|
||||
|
||||
size_t detail_count = 0;
|
||||
icsneoc2_disk_details_count_get(details, &detail_count);
|
||||
for(size_t i = 0; i < detail_count; i++) {
|
||||
icsneoc2_disk_format_flags_t flags = 0;
|
||||
icsneoc2_disk_details_flags_get(details, i, &flags);
|
||||
printf("\t Disk [%zu]:\n", i);
|
||||
printf("\t Present : %s\n", (flags & ICSNEOC2_DISK_FORMAT_FLAGS_PRESENT) ? "yes" : "no");
|
||||
printf("\t Initialized : %s\n", (flags & ICSNEOC2_DISK_FORMAT_FLAGS_INITIALIZED) ? "yes" : "no");
|
||||
printf("\t Formatted : %s\n", (flags & ICSNEOC2_DISK_FORMAT_FLAGS_FORMATTED) ? "yes" : "no");
|
||||
if(flags & ICSNEOC2_DISK_FORMAT_FLAGS_PRESENT) {
|
||||
uint64_t sectors = 0, bps = 0;
|
||||
icsneoc2_disk_details_size_get(details, i, §ors, &bps);
|
||||
printf("\t Size : %" PRIu64 " MB (%" PRIu64 " sectors x %" PRIu64 " bytes)\n",
|
||||
(sectors * bps) / (1024 * 1024), sectors, bps);
|
||||
}
|
||||
}
|
||||
|
||||
/* Build format config: mark present disks for formatting */
|
||||
bool any_present = false;
|
||||
for(size_t i = 0; i < detail_count; i++) {
|
||||
icsneoc2_disk_format_flags_t flags = 0;
|
||||
icsneoc2_disk_details_flags_get(details, i, &flags);
|
||||
if(flags & ICSNEOC2_DISK_FORMAT_FLAGS_PRESENT) {
|
||||
flags |= ICSNEOC2_DISK_FORMAT_FLAGS_FORMATTED;
|
||||
icsneoc2_disk_details_flags_set(details, i, flags);
|
||||
any_present = true;
|
||||
}
|
||||
}
|
||||
icsneoc2_disk_details_full_format_set(details, false); /* Quick format */
|
||||
|
||||
if(!any_present) {
|
||||
printf("\n\terror: no disks are present in the device\n");
|
||||
icsneoc2_disk_details_free(details);
|
||||
icsneoc2_device_close(device);
|
||||
icsneoc2_device_free(device);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Confirm */
|
||||
printf("\n\tThis will format the disk(s) in %s.\n", description);
|
||||
printf("\tAll existing data will be lost. Continue? [y/N]: ");
|
||||
char confirm[8] = {0};
|
||||
if(scanf("%7s", confirm) != 1 || (confirm[0] != 'y' && confirm[0] != 'Y')) {
|
||||
printf("\tAborted.\n");
|
||||
icsneoc2_disk_details_free(details);
|
||||
icsneoc2_device_close(device);
|
||||
icsneoc2_device_free(device);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Format */
|
||||
printf("\n\tStarting format...\n");
|
||||
res = icsneoc2_device_format_disk(device, details, format_progress, NULL);
|
||||
printf("\n"); /* newline after progress line */
|
||||
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_error_code("\tFormat failed", res);
|
||||
icsneoc2_disk_details_free(details);
|
||||
icsneoc2_device_close(device);
|
||||
icsneoc2_device_free(device);
|
||||
return -1;
|
||||
}
|
||||
printf("\tFormat complete!\n");
|
||||
icsneoc2_disk_details_free(details);
|
||||
|
||||
/* Verify */
|
||||
printf("\n\tVerifying disk state after format... ");
|
||||
fflush(stdout);
|
||||
icsneoc2_disk_details_t* post_details = NULL;
|
||||
res = icsneoc2_device_disk_details_get(device, &post_details);
|
||||
if(res != icsneoc2_error_success) {
|
||||
printf("FAIL (could not re-query disk details)\n");
|
||||
} else {
|
||||
printf("OK\n");
|
||||
size_t post_count = 0;
|
||||
icsneoc2_disk_details_count_get(post_details, &post_count);
|
||||
for(size_t i = 0; i < post_count; i++) {
|
||||
icsneoc2_disk_format_flags_t flags = 0;
|
||||
icsneoc2_disk_details_flags_get(post_details, i, &flags);
|
||||
printf("\t Disk [%zu] formatted: %s\n", i, (flags & ICSNEOC2_DISK_FORMAT_FLAGS_FORMATTED) ? "yes" : "no");
|
||||
}
|
||||
icsneoc2_disk_details_free(post_details);
|
||||
}
|
||||
|
||||
printf("\tClosing device: %s...\n", description);
|
||||
icsneoc2_device_close(device);
|
||||
icsneoc2_device_free(device);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
add_executable(libicsneoc2-lin-example src/main.c)
|
||||
target_link_libraries(libicsneoc2-lin-example icsneoc2-static)
|
||||
|
||||
if(WIN32)
|
||||
target_compile_definitions(libicsneoc2-lin-example PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
@@ -0,0 +1,311 @@
|
||||
/* Note: This example requires LIN 1 and LIN 2 channels to be connected on the device */
|
||||
|
||||
#include <icsneo/icsneoc2.h>
|
||||
#include <icsneo/icsneoc2messages.h>
|
||||
#include <icsneo/icsneoc2settings.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
void sleep_ms(uint32_t ms) {
|
||||
#ifdef _WIN32
|
||||
Sleep(ms);
|
||||
#else
|
||||
sleep(ms / 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
int print_error_code(const char* message, icsneoc2_error_t error) {
|
||||
char error_str[64];
|
||||
size_t error_str_len = sizeof(error_str);
|
||||
icsneoc2_error_t res = icsneoc2_error_code_get(error, error_str, &error_str_len);
|
||||
if(res != icsneoc2_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;
|
||||
}
|
||||
|
||||
void print_events(const char* device_description) {
|
||||
icsneoc2_event_t* events[1024] = {0};
|
||||
size_t events_count = 1024;
|
||||
for(size_t i = 0; i < events_count; ++i) {
|
||||
icsneoc2_error_t res = icsneoc2_event_get(&events[i], NULL);
|
||||
if(res != icsneoc2_error_success) {
|
||||
for(size_t j = 0; j < i; ++j) {
|
||||
icsneoc2_event_free(events[j]);
|
||||
}
|
||||
(void)print_error_code("\tFailed to get device events", res);
|
||||
return;
|
||||
}
|
||||
if(events[i] == NULL) {
|
||||
events_count = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(size_t i = 0; i < events_count; i++) {
|
||||
char event_description[255] = {0};
|
||||
size_t event_description_length = 255;
|
||||
icsneoc2_error_t res = icsneoc2_event_description_get(events[i], event_description, &event_description_length);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_error_code("\tFailed to get event description", res);
|
||||
continue;
|
||||
}
|
||||
printf("\t%s: Event %zu: %s\n", device_description, i, event_description);
|
||||
}
|
||||
for(size_t i = 0; i < events_count; i++) {
|
||||
icsneoc2_event_free(events[i]);
|
||||
}
|
||||
printf("\t%s: Received %zu events\n", device_description, events_count);
|
||||
}
|
||||
|
||||
void process_lin_messages(icsneoc2_message_t** messages, size_t count) {
|
||||
for(size_t i = 0; i < count; i++) {
|
||||
bool is_lin = false;
|
||||
icsneoc2_error_t res = icsneoc2_message_is_lin(messages[i], &is_lin);
|
||||
if(res != icsneoc2_error_success || !is_lin)
|
||||
continue;
|
||||
|
||||
uint8_t id = 0;
|
||||
uint8_t protected_id = 0;
|
||||
uint8_t checksum = 0;
|
||||
icsneoc2_lin_msg_type_t msg_type = 0;
|
||||
bool is_enhanced_checksum = false;
|
||||
res = icsneoc2_message_lin_props_get(messages[i], &id, &protected_id, &checksum, &msg_type, &is_enhanced_checksum);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_error_code("\tFailed to get LIN properties", res);
|
||||
continue;
|
||||
}
|
||||
|
||||
icsneoc2_netid_t netid = 0;
|
||||
icsneoc2_message_netid_get(messages[i], &netid);
|
||||
char netid_name[128] = {0};
|
||||
size_t netid_name_length = 128;
|
||||
icsneoc2_netid_name_get(netid, netid_name, &netid_name_length);
|
||||
|
||||
uint8_t data[64] = {0};
|
||||
size_t data_length = 64;
|
||||
icsneoc2_message_data_get(messages[i], data, &data_length);
|
||||
|
||||
icsneoc2_lin_err_flags_t err_flags = 0;
|
||||
icsneoc2_message_lin_err_flags_get(messages[i], &err_flags);
|
||||
|
||||
printf("\t%s RX | ID: 0x%02x | Protected ID: 0x%02x\n", netid_name, id, protected_id);
|
||||
printf("\tData: [");
|
||||
for(size_t x = 0; x < data_length; x++) {
|
||||
printf(" 0x%02x", data[x]);
|
||||
}
|
||||
printf(" ]\n");
|
||||
printf("\tChecksum type: %s\n", is_enhanced_checksum ? "Enhanced" : "Classic");
|
||||
printf("\tChecksum: 0x%02x\n", checksum);
|
||||
printf("\tChecksum valid: %s\n\n", (!(err_flags & ICSNEOC2_LIN_ERR_CHECKSUM_MATCH)) ? "yes" : "no");
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
/* Open the first available device */
|
||||
printf("Opening first available device...\n");
|
||||
icsneoc2_device_t* device = NULL;
|
||||
icsneoc2_error_t res = icsneoc2_device_open_first(0, icsneoc2_open_options_default, &device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to open first device", res);
|
||||
}
|
||||
|
||||
char description[255] = {0};
|
||||
size_t description_length = 255;
|
||||
res = icsneoc2_device_description_get(device, description, &description_length);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_device_close(device);
|
||||
return print_error_code("\tFailed to get device description", res);
|
||||
}
|
||||
printf("\tOpened device: %s\n\n", description);
|
||||
|
||||
/* Configure LIN settings */
|
||||
int64_t baud = 19200;
|
||||
|
||||
printf("Enable LIN 01 commander resistor... ");
|
||||
res = icsneoc2_settings_commander_resistor_set(device, icsneoc2_netid_lin_01, true);
|
||||
printf("%s\n", res == icsneoc2_error_success ? "OK" : "FAIL");
|
||||
|
||||
printf("Disable LIN 02 commander resistor... ");
|
||||
res = icsneoc2_settings_commander_resistor_set(device, icsneoc2_netid_lin_02, false);
|
||||
printf("%s\n", res == icsneoc2_error_success ? "OK" : "FAIL");
|
||||
|
||||
printf("Setting LIN 01 baudrate to %" PRId64 " bit/s... ", baud);
|
||||
res = icsneoc2_settings_baudrate_set(device, icsneoc2_netid_lin_01, baud);
|
||||
printf("%s\n", res == icsneoc2_error_success ? "OK" : "FAIL");
|
||||
|
||||
printf("Setting LIN 02 baudrate to %" PRId64 " bit/s... ", baud);
|
||||
res = icsneoc2_settings_baudrate_set(device, icsneoc2_netid_lin_02, baud);
|
||||
printf("%s\n", res == icsneoc2_error_success ? "OK" : "FAIL");
|
||||
|
||||
printf("Setting LIN 01 mode to NORMAL... ");
|
||||
res = icsneoc2_settings_lin_mode_set(device, icsneoc2_netid_lin_01, icsneoc2_lin_mode_normal);
|
||||
printf("%s\n", res == icsneoc2_error_success ? "OK" : "FAIL");
|
||||
|
||||
printf("Setting LIN 02 mode to NORMAL... ");
|
||||
res = icsneoc2_settings_lin_mode_set(device, icsneoc2_netid_lin_02, icsneoc2_lin_mode_normal);
|
||||
printf("%s\n", res == icsneoc2_error_success ? "OK" : "FAIL");
|
||||
|
||||
printf("Applying settings... ");
|
||||
res = icsneoc2_settings_apply(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_close(device);
|
||||
return print_error_code("\tFailed to apply settings", res);
|
||||
}
|
||||
printf("OK\n");
|
||||
|
||||
printf("Getting LIN 01 baudrate... ");
|
||||
int64_t read_baud = 0;
|
||||
res = icsneoc2_settings_baudrate_get(device, icsneoc2_netid_lin_01, &read_baud);
|
||||
if(res == icsneoc2_error_success)
|
||||
printf("OK, %" PRId64 " bit/s\n", read_baud);
|
||||
else
|
||||
printf("FAIL\n");
|
||||
|
||||
printf("Getting LIN 02 baudrate... ");
|
||||
res = icsneoc2_settings_baudrate_get(device, icsneoc2_netid_lin_02, &read_baud);
|
||||
if(res == icsneoc2_error_success)
|
||||
printf("OK, %" PRId64 " bit/s\n\n", read_baud);
|
||||
else
|
||||
printf("FAIL\n\n");
|
||||
|
||||
/* Transmit a LIN responder data update on LIN 02 */
|
||||
printf("Transmitting a LIN 02 responder data frame... ");
|
||||
{
|
||||
icsneoc2_message_t* msg = NULL;
|
||||
res = icsneoc2_message_lin_create(&msg, 0x11);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_close(device);
|
||||
return print_error_code("\tFailed to create LIN message", res);
|
||||
}
|
||||
icsneoc2_lin_msg_type_t msg_type = icsneoc2_lin_msg_type_update_responder;
|
||||
res = icsneoc2_message_lin_props_set(msg, NULL, NULL, &msg_type, NULL);
|
||||
uint8_t data[] = {0xaa, 0xbb, 0xcc, 0xdd, 0x11, 0x22, 0x33, 0x44};
|
||||
res += icsneoc2_message_data_set(msg, data, sizeof(data));
|
||||
res += icsneoc2_message_netid_set(msg, icsneoc2_netid_lin_02);
|
||||
res += icsneoc2_message_lin_calc_checksum(msg);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_message_free(msg);
|
||||
print_events(description);
|
||||
icsneoc2_device_close(device);
|
||||
return print_error_code("\tFailed to set LIN message properties", res);
|
||||
}
|
||||
res = icsneoc2_device_message_transmit(device, msg);
|
||||
icsneoc2_message_free(msg);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_close(device);
|
||||
return print_error_code("\tFailed to transmit LIN responder message", res);
|
||||
}
|
||||
printf("OK\n");
|
||||
}
|
||||
|
||||
/* Transmit a LIN commander header on LIN 01 */
|
||||
printf("Transmitting a LIN 01 commander header... ");
|
||||
{
|
||||
icsneoc2_message_t* msg = NULL;
|
||||
res = icsneoc2_message_lin_create(&msg, 0x11);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_close(device);
|
||||
return print_error_code("\tFailed to create LIN message", res);
|
||||
}
|
||||
icsneoc2_lin_msg_type_t msg_type = icsneoc2_lin_msg_type_header_only;
|
||||
res = icsneoc2_message_lin_props_set(msg, NULL, NULL, &msg_type, NULL);
|
||||
res += icsneoc2_message_netid_set(msg, icsneoc2_netid_lin_01);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_message_free(msg);
|
||||
print_events(description);
|
||||
icsneoc2_device_close(device);
|
||||
return print_error_code("\tFailed to set LIN message properties", res);
|
||||
}
|
||||
res = icsneoc2_device_message_transmit(device, msg);
|
||||
icsneoc2_message_free(msg);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_close(device);
|
||||
return print_error_code("\tFailed to transmit LIN header", res);
|
||||
}
|
||||
printf("OK\n\n");
|
||||
}
|
||||
|
||||
sleep_ms(100);
|
||||
|
||||
/* Transmit a LIN commander message with data on LIN 01 */
|
||||
printf("Transmitting a LIN 01 commander frame with data... ");
|
||||
{
|
||||
icsneoc2_message_t* msg = NULL;
|
||||
res = icsneoc2_message_lin_create(&msg, 0x22);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_close(device);
|
||||
return print_error_code("\tFailed to create LIN message", res);
|
||||
}
|
||||
icsneoc2_lin_msg_type_t msg_type = icsneoc2_lin_msg_type_commander_msg;
|
||||
bool enhanced = true;
|
||||
res = icsneoc2_message_lin_props_set(msg, NULL, NULL, &msg_type, &enhanced);
|
||||
uint8_t data[] = {0x11, 0x22, 0x33, 0x44, 0xaa, 0xbb, 0xcc, 0xdd};
|
||||
res += icsneoc2_message_data_set(msg, data, sizeof(data));
|
||||
res += icsneoc2_message_netid_set(msg, icsneoc2_netid_lin_01);
|
||||
res += icsneoc2_message_lin_calc_checksum(msg);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_message_free(msg);
|
||||
print_events(description);
|
||||
icsneoc2_device_close(device);
|
||||
return print_error_code("\tFailed to set LIN message properties", res);
|
||||
}
|
||||
res = icsneoc2_device_message_transmit(device, msg);
|
||||
icsneoc2_message_free(msg);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_close(device);
|
||||
return print_error_code("\tFailed to transmit LIN commander message", res);
|
||||
}
|
||||
printf("OK\n\n");
|
||||
}
|
||||
|
||||
sleep_ms(100);
|
||||
|
||||
/* Read back any received messages and display LIN frames */
|
||||
icsneoc2_message_t* messages[2048] = {0};
|
||||
size_t message_count = 2048;
|
||||
printf("Getting messages...\n");
|
||||
for(size_t i = 0; i < message_count; ++i) {
|
||||
res = icsneoc2_device_message_get(device, &messages[i], 0);
|
||||
if(res != icsneoc2_error_success) {
|
||||
for(size_t j = 0; j < i; ++j) {
|
||||
icsneoc2_message_free(messages[j]);
|
||||
}
|
||||
print_events(description);
|
||||
icsneoc2_device_close(device);
|
||||
return print_error_code("\tFailed to get messages", res);
|
||||
}
|
||||
if(messages[i] == NULL) {
|
||||
message_count = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("\tReceived %zu messages\n", message_count);
|
||||
process_lin_messages(messages, message_count);
|
||||
for(size_t i = 0; i < message_count; ++i) {
|
||||
icsneoc2_message_free(messages[i]);
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
print_events(description);
|
||||
printf("Closing device... ");
|
||||
res = icsneoc2_device_close(device);
|
||||
printf("%s\n", res == icsneoc2_error_success ? "OK" : "FAIL");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
add_executable(libicsneoc2-lin-transmit-example src/main.c)
|
||||
target_link_libraries(libicsneoc2-lin-transmit-example icsneoc2-static)
|
||||
|
||||
if(WIN32)
|
||||
target_compile_definitions(libicsneoc2-lin-transmit-example PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
@@ -0,0 +1,276 @@
|
||||
#include <icsneo/icsneoc2.h>
|
||||
#include <icsneo/icsneoc2messages.h>
|
||||
#include <icsneo/icsneoc2settings.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
void sleep_ms(uint32_t ms) {
|
||||
#ifdef _WIN32
|
||||
Sleep(ms);
|
||||
#else
|
||||
sleep(ms / 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
int print_error_code(const char* message, icsneoc2_error_t error) {
|
||||
char error_str[64];
|
||||
size_t error_str_len = sizeof(error_str);
|
||||
icsneoc2_error_t res = icsneoc2_error_code_get(error, error_str, &error_str_len);
|
||||
if(res != icsneoc2_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;
|
||||
}
|
||||
|
||||
int read_int(const char* prompt, int min_val, int max_val) {
|
||||
int value;
|
||||
while(1) {
|
||||
printf("%s", prompt);
|
||||
if(scanf("%d", &value) != 1) {
|
||||
/* Clear invalid input */
|
||||
int c;
|
||||
while((c = getchar()) != '\n' && c != EOF) {}
|
||||
printf("Invalid input, try again.\n");
|
||||
continue;
|
||||
}
|
||||
if(value < min_val || value > max_val) {
|
||||
printf("Please enter a value between %d and %d.\n", min_val, max_val);
|
||||
continue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
int read_hex(const char* prompt, int min_val, int max_val) {
|
||||
int value;
|
||||
while(1) {
|
||||
printf("%s", prompt);
|
||||
if(scanf("%x", &value) != 1) {
|
||||
/* Clear invalid input */
|
||||
int c;
|
||||
while((c = getchar()) != '\n' && c != EOF) {}
|
||||
printf("Invalid input, try again.\n");
|
||||
continue;
|
||||
}
|
||||
if(value < min_val || value > max_val) {
|
||||
printf("Please enter a value between 0x%X and 0x%X.\n", min_val, max_val);
|
||||
continue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
icsneoc2_error_t res;
|
||||
|
||||
/* ===== Device Selection ===== */
|
||||
printf("Searching for devices...\n");
|
||||
icsneoc2_device_info_t* found_devices = NULL;
|
||||
res = icsneoc2_device_enumerate(0, &found_devices);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("Failed to enumerate devices", res);
|
||||
}
|
||||
if(!found_devices) {
|
||||
printf("No devices found.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Count and display devices */
|
||||
int device_count = 0;
|
||||
for(icsneoc2_device_info_t* cur = found_devices; cur; cur = icsneoc2_device_info_next(cur)) {
|
||||
char desc[128] = {0};
|
||||
size_t desc_len = sizeof(desc);
|
||||
icsneoc2_device_info_description_get(cur, desc, &desc_len);
|
||||
printf(" [%d] %s\n", device_count + 1, desc);
|
||||
device_count++;
|
||||
}
|
||||
|
||||
int device_choice = read_int("Select device: ", 1, device_count);
|
||||
|
||||
/* Find the selected device_info node */
|
||||
icsneoc2_device_info_t* selected_info = found_devices;
|
||||
for(int i = 1; i < device_choice; i++) {
|
||||
selected_info = icsneoc2_device_info_next(selected_info);
|
||||
}
|
||||
|
||||
/* Open the selected device */
|
||||
icsneoc2_device_t* device = NULL;
|
||||
res = icsneoc2_device_create(selected_info, &device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("Failed to create device from device info", res);
|
||||
}
|
||||
res = icsneoc2_device_open(device, icsneoc2_open_options_default);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_device_free(device);
|
||||
return print_error_code("Failed to open device", res);
|
||||
}
|
||||
|
||||
char description[128] = {0};
|
||||
size_t description_length = sizeof(description);
|
||||
icsneoc2_device_description_get(device, description, &description_length);
|
||||
printf("Opened device: %s\n\n", description);
|
||||
|
||||
/* ===== LIN Network Selection ===== */
|
||||
/* Get all supported TX networks */
|
||||
size_t tx_net_count = 0;
|
||||
res = icsneoc2_device_supported_tx_networks_get(device, NULL, &tx_net_count);
|
||||
if(res != icsneoc2_error_success || tx_net_count == 0) {
|
||||
printf("No supported TX networks.\n");
|
||||
icsneoc2_device_close(device);
|
||||
return 1;
|
||||
}
|
||||
|
||||
icsneoc2_netid_t* tx_networks = (icsneoc2_netid_t*)malloc(tx_net_count * sizeof(icsneoc2_netid_t));
|
||||
if(!tx_networks) {
|
||||
printf("Out of memory.\n");
|
||||
icsneoc2_device_close(device);
|
||||
icsneoc2_device_free(device);
|
||||
return 1;
|
||||
}
|
||||
res = icsneoc2_device_supported_tx_networks_get(device, tx_networks, &tx_net_count);
|
||||
if(res != icsneoc2_error_success) {
|
||||
free(tx_networks);
|
||||
icsneoc2_device_close(device);
|
||||
icsneoc2_device_free(device);
|
||||
return print_error_code("Failed to get TX networks", res);
|
||||
}
|
||||
|
||||
/* Filter for LIN networks */
|
||||
icsneoc2_netid_t lin_networks[64] = {0};
|
||||
char lin_names[64][128] = {{0}};
|
||||
size_t lin_count = 0;
|
||||
for(size_t i = 0; i < tx_net_count && lin_count < 64; i++) {
|
||||
icsneoc2_message_t* tmp = NULL;
|
||||
res = icsneoc2_message_lin_create(&tmp, 0);
|
||||
if(res != icsneoc2_error_success) continue;
|
||||
res = icsneoc2_message_netid_set(tmp, tx_networks[i]);
|
||||
if(res != icsneoc2_error_success) { icsneoc2_message_free(tmp); continue; }
|
||||
icsneoc2_network_type_t ntype = 0;
|
||||
res = icsneoc2_message_network_type_get(tmp, &ntype);
|
||||
icsneoc2_message_free(tmp);
|
||||
if(res != icsneoc2_error_success) continue;
|
||||
if(ntype == icsneoc2_network_type_lin) {
|
||||
lin_networks[lin_count] = tx_networks[i];
|
||||
size_t name_len = 128;
|
||||
icsneoc2_netid_name_get(tx_networks[i], lin_names[lin_count], &name_len);
|
||||
lin_count++;
|
||||
}
|
||||
}
|
||||
free(tx_networks);
|
||||
|
||||
if(lin_count == 0) {
|
||||
printf("No LIN networks available on this device.\n");
|
||||
icsneoc2_device_close(device);
|
||||
icsneoc2_device_free(device);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Available LIN networks:\n");
|
||||
for(size_t i = 0; i < lin_count; i++) {
|
||||
printf(" [%zu] %s\n", i + 1, lin_names[i]);
|
||||
}
|
||||
|
||||
int lin_choice = read_int("Select LIN network: ", 1, (int)lin_count);
|
||||
icsneoc2_netid_t selected_netid = lin_networks[lin_choice - 1];
|
||||
printf("Selected: %s\n\n", lin_names[lin_choice - 1]);
|
||||
|
||||
/* ===== Commander / Responder Selection ===== */
|
||||
printf("Message type:\n");
|
||||
printf(" [1] Commander frame\n");
|
||||
printf(" [2] Responder frame (update responder + header only)\n");
|
||||
int type_choice = read_int("Select message type: ", 1, 2);
|
||||
bool is_commander = (type_choice == 1);
|
||||
printf("Selected: %s\n\n", is_commander ? "Commander" : "Responder");
|
||||
|
||||
uint8_t id_choice = (uint8_t)read_hex("Select LIN ID (0x00-0x3F): ", 0, 0x3F);
|
||||
printf("Selected: 0x%02X\n\n", id_choice);
|
||||
|
||||
/* ===== Configure LIN ===== */
|
||||
printf("Configuring %s... ", lin_names[lin_choice - 1]);
|
||||
res = icsneoc2_settings_commander_resistor_set(device, selected_netid, is_commander);
|
||||
res += icsneoc2_settings_baudrate_set(device, selected_netid, 19200);
|
||||
res += icsneoc2_settings_lin_mode_set(device, selected_netid, icsneoc2_lin_mode_normal);
|
||||
res += icsneoc2_settings_apply(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_device_close(device);
|
||||
icsneoc2_device_free(device);
|
||||
return print_error_code("Failed to configure LIN", res);
|
||||
}
|
||||
printf("OK\n\n");
|
||||
|
||||
/* ===== Transmit Loop ===== */
|
||||
printf("Transmitting on %s every second for 10 seconds...\n", lin_names[lin_choice - 1]);
|
||||
uint8_t counter = 0;
|
||||
for(int i = 0; i < 10; i++) {
|
||||
icsneoc2_message_t* msg = NULL;
|
||||
res = icsneoc2_message_lin_create(&msg, id_choice);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_error_code("\tFailed to create LIN message", res);
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t data[] = {counter, counter + 1, counter + 2, counter + 3, 0xAA, 0xBB, 0xCC, 0xDD};
|
||||
bool enhanced = true;
|
||||
|
||||
if(is_commander) {
|
||||
/* Commander: send header-only frame to poll the bus */
|
||||
icsneoc2_lin_msg_type_t msg_type = icsneoc2_lin_msg_type_header_only;
|
||||
res = icsneoc2_message_lin_props_set(msg, NULL, NULL, &msg_type, &enhanced);
|
||||
res += icsneoc2_message_netid_set(msg, selected_netid);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_message_free(msg);
|
||||
print_error_code("\tFailed to set commander properties", res);
|
||||
break;
|
||||
}
|
||||
res = icsneoc2_device_message_transmit(device, msg);
|
||||
icsneoc2_message_free(msg);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_error_code("\tFailed to transmit header", res);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Responder: update the responder table with new data */
|
||||
icsneoc2_lin_msg_type_t msg_type = icsneoc2_lin_msg_type_update_responder;
|
||||
res = icsneoc2_message_lin_props_set(msg, NULL, NULL, &msg_type, &enhanced);
|
||||
res += icsneoc2_message_data_set(msg, data, sizeof(data));
|
||||
res += icsneoc2_message_lin_calc_checksum(msg);
|
||||
res += icsneoc2_message_netid_set(msg, selected_netid);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_message_free(msg);
|
||||
print_error_code("\tFailed to update responder", res);
|
||||
break;
|
||||
}
|
||||
res = icsneoc2_device_message_transmit(device, msg);
|
||||
icsneoc2_message_free(msg);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_error_code("\tFailed to transmit responder update", res);
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("[%2d/10] Transmitted %s msg ID=0x%02X, counter=%u\n",
|
||||
i + 1, is_commander ? "commander" : "responder", id_choice, counter);
|
||||
counter += 4;
|
||||
sleep_ms(1000);
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
printf("\nClosing device... ");
|
||||
res = icsneoc2_device_close(device);
|
||||
printf("%s\n", res == icsneoc2_error_success ? "OK" : "FAIL");
|
||||
icsneoc2_device_free(device);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
add_executable(libicsneoc2-read_messages-example src/main.c)
|
||||
target_link_libraries(libicsneoc2-read_messages-example icsneoc2-static)
|
||||
|
||||
if(WIN32)
|
||||
target_compile_definitions(libicsneoc2-read_messages-example PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
@@ -0,0 +1,331 @@
|
||||
#include <icsneo/icsneoc2.h>
|
||||
#include <icsneo/icsneoc2settings.h>
|
||||
#include <icsneo/icsneoc2messages.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
#ifdef _WIN32
|
||||
Sleep(ms);
|
||||
#else
|
||||
sleep(ms / 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints all events
|
||||
*
|
||||
* @param device_description A description of the device used in the output.
|
||||
*/
|
||||
void print_events(const char* device_description);
|
||||
|
||||
/**
|
||||
* Prints an error message with the given string and error code.
|
||||
*
|
||||
* If the error code is not icsneoc2_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, icsneoc2_error_t error) {
|
||||
char error_str[64];
|
||||
size_t error_str_len = sizeof(error_str);
|
||||
icsneoc2_error_t res = icsneoc2_error_code_get(error, error_str, &error_str_len);
|
||||
if(res != icsneoc2_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 messages An array of pointers to icsneoc2_message_t structures containing the messages to process.
|
||||
* @param messages_count The number of messages in the messages array.
|
||||
*
|
||||
* @return An icsneoc2_error_t value indicating success or failure of the message processing.
|
||||
*/
|
||||
int process_message(icsneoc2_message_t** messages, size_t messages_count);
|
||||
|
||||
int transmit_can_messages(icsneoc2_device_t* device);
|
||||
|
||||
int main() {
|
||||
// Open the first available device with default options
|
||||
printf("Opening first available device...\n");
|
||||
icsneoc2_device_t* open_device = NULL;
|
||||
icsneoc2_error_t res = icsneoc2_device_open_first(0, icsneoc2_open_options_default, &open_device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to open first device", res);
|
||||
};
|
||||
|
||||
// Get a description of the opened device
|
||||
char description[255] = {0};
|
||||
size_t description_length = 255;
|
||||
res = icsneoc2_device_description_get(open_device, description, &description_length);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_device_free(open_device);
|
||||
return print_error_code("\tFailed to get device description", res);
|
||||
};
|
||||
printf("\tOpened device: %s\n", description);
|
||||
|
||||
// Transmit messages for debugging purposes
|
||||
// transmit_can_messages(open_device);
|
||||
// sleep_ms(1000);
|
||||
|
||||
// Get the messages
|
||||
icsneoc2_message_t* messages[20000] = {0};
|
||||
size_t message_count = 20000;
|
||||
time_t start_time = time(NULL);
|
||||
printf("\tGetting messages from device with timeout of 3000ms on %s...\n", description);
|
||||
for(size_t i = 0; i < message_count; ++i) {
|
||||
res = icsneoc2_device_message_get(open_device, &messages[i], 0);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
return print_error_code("\tFailed to get messages from device", res);
|
||||
};
|
||||
if(messages[i] == NULL) {
|
||||
// no more messages
|
||||
message_count = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
return print_error_code("\tFailed to get messages from device", res);
|
||||
}
|
||||
time_t end_time = time(NULL);
|
||||
printf("\tGot %zu messages in %lld seconds\n", message_count, (long long)(end_time - start_time));
|
||||
// Process the messages
|
||||
res = process_message(messages, message_count);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
return print_error_code("\tFailed to process messages", res);
|
||||
}
|
||||
// Finally, close the device.
|
||||
printf("\tClosing device: %s...\n", description);
|
||||
res = icsneoc2_device_close(open_device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
return print_error_code("\tFailed to close device", res);
|
||||
};
|
||||
icsneoc2_device_free(open_device);
|
||||
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_events(const char* device_description) {
|
||||
icsneoc2_event_t* events[1024] = {0};
|
||||
size_t events_count = 1024;
|
||||
for(size_t i = 0; i < events_count; ++i) {
|
||||
// no device filter, get all events
|
||||
icsneoc2_error_t res = icsneoc2_event_get(&events[i], NULL);
|
||||
if(res != icsneoc2_error_success) {
|
||||
(void)print_error_code("\tFailed to get device events", res);
|
||||
return;
|
||||
}
|
||||
if(events[i] == NULL) {
|
||||
events_count = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Loop over each event and describe it.
|
||||
for(size_t i = 0; i < events_count; i++) {
|
||||
char event_description[255] = {0};
|
||||
size_t event_description_length = 255;
|
||||
icsneoc2_error_t res = icsneoc2_event_description_get(events[i], event_description, &event_description_length);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_error_code("\tFailed to get event description", res);
|
||||
continue;
|
||||
}
|
||||
printf("\t%s: Event %zu: %s\n", device_description, i, event_description);
|
||||
}
|
||||
for(size_t i = 0; i < events_count; i++) {
|
||||
icsneoc2_event_free(events[i]);
|
||||
}
|
||||
printf("\t%s: Received %zu events\n", device_description, events_count);
|
||||
}
|
||||
|
||||
int process_message(icsneoc2_message_t** messages, size_t messages_count) {
|
||||
// Print the type and bus type of each message
|
||||
size_t tx_count = 0;
|
||||
size_t can_error_count = 0;
|
||||
icsneoc2_error_t res = icsneoc2_error_success;
|
||||
for(size_t i = 0; i < messages_count; i++) {
|
||||
icsneoc2_message_t* message = messages[i];
|
||||
|
||||
bool is_can_error = false;
|
||||
res = icsneoc2_message_is_can_error(message, &is_can_error);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to check if message is a CAN error", res);
|
||||
}
|
||||
if(is_can_error) {
|
||||
icsneoc2_network_type_t network_type;
|
||||
uint8_t tec = 0;
|
||||
uint8_t rec = 0;
|
||||
icsneoc2_can_error_code_t error_code = 0;
|
||||
icsneoc2_can_error_code_t data_error_code = 0;
|
||||
icsneoc2_message_can_error_flags_t error_flags = 0;
|
||||
icsneoc2_netid_t netid = 0;
|
||||
char network_type_name[128] = {0};
|
||||
size_t network_type_name_length = 128;
|
||||
char netid_name[128] = {0};
|
||||
size_t netid_name_length = 128;
|
||||
|
||||
res = icsneoc2_message_network_type_get(message, &network_type);
|
||||
res += icsneoc2_network_type_name_get(network_type, network_type_name, &network_type_name_length);
|
||||
res += icsneoc2_message_netid_get(message, &netid);
|
||||
res += icsneoc2_netid_name_get(netid, netid_name, &netid_name_length);
|
||||
res += icsneoc2_message_can_error_props_get(message, &tec, &rec, &error_code, &data_error_code, &error_flags);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to get CAN error properties", res);
|
||||
}
|
||||
|
||||
printf("\t%zd) CAN Error on %s [%s] (0x%x): TEC=%u REC=%u ErrorCode=%u DataErrorCode=%u%s%s%s\n",
|
||||
i, netid_name, network_type_name, netid, tec, rec, error_code, data_error_code,
|
||||
(error_flags & ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_BUS_OFF) ? " [BusOff]" : "",
|
||||
(error_flags & ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_ERROR_PASSIVE) ? " [ErrorPassive]" : "",
|
||||
(error_flags & ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_ERROR_WARN) ? " [ErrorWarn]" : "");
|
||||
can_error_count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
bool is_frame = false;
|
||||
res = icsneoc2_message_is_frame(message, &is_frame);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to check if message is a frame", res);
|
||||
}
|
||||
if(!is_frame) {
|
||||
printf("Ignoring non-frame message at index %zu\n", i);
|
||||
continue;
|
||||
}
|
||||
icsneoc2_network_type_t network_type;
|
||||
res = icsneoc2_message_network_type_get(message, &network_type);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to get message network type", res);
|
||||
}
|
||||
|
||||
char network_type_name[128] = {0};
|
||||
size_t network_type_name_length = 128;
|
||||
res = icsneoc2_network_type_name_get(network_type, network_type_name, &network_type_name_length);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to get message bus type name", res);
|
||||
}
|
||||
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to get message is transmit", res);
|
||||
}
|
||||
|
||||
printf("\t%zd) network type: %s (%u)\n", i, network_type_name, network_type);
|
||||
if(network_type == icsneoc2_network_type_can) {
|
||||
uint64_t arbid = 0;
|
||||
int32_t dlc = 0;
|
||||
icsneoc2_netid_t netid = 0;
|
||||
icsneoc2_message_can_flags_t can_flags = 0;
|
||||
uint8_t data[64] = {0};
|
||||
size_t data_length = 64;
|
||||
char netid_name[128] = {0};
|
||||
size_t netid_name_length = 128;
|
||||
bool is_error = false;
|
||||
bool is_tx = false;
|
||||
icsneoc2_error_t result = icsneoc2_message_netid_get(message, &netid);
|
||||
result += icsneoc2_netid_name_get(netid, netid_name, &netid_name_length);
|
||||
result += icsneoc2_message_can_props_get(message, &arbid, &can_flags);
|
||||
result += icsneoc2_message_data_get(message, data, &data_length);
|
||||
result += icsneoc2_message_is_transmit(message, &is_tx);
|
||||
result += icsneoc2_message_is_error(message, &is_error);
|
||||
if(result != icsneoc2_error_success) {
|
||||
printf("\tFailed get get CAN parameters (error: %u) for index %zu\n", result, i);
|
||||
continue;
|
||||
}
|
||||
tx_count += is_tx ? 1 : 0;
|
||||
bool is_remote = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_RTR) != 0;
|
||||
bool is_extended = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_IDE) != 0;
|
||||
bool is_canfd = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_FDF) != 0;
|
||||
bool is_brs = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_BRS) != 0;
|
||||
bool is_esi = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_ESI) != 0;
|
||||
bool tx_aborted = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_TX_ABORTED) != 0;
|
||||
bool tx_lost_arb = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_TX_LOST_ARB) != 0;
|
||||
bool tx_error = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_TX_ERROR) != 0;
|
||||
dlc = (int32_t)data_length;
|
||||
|
||||
printf("\t %s%s\n", is_tx ? "TX" : "RX", is_error ? " [Error]" : "");
|
||||
printf("\t NetID: %s (0x%x)\tArbID: 0x%llx\tDLC: %u\tLen: %zu\n", netid_name, netid, (unsigned long long)arbid, dlc, data_length);
|
||||
printf("\t Flags:%s%s%s%s%s%s%s%s\n",
|
||||
is_remote ? " RTR" : "",
|
||||
is_extended ? " IDE" : "",
|
||||
is_canfd ? " FDF" : "",
|
||||
is_brs ? " BRS" : "",
|
||||
is_esi ? " ESI" : "",
|
||||
tx_aborted ? " TX_ABORTED" : "",
|
||||
tx_lost_arb ? " TX_LOST_ARB" : "",
|
||||
tx_error ? " TX_ERROR" : "");
|
||||
printf("\t Data: [");
|
||||
for(size_t x = 0; x < data_length; x++) {
|
||||
printf(" 0x%x", data[x]);
|
||||
}
|
||||
printf(" ]\n");
|
||||
}
|
||||
}
|
||||
printf("\tReceived %zu messages total, %zu were TX messages, %zu were CAN errors\n", messages_count, tx_count, can_error_count);
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
int transmit_can_messages(icsneoc2_device_t* device) {
|
||||
uint64_t counter = 0;
|
||||
const size_t msg_count = 10;
|
||||
printf("\tTransmitting %zd messages...\n", msg_count);
|
||||
for(size_t i = 0; i < msg_count; i++) {
|
||||
// Create the message
|
||||
icsneoc2_message_t* message = NULL;
|
||||
icsneoc2_error_t res = icsneoc2_message_can_create(&message);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to create messages", res);
|
||||
}
|
||||
// Set the message attributes
|
||||
res = icsneoc2_message_netid_set(message, icsneoc2_netid_dwcan_01);
|
||||
uint64_t arb_id = 0x10;
|
||||
uint64_t flags = 0;
|
||||
res += icsneoc2_message_can_props_set(message, &arb_id, &flags);
|
||||
res += icsneoc2_message_data_set(message, (uint8_t*)&counter, sizeof(counter));
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_message_free(message);
|
||||
return print_error_code("\tFailed to modify message", res);
|
||||
}
|
||||
res = icsneoc2_device_message_transmit(device, message);
|
||||
res += icsneoc2_message_free(message);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to transmit message", res);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
add_executable(libicsneoc2-reconnect-example src/main.c)
|
||||
target_link_libraries(libicsneoc2-reconnect-example icsneoc2-static)
|
||||
|
||||
if(WIN32)
|
||||
target_compile_definitions(libicsneoc2-reconnect-example PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
@@ -0,0 +1,132 @@
|
||||
#include <icsneo/icsneoc2.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
void sleep_ms(uint32_t ms) {
|
||||
#ifdef _WIN32
|
||||
Sleep(ms);
|
||||
#else
|
||||
usleep(ms * 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
int print_error_code(const char* message, icsneoc2_error_t error) {
|
||||
char error_str[64];
|
||||
size_t error_str_len = sizeof(error_str);
|
||||
icsneoc2_error_t res = icsneoc2_error_code_get(error, error_str, &error_str_len);
|
||||
if(res != icsneoc2_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;
|
||||
}
|
||||
|
||||
void print_events(void) {
|
||||
icsneoc2_event_t* events[256] = {0};
|
||||
size_t events_count = 256;
|
||||
for(size_t i = 0; i < events_count; ++i) {
|
||||
icsneoc2_error_t res = icsneoc2_event_get(&events[i], NULL);
|
||||
if(res != icsneoc2_error_success) {
|
||||
(void)print_error_code("\tFailed to get events", res);
|
||||
return;
|
||||
}
|
||||
if(events[i] == NULL) {
|
||||
events_count = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(size_t i = 0; i < events_count; i++) {
|
||||
char description[255] = {0};
|
||||
size_t description_length = 255;
|
||||
icsneoc2_error_t res = icsneoc2_event_description_get(events[i], description, &description_length);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_error_code("\tFailed to get event description", res);
|
||||
continue;
|
||||
}
|
||||
printf("\tEvent %zu: %s\n", i, description);
|
||||
}
|
||||
for(size_t i = 0; i < events_count; i++) {
|
||||
icsneoc2_event_free(events[i]);
|
||||
}
|
||||
if(events_count > 0) {
|
||||
printf("\tReceived %zu events\n", events_count);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
/* Open the first available device */
|
||||
printf("Opening first available device...\n");
|
||||
icsneoc2_device_t* device = NULL;
|
||||
icsneoc2_error_t res = icsneoc2_device_open_first(0, icsneoc2_open_options_default, &device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("Failed to open first device", res);
|
||||
}
|
||||
|
||||
/* Get a description of the opened device */
|
||||
char description[255] = {0};
|
||||
size_t description_length = 255;
|
||||
res = icsneoc2_device_description_get(device, description, &description_length);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_device_free(device);
|
||||
return print_error_code("Failed to get device description", res);
|
||||
}
|
||||
printf("Opened device: %s\n", description);
|
||||
|
||||
/* Wait for the device to disconnect */
|
||||
printf("Waiting for device to disconnect (unplug device from PC)...\n");
|
||||
for(;;) {
|
||||
bool is_open = true;
|
||||
res = icsneoc2_device_is_open(device, &is_open);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events();
|
||||
icsneoc2_device_free(device);
|
||||
return print_error_code("Failed to check open status", res);
|
||||
}
|
||||
if(!is_open) {
|
||||
printf("Device disconnected!\n");
|
||||
break;
|
||||
}
|
||||
sleep_ms(500);
|
||||
}
|
||||
|
||||
/* Attempt to reconnect */
|
||||
uint32_t timeout_ms = 20000; // 20 second timeout
|
||||
printf("Attempting to reconnect (%u second timeout)...\n", timeout_ms / 1000);
|
||||
res = icsneoc2_device_reconnect(device, icsneoc2_open_options_default, timeout_ms);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events();
|
||||
icsneoc2_device_free(device);
|
||||
return print_error_code("Failed to reconnect", res);
|
||||
}
|
||||
|
||||
printf("Reconnected successfully!\n");
|
||||
|
||||
/* Verify by getting the description again */
|
||||
description_length = 255;
|
||||
res = icsneoc2_device_description_get(device, description, &description_length);
|
||||
if(res == icsneoc2_error_success) {
|
||||
printf("Device: %s\n", description);
|
||||
}
|
||||
|
||||
/* Print any events */
|
||||
print_events();
|
||||
|
||||
/* Close the device */
|
||||
printf("Closing device...\n");
|
||||
res = icsneoc2_device_close(device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_device_free(device);
|
||||
return print_error_code("Failed to close device", res);
|
||||
}
|
||||
icsneoc2_device_free(device);
|
||||
|
||||
printf("Done.\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
add_executable(libicsneoc2-simple-example src/main.c)
|
||||
target_link_libraries(libicsneoc2-simple-example icsneoc2-static)
|
||||
|
||||
if(WIN32)
|
||||
target_compile_definitions(libicsneoc2-simple-example PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
@@ -0,0 +1,507 @@
|
||||
#include <icsneo/icsneoc2.h>
|
||||
#include <icsneo/icsneoc2messages.h>
|
||||
#include <icsneo/icsneoc2settings.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <time.h>
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
#ifdef _WIN32
|
||||
Sleep(ms);
|
||||
#else
|
||||
sleep(ms / 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints an error message with the given string and error code.
|
||||
*
|
||||
* If the error code is not icsneoc2_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, icsneoc2_error_t error) {
|
||||
char error_str[64];
|
||||
size_t error_str_len = sizeof(error_str);
|
||||
icsneoc2_error_t res = icsneoc2_error_code_get(error, error_str, &error_str_len);
|
||||
if(res != icsneoc2_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 messages An array of pointers to icsneoc2_message_t structures containing the messages to process.
|
||||
* @param messages_count The number of messages in the messages array.
|
||||
*
|
||||
* @return An icsneoc2_error_t value indicating success or failure of the message processing.
|
||||
*/
|
||||
int process_messages(icsneoc2_message_t** messages, size_t messages_count);
|
||||
|
||||
/**
|
||||
* Prints all events
|
||||
*
|
||||
* @param device_description A description of the device used in the output.
|
||||
*/
|
||||
void print_events(const char* device_description);
|
||||
|
||||
/**
|
||||
* 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 icsneoc2_device_t structure representing the device to transmit messages from.
|
||||
*
|
||||
* @return An icsneoc2_error_t value indicating success or failure of the message transmission process.
|
||||
*/
|
||||
int transmit_can_messages(icsneoc2_device_t* device);
|
||||
|
||||
/**
|
||||
* 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 icsneoc2_error_t icsneoc2_error_success if successful, icsneoc2_error_invalid_parameters otherwise.
|
||||
*/
|
||||
icsneoc2_error_t get_and_print_rtc(icsneoc2_device_t* device);
|
||||
|
||||
int main() {
|
||||
icsneoc2_device_info_t* found_devices = NULL;
|
||||
|
||||
printf("Finding devices...\n");
|
||||
icsneoc2_error_t res = icsneoc2_device_enumerate(0, &found_devices);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to find devices", res);
|
||||
}
|
||||
if(found_devices == NULL) {
|
||||
printf("No devices found, exiting\n");
|
||||
return 0;
|
||||
}
|
||||
// Count and list off the devices
|
||||
size_t devices_count = 0;
|
||||
for(icsneoc2_device_info_t* cur = found_devices; cur != NULL; cur = icsneoc2_device_info_next(cur)) {
|
||||
devices_count++;
|
||||
}
|
||||
printf("OK, %zu device%s found\n", devices_count, devices_count == 1 ? "" : "s");
|
||||
for(icsneoc2_device_info_t* cur = found_devices; cur != NULL; cur = icsneoc2_device_info_next(cur)) {
|
||||
// Get description of the device
|
||||
char description[255] = {0};
|
||||
size_t description_length = 255;
|
||||
res = icsneoc2_device_info_description_get(cur, description, &description_length);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to get device description", res);
|
||||
};
|
||||
printf("%.*s\n", (int)description_length, description);
|
||||
// Open the device without RTC sync and going online
|
||||
icsneoc2_open_options_t options = icsneoc2_open_options_default;
|
||||
options &= ~ICSNEOC2_OPEN_OPTIONS_SYNC_RTC;
|
||||
options &= ~ICSNEOC2_OPEN_OPTIONS_GO_ONLINE;
|
||||
printf("\tDevice open options: 0x%x\n", options);
|
||||
printf("\tOpening device: %s...\n", description);
|
||||
icsneoc2_device_t* open_device = NULL;
|
||||
res = icsneoc2_device_create(cur, &open_device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to create device", res);
|
||||
}
|
||||
res = icsneoc2_device_open(open_device, options);
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to open device", res);
|
||||
};
|
||||
|
||||
// Get timestamp resolution of the device
|
||||
printf("\tGetting timestamp resolution... ");
|
||||
uint32_t timestamp_resolution = 0;
|
||||
res = icsneoc2_device_timestamp_resolution_get(open_device, ×tamp_resolution);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to get timestamp resolution", res);
|
||||
}
|
||||
printf("%uns\n", timestamp_resolution);
|
||||
// Get baudrates for HSCAN
|
||||
printf("\tGetting DW CAN 01 Baudrate... ");
|
||||
int64_t baudrate = 0;
|
||||
res = icsneoc2_settings_baudrate_get(open_device, icsneoc2_netid_dwcan_01, &baudrate);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to get baudrate", res);
|
||||
};
|
||||
printf("%" PRIu64 "mbit/s\n", baudrate);
|
||||
// Get FDbaudrates for HSCAN
|
||||
printf("\tGetting FD DW CAN 01 Baudrate... ");
|
||||
int64_t fd_baudrate = 0;
|
||||
res = icsneoc2_settings_canfd_baudrate_get(open_device, icsneoc2_netid_dwcan_01, &fd_baudrate);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to get FD baudrate", res);
|
||||
};
|
||||
printf("%" PRIu64 "mbit/s\n", fd_baudrate);
|
||||
// Set baudrates for HSCAN
|
||||
// save_to_device: If this is set to true, the baudrate will be saved on the device
|
||||
// and will persist through a power cycle
|
||||
printf("\tSetting DW CAN 01 Baudrate... ");
|
||||
res = icsneoc2_settings_baudrate_set(open_device, icsneoc2_netid_dwcan_01, baudrate);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to set baudrate", res);
|
||||
};
|
||||
printf("Ok\n");
|
||||
// Set FDbaudrates for HSCAN
|
||||
printf("\tSetting FD DW CAN 01 Baudrate... ");
|
||||
res = icsneoc2_settings_canfd_baudrate_set(open_device, icsneoc2_netid_dwcan_01, fd_baudrate);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to set FD baudrate", res);
|
||||
};
|
||||
printf("Ok\n");
|
||||
// Get RTC
|
||||
printf("\tGetting RTC... ");
|
||||
res = get_and_print_rtc(open_device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to get RTC", res);
|
||||
}
|
||||
// Set RTC
|
||||
printf("\tSetting RTC to current time... ");
|
||||
time_t current_time = time(NULL);
|
||||
res = icsneoc2_device_rtc_set(open_device, current_time);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to set RTC", res);
|
||||
}
|
||||
printf("Ok\n");
|
||||
// Get RTC
|
||||
printf("\tGetting RTC... ");
|
||||
res = get_and_print_rtc(open_device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to get RTC", res);
|
||||
}
|
||||
// Go online, start acking traffic
|
||||
printf("\tGoing online... ");
|
||||
res = icsneoc2_device_go_online(open_device, true);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to go online", res);
|
||||
}
|
||||
// Redundant check to show how to check if the device is online, if the previous
|
||||
// icsneoc2_device_go_online call was successful we can assume we are online already
|
||||
bool is_online = false;
|
||||
res = icsneoc2_device_is_online(open_device, &is_online);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to check if online", res);
|
||||
}
|
||||
printf("%s\n", is_online ? "Online" : "Offline");
|
||||
// Transmit CAN messages
|
||||
res = transmit_can_messages(open_device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to transmit CAN messages", res);
|
||||
}
|
||||
// Wait for the bus to collect some messages, requires an active bus to get messages
|
||||
printf("\tWaiting 1 second for messages...\n");
|
||||
sleep_ms(1000);
|
||||
// Get the messages
|
||||
icsneoc2_message_t* messages[20000] = {0};
|
||||
size_t message_count = 20000;
|
||||
printf("\tGetting messages from device with timeout of 3000ms on %s...\n", description);
|
||||
for(size_t i = 0; i < message_count; ++i) {
|
||||
res = icsneoc2_device_message_get(open_device, &messages[i], 0);
|
||||
if(res != icsneoc2_error_success) {
|
||||
for(size_t j = 0; j < i; ++j) {
|
||||
icsneoc2_message_free(messages[j]);
|
||||
}
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to get messages from device", res);
|
||||
};
|
||||
if(messages[i] == NULL) {
|
||||
// no more messages
|
||||
message_count = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Process the messages
|
||||
res = process_messages(messages, message_count);
|
||||
if(res != icsneoc2_error_success) {
|
||||
for(size_t i = 0; i < message_count; ++i) {
|
||||
icsneoc2_message_free(messages[i]);
|
||||
}
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to process messages", res);
|
||||
}
|
||||
for(size_t i = 0; i < message_count; ++i) {
|
||||
icsneoc2_message_free(messages[i]);
|
||||
}
|
||||
// Finally, close the device.
|
||||
printf("\tClosing device: %s...\n", description);
|
||||
res = icsneoc2_device_close(open_device);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
return print_error_code("\tFailed to close device", res);
|
||||
};
|
||||
// Print device events
|
||||
print_events(description);
|
||||
icsneoc2_device_free(open_device);
|
||||
}
|
||||
icsneoc2_enumeration_free(found_devices);
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
icsneoc2_error_t get_and_print_rtc(icsneoc2_device_t* device) {
|
||||
time_t unix_epoch = 0;
|
||||
icsneoc2_error_t res = icsneoc2_device_rtc_get(device, &unix_epoch);
|
||||
if(res != icsneoc2_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", (long long)unix_epoch, rtc_time);
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
void print_events(const char* device_description) {
|
||||
icsneoc2_event_t* events[1024] = {0};
|
||||
size_t events_count = 1024;
|
||||
for(size_t i = 0; i < events_count; ++i) {
|
||||
// no device filter, get all events
|
||||
icsneoc2_error_t res = icsneoc2_event_get(&events[i], NULL);
|
||||
if(res != icsneoc2_error_success) {
|
||||
for(size_t j = 0; j < i; ++j) {
|
||||
icsneoc2_event_free(events[j]);
|
||||
}
|
||||
(void)print_error_code("\tFailed to get device events", res);
|
||||
return;
|
||||
}
|
||||
if(events[i] == NULL) {
|
||||
events_count = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Loop over each event and describe it.
|
||||
for(size_t i = 0; i < events_count; i++) {
|
||||
char event_description[255] = {0};
|
||||
size_t event_description_length = 255;
|
||||
icsneoc2_error_t res = icsneoc2_event_description_get(events[i], event_description, &event_description_length);
|
||||
if(res != icsneoc2_error_success) {
|
||||
print_error_code("\tFailed to get event description", res);
|
||||
continue;
|
||||
}
|
||||
printf("\t%s: Event %zu: %s\n", device_description, i, event_description);
|
||||
}
|
||||
for(size_t i = 0; i < events_count; i++) {
|
||||
icsneoc2_event_free(events[i]);
|
||||
}
|
||||
printf("\t%s: Received %zu events\n", device_description, events_count);
|
||||
}
|
||||
|
||||
int process_messages(icsneoc2_message_t** messages, size_t messages_count) {
|
||||
// Print the type and bus type of each message
|
||||
size_t tx_count = 0;
|
||||
size_t can_error_count = 0;
|
||||
for(size_t i = 0; i < messages_count; i++) {
|
||||
icsneoc2_message_t* message = messages[i];
|
||||
|
||||
// Check for CAN error messages
|
||||
bool is_can_error = false;
|
||||
icsneoc2_error_t res = icsneoc2_message_is_can_error(message, &is_can_error);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to check if message is a CAN error", res);
|
||||
}
|
||||
if(is_can_error) {
|
||||
uint8_t tec = 0;
|
||||
uint8_t rec = 0;
|
||||
icsneoc2_can_error_code_t error_code = 0;
|
||||
icsneoc2_can_error_code_t data_error_code = 0;
|
||||
icsneoc2_message_can_error_flags_t error_flags = 0;
|
||||
icsneoc2_netid_t netid = 0;
|
||||
res = icsneoc2_message_netid_get(message, &netid);
|
||||
res += icsneoc2_message_can_error_props_get(message, &tec, &rec, &error_code, &data_error_code, &error_flags);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to get CAN error properties", res);
|
||||
}
|
||||
char netid_name[128] = {0};
|
||||
size_t netid_name_length = 128;
|
||||
icsneoc2_netid_name_get(netid, netid_name, &netid_name_length);
|
||||
printf("\t%zd) CAN Error on %s (0x%x): TEC=%u REC=%u ErrorCode=%u DataErrorCode=%u%s%s%s\n",
|
||||
i, netid_name, netid, tec, rec, error_code, data_error_code,
|
||||
(error_flags & ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_BUS_OFF) ? " [BusOff]" : "",
|
||||
(error_flags & ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_ERROR_PASSIVE) ? " [ErrorPassive]" : "",
|
||||
(error_flags & ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_ERROR_WARN) ? " [ErrorWarn]" : "");
|
||||
can_error_count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
bool is_frame = false;
|
||||
res = icsneoc2_message_is_frame(message, &is_frame);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to check if message is a frame", res);
|
||||
}
|
||||
if(!is_frame) {
|
||||
printf("Ignoring non-frame message at index %zu\n", i);
|
||||
continue;
|
||||
}
|
||||
icsneoc2_network_type_t network_type;
|
||||
res = icsneoc2_message_network_type_get(message, &network_type);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to get message network type", res);
|
||||
}
|
||||
|
||||
char network_type_name[128] = {0};
|
||||
size_t network_type_name_length = 128;
|
||||
res = icsneoc2_network_type_name_get(network_type, network_type_name, &network_type_name_length);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to get network type name", res);
|
||||
}
|
||||
bool is_tx = false;
|
||||
res = icsneoc2_message_is_transmit(message, &is_tx);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to get message is transmit", res);
|
||||
}
|
||||
if(is_tx) {
|
||||
tx_count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("\t%zd) network type: %s (%u)\n", i, network_type_name, network_type);
|
||||
|
||||
if(network_type == icsneoc2_network_type_can) {
|
||||
uint64_t arbid = 0;
|
||||
int32_t dlc = 0;
|
||||
icsneoc2_netid_t netid = 0;
|
||||
icsneoc2_message_can_flags_t can_flags = 0;
|
||||
uint8_t data[64] = {0};
|
||||
size_t data_length = 64;
|
||||
char netid_name[128] = {0};
|
||||
size_t netid_name_length = 128;
|
||||
icsneoc2_error_t result = icsneoc2_message_netid_get(message, &netid);
|
||||
result += icsneoc2_netid_name_get(netid, netid_name, &netid_name_length);
|
||||
result += icsneoc2_message_can_props_get(message, &arbid, &can_flags);
|
||||
result += icsneoc2_message_data_get(message, data, &data_length);
|
||||
if(result != icsneoc2_error_success) {
|
||||
printf("\tFailed get get CAN parameters (error: %u) for index %zu\n", result, i);
|
||||
continue;
|
||||
}
|
||||
bool is_remote = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_RTR) != 0;
|
||||
bool is_extended = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_IDE) != 0;
|
||||
bool is_canfd = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_FDF) != 0;
|
||||
bool is_brs = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_BRS) != 0;
|
||||
bool is_esi = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_ESI) != 0;
|
||||
bool tx_aborted = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_TX_ABORTED) != 0;
|
||||
bool tx_lost_arb = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_TX_LOST_ARB) != 0;
|
||||
bool tx_error = (can_flags & ICSNEOC2_MESSAGE_CAN_FLAGS_TX_ERROR) != 0;
|
||||
dlc = (int32_t)data_length;
|
||||
|
||||
printf("\t NetID: %s (0x%x)\tArbID: 0x%llx\tDLC: %u\tLen: %zu\n", netid_name, netid, (unsigned long long)arbid, dlc, data_length);
|
||||
printf("\t Flags:%s%s%s%s%s%s%s%s\n",
|
||||
is_remote ? " RTR" : "",
|
||||
is_extended ? " IDE" : "",
|
||||
is_canfd ? " FDF" : "",
|
||||
is_brs ? " BRS" : "",
|
||||
is_esi ? " ESI" : "",
|
||||
tx_aborted ? " TX_ABORTED" : "",
|
||||
tx_lost_arb ? " TX_LOST_ARB" : "",
|
||||
tx_error ? " TX_ERROR" : "");
|
||||
printf("\t Data: [");
|
||||
for(size_t x = 0; x < data_length; x++) {
|
||||
printf(" 0x%x", data[x]);
|
||||
}
|
||||
printf(" ]\n");
|
||||
}
|
||||
}
|
||||
printf("\tReceived %zu messages total, %zu were TX messages, %zu were CAN errors\n", messages_count, tx_count, can_error_count);
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
int transmit_can_messages(icsneoc2_device_t* device) {
|
||||
uint64_t counter = 0;
|
||||
const size_t msg_count = 100;
|
||||
printf("\tTransmitting %zd messages...\n", msg_count);
|
||||
for(size_t i = 0; i < msg_count; i++) {
|
||||
// Create the message
|
||||
icsneoc2_message_t* message = NULL;
|
||||
icsneoc2_error_t res = icsneoc2_message_can_create(&message);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to create messages", res);
|
||||
}
|
||||
// Set the message attributes
|
||||
res = icsneoc2_message_netid_set(message, icsneoc2_netid_dwcan_01);
|
||||
uint64_t arb_id = 0x10;
|
||||
uint64_t flags = ICSNEOC2_MESSAGE_CAN_FLAGS_BRS | ICSNEOC2_MESSAGE_CAN_FLAGS_IDE | ICSNEOC2_MESSAGE_CAN_FLAGS_FDF;
|
||||
res += icsneoc2_message_can_props_set(message, &arb_id, &flags);
|
||||
res += icsneoc2_message_data_set(message, (uint8_t*)&counter, sizeof(counter));
|
||||
if(res != icsneoc2_error_success) {
|
||||
icsneoc2_message_free(message);
|
||||
return print_error_code("\tFailed to modify message", res);
|
||||
}
|
||||
res = icsneoc2_device_message_transmit(device, message);
|
||||
res += icsneoc2_message_free(message);
|
||||
if(res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to transmit message", res);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
add_executable(libicsneocpp-analog-out src/analog_out.cpp)
|
||||
target_link_libraries(libicsneocpp-analog-out icsneocpp)
|
||||
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* libicsneo Analog Output example
|
||||
*
|
||||
* Demonstrates how to configure and control analog outputs on supported devices
|
||||
*
|
||||
* Usage: libicsneo-analog-out <pin> <voltage> [deviceSerial] [--yes]
|
||||
*
|
||||
* Arguments:
|
||||
* pin: Pin number (1-3 for RAD Galaxy)
|
||||
* voltage: Voltage level (0-5)
|
||||
* deviceSerial: 6 character string for device serial (optional)
|
||||
* --yes: Skip confirmation prompt
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <string_view>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "icsneo/icsneocpp.h"
|
||||
|
||||
static const std::string usage = "Usage: libicsneo-analog-out <pin> <voltage> [deviceSerial] [--yes]\n\n"
|
||||
"Arguments:\n"
|
||||
"pin: Pin number (1-3 for RAD Galaxy)\n"
|
||||
"voltage: Voltage level (0-5)\n"
|
||||
"deviceSerial: 6 character string for device serial (optional)\n"
|
||||
"--yes: Skip confirmation prompt\n";
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
std::vector<std::string_view> args(argv, argv + argc);
|
||||
|
||||
// Parse arguments
|
||||
if(args.size() < 3) {
|
||||
std::cerr << "Error: Missing required arguments\n" << std::endl;
|
||||
std::cerr << usage;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char* endPtr;
|
||||
long pinNum = std::strtol(args[1].data(), &endPtr, 10);
|
||||
if(endPtr != args[1].data() + args[1].size() || pinNum < 1 || pinNum > 3) {
|
||||
std::cerr << "Error: Invalid pin number (must be 1-3)" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
long voltageLevel = std::strtol(args[2].data(), &endPtr, 10);
|
||||
if(endPtr != args[2].data() + args[2].size() || voltageLevel < 0 || voltageLevel > 5) {
|
||||
std::cerr << "Error: Invalid voltage level (must be 0-5)" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
icsneo::MiscIOAnalogVoltage voltage = static_cast<icsneo::MiscIOAnalogVoltage>(voltageLevel);
|
||||
uint8_t pin = static_cast<uint8_t>(pinNum);
|
||||
|
||||
// Check for optional arguments
|
||||
bool skipConfirm = false;
|
||||
std::string_view serial;
|
||||
for(size_t i = 3; i < args.size(); i++) {
|
||||
if(args[i] == "--yes") {
|
||||
skipConfirm = true;
|
||||
} else if(serial.empty() && args[i].size() == 6) {
|
||||
serial = args[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Confirmation prompt
|
||||
if(!skipConfirm) {
|
||||
std::cout << "WARNING: This will set analog output pin " << static_cast<int>(pin)
|
||||
<< " to " << voltageLevel << "V" << std::endl;
|
||||
std::cout << "Make sure nothing sensitive is connected to this pin." << std::endl;
|
||||
std::cout << "Continue? (yes/no): ";
|
||||
std::string response;
|
||||
std::getline(std::cin, response);
|
||||
if(response != "yes") {
|
||||
std::cout << "Aborted." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<icsneo::Device> device = nullptr;
|
||||
|
||||
if(!serial.empty()) {
|
||||
// Find device by serial
|
||||
auto devices = icsneo::FindAllDevices();
|
||||
for(auto& dev : devices) {
|
||||
if(dev->getSerial() == serial) {
|
||||
device = dev;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!device) {
|
||||
std::cerr << "Device with serial " << serial << " not found" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
// Use first available device
|
||||
auto devices = icsneo::FindAllDevices();
|
||||
if(devices.empty()) {
|
||||
std::cerr << "No devices found" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
device = devices[0];
|
||||
}
|
||||
|
||||
std::cout << "Using device: " << device->describe() << std::endl;
|
||||
|
||||
if(!device->open()) {
|
||||
std::cerr << "Failed to open device" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto settings = device->settings;
|
||||
if(!settings) {
|
||||
std::cerr << "Device settings not available" << std::endl;
|
||||
device->close();
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << "Refreshing device settings..." << std::endl;
|
||||
if(!settings->refresh()) {
|
||||
std::cerr << "Failed to refresh settings" << std::endl;
|
||||
device->close();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Enable analog output on specified pin
|
||||
std::cout << "Enabling analog output on pin " << static_cast<int>(pin) << "..." << std::endl;
|
||||
if(!settings->setMiscIOAnalogOutputEnabled(pin, true)) {
|
||||
std::cerr << "Failed to enable analog output on pin " << static_cast<int>(pin) << std::endl;
|
||||
device->close();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set pin to specified voltage
|
||||
std::cout << "Setting pin " << static_cast<int>(pin) << " to " << voltageLevel << "V..." << std::endl;
|
||||
if(!settings->setMiscIOAnalogOutput(pin, voltage)) {
|
||||
std::cerr << "Failed to set voltage on pin " << static_cast<int>(pin) << std::endl;
|
||||
device->close();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Apply settings
|
||||
std::cout << "Applying settings..." << std::endl;
|
||||
if(!settings->apply()) {
|
||||
std::cerr << "Failed to apply settings" << std::endl;
|
||||
device->close();
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << "Analog output configured successfully!" << std::endl;
|
||||
std::cout << "Pin " << static_cast<int>(pin) << ": Enabled at " << voltageLevel << "V" << std::endl;
|
||||
|
||||
device->close();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
add_executable(libicsneocpp-diskformat-example src/DiskFormatExample.cpp)
|
||||
target_link_libraries(libicsneocpp-diskformat-example icsneocpp)
|
||||
@@ -0,0 +1,145 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "icsneo/icsneocpp.h"
|
||||
#include "icsneo/disk/diskdetails.h"
|
||||
|
||||
int main() {
|
||||
std::cout << "Running libicsneo " << icsneo::GetVersion() << std::endl;
|
||||
|
||||
std::cout << "\nFinding devices... " << std::flush;
|
||||
auto devices = icsneo::FindAllDevices();
|
||||
std::cout << "OK, " << devices.size() << " device" << (devices.size() == 1 ? "" : "s") << " found" << std::endl;
|
||||
|
||||
if(devices.empty()) {
|
||||
std::cout << "error: no devices found" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// List devices and let the user pick one
|
||||
for(size_t i = 0; i < devices.size(); i++) {
|
||||
std::cout << " [" << i << "] " << devices[i]->describe() << std::endl;
|
||||
}
|
||||
|
||||
size_t choice = 0;
|
||||
if(devices.size() > 1) {
|
||||
std::cout << "Select a device [0-" << (devices.size() - 1) << "]: ";
|
||||
std::cin >> choice;
|
||||
if(choice >= devices.size()) {
|
||||
std::cout << "error: invalid selection" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
auto& device = devices[choice];
|
||||
std::cout << "\nOpening " << device->describe() << "... " << std::flush;
|
||||
if(!device->open()) {
|
||||
std::cout << "FAIL" << std::endl;
|
||||
std::cout << "error: " << icsneo::GetLastError() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
// Check that this device supports disk formatting
|
||||
if(!device->supportsDiskFormatting()) {
|
||||
std::cout << "error: " << device->describe() << " does not support disk formatting" << std::endl;
|
||||
device->close();
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << "Disk count: " << device->getDiskCount() << std::endl;
|
||||
|
||||
// Query the current disk state from the device
|
||||
std::cout << "\nQuerying disk details... " << std::flush;
|
||||
auto details = device->getDiskDetails();
|
||||
if(!details) {
|
||||
std::cout << "FAIL" << std::endl;
|
||||
std::cout << "error: " << icsneo::GetLastError() << std::endl;
|
||||
device->close();
|
||||
return -1;
|
||||
}
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
std::cout << " Layout : " << (details->layout == icsneo::DiskLayout::RAID0 ? "RAID0" : "Spanned") << std::endl;
|
||||
for(size_t i = 0; i < details->disks.size(); i++) {
|
||||
const auto& disk = details->disks[i];
|
||||
std::cout << " Disk [" << i << "]:" << std::endl;
|
||||
std::cout << " Present : " << (disk.present ? "yes" : "no") << std::endl;
|
||||
std::cout << " Initialized : " << (disk.initialized ? "yes" : "no") << std::endl;
|
||||
std::cout << " Formatted : " << (disk.formatted ? "yes" : "no") << std::endl;
|
||||
if(disk.present) {
|
||||
uint64_t bytes = disk.size();
|
||||
std::cout << " Size : " << (bytes / (1024 * 1024)) << " MB"
|
||||
<< " (" << disk.sectors << " sectors x " << disk.bytesPerSector << " bytes)" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Build a format configuration.
|
||||
// We keep the existing layout and re-use the disk geometry reported by the device.
|
||||
// The 'formatted' flag must be true for each disk you want the device to format.
|
||||
icsneo::DiskDetails formatConfig;
|
||||
formatConfig.layout = details->layout;
|
||||
formatConfig.fullFormat = false; // Quick format; set to true for a full (slow) format
|
||||
formatConfig.disks = details->disks;
|
||||
|
||||
// Mark all present disks for formatting
|
||||
bool anyPresent = false;
|
||||
for(auto& disk : formatConfig.disks) {
|
||||
if(disk.present) {
|
||||
disk.formatted = true;
|
||||
anyPresent = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!anyPresent) {
|
||||
std::cout << "\nerror: no disks are present in the device" << std::endl;
|
||||
device->close();
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << "\nThis will format the disk(s) in " << device->describe() << "." << std::endl;
|
||||
std::cout << "All existing data will be lost. Continue? [y/N]: ";
|
||||
std::string confirm;
|
||||
std::cin >> confirm;
|
||||
if(confirm != "y" && confirm != "Y") {
|
||||
std::cout << "Aborted." << std::endl;
|
||||
device->close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::cout << "\nStarting format..." << std::endl;
|
||||
|
||||
// Progress callback — called every 500 ms while formatting
|
||||
auto progressHandler = [](uint64_t sectorsFormatted, uint64_t sectorsTotal) -> icsneo::Device::DiskFormatDirective {
|
||||
double pct = sectorsTotal > 0 ? (100.0 * sectorsFormatted / sectorsTotal) : 0.0;
|
||||
std::cout << "\r Progress: " << sectorsFormatted << " / " << sectorsTotal
|
||||
<< " sectors (" << static_cast<int>(pct) << "%)" << std::flush;
|
||||
return icsneo::Device::DiskFormatDirective::Continue;
|
||||
};
|
||||
|
||||
bool success = device->formatDisk(formatConfig, progressHandler);
|
||||
std::cout << std::endl; // newline after progress line
|
||||
|
||||
if(!success) {
|
||||
std::cout << "error: format failed: " << icsneo::GetLastError() << std::endl;
|
||||
device->close();
|
||||
return -1;
|
||||
}
|
||||
std::cout << "Format complete!" << std::endl;
|
||||
|
||||
// Verify by re-querying disk details
|
||||
std::cout << "\nVerifying disk state after format... " << std::flush;
|
||||
auto postDetails = device->getDiskDetails();
|
||||
if(!postDetails) {
|
||||
std::cout << "FAIL (could not re-query disk details)" << std::endl;
|
||||
} else {
|
||||
std::cout << "OK" << std::endl;
|
||||
for(size_t i = 0; i < postDetails->disks.size(); i++) {
|
||||
const auto& disk = postDetails->disks[i];
|
||||
std::cout << " Disk [" << i << "] formatted: " << (disk.formatted ? "yes" : "no") << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
device->close();
|
||||
return 0;
|
||||
}
|
||||
@@ -29,7 +29,7 @@ int main() {
|
||||
}
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
// Create a subscription message for the GPS signals
|
||||
// Create a subscription message for the GPS signals and TIME_SINCE_MSG
|
||||
std::cout << "\tSending a live data subscribe command... ";
|
||||
auto msg = std::make_shared<icsneo::LiveDataCommandMessage>();
|
||||
msg->appendSignalArg(icsneo::LiveDataValueType::GPS_LATITUDE);
|
||||
@@ -37,6 +37,7 @@ int main() {
|
||||
msg->appendSignalArg(icsneo::LiveDataValueType::GPS_ACCURACY);
|
||||
msg->appendSignalArg(icsneo::LiveDataValueType::DAQ_ENABLE);
|
||||
msg->appendSignalArg(icsneo::LiveDataValueType::MANUAL_TRIGGER);
|
||||
msg->appendSignalArg(icsneo::LiveDataValueType::TIME_SINCE_MSG);
|
||||
msg->cmd = icsneo::LiveDataCommand::SUBSCRIBE;
|
||||
msg->handle = icsneo::LiveDataUtil::getNewHandle();
|
||||
msg->updatePeriod = std::chrono::milliseconds(100);
|
||||
@@ -44,6 +45,9 @@ int main() {
|
||||
// Transmit the subscription message
|
||||
ret = device->subscribeLiveData(msg);
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
if (!ret) {
|
||||
std::cout << "\t\tError: " << icsneo::GetLastError() << std::endl;
|
||||
}
|
||||
|
||||
// Register a handler that uses the data after it arrives every ~100ms
|
||||
std::cout << "\tStreaming messages for 3 seconds... " << std::endl << std::endl;
|
||||
@@ -53,19 +57,21 @@ int main() {
|
||||
switch(ldMsg->cmd) {
|
||||
case icsneo::LiveDataCommand::STATUS: {
|
||||
auto msg2 = std::dynamic_pointer_cast<icsneo::LiveDataStatusMessage>(message);
|
||||
std::cout << "[Handle] " << ldMsg->handle << std::endl;
|
||||
std::cout << "[Requested Command] " << msg2->requestedCommand << std::endl;
|
||||
std::cout << "[Status] " << msg2->status << std::endl << std::endl;
|
||||
std::cout << "[STATUS Message]" << std::endl;
|
||||
std::cout << " Handle: " << ldMsg->handle << std::endl;
|
||||
std::cout << " Requested Command: " << msg2->requestedCommand << std::endl;
|
||||
std::cout << " Status: " << msg2->status << std::endl << std::endl;
|
||||
break;
|
||||
}
|
||||
case icsneo::LiveDataCommand::RESPONSE: {
|
||||
auto valueMsg = std::dynamic_pointer_cast<icsneo::LiveDataValueMessage>(message);
|
||||
if((valueMsg->handle == msg->handle) && (valueMsg->values.size() == msg->args.size()))
|
||||
{
|
||||
std::cout << "[Handle] " << msg->handle << std::endl;
|
||||
std::cout << "[Values] " << valueMsg->numArgs << std::endl;
|
||||
std::cout << "[Response Message]" << std::endl;
|
||||
std::cout << " Handle: " << msg->handle << std::endl;
|
||||
std::cout << " Number of Values: " << valueMsg->numArgs << std::endl;
|
||||
for(uint32_t i = 0; i < valueMsg->numArgs; ++i) {
|
||||
std::cout << "[" << msg->args[i]->valueType << "] ";
|
||||
std::cout << " [" << msg->args[i]->valueType << "] ";
|
||||
auto scaledValue = icsneo::LiveDataUtil::liveDataValueToDouble(*valueMsg->values[i]);
|
||||
std::cout << scaledValue << std::endl;
|
||||
}
|
||||
@@ -86,22 +92,33 @@ int main() {
|
||||
setValMsg->cmd = icsneo::LiveDataCommand::SET_VALUE;
|
||||
setValMsg->handle = msg->handle;
|
||||
// Convert the value format
|
||||
icsneo::LiveDataValue ldValueDAQEnable;
|
||||
icsneo::LiveDataValue ldValueManTrig;
|
||||
if (!icsneo::LiveDataUtil::liveDataDoubleToValue(val / 3, ldValueDAQEnable) ||
|
||||
!icsneo::LiveDataUtil::liveDataDoubleToValue(val, ldValueManTrig)) {
|
||||
auto ldValueDAQEnable = icsneo::LiveDataUtil::liveDataDoubleToValue(val / 3);
|
||||
auto ldValueManTrig = icsneo::LiveDataUtil::liveDataDoubleToValue(val);
|
||||
auto ldValueTimeSinceMsg = icsneo::LiveDataUtil::liveDataDoubleToValue(val);
|
||||
if (!ldValueDAQEnable || !ldValueManTrig || !ldValueTimeSinceMsg) {
|
||||
std::cout << "\tError: Failed to convert values" << std::endl;
|
||||
break;
|
||||
}
|
||||
setValMsg->appendSetValue(icsneo::LiveDataValueType::DAQ_ENABLE, ldValueDAQEnable);
|
||||
setValMsg->appendSetValue(icsneo::LiveDataValueType::MANUAL_TRIGGER, ldValueManTrig);
|
||||
device->setValueLiveData(setValMsg);
|
||||
setValMsg->appendSetValue(icsneo::LiveDataValueType::DAQ_ENABLE, *ldValueDAQEnable);
|
||||
setValMsg->appendSetValue(icsneo::LiveDataValueType::MANUAL_TRIGGER, *ldValueManTrig);
|
||||
setValMsg->appendSetValue(icsneo::LiveDataValueType::TIME_SINCE_MSG, *ldValueTimeSinceMsg);
|
||||
|
||||
std::cout << "\tSetting values: DAQ_ENABLE=" << (val / 3)
|
||||
<< ", MANUAL_TRIGGER=" << val
|
||||
<< ", TIME_SINCE_MSG=" << val << std::endl;
|
||||
|
||||
if (!device->setValueLiveData(setValMsg)) {
|
||||
std::cout << "\tError setting values: " << icsneo::GetLastError() << std::endl;
|
||||
}
|
||||
++val;
|
||||
// Run handler for three seconds to observe the signal data
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
}
|
||||
// Unsubscribe from the GPS signals and run handler for one more second
|
||||
// Unsubscription only requires a valid in-use handle, in this case from our previous subscription
|
||||
std::cout << "\tUnsubscribing... ";
|
||||
ret = device->unsubscribeLiveData(msg->handle);
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
// The handler should no longer print values
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
device->removeMessageCallback(handler);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
add_executable(libicsneocpp-t1s-settings src/T1SSettingsExample.cpp)
|
||||
target_link_libraries(libicsneocpp-t1s-settings icsneocpp)
|
||||
|
||||
add_executable(libicsneocpp-t1s-symbol-decoding src/T1SSymbolDecodingExample.cpp)
|
||||
target_link_libraries(libicsneocpp-t1s-symbol-decoding icsneocpp)
|
||||
@@ -0,0 +1,327 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "icsneo/icsneocpp.h"
|
||||
|
||||
template<typename T>
|
||||
std::string optToString(const std::optional<T>& opt) {
|
||||
if (!opt.has_value())
|
||||
return "N/A";
|
||||
if constexpr (std::is_same_v<T, bool>)
|
||||
return opt.value() ? "true" : "false";
|
||||
else
|
||||
return std::to_string(opt.value());
|
||||
}
|
||||
|
||||
bool getUserConfirmation(const std::string& prompt) {
|
||||
std::string input;
|
||||
std::cout << prompt << " (y/n): " << std::flush;
|
||||
std::getline(std::cin, input);
|
||||
if (!input.empty()) {
|
||||
char c = static_cast<char>(std::tolower(input[0]));
|
||||
return (c == 'y');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<icsneo::Network::NetID> selectNetworks(const std::vector<icsneo::Network::NetID>& availableNetworks) {
|
||||
std::vector<icsneo::Network::NetID> selectedNetworks;
|
||||
|
||||
std::cout << "\n" << std::string(70, '=') << std::endl;
|
||||
std::cout << "Select T1S Networks to Configure" << std::endl;
|
||||
std::cout << std::string(70, '=') << std::endl;
|
||||
|
||||
for (size_t i = 0; i < availableNetworks.size(); i++) {
|
||||
std::cout << " [" << (i + 1) << "] " << icsneo::Network(availableNetworks[i]) << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "\nEnter network numbers to configure (e.g., '1,3' or '1-3' or 'all'): " << std::flush;
|
||||
std::string input;
|
||||
std::getline(std::cin, input);
|
||||
|
||||
if (input.empty())
|
||||
return selectedNetworks;
|
||||
|
||||
std::transform(input.begin(), input.end(), input.begin(),
|
||||
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
|
||||
|
||||
if (input == "all") {
|
||||
return availableNetworks;
|
||||
}
|
||||
|
||||
std::stringstream ss(input);
|
||||
std::string token;
|
||||
while (std::getline(ss, token, ',')) {
|
||||
token.erase(0, token.find_first_not_of(" \t"));
|
||||
token.erase(token.find_last_not_of(" \t") + 1);
|
||||
|
||||
size_t dashPos = token.find('-');
|
||||
if (dashPos != std::string::npos) {
|
||||
try {
|
||||
int start = std::stoi(token.substr(0, dashPos));
|
||||
int end = std::stoi(token.substr(dashPos + 1));
|
||||
for (int i = start; i <= end; i++) {
|
||||
if (i >= 1 && i <= (int)availableNetworks.size()) {
|
||||
selectedNetworks.push_back(availableNetworks[i - 1]);
|
||||
}
|
||||
}
|
||||
} catch (...) {}
|
||||
} else {
|
||||
try {
|
||||
int num = std::stoi(token);
|
||||
if (num >= 1 && num <= (int)availableNetworks.size()) {
|
||||
selectedNetworks.push_back(availableNetworks[num - 1]);
|
||||
}
|
||||
} catch (...) {}
|
||||
}
|
||||
}
|
||||
|
||||
return selectedNetworks;
|
||||
}
|
||||
|
||||
uint8_t getUint8Input(const std::string& prompt, uint8_t defaultValue) {
|
||||
std::string input;
|
||||
std::cout << prompt << " [" << (int)defaultValue << "]: " << std::flush;
|
||||
std::getline(std::cin, input);
|
||||
if (input.empty())
|
||||
return defaultValue;
|
||||
try {
|
||||
int val = std::stoi(input);
|
||||
if (val >= 0 && val <= 255)
|
||||
return static_cast<uint8_t>(val);
|
||||
} catch (...) {}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
uint16_t getUint16Input(const std::string& prompt, uint16_t defaultValue) {
|
||||
std::string input;
|
||||
std::cout << prompt << " [" << (int)defaultValue << "]: " << std::flush;
|
||||
std::getline(std::cin, input);
|
||||
if (input.empty())
|
||||
return defaultValue;
|
||||
try {
|
||||
int val = std::stoi(input);
|
||||
if (val >= 0 && val <= 65535)
|
||||
return static_cast<uint16_t>(val);
|
||||
} catch (...) {}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
void displayT1SSettings(const std::shared_ptr<icsneo::Device>& device, icsneo::Network::NetID netId) {
|
||||
std::cout << "\t" << icsneo::Network(netId) << " T1S Settings:" << std::endl;
|
||||
|
||||
std::cout << "\t PLCA Enabled: " << optToString(device->settings->isT1SPLCAEnabledFor(netId)) << std::endl;
|
||||
std::cout << "\t Local ID: " << optToString(device->settings->getT1SLocalIDFor(netId)) << std::endl;
|
||||
std::cout << "\t Max Nodes: " << optToString(device->settings->getT1SMaxNodesFor(netId)) << std::endl;
|
||||
std::cout << "\t TX Opp Timer: " << optToString(device->settings->getT1STxOppTimerFor(netId)) << std::endl;
|
||||
std::cout << "\t Max Burst: " << optToString(device->settings->getT1SMaxBurstFor(netId)) << std::endl;
|
||||
std::cout << "\t Burst Timer: " << optToString(device->settings->getT1SBurstTimerFor(netId)) << std::endl;
|
||||
|
||||
auto termEnabled = device->settings->isT1STerminationEnabledFor(netId);
|
||||
if (termEnabled.has_value())
|
||||
std::cout << "\t Termination: " << optToString(termEnabled) << std::endl;
|
||||
|
||||
auto localIdAlt = device->settings->getT1SLocalIDAlternateFor(netId);
|
||||
if (localIdAlt.has_value()) {
|
||||
std::cout << "\t Local ID Alternate: " << optToString(localIdAlt) << std::endl;
|
||||
std::cout << "\t Bus Dec Beacons: " << optToString(device->settings->isT1SBusDecodingBeaconsEnabledFor(netId)) << std::endl;
|
||||
std::cout << "\t Bus Dec All: " << optToString(device->settings->isT1SBusDecodingAllEnabledFor(netId)) << std::endl;
|
||||
|
||||
auto multiIdMask = device->settings->getT1SMultiIDEnableMaskFor(netId);
|
||||
if (multiIdMask.has_value()) {
|
||||
std::cout << "\t Multi-ID Mask: 0x" << std::hex << std::setw(2) << std::setfill('0')
|
||||
<< (int)multiIdMask.value() << std::dec << std::endl;
|
||||
std::cout << "\t Multi-IDs: ";
|
||||
for (uint8_t i = 0; i < 7; i++) {
|
||||
if (i > 0) std::cout << ", ";
|
||||
auto multiId = device->settings->getT1SMultiIDFor(netId, i);
|
||||
std::cout << "[" << (int)i << "]=" << optToString(multiId);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void configureT1SNetwork(std::shared_ptr<icsneo::Device>& device, icsneo::Network::NetID netId) {
|
||||
std::cout << "\n" << std::string(70, '=') << std::endl;
|
||||
std::cout << "Configuring T1S Network: " << icsneo::Network(netId) << std::endl;
|
||||
std::cout << std::string(70, '=') << std::endl;
|
||||
|
||||
std::cout << "\n--- Basic PLCA Settings ---" << std::endl;
|
||||
bool plcaEnabled = getUserConfirmation("Enable PLCA");
|
||||
device->settings->setT1SPLCAFor(netId, plcaEnabled);
|
||||
|
||||
uint8_t localId = getUint8Input("Local ID (0-255)", 1);
|
||||
device->settings->setT1SLocalIDFor(netId, localId);
|
||||
|
||||
uint8_t maxNodes = getUint8Input("Max Nodes (0-255)", 8);
|
||||
device->settings->setT1SMaxNodesFor(netId, maxNodes);
|
||||
|
||||
uint8_t txOppTimer = getUint8Input("TX Opportunity Timer (0-255)", 20);
|
||||
device->settings->setT1STxOppTimerFor(netId, txOppTimer);
|
||||
|
||||
uint8_t maxBurst = getUint8Input("Max Burst (0-255)", 128);
|
||||
device->settings->setT1SMaxBurstFor(netId, maxBurst);
|
||||
|
||||
uint8_t burstTimer = getUint8Input("Burst Timer (0-255)", 64);
|
||||
device->settings->setT1SBurstTimerFor(netId, burstTimer);
|
||||
|
||||
if (device->settings->isT1STerminationEnabledFor(netId).has_value()) {
|
||||
std::cout << "\n--- Termination Settings ---" << std::endl;
|
||||
bool termEnabled = getUserConfirmation("Enable Termination");
|
||||
device->settings->setT1STerminationFor(netId, termEnabled);
|
||||
}
|
||||
|
||||
if (device->settings->getT1SLocalIDAlternateFor(netId).has_value()) {
|
||||
std::cout << "\n--- Extended Settings ---" << std::endl;
|
||||
uint8_t localIdAlt = getUint8Input("Local ID Alternate (0-255)", 0);
|
||||
device->settings->setT1SLocalIDAlternateFor(netId, localIdAlt);
|
||||
|
||||
bool busDecBeacons = getUserConfirmation("Enable Bus Decoding (Beacons)");
|
||||
device->settings->setT1SBusDecodingBeaconsFor(netId, busDecBeacons);
|
||||
|
||||
bool busDecAll = getUserConfirmation("Enable Bus Decoding (All Symbols)");
|
||||
device->settings->setT1SBusDecodingAllFor(netId, busDecAll);
|
||||
|
||||
if (getUserConfirmation("Configure Multi-ID settings?")) {
|
||||
uint8_t multiIdMask = getUint8Input("Multi-ID Enable Mask (0x00-0xFF, hex)", 0x00);
|
||||
device->settings->setT1SMultiIDEnableMaskFor(netId, multiIdMask);
|
||||
|
||||
std::cout << "Configure Multi-IDs (7 slots):" << std::endl;
|
||||
for (uint8_t i = 0; i < 7; i++) {
|
||||
uint8_t multiId = getUint8Input(" Multi-ID [" + std::to_string(i) + "]", 0);
|
||||
device->settings->setT1SMultiIDFor(netId, i, multiId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "\n✓ Configuration complete for " << icsneo::Network(netId) << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "\n" << std::string(70, '=') << std::endl;
|
||||
std::cout << "10BASE-T1S SETTINGS CONFIGURATION EXAMPLE" << std::endl;
|
||||
std::cout << std::string(70, '=') << std::endl;
|
||||
std::cout << "libicsneo " << icsneo::GetVersion() << std::endl;
|
||||
std::cout << std::string(70, '=') << std::endl;
|
||||
|
||||
std::cout << "\nFinding devices... " << std::flush;
|
||||
auto devices = icsneo::FindAllDevices();
|
||||
std::cout << "OK, " << devices.size() << " device" << (devices.size() == 1 ? "" : "s") << " found" << std::endl;
|
||||
|
||||
if (devices.empty()) {
|
||||
std::cout << "No devices found!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
for(auto& device : devices)
|
||||
std::cout << " " << device->describe() << std::endl;
|
||||
|
||||
std::shared_ptr<icsneo::Device> selectedDevice;
|
||||
for(auto& device : devices) {
|
||||
if (device->getType() == icsneo::DeviceType::RADComet3) {
|
||||
selectedDevice = device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!selectedDevice && !devices.empty())
|
||||
selectedDevice = devices[0];
|
||||
|
||||
if (!selectedDevice) {
|
||||
std::cout << "No suitable device found!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "\nSelected device: " << selectedDevice->describe() << std::endl;
|
||||
std::cout << "Serial: " << selectedDevice->getSerial() << std::endl;
|
||||
|
||||
std::cout << "\nOpening device... " << std::flush;
|
||||
if (!selectedDevice->open()) {
|
||||
std::cout << "✗ Failed" << std::endl;
|
||||
std::cout << icsneo::GetLastError() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "✓" << std::endl;
|
||||
|
||||
std::vector<icsneo::Network::NetID> candidateNetworks = {
|
||||
icsneo::Network::NetID::AE_01, icsneo::Network::NetID::AE_02,
|
||||
icsneo::Network::NetID::AE_03, icsneo::Network::NetID::AE_04,
|
||||
icsneo::Network::NetID::AE_05, icsneo::Network::NetID::AE_06,
|
||||
icsneo::Network::NetID::AE_07, icsneo::Network::NetID::AE_08,
|
||||
icsneo::Network::NetID::AE_09, icsneo::Network::NetID::AE_10
|
||||
};
|
||||
|
||||
std::vector<icsneo::Network::NetID> t1sNetworks;
|
||||
for (auto netId : candidateNetworks) {
|
||||
auto localId = selectedDevice->settings->getT1SLocalIDFor(netId);
|
||||
if (localId.has_value())
|
||||
t1sNetworks.push_back(netId);
|
||||
}
|
||||
|
||||
if (t1sNetworks.empty()) {
|
||||
std::cout << "No T1S networks found on this device" << std::endl;
|
||||
selectedDevice->close();
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "\nFound " << t1sNetworks.size() << " T1S network"
|
||||
<< (t1sNetworks.size() == 1 ? "" : "s") << ":" << std::endl;
|
||||
for (size_t i = 0; i < t1sNetworks.size(); i++)
|
||||
std::cout << " [" << (i + 1) << "] " << icsneo::Network(t1sNetworks[i]) << std::endl;
|
||||
|
||||
std::cout << "\n" << std::string(70, '-') << std::endl;
|
||||
std::cout << "Current T1S Settings:" << std::endl;
|
||||
std::cout << std::string(70, '-') << std::endl;
|
||||
for (auto netId : t1sNetworks)
|
||||
displayT1SSettings(selectedDevice, netId);
|
||||
|
||||
auto networksToConfig = selectNetworks(t1sNetworks);
|
||||
|
||||
if (networksToConfig.empty()) {
|
||||
std::cout << "\nNo networks selected for configuration." << std::endl;
|
||||
std::cout << "Closing device... " << std::flush;
|
||||
selectedDevice->close();
|
||||
std::cout << "✓" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::cout << "\nConfiguring " << networksToConfig.size() << " network"
|
||||
<< (networksToConfig.size() == 1 ? "" : "s") << "..." << std::endl;
|
||||
|
||||
for (auto netId : networksToConfig)
|
||||
configureT1SNetwork(selectedDevice, netId);
|
||||
|
||||
std::cout << "\n" << std::string(70, '=') << std::endl;
|
||||
bool saveToEEPROM = getUserConfirmation("Save settings to EEPROM (permanent)?");
|
||||
std::cout << std::string(70, '=') << std::endl;
|
||||
|
||||
std::cout << "\nApplying settings" << (saveToEEPROM ? " to EEPROM" : " temporarily") << "... " << std::flush;
|
||||
bool success = selectedDevice->settings->apply(!saveToEEPROM);
|
||||
if (!success) {
|
||||
std::cout << "✗ Failed" << std::endl;
|
||||
std::cout << icsneo::GetLastError() << std::endl;
|
||||
selectedDevice->close();
|
||||
return 1;
|
||||
}
|
||||
std::cout << "✓" << std::endl;
|
||||
|
||||
std::cout << "\n" << std::string(70, '-') << std::endl;
|
||||
std::cout << "Updated T1S Settings:" << std::endl;
|
||||
std::cout << std::string(70, '-') << std::endl;
|
||||
for (auto netId : t1sNetworks)
|
||||
displayT1SSettings(selectedDevice, netId);
|
||||
|
||||
std::cout << "Closing device... " << std::flush;
|
||||
selectedDevice->close();
|
||||
std::cout << "✓" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
// 10BASE-T1S Symbol Decoding Example
|
||||
// Demonstrates T1S bus symbol decoding and analysis
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
|
||||
#include "icsneo/icsneocpp.h"
|
||||
|
||||
enum class T1SSymbol : uint8_t {
|
||||
SSD = 0x04,
|
||||
ESDOK = 0x07,
|
||||
BEACON = 0x08,
|
||||
ESD = 0x0D,
|
||||
ESDERR = 0x11,
|
||||
SYNC = 0x18,
|
||||
ESDJAB = 0x19,
|
||||
SILENCE = 0x1F
|
||||
};
|
||||
|
||||
std::string getSymbolName(uint8_t value) {
|
||||
switch(static_cast<T1SSymbol>(value)) {
|
||||
case T1SSymbol::SSD: return "SSD";
|
||||
case T1SSymbol::ESDOK: return "ESDOK";
|
||||
case T1SSymbol::BEACON: return "BEACON";
|
||||
case T1SSymbol::ESD: return "ESD";
|
||||
case T1SSymbol::ESDERR: return "ESDERR";
|
||||
case T1SSymbol::SYNC: return "SYNC";
|
||||
case T1SSymbol::ESDJAB: return "ESDJAB";
|
||||
case T1SSymbol::SILENCE: return "SILENCE";
|
||||
default:
|
||||
if (value <= 0x0F) {
|
||||
std::stringstream ss;
|
||||
ss << "DATA(0x" << std::hex << std::uppercase << (int)value << ")";
|
||||
return ss.str();
|
||||
}
|
||||
std::stringstream ss;
|
||||
ss << "UNKNOWN(0x" << std::hex << std::uppercase << std::setw(2)
|
||||
<< std::setfill('0') << (int)value << std::setfill(' ') << ")";
|
||||
return ss.str();
|
||||
}
|
||||
}
|
||||
|
||||
struct T1SStatistics {
|
||||
std::atomic<uint64_t> symbolCount{0};
|
||||
std::atomic<uint64_t> beaconCount{0};
|
||||
std::atomic<uint64_t> wakeCount{0};
|
||||
std::atomic<uint64_t> burstCount{0};
|
||||
std::atomic<uint64_t> dataFrameCount{0};
|
||||
std::map<std::string, uint64_t> symbolStats;
|
||||
|
||||
void reset() {
|
||||
symbolCount = 0;
|
||||
beaconCount = 0;
|
||||
wakeCount = 0;
|
||||
burstCount = 0;
|
||||
dataFrameCount = 0;
|
||||
symbolStats.clear();
|
||||
}
|
||||
|
||||
void print() const {
|
||||
std::cout << std::setfill(' ');
|
||||
|
||||
std::cout << "\n" << std::string(70, '=') << std::endl;
|
||||
std::cout << "T1S SYMBOL DECODING STATISTICS" << std::endl;
|
||||
std::cout << std::string(70, '=') << std::endl;
|
||||
|
||||
std::cout << "Total Symbols: " << symbolCount << std::endl;
|
||||
std::cout << "Total Beacons: " << beaconCount << std::endl;
|
||||
std::cout << "Total Wake Signals: " << wakeCount << std::endl;
|
||||
std::cout << "Total Bursts: " << burstCount << std::endl;
|
||||
std::cout << "Total Data Frames: " << dataFrameCount << std::endl;
|
||||
|
||||
if (!symbolStats.empty()) {
|
||||
std::cout << "\n" << std::string(70, '-') << std::endl;
|
||||
std::cout << "Symbol Type Breakdown:" << std::endl;
|
||||
std::cout << std::string(70, '-') << std::endl;
|
||||
std::vector<std::pair<std::string, uint64_t>> sortedStats(
|
||||
symbolStats.begin(), symbolStats.end());
|
||||
std::sort(sortedStats.begin(), sortedStats.end(),
|
||||
[](const auto& a, const auto& b) { return a.second > b.second; });
|
||||
|
||||
for (const auto& [name, count] : sortedStats) {
|
||||
std::cout << " " << std::left << std::setw(20) << name
|
||||
<< std::right << std::setw(10) << count << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << std::string(70, '=') << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
bool getUserConfirmation(const std::string& prompt) {
|
||||
std::string input;
|
||||
std::cout << prompt << " (y/n): " << std::flush;
|
||||
std::getline(std::cin, input);
|
||||
if (!input.empty()) {
|
||||
char c = static_cast<char>(std::tolower(input[0]));
|
||||
return (c == 'y');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool configureT1SDecoding(std::shared_ptr<icsneo::Device>& device, icsneo::Network::NetID network,
|
||||
bool enableSymbols, bool enableBeacons) {
|
||||
std::cout << "\nConfiguring T1S decoding on network " << icsneo::Network(network) << "..." << std::endl;
|
||||
if (!device->settings->setT1SBusDecodingAllFor(network, enableSymbols)) {
|
||||
std::cerr << " ✗ Failed to set T1S symbol decoding" << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (enableSymbols) {
|
||||
std::cout << " ✓ Enabled decoding of all T1S symbols" << std::endl;
|
||||
} else {
|
||||
std::cout << " • T1S symbol decoding disabled" << std::endl;
|
||||
}
|
||||
|
||||
if (!device->settings->setT1SBusDecodingBeaconsFor(network, enableBeacons)) {
|
||||
std::cerr << " ✗ Failed to set T1S beacon decoding" << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (enableBeacons) {
|
||||
std::cout << " ✓ Enabled T1S beacon decoding" << std::endl;
|
||||
} else {
|
||||
std::cout << " • T1S beacon decoding disabled" << std::endl;
|
||||
}
|
||||
|
||||
if (!device->settings->apply(true)) {
|
||||
std::cerr << " ✗ Failed to apply settings to device" << std::endl;
|
||||
std::cerr << " " << icsneo::GetLastError() << std::endl;
|
||||
return false;
|
||||
}
|
||||
std::cout << " ✓ Settings applied successfully" << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void setupSymbolMonitoring(std::shared_ptr<icsneo::Device>& device,
|
||||
icsneo::Network::NetID network,
|
||||
T1SStatistics& stats) {
|
||||
|
||||
auto callback = std::make_shared<icsneo::MessageCallback>(
|
||||
icsneo::MessageFilter(network),
|
||||
[&stats](std::shared_ptr<icsneo::Message> message) {
|
||||
if (message->type != icsneo::Message::Type::Frame)
|
||||
return;
|
||||
|
||||
auto frame = std::static_pointer_cast<icsneo::Frame>(message);
|
||||
auto netType = frame->network.getType();
|
||||
if (netType != icsneo::Network::Type::Ethernet && netType != icsneo::Network::Type::AutomotiveEthernet)
|
||||
return;
|
||||
|
||||
auto ethMsg = std::static_pointer_cast<icsneo::EthernetMessage>(frame);
|
||||
|
||||
if (!ethMsg->isT1S)
|
||||
return;
|
||||
|
||||
double timestamp_ms = ethMsg->timestamp / 1000000.0;
|
||||
|
||||
if (ethMsg->isT1SSymbol) {
|
||||
size_t numSymbols = ethMsg->data.size();
|
||||
|
||||
std::cout << std::fixed << std::setprecision(3)
|
||||
<< "[" << std::setw(12) << timestamp_ms << " ms] "
|
||||
<< "T1S Symbols";
|
||||
|
||||
if (numSymbols > 0) {
|
||||
std::cout << " (" << numSymbols << " symbol" << (numSymbols > 1 ? "s" : "") << ")";
|
||||
}
|
||||
std::cout << " | Node ID: " << (int)ethMsg->t1sNodeId << std::endl;
|
||||
|
||||
for (size_t i = 0; i < numSymbols; i++) {
|
||||
uint8_t symbolValue = ethMsg->data[i];
|
||||
std::string symbolName = getSymbolName(symbolValue);
|
||||
|
||||
stats.symbolCount++;
|
||||
stats.symbolStats[symbolName]++;
|
||||
|
||||
if (symbolValue == static_cast<uint8_t>(T1SSymbol::BEACON)) {
|
||||
stats.beaconCount++;
|
||||
}
|
||||
|
||||
std::cout << " [" << i << "] " << std::left << std::setw(10) << symbolName << std::right
|
||||
<< " = 0x" << std::hex << std::uppercase << std::setw(2)
|
||||
<< std::setfill('0') << (int)symbolValue << std::setfill(' ')
|
||||
<< std::dec << std::endl;
|
||||
}
|
||||
|
||||
if (numSymbols == 0 && ethMsg->t1sSymbolType != 0) {
|
||||
uint8_t symbolValue = ethMsg->t1sSymbolType;
|
||||
std::string symbolName = getSymbolName(symbolValue);
|
||||
|
||||
stats.symbolCount++;
|
||||
stats.symbolStats[symbolName]++;
|
||||
|
||||
if (symbolValue == static_cast<uint8_t>(T1SSymbol::BEACON)) {
|
||||
stats.beaconCount++;
|
||||
}
|
||||
|
||||
std::cout << " " << std::left << std::setw(10) << symbolName << std::right
|
||||
<< " = 0x" << std::hex << std::uppercase << std::setw(2)
|
||||
<< std::setfill('0') << (int)symbolValue << std::setfill(' ')
|
||||
<< std::dec << " (from t1sSymbolType field)" << std::endl;
|
||||
}
|
||||
}
|
||||
else if (ethMsg->isT1SBurst) {
|
||||
stats.burstCount++;
|
||||
std::cout << std::fixed << std::setprecision(3)
|
||||
<< "[" << std::setw(12) << timestamp_ms << " ms] "
|
||||
<< "BURST | "
|
||||
<< "Node ID: " << (int)ethMsg->t1sNodeId << " | "
|
||||
<< "Burst Count: " << (int)ethMsg->t1sBurstCount << std::endl;
|
||||
}
|
||||
else if (ethMsg->isT1SWake) {
|
||||
stats.wakeCount++;
|
||||
std::cout << std::fixed << std::setprecision(3)
|
||||
<< "[" << std::setw(12) << timestamp_ms << " ms] "
|
||||
<< "WAKE signal detected | "
|
||||
<< "Node ID: " << (int)ethMsg->t1sNodeId << std::endl;
|
||||
}
|
||||
else {
|
||||
stats.dataFrameCount++;
|
||||
std::cout << std::fixed << std::setprecision(3)
|
||||
<< "[" << std::setw(12) << timestamp_ms << " ms] "
|
||||
<< "T1S Data Frame | "
|
||||
<< "Length: " << ethMsg->data.size() << " bytes | "
|
||||
<< "Node ID: " << (int)ethMsg->t1sNodeId << std::endl;
|
||||
|
||||
if (!ethMsg->data.empty()) {
|
||||
std::cout << " Data: ";
|
||||
size_t preview_len = std::min(ethMsg->data.size(), size_t(16));
|
||||
for (size_t i = 0; i < preview_len; i++) {
|
||||
std::cout << std::hex << std::uppercase << std::setw(2)
|
||||
<< std::setfill('0') << (int)ethMsg->data[i] << " ";
|
||||
}
|
||||
if (ethMsg->data.size() > 16)
|
||||
std::cout << "...";
|
||||
std::cout << std::setfill(' ') << std::dec << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
device->addMessageCallback(callback);
|
||||
}
|
||||
|
||||
int main() {
|
||||
const icsneo::Network::NetID MONITOR_NETWORK = icsneo::Network::NetID::AE_02;
|
||||
const int MONITOR_DURATION_SECONDS = 30;
|
||||
|
||||
std::cout << "\n" << std::string(70, '=') << std::endl;
|
||||
std::cout << "10BASE-T1S SYMBOL DECODING EXAMPLE" << std::endl;
|
||||
std::cout << std::string(70, '=') << std::endl;
|
||||
std::cout << "libicsneo " << icsneo::GetVersion() << std::endl;
|
||||
std::cout << std::string(70, '=') << std::endl;
|
||||
|
||||
std::cout << "\nFinding devices... " << std::flush;
|
||||
auto devices = icsneo::FindAllDevices();
|
||||
std::cout << "OK, " << devices.size() << " device" << (devices.size() == 1 ? "" : "s") << " found" << std::endl;
|
||||
|
||||
if (devices.empty()) {
|
||||
std::cerr << "No devices found!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// List devices
|
||||
for (const auto& device : devices) {
|
||||
std::cout << " " << device->describe() << std::endl;
|
||||
}
|
||||
|
||||
std::shared_ptr<icsneo::Device> device;
|
||||
for (auto& dev : devices) {
|
||||
if (dev->getType() == icsneo::DeviceType::RADComet3) {
|
||||
device = dev;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!device && !devices.empty())
|
||||
device = devices[0];
|
||||
|
||||
if (!device) {
|
||||
std::cerr << "No suitable device found!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "\nSelected device: " << device->describe() << std::endl;
|
||||
std::cout << "Serial: " << device->getSerial() << std::endl;
|
||||
|
||||
std::cout << "\n" << std::string(70, '-') << std::endl;
|
||||
std::cout << "T1S DECODING CONFIGURATION" << std::endl;
|
||||
std::cout << std::string(70, '-') << std::endl;
|
||||
bool enableSymbols = getUserConfirmation("Enable T1S symbol decoding (all symbols)");
|
||||
bool enableBeacons = getUserConfirmation("Enable T1S beacon decoding");
|
||||
std::cout << std::string(70, '-') << std::endl;
|
||||
|
||||
std::cout << "\nOpening device... " << std::flush;
|
||||
if (!device->open()) {
|
||||
std::cerr << "✗ Failed" << std::endl;
|
||||
std::cerr << " " << icsneo::GetLastError() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "✓" << std::endl;
|
||||
|
||||
std::cout << "Enabling message polling... " << std::flush;
|
||||
if (!device->enableMessagePolling()) {
|
||||
std::cerr << "✗ Failed" << std::endl;
|
||||
std::cerr << " " << icsneo::GetLastError() << std::endl;
|
||||
device->close();
|
||||
return 1;
|
||||
}
|
||||
device->setPollingMessageLimit(100000);
|
||||
std::cout << "✓" << std::endl;
|
||||
|
||||
if (!configureT1SDecoding(device, MONITOR_NETWORK, enableSymbols, enableBeacons)) {
|
||||
device->close();
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Going online... " << std::flush;
|
||||
if (!device->goOnline()) {
|
||||
std::cerr << "✗ Failed" << std::endl;
|
||||
std::cerr << " " << icsneo::GetLastError() << std::endl;
|
||||
device->close();
|
||||
return 1;
|
||||
}
|
||||
std::cout << "✓" << std::endl;
|
||||
|
||||
T1SStatistics stats;
|
||||
setupSymbolMonitoring(device, MONITOR_NETWORK, stats);
|
||||
|
||||
std::cout << "\n" << std::string(70, '-') << std::endl;
|
||||
std::cout << "Monitoring T1S traffic for " << MONITOR_DURATION_SECONDS << " seconds..." << std::endl;
|
||||
std::cout << std::string(70, '-') << std::endl;
|
||||
|
||||
auto startTime = std::chrono::steady_clock::now();
|
||||
std::vector<std::shared_ptr<icsneo::Message>> messages;
|
||||
messages.reserve(10000);
|
||||
|
||||
while (std::chrono::steady_clock::now() - startTime < std::chrono::seconds(MONITOR_DURATION_SECONDS)) {
|
||||
device->getMessages(messages);
|
||||
messages.clear();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
|
||||
std::cout << "\n" << std::string(70, '-') << std::endl;
|
||||
std::cout << "Closing device... " << std::flush;
|
||||
device->close();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
std::cout << "✓" << std::endl;
|
||||
|
||||
stats.print();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
"""
|
||||
Basic analog output control example using icsneopy library.
|
||||
|
||||
Demonstrates how to configure and control analog outputs on supported devices.
|
||||
|
||||
Usage: python analog_out_basic.py <pin> <voltage> [--yes]
|
||||
|
||||
Arguments:
|
||||
pin: Pin number (1-3 for RAD Galaxy)
|
||||
voltage: Voltage level (0-5)
|
||||
--yes: Skip confirmation prompt
|
||||
"""
|
||||
|
||||
import sys
|
||||
import icsneopy
|
||||
|
||||
|
||||
def analog_output_example(pin: int, voltage: int, skip_confirm: bool = False):
|
||||
"""Configure and control analog outputs."""
|
||||
# Confirmation prompt
|
||||
if not skip_confirm:
|
||||
print(f"WARNING: This will set analog output pin {pin} to {voltage}V")
|
||||
print("Make sure nothing sensitive is connected to this pin.")
|
||||
response = input("Continue? (yes/no): ")
|
||||
if response.lower() != "yes":
|
||||
print("Aborted.")
|
||||
return
|
||||
|
||||
devices = icsneopy.find_all_devices()
|
||||
if not devices:
|
||||
raise RuntimeError("No devices found")
|
||||
|
||||
device = devices[0]
|
||||
|
||||
try:
|
||||
if not device.open():
|
||||
raise RuntimeError("Failed to open device")
|
||||
|
||||
settings = device.settings
|
||||
if not settings:
|
||||
raise RuntimeError("Device settings not available")
|
||||
|
||||
print("Refreshing device settings...")
|
||||
if not settings.refresh():
|
||||
raise RuntimeError("Failed to refresh settings")
|
||||
|
||||
# Enable analog output on specified pin
|
||||
print(f"Enabling analog output on pin {pin}...")
|
||||
if not settings.set_misc_io_analog_output_enabled(pin, True):
|
||||
raise RuntimeError(f"Failed to enable analog output on pin {pin}")
|
||||
|
||||
# Map voltage level to enum
|
||||
voltage_map = {
|
||||
0: icsneopy.Settings.MiscIOAnalogVoltage.V0,
|
||||
1: icsneopy.Settings.MiscIOAnalogVoltage.V1,
|
||||
2: icsneopy.Settings.MiscIOAnalogVoltage.V2,
|
||||
3: icsneopy.Settings.MiscIOAnalogVoltage.V3,
|
||||
4: icsneopy.Settings.MiscIOAnalogVoltage.V4,
|
||||
5: icsneopy.Settings.MiscIOAnalogVoltage.V5
|
||||
}
|
||||
voltage_enum = voltage_map[voltage]
|
||||
|
||||
# Set pin to specified voltage
|
||||
print(f"Setting pin {pin} to {voltage}V...")
|
||||
if not settings.set_misc_io_analog_output(pin, voltage_enum):
|
||||
raise RuntimeError(f"Failed to set voltage on pin {pin}")
|
||||
|
||||
# Apply settings
|
||||
print("Applying settings...")
|
||||
if not settings.apply():
|
||||
raise RuntimeError("Failed to apply settings")
|
||||
|
||||
print("Analog output configured successfully!")
|
||||
print(f"Pin {pin}: Enabled at {voltage}V")
|
||||
|
||||
finally:
|
||||
device.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 3:
|
||||
print("Error: Missing required arguments\n")
|
||||
print("Usage: python analog_out_basic.py <pin> <voltage> [--yes]")
|
||||
print("\nArguments:")
|
||||
print(" pin: Pin number (1-3 for RAD Galaxy)")
|
||||
print(" voltage: Voltage level (0-5)")
|
||||
print(" --yes: Skip confirmation prompt")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
pin = int(sys.argv[1])
|
||||
if pin < 1 or pin > 3:
|
||||
print("Error: Invalid pin number (must be 1-3)")
|
||||
sys.exit(1)
|
||||
|
||||
voltage = int(sys.argv[2])
|
||||
if voltage < 0 or voltage > 5:
|
||||
print("Error: Invalid voltage level (must be 0-5)")
|
||||
sys.exit(1)
|
||||
|
||||
skip_confirm = "--yes" in sys.argv
|
||||
|
||||
analog_output_example(pin, voltage, skip_confirm)
|
||||
|
||||
except ValueError:
|
||||
print("Error: Pin and voltage must be integers")
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,114 @@
|
||||
import sys
|
||||
import icsneopy
|
||||
|
||||
def disk_format_example():
|
||||
devices = icsneopy.find_all_devices()
|
||||
if not devices:
|
||||
print("error: no devices found")
|
||||
return False
|
||||
|
||||
print(f"Found {len(devices)} device(s):")
|
||||
for i, d in enumerate(devices):
|
||||
print(f" [{i}] {d}")
|
||||
|
||||
if len(devices) == 1:
|
||||
choice = 0
|
||||
else:
|
||||
try:
|
||||
choice = int(input(f"Select a device [0-{len(devices)-1}]: "))
|
||||
except (ValueError, EOFError):
|
||||
print("error: invalid selection")
|
||||
return False
|
||||
if choice < 0 or choice >= len(devices):
|
||||
print("error: invalid selection")
|
||||
return False
|
||||
|
||||
device = devices[choice]
|
||||
print(f"\nOpening {device}... ", end="", flush=True)
|
||||
if not device.open():
|
||||
print("FAIL")
|
||||
print(f"error: {icsneopy.get_last_error().describe()}")
|
||||
return False
|
||||
print("OK")
|
||||
|
||||
if not device.supports_disk_formatting():
|
||||
print(f"error: {device} does not support disk formatting")
|
||||
device.close()
|
||||
return False
|
||||
|
||||
print(f"Disk count: {device.get_disk_count()}")
|
||||
|
||||
# Query current disk state
|
||||
print("\nQuerying disk details... ", end="", flush=True)
|
||||
details = device.get_disk_details()
|
||||
if details is None:
|
||||
print("FAIL")
|
||||
print(f"error: {icsneopy.get_last_error().describe()}")
|
||||
device.close()
|
||||
return False
|
||||
print("OK")
|
||||
|
||||
layout_name = "RAID0" if details.layout == icsneopy.DiskLayout.RAID0 else "Spanned"
|
||||
print(f" Layout : {layout_name}")
|
||||
for i, disk in enumerate(details.disks):
|
||||
print(f" Disk [{i}]:")
|
||||
print(f" Present : {'yes' if disk.present else 'no'}")
|
||||
print(f" Initialized : {'yes' if disk.initialized else 'no'}")
|
||||
print(f" Formatted : {'yes' if disk.formatted else 'no'}")
|
||||
if disk.present:
|
||||
mb = disk.size() // (1024 * 1024)
|
||||
print(f" Size : {mb} MB ({disk.sectors} sectors x {disk.bytes_per_sector} bytes)")
|
||||
|
||||
any_present = any(d.present for d in details.disks)
|
||||
if not any_present:
|
||||
print("\nerror: no disks are present in the device")
|
||||
device.close()
|
||||
return False
|
||||
|
||||
# Build format config from the queried state
|
||||
fmt = icsneopy.DiskDetails()
|
||||
fmt.layout = details.layout
|
||||
fmt.full_format = False # Quick format; set True for a full (slow) format
|
||||
fmt.disks = details.disks
|
||||
for disk in fmt.disks:
|
||||
if disk.present:
|
||||
disk.formatted = True # mark for formatting
|
||||
|
||||
confirm = input(
|
||||
f"\nThis will format the disk(s) in {device}.\n"
|
||||
"All existing data will be lost. Continue? [y/N]: "
|
||||
).strip()
|
||||
if confirm.lower() != "y":
|
||||
print("Aborted.")
|
||||
device.close()
|
||||
return True
|
||||
|
||||
print("\nStarting format...")
|
||||
state = {"total": 0}
|
||||
|
||||
ok = device.format_disk(fmt)
|
||||
print() # newline after progress line
|
||||
|
||||
if not ok:
|
||||
print(f"error: format failed: {icsneopy.get_last_error().describe()}")
|
||||
device.close()
|
||||
return False
|
||||
|
||||
print("Format complete!")
|
||||
|
||||
# Verify
|
||||
print("\nVerifying disk state after format... ", end="", flush=True)
|
||||
post = device.get_disk_details()
|
||||
if post is None:
|
||||
print("FAIL (could not re-query disk details)")
|
||||
else:
|
||||
print("OK")
|
||||
for i, disk in enumerate(post.disks):
|
||||
print(f" Disk [{i}] formatted: {'yes' if disk.formatted else 'no'}")
|
||||
|
||||
device.close()
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(0 if disk_format_example() else 1)
|
||||
@@ -0,0 +1,218 @@
|
||||
"""
|
||||
FlexRay coldstart example using icsneopy library.
|
||||
|
||||
Demonstrates coldstart capability where one FlexRay device can start
|
||||
the network without needing other devices connected.
|
||||
|
||||
CRITICAL COLDSTART REQUIREMENTS:
|
||||
1. key_slot_used_for_startup = True
|
||||
2. key_slot_used_for_sync = True
|
||||
3. set_allow_coldstart(True)
|
||||
4. Each controller needs a unique key_slot_id
|
||||
5. Proper bus termination (required for FlexRay)
|
||||
"""
|
||||
|
||||
import icsneopy
|
||||
import time
|
||||
|
||||
|
||||
def get_coldstart_controller_config(slot_id):
|
||||
"""
|
||||
Create FlexRay controller configuration for COLDSTART.
|
||||
|
||||
The three critical settings for coldstart are marked below.
|
||||
"""
|
||||
config = icsneopy.FlexRay.Controller.Configuration()
|
||||
config.accept_startup_range_microticks = 160
|
||||
config.allow_halt_due_to_clock = True
|
||||
config.allow_passive_to_active_cycle_pairs = 15
|
||||
config.cluster_drift_damping = 2
|
||||
config.channel_a = True
|
||||
config.channel_b = True
|
||||
config.decoding_correction_microticks = 56
|
||||
config.delay_compensation_a_microticks = 28
|
||||
config.delay_compensation_b_microticks = 28
|
||||
config.extern_offset_correction_control = 0
|
||||
config.extern_rate_correction_control = 0
|
||||
config.extern_offset_correction_microticks = 0
|
||||
config.extern_rate_correction_microticks = 0
|
||||
|
||||
# CRITICAL FOR COLDSTART: Set the key slot ID
|
||||
config.key_slot_id = slot_id
|
||||
|
||||
config.key_slot_only_enabled = False
|
||||
|
||||
# CRITICAL FOR COLDSTART: Enable startup and sync on key slot
|
||||
config.key_slot_used_for_startup = True # Required for coldstart
|
||||
config.key_slot_used_for_sync = True # Required for coldstart
|
||||
|
||||
config.latest_tx_minislot = 226
|
||||
config.listen_timeout = 401202
|
||||
config.macro_initial_offset_a = 7
|
||||
config.macro_initial_offset_b = 7
|
||||
config.micro_initial_offset_a = 36
|
||||
config.micro_initial_offset_b = 36
|
||||
config.micro_per_cycle = 200000
|
||||
config.mts_on_a = False
|
||||
config.mts_on_b = False
|
||||
config.offset_correction_out_microticks = 189
|
||||
config.rate_correction_out_microticks = 601
|
||||
config.second_key_slot_id = 0
|
||||
config.two_key_slot_mode = False
|
||||
config.wakeup_pattern = 55
|
||||
config.wakeup_on_channel_b = False
|
||||
return config
|
||||
|
||||
|
||||
def get_cluster_config():
|
||||
"""Create FlexRay cluster configuration."""
|
||||
config = icsneopy.FlexRay.Cluster.Configuration()
|
||||
config.speed = icsneopy.FlexRay.Cluster.SpeedType.FLEXRAY_BAUDRATE_10M
|
||||
config.strobe_point_position = icsneopy.FlexRay.Cluster.SPPType.FLEXRAY_SPP_5
|
||||
config.action_point_offset = 4
|
||||
config.casr_x_low_max = 64
|
||||
config.cold_start_attempts = 8
|
||||
config.cycle_duration_micro_sec = 5000
|
||||
config.dynamic_slot_idle_phase_minislots = 1
|
||||
config.listen_noise_macroticks = 4
|
||||
config.macroticks_per_cycle = 5000
|
||||
config.macrotick_duration_micro_sec = 1
|
||||
config.max_without_clock_correction_fatal = 2
|
||||
config.max_without_clock_correction_passive = 2
|
||||
config.minislot_action_point_offset_macroticks = 4
|
||||
config.minislot_duration_macroticks = 10
|
||||
config.network_idle_time_macroticks = 40
|
||||
config.network_management_vector_length_bytes = 1
|
||||
config.number_of_minislots = 0
|
||||
config.number_of_static_slots = 32
|
||||
config.offset_correction_start_macroticks = 4991
|
||||
config.payload_length_of_static_slot_in_words = 67
|
||||
config.static_slot_macroticks = 155
|
||||
config.symbol_window_macroticks = 0
|
||||
config.symbol_window_action_point_offset_macroticks = 0
|
||||
config.sync_frame_id_count_max = 15
|
||||
config.transmission_start_sequence_duration_bits = 11
|
||||
config.wakeup_rx_idle_bits = 40
|
||||
config.wakeup_rx_low_bits = 40
|
||||
config.wakeup_rx_window_bits = 301
|
||||
config.wakeup_tx_active_bits = 60
|
||||
config.wakeup_tx_idle_bits = 180
|
||||
return config
|
||||
|
||||
|
||||
def flexray_coldstart():
|
||||
"""Perform FlexRay coldstart operation."""
|
||||
devices = icsneopy.find_all_devices()
|
||||
if not devices:
|
||||
raise RuntimeError("No devices found")
|
||||
|
||||
# Find a device with FlexRay support
|
||||
device = None
|
||||
for dev in devices:
|
||||
if dev.get_extension("FlexRay"):
|
||||
device = dev
|
||||
break
|
||||
|
||||
if not device:
|
||||
raise RuntimeError("No FlexRay-capable device found")
|
||||
|
||||
print(f"Using device: {device.get_product_name()} {device.get_serial()}")
|
||||
|
||||
try:
|
||||
# Get FlexRay controllers
|
||||
controllers = device.get_flexray_controllers()
|
||||
if not controllers:
|
||||
raise RuntimeError("Device has no FlexRay controllers")
|
||||
|
||||
print(f"Device has {len(controllers)} FlexRay controller(s)")
|
||||
|
||||
# Configure controllers for coldstart
|
||||
cluster_config = get_cluster_config()
|
||||
base_slot_id = 1
|
||||
|
||||
for i, controller in enumerate(controllers):
|
||||
slot_id = base_slot_id + i
|
||||
controller_config = get_coldstart_controller_config(slot_id)
|
||||
|
||||
print(f"\nConfiguring controller {i} for COLDSTART:")
|
||||
print(f" Key Slot ID: {slot_id}")
|
||||
print(f" Key Slot Used for Startup: {controller_config.key_slot_used_for_startup}")
|
||||
print(f" Key Slot Used for Sync: {controller_config.key_slot_used_for_sync}")
|
||||
|
||||
# CRITICAL FOR COLDSTART: Enable coldstart capability
|
||||
controller.set_allow_coldstart(True)
|
||||
print(f" Allow Coldstart: True")
|
||||
|
||||
# Configure to start when going online
|
||||
controller.set_start_when_going_online(True)
|
||||
|
||||
# Set the configuration
|
||||
controller.set_configuration(cluster_config, controller_config)
|
||||
|
||||
# Open device
|
||||
print("\nOpening device...")
|
||||
if not device.open():
|
||||
raise RuntimeError("Failed to open device")
|
||||
print("Device opened successfully")
|
||||
|
||||
# Go online - this triggers coldstart
|
||||
print("\nGoing online (coldstart will initiate)...")
|
||||
if not device.go_online():
|
||||
raise RuntimeError("Failed to go online - check bus termination and configuration")
|
||||
|
||||
print("Device online successfully!")
|
||||
print("\n" + "=" * 60)
|
||||
print("✓ FlexRay network started via COLDSTART")
|
||||
print("=" * 60)
|
||||
|
||||
# Transmit test messages on the coldstart key slot
|
||||
print("\nTransmitting initial test messages...")
|
||||
for i in range(5):
|
||||
frame = icsneopy.FlexRayMessage()
|
||||
frame.network = icsneopy.Network(icsneopy.Network.NetID.FLEXRAY_01)
|
||||
frame.slotid = base_slot_id # Use the first key slot
|
||||
frame.cycle = 0
|
||||
frame.cycle_repetition = 1
|
||||
frame.channel = icsneopy.FlexRay.Channel.AB
|
||||
frame.data = (0xAA, 0xBB, 0xCC, 0xDD, i, i+1, i+2, i+3)
|
||||
|
||||
if device.transmit(frame):
|
||||
print(f" ✓ Transmitted message {i+1}")
|
||||
else:
|
||||
print(f" ✗ Failed to transmit message {i+1}")
|
||||
|
||||
time.sleep(0.1)
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("Network is now active and will stay alive.")
|
||||
print("You can now run transmit/receive examples in another terminal.")
|
||||
print("Press Ctrl+C to stop and shut down the network.")
|
||||
print("=" * 60)
|
||||
|
||||
# Keep transmitting periodically to maintain network presence
|
||||
counter = 0
|
||||
try:
|
||||
while True:
|
||||
frame = icsneopy.FlexRayMessage()
|
||||
frame.network = icsneopy.Network(icsneopy.Network.NetID.FLEXRAY_01)
|
||||
frame.slotid = base_slot_id
|
||||
frame.cycle = 0
|
||||
frame.cycle_repetition = 1
|
||||
frame.channel = icsneopy.FlexRay.Channel.AB
|
||||
frame.data = (0xCA, 0xFE, 0xBA, 0xBE, counter & 0xFF,
|
||||
(counter >> 8) & 0xFF, (counter >> 16) & 0xFF, (counter >> 24) & 0xFF)
|
||||
|
||||
device.transmit(frame)
|
||||
counter += 1
|
||||
time.sleep(1) # Transmit every second
|
||||
except KeyboardInterrupt:
|
||||
print("\n\nStopping coldstart node...")
|
||||
|
||||
print("\n✓ Coldstart example completed successfully!")
|
||||
|
||||
finally:
|
||||
device.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
flexray_coldstart()
|
||||
@@ -0,0 +1,188 @@
|
||||
|
||||
# Basic FlexRay frame reception example using icsneopy library.
|
||||
|
||||
|
||||
import icsneopy
|
||||
import time
|
||||
import signal
|
||||
import sys
|
||||
|
||||
|
||||
def get_controller_config(slot_id):
|
||||
"""Create a FlexRay controller configuration matching the network.
|
||||
|
||||
Args:
|
||||
slot_id: The key slot ID for this node (must be unique per node)
|
||||
|
||||
Returns:
|
||||
FlexRay.Controller.Configuration with all parameters set
|
||||
|
||||
Note:
|
||||
For passive listening on an existing network, set:
|
||||
- key_slot_used_for_startup = False
|
||||
- Remove set_allow_coldstart(True) call below
|
||||
"""
|
||||
config = icsneopy.FlexRay.Controller.Configuration()
|
||||
config.accept_startup_range_microticks = 160
|
||||
config.allow_halt_due_to_clock = True
|
||||
config.allow_passive_to_active_cycle_pairs = 15
|
||||
config.cluster_drift_damping = 2
|
||||
|
||||
# Physical channel configuration (Channel A only for this example)
|
||||
config.channel_a = True
|
||||
config.channel_b = False # Single channel A only
|
||||
|
||||
config.decoding_correction_microticks = 56
|
||||
config.delay_compensation_a_microticks = 28
|
||||
config.delay_compensation_b_microticks = 28
|
||||
config.extern_offset_correction_control = 0
|
||||
config.extern_rate_correction_control = 0
|
||||
config.extern_offset_correction_microticks = 0
|
||||
config.extern_rate_correction_microticks = 0
|
||||
|
||||
# KEY SLOT CONFIGURATION - Critical for FlexRay operation
|
||||
config.key_slot_id = slot_id # Must be unique per node
|
||||
config.key_slot_only_enabled = False
|
||||
config.key_slot_used_for_startup = True # True = participate in coldstart
|
||||
config.key_slot_used_for_sync = True # True = synchronize with network
|
||||
|
||||
config.latest_tx_minislot = 226
|
||||
config.listen_timeout = 401202
|
||||
config.macro_initial_offset_a = 7
|
||||
config.macro_initial_offset_b = 7
|
||||
config.micro_initial_offset_a = 36
|
||||
config.micro_initial_offset_b = 36
|
||||
config.micro_per_cycle = 200000
|
||||
config.mts_on_a = False
|
||||
config.mts_on_b = False
|
||||
config.offset_correction_out_microticks = 189
|
||||
config.rate_correction_out_microticks = 601
|
||||
config.second_key_slot_id = 0
|
||||
config.two_key_slot_mode = False
|
||||
config.wakeup_pattern = 55
|
||||
config.wakeup_on_channel_b = False
|
||||
return config
|
||||
|
||||
|
||||
def get_cluster_config():
|
||||
"""Create a FlexRay cluster configuration matching the network."""
|
||||
config = icsneopy.FlexRay.Cluster.Configuration()
|
||||
config.speed = icsneopy.FlexRay.Cluster.SpeedType.FLEXRAY_BAUDRATE_10M
|
||||
config.strobe_point_position = icsneopy.FlexRay.Cluster.SPPType.FLEXRAY_SPP_5
|
||||
config.action_point_offset = 4
|
||||
config.casr_x_low_max = 64
|
||||
config.cold_start_attempts = 8
|
||||
config.cycle_duration_micro_sec = 5000
|
||||
config.dynamic_slot_idle_phase_minislots = 1
|
||||
config.listen_noise_macroticks = 4
|
||||
config.macroticks_per_cycle = 5000
|
||||
config.macrotick_duration_micro_sec = 1
|
||||
config.max_without_clock_correction_fatal = 2
|
||||
config.max_without_clock_correction_passive = 2
|
||||
config.minislot_action_point_offset_macroticks = 4
|
||||
config.minislot_duration_macroticks = 10
|
||||
config.network_idle_time_macroticks = 40
|
||||
config.network_management_vector_length_bytes = 1
|
||||
config.number_of_minislots = 0
|
||||
config.number_of_static_slots = 32
|
||||
config.offset_correction_start_macroticks = 4991
|
||||
config.payload_length_of_static_slot_in_words = 67
|
||||
config.static_slot_macroticks = 155
|
||||
config.symbol_window_macroticks = 0
|
||||
config.symbol_window_action_point_offset_macroticks = 0
|
||||
config.sync_frame_id_count_max = 15
|
||||
config.transmission_start_sequence_duration_bits = 11
|
||||
config.wakeup_rx_idle_bits = 40
|
||||
config.wakeup_rx_low_bits = 40
|
||||
config.wakeup_rx_window_bits = 301
|
||||
config.wakeup_tx_active_bits = 60
|
||||
config.wakeup_tx_idle_bits = 180
|
||||
return config
|
||||
|
||||
|
||||
def receive_flexray_frames():
|
||||
"""Receive FlexRay frames as passive node with callback handling."""
|
||||
devices = icsneopy.find_all_devices()
|
||||
if not devices:
|
||||
raise RuntimeError("No devices found")
|
||||
|
||||
# Find a device with FlexRay support
|
||||
device = None
|
||||
for dev in devices:
|
||||
if dev.get_extension("FlexRay"):
|
||||
device = dev
|
||||
break
|
||||
|
||||
if not device:
|
||||
raise RuntimeError("No FlexRay-capable device found")
|
||||
|
||||
frame_count = 0
|
||||
running = True
|
||||
|
||||
def on_frame(frame):
|
||||
nonlocal frame_count
|
||||
if isinstance(frame, icsneopy.FlexRayMessage):
|
||||
# Only show frames from slot 1 (filter out null frames)
|
||||
if frame.slotid == 1:
|
||||
frame_count += 1
|
||||
# Nice formatted view of the frame
|
||||
payload_hex = ' '.join([f'{b:02X}' for b in frame.data[:8]])
|
||||
payload_dec = ' '.join([f'{b:3d}' for b in frame.data[:8]])
|
||||
print(f"[Frame {frame_count:4d}] Slot: {frame.slotid:2d} | Cycle: {frame.cycle:2d} | "
|
||||
f"Channel: {str(frame.channel):10s}")
|
||||
print(f" Hex: [{payload_hex}]")
|
||||
print(f" Dec: [{payload_dec}]\n")
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
nonlocal running
|
||||
print("\nShutting down...")
|
||||
running = False
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
|
||||
frame_filter = icsneopy.MessageFilter(icsneopy.Network.NetID.FLEXRAY_02)
|
||||
callback = icsneopy.MessageCallback(on_frame, frame_filter)
|
||||
|
||||
try:
|
||||
# Configure FlexRay controller 1 (FLEXRAY_02) as passive node
|
||||
controllers = device.get_flexray_controllers()
|
||||
if len(controllers) < 2:
|
||||
raise RuntimeError("Device needs at least 2 FlexRay controllers")
|
||||
|
||||
controller = controllers[1] # Use controller 1
|
||||
cluster_config = get_cluster_config()
|
||||
controller_config = get_controller_config(slot_id=2)
|
||||
|
||||
# Enable coldstart so this node transmits and coldstart node sees activity
|
||||
controller.set_allow_coldstart(True)
|
||||
controller.set_configuration(cluster_config, controller_config)
|
||||
controller.set_start_when_going_online(True)
|
||||
|
||||
if not device.open():
|
||||
raise RuntimeError("Failed to open device")
|
||||
|
||||
if not device.go_online():
|
||||
raise RuntimeError("Failed to go online")
|
||||
|
||||
device.add_message_callback(callback)
|
||||
print("="*60)
|
||||
print("FlexRay Receive Node - Coldstart Config Loaded")
|
||||
print("="*60)
|
||||
print(f"Controller: FLEXRAY_02 | Slot ID: 2 | Channel: A")
|
||||
print(f"Listening for frames...")
|
||||
print(f"Start the transmit script now to begin communication")
|
||||
print("="*60)
|
||||
print("Press Ctrl+C to stop\n")
|
||||
|
||||
while running:
|
||||
time.sleep(0.1)
|
||||
|
||||
print(f"\nTotal frames received: {frame_count}")
|
||||
|
||||
finally:
|
||||
device.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
receive_flexray_frames()
|
||||
@@ -0,0 +1,218 @@
|
||||
|
||||
# Basic FlexRay frame transmission example using icsneopy library.
|
||||
|
||||
|
||||
import icsneopy
|
||||
import time
|
||||
import signal
|
||||
import sys
|
||||
import random
|
||||
|
||||
|
||||
def get_controller_config(slot_id, is_coldstart=False):
|
||||
"""Create a FlexRay controller configuration matching the network.
|
||||
|
||||
Args:
|
||||
slot_id: The key slot ID for this node (must be unique per node)
|
||||
is_coldstart: True if this node participates in coldstart
|
||||
|
||||
Returns:
|
||||
FlexRay.Controller.Configuration with all parameters set
|
||||
"""
|
||||
config = icsneopy.FlexRay.Controller.Configuration()
|
||||
config.accept_startup_range_microticks = 160
|
||||
config.allow_halt_due_to_clock = True
|
||||
config.allow_passive_to_active_cycle_pairs = 15
|
||||
config.cluster_drift_damping = 2
|
||||
|
||||
# Physical channel configuration (Channel A only for this example)
|
||||
config.channel_a = True
|
||||
config.channel_b = False # Single channel A only
|
||||
|
||||
config.decoding_correction_microticks = 56
|
||||
config.delay_compensation_a_microticks = 28
|
||||
config.delay_compensation_b_microticks = 28
|
||||
config.extern_offset_correction_control = 0
|
||||
config.extern_rate_correction_control = 0
|
||||
config.extern_offset_correction_microticks = 0
|
||||
config.extern_rate_correction_microticks = 0
|
||||
|
||||
# KEY SLOT CONFIGURATION - Critical for FlexRay operation
|
||||
config.key_slot_id = slot_id # Must be unique per node
|
||||
config.key_slot_only_enabled = False
|
||||
config.key_slot_used_for_startup = is_coldstart # True = coldstart node
|
||||
config.key_slot_used_for_sync = is_coldstart # True = provides sync
|
||||
|
||||
config.latest_tx_minislot = 226
|
||||
config.listen_timeout = 401202
|
||||
config.macro_initial_offset_a = 7
|
||||
config.macro_initial_offset_b = 7
|
||||
config.micro_initial_offset_a = 36
|
||||
config.micro_initial_offset_b = 36
|
||||
config.micro_per_cycle = 200000
|
||||
config.mts_on_a = False
|
||||
config.mts_on_b = False
|
||||
config.offset_correction_out_microticks = 189
|
||||
config.rate_correction_out_microticks = 601
|
||||
config.second_key_slot_id = 0
|
||||
config.two_key_slot_mode = False
|
||||
config.wakeup_pattern = 55
|
||||
config.wakeup_on_channel_b = False
|
||||
return config
|
||||
|
||||
|
||||
def get_cluster_config():
|
||||
"""Create a FlexRay cluster configuration matching the network.
|
||||
|
||||
All nodes on the FlexRay network must have identical cluster parameters.
|
||||
These define the timing and structure of the FlexRay communication cycle.
|
||||
|
||||
Key parameters:
|
||||
- cycle_duration_micro_sec: 5000 = 5ms cycle time
|
||||
- macroticks_per_cycle: 5000 macroticks per cycle
|
||||
- number_of_static_slots: 32 static slots for guaranteed transmission
|
||||
- payload_length_of_static_slot_in_words: 67 words = 134 bytes max payload
|
||||
|
||||
Returns:
|
||||
FlexRay.Cluster.Configuration with all timing parameters set
|
||||
"""
|
||||
config = icsneopy.FlexRay.Cluster.Configuration()
|
||||
config.speed = icsneopy.FlexRay.Cluster.SpeedType.FLEXRAY_BAUDRATE_10M
|
||||
config.strobe_point_position = icsneopy.FlexRay.Cluster.SPPType.FLEXRAY_SPP_5
|
||||
config.action_point_offset = 4
|
||||
config.casr_x_low_max = 64
|
||||
config.cold_start_attempts = 8
|
||||
config.cycle_duration_micro_sec = 5000
|
||||
config.dynamic_slot_idle_phase_minislots = 1
|
||||
config.listen_noise_macroticks = 4
|
||||
config.macroticks_per_cycle = 5000
|
||||
config.macrotick_duration_micro_sec = 1
|
||||
config.max_without_clock_correction_fatal = 2
|
||||
config.max_without_clock_correction_passive = 2
|
||||
config.minislot_action_point_offset_macroticks = 4
|
||||
config.minislot_duration_macroticks = 10
|
||||
config.network_idle_time_macroticks = 40
|
||||
config.network_management_vector_length_bytes = 1
|
||||
config.number_of_minislots = 0
|
||||
config.number_of_static_slots = 32
|
||||
config.offset_correction_start_macroticks = 4991
|
||||
config.payload_length_of_static_slot_in_words = 67
|
||||
config.static_slot_macroticks = 155
|
||||
config.symbol_window_macroticks = 0
|
||||
config.symbol_window_action_point_offset_macroticks = 0
|
||||
config.sync_frame_id_count_max = 15
|
||||
config.transmission_start_sequence_duration_bits = 11
|
||||
config.wakeup_rx_idle_bits = 40
|
||||
config.wakeup_rx_low_bits = 40
|
||||
config.wakeup_rx_window_bits = 301
|
||||
config.wakeup_tx_active_bits = 60
|
||||
config.wakeup_tx_idle_bits = 180
|
||||
return config
|
||||
|
||||
|
||||
def transmit_flexray_frame():
|
||||
"""Transmit FlexRay frames as coldstart node."""
|
||||
devices = icsneopy.find_all_devices()
|
||||
if not devices:
|
||||
raise RuntimeError("No devices found")
|
||||
|
||||
# Find a device with FlexRay support
|
||||
device = None
|
||||
for dev in devices:
|
||||
if dev.get_extension("FlexRay"):
|
||||
device = dev
|
||||
break
|
||||
|
||||
if not device:
|
||||
raise RuntimeError("No FlexRay-capable device found")
|
||||
|
||||
running = True
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
nonlocal running
|
||||
print("\nShutting down...")
|
||||
running = False
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
|
||||
try:
|
||||
# Configure FlexRay controller 0 (FLEXRAY_01) as coldstart node
|
||||
controllers = device.get_flexray_controllers()
|
||||
if not controllers:
|
||||
raise RuntimeError("Device has no FlexRay controllers")
|
||||
|
||||
controller = controllers[0] # Use controller 0
|
||||
cluster_config = get_cluster_config()
|
||||
controller_config = get_controller_config(slot_id=1, is_coldstart=True)
|
||||
|
||||
# Enable coldstart capability
|
||||
controller.set_allow_coldstart(True)
|
||||
controller.set_configuration(cluster_config, controller_config)
|
||||
controller.set_start_when_going_online(True)
|
||||
|
||||
if not device.open():
|
||||
raise RuntimeError("Failed to open device")
|
||||
|
||||
if not device.go_online():
|
||||
raise RuntimeError("Failed to go online")
|
||||
|
||||
print("="*60)
|
||||
print("FlexRay Transmit Node - Starting Network")
|
||||
print("="*60)
|
||||
print(f"Controller: FLEXRAY_01 | Slot ID: 1 | Channel: A")
|
||||
print(f"Transmitting frames continuously...")
|
||||
print("="*60)
|
||||
print("Press Ctrl+C to stop\n")
|
||||
|
||||
# Transmit frames continuously starting immediately
|
||||
counter = 0
|
||||
sensor_temp = 20.0 # Simulated temperature sensor
|
||||
sensor_pressure = 100.0 # Simulated pressure sensor
|
||||
|
||||
while running:
|
||||
# Create new frame each time (important for FlexRay)
|
||||
frame = icsneopy.FlexRayMessage()
|
||||
frame.network = icsneopy.Network(icsneopy.Network.NetID.FLEXRAY_01)
|
||||
frame.slotid = 1
|
||||
frame.cycle = 0
|
||||
frame.cycle_repetition = 1
|
||||
frame.channel = icsneopy.FlexRay.Channel.A
|
||||
|
||||
# Simulate realistic sensor data
|
||||
sensor_temp += random.uniform(-0.5, 0.5) # Temperature varies
|
||||
sensor_pressure += random.uniform(-2.0, 2.0) # Pressure varies
|
||||
|
||||
# Pack data: [status, counter, temp_high, temp_low, pressure_high, pressure_low, checksum_placeholder, sequence]
|
||||
status_byte = 0xA0 | (counter % 16) # Status with rolling bits
|
||||
temp_int = int(sensor_temp * 10) & 0xFFFF
|
||||
pressure_int = int(sensor_pressure * 10) & 0xFFFF
|
||||
|
||||
frame.data = (
|
||||
status_byte,
|
||||
counter & 0xFF,
|
||||
(temp_int >> 8) & 0xFF,
|
||||
temp_int & 0xFF,
|
||||
(pressure_int >> 8) & 0xFF,
|
||||
pressure_int & 0xFF,
|
||||
random.randint(0, 255), # Random data
|
||||
(counter >> 8) & 0xFF
|
||||
)
|
||||
|
||||
success = device.transmit(frame)
|
||||
if counter % 100 == 0: # Print every 100th to reduce spam
|
||||
if success:
|
||||
print(f" [TX {counter}] Temp: {sensor_temp:.1f}°C | Pressure: {sensor_pressure:.1f} kPa")
|
||||
else:
|
||||
print(f" Frame {counter}: Failed to transmit")
|
||||
counter += 1
|
||||
time.sleep(0.005) # 5ms per cycle
|
||||
|
||||
print("\nTransmission complete!")
|
||||
|
||||
finally:
|
||||
device.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
transmit_flexray_frame()
|
||||
@@ -0,0 +1,130 @@
|
||||
"""
|
||||
LiveData subscription and monitoring example using icsneopy library.
|
||||
|
||||
"""
|
||||
|
||||
import icsneopy
|
||||
import time
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
def livedata_example():
|
||||
"""Subscribe to and monitor LiveData signals."""
|
||||
devices = icsneopy.find_all_devices()
|
||||
if not devices:
|
||||
raise RuntimeError("No devices found")
|
||||
|
||||
device = devices[0]
|
||||
print(f"Using device: {device}")
|
||||
|
||||
try:
|
||||
if not device.open():
|
||||
raise RuntimeError("Failed to open device")
|
||||
|
||||
if not device.go_online():
|
||||
raise RuntimeError("Failed to go online")
|
||||
|
||||
device.enable_message_polling()
|
||||
|
||||
# Create subscription message
|
||||
msg = icsneopy.LiveDataCommandMessage()
|
||||
msg.handle = icsneopy.get_new_handle()
|
||||
msg.cmd = icsneopy.LiveDataCommand.SUBSCRIBE
|
||||
msg.update_period = timedelta(milliseconds=500)
|
||||
msg.expiration_time = timedelta(milliseconds=0)
|
||||
|
||||
# Subscribe to various LiveData signals
|
||||
msg.append_signal_arg(icsneopy.LiveDataValueType.GPS_LATITUDE)
|
||||
msg.append_signal_arg(icsneopy.LiveDataValueType.GPS_LONGITUDE)
|
||||
msg.append_signal_arg(icsneopy.LiveDataValueType.GPS_ACCURACY)
|
||||
msg.append_signal_arg(icsneopy.LiveDataValueType.DAQ_ENABLE)
|
||||
msg.append_signal_arg(icsneopy.LiveDataValueType.MANUAL_TRIGGER)
|
||||
msg.append_signal_arg(icsneopy.LiveDataValueType.TIME_SINCE_MSG)
|
||||
|
||||
print("\nSubscribing to LiveData signals...")
|
||||
if not device.subscribe_live_data(msg):
|
||||
raise RuntimeError(f"Subscription failed: {icsneopy.get_last_error()}")
|
||||
|
||||
print("Subscription successful")
|
||||
print("\nMonitoring LiveData for 5 seconds...")
|
||||
|
||||
response_count = 0
|
||||
start_time = time.time()
|
||||
|
||||
while time.time() - start_time < 5:
|
||||
result = device.get_messages()
|
||||
messages = result[0] if isinstance(result, tuple) else result
|
||||
|
||||
for m in messages:
|
||||
if isinstance(m, icsneopy.LiveDataStatusMessage):
|
||||
if m.handle == msg.handle:
|
||||
print(f"\n[Status] Command: {m.requested_command}, Status: {m.status}")
|
||||
|
||||
elif isinstance(m, icsneopy.LiveDataValueMessage):
|
||||
if m.handle == msg.handle:
|
||||
response_count += 1
|
||||
print(f"\n[Response #{response_count}]")
|
||||
signal_names = ["GPS_LAT", "GPS_LON", "GPS_ACC",
|
||||
"DAQ_EN", "MAN_TRIG", "TIME_SINCE"]
|
||||
for idx, val in enumerate(m.values):
|
||||
value = icsneopy.livedata_value_to_double(val)
|
||||
name = signal_names[idx] if idx < len(signal_names) else f"Signal_{idx}"
|
||||
print(f" {name:12s}: {value:10.2f}")
|
||||
|
||||
time.sleep(0.1)
|
||||
|
||||
print(f"\nReceived {response_count} response messages")
|
||||
|
||||
# Demonstrate setting values
|
||||
print("\nSetting custom values...")
|
||||
set_msg = icsneopy.LiveDataSetValueMessage()
|
||||
set_msg.handle = icsneopy.get_new_handle()
|
||||
set_msg.cmd = icsneopy.LiveDataCommand.SET_VALUE
|
||||
|
||||
# Set DAQ_ENABLE
|
||||
value = icsneopy.livedata_double_to_value(1.0)
|
||||
if value:
|
||||
set_msg.append_set_value(icsneopy.LiveDataValueType.DAQ_ENABLE, value)
|
||||
|
||||
# Set MANUAL_TRIGGER
|
||||
value = icsneopy.livedata_double_to_value(1.0)
|
||||
if value:
|
||||
set_msg.append_set_value(icsneopy.LiveDataValueType.MANUAL_TRIGGER, value)
|
||||
|
||||
if device.set_value_live_data(set_msg):
|
||||
print("Values set successfully")
|
||||
time.sleep(0.5)
|
||||
|
||||
# Check the results
|
||||
result = device.get_messages()
|
||||
messages = result[0] if isinstance(result, tuple) else result
|
||||
for m in messages:
|
||||
if isinstance(m, icsneopy.LiveDataStatusMessage):
|
||||
if m.handle == set_msg.handle:
|
||||
print(f" Set status: {m.status}")
|
||||
|
||||
# Keep device awake by resetting TIME_SINCE_MSG
|
||||
print("\nResetting TIME_SINCE_MSG to keep device awake...")
|
||||
reset_msg = icsneopy.LiveDataSetValueMessage()
|
||||
reset_msg.handle = icsneopy.get_new_handle()
|
||||
reset_msg.cmd = icsneopy.LiveDataCommand.SET_VALUE
|
||||
|
||||
value = icsneopy.livedata_double_to_value(0.0)
|
||||
if value:
|
||||
reset_msg.append_set_value(icsneopy.LiveDataValueType.TIME_SINCE_MSG, value)
|
||||
if device.set_value_live_data(reset_msg):
|
||||
print("TIME_SINCE_MSG reset to 0")
|
||||
|
||||
# Unsubscribe
|
||||
print("\nUnsubscribing...")
|
||||
if device.unsubscribe_live_data(msg.handle):
|
||||
print("Unsubscribed successfully")
|
||||
|
||||
finally:
|
||||
device.close()
|
||||
print("\nDevice closed")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
livedata_example()
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
"""
|
||||
Complete SPI example for 10BASE-T1S MACPHYs using icsneopy library.
|
||||
|
||||
Demonstrates device setup and SPI frame transmission/reception.
|
||||
"""
|
||||
|
||||
import icsneopy
|
||||
import time
|
||||
|
||||
|
||||
def setup_device():
|
||||
"""Initialize SPI device."""
|
||||
devices = icsneopy.find_all_devices()
|
||||
if not devices:
|
||||
raise RuntimeError("No devices found")
|
||||
|
||||
device = devices[0]
|
||||
print(f"Using device: {device}")
|
||||
return device
|
||||
|
||||
|
||||
def open_device(device):
|
||||
"""Open device connection."""
|
||||
try:
|
||||
if not device.open():
|
||||
raise RuntimeError("Failed to open device")
|
||||
|
||||
if not device.go_online():
|
||||
device.close()
|
||||
raise RuntimeError("Failed to go online")
|
||||
|
||||
print("Device initialized successfully")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"Device setup failed: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def transmit_spi_frame(device, mms, addr, dir, write_data=None):
|
||||
"""Transmit a SPI frame."""
|
||||
frame = icsneopy.SPIMessage()
|
||||
frame.network = icsneopy.Network(icsneopy.Network.NetID.SPI_01)
|
||||
frame.direction = dir
|
||||
frame.mms = mms
|
||||
frame.address = addr
|
||||
if dir == icsneopy.SPIMessage.Direction.Read:
|
||||
frame.payload = [0] # single register
|
||||
else:
|
||||
frame.payload = [write_data]
|
||||
|
||||
success = device.transmit(frame)
|
||||
if success:
|
||||
print("Frame transmitted")
|
||||
else:
|
||||
print("Failed to transmit frame")
|
||||
|
||||
return success
|
||||
|
||||
|
||||
def setup_spi_reception(device):
|
||||
"""Configure SPI frame reception with callback."""
|
||||
|
||||
def frame_handler(frame):
|
||||
access = (
|
||||
"Write"
|
||||
if frame.direction == icsneopy.SPIMessage.Direction.Write
|
||||
else "Read"
|
||||
)
|
||||
print(
|
||||
f"{access}, "
|
||||
f"MMS: 0x{frame.mms:02X}, "
|
||||
f"Register: 0x{frame.address:03X}, "
|
||||
f"Data: {[hex(b) for b in frame.payload]}, "
|
||||
f"Length: {len(frame.payload)}"
|
||||
)
|
||||
|
||||
frame_filter = icsneopy.MessageFilter(icsneopy.Network.NetID.SPI_01)
|
||||
callback = icsneopy.MessageCallback(frame_handler, frame_filter)
|
||||
device.add_message_callback(callback)
|
||||
|
||||
print("SPI frame reception configured")
|
||||
|
||||
|
||||
def cleanup_device(device):
|
||||
"""Close device connection."""
|
||||
if device:
|
||||
device.close()
|
||||
print("Device connection closed")
|
||||
|
||||
|
||||
def main():
|
||||
"""Complete SPI example with proper error handling."""
|
||||
device = None
|
||||
|
||||
try:
|
||||
# Setup device
|
||||
device = setup_device()
|
||||
|
||||
# Open device
|
||||
if not open_device(device):
|
||||
raise RuntimeError("Failed to initialize device")
|
||||
|
||||
# Setup frame reception
|
||||
setup_spi_reception(device)
|
||||
|
||||
# Read 10BASE-T1S MACPHY ID register
|
||||
transmit_spi_frame(device, 0x0, 0x0001, icsneopy.SPIMessage.Direction.Read)
|
||||
|
||||
# Change 10BASE-T1S Test mode control
|
||||
transmit_spi_frame(device, 0x3, 0x08FB, icsneopy.SPIMessage.Direction.Read)
|
||||
transmit_spi_frame(
|
||||
device, 0x3, 0x08FB, icsneopy.SPIMessage.Direction.Write, 0x6000
|
||||
)
|
||||
transmit_spi_frame(device, 0x3, 0x08FB, icsneopy.SPIMessage.Direction.Read)
|
||||
|
||||
time.sleep(0.1)
|
||||
|
||||
# Listen for responses
|
||||
print("Listening for SPI frames for 5 seconds...")
|
||||
time.sleep(5)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
return 1
|
||||
|
||||
finally:
|
||||
cleanup_device(device)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,325 @@
|
||||
"""
|
||||
10BASE-T1S Settings Configuration Example
|
||||
Demonstrates interactive T1S network configuration
|
||||
"""
|
||||
|
||||
import icsneopy
|
||||
|
||||
|
||||
def get_user_confirmation(prompt):
|
||||
"""Get yes/no confirmation from user."""
|
||||
response = input(f"{prompt} (y/n): ").strip().lower()
|
||||
return response == 'y'
|
||||
|
||||
|
||||
def select_networks(available_networks):
|
||||
"""Let user select which networks to configure."""
|
||||
print("\n" + "=" * 70)
|
||||
print("Select T1S Networks to Configure")
|
||||
print("=" * 70)
|
||||
|
||||
for i, net_id in enumerate(available_networks, 1):
|
||||
print(f" [{i}] {net_id}")
|
||||
|
||||
response = input("\nEnter network numbers to configure (e.g., '1,3' or '1-3' or 'all'): ").strip().lower()
|
||||
|
||||
if not response:
|
||||
return []
|
||||
|
||||
if response == 'all':
|
||||
return available_networks
|
||||
|
||||
selected = []
|
||||
tokens = response.split(',')
|
||||
|
||||
for token in tokens:
|
||||
token = token.strip()
|
||||
|
||||
if '-' in token:
|
||||
try:
|
||||
parts = token.split('-')
|
||||
start = int(parts[0])
|
||||
end = int(parts[1])
|
||||
for i in range(start, end + 1):
|
||||
if 1 <= i <= len(available_networks):
|
||||
selected.append(available_networks[i - 1])
|
||||
except (ValueError, IndexError):
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
num = int(token)
|
||||
if 1 <= num <= len(available_networks):
|
||||
selected.append(available_networks[num - 1])
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return selected
|
||||
|
||||
|
||||
def get_uint8_input(prompt, default_value):
|
||||
"""Get uint8 input from user with default."""
|
||||
response = input(f"{prompt} [{default_value}]: ").strip()
|
||||
if not response:
|
||||
return default_value
|
||||
try:
|
||||
val = int(response)
|
||||
if 0 <= val <= 255:
|
||||
return val
|
||||
except ValueError:
|
||||
pass
|
||||
return default_value
|
||||
|
||||
|
||||
def get_uint16_input(prompt, default_value):
|
||||
"""Get uint16 input from user with default."""
|
||||
response = input(f"{prompt} [{default_value}]: ").strip()
|
||||
if not response:
|
||||
return default_value
|
||||
try:
|
||||
val = int(response)
|
||||
if 0 <= val <= 65535:
|
||||
return val
|
||||
except ValueError:
|
||||
pass
|
||||
return default_value
|
||||
|
||||
|
||||
def opt_to_string(opt):
|
||||
"""Convert optional value to string for display."""
|
||||
if opt is None:
|
||||
return "N/A"
|
||||
if isinstance(opt, bool):
|
||||
return "true" if opt else "false"
|
||||
return str(opt)
|
||||
|
||||
|
||||
def display_t1s_settings(device, network):
|
||||
"""Display T1S settings for a network."""
|
||||
print(f"\t{network} T1S Settings:")
|
||||
|
||||
settings = device.get_settings()
|
||||
if not settings:
|
||||
print("\t Unable to read settings")
|
||||
return
|
||||
|
||||
print(f"\t PLCA Enabled: {opt_to_string(settings.get_t1s_plca_enabled(network))}")
|
||||
print(f"\t Local ID: {opt_to_string(settings.get_t1s_local_id(network))}")
|
||||
print(f"\t Max Nodes: {opt_to_string(settings.get_t1s_max_nodes(network))}")
|
||||
print(f"\t TX Opp Timer: {opt_to_string(settings.get_t1s_tx_opp_timer(network))}")
|
||||
print(f"\t Max Burst: {opt_to_string(settings.get_t1s_max_burst(network))}")
|
||||
print(f"\t Burst Timer: {opt_to_string(settings.get_t1s_burst_timer(network))}")
|
||||
|
||||
term_enabled = settings.get_t1s_termination_enabled(network)
|
||||
if term_enabled is not None:
|
||||
print(f"\t Termination: {opt_to_string(term_enabled)}")
|
||||
|
||||
local_id_alt = settings.get_t1s_local_id_alternate(network)
|
||||
if local_id_alt is not None:
|
||||
print(f"\t Local ID Alternate: {opt_to_string(local_id_alt)}")
|
||||
print(f"\t Bus Dec Beacons: {opt_to_string(settings.get_t1s_bus_decoding_beacons_enabled(network))}")
|
||||
print(f"\t Bus Dec All: {opt_to_string(settings.get_t1s_bus_decoding_all_enabled(network))}")
|
||||
|
||||
multi_id_mask = settings.get_t1s_multi_id_enable_mask(network)
|
||||
if multi_id_mask is not None:
|
||||
print(f"\t Multi-ID Mask: 0x{multi_id_mask:02X}")
|
||||
print("\t Multi-IDs: ", end="")
|
||||
multi_ids = []
|
||||
for i in range(7):
|
||||
multi_id = settings.get_t1s_multi_id(network, i)
|
||||
multi_ids.append(f"[{i}]={opt_to_string(multi_id)}")
|
||||
print(", ".join(multi_ids))
|
||||
|
||||
print()
|
||||
|
||||
|
||||
def configure_t1s_network(device, network):
|
||||
"""Interactively configure T1S settings for a network."""
|
||||
print("\n" + "=" * 70)
|
||||
print(f"Configuring T1S Network: {network}")
|
||||
print("=" * 70)
|
||||
|
||||
settings = device.get_settings()
|
||||
if not settings:
|
||||
print("Unable to read settings")
|
||||
return
|
||||
|
||||
print("\n--- Basic PLCA Settings ---")
|
||||
plca_enabled = get_user_confirmation("Enable PLCA")
|
||||
settings.set_t1s_plca(network, plca_enabled)
|
||||
|
||||
local_id = get_uint8_input("Local ID (0-255)", 1)
|
||||
settings.set_t1s_local_id(network, local_id)
|
||||
|
||||
max_nodes = get_uint8_input("Max Nodes (0-255)", 8)
|
||||
settings.set_t1s_max_nodes(network, max_nodes)
|
||||
|
||||
tx_opp_timer = get_uint8_input("TX Opportunity Timer (0-255)", 20)
|
||||
settings.set_t1s_tx_opp_timer(network, tx_opp_timer)
|
||||
|
||||
max_burst = get_uint16_input("Max Burst (0-65535)", 128)
|
||||
settings.set_t1s_max_burst(network, max_burst)
|
||||
|
||||
burst_timer = get_uint16_input("Burst Timer (0-65535)", 64)
|
||||
settings.set_t1s_burst_timer(network, burst_timer)
|
||||
|
||||
if settings.get_t1s_termination_enabled(network) is not None:
|
||||
print("\n--- Termination Settings ---")
|
||||
term_enabled = get_user_confirmation("Enable Termination")
|
||||
settings.set_t1s_termination(network, term_enabled)
|
||||
|
||||
if settings.get_t1s_local_id_alternate(network) is not None:
|
||||
print("\n--- Extended Settings ---")
|
||||
local_id_alt = get_uint8_input("Local ID Alternate (0-255)", 0)
|
||||
settings.set_t1s_local_id_alternate(network, local_id_alt)
|
||||
|
||||
bus_dec_beacons = get_user_confirmation("Enable Bus Decoding (Beacons)")
|
||||
settings.set_t1s_bus_decoding_beacons(network, bus_dec_beacons)
|
||||
|
||||
bus_dec_all = get_user_confirmation("Enable Bus Decoding (All Symbols)")
|
||||
settings.set_t1s_bus_decoding_all(network, bus_dec_all)
|
||||
|
||||
if get_user_confirmation("Configure Multi-ID settings?"):
|
||||
multi_id_mask = get_uint8_input("Multi-ID Enable Mask (0x00-0xFF, hex)", 0x00)
|
||||
settings.set_t1s_multi_id_enable_mask(network, multi_id_mask)
|
||||
|
||||
print("Configure Multi-IDs (7 slots):")
|
||||
for i in range(7):
|
||||
multi_id = get_uint8_input(f" Multi-ID [{i}]", 0)
|
||||
settings.set_t1s_multi_id(network, i, multi_id)
|
||||
|
||||
if not device.set_settings(settings):
|
||||
print("✗ Failed to update device settings")
|
||||
else:
|
||||
print(f"\n✓ Configuration complete for {network}")
|
||||
|
||||
|
||||
def main():
|
||||
"""Main T1S settings configuration example."""
|
||||
device = None
|
||||
|
||||
try:
|
||||
print("\n" + "=" * 70)
|
||||
print("10BASE-T1S SETTINGS CONFIGURATION EXAMPLE")
|
||||
print("=" * 70)
|
||||
print(f"libicsneo {icsneopy.get_version()}")
|
||||
print("=" * 70)
|
||||
|
||||
print("\nFinding devices... ", end="", flush=True)
|
||||
devices = icsneopy.find_all_devices()
|
||||
print(f"OK, {len(devices)} device{'s' if len(devices) != 1 else ''} found")
|
||||
|
||||
if not devices:
|
||||
print("No devices found!")
|
||||
return 1
|
||||
|
||||
for d in devices:
|
||||
print(f" {d}")
|
||||
|
||||
device = None
|
||||
for d in devices:
|
||||
if d.get_type() == icsneopy.DeviceType.RADComet3:
|
||||
device = d
|
||||
break
|
||||
|
||||
if not device and devices:
|
||||
device = devices[0]
|
||||
|
||||
if not device:
|
||||
print("No suitable device found!")
|
||||
return 1
|
||||
|
||||
print(f"\nSelected device: {device}")
|
||||
print(f"Serial: {device.get_serial()}")
|
||||
|
||||
print("\nOpening device... ", end="", flush=True)
|
||||
if not device.open():
|
||||
print("✗ Failed")
|
||||
return 1
|
||||
print("✓")
|
||||
|
||||
candidate_networks = [
|
||||
icsneopy.Network.NetID.AE_01, icsneopy.Network.NetID.AE_02,
|
||||
icsneopy.Network.NetID.AE_03, icsneopy.Network.NetID.AE_04,
|
||||
icsneopy.Network.NetID.AE_05, icsneopy.Network.NetID.AE_06,
|
||||
icsneopy.Network.NetID.AE_07, icsneopy.Network.NetID.AE_08,
|
||||
icsneopy.Network.NetID.AE_09, icsneopy.Network.NetID.AE_10
|
||||
]
|
||||
|
||||
settings = device.get_settings()
|
||||
t1s_networks = []
|
||||
for net_id in candidate_networks:
|
||||
local_id = settings.get_t1s_local_id(net_id)
|
||||
if local_id is not None:
|
||||
t1s_networks.append(net_id)
|
||||
|
||||
if not t1s_networks:
|
||||
print("No T1S networks found on this device")
|
||||
device.close()
|
||||
return 1
|
||||
|
||||
print(f"\nFound {len(t1s_networks)} T1S network{'s' if len(t1s_networks) != 1 else ''}:")
|
||||
for i, net_id in enumerate(t1s_networks, 1):
|
||||
print(f" [{i}] {net_id}")
|
||||
|
||||
print("\n" + "-" * 70)
|
||||
print("Current T1S Settings:")
|
||||
print("-" * 70)
|
||||
for net_id in t1s_networks:
|
||||
display_t1s_settings(device, net_id)
|
||||
|
||||
networks_to_config = select_networks(t1s_networks)
|
||||
|
||||
if not networks_to_config:
|
||||
print("\nNo networks selected for configuration.")
|
||||
print("Closing device... ", end="", flush=True)
|
||||
device.close()
|
||||
print("✓")
|
||||
return 0
|
||||
|
||||
print(f"\nConfiguring {len(networks_to_config)} network{'s' if len(networks_to_config) != 1 else ''}...")
|
||||
|
||||
for net_id in networks_to_config:
|
||||
configure_t1s_network(device, net_id)
|
||||
|
||||
print("\n" + "=" * 70)
|
||||
save_to_eeprom = get_user_confirmation("Save settings to EEPROM (permanent)?")
|
||||
print("=" * 70)
|
||||
|
||||
settings = device.get_settings()
|
||||
print(f"\nApplying settings{' to EEPROM' if save_to_eeprom else ' temporarily'}... ", end="", flush=True)
|
||||
success = settings.apply(not save_to_eeprom)
|
||||
if not success:
|
||||
print("✗ Failed")
|
||||
device.close()
|
||||
return 1
|
||||
print("✓")
|
||||
|
||||
print("\n" + "-" * 70)
|
||||
print("Updated T1S Settings:")
|
||||
print("-" * 70)
|
||||
for net_id in t1s_networks:
|
||||
display_t1s_settings(device, net_id)
|
||||
|
||||
print("Closing device... ", end="", flush=True)
|
||||
device.close()
|
||||
print("✓")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n\nInterrupted by user")
|
||||
return 1
|
||||
|
||||
except Exception as e:
|
||||
print(f"\nError: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return 1
|
||||
|
||||
finally:
|
||||
if device and device.is_open():
|
||||
device.close()
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit(main())
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user