mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-09-21 16:38:39 +02:00
Compare commits
54
Commits
icsneo_api
..
1.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6926ca8199 | ||
|
|
29dc7b345f | ||
|
|
17285389e3 | ||
|
|
328563b7e6 | ||
|
|
6b60804174 | ||
|
|
c5bce795c6 | ||
|
|
1e5e714f5b | ||
|
|
d70defbf8a | ||
|
|
10efacf91e | ||
|
|
6d985ca873 | ||
|
|
19df557b4a | ||
|
|
7afa41bf2a | ||
|
|
c056e8dc2e | ||
|
|
d5ae1cdb03 | ||
|
|
5795791eac | ||
|
|
c91db6355c | ||
|
|
f37b88d616 | ||
|
|
33dea748f7 | ||
|
|
245073f9d5 | ||
|
|
c4e858d346 | ||
|
|
b3d47f2ae5 | ||
|
|
b94ade1ef6 | ||
|
|
d9ea5e085e | ||
|
|
5125520e76 | ||
|
|
4dcb944d35 | ||
|
|
7eeb1b6c38 | ||
|
|
b1e875980c | ||
|
|
8b680f2b64 | ||
|
|
e88cd244c8 | ||
|
|
70733b3d96 | ||
|
|
f743f32e63 | ||
|
|
830fe1af59 | ||
|
|
2209e348a3 | ||
|
|
52e98af9fd | ||
|
|
e1a0ca056a | ||
|
|
538d6ec0c8 | ||
|
|
1ba3eded09 | ||
|
|
89047447a6 | ||
|
|
f97fd75b8d | ||
|
|
ea5f11268c | ||
|
|
759cb2436d | ||
|
|
771d82826f | ||
|
|
b7330a2cea | ||
|
|
fb3778f91b | ||
|
|
a0c8cc62df | ||
|
|
77b3564677 | ||
|
|
051063e684 | ||
|
|
7c1cfde6a0 | ||
|
|
d4995fa2a9 | ||
|
|
fb5c4babce | ||
|
|
4ba1a1e1dd | ||
|
|
6b9a687ff9 | ||
|
|
02b5dafca9 | ||
|
|
f04cd16bee |
@@ -15,3 +15,4 @@ third-party/concurrentqueue/tests
|
||||
examples/csharp/bin
|
||||
examples/csharp/obj
|
||||
test/system
|
||||
.env
|
||||
|
||||
+66
-202
@@ -4,7 +4,6 @@ variables:
|
||||
stages:
|
||||
- build
|
||||
- unit_test
|
||||
- hardware_test
|
||||
- deploy
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -68,7 +67,7 @@ unit_test windows/x86:
|
||||
script:
|
||||
- apt update -y
|
||||
- apt upgrade -y
|
||||
- apt install -y g++ ninja-build cmake libusb-1.0-0-dev libpcap-dev git
|
||||
- apt install -y g++ ninja-build cmake libpcap-dev git
|
||||
- sh ci/build-posix.sh
|
||||
artifacts:
|
||||
when: always
|
||||
@@ -83,7 +82,7 @@ unit_test windows/x86:
|
||||
script:
|
||||
- apt update -y
|
||||
- apt upgrade -y
|
||||
- apt install -y libusb-1.0-0-dev libpcap-dev
|
||||
- apt install -y libpcap-dev
|
||||
- build/libicsneo-unit-tests
|
||||
tags:
|
||||
- linux-build
|
||||
@@ -94,7 +93,7 @@ unit_test windows/x86:
|
||||
script:
|
||||
- apt update -y
|
||||
- apt upgrade -y
|
||||
- apt install -y clang lld ninja-build cmake libusb-1.0-0-dev libpcap-dev git
|
||||
- apt install -y clang lld ninja-build cmake libpcap-dev git
|
||||
- CC=clang CXX=clang++ LDFLAGS=-fuse-ld=lld sh ci/build-posix.sh
|
||||
artifacts:
|
||||
when: always
|
||||
@@ -109,36 +108,12 @@ unit_test windows/x86:
|
||||
script:
|
||||
- apt update -y
|
||||
- apt upgrade -y
|
||||
- apt install -y libusb-1.0-0-dev libpcap-dev
|
||||
- apt install -y libpcap-dev
|
||||
- build/libicsneo-unit-tests
|
||||
tags:
|
||||
- linux-build
|
||||
timeout: 5m
|
||||
|
||||
build linux/ubuntu/2004/amd64/gcc:
|
||||
<<: *build_linux_ubuntu_gcc
|
||||
image: ubuntu:20.04
|
||||
|
||||
unit_test linux/ubuntu/2004/amd64/gcc:
|
||||
<<: *test_linux_ubuntu_gcc
|
||||
image: ubuntu:20.04
|
||||
dependencies:
|
||||
- build linux/ubuntu/2004/amd64/gcc
|
||||
needs:
|
||||
- build linux/ubuntu/2004/amd64/gcc
|
||||
|
||||
build linux/ubuntu/2004/amd64/clang:
|
||||
<<: *build_linux_ubuntu_clang
|
||||
image: ubuntu:20.04
|
||||
|
||||
unit_test linux/ubuntu/2004/amd64/clang:
|
||||
<<: *test_linux_ubuntu_clang
|
||||
image: ubuntu:20.04
|
||||
dependencies:
|
||||
- build linux/ubuntu/2004/amd64/clang
|
||||
needs:
|
||||
- build linux/ubuntu/2004/amd64/clang
|
||||
|
||||
build linux/ubuntu/2204/amd64/gcc:
|
||||
<<: *build_linux_ubuntu_gcc
|
||||
image: ubuntu:22.04
|
||||
@@ -163,6 +138,30 @@ unit_test linux/ubuntu/2204/amd64/clang:
|
||||
needs:
|
||||
- build linux/ubuntu/2204/amd64/clang
|
||||
|
||||
build linux/ubuntu/2404/amd64/gcc:
|
||||
<<: *build_linux_ubuntu_gcc
|
||||
image: ubuntu:24.04
|
||||
|
||||
unit_test linux/ubuntu/2404/amd64/gcc:
|
||||
<<: *test_linux_ubuntu_gcc
|
||||
image: ubuntu:24.04
|
||||
dependencies:
|
||||
- build linux/ubuntu/2404/amd64/gcc
|
||||
needs:
|
||||
- build linux/ubuntu/2404/amd64/gcc
|
||||
|
||||
build linux/ubuntu/2404/amd64/clang:
|
||||
<<: *build_linux_ubuntu_clang
|
||||
image: ubuntu:24.04
|
||||
|
||||
unit_test linux/ubuntu/2404/amd64/clang:
|
||||
<<: *test_linux_ubuntu_clang
|
||||
image: ubuntu:24.04
|
||||
dependencies:
|
||||
- build linux/ubuntu/2404/amd64/clang
|
||||
needs:
|
||||
- build linux/ubuntu/2404/amd64/clang
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Fedora
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -176,7 +175,7 @@ unit_test linux/ubuntu/2204/amd64/clang:
|
||||
- echo max_parallel_downloads=10 >>/etc/dnf/dnf.conf
|
||||
- echo fastestmirror=True >>/etc/dnf/dnf.conf
|
||||
- dnf upgrade -y
|
||||
- dnf install -y g++ libpcap-devel cmake ninja-build libusb1-devel git
|
||||
- dnf install -y g++ libpcap-devel cmake ninja-build git
|
||||
- sh ci/build-posix.sh
|
||||
artifacts:
|
||||
when: always
|
||||
@@ -195,7 +194,7 @@ unit_test linux/ubuntu/2204/amd64/clang:
|
||||
- echo max_parallel_downloads=10 >>/etc/dnf/dnf.conf
|
||||
- echo fastestmirror=True >>/etc/dnf/dnf.conf
|
||||
- dnf upgrade -y
|
||||
- dnf install -y libpcap-devel libusb1-devel
|
||||
- dnf install -y libpcap-devel
|
||||
- build/libicsneo-unit-tests
|
||||
tags:
|
||||
- linux-build
|
||||
@@ -210,7 +209,7 @@ unit_test linux/ubuntu/2204/amd64/clang:
|
||||
- echo max_parallel_downloads=10 >>/etc/dnf/dnf.conf
|
||||
- echo fastestmirror=True >>/etc/dnf/dnf.conf
|
||||
- dnf upgrade -y
|
||||
- dnf install -y clang lld libpcap-devel cmake ninja-build libusb1-devel git
|
||||
- dnf install -y clang lld libpcap-devel cmake ninja-build git
|
||||
- CC=clang CXX=clang++ LDFLAGS=-fuse-ld=lld sh ci/build-posix.sh
|
||||
artifacts:
|
||||
when: always
|
||||
@@ -229,196 +228,59 @@ unit_test linux/ubuntu/2204/amd64/clang:
|
||||
- echo max_parallel_downloads=10 >>/etc/dnf/dnf.conf
|
||||
- echo fastestmirror=True >>/etc/dnf/dnf.conf
|
||||
- dnf upgrade -y
|
||||
- dnf install -y libpcap-devel libusb1-devel
|
||||
- dnf install -y libpcap-devel
|
||||
- build/libicsneo-unit-tests
|
||||
tags:
|
||||
- linux-build
|
||||
timeout: 5m
|
||||
|
||||
build linux/fedora/37/amd64/gcc:
|
||||
build linux/fedora/41/amd64/gcc:
|
||||
<<: *build_linux_fedora_gcc
|
||||
image: fedora:37
|
||||
image: fedora:41
|
||||
|
||||
unit_test linux/fedora/37/amd64/gcc:
|
||||
unit_test linux/fedora/41/amd64/gcc:
|
||||
<<: *test_linux_fedora_gcc
|
||||
image: fedora:37
|
||||
image: fedora:41
|
||||
dependencies:
|
||||
- build linux/fedora/37/amd64/gcc
|
||||
- build linux/fedora/41/amd64/gcc
|
||||
needs:
|
||||
- build linux/fedora/37/amd64/gcc
|
||||
- build linux/fedora/41/amd64/gcc
|
||||
|
||||
build linux/fedora/37/amd64/clang:
|
||||
build linux/fedora/41/amd64/clang:
|
||||
<<: *build_linux_fedora_clang
|
||||
image: fedora:37
|
||||
image: fedora:41
|
||||
|
||||
unit_test linux/fedora/37/amd64/clang:
|
||||
unit_test linux/fedora/41/amd64/clang:
|
||||
<<: *test_linux_fedora_clang
|
||||
image: fedora:37
|
||||
image: fedora:41
|
||||
dependencies:
|
||||
- build linux/fedora/37/amd64/clang
|
||||
- build linux/fedora/41/amd64/clang
|
||||
needs:
|
||||
- build linux/fedora/37/amd64/clang
|
||||
- build linux/fedora/41/amd64/clang
|
||||
|
||||
build linux/fedora/38/amd64/gcc:
|
||||
build linux/fedora/42/amd64/gcc:
|
||||
<<: *build_linux_fedora_gcc
|
||||
image: fedora:38
|
||||
image: fedora:42
|
||||
|
||||
unit_test linux/fedora/38/amd64/gcc:
|
||||
unit_test linux/fedora/42/amd64/gcc:
|
||||
<<: *test_linux_fedora_gcc
|
||||
image: fedora:38
|
||||
image: fedora:42
|
||||
dependencies:
|
||||
- build linux/fedora/38/amd64/gcc
|
||||
- build linux/fedora/42/amd64/gcc
|
||||
needs:
|
||||
- build linux/fedora/38/amd64/gcc
|
||||
- build linux/fedora/42/amd64/gcc
|
||||
|
||||
build linux/fedora/38/amd64/clang:
|
||||
build linux/fedora/42/amd64/clang:
|
||||
<<: *build_linux_fedora_clang
|
||||
image: fedora:38
|
||||
image: fedora:42
|
||||
|
||||
unit_test linux/fedora/38/amd64/clang:
|
||||
unit_test linux/fedora/42/amd64/clang:
|
||||
<<: *test_linux_fedora_clang
|
||||
image: fedora:38
|
||||
image: fedora:42
|
||||
dependencies:
|
||||
- build linux/fedora/38/amd64/clang
|
||||
- build linux/fedora/42/amd64/clang
|
||||
needs:
|
||||
- build linux/fedora/38/amd64/clang
|
||||
|
||||
build linux/fedora/39/amd64/gcc:
|
||||
<<: *build_linux_fedora_gcc
|
||||
image: fedora:39
|
||||
|
||||
unit_test linux/fedora/39/amd64/gcc:
|
||||
<<: *test_linux_fedora_gcc
|
||||
image: fedora:39
|
||||
dependencies:
|
||||
- build linux/fedora/39/amd64/gcc
|
||||
needs:
|
||||
- build linux/fedora/39/amd64/gcc
|
||||
|
||||
build linux/fedora/39/amd64/clang:
|
||||
<<: *build_linux_fedora_clang
|
||||
image: fedora:39
|
||||
|
||||
unit_test linux/fedora/39/amd64/clang:
|
||||
<<: *test_linux_fedora_clang
|
||||
image: fedora:39
|
||||
dependencies:
|
||||
- build linux/fedora/39/amd64/clang
|
||||
needs:
|
||||
- build linux/fedora/39/amd64/clang
|
||||
|
||||
.hw_test: &hw_test
|
||||
stage: hardware_test
|
||||
tags:
|
||||
- libicsneo_hil
|
||||
timeout: 5m
|
||||
script:
|
||||
- echo $GUEST_OS_TAG
|
||||
- echo $DEVICE_PORT
|
||||
- /opt/libvirt-driver/prepare.sh
|
||||
- /opt/libvirt-driver/run.sh
|
||||
after_script:
|
||||
- /opt/libvirt-driver/cleanup.sh
|
||||
allow_failure: true
|
||||
|
||||
.fedora38_needs: &fedora38_needs
|
||||
needs:
|
||||
- job: build linux/fedora/38/amd64/clang
|
||||
artifacts: true
|
||||
|
||||
hardware_test fedora38-red2:
|
||||
<<: *hw_test
|
||||
<<: *fedora38_needs
|
||||
variables:
|
||||
GUEST_OS_TAG: fedora38
|
||||
DEVICE_PORT: ETH_A
|
||||
|
||||
hardware_test fedora38-vcan42:
|
||||
<<: *hw_test
|
||||
<<: *fedora38_needs
|
||||
variables:
|
||||
GUEST_OS_TAG: fedora38
|
||||
DEVICE_PORT: USB_D
|
||||
|
||||
hardware_test fedora38-fire3:
|
||||
<<: *hw_test
|
||||
<<: *fedora38_needs
|
||||
variables:
|
||||
GUEST_OS_TAG: fedora38
|
||||
DEVICE_PORT: ETH_B
|
||||
|
||||
hardware_test fedora38-vcan42-EL:
|
||||
<<: *hw_test
|
||||
<<: *fedora38_needs
|
||||
variables:
|
||||
GUEST_OS_TAG: fedora38
|
||||
DEVICE_PORT: USB_C
|
||||
|
||||
.ubuntu2204_needs: &ubuntu2204_needs
|
||||
needs:
|
||||
- job: build linux/ubuntu/2204/amd64/clang
|
||||
artifacts: true
|
||||
|
||||
hardware_test ubuntu2204-red2:
|
||||
<<: *hw_test
|
||||
<<: *ubuntu2204_needs
|
||||
variables:
|
||||
GUEST_OS_TAG: ubuntu22.04
|
||||
DEVICE_PORT: ETH_A
|
||||
|
||||
hardware_test ubuntu2204-vcan42:
|
||||
<<: *hw_test
|
||||
<<: *ubuntu2204_needs
|
||||
variables:
|
||||
GUEST_OS_TAG: ubuntu22.04
|
||||
DEVICE_PORT: USB_D
|
||||
|
||||
hardware_test ubuntu2204-fire3:
|
||||
<<: *hw_test
|
||||
<<: *ubuntu2204_needs
|
||||
variables:
|
||||
GUEST_OS_TAG: ubuntu22.04
|
||||
DEVICE_PORT: ETH_B
|
||||
|
||||
hardware_test ubuntu2204-vcan42-EL:
|
||||
<<: *hw_test
|
||||
<<: *ubuntu2204_needs
|
||||
variables:
|
||||
GUEST_OS_TAG: ubuntu22.04
|
||||
DEVICE_PORT: USB_C
|
||||
|
||||
.win10_needs: &win10_needs
|
||||
needs:
|
||||
- job: build windows/x64
|
||||
artifacts: true
|
||||
|
||||
hardware_test win10-red2:
|
||||
<<: *hw_test
|
||||
<<: *win10_needs
|
||||
variables:
|
||||
GUEST_OS_TAG: win10
|
||||
DEVICE_PORT: ETH_A
|
||||
|
||||
hardware_test win10-vcan42:
|
||||
<<: *hw_test
|
||||
<<: *win10_needs
|
||||
variables:
|
||||
GUEST_OS_TAG: win10
|
||||
DEVICE_PORT: USB_D
|
||||
|
||||
hardware_test win10-fire3:
|
||||
<<: *hw_test
|
||||
<<: *win10_needs
|
||||
variables:
|
||||
GUEST_OS_TAG: win10
|
||||
DEVICE_PORT: ETH_B
|
||||
|
||||
hardware_test win10-vcan42-EL:
|
||||
<<: *hw_test
|
||||
<<: *win10_needs
|
||||
variables:
|
||||
GUEST_OS_TAG: win10
|
||||
DEVICE_PORT: USB_C
|
||||
- build linux/fedora/42/amd64/clang
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Python Module
|
||||
@@ -428,19 +290,19 @@ build python/linux/amd64:
|
||||
stage: build
|
||||
tags:
|
||||
- linux-build
|
||||
image: python:3.12
|
||||
image: python:3.13
|
||||
services:
|
||||
- name: docker:dind
|
||||
entrypoint: ["env", "-u", "DOCKER_HOST"]
|
||||
command: ["dockerd-entrypoint.sh"]
|
||||
variables:
|
||||
CIBW_BEFORE_ALL: yum install -y flex && sh ci/bootstrap-libpcap.sh && sh ci/bootstrap-libusb.sh
|
||||
CIBW_BEFORE_ALL: yum install -y flex && sh ci/bootstrap-libpcap.sh
|
||||
CIBW_BUILD: "*manylinux*" # no musl
|
||||
CIBW_ARCHS: x86_64
|
||||
DOCKER_HOST: unix:///var/run/docker.sock
|
||||
DOCKER_DRIVER: overlay2
|
||||
DOCKER_TLS_CERTDIR: ""
|
||||
CIBW_ENVIRONMENT: CMAKE_PREFIX_PATH=/project/libpcap/install:/project/libusb/install
|
||||
CIBW_ENVIRONMENT: CMAKE_PREFIX_PATH=/project/libpcap/install
|
||||
script:
|
||||
- curl -sSL https://get.docker.com/ | sh
|
||||
- sh ci/build-wheel-posix.sh
|
||||
@@ -453,10 +315,10 @@ build python/linux/arm64:
|
||||
tags:
|
||||
- arm64-linux-build
|
||||
variables:
|
||||
CIBW_BEFORE_ALL: yum install -y flex && sh ci/bootstrap-libpcap.sh && sh ci/bootstrap-libusb.sh
|
||||
CIBW_BEFORE_ALL: yum install -y flex && sh ci/bootstrap-libpcap.sh
|
||||
CIBW_BUILD: "*manylinux*" # no musl
|
||||
CIBW_ARCHS: aarch64
|
||||
CIBW_ENVIRONMENT: CMAKE_PREFIX_PATH=/project/libpcap/install:/project/libusb/install
|
||||
CIBW_ENVIRONMENT: CMAKE_PREFIX_PATH=/project/libpcap/install
|
||||
script:
|
||||
- sh ci/build-wheel-posix.sh
|
||||
artifacts:
|
||||
@@ -468,9 +330,9 @@ build python/macos:
|
||||
tags:
|
||||
- macos-arm64
|
||||
variables:
|
||||
CIBW_BEFORE_ALL: sh ci/bootstrap-libpcap.sh && sh ci/bootstrap-libusb.sh
|
||||
CIBW_BEFORE_ALL: sh ci/bootstrap-libpcap.sh
|
||||
CIBW_ARCHS: arm64
|
||||
CIBW_ENVIRONMENT: CMAKE_PREFIX_PATH=$CI_PROJECT_DIR/libpcap/install:$CI_PROJECT_DIR/libusb/install
|
||||
CIBW_ENVIRONMENT: CMAKE_PREFIX_PATH=$CI_PROJECT_DIR/libpcap/install
|
||||
MACOSX_DEPLOYMENT_TARGET: 10.14
|
||||
script:
|
||||
- sh ci/build-wheel-posix.sh
|
||||
@@ -498,7 +360,7 @@ deploy python/pypi:
|
||||
TWINE_PASSWORD: $PYPI_TOKEN
|
||||
tags:
|
||||
- linux-build
|
||||
image: python:3.12
|
||||
image: python:3.13
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
||||
script:
|
||||
@@ -522,6 +384,8 @@ push github:
|
||||
image: alpine:latest
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
||||
when: delayed
|
||||
start_in: 10 minutes
|
||||
dependencies:
|
||||
- deploy python/pypi
|
||||
needs:
|
||||
|
||||
+35
-154
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(libicsneo VERSION 0.3.0)
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(libicsneo VERSION 1.0.0)
|
||||
|
||||
cmake_policy(SET CMP0074 NEW)
|
||||
if(POLICY CMP0135)
|
||||
@@ -7,13 +7,10 @@ if(POLICY CMP0135)
|
||||
endif()
|
||||
|
||||
option(LIBICSNEO_BUILD_UNIT_TESTS "Build unit tests." OFF)
|
||||
option(LIBICSNEO_BUILD_SYSTEM_TESTS "Build system tests." OFF)
|
||||
option(LIBICSNEO_BUILD_DOCS "Build documentation. Don't use in Visual Studio." OFF)
|
||||
option(LIBICSNEO_BUILD_EXAMPLES "Build examples." ON)
|
||||
option(LIBICSNEO_BUILD_ICSNEOC "Build dynamic C library" ON)
|
||||
option(LIBICSNEO_BUILD_ICSNEOC_STATIC "Build static C library" ON)
|
||||
option(LIBICSNEO_BUILD_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")
|
||||
@@ -25,12 +22,10 @@ set(LIBICSNEO_NPCAP_INCLUDE_DIR "" CACHE STRING "Npcap include directory; set to
|
||||
option(LIBICSNEO_ENABLE_FIRMIO "Enable communication between Linux and CoreMini within the same device" OFF)
|
||||
option(LIBICSNEO_ENABLE_RAW_ETHERNET "Enable devices which communicate over raw ethernet" ON)
|
||||
option(LIBICSNEO_ENABLE_CDCACM "Enable devices which communicate over USB CDC ACM" ON)
|
||||
option(LIBICSNEO_ENABLE_FTDI "Enable devices which communicate over USB FTDI2XX" ON)
|
||||
option(LIBICSNEO_ENABLE_TCP "Enable devices which communicate over TCP" OFF)
|
||||
option(LIBICSNEO_ENABLE_FTD3XX "Enable devices which communicate over USB FTD3XX" ON)
|
||||
option(LIBICSNEO_ENABLE_DXX "Enable devices which communicate over D2XX/D3XX via libredxx" ON)
|
||||
|
||||
option(LIBICSNEO_ENABLE_BINDINGS_PYTHON "Enable Python library" OFF)
|
||||
option(LIBICSNEO_ENABLE_BINDINGS_RUST "Enable Rust library" OFF)
|
||||
|
||||
if(NOT CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
@@ -114,6 +109,7 @@ endif()
|
||||
|
||||
if(WIN32)
|
||||
set(PLATFORM_SRC
|
||||
platform/windows/strings.cpp
|
||||
platform/windows/registry.cpp
|
||||
)
|
||||
|
||||
@@ -124,9 +120,9 @@ if(WIN32)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_ENABLE_CDCACM OR LIBICSNEO_ENABLE_FTDI)
|
||||
if(LIBICSNEO_ENABLE_CDCACM)
|
||||
list(APPEND PLATFORM_SRC
|
||||
platform/windows/vcp.cpp
|
||||
platform/windows/cdcacm.cpp
|
||||
)
|
||||
endif()
|
||||
else() # Darwin or Linux
|
||||
@@ -144,12 +140,6 @@ else() # Darwin or Linux
|
||||
)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_ENABLE_FTDI)
|
||||
list(APPEND PLATFORM_SRC
|
||||
platform/posix/ftdi.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_ENABLE_CDCACM)
|
||||
list(APPEND PLATFORM_SRC
|
||||
platform/posix/cdcacm.cpp
|
||||
@@ -173,51 +163,9 @@ else() # Darwin or Linux
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_ENABLE_FTD3XX)
|
||||
if(NOT FTD3XX_ROOT) # allow system override
|
||||
include(FetchContent)
|
||||
if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(LIBICSNEO_FTD3XX_URL "https://github.com/intrepidcs/libftd3xx-repack/releases/download/24.34.0/libftd3xx-1.3.0.10-win-x64.zip")
|
||||
set(LIBICSNEO_FTD3XX_URL_HASH "SHA256=459e635496ab47d6069c9d3515fdd6d82cba3d95e7ae34f794d66ffdf336e9d1")
|
||||
elseif(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
set(LIBICSNEO_FTD3XX_URL "https://github.com/intrepidcs/libftd3xx-repack/releases/download/24.34.0/libftd3xx-1.3.0.10-win-i686.zip")
|
||||
set(LIBICSNEO_FTD3XX_URL_HASH "SHA256=ce4259ae11772d6ede7d217172156fa392f329b29d9455131f4126a2fb89dad1")
|
||||
elseif(APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(LIBICSNEO_FTD3XX_URL "https://github.com/intrepidcs/libftd3xx-repack/releases/download/24.34.0/libftd3xx-1.0.16-macos-universal2.zip")
|
||||
set(LIBICSNEO_FTD3XX_URL_HASH "SHA256=0904ac5eda8e1dc4b5aac3714383bcc7792b42dfeb585dce6cbfb8b67b8c0c51")
|
||||
elseif(UNIX)
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(LIBICSNEO_FTD3XX_URL "https://github.com/intrepidcs/libftd3xx-repack/releases/download/24.34.0/libftd3xx-1.0.16-linux-x64.zip")
|
||||
set(LIBICSNEO_FTD3XX_URL_HASH "SHA256=cf66bf299fc722f050cdd3c36998a670f1df69f7c0df18afa73707277067114b")
|
||||
endif()
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*|aarch64")
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(LIBICSNEO_FTD3XX_URL "https://github.com/intrepidcs/libftd3xx-repack/releases/download/24.34.0/libftd3xx-1.0.16-linux-aarch64.zip")
|
||||
set(LIBICSNEO_FTD3XX_URL_HASH "SHA256=66341b5112b9841e959e81400b51711be96fec91894477c5cbfc29b10a0c00a6")
|
||||
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
set(LIBICSNEO_FTD3XX_URL "https://github.com/intrepidcs/libftd3xx-repack/releases/download/24.34.0/libftd3xx-1.0.16-linux-armhf.zip")
|
||||
set(LIBICSNEO_FTD3XX_URL_HASH "SHA256=cec1f959b48a11eb6b829ed43c81b6ba1c0bcf3e797bafcc84a6376e5ffc3c47")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
if(NOT LIBICSNEO_FTD3XX_URL)
|
||||
message(FATAL_ERROR "Unsupported platform for FTD3XX driver")
|
||||
endif()
|
||||
FetchContent_Declare(
|
||||
ftdi3xx
|
||||
URL ${LIBICSNEO_FTD3XX_URL}
|
||||
URL_HASH ${LIBICSNEO_FTD3XX_URL_HASH}
|
||||
)
|
||||
FetchContent_GetProperties(ftdi3xx)
|
||||
if(NOT ftdi3xx_POPULATED)
|
||||
FetchContent_Populate(ftdi3xx)
|
||||
endif()
|
||||
set(FTD3XX_ROOT "${ftdi3xx_SOURCE_DIR}")
|
||||
endif()
|
||||
find_package(FTD3XX REQUIRED)
|
||||
if(LIBICSNEO_ENABLE_DXX)
|
||||
list(APPEND PLATFORM_SRC
|
||||
platform/ftd3xx.cpp
|
||||
platform/dxx.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -248,9 +196,11 @@ set(SRC_FILES
|
||||
communication/message/ethphymessage.cpp
|
||||
communication/message/linmessage.cpp
|
||||
communication/message/livedatamessage.cpp
|
||||
communication/message/logdatamessage.cpp
|
||||
communication/message/tc10statusmessage.cpp
|
||||
communication/message/gptpstatusmessage.cpp
|
||||
communication/message/ethernetstatusmessage.cpp
|
||||
communication/message/macsecmessage.cpp
|
||||
communication/packet/flexraypacket.cpp
|
||||
communication/packet/canpacket.cpp
|
||||
communication/packet/a2bpacket.cpp
|
||||
@@ -278,6 +228,7 @@ set(SRC_FILES
|
||||
communication/driver.cpp
|
||||
communication/livedata.cpp
|
||||
communication/ringbuffer.cpp
|
||||
communication/crc32.cpp
|
||||
device/extensions/flexray/extension.cpp
|
||||
device/extensions/flexray/controller.cpp
|
||||
device/idevicesettings.cpp
|
||||
@@ -291,6 +242,7 @@ set(SRC_FILES
|
||||
disk/plasiondiskreaddriver.cpp
|
||||
disk/extextractordiskreaddriver.cpp
|
||||
disk/fat.cpp
|
||||
disk/diskdetails.cpp
|
||||
disk/vsa/vsa.cpp
|
||||
disk/vsa/vsa02.cpp
|
||||
disk/vsa/vsa03.cpp
|
||||
@@ -307,6 +259,7 @@ set(SRC_FILES
|
||||
disk/vsa/vsa0f.cpp
|
||||
disk/vsa/vsa6a.cpp
|
||||
disk/vsa/vsaparser.cpp
|
||||
platform/servd.cpp
|
||||
${PLATFORM_SRC}
|
||||
)
|
||||
|
||||
@@ -337,7 +290,6 @@ 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})
|
||||
@@ -368,7 +320,7 @@ target_include_directories(icsneocpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${LIBICSNEO_EXTENSION_INCLUDE_PATHS}
|
||||
)
|
||||
target_link_libraries(icsneocpp PUBLIC Threads::Threads)
|
||||
target_link_libraries(icsneocpp PUBLIC Threads::Threads $<$<BOOL:${WIN32}>:ws2_32 iphlpapi>)
|
||||
set_property(TARGET icsneocpp PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
target_compile_features(icsneocpp PUBLIC cxx_auto_type cxx_constexpr cxx_lambdas cxx_nullptr cxx_range_for cxx_rvalue_references cxx_sizeof_member cxx_strong_enums)
|
||||
message("Loaded extensions: " ${LIBICSNEO_EXTENSION_TARGETS})
|
||||
@@ -382,12 +334,9 @@ endif()
|
||||
if(LIBICSNEO_ENABLE_CDCACM)
|
||||
target_compile_definitions(icsneocpp PRIVATE ICSNEO_ENABLE_CDCACM)
|
||||
endif()
|
||||
if(LIBICSNEO_ENABLE_FTDI)
|
||||
target_compile_definitions(icsneocpp PRIVATE ICSNEO_ENABLE_FTDI)
|
||||
endif()
|
||||
if(LIBICSNEO_ENABLE_FTD3XX)
|
||||
target_compile_definitions(icsneocpp PRIVATE ICSNEO_ENABLE_FTD3XX)
|
||||
target_link_libraries(icsneocpp PRIVATE FTD3XX::FTD3XX)
|
||||
if(LIBICSNEO_ENABLE_DXX)
|
||||
target_compile_definitions(icsneocpp PRIVATE ICSNEO_ENABLE_DXX)
|
||||
target_link_libraries(icsneocpp PRIVATE libredxx::libredxx)
|
||||
endif()
|
||||
if(LIBICSNEO_ENABLE_TCP)
|
||||
target_compile_definitions(icsneocpp PRIVATE ICSNEO_ENABLE_TCP)
|
||||
@@ -401,35 +350,24 @@ add_subdirectory(third-party/fatfs)
|
||||
set_property(TARGET fatfs PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
target_link_libraries(icsneocpp PRIVATE fatfs)
|
||||
|
||||
# libftdi
|
||||
if(LIBICSNEO_ENABLE_FTDI)
|
||||
if(NOT WIN32)
|
||||
target_include_directories(icsneocpp PUBLIC third-party/libftdi/src)
|
||||
set(LIBFTDI_DOCUMENTATION OFF CACHE INTERNAL "")
|
||||
set(LIBFTDI_BUILD_TESTS OFF CACHE INTERNAL "")
|
||||
set(LIBFTDI_INSTALL OFF CACHE INTERNAL "")
|
||||
set(LIBFTDI_PYTHON_BINDINGS OFF CACHE INTERNAL "")
|
||||
set(LIBFTDI_LINK_PYTHON_LIBRARY OFF CACHE INTERNAL "")
|
||||
set(FTDIPP OFF CACHE INTERNAL "")
|
||||
set(FTDI_EEPROM OFF CACHE INTERNAL "")
|
||||
add_subdirectory(third-party/libftdi)
|
||||
target_include_directories(icsneocpp PRIVATE ${LIBUSB_INCLUDE_DIR})
|
||||
|
||||
set_property(TARGET ftdi1-static PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
target_link_libraries(icsneocpp PUBLIC ftdi1-static)
|
||||
target_link_libraries(icsneocpp PUBLIC ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif(NOT WIN32)
|
||||
endif(LIBICSNEO_ENABLE_FTDI)
|
||||
# dxx
|
||||
if(LIBICSNEO_ENABLE_DXX)
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(libredxx
|
||||
GIT_REPOSITORY https://github.com/Zeranoe/libredxx.git
|
||||
GIT_TAG 2b7932fe7f2fc006ef269c7a72595f3940178a10
|
||||
)
|
||||
FetchContent_MakeAvailable(libredxx)
|
||||
endif()
|
||||
|
||||
# pcap
|
||||
if(LIBICSNEO_ENABLE_RAW_ETHERNET)
|
||||
if(WIN32)
|
||||
if(LIBICSNEO_NPCAP_INCLUDE_DIR STREQUAL "")
|
||||
target_include_directories(icsneocpp PUBLIC AFTER third-party/winpcap/include)
|
||||
add_definitions(-DWPCAP -DHAVE_REMOTE -DWIN32_LEAN_AND_MEAN)
|
||||
add_definitions(-DWPCAP -DHAVE_REMOTE)
|
||||
else()
|
||||
target_include_directories(icsneocpp PUBLIC AFTER ${LIBICSNEO_NPCAP_INCLUDE_DIR})
|
||||
add_definitions(-DNPCAP -DWIN32_LEAN_AND_MEAN)
|
||||
endif()
|
||||
else()
|
||||
find_package(PCAP REQUIRED)
|
||||
@@ -465,42 +403,6 @@ if(LIBICSNEO_BUILD_ICSNEOC_STATIC)
|
||||
target_compile_definitions(icsneoc-static PUBLIC ICSNEOC_BUILD_STATIC)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_ICSNEOC2)
|
||||
add_library(icsneoc2 SHARED api/icsneoc2/icsneoc2.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_definitions(icsneoc2
|
||||
PRIVATE
|
||||
ICSNEO_EXPORTS _CRT_SECURE_NO_WARNINGS
|
||||
PUBLIC
|
||||
ICSNEO_IMPORTS _CRT_SECURE_NO_WARNINGS
|
||||
INTERFACE
|
||||
ICSNEO_IMPORTS _CRT_SECURE_NO_WARNINGS
|
||||
)
|
||||
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_definitions(icsneoc2 PUBLIC ICSNEOC2_BUILD_DYNAMIC)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_ICSNEOC2_STATIC)
|
||||
add_library(icsneoc2-static STATIC api/icsneoc2/icsneoc2.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)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_ICSNEOLEGACY)
|
||||
add_library(icsneolegacy SHARED
|
||||
api/icsneolegacy/icsneolegacy.cpp
|
||||
@@ -542,17 +444,12 @@ add_subdirectory(bindings)
|
||||
|
||||
# googletest
|
||||
if(LIBICSNEO_BUILD_UNIT_TESTS)
|
||||
if(WIN32)
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
|
||||
if (NOT TARGET gtest)
|
||||
add_subdirectory(third-party/googletest-master)
|
||||
endif()
|
||||
|
||||
if (CMAKE_VERSION VERSION_LESS 2.8.11)
|
||||
include_directories("${gtest_SOURCE_DIR}/include")
|
||||
endif()
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(googletest
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
GIT_TAG 6986c2b575f77135401a4e1c65a7a42f20e18fef
|
||||
)
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
|
||||
add_executable(libicsneo-unit-tests
|
||||
test/unit/main.cpp
|
||||
@@ -567,12 +464,12 @@ 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
|
||||
)
|
||||
|
||||
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})
|
||||
|
||||
@@ -581,22 +478,6 @@ if(LIBICSNEO_BUILD_UNIT_TESTS)
|
||||
add_test(NAME libicsneo-unit-test-suite COMMAND libicsneo-unit-tests)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_SYSTEM_TESTS)
|
||||
if(DEFINED ENV{LIBICSNEO_SYSTEM_TESTS})
|
||||
include(FetchContent)
|
||||
file(MAKE_DIRECTORY test/system)
|
||||
FetchContent_Declare(
|
||||
SystemTests
|
||||
GIT_REPOSITORY $ENV{LIBICSNEO_SYSTEM_TESTS}
|
||||
GIT_TAG main
|
||||
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test/system
|
||||
)
|
||||
FetchContent_MakeAvailable(SystemTests)
|
||||
else()
|
||||
message("System test repo not defined!")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||||
include(CPack)
|
||||
@@ -23,6 +23,8 @@ each of the respective APIs.
|
||||
- RAD-A2B
|
||||
- RAD-Comet 2
|
||||
- RAD-Comet 3
|
||||
- RAD-Epsilon
|
||||
- RAD-EpsilonXL
|
||||
- RAD-Galaxy
|
||||
- RAD-Galaxy 2
|
||||
- RAD-Gigastar
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#include "icsneo/icsneo.h"
|
||||
#include "icsneo/icsneocpp.h"
|
||||
#include "icsneo/device/devicefinder.h"
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
struct icsneoOpenOptions_t {
|
||||
/** Open the device in online mode on open. */
|
||||
bool goOnlineOnOpen = true;
|
||||
/** Enable message polling on open. */
|
||||
bool enablePollingOnOpen = true;
|
||||
/** Synchronize the device RTC on open.
|
||||
* Useful for devices that don't have an RTC battery like ValueCAN4 */
|
||||
bool syncRTCOnOpen = true;
|
||||
};
|
||||
|
||||
typedef struct icsneo_device_t {
|
||||
// This is the actual device handle, when its not open it will be NULL.
|
||||
std::shared_ptr<Device> device;
|
||||
|
||||
icsneoOpenOptions_t openOptions;
|
||||
} *icsneo_device_ptr_t;
|
||||
|
||||
icsneo_result_t icsneo_find(icsneo_device_ptr_t* devices, uint32_t* devices_count, void* reserved) {
|
||||
static std::deque<icsneo_device_t> found_icsneo_devices;
|
||||
if (!devices || !devices_count) {
|
||||
return icsneo_error_invalid_parameter;
|
||||
}
|
||||
|
||||
// Find all devices and get the minimum size to process
|
||||
auto found_devices = DeviceFinder::FindAll();
|
||||
auto min_size = std::minmax(found_devices.size(), static_cast<size_t>(*devices_count)).first;
|
||||
// lets resize the array to the minimum size
|
||||
for (auto i = 0; i < min_size; i++) {
|
||||
const auto* dev = devices[i];
|
||||
dev = new icsneo_device_t {};
|
||||
dev->device = found_devices[i];
|
||||
}
|
||||
|
||||
|
||||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
icsneo_result_t icsneo_open(icsneo_device_ptr_t* device) {
|
||||
if (!device) {
|
||||
return icsneo_error_invalid_parameter;
|
||||
}
|
||||
|
||||
|
||||
return icsneo_error_success;
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
#define VER_FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@
|
||||
#define VER_FILEVERSION_STR "v@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@@BUILD_METADATA_PLUS@ @BUILD_GIT_INFO@"
|
||||
|
||||
#define VER_PRODUCTVERSION VER_FILEVERSION
|
||||
#define VER_PRODUCTVERSION_STR VER_FILEVERSION_STR
|
||||
|
||||
#ifndef DEBUG
|
||||
#define VER_DEBUG 0
|
||||
#else
|
||||
#define VER_DEBUG VS_FF_DEBUG
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION VER_FILEVERSION
|
||||
PRODUCTVERSION VER_PRODUCTVERSION
|
||||
FILEFLAGSMASK (VS_FF_DEBUG)
|
||||
FILEFLAGS (VER_DEBUG)
|
||||
FILEOS VOS__WINDOWS32
|
||||
FILETYPE VFT_DLL
|
||||
FILESUBTYPE VFT2_UNKNOWN
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904E4"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Intrepid Control Systems, Inc."
|
||||
VALUE "FileDescription", "Intrepid Control Systems Open Device Communication C API"
|
||||
VALUE "FileVersion", VER_FILEVERSION_STR
|
||||
VALUE "InternalName", "icsneo.dll"
|
||||
VALUE "LegalCopyright", "Intrepid Control Systems, Inc. (C) 2018-2024"
|
||||
VALUE "OriginalFilename", "icsneo.dll"
|
||||
VALUE "ProductName", "libicsneo"
|
||||
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
|
||||
END
|
||||
END
|
||||
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
/* The following line should only be modified for localized versions. */
|
||||
/* It consists of any number of WORD,WORD pairs, with each pair */
|
||||
/* describing a language,codepage combination supported by the file. */
|
||||
/* */
|
||||
/* For example, a file might have values "0x409,1252" indicating that it */
|
||||
/* supports English language (0x409) in the Windows ANSI codepage (1252). */
|
||||
|
||||
VALUE "Translation", 0x409, 1252
|
||||
|
||||
END
|
||||
END
|
||||
+32
-2
@@ -462,7 +462,7 @@ bool icsneo_transmit(const neodevice_t* device, const neomessage_t* message) {
|
||||
if(!icsneo_isValidNeoDevice(device))
|
||||
return false;
|
||||
|
||||
if(auto frame = std::dynamic_pointer_cast<icsneo::BusMessage>(CreateMessageFromNeoMessage(message)))
|
||||
if(auto frame = std::dynamic_pointer_cast<icsneo::Frame>(CreateMessageFromNeoMessage(message)))
|
||||
return device->device->transmit(frame);
|
||||
|
||||
return false;
|
||||
@@ -738,7 +738,7 @@ int icsneo_getDeviceStatus(const neodevice_t* device, void* status, size_t* size
|
||||
if(!msg) // Did not receive a message
|
||||
return false;
|
||||
|
||||
auto rawMessage = std::static_pointer_cast<InternalMessage>(msg);
|
||||
auto rawMessage = std::static_pointer_cast<RawMessage>(msg);
|
||||
if(!rawMessage || (rawMessage->network.getNetID() != Network::NetID::DeviceStatus))
|
||||
return false;
|
||||
|
||||
@@ -757,3 +757,33 @@ bool icsneo_isOnlineSupported(const neodevice_t* device) {
|
||||
|
||||
return device->device->isOnlineSupported();
|
||||
}
|
||||
|
||||
bool icsneo_requestTC10Wake(const neodevice_t* device, neonetid_t netid) {
|
||||
if(!icsneo_isValidNeoDevice(device))
|
||||
return false;
|
||||
|
||||
return device->device->requestTC10Wake((Network::NetID)netid);
|
||||
}
|
||||
|
||||
bool icsneo_requestTC10Sleep(const neodevice_t* device, neonetid_t netid) {
|
||||
if(!icsneo_isValidNeoDevice(device))
|
||||
return false;
|
||||
|
||||
return device->device->requestTC10Sleep((Network::NetID)netid);
|
||||
}
|
||||
|
||||
bool icsneo_getTC10Status(const neodevice_t* device, neonetid_t netid, neotc10status_t* status) {
|
||||
if(!icsneo_isValidNeoDevice(device))
|
||||
return false;
|
||||
|
||||
const auto statusMsg = device->device->getTC10Status((Network::NetID)netid);
|
||||
|
||||
if(!statusMsg)
|
||||
return false;
|
||||
|
||||
status->wakeStatus = (neotc10wakestatus_t)statusMsg->wakeStatus;
|
||||
status->sleepStatus = (neotc10sleepstatus_t)statusMsg->sleepStatus;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,51 +0,0 @@
|
||||
#define VER_FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@
|
||||
#define VER_FILEVERSION_STR "v@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@@BUILD_METADATA_PLUS@ @BUILD_GIT_INFO@"
|
||||
|
||||
#define VER_PRODUCTVERSION VER_FILEVERSION
|
||||
#define VER_PRODUCTVERSION_STR VER_FILEVERSION_STR
|
||||
|
||||
#ifndef DEBUG
|
||||
#define VER_DEBUG 0
|
||||
#else
|
||||
#define VER_DEBUG VS_FF_DEBUG
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION VER_FILEVERSION
|
||||
PRODUCTVERSION VER_PRODUCTVERSION
|
||||
FILEFLAGSMASK (VS_FF_DEBUG)
|
||||
FILEFLAGS (VER_DEBUG)
|
||||
FILEOS VOS__WINDOWS32
|
||||
FILETYPE VFT_DLL
|
||||
FILESUBTYPE VFT2_UNKNOWN
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904E4"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Intrepid Control Systems, Inc."
|
||||
VALUE "FileDescription", "Intrepid Control Systems Open Device Communication C API"
|
||||
VALUE "FileVersion", VER_FILEVERSION_STR
|
||||
VALUE "InternalName", "icsneo.dll"
|
||||
VALUE "LegalCopyright", "Intrepid Control Systems, Inc. (C) 2018-2024"
|
||||
VALUE "OriginalFilename", "icsneo.dll"
|
||||
VALUE "ProductName", "libicsneo"
|
||||
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
|
||||
END
|
||||
END
|
||||
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
/* The following line should only be modified for localized versions. */
|
||||
/* It consists of any number of WORD,WORD pairs, with each pair */
|
||||
/* describing a language,codepage combination supported by the file. */
|
||||
/* */
|
||||
/* For example, a file might have values "0x409,1252" indicating that it */
|
||||
/* supports English language (0x409) in the Windows ANSI codepage (1252). */
|
||||
|
||||
VALUE "Translation", 0x409, 1252
|
||||
|
||||
END
|
||||
END
|
||||
+76
-103
@@ -74,6 +74,9 @@ static constexpr const char* TIMEOUT = "The timeout was reached.";
|
||||
static constexpr const char* WIVI_NOT_SUPPORTED = "Wireless neoVI functions are not supported on this device.";
|
||||
static constexpr const char* RESTRICTED_ENTRY_FLAG = "Attempted to set a restricted flag in a Root Directory entry.";
|
||||
static constexpr const char* NOT_SUPPORTED = "The requested feature is not supported.";
|
||||
static constexpr const char* FIXED_POINT_OVERFLOW = "Value is too large to convert to fixed point.";
|
||||
static constexpr const char* FIXED_POINT_PRECISION = "Value is too small for fixed point precision.";
|
||||
static constexpr const char* SYSCALL_ERROR = "Error returned from syscall, check errno/GetLastError().";
|
||||
|
||||
// Device Errors
|
||||
static constexpr const char* POLLING_MESSAGE_OVERFLOW = "Too many messages have been recieved for the polling message buffer, some have been lost!";
|
||||
@@ -121,6 +124,11 @@ static constexpr const char* UNEXPECTED_RESPONSE = "Received an unexpected or in
|
||||
static constexpr const char* LIN_SETTINGS_NOT_AVAILABLE = "LIN settings are not available for this device.";
|
||||
static constexpr const char* MODE_NOT_FOUND = "The mode was not found.";
|
||||
static constexpr const char* GPTP_NOT_SUPPORTED = "GPTP clock synchronization is not supported on this device.";
|
||||
static constexpr const char* SETTING_NOT_AVAILABLE = "Requested a setting that is not available on this device";
|
||||
static constexpr const char* DISK_FORMAT_NOT_SUPPORTED = "Disk formatting is not supported on this device.";
|
||||
static constexpr const char* DISK_FORMAT_INVALID_COUNT = "Disk format config disk count is mismatched with device disk count.";
|
||||
|
||||
|
||||
|
||||
// Transport Errors
|
||||
static constexpr const char* FAILED_TO_READ = "A read operation failed.";
|
||||
@@ -139,41 +147,6 @@ static constexpr const char* ERROR_SETTING_SOCKET_OPTION = "A call to setsockopt
|
||||
static constexpr const char* GETIFADDRS_ERROR = "A call to getifaddrs() failed.";
|
||||
static constexpr const char* SEND_TO_ERROR = "A call to sendto() failed.";
|
||||
|
||||
// FTD3XX
|
||||
static constexpr const char* FT_OK = "FTD3XX success.";
|
||||
static constexpr const char* FT_INVALID_HANDLE = "Invalid FTD3XX handle.";
|
||||
static constexpr const char* FT_DEVICE_NOT_FOUND = "FTD3XX device not found.";
|
||||
static constexpr const char* FT_DEVICE_NOT_OPENED = "FTD3XX device not opened.";
|
||||
static constexpr const char* FT_IO_ERROR = "FTD3XX IO error.";
|
||||
static constexpr const char* FT_INSUFFICIENT_RESOURCES = "Insufficient resources for FTD3XX.";
|
||||
static constexpr const char* FT_INVALID_PARAMETER = "Invalid FTD3XX parameter.";
|
||||
static constexpr const char* FT_INVALID_BAUD_RATE = "Invalid FTD3XX baud rate.";
|
||||
static constexpr const char* FT_DEVICE_NOT_OPENED_FOR_ERASE = "FTD3XX device not opened for erase.";
|
||||
static constexpr const char* FT_DEVICE_NOT_OPENED_FOR_WRITE = "FTD3XX not opened for write.";
|
||||
static constexpr const char* FT_FAILED_TO_WRITE_DEVICE = "FTD3XX failed to write device.";
|
||||
static constexpr const char* FT_EEPROM_READ_FAILED = "FTD3XX EEPROM read failed.";
|
||||
static constexpr const char* FT_EEPROM_WRITE_FAILED = "FTD3XX EEPROM write failed.";
|
||||
static constexpr const char* FT_EEPROM_ERASE_FAILED = "FTD3XX EEPROM erase failed.";
|
||||
static constexpr const char* FT_EEPROM_NOT_PRESENT = "FTD3XX EEPROM not present.";
|
||||
static constexpr const char* FT_EEPROM_NOT_PROGRAMMED = "FTD3XX EEPROM not programmed.";
|
||||
static constexpr const char* FT_INVALID_ARGS = "Invalid FTD3XX arguments.";
|
||||
static constexpr const char* FT_NOT_SUPPORTED = "FTD3XX not supported.";
|
||||
static constexpr const char* FT_NO_MORE_ITEMS = "No more FTD3XX items.";
|
||||
static constexpr const char* FT_TIMEOUT = "FTD3XX timeout.";
|
||||
static constexpr const char* FT_OPERATION_ABORTED = "FTD3XX operation aborted.";
|
||||
static constexpr const char* FT_RESERVED_PIPE = "Reserved FTD3XX pipe.";
|
||||
static constexpr const char* FT_INVALID_CONTROL_REQUEST_DIRECTION = "Invalid FTD3XX control request direction.";
|
||||
static constexpr const char* FT_INVALID_CONTROL_REQUEST_TYPE = "Invalid FTD3XX control request type.";
|
||||
static constexpr const char* FT_IO_PENDING = "FTD3XX IO pending.";
|
||||
static constexpr const char* FT_IO_INCOMPLETE = "FTD3XX IO incomplete.";
|
||||
static constexpr const char* FT_HANDLE_EOF = "Handle FTD3XX EOF.";
|
||||
static constexpr const char* FT_BUSY = "FTD3XX busy.";
|
||||
static constexpr const char* FT_NO_SYSTEM_RESOURCES = "No FTD3XX system resources.";
|
||||
static constexpr const char* FT_DEVICE_LIST_NOT_READY = "FTD3XX device list not ready.";
|
||||
static constexpr const char* FT_DEVICE_NOT_CONNECTED = "FTD3XX device not connected.";
|
||||
static constexpr const char* FT_INCORRECT_DEVICE_PATH = "Incorrect FTD3XX device path.";
|
||||
static constexpr const char* FT_OTHER_ERROR = "Other FTD3XX error.";
|
||||
|
||||
// VSA
|
||||
static constexpr const char* VSA_BUFFER_CORRUPTED = "VSA data in record buffer is corrupted.";
|
||||
static constexpr const char* VSA_TIMESTAMP_NOT_FOUND = "Unable to find a VSA record with a valid timestamp.";
|
||||
@@ -183,6 +156,26 @@ static constexpr const char* VSA_BYTE_PARSE_FAILURE = "Failure to parse record b
|
||||
static constexpr const char* VSA_EXTENDED_MESSAGE_ERROR = "Failure to parse extended message record sequence";
|
||||
static constexpr const char* VSA_OTHER_ERROR = "Unknown error in VSA read API.";
|
||||
|
||||
// Servd
|
||||
static constexpr const char* SERVD_BIND_ERROR = "Error binding socket for Servd communication";
|
||||
static constexpr const char* SERVD_NONBLOCK_ERROR = "Error setting non-blocking mode for Servd socket";
|
||||
static constexpr const char* SERVD_TRANSCEIVE_ERROR = "Error while sending to or receiving from Servd";
|
||||
static constexpr const char* SERVD_OUTDATED_ERROR = "Servd version is lower than client (libicsneo) version, update Servd";
|
||||
static constexpr const char* SERVD_INVALID_RESPONSE_ERROR = "Unexpected response from Servd";
|
||||
static constexpr const char* SERVD_LOCK_ERROR = "Error locking Servd mutex";
|
||||
static constexpr const char* SERVD_SEND_ERROR = "Error sending to Servd";
|
||||
static constexpr const char* SERVD_RECV_ERROR = "Error receiving from Servd";
|
||||
static constexpr const char* SERVD_POLL_ERROR = "Error polling on Servd socket";
|
||||
static constexpr const char* SERVD_NODATA_ERROR = "No data received from Servd";
|
||||
static constexpr const char* SERVD_JOIN_MULTICAST_ERROR = "Error joining Servd multicast group";
|
||||
|
||||
// DXX
|
||||
static constexpr const char* DXX_ERROR_SYS = "System error, check errno/GetLastError()";
|
||||
static constexpr const char* DXX_ERROR_INT = "DXX interrupt called";
|
||||
static constexpr const char* DXX_ERROR_OVERFLOW = "Overflow in DXX";
|
||||
static constexpr const char* DXX_ERROR_IO = "I/O failure in DXX";
|
||||
static constexpr const char* DXX_ERROR_ARG = "Invalid arg passed to DXX";
|
||||
|
||||
static constexpr const char* TOO_MANY_EVENTS = "Too many events have occurred. The list has been truncated.";
|
||||
static constexpr const char* UNKNOWN = "An unknown internal error occurred.";
|
||||
static constexpr const char* INVALID = "An invalid internal error occurred.";
|
||||
@@ -226,6 +219,12 @@ const char* APIEvent::DescriptionForType(Type type) {
|
||||
return RESTRICTED_ENTRY_FLAG;
|
||||
case Type::NotSupported:
|
||||
return NOT_SUPPORTED;
|
||||
case Type::FixedPointOverflow:
|
||||
return FIXED_POINT_OVERFLOW;
|
||||
case Type::FixedPointPrecision:
|
||||
return FIXED_POINT_PRECISION;
|
||||
case Type::SyscallError:
|
||||
return SYSCALL_ERROR;
|
||||
|
||||
// Device Errors
|
||||
case Type::PollingMessageOverflow:
|
||||
@@ -316,6 +315,8 @@ const char* APIEvent::DescriptionForType(Type type) {
|
||||
return LIN_SETTINGS_NOT_AVAILABLE;
|
||||
case Type::ModeNotFound:
|
||||
return MODE_NOT_FOUND;
|
||||
case Type::SettingNotAvaiableDevice:
|
||||
return SETTING_NOT_AVAILABLE;
|
||||
// Transport Errors
|
||||
case Type::FailedToRead:
|
||||
return FAILED_TO_READ;
|
||||
@@ -349,74 +350,10 @@ const char* APIEvent::DescriptionForType(Type type) {
|
||||
return SEND_TO_ERROR;
|
||||
case Type::GPTPNotSupported:
|
||||
return GPTP_NOT_SUPPORTED;
|
||||
|
||||
// FTD3XX
|
||||
case Type::FTOK:
|
||||
return FT_OK;
|
||||
case Type::FTInvalidHandle:
|
||||
return FT_INVALID_HANDLE;
|
||||
case Type::FTDeviceNotFound:
|
||||
return FT_DEVICE_NOT_FOUND;
|
||||
case Type::FTDeviceNotOpened:
|
||||
return FT_DEVICE_NOT_OPENED;
|
||||
case Type::FTIOError:
|
||||
return FT_IO_ERROR;
|
||||
case Type::FTInsufficientResources:
|
||||
return FT_INSUFFICIENT_RESOURCES;
|
||||
case Type::FTInvalidParameter:
|
||||
return FT_INVALID_PARAMETER;
|
||||
case Type::FTInvalidBaudRate:
|
||||
return FT_INVALID_BAUD_RATE;
|
||||
case Type::FTDeviceNotOpenedForErase:
|
||||
return FT_DEVICE_NOT_OPENED_FOR_ERASE;
|
||||
case Type::FTDeviceNotOpenedForWrite:
|
||||
return FT_DEVICE_NOT_OPENED_FOR_WRITE;
|
||||
case Type::FTFailedToWriteDevice:
|
||||
return FT_FAILED_TO_WRITE_DEVICE;
|
||||
case Type::FTEEPROMReadFailed:
|
||||
return FT_EEPROM_READ_FAILED;
|
||||
case Type::FTEEPROMWriteFailed:
|
||||
return FT_EEPROM_WRITE_FAILED;
|
||||
case Type::FTEEPROMEraseFailed:
|
||||
return FT_EEPROM_ERASE_FAILED;
|
||||
case Type::FTEEPROMNotPresent:
|
||||
return FT_EEPROM_NOT_PRESENT;
|
||||
case Type::FTEEPROMNotProgrammed:
|
||||
return FT_EEPROM_NOT_PROGRAMMED;
|
||||
case Type::FTInvalidArgs:
|
||||
return FT_INVALID_ARGS;
|
||||
case Type::FTNotSupported:
|
||||
return FT_NOT_SUPPORTED;
|
||||
case Type::FTNoMoreItems:
|
||||
return FT_NO_MORE_ITEMS;
|
||||
case Type::FTTimeout:
|
||||
return FT_TIMEOUT;
|
||||
case Type::FTOperationAborted:
|
||||
return FT_OPERATION_ABORTED;
|
||||
case Type::FTReservedPipe:
|
||||
return FT_RESERVED_PIPE;
|
||||
case Type::FTInvalidControlRequestDirection:
|
||||
return FT_INVALID_CONTROL_REQUEST_DIRECTION;
|
||||
case Type::FTInvalidControlRequestType:
|
||||
return FT_INVALID_CONTROL_REQUEST_TYPE;
|
||||
case Type::FTIOPending:
|
||||
return FT_IO_PENDING;
|
||||
case Type::FTIOIncomplete:
|
||||
return FT_IO_INCOMPLETE;
|
||||
case Type::FTHandleEOF:
|
||||
return FT_HANDLE_EOF;
|
||||
case Type::FTBusy:
|
||||
return FT_BUSY;
|
||||
case Type::FTNoSystemResources:
|
||||
return FT_NO_SYSTEM_RESOURCES;
|
||||
case Type::FTDeviceListNotReady:
|
||||
return FT_DEVICE_LIST_NOT_READY;
|
||||
case Type::FTDeviceNotConnected:
|
||||
return FT_DEVICE_NOT_CONNECTED;
|
||||
case Type::FTIncorrectDevicePath:
|
||||
return FT_INCORRECT_DEVICE_PATH;
|
||||
case Type::FTOtherError:
|
||||
return FT_OTHER_ERROR;
|
||||
case Type::DiskFormatNotSupported:
|
||||
return DISK_FORMAT_NOT_SUPPORTED;
|
||||
case Type::DiskFormatInvalidCount:
|
||||
return DISK_FORMAT_INVALID_COUNT;
|
||||
|
||||
// VSA
|
||||
case Type::VSABufferCorrupted:
|
||||
@@ -434,6 +371,42 @@ const char* APIEvent::DescriptionForType(Type type) {
|
||||
case Type::VSAOtherError:
|
||||
return VSA_OTHER_ERROR;
|
||||
|
||||
// Servd
|
||||
case Type::ServdBindError:
|
||||
return SERVD_BIND_ERROR;
|
||||
case Type::ServdNonblockError:
|
||||
return SERVD_NONBLOCK_ERROR;
|
||||
case Type::ServdTransceiveError:
|
||||
return SERVD_TRANSCEIVE_ERROR;
|
||||
case Type::ServdOutdatedError:
|
||||
return SERVD_OUTDATED_ERROR;
|
||||
case Type::ServdInvalidResponseError:
|
||||
return SERVD_INVALID_RESPONSE_ERROR;
|
||||
case Type::ServdLockError:
|
||||
return SERVD_LOCK_ERROR;
|
||||
case Type::ServdSendError:
|
||||
return SERVD_SEND_ERROR;
|
||||
case Type::ServdRecvError:
|
||||
return SERVD_RECV_ERROR;
|
||||
case Type::ServdPollError:
|
||||
return SERVD_POLL_ERROR;
|
||||
case Type::ServdNoDataError:
|
||||
return SERVD_NODATA_ERROR;
|
||||
case Type::ServdJoinMulticastError:
|
||||
return SERVD_JOIN_MULTICAST_ERROR;
|
||||
|
||||
// DXX
|
||||
case Type::DXXErrorSys:
|
||||
return DXX_ERROR_SYS;
|
||||
case Type::DXXErrorInt:
|
||||
return DXX_ERROR_INT;
|
||||
case Type::DXXErrorOverflow:
|
||||
return DXX_ERROR_OVERFLOW;
|
||||
case Type::DXXErrorIO:
|
||||
return DXX_ERROR_IO;
|
||||
case Type::DXXErrorArg:
|
||||
return DXX_ERROR_ARG;
|
||||
|
||||
// Other Errors
|
||||
case Type::TooManyEvents:
|
||||
return TOO_MANY_EVENTS;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
//FILE: icsneo40DLLAPI.H
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#include "icsneo/icsnVC40.h"
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
#error "icsneolegacy.cpp must be compiled with a C++ compiler!"
|
||||
#endif
|
||||
|
||||
#define NOMINMAX
|
||||
|
||||
#define ICSNEOC_MAKEDLL
|
||||
#include "icsneo/icsneolegacy.h"
|
||||
#include "icsneo/J2534.h"
|
||||
@@ -29,25 +27,25 @@ static std::map<legacymaphandle_t, neodevice_t> neodevices;
|
||||
static std::map<neodevice_t*, NeoDeviceEx*> openneodevices;
|
||||
|
||||
static const std::map<size_t, size_t> mp_netIDToVnetOffSet = {
|
||||
{NETID_HSCAN, 1},
|
||||
{NETID_MSCAN, 2},
|
||||
{NETID_HSCAN2, 18},
|
||||
{NETID_HSCAN3, 19},
|
||||
{NETID_HSCAN4, 32},
|
||||
{NETID_HSCAN5, 33},
|
||||
{NETID_HSCAN6, 47},
|
||||
{NETID_HSCAN7, 48},
|
||||
{NETID_DWCAN_01, 1},
|
||||
{NETID_DWCAN_08, 2},
|
||||
{NETID_DWCAN_02, 18},
|
||||
{NETID_DWCAN_03, 19},
|
||||
{NETID_DWCAN_04, 32},
|
||||
{NETID_DWCAN_05, 33},
|
||||
{NETID_DWCAN_06, 47},
|
||||
{NETID_DWCAN_07, 48},
|
||||
};
|
||||
|
||||
static const std::map<size_t, size_t> mp_HWnetIDToCMnetID = {
|
||||
{NETID_HSCAN, 0},
|
||||
{NETID_MSCAN, 1},
|
||||
{NETID_HSCAN2, 5},
|
||||
{NETID_HSCAN3, 8},
|
||||
{NETID_HSCAN4, 14},
|
||||
{NETID_HSCAN5, 15},
|
||||
{NETID_HSCAN6, 32},
|
||||
{NETID_HSCAN7, 33},
|
||||
{NETID_DWCAN_01, 0},
|
||||
{NETID_DWCAN_08, 1},
|
||||
{NETID_DWCAN_02, 5},
|
||||
{NETID_DWCAN_03, 8},
|
||||
{NETID_DWCAN_04, 14},
|
||||
{NETID_DWCAN_05, 15},
|
||||
{NETID_DWCAN_06, 32},
|
||||
{NETID_DWCAN_07, 33},
|
||||
};
|
||||
|
||||
static unsigned long vnet_table[] = {0, PLASMA_SLAVE1_OFFSET, PLASMA_SLAVE2_OFFSET};
|
||||
|
||||
@@ -1,18 +1,3 @@
|
||||
if(LIBICSNEO_ENABLE_BINDINGS_PYTHON)
|
||||
add_subdirectory(python)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_ENABLE_BINDINGS_RUST)
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
Corrosion
|
||||
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
|
||||
GIT_TAG v0.5 # Optionally specify a commit hash, version tag or branch here
|
||||
)
|
||||
FetchContent_MakeAvailable(Corrosion)
|
||||
|
||||
corrosion_import_crate(MANIFEST_PATH ${CMAKE_SOURCE_DIR}/bindings/rust/icsneoc2rs/Cargo.toml)
|
||||
else()
|
||||
message(STATUS "Not building rust bindings")
|
||||
endif()
|
||||
@@ -1,7 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
set(PYBIND11_FINDPYTHON ON)
|
||||
find_package(pybind11 CONFIG REQUIRED)
|
||||
|
||||
if(PYBIND11_ROOT)
|
||||
find_package(pybind11 CONFIG REQUIRED)
|
||||
else()
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
pybind11
|
||||
GIT_REPOSITORY https://github.com/pybind/pybind11.git
|
||||
GIT_TAG v2.13.6
|
||||
)
|
||||
FetchContent_MakeAvailable(pybind11)
|
||||
endif()
|
||||
|
||||
pybind11_add_module(icsneopy
|
||||
icsneopy/api/event.cpp
|
||||
@@ -10,6 +21,7 @@ pybind11_add_module(icsneopy
|
||||
icsneopy/api/version.cpp
|
||||
icsneopy/device/devicetype.cpp
|
||||
icsneopy/communication/network.cpp
|
||||
icsneopy/communication/io.cpp
|
||||
icsneopy/communication/message/message.cpp
|
||||
icsneopy/communication/message/canmessage.cpp
|
||||
icsneopy/communication/message/canerrormessage.cpp
|
||||
@@ -19,16 +31,24 @@ pybind11_add_module(icsneopy
|
||||
icsneopy/communication/message/mdiomessage.cpp
|
||||
icsneopy/communication/message/gptpstatusmessage.cpp
|
||||
icsneopy/communication/message/ethernetstatusmessage.cpp
|
||||
icsneopy/communication/message/macsecmessage.cpp
|
||||
icsneopy/communication/message/scriptstatusmessage.cpp
|
||||
icsneopy/communication/message/callback/messagecallback.cpp
|
||||
icsneopy/communication/message/filter/messagefilter.cpp
|
||||
icsneopy/communication/message/flexray/flexraymessage.cpp
|
||||
icsneopy/disk/diskdriver.cpp
|
||||
icsneopy/device/device.cpp
|
||||
icsneopy/device/idevicesettings.cpp
|
||||
icsneopy/icsneocpp.cpp
|
||||
)
|
||||
target_link_libraries(icsneopy PRIVATE icsneocpp)
|
||||
|
||||
install(TARGETS icsneopy LIBRARY DESTINATION icsneopy)
|
||||
|
||||
find_program(STUBGEN stubgen REQUIRED)
|
||||
add_custom_command(TARGET icsneopy POST_BUILD COMMAND ${STUBGEN} -m icsneopy -o .)
|
||||
find_program(STUBGEN_EXE stubgen)
|
||||
if(STUBGEN_EXE)
|
||||
add_custom_command(TARGET icsneopy POST_BUILD COMMAND stubgen -v -p icsneopy -o .)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/icsneopy.pyi py.typed DESTINATION icsneopy)
|
||||
endif()
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/icsneopy.pyi __init__.py py.typed DESTINATION icsneopy)
|
||||
install(FILES __init__.py DESTINATION icsneopy)
|
||||
|
||||
@@ -28,6 +28,9 @@ void init_event(pybind11::module_& m) {
|
||||
.value("WiVINotSupported", APIEvent::Type::WiVINotSupported)
|
||||
.value("RestrictedEntryFlag", APIEvent::Type::RestrictedEntryFlag)
|
||||
.value("NotSupported", APIEvent::Type::NotSupported)
|
||||
.value("FixedPointOverflow", APIEvent::Type::FixedPointOverflow)
|
||||
.value("FixedPointPrecision", APIEvent::Type::FixedPointPrecision)
|
||||
.value("SyscallError", APIEvent::Type::SyscallError)
|
||||
.value("PollingMessageOverflow", APIEvent::Type::PollingMessageOverflow)
|
||||
.value("NoSerialNumber", APIEvent::Type::NoSerialNumber)
|
||||
.value("IncorrectSerialNumber", APIEvent::Type::IncorrectSerialNumber)
|
||||
@@ -84,6 +87,10 @@ void init_event(pybind11::module_& m) {
|
||||
.value("LINSettingsNotAvailable", APIEvent::Type::LINSettingsNotAvailable)
|
||||
.value("ModeNotFound", APIEvent::Type::ModeNotFound)
|
||||
.value("AppErrorParsingFailed", APIEvent::Type::AppErrorParsingFailed)
|
||||
.value("GPTPNotSupported", APIEvent::Type::GPTPNotSupported)
|
||||
.value("SettingNotAvaiableDevice", APIEvent::Type::SettingNotAvaiableDevice)
|
||||
.value("DiskFormatNotSupported", APIEvent::Type::DiskFormatNotSupported)
|
||||
.value("DiskFormatInvalidCount", APIEvent::Type::DiskFormatInvalidCount)
|
||||
.value("FailedToRead", APIEvent::Type::FailedToRead)
|
||||
.value("FailedToWrite", APIEvent::Type::FailedToWrite)
|
||||
.value("DriverFailedToOpen", APIEvent::Type::DriverFailedToOpen)
|
||||
@@ -100,39 +107,6 @@ void init_event(pybind11::module_& m) {
|
||||
.value("GetIfAddrsError", APIEvent::Type::GetIfAddrsError)
|
||||
.value("SendToError", APIEvent::Type::SendToError)
|
||||
.value("MDIOMessageExceedsMaxLength", APIEvent::Type::MDIOMessageExceedsMaxLength)
|
||||
.value("FTOK", APIEvent::Type::FTOK)
|
||||
.value("FTInvalidHandle", APIEvent::Type::FTInvalidHandle)
|
||||
.value("FTDeviceNotFound", APIEvent::Type::FTDeviceNotFound)
|
||||
.value("FTDeviceNotOpened", APIEvent::Type::FTDeviceNotOpened)
|
||||
.value("FTIOError", APIEvent::Type::FTIOError)
|
||||
.value("FTInsufficientResources", APIEvent::Type::FTInsufficientResources)
|
||||
.value("FTInvalidParameter", APIEvent::Type::FTInvalidParameter)
|
||||
.value("FTInvalidBaudRate", APIEvent::Type::FTInvalidBaudRate)
|
||||
.value("FTDeviceNotOpenedForErase", APIEvent::Type::FTDeviceNotOpenedForErase)
|
||||
.value("FTDeviceNotOpenedForWrite", APIEvent::Type::FTDeviceNotOpenedForWrite)
|
||||
.value("FTFailedToWriteDevice", APIEvent::Type::FTFailedToWriteDevice)
|
||||
.value("FTEEPROMReadFailed", APIEvent::Type::FTEEPROMReadFailed)
|
||||
.value("FTEEPROMWriteFailed", APIEvent::Type::FTEEPROMWriteFailed)
|
||||
.value("FTEEPROMEraseFailed", APIEvent::Type::FTEEPROMEraseFailed)
|
||||
.value("FTEEPROMNotPresent", APIEvent::Type::FTEEPROMNotPresent)
|
||||
.value("FTEEPROMNotProgrammed", APIEvent::Type::FTEEPROMNotProgrammed)
|
||||
.value("FTInvalidArgs", APIEvent::Type::FTInvalidArgs)
|
||||
.value("FTNotSupported", APIEvent::Type::FTNotSupported)
|
||||
.value("FTNoMoreItems", APIEvent::Type::FTNoMoreItems)
|
||||
.value("FTTimeout", APIEvent::Type::FTTimeout)
|
||||
.value("FTOperationAborted", APIEvent::Type::FTOperationAborted)
|
||||
.value("FTReservedPipe", APIEvent::Type::FTReservedPipe)
|
||||
.value("FTInvalidControlRequestDirection", APIEvent::Type::FTInvalidControlRequestDirection)
|
||||
.value("FTInvalidControlRequestType", APIEvent::Type::FTInvalidControlRequestType)
|
||||
.value("FTIOPending", APIEvent::Type::FTIOPending)
|
||||
.value("FTIOIncomplete", APIEvent::Type::FTIOIncomplete)
|
||||
.value("FTHandleEOF", APIEvent::Type::FTHandleEOF)
|
||||
.value("FTBusy", APIEvent::Type::FTBusy)
|
||||
.value("FTNoSystemResources", APIEvent::Type::FTNoSystemResources)
|
||||
.value("FTDeviceListNotReady", APIEvent::Type::FTDeviceListNotReady)
|
||||
.value("FTDeviceNotConnected", APIEvent::Type::FTDeviceNotConnected)
|
||||
.value("FTIncorrectDevicePath", APIEvent::Type::FTIncorrectDevicePath)
|
||||
.value("FTOtherError", APIEvent::Type::FTOtherError)
|
||||
.value("VSABufferCorrupted", APIEvent::Type::VSABufferCorrupted)
|
||||
.value("VSATimestampNotFound", APIEvent::Type::VSATimestampNotFound)
|
||||
.value("VSABufferFormatError", APIEvent::Type::VSABufferFormatError)
|
||||
@@ -140,11 +114,27 @@ void init_event(pybind11::module_& m) {
|
||||
.value("VSAByteParseFailure", APIEvent::Type::VSAByteParseFailure)
|
||||
.value("VSAExtendedMessageError", APIEvent::Type::VSAExtendedMessageError)
|
||||
.value("VSAOtherError", APIEvent::Type::VSAOtherError)
|
||||
.value("ServdBindError", APIEvent::Type::ServdBindError)
|
||||
.value("ServdNonblockError", APIEvent::Type::ServdNonblockError)
|
||||
.value("ServdTransceiveError", APIEvent::Type::ServdTransceiveError)
|
||||
.value("ServdOutdatedError", APIEvent::Type::ServdOutdatedError)
|
||||
.value("ServdInvalidResponseError", APIEvent::Type::ServdInvalidResponseError)
|
||||
.value("ServdLockError", APIEvent::Type::ServdLockError)
|
||||
.value("ServdSendError", APIEvent::Type::ServdSendError)
|
||||
.value("ServdRecvError", APIEvent::Type::ServdRecvError)
|
||||
.value("ServdPollError", APIEvent::Type::ServdPollError)
|
||||
.value("ServdNoDataError", APIEvent::Type::ServdNoDataError)
|
||||
.value("ServdJoinMulticastError", APIEvent::Type::ServdJoinMulticastError)
|
||||
.value("DXXErrorSys", APIEvent::Type::DXXErrorSys)
|
||||
.value("DXXErrorInt", APIEvent::Type::DXXErrorInt)
|
||||
.value("DXXErrorOverflow", APIEvent::Type::DXXErrorOverflow)
|
||||
.value("DXXErrorIO", APIEvent::Type::DXXErrorIO)
|
||||
.value("DXXErrorArg", APIEvent::Type::DXXErrorArg)
|
||||
.value("NoErrorFound", APIEvent::Type::NoErrorFound)
|
||||
.value("TooManyEvents", APIEvent::Type::TooManyEvents)
|
||||
.value("Unknown", APIEvent::Type::Unknown);
|
||||
|
||||
pybind11::enum_<APIEvent::Severity>(apiEvent, "Severity")
|
||||
pybind11::enum_<APIEvent::Severity>(apiEvent, "Severity")
|
||||
.value("Any", APIEvent::Severity::Any)
|
||||
.value("EventInfo", APIEvent::Severity::EventInfo)
|
||||
.value("EventWarning", APIEvent::Severity::EventWarning)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
#include "icsneo/communication/io.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_io(pybind11::module_& m) {
|
||||
pybind11::enum_<IO>(m, "IO")
|
||||
.value("EthernetActivation", IO::EthernetActivation)
|
||||
.value("USBHostPower", IO::USBHostPower)
|
||||
.value("BackupPowerEnabled", IO::BackupPowerEnabled)
|
||||
.value("BackupPowerGood", IO::BackupPowerGood)
|
||||
.value("Misc", IO::Misc)
|
||||
.value("EMisc", IO::EMisc);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_canmessage(pybind11::module_& m) {
|
||||
pybind11::class_<CANMessage, std::shared_ptr<CANMessage>, BusMessage>(m, "CANMessage")
|
||||
pybind11::class_<CANMessage, std::shared_ptr<CANMessage>, Frame>(m, "CANMessage")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("arbid", &CANMessage::arbid)
|
||||
.def_readwrite("dlcOnWire", &CANMessage::dlcOnWire)
|
||||
|
||||
@@ -11,7 +11,7 @@ void init_ethernetmessage(pybind11::module_& m) {
|
||||
.def("to_string", &MACAddress::toString)
|
||||
.def("__repr__", &MACAddress::toString);
|
||||
|
||||
pybind11::class_<EthernetMessage, std::shared_ptr<EthernetMessage>, BusMessage>(m, "EthernetMessage")
|
||||
pybind11::class_<EthernetMessage, std::shared_ptr<EthernetMessage>, Frame>(m, "EthernetMessage")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("preemptionEnabled", &EthernetMessage::preemptionEnabled)
|
||||
.def_readwrite("preemptionFlags", &EthernetMessage::preemptionFlags)
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
#include "icsneo/communication/message/flexray/flexraymessage.h"
|
||||
#include "icsneo/device/extensions/flexray/symbol.h"
|
||||
#include "icsneo/device/extensions/flexray/channel.h"
|
||||
#include "icsneo/device/extensions/flexray/crcstatus.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
struct FlexRayNamespace {
|
||||
using Symbol = icsneo::FlexRay::Symbol;
|
||||
using CRCStatus = icsneo::FlexRay::CRCStatus;
|
||||
using Channel = icsneo::FlexRay::Channel;
|
||||
};
|
||||
|
||||
void init_flexraymessage(pybind11::module_& m) {
|
||||
// dummy class to hold the enums
|
||||
pybind11::class_<FlexRayNamespace> flexray(m, "FlexRay");
|
||||
// enumerations
|
||||
pybind11::enum_<FlexRayNamespace::Symbol>(flexray, "Symbol")
|
||||
.value("None", FlexRayNamespace::Symbol::None)
|
||||
.value("Unknown", FlexRayNamespace::Symbol::Unknown)
|
||||
.value("Wakeup", FlexRayNamespace::Symbol::Wakeup)
|
||||
.value("CAS", FlexRayNamespace::Symbol::CAS);
|
||||
pybind11::enum_<FlexRayNamespace::CRCStatus>(flexray, "CRCStatus")
|
||||
.value("OK", FlexRayNamespace::CRCStatus::OK)
|
||||
.value("Error", FlexRayNamespace::CRCStatus::Error)
|
||||
.value("NoCRC", FlexRayNamespace::CRCStatus::NoCRC);
|
||||
pybind11::enum_<FlexRayNamespace::Channel>(flexray, "Channel")
|
||||
.value("None", FlexRayNamespace::Channel::None)
|
||||
.value("A", FlexRayNamespace::Channel::A)
|
||||
.value("B", FlexRayNamespace::Channel::B)
|
||||
.value("AB", FlexRayNamespace::Channel::AB);
|
||||
// read-only until transmit is supported
|
||||
pybind11::class_<FlexRayMessage, std::shared_ptr<FlexRayMessage>, Frame>(m, "FlexRayMessage")
|
||||
.def(pybind11::init())
|
||||
.def_readonly("slotid", &FlexRayMessage::slotid)
|
||||
.def_readonly("tsslen", &FlexRayMessage::tsslen)
|
||||
.def_readonly("framelen", &FlexRayMessage::framelen)
|
||||
.def_readonly("symbol", &FlexRayMessage::symbol)
|
||||
.def_readonly("header_crc_status", &FlexRayMessage::headerCRCStatus)
|
||||
.def_readonly("header_crc", &FlexRayMessage::headerCRC)
|
||||
.def_readonly("frame_crc_status", &FlexRayMessage::crcStatus)
|
||||
.def_readonly("frame_crc", &FlexRayMessage::frameCRC)
|
||||
.def_readonly("channel", &FlexRayMessage::channel)
|
||||
.def_readonly("null_frame", &FlexRayMessage::nullFrame)
|
||||
.def_readonly("payload_preamble", &FlexRayMessage::payloadPreamble)
|
||||
.def_readonly("sync_frame", &FlexRayMessage::sync)
|
||||
.def_readonly("startup_frame", &FlexRayMessage::startup)
|
||||
.def_readonly("dynamic_frame", &FlexRayMessage::dynamic)
|
||||
.def_readonly("cycle", &FlexRayMessage::cycle);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -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>, BusMessage> linMessage(m, "LINMessage");
|
||||
pybind11::class_<LINMessage, std::shared_ptr<LINMessage>, Frame> linMessage(m, "LINMessage");
|
||||
|
||||
pybind11::enum_<LINMessage::Type>(linMessage, "Type")
|
||||
.value("NOT_SET", LINMessage::Type::NOT_SET)
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
#include "icsneo/communication/message/macsecmessage.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_macsecmessage(pybind11::module_ & m)
|
||||
{
|
||||
pybind11::enum_<MACsecPacketType>(m, "MACsecPacketType")
|
||||
.value("NoVLAN_OrMPLS", MACsecPacketType::NoVLANOrMPLS)
|
||||
.value("SingleVLAN", MACsecPacketType::SingleVLAN)
|
||||
.value("DualVLAN", MACsecPacketType::DualVLAN)
|
||||
.value("MPLS", MACsecPacketType::MPLS)
|
||||
.value("SingleVLAN_FollowByMPLS", MACsecPacketType::SingleVLANFollowedByMPLS)
|
||||
.value("DualVLAN_FollowByMPLS", MACsecPacketType::DualVLANFollowedByMPLS)
|
||||
.value("Unsupported", MACsecPacketType::Unsupported);
|
||||
|
||||
pybind11::enum_<MACsecValidateFrameType>(m, "MACsecValidateFrameType")
|
||||
.value("Disabled", MACsecValidateFrameType::Disabled)
|
||||
.value("Check", MACsecValidateFrameType::Check)
|
||||
.value("Strict", MACsecValidateFrameType::Strict)
|
||||
.value("NA", MACsecValidateFrameType::NA);
|
||||
|
||||
pybind11::enum_<MACsecSecTagIcvStripType>(m, "MACsecSecTagIcvStripType")
|
||||
.value("StripBoth", MACsecSecTagIcvStripType::StripBoth)
|
||||
.value("StripSecTagPreserveICV", MACsecSecTagIcvStripType::StripSecTagPreserveICV)
|
||||
.value("PreserveSecTagStripICV", MACsecSecTagIcvStripType::PreserveSecTagStripICV)
|
||||
.value("PreserveBoth", MACsecSecTagIcvStripType::PreserveBoth);
|
||||
|
||||
pybind11::enum_<MACsecCipherSuiteType>(m, "MACsecCipherSuiteType")
|
||||
.value("AES_128", MACsecCipherSuiteType::GcmAes128)
|
||||
.value("AES_256", MACsecCipherSuiteType::GcmAes256)
|
||||
.value("AES_128_XPN", MACsecCipherSuiteType::GcmAes128Xpn)
|
||||
.value("AES_256_XPN", MACsecCipherSuiteType::GcmAes256Xpn);
|
||||
|
||||
pybind11::class_<MACsecVLANTag, std::shared_ptr<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")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("mpls_label", &MACsecMPLSOuter::mplsLabel)
|
||||
.def_readwrite("exp", &MACsecMPLSOuter::exp);
|
||||
|
||||
pybind11::class_<MACsecRule, std::shared_ptr<MACsecRule>>(m, "MACsecRule")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("index", &MACsecRule::index)
|
||||
.def_readwrite("keyMacDa", &MACsecRule::keyMacDa)
|
||||
.def_readwrite("maskMacDa", &MACsecRule::maskMacDa)
|
||||
.def_readwrite("keyMacSa", &MACsecRule::keyMacSa)
|
||||
.def_readwrite("maskMacSa", &MACsecRule::maskMacSa)
|
||||
.def_readwrite("keyEthertype", &MACsecRule::keyEthertype)
|
||||
.def_readwrite("maskEthertype", &MACsecRule::maskEthertype)
|
||||
.def_readwrite("keyVlanTagOuter1", &MACsecRule::keyVlanTagOuter1)
|
||||
.def_readwrite("keyMplsOuter1", &MACsecRule::keyMplsOuter1)
|
||||
.def_readwrite("maskVlanTagOuter1", &MACsecRule::maskVlanTagOuter1)
|
||||
.def_readwrite("maskMplsOuter1", &MACsecRule::maskMplsOuter1)
|
||||
.def_readwrite("keyVlanTagOuter2", &MACsecRule::keyVlanTagOuter2)
|
||||
.def_readwrite("keyMplsOuter2", &MACsecRule::keyMplsOuter2)
|
||||
.def_readwrite("maskVlanTagOuter2", &MACsecRule::maskVlanTagOuter2)
|
||||
.def_readwrite("maskMplsOuter2", &MACsecRule::maskMplsOuter2)
|
||||
.def_readwrite("keyBonusData", &MACsecRule::keyBonusData)
|
||||
.def_readwrite("maskBonusData", &MACsecRule::maskBonusData)
|
||||
.def_readwrite("keyTagMatchBitmap", &MACsecRule::keyTagMatchBitmap)
|
||||
.def_readwrite("maskTagMatchBitmap", &MACsecRule::maskTagMatchBitmap)
|
||||
.def_readwrite("keyPacketType", &MACsecRule::keyPacketType)
|
||||
.def_readwrite("maskPacketType", &MACsecRule::maskPacketType)
|
||||
.def_readwrite("keyInnerVlanType", &MACsecRule::keyInnerVlanType)
|
||||
.def_readwrite("maskInnerVlanType", &MACsecRule::maskInnerVlanType)
|
||||
.def_readwrite("keyOuterVlanType", &MACsecRule::keyOuterVlanType)
|
||||
.def_readwrite("maskOuterVlanType", &MACsecRule::maskOuterVlanType)
|
||||
.def_readwrite("keyNumTags", &MACsecRule::keyNumTags)
|
||||
.def_readwrite("maskNumTags", &MACsecRule::maskNumTags)
|
||||
.def_readwrite("keyExpress", &MACsecRule::keyExpress)
|
||||
.def_readwrite("maskExpress", &MACsecRule::maskExpress)
|
||||
.def_readwrite("isMpls", &MACsecRule::isMpls)
|
||||
.def_readwrite("enable", &MACsecRule::enable);
|
||||
|
||||
pybind11::class_<MACsecMap, std::shared_ptr<MACsecMap>>(m, "MACsecMap")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("index", &MACsecMap::index)
|
||||
.def_readwrite("secTagSci", &MACsecMap::secTagSci)
|
||||
.def_readwrite("secYIndex", &MACsecMap::secYIndex)
|
||||
.def_readwrite("isControlPacket", &MACsecMap::isControlPacket)
|
||||
.def_readwrite("scIndex", &MACsecMap::scIndex)
|
||||
.def_readwrite("auxiliaryPlcy", &MACsecMap::auxiliaryPlcy)
|
||||
.def_readwrite("ruleId", &MACsecMap::ruleId)
|
||||
.def_readwrite("enable", &MACsecMap::enable);
|
||||
|
||||
pybind11::class_<MACsecSecY, std::shared_ptr<MACsecSecY>>(m, "MACsecSecY")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("index", &MACsecSecY::index)
|
||||
.def_readwrite("controlledPortEnabled", &MACsecSecY::controlledPortEnabled)
|
||||
.def_readwrite("frameValidationType", &MACsecSecY::frameValidationType)
|
||||
.def_readwrite("secTagIcvStripType", &MACsecSecY::secTagIcvStripType)
|
||||
.def_readwrite("cipher", &MACsecSecY::cipher)
|
||||
.def_readwrite("confidentialOffset", &MACsecSecY::confidentialOffset)
|
||||
.def_readwrite("icvIncludesDaSa", &MACsecSecY::icvIncludesDaSa)
|
||||
.def_readwrite("replayProtect", &MACsecSecY::replayProtect)
|
||||
.def_readwrite("replayWindow", &MACsecSecY::replayWindow)
|
||||
.def_readwrite("protectFrames", &MACsecSecY::protectFrames)
|
||||
.def_readwrite("secTagOffset", &MACsecSecY::secTagOffset)
|
||||
.def_readwrite("secTagTci", &MACsecSecY::secTagTci)
|
||||
.def_readwrite("mtu", &MACsecSecY::mtu)
|
||||
.def_readwrite("enable", &MACsecSecY::enable);
|
||||
|
||||
pybind11::class_<MACsecSc, std::shared_ptr<MACsecSc>>(m, "MACsecSc")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("index", &MACsecSc::index)
|
||||
.def_readwrite("secYIndex", &MACsecSc::secYIndex)
|
||||
.def_readwrite("sci", &MACsecSc::sci)
|
||||
.def_readwrite("saIndex0", &MACsecSc::saIndex0)
|
||||
.def_readwrite("saIndex1", &MACsecSc::saIndex1)
|
||||
.def_readwrite("saIndex0InUse", &MACsecSc::saIndex0InUse)
|
||||
.def_readwrite("saIndex1InUse", &MACsecSc::saIndex1InUse)
|
||||
.def_readwrite("enableAutoRekey", &MACsecSc::enableAutoRekey)
|
||||
.def_readwrite("isActiveSa1", &MACsecSc::isActiveSa1)
|
||||
.def_readwrite("enable", &MACsecSc::enable);
|
||||
|
||||
pybind11::class_<MACsecSa, std::shared_ptr<MACsecSa>>(m, "MACsecSa")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("index", &MACsecSa::index)
|
||||
.def_readwrite("sak", &MACsecSa::sak)
|
||||
.def_readwrite("hashKey", &MACsecSa::hashKey)
|
||||
.def_readwrite("salt", &MACsecSa::salt)
|
||||
.def_readwrite("ssci", &MACsecSa::ssci)
|
||||
.def_readwrite("an", &MACsecSa::an)
|
||||
.def_readwrite("nextPn", &MACsecSa::nextPn)
|
||||
.def_readwrite("enable", &MACsecSa::enable);
|
||||
|
||||
pybind11::class_<MACSecFlags, std::shared_ptr<MACSecFlags>>(m, "MACSecFlags")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("en", &MACSecFlags::en);
|
||||
|
||||
pybind11::class_<MACsecConfig, std::shared_ptr<MACsecConfig>>(m, "MACsecConfig")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("flags", &MACsecConfig::flags)
|
||||
.def_readwrite("rule", &MACsecConfig::rule)
|
||||
.def_readwrite("map", &MACsecConfig::map)
|
||||
.def_readwrite("secy", &MACsecConfig::secy)
|
||||
.def_readwrite("sc", &MACsecConfig::sc)
|
||||
.def_readwrite("sa", &MACsecConfig::sa);
|
||||
|
||||
pybind11::class_<MACSecGlobalFlags, std::shared_ptr<MACSecGlobalFlags>>(m, "MACSecGlobalFlags")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("en", &MACSecGlobalFlags::en)
|
||||
.def_readwrite("nvm", &MACSecGlobalFlags::nvm);
|
||||
|
||||
pybind11::class_<MACsecMessage, std::shared_ptr<MACsecMessage>>(m, "MACsecMessage")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("flags", &MACsecMessage::flags)
|
||||
.def_readwrite("rx", &MACsecMessage::rx)
|
||||
.def_readwrite("tx", &MACsecMessage::tx);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_mdiomessage(pybind11::module_& m) {
|
||||
pybind11::class_<MDIOMessage, std::shared_ptr<MDIOMessage>, BusMessage> mdioMessage(m, "MDIOMessage");
|
||||
pybind11::class_<MDIOMessage, std::shared_ptr<MDIOMessage>, Frame> mdioMessage(m, "MDIOMessage");
|
||||
pybind11::enum_<MDIOMessage::Clause>(mdioMessage, "Clause")
|
||||
.value("Clause45", MDIOMessage::Clause::Clause45)
|
||||
.value("Clause22", MDIOMessage::Clause::Clause22);
|
||||
|
||||
@@ -9,13 +9,13 @@ namespace icsneo {
|
||||
void init_message(pybind11::module_& m) {
|
||||
pybind11::class_<Message, std::shared_ptr<Message>> message(m, "Message");
|
||||
pybind11::enum_<Message::Type>(message, "Type")
|
||||
.value("BusMessage", Message::Type::BusMessage)
|
||||
.value("Frame", Message::Type::Frame)
|
||||
.value("CANErrorCount", Message::Type::CANErrorCount)
|
||||
.value("CANError", Message::Type::CANError)
|
||||
.value("LINHeaderOnly", Message::Type::LINHeaderOnly)
|
||||
.value("LINBreak", Message::Type::LINBreak)
|
||||
.value("Invalid", Message::Type::Invalid)
|
||||
.value("InternalMessage", Message::Type::InternalMessage)
|
||||
.value("RawMessage", Message::Type::RawMessage)
|
||||
.value("ReadSettings", Message::Type::ReadSettings)
|
||||
.value("ResetStatus", Message::Type::ResetStatus)
|
||||
.value("DeviceVersion", Message::Type::DeviceVersion)
|
||||
@@ -40,14 +40,14 @@ void init_message(pybind11::module_& m) {
|
||||
message.def_readonly("type", &Message::type);
|
||||
message.def_readwrite("timestamp", &Message::timestamp);
|
||||
|
||||
pybind11::class_<InternalMessage, std::shared_ptr<InternalMessage>, Message>(m, "InternalMessage")
|
||||
.def_readwrite("network", &InternalMessage::network)
|
||||
.def_readwrite("data", &InternalMessage::data);
|
||||
pybind11::class_<RawMessage, std::shared_ptr<RawMessage>, Message>(m, "RawMessage")
|
||||
.def_readwrite("network", &RawMessage::network)
|
||||
.def_readwrite("data", &RawMessage::data);
|
||||
|
||||
pybind11::class_<BusMessage, std::shared_ptr<BusMessage>, InternalMessage>(m, "BusMessage")
|
||||
.def_readwrite("description", &BusMessage::description)
|
||||
.def_readwrite("transmitted", &BusMessage::transmitted)
|
||||
.def_readwrite("error", &BusMessage::error);
|
||||
pybind11::class_<Frame, std::shared_ptr<Frame>, RawMessage>(m, "Frame")
|
||||
.def_readwrite("description", &Frame::description)
|
||||
.def_readwrite("transmitted", &Frame::transmitted)
|
||||
.def_readwrite("error", &Frame::error);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
#include "icsneo/communication/message/scriptstatusmessage.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_scriptstatusmessage(pybind11::module_& m) {
|
||||
pybind11::class_<ScriptStatusMessage, std::shared_ptr<ScriptStatusMessage>, Message>(m, "ScriptStatusMessage")
|
||||
.def_readonly("isEncrypted", &ScriptStatusMessage::isEncrypted)
|
||||
.def_readonly("isCoreminiRunning", &ScriptStatusMessage::isCoreminiRunning)
|
||||
.def_readonly("sectorOverflows", &ScriptStatusMessage::sectorOverflows)
|
||||
.def_readonly("numRemainingSectorBuffers", &ScriptStatusMessage::numRemainingSectorBuffers)
|
||||
.def_readonly("lastSector", &ScriptStatusMessage::lastSector)
|
||||
.def_readonly("readBinSize", &ScriptStatusMessage::readBinSize)
|
||||
.def_readonly("minSector", &ScriptStatusMessage::minSector)
|
||||
.def_readonly("maxSector", &ScriptStatusMessage::maxSector)
|
||||
.def_readonly("currentSector", &ScriptStatusMessage::currentSector)
|
||||
.def_readonly("coreminiCreateTime", &ScriptStatusMessage::coreminiCreateTime)
|
||||
.def_readonly("fileChecksum", &ScriptStatusMessage::fileChecksum)
|
||||
.def_readonly("coreminiVersion", &ScriptStatusMessage::coreminiVersion)
|
||||
.def_readonly("coreminiHeaderSize", &ScriptStatusMessage::coreminiHeaderSize)
|
||||
.def_readonly("diagnosticErrorCode", &ScriptStatusMessage::diagnosticErrorCode)
|
||||
.def_readonly("diagnosticErrorCodeCount", &ScriptStatusMessage::diagnosticErrorCodeCount)
|
||||
.def_readonly("maxCoreminiSizeKB", &ScriptStatusMessage::maxCoreminiSizeKB);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -11,25 +11,25 @@ void init_network(pybind11::module_& m) {
|
||||
|
||||
pybind11::enum_<Network::NetID>(network, "NetID")
|
||||
.value("Device", Network::NetID::Device)
|
||||
.value("HSCAN", Network::NetID::HSCAN)
|
||||
.value("MSCAN", Network::NetID::MSCAN)
|
||||
.value("SWCAN", Network::NetID::SWCAN)
|
||||
.value("LSFTCAN", Network::NetID::LSFTCAN)
|
||||
.value("DWCAN_01", Network::NetID::DWCAN_01)
|
||||
.value("DWCAN_08", Network::NetID::DWCAN_08)
|
||||
.value("SWCAN_01", Network::NetID::SWCAN_01)
|
||||
.value("LSFTCAN_01", Network::NetID::LSFTCAN_01)
|
||||
.value("FordSCP", Network::NetID::FordSCP)
|
||||
.value("J1708", Network::NetID::J1708)
|
||||
.value("Aux", Network::NetID::Aux)
|
||||
.value("J1850VPW", Network::NetID::J1850VPW)
|
||||
.value("ISO9141", Network::NetID::ISO9141)
|
||||
.value("ISO9141_01", Network::NetID::ISO9141_01)
|
||||
.value("DiskData", Network::NetID::DiskData)
|
||||
.value("Main51", Network::NetID::Main51)
|
||||
.value("RED", Network::NetID::RED)
|
||||
.value("SCI", Network::NetID::SCI)
|
||||
.value("ISO9141_2", Network::NetID::ISO9141_2)
|
||||
.value("ISO9141_02", Network::NetID::ISO9141_02)
|
||||
.value("ISO14230", Network::NetID::ISO14230)
|
||||
.value("LIN", Network::NetID::LIN)
|
||||
.value("OP_Ethernet1", Network::NetID::OP_Ethernet1)
|
||||
.value("OP_Ethernet2", Network::NetID::OP_Ethernet2)
|
||||
.value("OP_Ethernet3", Network::NetID::OP_Ethernet3)
|
||||
.value("LIN_01", Network::NetID::LIN_01)
|
||||
.value("AE_01", Network::NetID::AE_01)
|
||||
.value("AE_02", Network::NetID::AE_02)
|
||||
.value("AE_03", Network::NetID::AE_03)
|
||||
.value("RED_EXT_MEMORYREAD", Network::NetID::RED_EXT_MEMORYREAD)
|
||||
.value("RED_INT_MEMORYREAD", Network::NetID::RED_INT_MEMORYREAD)
|
||||
.value("RED_DFLASH_READ", Network::NetID::RED_DFLASH_READ)
|
||||
@@ -51,15 +51,15 @@ void init_network(pybind11::module_& m) {
|
||||
.value("RED_SCOPE_CAPTURE", Network::NetID::RED_SCOPE_CAPTURE)
|
||||
.value("RED_HARDWARE_EXCEP", Network::NetID::RED_HARDWARE_EXCEP)
|
||||
.value("RED_GET_RTC", Network::NetID::RED_GET_RTC)
|
||||
.value("ISO9141_3", Network::NetID::ISO9141_3)
|
||||
.value("HSCAN2", Network::NetID::HSCAN2)
|
||||
.value("HSCAN3", Network::NetID::HSCAN3)
|
||||
.value("OP_Ethernet4", Network::NetID::OP_Ethernet4)
|
||||
.value("OP_Ethernet5", Network::NetID::OP_Ethernet5)
|
||||
.value("ISO9141_4", Network::NetID::ISO9141_4)
|
||||
.value("LIN2", Network::NetID::LIN2)
|
||||
.value("LIN3", Network::NetID::LIN3)
|
||||
.value("LIN4", Network::NetID::LIN4)
|
||||
.value("ISO9141_03", Network::NetID::ISO9141_03)
|
||||
.value("DWCAN_02", Network::NetID::DWCAN_02)
|
||||
.value("DWCAN_03", Network::NetID::DWCAN_03)
|
||||
.value("AE_04", Network::NetID::AE_04)
|
||||
.value("AE_05", Network::NetID::AE_05)
|
||||
.value("ISO9141_04", Network::NetID::ISO9141_04)
|
||||
.value("LIN_02", Network::NetID::LIN_02)
|
||||
.value("LIN_03", Network::NetID::LIN_03)
|
||||
.value("LIN_04", Network::NetID::LIN_04)
|
||||
.value("RED_App_Error", Network::NetID::RED_App_Error)
|
||||
.value("CGI", Network::NetID::CGI)
|
||||
.value("Reset_Status", Network::NetID::Reset_Status)
|
||||
@@ -69,44 +69,44 @@ void init_network(pybind11::module_& m) {
|
||||
.value("Read_Datalink_Cm_Rx_Msg", Network::NetID::Read_Datalink_Cm_Rx_Msg)
|
||||
.value("Logging_Overflow", Network::NetID::Logging_Overflow)
|
||||
.value("ReadSettings", Network::NetID::ReadSettings)
|
||||
.value("HSCAN4", Network::NetID::HSCAN4)
|
||||
.value("HSCAN5", Network::NetID::HSCAN5)
|
||||
.value("DWCAN_04", Network::NetID::DWCAN_04)
|
||||
.value("DWCAN_05", Network::NetID::DWCAN_05)
|
||||
.value("RS232", Network::NetID::RS232)
|
||||
.value("UART", Network::NetID::UART)
|
||||
.value("UART2", Network::NetID::UART2)
|
||||
.value("UART3", Network::NetID::UART3)
|
||||
.value("UART4", Network::NetID::UART4)
|
||||
.value("SWCAN2", Network::NetID::SWCAN2)
|
||||
.value("Ethernet_DAQ", Network::NetID::Ethernet_DAQ)
|
||||
.value("UART_01", Network::NetID::UART_01)
|
||||
.value("UART_02", Network::NetID::UART_02)
|
||||
.value("UART_03", Network::NetID::UART_03)
|
||||
.value("UART_04", Network::NetID::UART_04)
|
||||
.value("SWCAN_02", Network::NetID::SWCAN_02)
|
||||
.value("ETHERNET_DAQ", Network::NetID::ETHERNET_DAQ)
|
||||
.value("Data_To_Host", Network::NetID::Data_To_Host)
|
||||
.value("TextAPI_To_Host", Network::NetID::TextAPI_To_Host)
|
||||
.value("SPI1", Network::NetID::SPI1)
|
||||
.value("OP_Ethernet6", Network::NetID::OP_Ethernet6)
|
||||
.value("SPI_01", Network::NetID::SPI_01)
|
||||
.value("AE_06", Network::NetID::AE_06)
|
||||
.value("Red_VBat", Network::NetID::Red_VBat)
|
||||
.value("OP_Ethernet7", Network::NetID::OP_Ethernet7)
|
||||
.value("OP_Ethernet8", Network::NetID::OP_Ethernet8)
|
||||
.value("OP_Ethernet9", Network::NetID::OP_Ethernet9)
|
||||
.value("OP_Ethernet10", Network::NetID::OP_Ethernet10)
|
||||
.value("OP_Ethernet11", Network::NetID::OP_Ethernet11)
|
||||
.value("FlexRay1a", Network::NetID::FlexRay1a)
|
||||
.value("FlexRay1b", Network::NetID::FlexRay1b)
|
||||
.value("FlexRay2a", Network::NetID::FlexRay2a)
|
||||
.value("FlexRay2b", Network::NetID::FlexRay2b)
|
||||
.value("LIN5", Network::NetID::LIN5)
|
||||
.value("FlexRay", Network::NetID::FlexRay)
|
||||
.value("FlexRay2", Network::NetID::FlexRay2)
|
||||
.value("OP_Ethernet12", Network::NetID::OP_Ethernet12)
|
||||
.value("I2C", Network::NetID::I2C)
|
||||
.value("MOST25", Network::NetID::MOST25)
|
||||
.value("MOST50", Network::NetID::MOST50)
|
||||
.value("MOST150", Network::NetID::MOST150)
|
||||
.value("Ethernet", Network::NetID::Ethernet)
|
||||
.value("AE_07", Network::NetID::AE_07)
|
||||
.value("AE_08", Network::NetID::AE_08)
|
||||
.value("AE_09", Network::NetID::AE_09)
|
||||
.value("AE_10", Network::NetID::AE_10)
|
||||
.value("AE_11", Network::NetID::AE_11)
|
||||
.value("FLEXRAY_01A", Network::NetID::FLEXRAY_01A)
|
||||
.value("FLEXRAY_01B", Network::NetID::FLEXRAY_01B)
|
||||
.value("FLEXRAY_02A", Network::NetID::FLEXRAY_02A)
|
||||
.value("FLEXRAY_02B", Network::NetID::FLEXRAY_02B)
|
||||
.value("LIN_05", Network::NetID::LIN_05)
|
||||
.value("FLEXRAY_01", Network::NetID::FLEXRAY_01)
|
||||
.value("FLEXRAY_02", Network::NetID::FLEXRAY_02)
|
||||
.value("AE_12", Network::NetID::AE_12)
|
||||
.value("I2C_01", Network::NetID::I2C_01)
|
||||
.value("MOST_25", Network::NetID::MOST_25)
|
||||
.value("MOST_50", Network::NetID::MOST_50)
|
||||
.value("MOST_150", Network::NetID::MOST_150)
|
||||
.value("ETHERNET_01", Network::NetID::ETHERNET_01)
|
||||
.value("GMFSA", Network::NetID::GMFSA)
|
||||
.value("TCP", Network::NetID::TCP)
|
||||
.value("HSCAN6", Network::NetID::HSCAN6)
|
||||
.value("HSCAN7", Network::NetID::HSCAN7)
|
||||
.value("LIN6", Network::NetID::LIN6)
|
||||
.value("LSFTCAN2", Network::NetID::LSFTCAN2)
|
||||
.value("DWCAN_06", Network::NetID::DWCAN_06)
|
||||
.value("DWCAN_07", Network::NetID::DWCAN_07)
|
||||
.value("LIN_06", Network::NetID::LIN_06)
|
||||
.value("LSFTCAN_02", Network::NetID::LSFTCAN_02)
|
||||
.value("LogicalDiskInfo", Network::NetID::LogicalDiskInfo)
|
||||
.value("WiVICommand", Network::NetID::WiVICommand)
|
||||
.value("ScriptStatus", Network::NetID::ScriptStatus)
|
||||
@@ -119,51 +119,52 @@ void init_network(pybind11::module_& m) {
|
||||
.value("DeviceStatus", Network::NetID::DeviceStatus)
|
||||
.value("UDP", Network::NetID::UDP)
|
||||
.value("ForwardedMessage", Network::NetID::ForwardedMessage)
|
||||
.value("I2C2", Network::NetID::I2C2)
|
||||
.value("I2C3", Network::NetID::I2C3)
|
||||
.value("I2C4", Network::NetID::I2C4)
|
||||
.value("Ethernet2", Network::NetID::Ethernet2)
|
||||
.value("A2B1", Network::NetID::A2B1)
|
||||
.value("A2B2", Network::NetID::A2B2)
|
||||
.value("Ethernet3", Network::NetID::Ethernet3)
|
||||
.value("WBMS", Network::NetID::WBMS)
|
||||
.value("DWCAN9", Network::NetID::DWCAN9)
|
||||
.value("DWCAN10", Network::NetID::DWCAN10)
|
||||
.value("DWCAN11", Network::NetID::DWCAN11)
|
||||
.value("DWCAN12", Network::NetID::DWCAN12)
|
||||
.value("DWCAN13", Network::NetID::DWCAN13)
|
||||
.value("DWCAN14", Network::NetID::DWCAN14)
|
||||
.value("DWCAN15", Network::NetID::DWCAN15)
|
||||
.value("DWCAN16", Network::NetID::DWCAN16)
|
||||
.value("LIN7", Network::NetID::LIN7)
|
||||
.value("LIN8", Network::NetID::LIN8)
|
||||
.value("SPI2", Network::NetID::SPI2)
|
||||
.value("MDIO1", Network::NetID::MDIO1)
|
||||
.value("MDIO2", Network::NetID::MDIO2)
|
||||
.value("MDIO3", Network::NetID::MDIO3)
|
||||
.value("MDIO4", Network::NetID::MDIO4)
|
||||
.value("MDIO5", Network::NetID::MDIO5)
|
||||
.value("MDIO6", Network::NetID::MDIO6)
|
||||
.value("MDIO7", Network::NetID::MDIO7)
|
||||
.value("MDIO8", Network::NetID::MDIO8)
|
||||
.value("OP_Ethernet13", Network::NetID::OP_Ethernet13)
|
||||
.value("OP_Ethernet14", Network::NetID::OP_Ethernet14)
|
||||
.value("OP_Ethernet15", Network::NetID::OP_Ethernet15)
|
||||
.value("OP_Ethernet16", Network::NetID::OP_Ethernet16)
|
||||
.value("SPI3", Network::NetID::SPI3)
|
||||
.value("SPI4", Network::NetID::SPI4)
|
||||
.value("SPI5", Network::NetID::SPI5)
|
||||
.value("SPI6", Network::NetID::SPI6)
|
||||
.value("SPI7", Network::NetID::SPI7)
|
||||
.value("SPI8", Network::NetID::SPI8)
|
||||
.value("LIN9", Network::NetID::LIN9)
|
||||
.value("LIN10", Network::NetID::LIN10)
|
||||
.value("LIN11", Network::NetID::LIN11)
|
||||
.value("LIN12", Network::NetID::LIN12)
|
||||
.value("LIN13", Network::NetID::LIN13)
|
||||
.value("LIN14", Network::NetID::LIN14)
|
||||
.value("LIN15", Network::NetID::LIN15)
|
||||
.value("LIN16", Network::NetID::LIN16)
|
||||
.value("I2C_02", Network::NetID::I2C_02)
|
||||
.value("I2C_03", Network::NetID::I2C_03)
|
||||
.value("I2C_04", Network::NetID::I2C_04)
|
||||
.value("ETHERNET_02", Network::NetID::ETHERNET_02)
|
||||
.value("ETHERNET_TX_WRAP", Network::NetID::ETHERNET_TX_WRAP)
|
||||
.value("A2B_01", Network::NetID::A2B_01)
|
||||
.value("A2B_02", Network::NetID::A2B_02)
|
||||
.value("ETHERNET_03", Network::NetID::ETHERNET_03)
|
||||
.value("WBMS_01", Network::NetID::WBMS_01)
|
||||
.value("DWCAN_09", Network::NetID::DWCAN_09)
|
||||
.value("DWCAN_10", Network::NetID::DWCAN_10)
|
||||
.value("DWCAN_11", Network::NetID::DWCAN_11)
|
||||
.value("DWCAN_12", Network::NetID::DWCAN_12)
|
||||
.value("DWCAN_13", Network::NetID::DWCAN_13)
|
||||
.value("DWCAN_14", Network::NetID::DWCAN_14)
|
||||
.value("DWCAN_15", Network::NetID::DWCAN_15)
|
||||
.value("DWCAN_16", Network::NetID::DWCAN_16)
|
||||
.value("LIN_07", Network::NetID::LIN_07)
|
||||
.value("LIN_08", Network::NetID::LIN_08)
|
||||
.value("SPI_02", Network::NetID::SPI_02)
|
||||
.value("MDIO_01", Network::NetID::MDIO_01)
|
||||
.value("MDIO_02", Network::NetID::MDIO_02)
|
||||
.value("MDIO_03", Network::NetID::MDIO_03)
|
||||
.value("MDIO_04", Network::NetID::MDIO_04)
|
||||
.value("MDIO_05", Network::NetID::MDIO_05)
|
||||
.value("MDIO_06", Network::NetID::MDIO_06)
|
||||
.value("MDIO_07", Network::NetID::MDIO_07)
|
||||
.value("MDIO_08", Network::NetID::MDIO_08)
|
||||
.value("AE_13", Network::NetID::AE_13)
|
||||
.value("AE_14", Network::NetID::AE_14)
|
||||
.value("AE_15", Network::NetID::AE_15)
|
||||
.value("AE_16", Network::NetID::AE_16)
|
||||
.value("SPI_03", Network::NetID::SPI_03)
|
||||
.value("SPI_04", Network::NetID::SPI_04)
|
||||
.value("SPI_05", Network::NetID::SPI_05)
|
||||
.value("SPI_06", Network::NetID::SPI_06)
|
||||
.value("SPI_07", Network::NetID::SPI_07)
|
||||
.value("SPI_08", Network::NetID::SPI_08)
|
||||
.value("LIN_09", Network::NetID::LIN_09)
|
||||
.value("LIN_10", Network::NetID::LIN_10)
|
||||
.value("LIN_11", Network::NetID::LIN_11)
|
||||
.value("LIN_12", Network::NetID::LIN_12)
|
||||
.value("LIN_13", Network::NetID::LIN_13)
|
||||
.value("LIN_14", Network::NetID::LIN_14)
|
||||
.value("LIN_15", Network::NetID::LIN_15)
|
||||
.value("LIN_16", Network::NetID::LIN_16)
|
||||
.value("Any", Network::NetID::Any)
|
||||
.value("Invalid", Network::NetID::Invalid);
|
||||
|
||||
@@ -178,7 +179,7 @@ void init_network(pybind11::module_& m) {
|
||||
.value("LSFTCAN", Network::Type::LSFTCAN)
|
||||
.value("SWCAN", Network::Type::SWCAN)
|
||||
.value("ISO9141", Network::Type::ISO9141)
|
||||
.value("I2C", Network::Type::I2C)
|
||||
.value("I2C_01", Network::Type::I2C)
|
||||
.value("A2B", Network::Type::A2B)
|
||||
.value("SPI", Network::Type::SPI)
|
||||
.value("MDIO", Network::Type::MDIO)
|
||||
|
||||
@@ -5,42 +5,54 @@
|
||||
|
||||
#include "icsneo/device/device.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_device(pybind11::module_& m) {
|
||||
pybind11::class_<Device, std::shared_ptr<Device>>(m, "Device")
|
||||
.def("get_type", &Device::getType)
|
||||
.def("get_serial", &Device::getSerial)
|
||||
.def("get_serial_number", &Device::getSerialNumber)
|
||||
.def("get_product_name", &Device::getProductName)
|
||||
.def("open", [](Device& device) { return device.open(); }, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("close", &Device::close, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("is_open", &Device::isOpen)
|
||||
.def("go_online", &Device::goOnline, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("go_offline", &Device::goOffline, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("is_online", &Device::isOnline)
|
||||
.def("enable_message_polling", &Device::enableMessagePolling, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("disable_message_polling", &Device::disableMessagePolling, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("is_message_polling_enabled", &Device::isMessagePollingEnabled)
|
||||
.def("get_messages", [](Device& device) { return device.getMessages(); }, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_current_message_count", &Device::getCurrentMessageCount)
|
||||
.def("get_polling_message_limit", &Device::getPollingMessageLimit)
|
||||
.def("set_polling_message_limit", &Device::setPollingMessageLimit)
|
||||
.def("__repr__", &Device::describe)
|
||||
.def("add_message_callback", &Device::addMessageCallback, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("remove_message_callback", &Device::removeMessageCallback, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("transmit", pybind11::overload_cast<std::shared_ptr<BusMessage>>(&Device::transmit), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("clear_script", &Device::clearScript, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("close", &Device::close, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("describe", &Device::describe)
|
||||
.def("disable_message_polling", &Device::disableMessagePolling, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("enable_message_polling", &Device::enableMessagePolling, pybind11::arg("filter") = std::nullopt, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_current_message_count", &Device::getCurrentMessageCount)
|
||||
.def("get_digital_io", &Device::getDigitalIO, pybind11::arg("type"), pybind11::arg("number"), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_gptp_status", &Device::getGPTPStatus, pybind11::arg("timeout") = std::chrono::milliseconds(100), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_messages", [](Device& device) { return device.getMessages(); }, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_polling_message_limit", &Device::getPollingMessageLimit)
|
||||
.def("get_product_name", &Device::getProductName)
|
||||
.def("get_rtc", &Device::getRTC, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.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_supported_rx_networks", &Device::getSupportedRXNetworks, pybind11::return_value_policy::reference)
|
||||
.def("get_supported_tx_networks", &Device::getSupportedTXNetworks, pybind11::return_value_policy::reference)
|
||||
.def("get_rtc", &Device::getRTC, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_rtc", &Device::setRTC, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("describe", &Device::describe)
|
||||
.def("is_online_supported", &Device::isOnlineSupported)
|
||||
.def("supports_tc10", &Device::supportsTC10)
|
||||
.def("request_tc10_wake", &Device::requestTC10Wake, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("request_tc10_sleep", &Device::requestTC10Sleep, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_tc10_status", &Device::getTC10Status, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_gptp_status", &Device::getGPTPStatus, pybind11::arg("timeout") = std::chrono::milliseconds(100), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("__repr__", &Device::describe);
|
||||
.def("get_type", &Device::getType)
|
||||
.def("go_offline", &Device::goOffline, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("go_online", &Device::goOnline, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("is_message_polling_enabled", &Device::isMessagePollingEnabled)
|
||||
.def("is_online_supported", &Device::isOnlineSupported)
|
||||
.def("is_online", &Device::isOnline)
|
||||
.def("is_open", &Device::isOpen)
|
||||
.def("open", [](Device& device) { return device.open(); }, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("prepare_script_load", &Device::prepareScriptLoad, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("remove_message_callback", &Device::removeMessageCallback, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("request_tc10_sleep", &Device::requestTC10Sleep, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("request_tc10_wake", &Device::requestTC10Wake, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_digital_io", pybind11::overload_cast<IO, size_t, bool>(&Device::setDigitalIO), pybind11::arg("type"), pybind11::arg("number"), pybind11::arg("value"), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_polling_message_limit", &Device::setPollingMessageLimit)
|
||||
.def("set_rtc", &Device::setRTC, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.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("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_readonly("settings", &Device::settings);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -33,6 +33,7 @@ void init_devicetype(pybind11::module_& m) {
|
||||
.value("EtherBADGE", DeviceType::Enum::EtherBADGE)
|
||||
.value("RAD_A2B", DeviceType::Enum::RAD_A2B)
|
||||
.value("RADEpsilon", DeviceType::Enum::RADEpsilon)
|
||||
.value("RADEpsilonXL", DeviceType::Enum::RADEpsilonXL)
|
||||
.value("RADGalaxy2", DeviceType::Enum::RADGalaxy2)
|
||||
.value("RADMoon3", DeviceType::Enum::RADMoon3)
|
||||
.value("RADComet", DeviceType::Enum::RADComet)
|
||||
@@ -48,10 +49,14 @@ void init_devicetype(pybind11::module_& m) {
|
||||
.value("OBD2_PRO", DeviceType::Enum::OBD2_PRO)
|
||||
.value("ECUChip_UART", DeviceType::Enum::ECUChip_UART)
|
||||
.value("PLASMA", DeviceType::Enum::PLASMA)
|
||||
.value("DONT_REUSE0", DeviceType::Enum::DONT_REUSE0)
|
||||
.value("NEOAnalog", DeviceType::Enum::NEOAnalog)
|
||||
.value("CT_OBD", DeviceType::Enum::CT_OBD)
|
||||
.value("DONT_REUSE1", DeviceType::Enum::DONT_REUSE1)
|
||||
.value("DONT_REUSE2", DeviceType::Enum::DONT_REUSE2)
|
||||
.value("ION", DeviceType::Enum::ION)
|
||||
.value("RADStar", DeviceType::Enum::RADStar)
|
||||
.value("DONT_REUSE3", DeviceType::Enum::DONT_REUSE3)
|
||||
.value("VCAN4_4", DeviceType::Enum::VCAN4_4)
|
||||
.value("VCAN4_2", DeviceType::Enum::VCAN4_2)
|
||||
.value("CMProbe", DeviceType::Enum::CMProbe)
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/stl_bind.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/chrono.h>
|
||||
|
||||
#include "icsneo/device/idevicesettings.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
struct DeviceSettingsNamespace {
|
||||
using EthLinkMode = AELinkMode;
|
||||
using LinkSpeed = EthLinkSpeed;
|
||||
};
|
||||
|
||||
void init_idevicesettings(pybind11::module_& m) {
|
||||
pybind11::class_<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::class_<IDeviceSettings, std::shared_ptr<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("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::arg("ignoreChecksum") = 0, pybind11::call_guard<pybind11::gil_scoped_release>());
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
#include "icsneo/disk/diskdriver.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
// binding namespace workaround to avoid submodules
|
||||
struct DiskNamespace {
|
||||
using Access = icsneo::Disk::Access;
|
||||
using MemoryType = icsneo::Disk::MemoryType;
|
||||
};
|
||||
|
||||
void init_diskdriver(pybind11::module_& m) {
|
||||
pybind11::class_<DiskNamespace> disk(m, "Disk");
|
||||
pybind11::enum_<Disk::Access>(disk, "Access")
|
||||
.value("None", Disk::Access::None)
|
||||
.value("EntireCard", Disk::Access::EntireCard)
|
||||
.value("VSA", Disk::Access::VSA);
|
||||
pybind11::enum_<Disk::MemoryType>(disk, "MemoryType")
|
||||
.value("Flash", Disk::MemoryType::Flash)
|
||||
.value("SD", Disk::MemoryType::SD);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -10,6 +10,7 @@ void init_event(pybind11::module_&);
|
||||
void init_eventcallback(pybind11::module_&);
|
||||
void init_eventmanager(pybind11::module_&);
|
||||
void init_network(pybind11::module_&);
|
||||
void init_io(pybind11::module_&);
|
||||
void init_devicetype(pybind11::module_&);
|
||||
void init_message(pybind11::module_&);
|
||||
void init_canmessage(pybind11::module_&);
|
||||
@@ -20,10 +21,15 @@ void init_tc10statusmessage(pybind11::module_&);
|
||||
void init_gptpstatusmessage(pybind11::module_&);
|
||||
void init_mdiomessage(pybind11::module_&);
|
||||
void init_ethernetstatusmessage(pybind11::module_&);
|
||||
void init_macsecmessage(pybind11::module_&);
|
||||
void init_scriptstatusmessage(pybind11::module_&);
|
||||
void init_diskdriver(pybind11::module_&);
|
||||
void init_device(pybind11::module_&);
|
||||
void init_messagefilter(pybind11::module_&);
|
||||
void init_messagecallback(pybind11::module_&);
|
||||
void init_version(pybind11::module_&);
|
||||
void init_flexraymessage(pybind11::module_& m);
|
||||
void init_idevicesettings(pybind11::module_&);
|
||||
|
||||
PYBIND11_MODULE(icsneopy, m) {
|
||||
pybind11::options options;
|
||||
@@ -36,6 +42,7 @@ PYBIND11_MODULE(icsneopy, m) {
|
||||
init_version(m);
|
||||
init_devicetype(m);
|
||||
init_network(m);
|
||||
init_io(m);
|
||||
init_message(m);
|
||||
init_canmessage(m);
|
||||
init_canerrormessage(m);
|
||||
@@ -45,9 +52,14 @@ PYBIND11_MODULE(icsneopy, m) {
|
||||
init_gptpstatusmessage(m);
|
||||
init_mdiomessage(m);
|
||||
init_ethernetstatusmessage(m);
|
||||
init_macsecmessage(m);
|
||||
init_scriptstatusmessage(m);
|
||||
init_messagefilter(m);
|
||||
init_messagecallback(m);
|
||||
init_diskdriver(m);
|
||||
init_device(m);
|
||||
init_flexraymessage(m);
|
||||
init_idevicesettings(m);
|
||||
|
||||
m.def("find_all_devices", &FindAllDevices);
|
||||
m.def("get_supported_devices", &GetSupportedDevices);
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
|
||||
# RustRover
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
Generated
-293
@@ -1,293 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bindgen"
|
||||
version = "0.71.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cexpr",
|
||||
"clang-sys",
|
||||
"itertools",
|
||||
"log",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
|
||||
|
||||
[[package]]
|
||||
name = "cexpr"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
||||
dependencies = [
|
||||
"nom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "clang-sys"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
|
||||
dependencies = [
|
||||
"glob",
|
||||
"libc",
|
||||
"libloading",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
|
||||
|
||||
[[package]]
|
||||
name = "icsneoc2rs"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.169"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prettyplease"
|
||||
version = "0.2.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6924ced06e1f7dfe3fa48d57b9f74f55d8915f5036121bef647ef4b204895fac"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.93"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497"
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.96"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
@@ -1,22 +0,0 @@
|
||||
[package]
|
||||
name = "icsneoc2rs"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "icsneoc2rs"
|
||||
crate-type = ["rlib", "staticlib", "cdylib"]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[example]]
|
||||
name = "simple"
|
||||
path = "examples/simple.rs"
|
||||
|
||||
[dev-dependencies]
|
||||
scopeguard = "1.2.0"
|
||||
|
||||
[features]
|
||||
static = []
|
||||
|
||||
[build-dependencies]
|
||||
bindgen = "0.71.1"
|
||||
@@ -1,40 +0,0 @@
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn main() {
|
||||
// Tell cargo to look for shared libraries in the specified directory
|
||||
println!("cargo:rustc-link-search=../../../build");
|
||||
|
||||
// Tell cargo to tell rustc to link the system
|
||||
// shared library.
|
||||
println!("cargo:rustc-link-lib=icsneoc2");
|
||||
|
||||
// The bindgen::Builder is the main entry point
|
||||
// to bindgen, and lets you build up options for
|
||||
// the resulting bindings.
|
||||
let bindings = bindgen::Builder::default()
|
||||
// The input header we would like to generate
|
||||
// bindings for.
|
||||
.header("../../../include/icsneo/icsneoc2.h")
|
||||
.clang_arg("-I../../../include")
|
||||
// Tell cargo to invalidate the built crate whenever any of the
|
||||
// included header files changed.
|
||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
||||
.derive_default(true)
|
||||
.derive_debug(true)
|
||||
.derive_partialeq(true)
|
||||
.derive_copy(true)
|
||||
.default_enum_style(bindgen::EnumVariation::Rust { non_exhaustive: true })
|
||||
.default_alias_style(bindgen::AliasVariation::TypeAlias)
|
||||
.generate_cstr(true)
|
||||
// Finish the builder and generate the bindings.
|
||||
.generate()
|
||||
// Unwrap the Result and panic on failure.
|
||||
.expect("Unable to generate bindings");
|
||||
|
||||
// Write the bindings to the $OUT_DIR/bindings.rs file.
|
||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
bindings
|
||||
.write_to_file(out_path.join("bindings.rs"))
|
||||
.expect("Couldn't write bindings!");
|
||||
}
|
||||
@@ -1,333 +0,0 @@
|
||||
use icsneoc2rs::ffi::_icsneoc2_msg_bus_type_t::*;
|
||||
use icsneoc2rs::ffi::_icsneoc2_msg_type_t::*;
|
||||
use icsneoc2rs::ffi::_icsneoc2_netid_t;
|
||||
use icsneoc2rs::ffi::_icsneoc2_netid_t::*;
|
||||
use icsneoc2rs::ffi::_icsneoc2_open_options_t::*;
|
||||
use icsneoc2rs::ffi::icsneoc2_message_t;
|
||||
use icsneoc2rs::ffi::icsneoc2_msg_bus_type_t;
|
||||
use icsneoc2rs::ffi::icsneoc2_msg_type_t;
|
||||
use icsneoc2rs::ffi::icsneoc2_netid_t;
|
||||
use icsneoc2rs::Device;
|
||||
use icsneoc2rs::Error;
|
||||
use icsneoc2rs::Result as ICSNeoResult;
|
||||
|
||||
use scopeguard::defer;
|
||||
|
||||
fn main() -> ICSNeoResult<()> {
|
||||
print!("Finding devices... ");
|
||||
let devices = Device::find_all(255)?;
|
||||
println!(
|
||||
"OK, {} device{} found...",
|
||||
devices.len(),
|
||||
if devices.len() > 1 { "s" } else { "" }
|
||||
);
|
||||
for device in devices {
|
||||
device.device_is_valid()?;
|
||||
// Get description of the device
|
||||
let description = match device.device_description_get() {
|
||||
Ok(description) => description,
|
||||
Err(err) => {
|
||||
println!("Failed to get description of device: {err}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("{} @ Handle {:?}", description, device.handle);
|
||||
// Get/Set open options
|
||||
let mut open_options = match device.device_open_options_get() {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
println!("Failed to get open options of device: {err}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
// Disable Syncing RTC and going online
|
||||
open_options &= !(icsneoc2_open_options_sync_rtc as u32);
|
||||
open_options &= !(icsneoc2_open_options_go_online as u32);
|
||||
match device.device_open_options_set(open_options) {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
print_error(&device, &description, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("\tDevice open options: {open_options:#02x}");
|
||||
// Open the device
|
||||
print!("\tOpening device... ");
|
||||
match device.device_open() {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
print_error(&device, &description, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("OK");
|
||||
defer! {
|
||||
print_device_events(&device, &description).expect("Critical: Failed to print device events");
|
||||
}
|
||||
// Get timestamp resolution of the device
|
||||
print!("\tGetting timestamp resolution... ");
|
||||
let timestamp_resolution = match device.device_timestamp_resolution_get() {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
print_error(&device, &description, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("{timestamp_resolution}ns");
|
||||
// Get baudrates for HSCAN
|
||||
print!("\tGetting HSCAN baudrate... ");
|
||||
let baudrate = match device.device_baudrate_get(icsneoc2_netid_hscan) {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
print_error(&device, &description, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("{baudrate}mbit/s");
|
||||
// Get FD baudrates for HSCAN
|
||||
print!("\tGetting FD HSCAN baudrate... ");
|
||||
let fd_baudrate = match device.device_canfd_baudrate_get(icsneoc2_netid_hscan) {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
print_error(&device, &description, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("{fd_baudrate}mbit/s");
|
||||
// Set baudrates for HSCAN
|
||||
// saveToDevice: If this is set to true, the baudrate will be saved on the device
|
||||
// and will persist through a power cycle
|
||||
print!("\tSetting HSCAN baudrate... ");
|
||||
let save_to_device = false;
|
||||
match device.device_baudrate_set(icsneoc2_netid_hscan, baudrate, save_to_device) {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
print_error(&device, &description, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("OK");
|
||||
// Set FD baudrates for HSCAN
|
||||
print!("\tSetting FD HSCAN baudrate... ");
|
||||
match device.device_canfd_baudrate_set(icsneoc2_netid_hscan, fd_baudrate, save_to_device) {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
print_error(&device, &description, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("OK");
|
||||
// Get RTC
|
||||
print!("\tGetting RTC... ");
|
||||
let current_rtc = match device.device_rtc_get() {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
print_error(&device, &description, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("{current_rtc}");
|
||||
// Set RTC
|
||||
print!("\tSetting RTC... ");
|
||||
match device.device_rtc_set(current_rtc) {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
print_error(&device, &description, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("OK");
|
||||
// Get RTC
|
||||
print!("\tGetting RTC... ");
|
||||
let rtc = match device.device_rtc_get() {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
print_error(&device, &description, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("{rtc}");
|
||||
// Go online, start acking traffic
|
||||
print!("\tGoing online... ");
|
||||
match device.device_go_online(true) {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
print_error(&device, &description, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
// 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
|
||||
let is_online = match device.device_is_online() {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
print_error(&device, &description, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("{}", if is_online { "Online" } else { "Offline" });
|
||||
// Transmit CAN messages
|
||||
if transmit_can_messages(&device).is_err() {
|
||||
continue;
|
||||
}
|
||||
println!("\tWaiting 1 second for messages...");
|
||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||
// Get the messages
|
||||
let messages = match device.device_messages_get(20000, 3000) {
|
||||
Ok(messages) => messages,
|
||||
Err(err) => {
|
||||
print_error(&device, &description, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
// Process the messages
|
||||
if process_messages(&device, messages).is_err() {
|
||||
continue;
|
||||
}
|
||||
// Close the device
|
||||
print!("\tClosing device... ");
|
||||
match device.device_close() {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
print_error(&device, &description, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("OK");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_error(device: &Device, device_description: &String, err: Error) {
|
||||
println!("Failed: {err}");
|
||||
print_device_events(device, device_description)
|
||||
.expect("Critical: Failed to print device events");
|
||||
}
|
||||
|
||||
fn transmit_can_messages(device: &Device) -> ICSNeoResult<()> {
|
||||
const MESSAGE_COUNT: usize = 100;
|
||||
println!("\tTransmitting {MESSAGE_COUNT} messages...");
|
||||
for i in 0..MESSAGE_COUNT {
|
||||
let message = match device.message_can_create(1) {
|
||||
Ok(messages) => messages[0],
|
||||
Err(err) => {
|
||||
println!("Failed to create CAN message #{i}: {err}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
device.message_netid_set(message, icsneoc2_netid_hscan)?;
|
||||
device.message_can_arbid_set(message, 0x10)?;
|
||||
device.message_can_canfd_set(message, true)?;
|
||||
device.message_can_extended_set(message, true)?;
|
||||
device.message_can_baudrate_switch_set(message, true)?;
|
||||
device.message_data_set(
|
||||
message,
|
||||
vec![
|
||||
(i >> 56 & 0xFF) as u8,
|
||||
(i >> 48 & 0xFF) as u8,
|
||||
(i >> 40 & 0xFF) as u8,
|
||||
(i >> 32 & 0xFF) as u8,
|
||||
(i >> 24 & 0xFF) as u8,
|
||||
(i >> 16 & 0xFF) as u8,
|
||||
(i >> 8 & 0xFF) as u8,
|
||||
(i & 0xFF) as u8,
|
||||
],
|
||||
)?;
|
||||
device.message_can_dlc_set(message, -1)?;
|
||||
device.device_messages_transmit(vec![message])?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn process_messages(device: &Device, messages: Vec<*mut icsneoc2_message_t>) -> ICSNeoResult<()> {
|
||||
let mut tx_count: u32 = 0;
|
||||
for (i, message) in messages.iter().enumerate() {
|
||||
// Get the message type
|
||||
let msg_type = device.message_type_get(*message)?;
|
||||
// Get the message type name
|
||||
let msg_type_name = device.message_type_name_get(msg_type)?;
|
||||
// Check if the message is a bus message, ignore otherwise
|
||||
if msg_type != icsneoc2_msg_type_bus as icsneoc2_msg_type_t {
|
||||
println!("\tIgnoring message type : {msg_type} ({msg_type_name})");
|
||||
continue;
|
||||
}
|
||||
// Get the message bus type
|
||||
let msg_bus_type = device.message_bus_type_get(*message)?;
|
||||
// Get the message type name
|
||||
let msg_bus_type_name = device.bus_type_name_get(msg_bus_type)?;
|
||||
// Check if message is a transmit message
|
||||
if device.message_is_transmit(*message)? {
|
||||
tx_count += 1;
|
||||
continue;
|
||||
}
|
||||
println!("\t{i} Message type: {msg_type} bus type: {msg_bus_type_name} ({msg_bus_type})\n");
|
||||
// Check if the message is a CAN message, ignore otherwise
|
||||
if msg_bus_type == icsneoc2_msg_bus_type_can as icsneoc2_msg_bus_type_t {
|
||||
let netid = device.message_netid_get(*message)?;
|
||||
let netid_name = device.netid_name_get(netid)?;
|
||||
let arbid = device.message_can_arbid_get(*message)?;
|
||||
let dlc = device.message_can_dlc_get(*message)?;
|
||||
let is_remote = device.message_can_is_remote(*message)?;
|
||||
let is_canfd = device.message_can_is_canfd(*message)?;
|
||||
let is_extended = device.message_can_is_extended(*message)?;
|
||||
let data = device.message_data_get(*message, 64)?;
|
||||
// Finally lets print the RX message
|
||||
println!("\t NetID: {netid_name} ({:#02x})\tArbID: {arbid:#02x}\t DLC: {dlc}\t Remote: {is_remote}\t \
|
||||
CANFD: {is_canfd}\t Extended: {is_extended}\t Data length: {}\n", netid as icsneoc2_netid_t,data.len());
|
||||
println!("\t Data: {data:#02x?}\n");
|
||||
} else {
|
||||
println!("\tIgnoring bus message type: {msg_bus_type} ({msg_bus_type_name})\n");
|
||||
}
|
||||
}
|
||||
println!(
|
||||
"\tReceived {} messages total, {} were TX messages",
|
||||
messages.len(),
|
||||
tx_count
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_device_events(device: &Device, device_description: &String) -> ICSNeoResult<()> {
|
||||
let events = match device.device_events_get(1024) {
|
||||
Ok(events) => events,
|
||||
Err(err) => {
|
||||
println!("Failed to get device events: {err}");
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
for (i, event) in events.iter().enumerate() {
|
||||
let description = match device.event_description_get(*event) {
|
||||
Ok(description) => description,
|
||||
Err(err) => {
|
||||
println!("Failed to get event description: {err}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("\t{device_description}: Event {i}: {description}");
|
||||
}
|
||||
// Get global events
|
||||
let global_events = match device.events_get(1024) {
|
||||
Ok(events) => events,
|
||||
Err(err) => {
|
||||
println!("Failed to get global events: {err}");
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
for (i, event) in global_events.iter().enumerate() {
|
||||
let description = match device.event_description_get(*event) {
|
||||
Ok(description) => description,
|
||||
Err(err) => {
|
||||
println!("Failed to get event description: {err}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
println!("\t{device_description}: Global Event {i}: {description}");
|
||||
}
|
||||
println!(
|
||||
"\t{device_description}: Received {} events and {} global events\n",
|
||||
events.len(),
|
||||
global_events.len()
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
@@ -1,902 +0,0 @@
|
||||
pub mod ffi;
|
||||
|
||||
use ffi::_icsneoc2_error_t::{icsneoc2_error_invalid_device, icsneoc2_error_success};
|
||||
use ffi::_icsneoc2_open_options_t::*;
|
||||
use ffi::*;
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::fmt::Display;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Error {
|
||||
/// icsneoc2 API error
|
||||
APIError(icsneoc2_error_t, String),
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Error::APIError(error_code, error_string) => write!(f, "API Error: \"{}\" ({})", error_string, error_code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type Result<T> = core::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Device {
|
||||
/// Handle to the device.
|
||||
pub handle: *mut icsneoc2_device_t,
|
||||
}
|
||||
|
||||
impl Drop for Device {
|
||||
fn drop(&mut self) {
|
||||
// Make sure the device is closed before we go out of scope.
|
||||
self.device_close().expect("Failed to close device!");
|
||||
}
|
||||
}
|
||||
|
||||
impl Device {
|
||||
pub fn find_all(device_count: u32) -> Result<Vec<Self>> {
|
||||
// Find all the devices
|
||||
const MAX_DEVICE_COUNT: u32 = 255;
|
||||
let mut devices: [*mut icsneoc2_device_t; MAX_DEVICE_COUNT as usize] =
|
||||
[std::ptr::null_mut(); 255];
|
||||
let mut devices_count: u32 = if device_count > MAX_DEVICE_COUNT {
|
||||
MAX_DEVICE_COUNT
|
||||
} else {
|
||||
device_count
|
||||
};
|
||||
let res = unsafe {
|
||||
icsneoc2_device_find_all(
|
||||
devices.as_mut_ptr(),
|
||||
&mut devices_count as *mut u32,
|
||||
std::ptr::null_mut(),
|
||||
)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
// Return the results
|
||||
let found_devices: Vec<Self> = devices[..devices_count as usize]
|
||||
.iter()
|
||||
.map(|d| Self { handle: *d })
|
||||
.collect();
|
||||
Ok(found_devices)
|
||||
}
|
||||
|
||||
pub fn bus_type_name_get(&self, bus_type: icsneoc2_msg_bus_type_t) -> Result<String> {
|
||||
// Get the string
|
||||
let mut str: Vec<u8> = vec![0; 255];
|
||||
let mut str_length: u32 = 255;
|
||||
let res = unsafe {
|
||||
icsneoc2_bus_type_name_get(bus_type, str.as_mut_ptr() as *mut i8, &mut str_length)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
// Convert the vec to an String
|
||||
str.resize(str_length as usize, 0);
|
||||
let str_string = {
|
||||
CString::new(str)
|
||||
.expect("CString::new failed")
|
||||
.into_string()
|
||||
.expect("CString::new::into_string")
|
||||
};
|
||||
Ok(str_string)
|
||||
}
|
||||
|
||||
pub fn device_baudrate_get(&self, netid: _icsneoc2_netid_t) -> Result<u64> {
|
||||
let mut value: u64 = 0;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_baudrate_get(self.handle, netid as icsneoc2_netid_t, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn device_baudrate_set(
|
||||
&self,
|
||||
netid: _icsneoc2_netid_t,
|
||||
value: u64,
|
||||
save: bool,
|
||||
) -> Result<()> {
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_baudrate_set(self.handle, netid as icsneoc2_netid_t, value, save) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn device_canfd_baudrate_get(&self, netid: _icsneoc2_netid_t) -> Result<u64> {
|
||||
let mut value: u64 = 0;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_canfd_baudrate_get(self.handle, netid as icsneoc2_netid_t, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn device_canfd_baudrate_set(
|
||||
&self,
|
||||
netid: _icsneoc2_netid_t,
|
||||
value: u64,
|
||||
save: bool,
|
||||
) -> Result<()> {
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_canfd_baudrate_set(self.handle, netid as icsneoc2_netid_t, value, save) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn device_close(&self) -> Result<()> {
|
||||
let res: icsneoc2_error_t = unsafe { ffi::icsneoc2_device_close(self.handle) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn device_description_get(&self) -> Result<String> {
|
||||
// Get the error code
|
||||
let mut description: Vec<u8> = vec![0; 255];
|
||||
let mut description_length: u32 = 255;
|
||||
let res = unsafe {
|
||||
icsneoc2_device_description_get(
|
||||
self.handle,
|
||||
description.as_mut_ptr() as *mut i8,
|
||||
&mut description_length,
|
||||
)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
// Convert the vec to an String
|
||||
description.resize(description_length as usize, 0);
|
||||
let description_str = {
|
||||
CString::new(description)
|
||||
.expect("CString::new failed")
|
||||
.into_string()
|
||||
.expect("CString::new::into_string")
|
||||
};
|
||||
Ok(description_str)
|
||||
}
|
||||
|
||||
pub fn device_events_get(&self, event_count: u32) -> Result<Vec<*mut icsneoc2_event_t>> {
|
||||
let mut events: Vec<*mut icsneoc2_event_t> =
|
||||
vec![std::ptr::null_mut(); event_count as usize];
|
||||
let mut event_count: u32 = event_count;
|
||||
let res: icsneoc2_error_t = unsafe {
|
||||
ffi::icsneoc2_device_events_get(self.handle, events.as_mut_ptr(), &mut event_count)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
events.resize(event_count as usize, std::ptr::null_mut());
|
||||
Ok(events)
|
||||
}
|
||||
|
||||
pub fn device_go_online(&self, go_online: bool) -> Result<()> {
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_go_online(self.handle, go_online) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn device_is_online(&self) -> Result<bool> {
|
||||
let mut is_online: bool = false;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_is_online(self.handle, &mut is_online) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(is_online)
|
||||
}
|
||||
|
||||
pub fn device_is_online_supported(&self) -> Result<bool> {
|
||||
let mut is_online_supported: bool = false;
|
||||
let res: icsneoc2_error_t = unsafe {
|
||||
ffi::icsneoc2_device_is_online_supported(self.handle, &mut is_online_supported)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(is_online_supported)
|
||||
}
|
||||
|
||||
pub fn device_is_valid(&self) -> Result<bool> {
|
||||
let res: icsneoc2_error_t = unsafe { icsneoc2_device_is_valid(self.handle) };
|
||||
match res {
|
||||
res if res == icsneoc2_error_success as icsneoc2_error_t => Ok(true),
|
||||
res if res == icsneoc2_error_invalid_device as icsneoc2_error_t => Ok(false),
|
||||
_ => Err(Self::error_code_get(res)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn device_is_open(&self) -> Result<bool> {
|
||||
let mut is_open: bool = false;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_is_open(self.handle, &mut is_open) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(is_open)
|
||||
}
|
||||
|
||||
pub fn device_is_disconnected(&self) -> Result<bool> {
|
||||
let mut is_disconnected: bool = false;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_is_disconnected(self.handle, &mut is_disconnected) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(is_disconnected)
|
||||
}
|
||||
|
||||
pub fn device_load_default_settings(&self, save: bool) -> Result<()> {
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_load_default_settings(self.handle, save) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn device_message_count_get(&self) -> Result<u32> {
|
||||
let mut value: u32 = 0;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_message_count_get(self.handle, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn device_message_polling_get(&self) -> Result<bool> {
|
||||
let mut value: bool = false;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_message_polling_get(self.handle, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn device_message_polling_limit_get(&self) -> Result<u32> {
|
||||
let mut value: u32 = 0;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_message_polling_limit_get(self.handle, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn device_message_polling_set(&self, enable: bool) -> Result<()> {
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_message_polling_set(self.handle, enable) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn device_message_polling_set_limit(&self, value: u32) -> Result<()> {
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_message_polling_set_limit(self.handle, value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn device_messages_get(
|
||||
&self,
|
||||
message_count: u32,
|
||||
timeout_ms: u32,
|
||||
) -> Result<Vec<*mut icsneoc2_message_t>> {
|
||||
let mut messages: Vec<*mut icsneoc2_message_t> =
|
||||
vec![std::ptr::null_mut(); message_count as usize];
|
||||
let mut message_count: u32 = message_count;
|
||||
let res: icsneoc2_error_t = unsafe {
|
||||
ffi::icsneoc2_device_messages_get(
|
||||
self.handle,
|
||||
messages.as_mut_ptr(),
|
||||
&mut message_count,
|
||||
timeout_ms,
|
||||
)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
messages.resize(message_count as usize, std::ptr::null_mut());
|
||||
Ok(messages)
|
||||
}
|
||||
|
||||
pub fn device_messages_transmit(&self, messages: Vec<*mut icsneoc2_message_t>) -> Result<u32> {
|
||||
let mut messages_count: u32 = messages.len() as u32;
|
||||
let mut messages = messages;
|
||||
let res: icsneoc2_error_t = unsafe {
|
||||
ffi::icsneoc2_device_messages_transmit(
|
||||
self.handle,
|
||||
messages.as_mut_ptr(),
|
||||
&mut messages_count,
|
||||
)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(messages_count)
|
||||
}
|
||||
|
||||
pub fn device_open(&self) -> Result<()> {
|
||||
let res: icsneoc2_error_t = unsafe { ffi::icsneoc2_device_open(self.handle) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn device_open_options_get(&self) -> Result<ffi::icsneoc2_open_options_t> {
|
||||
let mut open_options: ffi::icsneoc2_open_options_t =
|
||||
icsneoc2_open_options_none as ffi::icsneoc2_open_options_t;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_open_options_get(self.handle, &mut open_options) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(open_options)
|
||||
}
|
||||
|
||||
pub fn device_open_options_set(
|
||||
&self,
|
||||
open_options: ffi::icsneoc2_open_options_t,
|
||||
) -> Result<()> {
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_open_options_set(self.handle, open_options) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn device_rtc_get(&self) -> Result<i64> {
|
||||
let mut value: i64 = 0;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_rtc_get(self.handle, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn device_rtc_set(&self, value: i64) -> Result<()> {
|
||||
let res: icsneoc2_error_t = unsafe { ffi::icsneoc2_device_rtc_set(self.handle, value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn device_serial_get(&self) -> Result<String> {
|
||||
// Get the string
|
||||
let mut str: Vec<u8> = vec![0; 255];
|
||||
let mut str_length: u32 = 255;
|
||||
let res = unsafe {
|
||||
icsneoc2_device_serial_get(self.handle, str.as_mut_ptr() as *mut i8, &mut str_length)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
// Convert the vec to an String
|
||||
str.resize(str_length as usize, 0);
|
||||
let str_string = {
|
||||
CString::new(str)
|
||||
.expect("CString::new failed")
|
||||
.into_string()
|
||||
.expect("CString::new::into_string")
|
||||
};
|
||||
Ok(str_string)
|
||||
}
|
||||
|
||||
pub fn device_supports_tc10(&self) -> Result<bool> {
|
||||
let mut value: bool = false;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_supports_tc10(self.handle, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn device_timestamp_resolution_get(&self) -> Result<u32> {
|
||||
let mut timestamp_resolution: u32 = 0;
|
||||
let res: icsneoc2_error_t = unsafe {
|
||||
ffi::icsneoc2_device_timestamp_resolution_get(self.handle, &mut timestamp_resolution)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(timestamp_resolution)
|
||||
}
|
||||
|
||||
pub fn device_type_from_type(&self, device_type: icsneoc2_devicetype_t) -> Result<String> {
|
||||
// Get the string
|
||||
let mut str: Vec<u8> = vec![0; 255];
|
||||
let mut str_length: u32 = 255;
|
||||
let res = unsafe {
|
||||
icsneoc2_device_type_name_get(
|
||||
device_type,
|
||||
str.as_mut_ptr() as *mut i8,
|
||||
&mut str_length,
|
||||
)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
// Convert the vec to an String
|
||||
str.resize(str_length as usize, 0);
|
||||
let str_string = {
|
||||
CString::new(str)
|
||||
.expect("CString::new failed")
|
||||
.into_string()
|
||||
.expect("CString::new::into_string")
|
||||
};
|
||||
Ok(str_string)
|
||||
}
|
||||
|
||||
pub fn device_type_get(&self) -> Result<icsneoc2_devicetype_t> {
|
||||
let mut value: icsneoc2_devicetype_t = 0;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_device_type_get(self.handle, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn error_code_get(error_code: icsneoc2_error_t) -> Error {
|
||||
// Get the error code
|
||||
let mut error_description: Vec<u8> = vec![0; 255];
|
||||
let mut error_description_length: u32 = 255;
|
||||
let res = unsafe {
|
||||
icsneoc2_error_code_get(
|
||||
error_code,
|
||||
error_description.as_mut_ptr() as *mut i8,
|
||||
&mut error_description_length,
|
||||
)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Error::APIError(res, "icsneoc2_error_code_get() failed.".to_string());
|
||||
}
|
||||
// Convert the vec to an String
|
||||
error_description.resize(error_description_length as usize, 0);
|
||||
let error_str = CString::new(error_description)
|
||||
.expect("CString::new failed")
|
||||
.into_string()
|
||||
.expect("CString::new::into_string");
|
||||
Error::APIError(error_code, error_str)
|
||||
}
|
||||
|
||||
pub fn event_description_get(&self, event: *mut icsneoc2_event_t) -> Result<String> {
|
||||
// Get the string
|
||||
let mut str: Vec<u8> = vec![0; 255];
|
||||
let mut str_length: u32 = 255;
|
||||
let res = unsafe {
|
||||
icsneoc2_event_description_get(event, str.as_mut_ptr() as *mut i8, &mut str_length)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
// Convert the vec to an String
|
||||
str.resize(str_length as usize, 0);
|
||||
let str_string = {
|
||||
CString::new(str)
|
||||
.expect("CString::new failed")
|
||||
.into_string()
|
||||
.expect("CString::new::into_string")
|
||||
};
|
||||
Ok(str_string)
|
||||
}
|
||||
|
||||
pub fn events_get(&self, event_count: u32) -> Result<Vec<*mut icsneoc2_event_t>> {
|
||||
let mut events: Vec<*mut icsneoc2_event_t> =
|
||||
vec![std::ptr::null_mut(); event_count as usize];
|
||||
let mut event_count: u32 = event_count;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_events_get(events.as_mut_ptr(), &mut event_count) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
events.resize(event_count as usize, std::ptr::null_mut());
|
||||
Ok(events)
|
||||
}
|
||||
|
||||
pub fn message_bus_type_get(
|
||||
&self,
|
||||
message: *mut icsneoc2_message_t,
|
||||
) -> Result<icsneoc2_msg_bus_type_t> {
|
||||
let mut value: icsneoc2_msg_bus_type_t = 0;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_bus_type_get(self.handle, message, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn message_can_arbid_get(&self, message: *mut icsneoc2_message_t) -> Result<u32> {
|
||||
let mut value: u32 = 0;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_can_arbid_get(self.handle, message, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn message_can_arbid_set(
|
||||
&self,
|
||||
message: *mut icsneoc2_message_t,
|
||||
value: u32,
|
||||
) -> Result<()> {
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_can_arbid_set(self.handle, message, value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn message_can_baudrate_switch_get(
|
||||
&self,
|
||||
message: *mut icsneoc2_message_t,
|
||||
) -> Result<bool> {
|
||||
let mut value: bool = false;
|
||||
let res: icsneoc2_error_t = unsafe {
|
||||
ffi::icsneoc2_message_can_baudrate_switch_get(self.handle, message, &mut value)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn message_can_baudrate_switch_set(
|
||||
&self,
|
||||
message: *mut icsneoc2_message_t,
|
||||
value: bool,
|
||||
) -> Result<()> {
|
||||
let res: icsneoc2_error_t = unsafe {
|
||||
ffi::icsneoc2_message_can_baudrate_switch_set(self.handle, message, value)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn message_can_canfd_set(
|
||||
&self,
|
||||
message: *mut icsneoc2_message_t,
|
||||
value: bool,
|
||||
) -> Result<()> {
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_can_canfd_set(self.handle, message, value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn message_can_create(&self, message_count: u32) -> Result<Vec<*mut icsneoc2_message_t>> {
|
||||
let mut messages: Vec<*mut icsneoc2_message_t> =
|
||||
vec![std::ptr::null_mut(); message_count as usize];
|
||||
let res: icsneoc2_error_t = unsafe {
|
||||
ffi::icsneoc2_message_can_create(self.handle, messages.as_mut_ptr(), message_count)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(messages)
|
||||
}
|
||||
|
||||
pub fn message_can_dlc_get(&self, message: *mut icsneoc2_message_t) -> Result<i32> {
|
||||
let mut value: i32 = 0;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_can_dlc_get(self.handle, message, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn message_can_dlc_set(&self, message: *mut icsneoc2_message_t, value: i32) -> Result<()> {
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_can_dlc_set(self.handle, message, value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn message_can_error_state_indicator_get(
|
||||
&self,
|
||||
message: *mut icsneoc2_message_t,
|
||||
) -> Result<bool> {
|
||||
let mut value: bool = false;
|
||||
let res: icsneoc2_error_t = unsafe {
|
||||
ffi::icsneoc2_message_can_error_state_indicator_get(self.handle, message, &mut value)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn message_can_extended_set(
|
||||
&self,
|
||||
message: *mut icsneoc2_message_t,
|
||||
value: bool,
|
||||
) -> Result<()> {
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_can_extended_set(self.handle, message, value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn message_can_free(&self, message: *mut icsneoc2_message_t) -> Result<()> {
|
||||
let res: icsneoc2_error_t = unsafe { ffi::icsneoc2_message_can_free(self.handle, message) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn message_can_is_canfd(&self, message: *mut icsneoc2_message_t) -> Result<bool> {
|
||||
let mut value: bool = false;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_can_is_canfd(self.handle, message, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn message_can_is_extended(&self, message: *mut icsneoc2_message_t) -> Result<bool> {
|
||||
let mut value: bool = false;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_can_is_extended(self.handle, message, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn message_can_is_remote(&self, message: *mut icsneoc2_message_t) -> Result<bool> {
|
||||
let mut value: bool = false;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_can_is_remote(self.handle, message, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn message_data_get(
|
||||
&self,
|
||||
message: *mut icsneoc2_message_t,
|
||||
data_length: u32,
|
||||
) -> Result<Vec<u8>> {
|
||||
let mut data: Vec<u8> = vec![0; data_length as usize];
|
||||
let mut data_length = data_length;
|
||||
let res: icsneoc2_error_t = unsafe {
|
||||
ffi::icsneoc2_message_data_get(
|
||||
self.handle,
|
||||
message,
|
||||
data.as_mut_ptr(),
|
||||
&mut data_length,
|
||||
)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
data.resize(data_length as usize, 0);
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
pub fn message_data_set(&self, message: *mut icsneoc2_message_t, data: Vec<u8>) -> Result<()> {
|
||||
let mut data = data;
|
||||
let res: icsneoc2_error_t = unsafe {
|
||||
ffi::icsneoc2_message_data_set(
|
||||
self.handle,
|
||||
message,
|
||||
data.as_mut_ptr(),
|
||||
data.len() as u32,
|
||||
)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn message_is_transmit(&self, message: *mut icsneoc2_message_t) -> Result<bool> {
|
||||
let mut value: bool = false;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_is_transmit(self.handle, message, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn message_is_valid(&self, message: *mut icsneoc2_message_t) -> Result<bool> {
|
||||
let mut value: bool = false;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_is_valid(self.handle, message, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn message_netid_get(&self, message: *mut icsneoc2_message_t) -> Result<_icsneoc2_netid_t> {
|
||||
let mut value: icsneoc2_netid_t = 0;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_netid_get(self.handle, message, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
// TODO: This is gross, there is probably a better way to do this.
|
||||
// TryFrom impl would be a lot of work to implement because there are so many values.
|
||||
// We are relying on the function call to always return a valid value.
|
||||
let value: _icsneoc2_netid_t = unsafe { std::mem::transmute(value as u32) };
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn message_netid_set(
|
||||
&self,
|
||||
message: *mut icsneoc2_message_t,
|
||||
value: _icsneoc2_netid_t,
|
||||
) -> Result<()> {
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_netid_set(self.handle, message, value as icsneoc2_netid_t) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn message_type_get(
|
||||
&self,
|
||||
message: *mut icsneoc2_message_t,
|
||||
) -> Result<icsneoc2_msg_type_t> {
|
||||
let mut value: icsneoc2_msg_type_t = 0;
|
||||
let res: icsneoc2_error_t =
|
||||
unsafe { ffi::icsneoc2_message_type_get(self.handle, message, &mut value) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
pub fn message_type_name_get(&self, msg_type: icsneoc2_msg_type_t) -> Result<String> {
|
||||
// Get the string
|
||||
let mut str: Vec<u8> = vec![0; 255];
|
||||
let mut str_length: u32 = 255;
|
||||
let res = unsafe {
|
||||
icsneoc2_message_type_name_get(msg_type, str.as_mut_ptr() as *mut i8, &mut str_length)
|
||||
};
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
// Convert the vec to an String
|
||||
str.resize(str_length as usize, 0);
|
||||
let str_string = {
|
||||
CString::new(str)
|
||||
.expect("CString::new failed")
|
||||
.into_string()
|
||||
.expect("CString::new::into_string")
|
||||
};
|
||||
Ok(str_string)
|
||||
}
|
||||
|
||||
pub fn netid_name_get(&self, netid: _icsneoc2_netid_t) -> Result<String> {
|
||||
// Get the string
|
||||
let mut str: Vec<u8> = vec![0; 255];
|
||||
let mut str_length: u32 = 255;
|
||||
let res =
|
||||
unsafe { icsneoc2_netid_name_get(netid as icsneoc2_netid_t, str.as_mut_ptr() as *mut i8, &mut str_length) };
|
||||
// Check the error code
|
||||
if res != icsneoc2_error_success as icsneoc2_error_t {
|
||||
return Err(Self::error_code_get(res));
|
||||
}
|
||||
// Convert the vec to an String
|
||||
str.resize(str_length as usize, 0);
|
||||
let str_string = {
|
||||
CString::new(str)
|
||||
.expect("CString::new failed")
|
||||
.into_string()
|
||||
.expect("CString::new::into_string")
|
||||
};
|
||||
Ok(str_string)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn test_device_find_all() {
|
||||
let devices = Device::find_all(0).unwrap();
|
||||
assert_eq!(devices.len(), 0);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
VERSION="1.0.27"
|
||||
ROOT="$PWD/libusb"
|
||||
SOURCE="$ROOT/source"
|
||||
BUILD="$ROOT/build"
|
||||
INSTALL="$ROOT/install"
|
||||
|
||||
mkdir -p "$ROOT"
|
||||
cd "$ROOT" || exit 1
|
||||
|
||||
curl -LO "https://github.com/libusb/libusb/releases/download/v$VERSION/libusb-$VERSION.tar.bz2" || exit 1
|
||||
tar -xf "libusb-$VERSION.tar.bz2" || exit 1
|
||||
mv "libusb-$VERSION" "$SOURCE" || exit 1
|
||||
|
||||
mkdir "$BUILD" || exit 1
|
||||
cd "$BUILD" || exit 1
|
||||
"$SOURCE/configure" --prefix="$INSTALL" --disable-shared --disable-udev --disable-eventfd --disable-timerfd --with-pic || exit 1
|
||||
make || exit 1
|
||||
make install || exit 1
|
||||
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
export CFLAGS="-Wall -Werror"
|
||||
export CXXFLAGS="-Wall -Werror"
|
||||
cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release -DLIBICSNEO_BUILD_EXAMPLES=ON \
|
||||
-DLIBICSNEO_BUILD_UNIT_TESTS=ON -DLIBICSNEO_BUILD_SYSTEM_TESTS=ON -DLIBICSNEO_ENABLE_TCP=OFF || exit 1
|
||||
-DLIBICSNEO_BUILD_UNIT_TESTS=ON -DLIBICSNEO_ENABLE_TCP=OFF || exit 1
|
||||
|
||||
cmake --build build || exit 1
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ mkdir build
|
||||
|
||||
REM build
|
||||
cd build
|
||||
set CFLAGS=/WX
|
||||
set CXXFLAGS=/WX
|
||||
cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLIBICSNEO_BUILD_UNIT_TESTS=ON -DLIBICSNEO_BUILD_SYSTEM_TESTS=ON -DLIBICSNEO_ENABLE_TCP=ON ..
|
||||
set CFLAGS=/WX /W4 /wd4127
|
||||
set CXXFLAGS=/WX /W4 /wd4127
|
||||
cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLIBICSNEO_BUILD_UNIT_TESTS=ON -DLIBICSNEO_ENABLE_TCP=ON ..
|
||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
cmake --build .
|
||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
find_path(FTD3XX_INCLUDE_DIR
|
||||
NAMES ftd3xx.h FTD3XX.h
|
||||
)
|
||||
|
||||
find_library(FTD3XX_LIBRARY
|
||||
NAMES libftd3xx.a libftd3xx-static.a FTD3XX.lib
|
||||
PATH_SUFFIXES x64/Static
|
||||
)
|
||||
|
||||
mark_as_advanced(FTD3XX_FOUND FTD3XX_INCLUDE_DIR FTD3XX_LIBRARY)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(FTD3XX
|
||||
REQUIRED_VARS FTD3XX_INCLUDE_DIR FTD3XX_LIBRARY
|
||||
)
|
||||
if(FTD3XX_FOUND AND NOT TARGET D3XX::D3XX)
|
||||
add_library(FTD3XX::FTD3XX INTERFACE IMPORTED)
|
||||
set_target_properties(FTD3XX::FTD3XX PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${FTD3XX_INCLUDE_DIR}"
|
||||
INTERFACE_LINK_LIBRARIES "${FTD3XX_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
@@ -37,29 +37,28 @@ bool Communication::open() {
|
||||
}
|
||||
|
||||
void Communication::spawnThreads() {
|
||||
closing = false;
|
||||
readTaskThread = std::thread(&Communication::readTask, this);
|
||||
}
|
||||
|
||||
void Communication::joinThreads() {
|
||||
closing = true;
|
||||
|
||||
if(pauseReadTask) {
|
||||
resumeReads();
|
||||
}
|
||||
|
||||
closing = true;
|
||||
if(readTaskThread.joinable())
|
||||
readTaskThread.join();
|
||||
closing = false;
|
||||
}
|
||||
|
||||
bool Communication::close() {
|
||||
joinThreads();
|
||||
|
||||
if(!isOpen() && !isDisconnected()) {
|
||||
report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
joinThreads();
|
||||
|
||||
return driver->close();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* crc32.c
|
||||
*
|
||||
* Created on: Jun 22, 2020
|
||||
* Author: BJones
|
||||
*/
|
||||
#include "icsneo/communication/crc32.h"
|
||||
#include <stddef.h>
|
||||
|
||||
static const unsigned long crc32_table[256] = { 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535,
|
||||
0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2,
|
||||
0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F,
|
||||
0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
|
||||
0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180,
|
||||
0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11,
|
||||
0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2,
|
||||
0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
|
||||
0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3,
|
||||
0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC,
|
||||
0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525,
|
||||
0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
|
||||
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E,
|
||||
0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
|
||||
0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8,
|
||||
0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
|
||||
0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9,
|
||||
0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226,
|
||||
0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B,
|
||||
0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
|
||||
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354,
|
||||
0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5,
|
||||
0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E,
|
||||
0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D };
|
||||
|
||||
uint32_t crc32(uint32_t crc, const unsigned char* buf, uint32_t len)
|
||||
{
|
||||
unsigned char octet;
|
||||
const unsigned char* p = buf;
|
||||
|
||||
crc = ~crc;
|
||||
while (len--)
|
||||
{
|
||||
octet = *p++; /* Cast to unsigned octet. */
|
||||
crc = (crc >> 8) ^ crc32_table[(crc & 0xff) ^ octet];
|
||||
}
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
static unsigned char rev_crc32_table[256];
|
||||
|
||||
static void revgen(void)
|
||||
{
|
||||
size_t k;
|
||||
|
||||
for (k = 0; k < 256; k++)
|
||||
rev_crc32_table[crc32_table[k] >> 24] = (uint8_t)k;
|
||||
}
|
||||
|
||||
uint32_t revcrc32(uint32_t crc, const unsigned char* buf, uint32_t len)
|
||||
{
|
||||
unsigned char k;
|
||||
revgen();
|
||||
crc = ~crc;
|
||||
while (len--)
|
||||
{
|
||||
k = rev_crc32_table[crc >> 24];
|
||||
crc = ((crc ^ crc32_table[k]) << 8) | (k ^ buf[len]);
|
||||
}
|
||||
return ~crc;
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "icsneo/communication/message/mdiomessage.h"
|
||||
#include "icsneo/communication/message/extendeddatamessage.h"
|
||||
#include "icsneo/communication/message/livedatamessage.h"
|
||||
#include "icsneo/communication/message/logdatamessage.h"
|
||||
#include "icsneo/communication/message/diskdatamessage.h"
|
||||
#include "icsneo/communication/message/hardwareinfo.h"
|
||||
#include "icsneo/communication/message/tc10statusmessage.h"
|
||||
@@ -89,7 +90,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||
result->timestamp *= timestampResolution;
|
||||
|
||||
switch(result->type) {
|
||||
case Message::Type::BusMessage: {
|
||||
case Message::Type::Frame: {
|
||||
CANMessage& can = *static_cast<CANMessage*>(result.get());
|
||||
can.network = packet->network;
|
||||
break;
|
||||
@@ -233,7 +234,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||
// They come in as CAN but we will handle them in the device rather than
|
||||
// passing them onto the user.
|
||||
if(packet->data.size() < 24) {
|
||||
auto rawmsg = std::make_shared<InternalMessage>(Network::NetID::Device);
|
||||
auto rawmsg = std::make_shared<RawMessage>(Network::NetID::Device);
|
||||
result = rawmsg;
|
||||
rawmsg->data = packet->data;
|
||||
return true;
|
||||
@@ -263,7 +264,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||
}
|
||||
case Network::NetID::DeviceStatus: {
|
||||
// Just pass along the data, the device needs to handle this itself
|
||||
result = std::make_shared<InternalMessage>(packet->network, packet->data);
|
||||
result = std::make_shared<RawMessage>(packet->network, packet->data);
|
||||
return true;
|
||||
}
|
||||
case Network::NetID::RED_INT_MEMORYREAD: {
|
||||
@@ -323,8 +324,19 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||
result = GPTPStatus::DecodeToMessage(packet->data, report);
|
||||
return true;
|
||||
}
|
||||
case ExtendedCommand::GetDiskDetails:
|
||||
case ExtendedCommand::DiskFormatProgress: {
|
||||
std::vector<uint8_t> responseBody(
|
||||
packet->data.begin() + sizeof(ExtendedResponseMessage::ResponseHeader),
|
||||
packet->data.end()
|
||||
);
|
||||
auto response = std::make_shared<ExtendedResponseMessage>(resp.command);
|
||||
response->data = std::move(responseBody);
|
||||
result = response;
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
// No defined handler, treat this as a InternalMessage
|
||||
// No defined handler, treat this as a RawMessage
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -491,7 +503,16 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||
result = std::make_shared<DiskDataMessage>(std::move(packet->data));
|
||||
return true;
|
||||
}
|
||||
case Network::NetID::Data_To_Host: {
|
||||
result = LogDataMessage::DecodeToMessage(packet->data);
|
||||
if(!result) {
|
||||
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::EventWarning);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -499,6 +520,6 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||
}
|
||||
|
||||
// For the moment other types of messages will automatically be decoded as raw messages
|
||||
result = std::make_shared<InternalMessage>(packet->network, packet->data);
|
||||
result = std::make_shared<RawMessage>(packet->network, packet->data);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
|
||||
result.clear();
|
||||
|
||||
switch(message->type) {
|
||||
case Message::Type::BusMessage: {
|
||||
auto frame = std::dynamic_pointer_cast<BusMessage>(message);
|
||||
case Message::Type::Frame: {
|
||||
auto frame = std::dynamic_pointer_cast<Frame>(message);
|
||||
|
||||
// Frame uses frame->data as the buffer unless directed otherwise
|
||||
buffer = &frame->data;
|
||||
@@ -35,15 +35,25 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
|
||||
auto ethmsg = std::dynamic_pointer_cast<EthernetMessage>(message);
|
||||
if(!ethmsg) {
|
||||
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
|
||||
return false; // The message was not a properly formed EthernetMessage
|
||||
return false;
|
||||
}
|
||||
|
||||
shortFormat = false; // Ensure long-format RED header is added
|
||||
netid = static_cast<uint16_t>(Network::NetID::ETHERNET_TX_WRAP);
|
||||
buffer = &result;
|
||||
if(!HardwareEthernetPacket::EncodeFromMessage(*ethmsg, result, report))
|
||||
|
||||
if(!HardwareEthernetPacket::EncodeFromMessage(*ethmsg, result, report)) {
|
||||
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(result.empty()) {
|
||||
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
} // End of Network::Type::Ethernet
|
||||
}
|
||||
case Network::Type::CAN:
|
||||
case Network::Type::SWCAN:
|
||||
case Network::Type::LSFTCAN: {
|
||||
@@ -130,8 +140,8 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
|
||||
|
||||
break;
|
||||
}
|
||||
case Message::Type::InternalMessage: {
|
||||
auto raw = std::dynamic_pointer_cast<InternalMessage>(message);
|
||||
case Message::Type::RawMessage: {
|
||||
auto raw = std::dynamic_pointer_cast<RawMessage>(message);
|
||||
|
||||
// Raw message uses raw->data as the buffer unless directed otherwise
|
||||
buffer = &raw->data;
|
||||
@@ -230,7 +240,6 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
|
||||
(uint8_t)(netid >> 8)
|
||||
});
|
||||
}
|
||||
|
||||
result = packetizer.packetWrap(*buffer, shortFormat);
|
||||
return true;
|
||||
}
|
||||
@@ -243,7 +252,7 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
|
||||
* In this case, command 0x06 is SetLEDState.
|
||||
* This old command type is not really used anywhere else.
|
||||
*/
|
||||
auto canmsg = std::make_shared<InternalMessage>(Network::NetID::Device);
|
||||
auto canmsg = std::make_shared<RawMessage>(Network::NetID::Device);
|
||||
msg = canmsg;
|
||||
if(arguments.empty()) {
|
||||
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
|
||||
@@ -265,6 +274,8 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
|
||||
case Command::GetMainVersion:
|
||||
case Command::GetSecondaryVersions:
|
||||
case Command::NeoReadMemory:
|
||||
case Command::ClearCoreMini:
|
||||
case Command::LoadCoreMini:
|
||||
// There is a firmware handling idiosyncrasy with these commands
|
||||
// They must be encoded in the short format
|
||||
m51msg->forceShortFormat = true;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "icsneo/communication/livedata.h"
|
||||
#include <cmath>
|
||||
namespace icsneo {
|
||||
|
||||
namespace LiveDataUtil {
|
||||
@@ -18,5 +19,61 @@ double liveDataValueToDouble(const LiveDataValue& val) {
|
||||
return val.value * liveDataFixedPointToDouble;
|
||||
}
|
||||
|
||||
bool liveDataDoubleToValue(const double& dFloat, LiveDataValue& value) {
|
||||
union {
|
||||
struct
|
||||
{
|
||||
uint32_t ValueFractionPart;
|
||||
int32_t ValueInt32;
|
||||
} parts;
|
||||
int64_t ValueLarge;
|
||||
} CminiFixedPt;
|
||||
constexpr double CM_FIXED_POINT_TO_DOUBLEVALUE = (1.0 / (double)(1ULL << 32)); // 2^-32
|
||||
constexpr double CM_DOUBLEVALUE_TO_FIXED_POINT = ((double)(1ULL << 32)); // 2^32
|
||||
// Use const for limits (C++98 compatible)
|
||||
const double INT32_MAX_DOUBLE =
|
||||
static_cast<double>(std::numeric_limits<int32_t>::max()) + (1.0 - std::numeric_limits<double>::epsilon());
|
||||
const double INT32_MIN_DOUBLE = static_cast<double>(std::numeric_limits<int32_t>::min());
|
||||
const double MIN_FIXED_POINT_DOUBLE = (double)(1ull * CM_FIXED_POINT_TO_DOUBLEVALUE);
|
||||
|
||||
// This needs to be assigned separately, otherwise, for dFloat >= 2^31,
|
||||
// long double dBigFloat = dFloat * CM_DOUBLEVALUE_TO_FIXED_POINT overflows
|
||||
// long long (value is >= 2^63) and so the assignment ValueLarge = dBigFloat is undefined
|
||||
|
||||
int32_t intPart; //creating temp variable due to static analysis warning about writing and reading to different union members
|
||||
if(dFloat < 0.0)
|
||||
intPart = (int32_t)std::floor(dFloat);
|
||||
else
|
||||
intPart = (int32_t)dFloat;
|
||||
|
||||
//using temp varialbes to avoid static analysis warning about read/write to different union members
|
||||
double frac = dFloat - (double)(intPart);
|
||||
uint32_t fracPart = (uint32_t)std::floor((frac * CM_DOUBLEVALUE_TO_FIXED_POINT) + 0.5);
|
||||
|
||||
//write temp vars back into the union
|
||||
CminiFixedPt.parts.ValueInt32 = intPart;
|
||||
CminiFixedPt.parts.ValueFractionPart = fracPart;
|
||||
value.value = CminiFixedPt.ValueLarge;
|
||||
|
||||
if(dFloat == (double)0.0)
|
||||
return true;
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
// 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 true;
|
||||
}
|
||||
|
||||
} // namespace LiveDataUtil
|
||||
} // namespace icsneo
|
||||
@@ -102,11 +102,11 @@ bool A2BWAVOutput::callIfMatch(const std::shared_ptr<Message>& message) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(message->type != Message::Type::BusMessage) {
|
||||
if(message->type != Message::Type::Frame) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& frameMsg = std::dynamic_pointer_cast<BusMessage>(message);
|
||||
const auto& frameMsg = std::dynamic_pointer_cast<Frame>(message);
|
||||
|
||||
if(!frameMsg) {
|
||||
return false;
|
||||
|
||||
@@ -14,10 +14,10 @@ enum LinkSpeed {
|
||||
};
|
||||
|
||||
enum LinkMode {
|
||||
OPETH_LINK_AUTO,
|
||||
OPETH_LINK_MASTER,
|
||||
OPETH_LINK_SLAVE,
|
||||
OPETH_LINK_INVALID = 255,
|
||||
AE_LINK_AUTO,
|
||||
AE_LINK_MASTER,
|
||||
AE_LINK_SLAVE,
|
||||
AE_LINK_INVALID = 255,
|
||||
};
|
||||
|
||||
struct Packet {
|
||||
@@ -47,10 +47,10 @@ std::shared_ptr<Message> EthernetStatusMessage::DecodeToMessage(const std::vecto
|
||||
}
|
||||
LinkMode mode;
|
||||
switch(packet->mode) {
|
||||
case OPETH_LINK_INVALID: mode = EthernetStatusMessage::LinkMode::LinkModeInvalid; break;
|
||||
case OPETH_LINK_AUTO: mode = EthernetStatusMessage::LinkMode::LinkModeAuto; break;
|
||||
case OPETH_LINK_MASTER: mode = EthernetStatusMessage::LinkMode::LinkModeMaster; break;
|
||||
case OPETH_LINK_SLAVE: mode = EthernetStatusMessage::LinkMode::LinkModeSlave; break;
|
||||
case AE_LINK_INVALID: mode = EthernetStatusMessage::LinkMode::LinkModeInvalid; break;
|
||||
case AE_LINK_AUTO: mode = EthernetStatusMessage::LinkMode::LinkModeAuto; break;
|
||||
case AE_LINK_MASTER: mode = EthernetStatusMessage::LinkMode::LinkModeMaster; break;
|
||||
case AE_LINK_SLAVE: mode = EthernetStatusMessage::LinkMode::LinkModeSlave; break;
|
||||
default: return nullptr;
|
||||
}
|
||||
return std::make_shared<EthernetStatusMessage>(packet->network, packet->state, speed, packet->duplex, mode);
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
using namespace icsneo;
|
||||
|
||||
std::vector<uint8_t> FlexRayControlMessage::BuildBaseControlArgs(uint8_t controller, FlexRay::Opcode op, const std::vector<uint8_t>& args) {
|
||||
std::vector<uint8_t> ret;
|
||||
ret.reserve(args.size() + 4);
|
||||
std::vector<uint8_t> ret(args.size() + 4);
|
||||
ret.push_back(controller);
|
||||
const uint16_t size = uint16_t((std::min)(args.size() + 1, size_t(std::numeric_limits<uint16_t>::max()))); // Add 1 for the opcode
|
||||
ret.push_back(uint8_t(size));
|
||||
|
||||
@@ -12,4 +12,14 @@ void LiveDataCommandMessage::appendSignalArg(LiveDataValueType valueType) {
|
||||
arg->valueType = valueType;
|
||||
}
|
||||
|
||||
void LiveDataSetValueMessage::appendSetValue(LiveDataValueType valueType, const LiveDataValue& value) {
|
||||
auto& arg = args.emplace_back(std::make_shared<LiveDataArgument>());
|
||||
arg->objectType = LiveDataObjectType::MISC;
|
||||
arg->objectIndex = 0u;
|
||||
arg->signalIndex = 0u;
|
||||
arg->valueType = valueType;
|
||||
|
||||
values.push_back(std::make_shared<LiveDataValue>(value));
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "icsneo/communication/message/logdatamessage.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
std::shared_ptr<LogDataMessage> LogDataMessage::DecodeToMessage(const std::vector<uint8_t>& bytestream) {
|
||||
if(bytestream.size() % 2 != 0)
|
||||
return nullptr;
|
||||
const auto* begin = (char16_t*)bytestream.data();
|
||||
const auto* end = begin + (bytestream.size() / sizeof(char16_t));
|
||||
return std::make_shared<LogDataMessage>(std::wstring(begin,end));
|
||||
}
|
||||
@@ -0,0 +1,531 @@
|
||||
#include "icsneo/communication/message/macsecmessage.h"
|
||||
|
||||
#include "icsneo/communication/crc32.h"
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
namespace icsneo
|
||||
{
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4201) // nameless struct/union
|
||||
#endif
|
||||
|
||||
#pragma pack(push, 1)
|
||||
/* MACsec Rule */
|
||||
/**
|
||||
* @brief Structure of Vlan tag
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t vid; /*!< 12 bits */
|
||||
uint8_t priCfi; /*!< PRI - 3 bits, CFI - 1bit */
|
||||
} MACSEC_VLANTAG_t;
|
||||
/**
|
||||
* @brief Structure of MPLS
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t mplsLabel; /*!< 20 bits */
|
||||
uint8_t exp; /*!< 3 bits */
|
||||
} MACSEC_MPLS_OUTER_t;
|
||||
/**
|
||||
* @brief Define Encoded Packet Type from the parser
|
||||
*
|
||||
*/
|
||||
static constexpr int MACSEC_SETTINGS_RULE_SIZE = 88;
|
||||
typedef union _MACSecRule
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t index;
|
||||
uint8_t keyMacDa[6]; /*!< MAC DA field extracted from the packet */
|
||||
uint8_t maskMacDa[6]; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint8_t keyMacSa[6]; /*!< MAC SA field extracted from the packet */
|
||||
uint8_t maskMacSa[6]; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint16_t keyEthertype; /*!< First E-Type found in the packet that doesn't match one of the preconfigured custom tag. */
|
||||
uint16_t maskEthertype; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
MACSEC_VLANTAG_t keyVlanTagOuter1; /*!< outermost/1st VLAN ID {8'd0, VLAN_ID[11:0]}, or 20-bit MPLS label. */
|
||||
MACSEC_MPLS_OUTER_t keyMplsOuter1;
|
||||
MACSEC_VLANTAG_t maskVlanTagOuter1; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
MACSEC_MPLS_OUTER_t maskMplsOuter1;
|
||||
MACSEC_VLANTAG_t keyVlanTagOuter2; /*!< 2nd outermost VLAN ID {8'd0, VLAN_ID[11:0]}, or 20-bit MPLS label. */
|
||||
MACSEC_MPLS_OUTER_t keyMplsOuter2;
|
||||
MACSEC_VLANTAG_t maskVlanTagOuter2; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
MACSEC_MPLS_OUTER_t maskMplsOuter2;
|
||||
uint16_t keyBonusData; /*!< 2 bytes of additional bonus data extracted from one of the custom tags. */
|
||||
uint16_t maskBonusData; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint8_t
|
||||
keyTagMatchBitmap; /*!< 8 bits total. Maps 1 to 1 bitwise with the set of custom tags. (set bit[N]=1 if check Nth custom tag) */
|
||||
uint8_t maskTagMatchBitmap; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint8_t keyPacketType; /*!< Encoded Packet Type, see MACSEC_PACKET_TYPE */
|
||||
uint8_t maskPacketType; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint16_t
|
||||
keyInnerVlanType; /*!< 3 bits total. Encoded value indicating which VLAN TPID value matched for the second outermost VLAN Tag. */
|
||||
uint16_t maskInnerVlanType; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint16_t keyOuterVlanType; /*!< 3 bits total. Encoded value indicating which VLAN TPID value matched for the outermost VLAN Tag. */
|
||||
uint16_t maskOuterVlanType; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint8_t
|
||||
keyNumTags; /*!< 7 bits total. Number of VLAN/custom tags or MPLS lables detected. Ingress: before SecTag; Egress: total detected. Exclude MCS header tags. i.e. Bit 2: 2 tags/labels before SecTAG...Bit 6: 6 or more tags/labels before SecTAG. */
|
||||
uint8_t maskNumTags; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint8_t keyExpress; /*!< 1 bits. Express packet. */
|
||||
uint8_t maskExpress; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint8_t isMpls;
|
||||
uint8_t rsvd[5];
|
||||
uint8_t enable;
|
||||
};
|
||||
uint8_t byte[MACSEC_SETTINGS_RULE_SIZE];
|
||||
} MACSecRule_t;
|
||||
/* MACsec Map */
|
||||
static constexpr int MACSEC_SETTINGS_MAP_SIZE = 20;
|
||||
typedef union _MACSecMap
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t index;
|
||||
uint64_t secTagSci; /*!< Identifies the SecTAG SCI for this Flow. */
|
||||
uint8_t secYIndex; /*!< index for entry in Egress secY Policy */
|
||||
uint8_t isControlPacket; /*!< Identifies all packets matching this index lookup as control packets. */
|
||||
uint8_t scIndex; /*!< Identifies the SC for this Flow. */
|
||||
uint8_t auxiliaryPlcy; /*!< Auxiliary policy bits. */
|
||||
uint8_t ruleId; /*!< Identifies the Rule for this Flow. */
|
||||
uint8_t rsvd[5];
|
||||
uint8_t enable;
|
||||
};
|
||||
uint8_t byte[MACSEC_SETTINGS_MAP_SIZE];
|
||||
} MACSecMap_t;
|
||||
/* MACsec SecY */
|
||||
/**
|
||||
* @brief Define the permit police for frames as defined in 802.1ae
|
||||
*
|
||||
*/
|
||||
static constexpr int MACSEC_SETTINGS_SECY_SIZE = 24;
|
||||
typedef union _MACSecSecY
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t index; /*!< Identifies the SecY for this Flow. */
|
||||
uint8_t controlledPortEnabled; /*!< Enable (or disable) operation of the Controlled port associated with this SecY */
|
||||
uint8_t frameValidationType; /*!< see MACSEC_VALIDATEFRAME */
|
||||
uint8_t secTagIcvStripType; /*!< see MACSEC_STRIP_SECTAG_ICV */
|
||||
uint8_t cipher; /*!< Define the cipher suite to use for this SecY see MACSEC_CIPHER_SUITE */
|
||||
uint8_t confidentialOffset; /*!< Define the number of bytes that are unencrypted following the SecTag. */
|
||||
uint8_t icvIncludesDaSa; /*!< When set, the outer DA/SA bytes are included in the authentication GHASH calculation */
|
||||
uint8_t replayProtect; /*!< Enables Anti-Replay protection */
|
||||
uint32_t replayWindow; /*!< Unsigned value indicating the size of the anti-replay window. */
|
||||
uint8_t
|
||||
protectFrames; /*!< 0 = do not encrypt or authenticate this packet; 1 = always Authenticate frame and if SecTag.TCI.E = 1 encrypt the packet as well. */
|
||||
uint8_t
|
||||
secTagOffset; /*!< Define the offset in bytes from either the start of the packet or a matching Etype depending on SecTag_Insertion_Mode. */
|
||||
uint8_t secTagTci; /*!< Tag Control Information excluding the AN field which originates from the SA Policy table */
|
||||
uint16_t mtu; /*!< Specifies the outgoing MTU for this SecY */
|
||||
uint8_t rsvd[6];
|
||||
uint8_t enable;
|
||||
};
|
||||
uint8_t byte[MACSEC_SETTINGS_SECY_SIZE];
|
||||
} MACSecSecY_t;
|
||||
/* MACsec SC */
|
||||
static constexpr int MACSEC_SETTINGS_SC_SIZE = 24;
|
||||
typedef union _MACSecSc
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t index; /*!< SC index. */
|
||||
uint8_t secYIndex; /*!< SecY associated with this packet. */
|
||||
uint64_t sci; /*!< The Secure Channel Identifier. */
|
||||
uint8_t saIndex0; /*!< Define the 1st SA to use */
|
||||
uint8_t saIndex1; /*!< Define the 2nd SA to use */
|
||||
uint8_t saIndex0InUse; /*!< Specifies whether 1st SA is in use or not. */
|
||||
uint8_t saIndex1InUse; /*!< Specifies whether 2nd SA is in use or not. */
|
||||
uint8_t enableAutoRekey; /*!< If enabled, then once the pn_threshold is reached, auto rekey will happen. */
|
||||
uint8_t
|
||||
isActiveSa1; /*!< If set, then sa_index1 is the currently active SA index. If cleared, the sa_index0 is the currently active SA index). */
|
||||
uint8_t rsvd[7];
|
||||
uint8_t enable;
|
||||
};
|
||||
uint8_t byte[MACSEC_SETTINGS_SC_SIZE];
|
||||
} MACSecSc_t;
|
||||
/* MACsec SA */
|
||||
static constexpr int MACSEC_SETTINGS_SA_SIZE = 80;
|
||||
typedef union _MACSecSa
|
||||
{
|
||||
struct
|
||||
{
|
||||
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. */
|
||||
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. */
|
||||
uint8_t an; /*!< 2b SecTag Association Number (AN) */
|
||||
uint64_t nextPn; /*!< 64b next_pn value: Next packet number to insert into outgoing packet on a particular SA. */
|
||||
uint8_t rsvd[5];
|
||||
uint8_t enable;
|
||||
};
|
||||
uint8_t byte[MACSEC_SETTINGS_SA_SIZE];
|
||||
} MACSecSa_t;
|
||||
/* MACsec Flags */
|
||||
typedef union _MACSecFlags
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t en : 1; // '1' = enable; '0' = disable
|
||||
uint32_t reserved : 31;
|
||||
};
|
||||
uint32_t flags_32b;
|
||||
} MACSecFlags_t;
|
||||
#define MACSEC_SETTINGS_FLAGS_SIZE (4)
|
||||
/* MACSec Settings for 1 port/phy */
|
||||
typedef struct MACSEC_CONFIG_t
|
||||
{
|
||||
MACSecFlags_t flags;
|
||||
MACSecRule_t rule[MACsecConfig::NumRules];
|
||||
MACSecMap_t map[MACsecConfig::NumMaps];
|
||||
MACSecSecY_t secy[MACsecConfig::NumSecY];
|
||||
MACSecSc_t sc[MACsecConfig::NumSc];
|
||||
MACSecSa_t sa[MACsecConfig::NumSa];
|
||||
} MACSEC_CONFIG;
|
||||
typedef union _MACSecGlobalFlags
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t en : 1; // '1' = enable; '0' = disable
|
||||
uint32_t nvm : 1; // store macsec config in non-volatile memory
|
||||
uint32_t reserved : 30;
|
||||
};
|
||||
uint32_t flags_32b;
|
||||
} MACSecGlobalFlags_t;
|
||||
#define MACSEC_SETTINGS_SIZE (2040) // leave space for expansion and keep nicely aligned for flashing
|
||||
typedef union _MACSEC_SETTINGS
|
||||
{
|
||||
struct
|
||||
{
|
||||
MACSecGlobalFlags_t flags;
|
||||
MACSEC_CONFIG rx;
|
||||
MACSEC_CONFIG tx;
|
||||
};
|
||||
uint8_t byte[MACSEC_SETTINGS_SIZE];
|
||||
} MACSEC_SETTINGS;
|
||||
|
||||
#define MACSEC_SETTINGS_VERSION 1
|
||||
struct MACSEC_SETTINGS_W_HDR
|
||||
{
|
||||
uint16_t version;
|
||||
uint16_t len;
|
||||
uint32_t crc32;
|
||||
MACSEC_SETTINGS macsec;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
std::shared_ptr<MACsecMessage> MACsecMessage::DecodeToMessage(const std::vector<uint8_t>& bytestream, const device_eventhandler_t& report)
|
||||
{
|
||||
if (bytestream.empty() || (bytestream.size() < sizeof(MACSEC_SETTINGS_W_HDR)))
|
||||
{
|
||||
report(APIEvent::Type::RequiredParameterNull, APIEvent::Severity::Error);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MACSEC_SETTINGS_W_HDR* macsecArgs = (MACSEC_SETTINGS_W_HDR*)bytestream.data();
|
||||
if (macsecArgs->version != MACSEC_SETTINGS_VERSION)
|
||||
{
|
||||
report(APIEvent::Type::SettingsVersionError, APIEvent::Severity::Error);
|
||||
return nullptr;
|
||||
}
|
||||
if (macsecArgs->len != sizeof(MACSEC_SETTINGS))
|
||||
{
|
||||
report(APIEvent::Type::SettingsLengthError, APIEvent::Severity::Error);
|
||||
return nullptr;
|
||||
}
|
||||
const auto crcCalculted = crc32(0, (uint8_t*)&macsecArgs->macsec, macsecArgs->len);
|
||||
if (macsecArgs->crc32 != crcCalculted)
|
||||
{
|
||||
report(APIEvent::Type::SettingsChecksumError, APIEvent::Severity::Error);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto msg = std::make_shared<MACsecMessage>();
|
||||
|
||||
const auto& copyConfig = [](const MACSEC_CONFIG& source, MACsecConfig& dest)
|
||||
{
|
||||
dest.flags.en = source.flags.en;
|
||||
for (int index = 0; index < MACsecConfig::NumRules; index++)
|
||||
{
|
||||
if(!source.rule[index].enable) continue;
|
||||
#undef __COPY_ITEM
|
||||
#define __COPY_ITEM(___name__) dest.rule[index].___name__ = (decltype(dest.rule[index].___name__))source.rule[index].___name__
|
||||
#undef __COPY_ARR
|
||||
#define __COPY_ARR(___name__) (void)memcpy(dest.rule[index].___name__.data(), source.rule[index].___name__, dest.rule[index].___name__.size())
|
||||
__COPY_ITEM(index);
|
||||
__COPY_ARR(keyMacDa);
|
||||
__COPY_ARR(maskMacDa);
|
||||
__COPY_ARR(keyMacSa);
|
||||
__COPY_ARR(maskMacSa);
|
||||
__COPY_ITEM(keyVlanTagOuter1.vid);
|
||||
__COPY_ITEM(keyVlanTagOuter1.priCfi);
|
||||
__COPY_ITEM(keyMplsOuter1.mplsLabel);
|
||||
__COPY_ITEM(keyMplsOuter1.exp);
|
||||
__COPY_ITEM(maskVlanTagOuter1.vid);
|
||||
__COPY_ITEM(maskVlanTagOuter1.priCfi);
|
||||
__COPY_ITEM(maskMplsOuter1.mplsLabel);
|
||||
__COPY_ITEM(maskMplsOuter1.exp);
|
||||
__COPY_ITEM(keyVlanTagOuter2.vid);
|
||||
__COPY_ITEM(keyVlanTagOuter2.priCfi);
|
||||
__COPY_ITEM(keyMplsOuter2.mplsLabel);
|
||||
__COPY_ITEM(keyMplsOuter2.exp);
|
||||
__COPY_ITEM(maskVlanTagOuter2.vid);
|
||||
__COPY_ITEM(maskVlanTagOuter2.priCfi);
|
||||
__COPY_ITEM(maskMplsOuter2.mplsLabel);
|
||||
__COPY_ITEM(maskMplsOuter2.exp);
|
||||
__COPY_ITEM(keyEthertype);
|
||||
__COPY_ITEM(maskEthertype);
|
||||
__COPY_ITEM(keyBonusData);
|
||||
__COPY_ITEM(maskBonusData);
|
||||
__COPY_ITEM(keyTagMatchBitmap);
|
||||
__COPY_ITEM(maskTagMatchBitmap);
|
||||
__COPY_ITEM(keyPacketType);
|
||||
__COPY_ITEM(maskPacketType);
|
||||
__COPY_ITEM(keyInnerVlanType);
|
||||
__COPY_ITEM(maskInnerVlanType);
|
||||
__COPY_ITEM(keyOuterVlanType);
|
||||
__COPY_ITEM(maskOuterVlanType);
|
||||
__COPY_ITEM(keyNumTags);
|
||||
__COPY_ITEM(maskNumTags);
|
||||
__COPY_ITEM(keyExpress);
|
||||
__COPY_ITEM(maskExpress);
|
||||
__COPY_ITEM(isMpls);
|
||||
__COPY_ITEM(enable);
|
||||
}
|
||||
|
||||
for (int index = 0; index < MACsecConfig::NumMaps; index++)
|
||||
{
|
||||
if(!source.map[index].enable) continue;
|
||||
#undef __COPY_ITEM
|
||||
#define __COPY_ITEM(___name__) dest.map[index].___name__ = source.map[index].___name__
|
||||
__COPY_ITEM(index);
|
||||
__COPY_ITEM(secTagSci);
|
||||
__COPY_ITEM(secYIndex);
|
||||
__COPY_ITEM(isControlPacket);
|
||||
__COPY_ITEM(scIndex);
|
||||
__COPY_ITEM(auxiliaryPlcy);
|
||||
__COPY_ITEM(ruleId);
|
||||
__COPY_ITEM(enable);
|
||||
}
|
||||
|
||||
for (int index = 0; index < MACsecConfig::NumSecY; index++)
|
||||
{
|
||||
if(!source.secy[index].enable) continue;
|
||||
#undef __COPY_ITEM
|
||||
#define __COPY_ITEM(___name__) dest.secy[index].___name__ = (decltype(dest.secy[index].___name__))source.secy[index].___name__
|
||||
__COPY_ITEM(index);
|
||||
__COPY_ITEM(controlledPortEnabled);
|
||||
__COPY_ITEM(frameValidationType);
|
||||
__COPY_ITEM(secTagIcvStripType);
|
||||
__COPY_ITEM(cipher);
|
||||
__COPY_ITEM(confidentialOffset);
|
||||
__COPY_ITEM(icvIncludesDaSa);
|
||||
__COPY_ITEM(replayProtect);
|
||||
__COPY_ITEM(replayWindow);
|
||||
__COPY_ITEM(protectFrames);
|
||||
__COPY_ITEM(secTagOffset);
|
||||
__COPY_ITEM(secTagTci);
|
||||
__COPY_ITEM(mtu);
|
||||
__COPY_ITEM(enable);
|
||||
}
|
||||
|
||||
for (int index = 0; index < MACsecConfig::NumSc; index++)
|
||||
{
|
||||
if(!source.sc[index].enable) continue;
|
||||
#undef __COPY_ITEM
|
||||
#define __COPY_ITEM(___name__) dest.sc[index].___name__ = source.sc[index].___name__
|
||||
__COPY_ITEM(index);
|
||||
__COPY_ITEM(secYIndex);
|
||||
__COPY_ITEM(sci);
|
||||
__COPY_ITEM(saIndex0);
|
||||
__COPY_ITEM(saIndex1);
|
||||
__COPY_ITEM(saIndex0InUse);
|
||||
__COPY_ITEM(saIndex1InUse);
|
||||
__COPY_ITEM(enableAutoRekey);
|
||||
__COPY_ITEM(isActiveSa1);
|
||||
__COPY_ITEM(enable);
|
||||
}
|
||||
|
||||
for (int index = 0; index < MACsecConfig::NumSa; index++)
|
||||
{
|
||||
if(!source.sa[index].enable) continue;
|
||||
#undef __COPY_ITEM
|
||||
#define __COPY_ITEM(___name__) dest.sa[index].___name__ = source.sa[index].___name__
|
||||
#undef __COPY_ARR
|
||||
#define __COPY_ARR(___name__) (void)memcpy(dest.sa[index].___name__.data(), source.sa[index].___name__, dest.sa[index].___name__.size())
|
||||
__COPY_ITEM(index);
|
||||
__COPY_ARR(sak);
|
||||
__COPY_ARR(hashKey);
|
||||
__COPY_ARR(salt);
|
||||
__COPY_ITEM(ssci);
|
||||
__COPY_ITEM(an);
|
||||
__COPY_ITEM(nextPn);
|
||||
__COPY_ITEM(enable);
|
||||
}
|
||||
};
|
||||
|
||||
msg->flags.en = macsecArgs->macsec.flags.en;
|
||||
copyConfig(macsecArgs->macsec.rx, msg->rx);
|
||||
copyConfig(macsecArgs->macsec.tx, msg->tx);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
bool MACsecMessage::EncodeFromMessage(std::vector<uint8_t>& bytestream, const device_eventhandler_t& report) const
|
||||
{
|
||||
MACSEC_SETTINGS_W_HDR* macsecArgs;
|
||||
|
||||
bytestream.resize(sizeof(MACSEC_SETTINGS_W_HDR), 0);
|
||||
macsecArgs = (MACSEC_SETTINGS_W_HDR*)bytestream.data();
|
||||
|
||||
macsecArgs->version = MACSEC_SETTINGS_VERSION;
|
||||
macsecArgs->len = sizeof(MACSEC_SETTINGS_W_HDR);
|
||||
|
||||
const auto& copyConfig = [](const MACsecConfig& source, MACSEC_CONFIG& dest)
|
||||
{
|
||||
dest.flags.en = (uint8_t)source.flags.en;
|
||||
for (int index = 0; index < MACsecConfig::NumRules; index++)
|
||||
{
|
||||
if(!source.rule[index].enable) continue;
|
||||
#undef __COPY_ITEM
|
||||
#define __COPY_ITEM(___name__) dest.rule[index].___name__ = (decltype(dest.rule[index].___name__))source.rule[index].___name__
|
||||
#undef __COPY_ARR
|
||||
#define __COPY_ARR(___name__) (void)memcpy(dest.rule[index].___name__, source.rule[index].___name__.data(), source.rule[index].___name__.size())
|
||||
__COPY_ITEM(index);
|
||||
__COPY_ARR(keyMacDa);
|
||||
__COPY_ARR(maskMacDa);
|
||||
__COPY_ARR(keyMacSa);
|
||||
__COPY_ARR(maskMacSa);
|
||||
__COPY_ITEM(keyVlanTagOuter1.vid);
|
||||
__COPY_ITEM(keyVlanTagOuter1.priCfi);
|
||||
__COPY_ITEM(keyMplsOuter1.mplsLabel);
|
||||
__COPY_ITEM(keyMplsOuter1.exp);
|
||||
__COPY_ITEM(maskVlanTagOuter1.vid);
|
||||
__COPY_ITEM(maskVlanTagOuter1.priCfi);
|
||||
__COPY_ITEM(maskMplsOuter1.mplsLabel);
|
||||
__COPY_ITEM(maskMplsOuter1.exp);
|
||||
__COPY_ITEM(keyVlanTagOuter2.vid);
|
||||
__COPY_ITEM(keyVlanTagOuter2.priCfi);
|
||||
__COPY_ITEM(keyMplsOuter2.mplsLabel);
|
||||
__COPY_ITEM(keyMplsOuter2.exp);
|
||||
__COPY_ITEM(maskVlanTagOuter2.vid);
|
||||
__COPY_ITEM(maskVlanTagOuter2.priCfi);
|
||||
__COPY_ITEM(maskMplsOuter2.mplsLabel);
|
||||
__COPY_ITEM(maskMplsOuter2.exp);
|
||||
__COPY_ITEM(keyEthertype);
|
||||
__COPY_ITEM(maskEthertype);
|
||||
__COPY_ITEM(keyBonusData);
|
||||
__COPY_ITEM(maskBonusData);
|
||||
__COPY_ITEM(keyTagMatchBitmap);
|
||||
__COPY_ITEM(maskTagMatchBitmap);
|
||||
__COPY_ITEM(keyPacketType);
|
||||
__COPY_ITEM(maskPacketType);
|
||||
__COPY_ITEM(keyInnerVlanType);
|
||||
__COPY_ITEM(maskInnerVlanType);
|
||||
__COPY_ITEM(keyOuterVlanType);
|
||||
__COPY_ITEM(maskOuterVlanType);
|
||||
__COPY_ITEM(keyNumTags);
|
||||
__COPY_ITEM(maskNumTags);
|
||||
__COPY_ITEM(keyExpress);
|
||||
__COPY_ITEM(maskExpress);
|
||||
__COPY_ITEM(isMpls);
|
||||
__COPY_ITEM(enable);
|
||||
}
|
||||
|
||||
for (int index = 0; index < MACsecConfig::NumMaps; index++)
|
||||
{
|
||||
if(!source.map[index].enable) continue;
|
||||
#undef __COPY_ITEM
|
||||
#define __COPY_ITEM(___name__) dest.map[index].___name__ = source.map[index].___name__
|
||||
__COPY_ITEM(index);
|
||||
__COPY_ITEM(secTagSci);
|
||||
__COPY_ITEM(secYIndex);
|
||||
__COPY_ITEM(isControlPacket);
|
||||
__COPY_ITEM(scIndex);
|
||||
__COPY_ITEM(auxiliaryPlcy);
|
||||
__COPY_ITEM(ruleId);
|
||||
__COPY_ITEM(enable);
|
||||
}
|
||||
|
||||
for (int index = 0; index < MACsecConfig::NumSecY; index++)
|
||||
{
|
||||
if(!source.secy[index].enable) continue;
|
||||
#undef __COPY_ITEM
|
||||
#define __COPY_ITEM(___name__) dest.secy[index].___name__ = (decltype(dest.secy[index].___name__))source.secy[index].___name__
|
||||
__COPY_ITEM(index);
|
||||
__COPY_ITEM(controlledPortEnabled);
|
||||
__COPY_ITEM(frameValidationType);
|
||||
__COPY_ITEM(secTagIcvStripType);
|
||||
__COPY_ITEM(cipher);
|
||||
__COPY_ITEM(confidentialOffset);
|
||||
__COPY_ITEM(icvIncludesDaSa);
|
||||
__COPY_ITEM(replayProtect);
|
||||
__COPY_ITEM(replayWindow);
|
||||
__COPY_ITEM(protectFrames);
|
||||
__COPY_ITEM(secTagOffset);
|
||||
__COPY_ITEM(secTagTci);
|
||||
__COPY_ITEM(mtu);
|
||||
__COPY_ITEM(enable);
|
||||
}
|
||||
|
||||
for (int index = 0; index < MACsecConfig::NumSc; index++)
|
||||
{
|
||||
if(!source.sc[index].enable) continue;
|
||||
#undef __COPY_ITEM
|
||||
#define __COPY_ITEM(___name__) dest.sc[index].___name__ = source.sc[index].___name__
|
||||
__COPY_ITEM(index);
|
||||
__COPY_ITEM(secYIndex);
|
||||
__COPY_ITEM(sci);
|
||||
__COPY_ITEM(saIndex0);
|
||||
__COPY_ITEM(saIndex1);
|
||||
__COPY_ITEM(saIndex0InUse);
|
||||
__COPY_ITEM(saIndex1InUse);
|
||||
__COPY_ITEM(enableAutoRekey);
|
||||
__COPY_ITEM(isActiveSa1);
|
||||
__COPY_ITEM(enable);
|
||||
}
|
||||
|
||||
for (int index = 0; index < MACsecConfig::NumSa; index++)
|
||||
{
|
||||
if(!source.sa[index].enable) continue;
|
||||
#undef __COPY_ITEM
|
||||
#define __COPY_ITEM(___name__) dest.sa[index].___name__ = source.sa[index].___name__
|
||||
#undef __COPY_ARR
|
||||
#define __COPY_ARR(___name__) (void)memcpy(dest.sa[index].___name__, source.sa[index].___name__.data(), source.sa[index].___name__.size())
|
||||
__COPY_ITEM(index);
|
||||
__COPY_ARR(sak);
|
||||
__COPY_ARR(hashKey);
|
||||
__COPY_ARR(salt);
|
||||
__COPY_ITEM(ssci);
|
||||
__COPY_ITEM(an);
|
||||
__COPY_ITEM(nextPn);
|
||||
__COPY_ITEM(enable);
|
||||
}
|
||||
};
|
||||
macsecArgs->macsec.flags.en = this->flags.en;
|
||||
macsecArgs->macsec.flags.nvm = this->flags.nvm;
|
||||
|
||||
copyConfig(this->rx, macsecArgs->macsec.rx);
|
||||
copyConfig(this->tx, macsecArgs->macsec.tx);
|
||||
|
||||
macsecArgs->crc32 = crc32(0, (uint8_t*)&macsecArgs->macsec, sizeof(MACSEC_SETTINGS));
|
||||
|
||||
(void)report;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -14,9 +14,9 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
|
||||
neomsg.timestamp = message->timestamp;
|
||||
switch (message->type)
|
||||
{
|
||||
case Message::Type::BusMessage: {
|
||||
case Message::Type::Frame: {
|
||||
neomessage_frame_t& frame = *(neomessage_frame_t*)&neomsg;
|
||||
auto framemsg = std::static_pointer_cast<BusMessage>(message);
|
||||
auto framemsg = std::static_pointer_cast<Frame>(message);
|
||||
const auto netType = framemsg->network.getType();
|
||||
|
||||
frame.netid = (neonetid_t)framemsg->network.getNetID();
|
||||
@@ -75,13 +75,15 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
|
||||
lin.length = 1;
|
||||
|
||||
lin.linStatus = {
|
||||
linmsg->statusFlags.TxChecksumEnhanced,
|
||||
linmsg->statusFlags.TxCommander,
|
||||
linmsg->statusFlags.TxResponder,
|
||||
linmsg->statusFlags.UpdateResponderOnce,
|
||||
linmsg->statusFlags.HasUpdatedResponderOnce,
|
||||
linmsg->statusFlags.BusRecovered,
|
||||
linmsg->statusFlags.BreakOnly
|
||||
linmsg->statusFlags.TxChecksumEnhanced, // .txChecksumEnhanced
|
||||
linmsg->statusFlags.TxCommander, // .txCommander
|
||||
linmsg->statusFlags.TxResponder, // .txResponder
|
||||
0, // .txAborted
|
||||
linmsg->statusFlags.UpdateResponderOnce, // .updateResponderOnce
|
||||
linmsg->statusFlags.HasUpdatedResponderOnce, // .hasUpdatedResponderOnce
|
||||
linmsg->statusFlags.BusRecovered, // .busRecovered
|
||||
linmsg->statusFlags.BreakOnly // .breakOnly
|
||||
|
||||
};
|
||||
|
||||
lin.status.linJustBreakSync = linmsg->errFlags.ErrRxBreakSyncOnly;
|
||||
@@ -120,7 +122,7 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
|
||||
|
||||
std::shared_ptr<Message> icsneo::CreateMessageFromNeoMessage(const neomessage_t* neomessage) {
|
||||
switch((Message::Type)neomessage->messageType) {
|
||||
case Message::Type::BusMessage: {
|
||||
case Message::Type::Frame: {
|
||||
const Network network = ((neomessage_frame_t*)neomessage)->netid;
|
||||
switch(network.getType()) {
|
||||
case Network::Type::CAN:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
std::optional<uint8_t> icsneo::CAN_DLCToLength(uint8_t length, bool fd) {
|
||||
static std::optional<uint8_t> CAN_DLCToLength(uint8_t length, bool fd) {
|
||||
if (length <= 8)
|
||||
return length;
|
||||
|
||||
@@ -29,7 +29,7 @@ std::optional<uint8_t> icsneo::CAN_DLCToLength(uint8_t length, bool fd) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<uint8_t> icsneo::CAN_LengthToDLC(size_t dataLength, bool fd)
|
||||
static std::optional<uint8_t> CAN_LengthToDLC(size_t dataLength, bool fd)
|
||||
{
|
||||
if (dataLength <= 8)
|
||||
return uint8_t(dataLength);
|
||||
|
||||
@@ -31,7 +31,7 @@ std::shared_ptr<ComponentVersionsMessage> ComponentVersionPacket::DecodeToMessag
|
||||
// Get a reference to the payload to fully validate the length
|
||||
const auto& response = *reinterpret_cast<const ComponentVersionsResponse*>(bytes.data());
|
||||
// Expected size is the header, numVersions field, and numVersions ComponentVersion objects.
|
||||
auto expectedSize = sizeof(ExtendedResponseMessage::ResponseHeader) + 2 + (response.numVersions * sizeof(ComponentVersion));
|
||||
auto expectedSize = sizeof(ExtendedResponseMessage::ResponseHeader) + 2 + (response.numVersions * sizeof(PackedComponentVersion));
|
||||
// If the response is malformed (too small), return an empty message.
|
||||
if(bytes.size() < expectedSize) {
|
||||
return msg; // Empty
|
||||
@@ -39,7 +39,14 @@ std::shared_ptr<ComponentVersionsMessage> ComponentVersionPacket::DecodeToMessag
|
||||
// Unpack into the portable class
|
||||
for(unsigned int i = 0; i < response.numVersions; ++i) {
|
||||
const auto& packedVersion = response.versions[i];
|
||||
msg->versions.emplace_back(packedVersion.valid, packedVersion.componentInfo, packedVersion.identifier, packedVersion.dotVersion, packedVersion.commitHash);
|
||||
msg->versions.emplace_back(
|
||||
packedVersion.valid,
|
||||
packedVersion.componentInfo,
|
||||
packedVersion.identifier,
|
||||
packedVersion.dotVersion,
|
||||
packedVersion.commitHash,
|
||||
packedVersion.expansionSlot
|
||||
);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "icsneo/communication/packet/ethernetpacket.h"
|
||||
#include <cstring> // memcpy
|
||||
#include <algorithm> // for std::copy
|
||||
#include <iostream>
|
||||
|
||||
using namespace icsneo;
|
||||
@@ -7,40 +7,31 @@ using namespace icsneo;
|
||||
std::shared_ptr<EthernetMessage> HardwareEthernetPacket::DecodeToMessage(const std::vector<uint8_t>& bytestream, const device_eventhandler_t& report) {
|
||||
const HardwareEthernetPacket* packet = (const HardwareEthernetPacket*)((const void*)bytestream.data());
|
||||
const uint16_t* rawWords = (const uint16_t*)bytestream.data();
|
||||
|
||||
// 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;
|
||||
const size_t bytestreamExpectedSize = sizeof(HardwareEthernetPacket) + packet->Length;
|
||||
const size_t bytestreamActualSize = bytestream.size();
|
||||
if(bytestreamActualSize < bytestreamExpectedSize)
|
||||
return nullptr;
|
||||
|
||||
// Check for oversized packets, noting that some devices will send an extra byte to have an even number of bytes
|
||||
if(bytestreamActualSize > bytestreamExpectedSize + 1)
|
||||
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::EventWarning);
|
||||
|
||||
auto messagePtr = std::make_shared<EthernetMessage>();
|
||||
EthernetMessage& message = *messagePtr;
|
||||
|
||||
message.transmitted = packet->eid.TXMSG;
|
||||
if(message.transmitted)
|
||||
message.description = packet->stats;
|
||||
|
||||
message.preemptionEnabled = packet->header.PREEMPTION_ENABLED;
|
||||
if(message.preemptionEnabled)
|
||||
message.preemptionFlags = (uint8_t)((rawWords[0] & 0x03F8) >> 4);
|
||||
|
||||
message.frameTooShort = packet->header.RUNT_FRAME;
|
||||
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;
|
||||
@@ -59,41 +50,83 @@ std::shared_ptr<EthernetMessage> HardwareEthernetPacket::DecodeToMessage(const s
|
||||
|
||||
bool HardwareEthernetPacket::EncodeFromMessage(const EthernetMessage& message, std::vector<uint8_t>& bytestream, const device_eventhandler_t&) {
|
||||
const size_t unpaddedSize = message.data.size();
|
||||
size_t paddedSize = unpaddedSize;
|
||||
uint16_t description = message.description;
|
||||
|
||||
if(!message.noPadding && unpaddedSize < 60)
|
||||
paddedSize = 60; // Pad out short messages
|
||||
|
||||
size_t sizeWithHeader = paddedSize + 4; // DescriptionID and Padded Count
|
||||
if(unpaddedSize == 0)
|
||||
return false;
|
||||
|
||||
// Description ID Most Significant bit is used to identify preemption frames
|
||||
uint16_t description = message.description;
|
||||
if(description & 0x8000)
|
||||
return false;
|
||||
|
||||
if(message.preemptionEnabled) {
|
||||
sizeWithHeader++; // Make space for the preemption flags
|
||||
const bool preempt = message.preemptionEnabled;
|
||||
// full header including parent
|
||||
const size_t headerByteCount = preempt ? 15 : 14;
|
||||
// local header for netID, description, and flags
|
||||
const size_t localHeader = preempt ? 10 : 9;
|
||||
// allocate space for fcs override
|
||||
const size_t fcsSize = message.fcs ? 4 : 0;
|
||||
|
||||
if(preempt)
|
||||
description |= 0x8000;
|
||||
|
||||
size_t paddedSize = unpaddedSize;
|
||||
if(!message.noPadding && unpaddedSize < 60)
|
||||
paddedSize = 60;
|
||||
|
||||
// size of full payload including optional fcs
|
||||
size_t payloadSize = paddedSize + fcsSize;
|
||||
|
||||
|
||||
// totalBufferSize is local header + ethernet payload and option fcs
|
||||
const size_t totalBufferSize = localHeader + paddedSize + fcsSize;
|
||||
|
||||
bytestream.clear();
|
||||
bytestream.reserve(totalBufferSize);
|
||||
|
||||
// Header size field (little endian)
|
||||
bytestream.push_back(static_cast<uint8_t>(payloadSize & 0xFF));
|
||||
bytestream.push_back(static_cast<uint8_t>((payloadSize >> 8) & 0xFF));
|
||||
|
||||
// Description (big endian)
|
||||
bytestream.push_back(static_cast<uint8_t>(description >> 8));
|
||||
bytestream.push_back(static_cast<uint8_t>(description));
|
||||
|
||||
bytestream.push_back(0x00);
|
||||
bytestream.push_back(static_cast<uint8_t>(headerByteCount));
|
||||
|
||||
// Network ID (little endian)
|
||||
uint16_t realID = static_cast<uint16_t>(message.network.getNetID());
|
||||
bytestream.push_back(static_cast<uint8_t>(realID & 0xFF));
|
||||
bytestream.push_back(static_cast<uint8_t>((realID >> 8) & 0xFF));
|
||||
|
||||
// Flags
|
||||
constexpr uint8_t FLAG_PADDING = 0x01;
|
||||
constexpr uint8_t FLAG_FCS = 0x04;
|
||||
constexpr uint8_t FLAG_PREEMPTION = 0x08;
|
||||
|
||||
uint8_t flags = 0x00;
|
||||
if(!message.noPadding) flags |= FLAG_PADDING;
|
||||
if(message.fcs) flags |= FLAG_FCS;
|
||||
if(message.preemptionEnabled) flags |= FLAG_PREEMPTION;
|
||||
|
||||
bytestream.push_back(flags);
|
||||
|
||||
if(preempt)
|
||||
bytestream.push_back(static_cast<uint8_t>(message.preemptionFlags));
|
||||
|
||||
bytestream.insert(bytestream.end(), message.data.begin(), message.data.end());
|
||||
|
||||
// Only zero-fill when we want padding
|
||||
if(!message.noPadding && unpaddedSize < 60) {
|
||||
size_t paddingNeeded = 60 - unpaddedSize;
|
||||
bytestream.insert(bytestream.end(), paddingNeeded, 0); // Zero-fill for padding
|
||||
}
|
||||
|
||||
bytestream.reserve(sizeWithHeader + 8); // Also reserve space for the bytes we'll use later on
|
||||
bytestream.resize(sizeWithHeader);
|
||||
size_t index = 0;
|
||||
|
||||
// Padded size, little endian
|
||||
bytestream[index++] = uint8_t(paddedSize);
|
||||
bytestream[index++] = uint8_t(paddedSize >> 8);
|
||||
|
||||
// Description ID, big endian
|
||||
bytestream[index++] = uint8_t(description >> 8);
|
||||
bytestream[index++] = uint8_t(description);
|
||||
|
||||
// The header is one byte larger if preemption is enabled, shifting the data
|
||||
if(message.preemptionEnabled)
|
||||
bytestream[index++] = message.preemptionFlags;
|
||||
|
||||
// We only copy in the unpadded size, the rest will be 0
|
||||
memcpy(bytestream.data() + index, message.data.data(), unpaddedSize);
|
||||
if(message.fcs) {
|
||||
uint32_t fcs = message.fcs.value();
|
||||
const uint8_t* fcsBytes = reinterpret_cast<const uint8_t*>(&fcs);
|
||||
bytestream.insert(bytestream.end(), fcsBytes, fcsBytes + sizeof(fcs));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -31,7 +31,7 @@ std::shared_ptr<Message> HardwareLINPacket::DecodeToMessage(const std::vector<ui
|
||||
auto isChecksumInvalid = [&]() -> bool {
|
||||
/* messages with no data have no checksum (e.g. header only) */
|
||||
if(!msg->data.size())
|
||||
return true;
|
||||
return false;
|
||||
|
||||
uint8_t checkSum = (8 > numDataBytes) ? *(dataStart + numDataBytes) : packet->CoreMiniBitsLIN.LINByte9;
|
||||
LINMessage::calcChecksum(*msg);
|
||||
|
||||
@@ -99,6 +99,33 @@ bool HardwareLiveDataPacket::EncodeFromMessage(LiveDataMessage& message, std::ve
|
||||
clearMsg->cmd = static_cast<uint32_t>(message.cmd);
|
||||
break;
|
||||
}
|
||||
case LiveDataCommand::SET_VALUE: {
|
||||
auto setValMsg = reinterpret_cast<LiveDataSetValueMessage*>(&message);
|
||||
const auto numArgs = setValMsg->args.size();
|
||||
if(numArgs) {
|
||||
payloadSize = static_cast<uint16_t>(sizeof(LiveDataSetValue) + (sizeof(LiveDataSetValueEntry) * (numArgs-1)));
|
||||
bytestream.resize((payloadSize + sizeof(ExtendedCommandHeader)),0);
|
||||
LiveDataSetValue* out = reinterpret_cast<LiveDataSetValue*>(bytestream.data() + sizeof(ExtendedCommandHeader));
|
||||
out->version = icsneo::LiveDataUtil::LiveDataVersion;
|
||||
out->cmd = static_cast<uint32_t>(setValMsg->cmd);
|
||||
if(!setValMsg->handle)
|
||||
setValMsg->handle = LiveDataUtil::getNewHandle();
|
||||
out->handle = setValMsg->handle;
|
||||
out->numSetValues = (uint32_t)numArgs;
|
||||
for(size_t i = 0; i < numArgs; ++i) {
|
||||
out->values[i].arg.objectType = setValMsg->args[i]->objectType;
|
||||
out->values[i].arg.objectIndex = setValMsg->args[i]->objectIndex;
|
||||
out->values[i].arg.signalIndex = setValMsg->args[i]->signalIndex;
|
||||
out->values[i].arg.valueType = setValMsg->args[i]->valueType;
|
||||
out->values[i].value.value = setValMsg->values[i]->value;
|
||||
out->values[i].value.header.length = sizeof(LiveDataValue::value);
|
||||
}
|
||||
} else {
|
||||
report(APIEvent::Type::LiveDataInvalidArgument, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
report(APIEvent::Type::LiveDataInvalidCommand, APIEvent::Severity::Error);
|
||||
return false;
|
||||
|
||||
+320
-61
@@ -5,6 +5,7 @@
|
||||
#include "icsneo/device/device.h"
|
||||
#include "icsneo/device/extensions/deviceextension.h"
|
||||
#include "icsneo/disk/fat.h"
|
||||
#include "icsneo/communication/message/filter/extendedresponsefilter.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4996) // STL time functions
|
||||
@@ -88,6 +89,10 @@ Device::~Device() {
|
||||
disableMessagePolling();
|
||||
if(isOpen())
|
||||
close();
|
||||
if(heartbeatThread.joinable()) {
|
||||
stopHeartbeatThread = true;
|
||||
heartbeatThread.join();
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t Device::getTimestampResolution() const {
|
||||
@@ -100,15 +105,21 @@ std::string Device::describe() const {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool Device::enableMessagePolling() {
|
||||
bool Device::enableMessagePolling(std::optional<MessageFilter> filter) {
|
||||
if(isMessagePollingEnabled()) {// We are already polling
|
||||
report(APIEvent::Type::DeviceCurrentlyPolling, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
messagePollingCallbackID = com->addMessageCallback(std::make_shared<MessageCallback>([this](std::shared_ptr<Message> message) {
|
||||
if(!filter.has_value()) {
|
||||
// If no filter is provided, use a default that includes all messages
|
||||
filter.emplace(MessageFilter());
|
||||
filter->includeInternalInAny = true;
|
||||
}
|
||||
auto callback = std::make_shared<MessageCallback>(*filter, [this](std::shared_ptr<Message> message) {
|
||||
pollingContainer.enqueue(message);
|
||||
enforcePollingMessageLimit();
|
||||
}));
|
||||
});
|
||||
messagePollingCallbackID = com->addMessageCallback(callback);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -130,6 +141,18 @@ std::pair<std::vector<std::shared_ptr<Message>>, bool> Device::getMessages() {
|
||||
return std::make_pair(ret, retBool);
|
||||
}
|
||||
|
||||
std::shared_ptr<DeviceExtension> Device::getExtension(const std::string& name) const {
|
||||
std::shared_ptr<DeviceExtension> ret;
|
||||
std::lock_guard<std::mutex> lk(extensionsLock);
|
||||
for(auto& ext : extensions) {
|
||||
if((ext->getName() == name)) {
|
||||
ret = ext;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Device::getMessages(std::vector<std::shared_ptr<Message>>& container, size_t limit, std::chrono::milliseconds timeout) {
|
||||
if(!isOpen()) {
|
||||
report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error);
|
||||
@@ -176,6 +199,14 @@ void Device::enforcePollingMessageLimit() {
|
||||
}
|
||||
}
|
||||
|
||||
bool Device::refreshComponentVersions() {
|
||||
if(auto compVersions = com->getComponentVersionsSync()) {
|
||||
componentVersions = std::move(*compVersions);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Device::open(OpenFlags flags, OpenStatusHandler handler) {
|
||||
if(!com) {
|
||||
report(APIEvent::Type::Unknown, APIEvent::Severity::Error);
|
||||
@@ -195,6 +226,7 @@ bool Device::open(OpenFlags flags, OpenStatusHandler handler) {
|
||||
tryAgain = true;
|
||||
return true;
|
||||
});
|
||||
|
||||
if(!tryAgain) {
|
||||
com->close();
|
||||
report(attemptErr, APIEvent::Severity::Error);
|
||||
@@ -218,15 +250,7 @@ bool Device::open(OpenFlags flags, OpenStatusHandler handler) {
|
||||
if(block) // Extensions say no
|
||||
return false;
|
||||
|
||||
// Get component versions again *after* the extension "onDeviceOpen" hooks (e.g. device reflashes)
|
||||
if(supportsComponentVersions()) {
|
||||
if(auto compVersions = com->getComponentVersionsSync())
|
||||
componentVersions = std::move(*compVersions);
|
||||
else
|
||||
// It's possible the device is on older firmware so don't return false here
|
||||
report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::EventWarning);
|
||||
}
|
||||
|
||||
refreshComponentVersions();
|
||||
if(!settings->disabled) {
|
||||
// Since we will not fail the open if a settings read fails,
|
||||
// downgrade any errors to warnings. Otherwise the error will
|
||||
@@ -245,6 +269,12 @@ bool Device::open(OpenFlags flags, OpenStatusHandler handler) {
|
||||
handleInternalMessage(message);
|
||||
}));
|
||||
|
||||
// Clear the previous heartbeat thread, in case open() was called on this instance more than once
|
||||
if(heartbeatThread.joinable())
|
||||
heartbeatThread.join();
|
||||
|
||||
stopHeartbeatThread = false;
|
||||
|
||||
heartbeatThread = std::thread([this]() {
|
||||
EventManager::GetInstance().downgradeErrorsOnCurrentThread();
|
||||
|
||||
@@ -254,7 +284,7 @@ bool Device::open(OpenFlags flags, OpenStatusHandler handler) {
|
||||
std::condition_variable heartbeatCV;
|
||||
std::mutex receivedMessageMutex;
|
||||
bool receivedMessage = false;
|
||||
auto messageReceivedCallbackID = com->addMessageCallback(std::make_shared<MessageCallback>(filter, [&](std::shared_ptr<Message> message) {
|
||||
auto messageReceivedCallbackID = com->addMessageCallback(std::make_shared<MessageCallback>(filter, [&](std::shared_ptr<Message>) {
|
||||
{
|
||||
std::scoped_lock<std::mutex> lk(receivedMessageMutex);
|
||||
receivedMessage = true;
|
||||
@@ -270,12 +300,12 @@ bool Device::open(OpenFlags flags, OpenStatusHandler handler) {
|
||||
}
|
||||
|
||||
while(!stopHeartbeatThread) {
|
||||
// Wait for 110ms for a possible heartbeat
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(110));
|
||||
std::unique_lock<std::mutex> recvLk(receivedMessageMutex);
|
||||
if(receivedMessage) {
|
||||
// Wait for 110ms for a possible heartbeat
|
||||
if(heartbeatCV.wait_for(recvLk, std::chrono::milliseconds(110), [&]() { return receivedMessage; })) {
|
||||
receivedMessage = false;
|
||||
} else {
|
||||
} else if(!stopHeartbeatThread) { // Add this condition here in case the thread was stopped while waiting for the last message
|
||||
|
||||
// Some communication, such as the bootloader and extractor interfaces, must
|
||||
// redirect the input stream from the device as it will no longer be in the
|
||||
// packet format we expect here. As a result, status updates will not reach
|
||||
@@ -284,9 +314,8 @@ bool Device::open(OpenFlags flags, OpenStatusHandler handler) {
|
||||
// otherwise quiet stream. This lock makes sure suppressDisconnects() will
|
||||
// block until we've either gotten our status update or disconnected from
|
||||
// the device.
|
||||
std::lock_guard<std::mutex> lk(heartbeatMutex);
|
||||
if(heartbeatSuppressed())
|
||||
continue;
|
||||
std::unique_lock<std::mutex> lk(heartbeatMutex);
|
||||
if(heartbeatSuppressed()) continue;
|
||||
|
||||
// No heartbeat received, request a status
|
||||
com->sendCommand(Command::RequestStatusUpdate);
|
||||
@@ -296,8 +325,8 @@ bool Device::open(OpenFlags flags, OpenStatusHandler handler) {
|
||||
receivedMessage = false;
|
||||
} else {
|
||||
if(!stopHeartbeatThread && !isDisconnected()) {
|
||||
close();
|
||||
report(APIEvent::Type::DeviceDisconnected, APIEvent::Severity::Error);
|
||||
com->driver->close();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -323,7 +352,7 @@ APIEvent::Type Device::attemptToBeginCommunication() {
|
||||
return getCommunicationNotEstablishedError();
|
||||
}
|
||||
|
||||
if(!com->sendCommand(Command::EnableNetworkCommunication, false))
|
||||
if(!enableNetworkCommunication(false))
|
||||
return getCommunicationNotEstablishedError();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
|
||||
@@ -334,6 +363,7 @@ APIEvent::Type Device::attemptToBeginCommunication() {
|
||||
if(i++ > 5)
|
||||
break;
|
||||
}
|
||||
|
||||
if(!serial) // "Communication could not be established with the device. Perhaps it is not powered with 12 volts?"
|
||||
return getCommunicationNotEstablishedError();
|
||||
|
||||
@@ -347,13 +377,12 @@ APIEvent::Type Device::attemptToBeginCommunication() {
|
||||
else
|
||||
versions = std::move(*maybeVersions);
|
||||
|
||||
|
||||
// Get component versions before the extension "onDeviceOpen" hooks so that we can properly check verisons
|
||||
if(supportsComponentVersions()) {
|
||||
if(auto compVersions = com->getComponentVersionsSync())
|
||||
componentVersions = std::move(*compVersions);
|
||||
else
|
||||
return getCommunicationNotEstablishedError();
|
||||
report(APIEvent::Type::NotSupported, APIEvent::Severity::EventWarning); // outdated firmware
|
||||
}
|
||||
|
||||
return APIEvent::Type::NoErrorFound;
|
||||
@@ -379,16 +408,21 @@ bool Device::close() {
|
||||
|
||||
internalHandlerCallbackID = 0;
|
||||
|
||||
if(heartbeatThread.joinable())
|
||||
heartbeatThread.join();
|
||||
stopHeartbeatThread = false;
|
||||
|
||||
forEachExtension([](const std::shared_ptr<DeviceExtension>& ext) { ext->onDeviceClose(); return true; });
|
||||
return com->close();
|
||||
}
|
||||
|
||||
bool Device::enableLogData() {
|
||||
return com->sendCommand(Command::EnableLogData, true);
|
||||
}
|
||||
|
||||
bool Device::disableLogData() {
|
||||
return com->sendCommand(Command::EnableLogData, false);
|
||||
}
|
||||
|
||||
bool Device::goOnline() {
|
||||
if(!com->sendCommand(Command::EnableNetworkCommunication, true))
|
||||
static constexpr uint32_t onlineTimeoutMs = 5000;
|
||||
if(!enableNetworkCommunication(true, onlineTimeoutMs))
|
||||
return false;
|
||||
|
||||
auto startTime = std::chrono::system_clock::now();
|
||||
@@ -417,13 +451,19 @@ bool Device::goOnline() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// (re)start the keeponline
|
||||
keeponline = std::make_unique<Periodic>([this] { return enableNetworkCommunication(true, onlineTimeoutMs); }, std::chrono::milliseconds(onlineTimeoutMs / 4));
|
||||
|
||||
online = true;
|
||||
|
||||
forEachExtension([](const std::shared_ptr<DeviceExtension>& ext) { ext->onGoOnline(); return true; });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Device::goOffline() {
|
||||
keeponline.reset();
|
||||
|
||||
forEachExtension([](const std::shared_ptr<DeviceExtension>& ext) { ext->onGoOffline(); return true; });
|
||||
|
||||
if(isDisconnected()) {
|
||||
@@ -431,29 +471,13 @@ bool Device::goOffline() {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!com->sendCommand(Command::EnableNetworkCommunication, false))
|
||||
if(!enableNetworkCommunication(false))
|
||||
return false;
|
||||
|
||||
auto startTime = std::chrono::system_clock::now();
|
||||
|
||||
ledState = (latestResetStatus && latestResetStatus->cmRunning) ? LEDState::CoreMiniRunning : LEDState::Offline;
|
||||
|
||||
updateLEDState();
|
||||
|
||||
std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(Network::NetID::Reset_Status);
|
||||
filter->includeInternalInAny = true;
|
||||
|
||||
// Wait until communication is disabled or 5 seconds, whichever comes first
|
||||
while((std::chrono::system_clock::now() - startTime) < std::chrono::seconds(5)) {
|
||||
if(latestResetStatus && !latestResetStatus->comEnabled)
|
||||
break;
|
||||
|
||||
if(!com->sendCommand(Command::RequestStatusUpdate))
|
||||
return false;
|
||||
|
||||
com->waitForMessageSync(filter, std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
online = false;
|
||||
|
||||
return true;
|
||||
@@ -480,7 +504,7 @@ int8_t Device::prepareScriptLoad() {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto resp = std::static_pointer_cast<InternalMessage>(generic);
|
||||
const auto resp = std::static_pointer_cast<RawMessage>(generic);
|
||||
retVal = (int8_t)resp->data[0];
|
||||
}
|
||||
|
||||
@@ -743,7 +767,7 @@ std::optional<CoreminiHeader> Device::readCoreminiHeader(Disk::MemoryType memTyp
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Device::transmit(std::shared_ptr<BusMessage> frame) {
|
||||
bool Device::transmit(std::shared_ptr<Frame> frame) {
|
||||
if(!isOpen()) {
|
||||
report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error);
|
||||
return false;
|
||||
@@ -776,7 +800,7 @@ bool Device::transmit(std::shared_ptr<BusMessage> frame) {
|
||||
return com->sendPacket(packet);
|
||||
}
|
||||
|
||||
bool Device::transmit(std::vector<std::shared_ptr<BusMessage>> frames) {
|
||||
bool Device::transmit(std::vector<std::shared_ptr<Frame>> frames) {
|
||||
for(auto& frame : frames) {
|
||||
if(!transmit(frame))
|
||||
return false;
|
||||
@@ -814,7 +838,6 @@ std::shared_ptr<HardwareInfo> Device::getHardwareInfo(std::chrono::milliseconds
|
||||
report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto filter = std::make_shared<MessageFilter>(Message::Type::HardwareInfo);
|
||||
|
||||
auto response = com->waitForMessageSync([this]() {
|
||||
@@ -1694,7 +1717,10 @@ void Device::stopScriptStatusThreadIfNecessary(std::unique_lock<std::mutex> lk)
|
||||
Lifetime Device::suppressDisconnects() {
|
||||
std::lock_guard<std::mutex> lk(heartbeatMutex);
|
||||
heartbeatSuppressedByUser++;
|
||||
return Lifetime([this] { std::lock_guard<std::mutex> lk2(heartbeatMutex); heartbeatSuppressedByUser--; });
|
||||
return Lifetime([this] {
|
||||
std::lock_guard<std::mutex> lk2(heartbeatMutex);
|
||||
heartbeatSuppressedByUser--;
|
||||
});
|
||||
}
|
||||
|
||||
void Device::addExtension(std::shared_ptr<DeviceExtension>&& extension) {
|
||||
@@ -1721,8 +1747,8 @@ void Device::handleInternalMessage(std::shared_ptr<Message> message) {
|
||||
case Message::Type::ResetStatus:
|
||||
latestResetStatus = std::static_pointer_cast<ResetStatusMessage>(message);
|
||||
break;
|
||||
case Message::Type::InternalMessage: {
|
||||
auto rawMessage = std::static_pointer_cast<InternalMessage>(message);
|
||||
case Message::Type::RawMessage: {
|
||||
auto rawMessage = std::static_pointer_cast<RawMessage>(message);
|
||||
switch(rawMessage->network.getNetID()) {
|
||||
case Network::NetID::DeviceStatus:
|
||||
// Device Status format is unique per device, so the devices need to decode it themselves
|
||||
@@ -1733,8 +1759,8 @@ void Device::handleInternalMessage(std::shared_ptr<Message> message) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Message::Type::BusMessage: {
|
||||
// Device is not guaranteed to be a CANMessage, it might be a InternalMessage
|
||||
case Message::Type::Frame: {
|
||||
// Device is not guaranteed to be a CANMessage, it might be a RawMessage
|
||||
// if it couldn't be decoded to a CANMessage. We only care about the
|
||||
// CANMessage decoding right now.
|
||||
auto canmsg = std::dynamic_pointer_cast<CANMessage>(message);
|
||||
@@ -1898,7 +1924,7 @@ std::optional<std::chrono::time_point<std::chrono::system_clock>> Device::getRTC
|
||||
if(!generic) // Did not receive a message
|
||||
return std::nullopt;
|
||||
|
||||
auto rawMes = std::dynamic_pointer_cast<InternalMessage>(generic);
|
||||
auto rawMes = std::dynamic_pointer_cast<RawMessage>(generic);
|
||||
if(!rawMes)
|
||||
return std::nullopt;
|
||||
|
||||
@@ -1987,11 +2013,6 @@ std::optional<size_t> Device::getGenericBinarySize(uint16_t binaryIndex) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if(!isOnline()) {
|
||||
report(APIEvent::Type::DeviceCurrentlyOffline, APIEvent::Severity::Error);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> args = GenericBinaryStatusPacket::EncodeArguments(binaryIndex);
|
||||
|
||||
std::shared_ptr<Message> response = com->waitForMessageSync(
|
||||
@@ -2054,6 +2075,40 @@ bool Device::readBinaryFile(std::ostream& stream, uint16_t binaryIndex) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Device::writeBinaryFile(const std::vector<uint8_t>& in, uint16_t binaryIndex)
|
||||
{
|
||||
auto timeout = std::chrono::milliseconds(100);
|
||||
|
||||
auto size = in.size();
|
||||
|
||||
std::vector<uint8_t> arguments(sizeof(ExtendedDataMessage::ExtendedDataHeader) + ExtendedDataMessage::MaxExtendedDataBufferSize);
|
||||
ExtendedDataMessage::ExtendedDataHeader& parameters = *reinterpret_cast<ExtendedDataMessage::ExtendedDataHeader*>(arguments.data());
|
||||
|
||||
auto filter = std::make_shared<MessageFilter>(Network::NetID::ExtendedData);
|
||||
|
||||
for (size_t offset = 0; offset < size; offset += ExtendedDataMessage::MaxExtendedDataBufferSize)
|
||||
{
|
||||
parameters.subCommand = ExtendedDataSubCommand::GenericBinaryWrite;
|
||||
parameters.userValue = static_cast<uint32_t>(binaryIndex);
|
||||
parameters.offset = static_cast<uint32_t>(offset);
|
||||
parameters.length = static_cast<uint32_t>(std::min(ExtendedDataMessage::MaxExtendedDataBufferSize, size - offset));
|
||||
(void)memcpy(&arguments[sizeof(ExtendedDataMessage::ExtendedDataHeader)], &in[offset], parameters.length);
|
||||
|
||||
std::shared_ptr<Message> response = com->waitForMessageSync(
|
||||
[this, arguments]() {
|
||||
return com->sendCommand(Command::ExtendedData, arguments);
|
||||
},
|
||||
filter,
|
||||
timeout
|
||||
);
|
||||
if (!response) {
|
||||
report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Device::subscribeLiveData(std::shared_ptr<LiveDataCommandMessage> message) {
|
||||
if(!supportsLiveData()) {
|
||||
report(APIEvent::Type::LiveDataNotSupported, APIEvent::Severity::Error);
|
||||
@@ -2194,6 +2249,61 @@ bool Device::clearAllLiveData() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Device::setValueLiveData(std::shared_ptr<LiveDataSetValueMessage> message) {
|
||||
if(!supportsLiveData()) {
|
||||
report(APIEvent::Type::LiveDataNotSupported, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
if(!isOpen()) {
|
||||
report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
if((message->args.size() != message->values.size()) || message->args.empty()) {
|
||||
report(APIEvent::Type::LiveDataInvalidArgument, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> bytes;
|
||||
if(!com->encoder->encode(*com->packetizer, bytes, message)) {
|
||||
report(APIEvent::Type::LiveDataEncoderError, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<Message> response = com->waitForMessageSync(
|
||||
[this, &bytes](){ return com->sendPacket(bytes); },
|
||||
std::make_shared<MessageFilter>(Message::Type::LiveData));
|
||||
|
||||
if(response) {
|
||||
auto statusMsg = std::dynamic_pointer_cast<LiveDataStatusMessage>(response);
|
||||
if(statusMsg && statusMsg->requestedCommand == message->cmd) {
|
||||
switch(statusMsg->status) {
|
||||
case LiveDataStatus::SUCCESS:
|
||||
return true;
|
||||
case LiveDataStatus::ERR_DUPLICATE:
|
||||
case LiveDataStatus::ERR_HANDLE:
|
||||
{
|
||||
report(APIEvent::Type::LiveDataInvalidHandle, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
case LiveDataStatus::ERR_FULL:
|
||||
{
|
||||
report(APIEvent::Type::LiveDataMaxSignalsReached, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
case LiveDataStatus::ERR_UNKNOWN_COMMAND:
|
||||
{
|
||||
report(APIEvent::Type::LiveDataCommandFailed, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
report(APIEvent::Type::LiveDataNoDeviceResponse, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Device::readVSA(const VSAExtractionSettings& extractionSettings) {
|
||||
if(isOnline()) {
|
||||
goOffline();
|
||||
@@ -3369,3 +3479,152 @@ std::optional<GPTPStatus> Device::getGPTPStatus(std::chrono::milliseconds timeou
|
||||
|
||||
return *retMsg;
|
||||
}
|
||||
|
||||
bool Device::writeMACsecConfig(const MACsecMessage& message, uint16_t binaryIndex)
|
||||
{
|
||||
std::vector<uint8_t> raw;
|
||||
|
||||
message.EncodeFromMessage(raw, report);
|
||||
|
||||
return writeBinaryFile(raw, binaryIndex);
|
||||
}
|
||||
|
||||
bool Device::enableNetworkCommunication(bool enable, uint32_t timeout) {
|
||||
bool sendMsg = false;
|
||||
if(!com->driver->enableCommunication(enable, sendMsg)) {
|
||||
return false;
|
||||
}
|
||||
if(sendMsg) {
|
||||
const uint8_t* i = (uint8_t*)&timeout;
|
||||
if(!com->sendCommand(Command::EnableNetworkCommunication, {enable, 0, 0, 0, i[0], i[1], i[2], i[3]})) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Device::formatDisk(const DiskDetails& config, const DiskFormatProgress& handler, std::chrono::milliseconds interval) {
|
||||
#pragma pack(push, 2)
|
||||
struct DiskFormatProgressResponse {
|
||||
uint16_t state;
|
||||
uint64_t sectorsRemaining;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
auto diskCount = getDiskCount();
|
||||
|
||||
if(!diskCount) {
|
||||
report(APIEvent::Type::DiskFormatNotSupported, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
if(config.disks.size() != diskCount) {
|
||||
report(APIEvent::Type::DiskFormatInvalidCount, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> payload = DiskDetails::Encode(config);
|
||||
if(!com->sendCommand(ExtendedCommand::DiskFormatStart, payload)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t sectorsFormatted = 0;
|
||||
uint64_t sectorsTotal = 0;
|
||||
uint16_t lastState = 1;
|
||||
do {
|
||||
std::shared_ptr<Message> response = com->waitForMessageSync(
|
||||
[this](){
|
||||
return com->sendCommand(ExtendedCommand::DiskFormatProgress, {});
|
||||
},
|
||||
std::make_shared<ExtendedResponseFilter>(ExtendedCommand::DiskFormatProgress),
|
||||
std::chrono::milliseconds(200)
|
||||
);
|
||||
|
||||
if(!response) {
|
||||
report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto extResponse = std::dynamic_pointer_cast<ExtendedResponseMessage>(response);
|
||||
if(!extResponse) {
|
||||
// Should never happen
|
||||
return false;
|
||||
}
|
||||
|
||||
if(extResponse->data.size() < sizeof(DiskFormatProgressResponse)) {
|
||||
report(APIEvent::Type::BufferInsufficient, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* progress = reinterpret_cast<DiskFormatProgressResponse*>(extResponse->data.data());
|
||||
lastState = progress->state;
|
||||
|
||||
if(sectorsTotal == 0) {
|
||||
sectorsTotal = progress->sectorsRemaining;
|
||||
} else {
|
||||
sectorsFormatted = sectorsTotal - progress->sectorsRemaining;
|
||||
|
||||
if(handler) {
|
||||
auto directive = handler(sectorsFormatted, sectorsTotal);
|
||||
|
||||
if(directive == DiskFormatDirective::Stop) {
|
||||
return com->sendCommand(ExtendedCommand::DiskFormatCancel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(interval);
|
||||
} while(lastState);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Device::forceDiskConfigUpdate(const DiskDetails& config) {
|
||||
auto diskCount = getDiskCount();
|
||||
|
||||
if(!diskCount) {
|
||||
report(APIEvent::Type::DiskFormatNotSupported, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
if(config.disks.size() != diskCount) {
|
||||
report(APIEvent::Type::DiskFormatInvalidCount, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return com->sendCommand(ExtendedCommand::DiskFormatUpdate, DiskDetails::Encode(config));
|
||||
}
|
||||
|
||||
std::shared_ptr<DiskDetails> Device::getDiskDetails(std::chrono::milliseconds timeout) {
|
||||
if(!supportsDiskFormatting()) {
|
||||
report(APIEvent::Type::DiskFormatNotSupported, APIEvent::Severity::Error);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if(!isOpen()) {
|
||||
report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Message> response = com->waitForMessageSync(
|
||||
[this](){
|
||||
return com->sendCommand(ExtendedCommand::GetDiskDetails, {});
|
||||
},
|
||||
std::make_shared<ExtendedResponseFilter>(ExtendedCommand::GetDiskDetails),
|
||||
timeout
|
||||
);
|
||||
|
||||
if(!response) {
|
||||
report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto extResponse = std::dynamic_pointer_cast<ExtendedResponseMessage>(response);
|
||||
if(!extResponse) {
|
||||
// Should never happen
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return DiskDetails::Decode(extResponse->data, getDiskCount(), report);
|
||||
}
|
||||
|
||||
|
||||
+30
-25
@@ -2,6 +2,7 @@
|
||||
#include "icsneo/platform/devices.h"
|
||||
#include "icsneo/device/founddevice.h"
|
||||
#include "generated/extensions/builtin.h"
|
||||
#include "icsneo/platform/servd.h"
|
||||
|
||||
#ifdef ICSNEO_ENABLE_FIRMIO
|
||||
#include "icsneo/platform/firmio.h"
|
||||
@@ -15,12 +16,8 @@
|
||||
#include "icsneo/platform/cdcacm.h"
|
||||
#endif
|
||||
|
||||
#ifdef ICSNEO_ENABLE_FTDI
|
||||
#include "icsneo/platform/ftdi.h"
|
||||
#endif
|
||||
|
||||
#ifdef ICSNEO_ENABLE_FTD3XX
|
||||
#include "icsneo/platform/ftd3xx.h"
|
||||
#ifdef ICSNEO_ENABLE_DXX
|
||||
#include "icsneo/platform/dxx.h"
|
||||
#endif
|
||||
|
||||
#ifdef ICSNEO_ENABLE_TCP
|
||||
@@ -63,29 +60,29 @@ std::vector<std::shared_ptr<Device>> DeviceFinder::FindAll() {
|
||||
static std::vector<FoundDevice> newDriverFoundDevices;
|
||||
newDriverFoundDevices.clear();
|
||||
|
||||
#ifdef ICSNEO_ENABLE_FIRMIO
|
||||
FirmIO::Find(newDriverFoundDevices);
|
||||
#endif
|
||||
if(Servd::Enabled()) {
|
||||
Servd::Find(newDriverFoundDevices);
|
||||
} else {
|
||||
#ifdef ICSNEO_ENABLE_FIRMIO
|
||||
FirmIO::Find(newDriverFoundDevices);
|
||||
#endif
|
||||
|
||||
#ifdef ICSNEO_ENABLE_TCP
|
||||
TCP::Find(newDriverFoundDevices);
|
||||
#endif
|
||||
#ifdef ICSNEO_ENABLE_TCP
|
||||
TCP::Find(newDriverFoundDevices);
|
||||
#endif
|
||||
|
||||
#ifdef ICSNEO_ENABLE_RAW_ETHERNET
|
||||
PCAP::Find(newDriverFoundDevices);
|
||||
#endif
|
||||
#ifdef ICSNEO_ENABLE_RAW_ETHERNET
|
||||
PCAP::Find(newDriverFoundDevices);
|
||||
#endif
|
||||
|
||||
#ifdef ICSNEO_ENABLE_CDCACM
|
||||
CDCACM::Find(newDriverFoundDevices);
|
||||
#endif
|
||||
#ifdef ICSNEO_ENABLE_CDCACM
|
||||
CDCACM::Find(newDriverFoundDevices);
|
||||
#endif
|
||||
|
||||
#ifdef ICSNEO_ENABLE_FTDI
|
||||
FTDI::Find(newDriverFoundDevices);
|
||||
#endif
|
||||
|
||||
#ifdef ICSNEO_ENABLE_FTD3XX
|
||||
FTD3XX::Find(newDriverFoundDevices);
|
||||
#endif
|
||||
#ifdef ICSNEO_ENABLE_DXX
|
||||
DXX::Find(newDriverFoundDevices);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Weak because we don't want to keep devices open if they go out of scope elsewhere
|
||||
static std::vector<std::weak_ptr<Device>> foundDevices;
|
||||
@@ -193,6 +190,10 @@ std::vector<std::shared_ptr<Device>> DeviceFinder::FindAll() {
|
||||
makeIfSerialMatches<RADEpsilon>(dev, newFoundDevices);
|
||||
#endif
|
||||
|
||||
#ifdef __RADEPSILONXL_H_
|
||||
makeIfSerialMatches<RADEpsilonXL>(dev, newFoundDevices);
|
||||
#endif
|
||||
|
||||
#ifdef __RADGALAXY_H_
|
||||
makeIfSerialMatches<RADGalaxy>(dev, newFoundDevices);
|
||||
#endif
|
||||
@@ -352,6 +353,10 @@ const std::vector<DeviceType>& DeviceFinder::GetSupportedDevices() {
|
||||
RADEpsilon::DEVICE_TYPE,
|
||||
#endif
|
||||
|
||||
#ifdef __RADEPSILONXL_H_
|
||||
RADEpsilonXL::DEVICE_TYPE,
|
||||
#endif
|
||||
|
||||
#ifdef __RADGALAXY_H_
|
||||
RADGalaxy::DEVICE_TYPE,
|
||||
#endif
|
||||
|
||||
@@ -45,7 +45,7 @@ void FlexRay::Extension::handleMessage(const std::shared_ptr<Message>& message)
|
||||
}
|
||||
}
|
||||
|
||||
bool FlexRay::Extension::transmitHook(const std::shared_ptr<BusMessage>& frame, bool& success) {
|
||||
bool FlexRay::Extension::transmitHook(const std::shared_ptr<Frame>& frame, bool& success) {
|
||||
if(!frame || frame->network.getType() != Network::Type::FlexRay)
|
||||
return true; // Don't hook non-FlexRay messages
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
#include <icsneo/disk/diskdetails.h>
|
||||
#include <icsneo/device/idevicesettings.h>
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
#pragma pack(push, 2)
|
||||
|
||||
struct DISK_STATUS {
|
||||
uint16_t status;
|
||||
uint64_t sectors;
|
||||
uint32_t bytesPerSector;
|
||||
};
|
||||
|
||||
struct DISK_DETAILS {
|
||||
DISK_SETTINGS settings;
|
||||
uint16_t options;
|
||||
DISK_STATUS status[12];
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
static constexpr uint8_t DISK_FORMAT_FAT32 = 0x01u;
|
||||
static constexpr uint8_t DISK_STATUS_PRESENT = 0x01u;
|
||||
static constexpr uint8_t DISK_STATUS_INITIALIZED = 0x02u;
|
||||
static constexpr uint16_t DISK_DETAILS_FULL_FORMAT = 0x01u;
|
||||
|
||||
std::vector<uint8_t> DiskDetails::Encode(const DiskDetails& config) {
|
||||
std::vector<uint8_t> result(sizeof(DISK_DETAILS), 0);
|
||||
DISK_DETAILS* details = reinterpret_cast<DISK_DETAILS*>(result.data());
|
||||
details->settings.disk_layout = static_cast<uint8_t>(config.layout);
|
||||
details->settings.disk_format = DISK_FORMAT_FAT32; // Always FAT32
|
||||
details->options = config.fullFormat ? DISK_DETAILS_FULL_FORMAT : 0;
|
||||
uint32_t& enables = details->settings.disk_enables;
|
||||
enables = 0u;
|
||||
for(size_t i = 0; i < config.disks.size(); i++) {
|
||||
auto& disk = config.disks[i];
|
||||
details->status[i].sectors = disk.sectors;
|
||||
details->status[i].bytesPerSector = disk.bytesPerSector;
|
||||
|
||||
uint16_t& status = details->status[i].status;
|
||||
status = 0u;
|
||||
if(disk.initialized) {
|
||||
status |= DISK_STATUS_INITIALIZED;
|
||||
}
|
||||
if(disk.present) {
|
||||
status |= DISK_STATUS_PRESENT;
|
||||
}
|
||||
if(disk.formatted) {
|
||||
enables |= (1u << i);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::shared_ptr<DiskDetails> DiskDetails::Decode(const std::vector<uint8_t>& bytes, size_t diskCount, device_eventhandler_t report) {
|
||||
if(bytes.size() < sizeof(DISK_DETAILS)) {
|
||||
report(APIEvent::Type::BufferInsufficient, APIEvent::Severity::Error);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto result = std::make_shared<DiskDetails>();
|
||||
const DISK_DETAILS* details = reinterpret_cast<const DISK_DETAILS*>(bytes.data());
|
||||
result->layout = static_cast<DiskLayout>(details->settings.disk_layout);
|
||||
result->fullFormat = details->options & DISK_DETAILS_FULL_FORMAT;
|
||||
|
||||
result->disks.reserve(diskCount);
|
||||
|
||||
for(size_t i = 0; i < diskCount; i++) {
|
||||
auto& disk = details->status[i];
|
||||
result->disks.emplace_back();
|
||||
auto& info = result->disks.back();
|
||||
info.present = static_cast<bool>(disk.status & DISK_STATUS_PRESENT);
|
||||
info.initialized = static_cast<bool>(disk.status & DISK_STATUS_INITIALIZED);
|
||||
info.formatted = static_cast<bool>(details->settings.disk_enables & (1u << i));
|
||||
info.sectors = disk.sectors;
|
||||
info.bytesPerSector = disk.bytesPerSector;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ std::optional<uint64_t> ExtExtractorDiskReadDriver::readLogicalDiskAligned(Commu
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::optional<uint64_t> ExtExtractorDiskReadDriver::attemptReadLogicalDiskAligned(Communication& com, device_eventhandler_t report,
|
||||
std::optional<uint64_t> ExtExtractorDiskReadDriver::attemptReadLogicalDiskAligned(Communication& com, device_eventhandler_t,
|
||||
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout, MemoryType) {
|
||||
static std::shared_ptr<MessageFilter> NeoMemorySDRead = std::make_shared<MessageFilter>(Network::NetID::NeoMemorySDRead);
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ std::optional<uint64_t> NeoMemoryDiskDriver::readLogicalDiskAligned(Communicatio
|
||||
return SectorSize;
|
||||
}
|
||||
|
||||
std::optional<uint64_t> NeoMemoryDiskDriver::writeLogicalDiskAligned(Communication& com, device_eventhandler_t report,
|
||||
std::optional<uint64_t> NeoMemoryDiskDriver::writeLogicalDiskAligned(Communication& com, device_eventhandler_t,
|
||||
uint64_t pos, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout, MemoryType memType) {
|
||||
|
||||
static std::shared_ptr<MessageFilter> NeoMemoryDone = std::make_shared<MessageFilter>(Network::NetID::NeoMemoryWriteDone);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
using namespace icsneo;
|
||||
using namespace icsneo::Disk;
|
||||
|
||||
std::optional<uint64_t> PlasionDiskReadDriver::readLogicalDiskAligned(Communication& com, device_eventhandler_t report,
|
||||
std::optional<uint64_t> PlasionDiskReadDriver::readLogicalDiskAligned(Communication& com, device_eventhandler_t,
|
||||
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout, MemoryType) {
|
||||
static std::shared_ptr<MessageFilter> NeoMemorySDRead = std::make_shared<MessageFilter>(Network::NetID::NeoMemorySDRead);
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ VSA08::VSA08(uint8_t* const recordBytes)
|
||||
{
|
||||
setType(VSA::Type::AA08);
|
||||
troubleSramCount.insert(troubleSramCount.end(), recordBytes + 2, recordBytes + 6);
|
||||
troubleSectors.insert(troubleSectors.end(), reinterpret_cast<uint32_t*>(recordBytes + 6), reinterpret_cast<uint32_t*>(recordBytes + 20));
|
||||
troubleSectors.insert(troubleSectors.end(), reinterpret_cast<uint32_t*>(recordBytes + 6), reinterpret_cast<uint32_t*>(recordBytes + 22));
|
||||
timestamp = *reinterpret_cast<uint64_t*>(recordBytes + 22) & UINT63_MAX;
|
||||
checksum = *reinterpret_cast<uint16_t*>(recordBytes + 30);
|
||||
doChecksum(recordBytes);
|
||||
|
||||
@@ -8,7 +8,7 @@ Dependencies
|
||||
The minimum requirements to build libicsneo are:
|
||||
- CMake version 3.12 or newer
|
||||
- A C++17 compiler
|
||||
- libusb and libpcap on Linux and macOS
|
||||
- libpcap on Linux and macOS
|
||||
|
||||
|
||||
Building library & examples
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Python Examples
|
||||
===============
|
||||
|
||||
Transmit CAN frames on HSCAN
|
||||
Transmit CAN frames on DW CAN 01
|
||||
============================
|
||||
|
||||
.. code-block:: python
|
||||
@@ -15,7 +15,7 @@ Transmit CAN frames on HSCAN
|
||||
device: icsneopy.Device = devices[0]
|
||||
|
||||
message = icsneopy.CANMessage()
|
||||
message.network = icsneopy.Network(icsneopy.Network.NetID.HSCAN)
|
||||
message.network = icsneopy.Network(icsneopy.Network.NetID.DWCAN_01)
|
||||
message.arbid = 0x56
|
||||
message.data = (0x11, 0x22, 0x33)
|
||||
|
||||
@@ -25,7 +25,7 @@ Transmit CAN frames on HSCAN
|
||||
|
||||
device.transmit(message)
|
||||
|
||||
Receive CAN frames on HSCAN
|
||||
Receive CAN frames on DW CAN 01
|
||||
===========================
|
||||
|
||||
.. code-block:: python
|
||||
@@ -40,7 +40,7 @@ Receive CAN frames on HSCAN
|
||||
|
||||
def on_message(message: icsneopy.CANMessage):
|
||||
print(message.arbid, message.data)
|
||||
message_filter = icsneopy.MessageFilter(icsneopy.Network.NetID.HSCAN)
|
||||
message_filter = icsneopy.MessageFilter(icsneopy.Network.NetID.DWCAN_01)
|
||||
callback = icsneopy.MessageCallback(on_message, message_filter)
|
||||
|
||||
device.add_message_callback(callback)
|
||||
@@ -88,3 +88,43 @@ Monitor Ethernet Status
|
||||
time.sleep(1)
|
||||
|
||||
main()
|
||||
|
||||
TC10
|
||||
====
|
||||
|
||||
:download:`Download example <../../examples/python/tc10/tc10.py>`
|
||||
|
||||
.. literalinclude:: ../../examples/python/tc10/tc10.py
|
||||
|
||||
DoIP Ethernet Activation
|
||||
========================
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import icsneopy
|
||||
import time
|
||||
|
||||
devs = icsneopy.find_all_devices()
|
||||
|
||||
dev = devs[0]
|
||||
|
||||
dev.open()
|
||||
|
||||
# the device must be online for digital I/O
|
||||
dev.go_online()
|
||||
|
||||
print(f"initial state: {dev.get_digital_io(icsneopy.IO.EthernetActivation, 1)}")
|
||||
|
||||
dev.set_digital_io(icsneopy.IO.EthernetActivation, 1, True)
|
||||
|
||||
print(f"after setting to true: {dev.get_digital_io(icsneopy.IO.EthernetActivation, 1)}")
|
||||
|
||||
# allow for observing the change
|
||||
time.sleep(2)
|
||||
|
||||
dev.set_digital_io(icsneopy.IO.EthernetActivation, 1, False)
|
||||
|
||||
print(f"after setting to false: {dev.get_digital_io(icsneopy.IO.EthernetActivation, 1)}")
|
||||
|
||||
# allow for observing the change
|
||||
time.sleep(2)
|
||||
|
||||
@@ -7,3 +7,4 @@ icsneopy
|
||||
|
||||
examples
|
||||
api
|
||||
radepsilon
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
=======================================
|
||||
Python Examples for RAD-Epsilon Devices
|
||||
=======================================
|
||||
|
||||
|
||||
|
||||
Working with PHY Settings
|
||||
=========================
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import sys
|
||||
import icsneopy
|
||||
|
||||
|
||||
class PhyStaticInfo:
|
||||
|
||||
def __init__(self, index, type, switch_port):
|
||||
self.index = index
|
||||
self.type = type
|
||||
self.switch_port = switch_port
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.switch_port}: Type {self.type} / Index {self.index}"
|
||||
|
||||
|
||||
# Switch Port name to PHY index and PHY type
|
||||
RAD_EPSILON_PHY_INFO = {
|
||||
"1": PhyStaticInfo(0, "88Q2112", "1"),
|
||||
"2": PhyStaticInfo(1, "88Q2112", "2"),
|
||||
"3": PhyStaticInfo(2, "88Q2112", "3"),
|
||||
"4": PhyStaticInfo(3, "88Q2112", "4"),
|
||||
"5": PhyStaticInfo(4, "88Q2112", "5"),
|
||||
"6": PhyStaticInfo(5, "88Q2112", "6"),
|
||||
"9": PhyStaticInfo(6, "88Q2112", "9"),
|
||||
"10": PhyStaticInfo(7, "88Q2112", "10")
|
||||
}
|
||||
|
||||
RAD_EPSILON_XL_PHY_INFO = {
|
||||
"A1": PhyStaticInfo(0, "88Q222x", "A1"),
|
||||
"A2": PhyStaticInfo(1, "88Q222x", "A2"),
|
||||
"A3": PhyStaticInfo(2, "88Q222x", "A3"),
|
||||
"A4": PhyStaticInfo(3, "88Q222x", "A4"),
|
||||
"A5": PhyStaticInfo(4, "88Q222x", "A5"),
|
||||
"A6": PhyStaticInfo(5, "88Q222x", "A6"),
|
||||
"A11": PhyStaticInfo(6, "88Q222x", "A11"),
|
||||
"A8": PhyStaticInfo(7, "88Q222x", "A8"),
|
||||
"B1": PhyStaticInfo(8, "88Q222x", "B1"),
|
||||
"B2": PhyStaticInfo(9, "88Q222x", "B2"),
|
||||
"B3": PhyStaticInfo(10, "88Q222x", "B3"),
|
||||
"B4": PhyStaticInfo(11, "88Q222x", "B4"),
|
||||
"B5": PhyStaticInfo(12, "88Q222x", "B5"),
|
||||
"B6": PhyStaticInfo(13, "88Q222x", "B6"),
|
||||
"B7": PhyStaticInfo(14, "88Q222x", "B7"),
|
||||
"B8": PhyStaticInfo(15, "88Q222x", "B8"),
|
||||
"A9": PhyStaticInfo(16, "88X3310", "A9"),
|
||||
"B9": PhyStaticInfo(17, "88X3310", "B9"),
|
||||
}
|
||||
|
||||
|
||||
def find_specific_device(type: icsneopy.DeviceType.Enum, serial: str | None = None) -> icsneopy.Device | None:
|
||||
devices = icsneopy.find_all_devices()
|
||||
for device in devices:
|
||||
device_type = device.get_type().get_device_type()
|
||||
if serial: # always find by serial if specified
|
||||
if device.get_serial() == serial:
|
||||
return device
|
||||
elif device_type == type:
|
||||
return device
|
||||
return None
|
||||
|
||||
|
||||
def find_rad_epsilonxl(serial: str | None = None) -> icsneopy.Device | None:
|
||||
return find_specific_device(icsneopy.DeviceType.Enum.RADEpsilonXL, serial)
|
||||
|
||||
|
||||
def find_rad_epsilon(serial: str | None = None) -> icsneopy.Device | None:
|
||||
return find_specific_device(icsneopy.DeviceType.Enum.RADEpsilon, serial)
|
||||
|
||||
|
||||
def report_phy_settings(device: icsneopy.Device, phy: PhyStaticInfo) -> bool:
|
||||
phy_enable = device.settings.get_phy_enable(phy.index)
|
||||
phy_mode = device.settings.get_phy_mode(phy.index)
|
||||
phy_speed = device.settings.get_phy_speed(phy.index)
|
||||
if phy_enable is None or phy_mode is None or phy_speed is None:
|
||||
print(f"failed to get settings for PHY{phy.index} on port {phy.switch_port}")
|
||||
print(f"PHY {phy.index} ({phy.type})")
|
||||
print(f"\tPort: {phy.switch_port}")
|
||||
print(f"\tEnabled: {'TRUE' if phy_enable else 'FALSE'}")
|
||||
print(f"\tMode: {phy_mode}")
|
||||
print(f"\tSpeed: {phy_speed}")
|
||||
return True
|
||||
|
||||
def configure_phy(device: icsneopy.Device, phy: PhyStaticInfo, enable: bool, mode: int, speed: int) -> bool:
|
||||
if not device.settings.set_phy_enable(phy.index, enable):
|
||||
print(f"failed to set enable for PHY{phy.index} at port {phy.switch_port}")
|
||||
return False
|
||||
if not device.settings.set_phy_mode(phy.index, mode):
|
||||
print(f"failed to set mode for PHY{phy.index} at port {phy.switch_port}")
|
||||
return False
|
||||
if not device.settings.set_phy_speed(phy.index, speed):
|
||||
print(f"failed to set speed for PHY{phy.index} at port {phy.switch_port}")
|
||||
return False
|
||||
if not device.settings.apply(True):
|
||||
print(f"failed to apply settings")
|
||||
print(icsneopy.get_last_error())
|
||||
return False
|
||||
print(f"Successfully set settings for PHY{phy.index} at port {phy.switch_port}")
|
||||
return True
|
||||
|
||||
|
||||
# find the first RAD-EpsilonXL
|
||||
device = find_rad_epsilonxl()
|
||||
if not device:
|
||||
print("failed to find a RAD-EpsilonXL to open")
|
||||
sys.exit(-1)
|
||||
if not device.open():
|
||||
print(f"Failed to open {device.describe()}")
|
||||
print(icsneopy.get_last_error())
|
||||
sys.exit(-1)
|
||||
print(f"Opened {device.describe()}")
|
||||
print("Applying default settings")
|
||||
if not device.settings.apply_defaults():
|
||||
print(icsneopy.get_last_error())
|
||||
sys.exit(-1)
|
||||
print("Reporting PHY settings")
|
||||
for phy in RAD_EPSILON_XL_PHY_INFO.values():
|
||||
report_phy_settings(device, phy)
|
||||
# Setting Port A1 to Master mode, enabled, 1G speed
|
||||
phy = RAD_EPSILON_XL_PHY_INFO["A1"]
|
||||
if configure_phy(device, phy, True, icsneopy.Settings.EthernetLinkMode.Master, icsneopy.Settings.EthernetLinkSpeed.Speed1G) and device.settings.refresh(True):
|
||||
report_phy_settings(device, phy) # report them back
|
||||
else:
|
||||
print(icsneopy.get_last_error())
|
||||
sys.exit(-1)
|
||||
device.close()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
option(LIBICSNEO_BUILD_C_INTERACTIVE_EXAMPLE "Build the command-line interactive C example." ON)
|
||||
option(LIBICSNEO_BUILD_C_SIMPLE_EXAMPLE "Build the command-line simple C example." ON)
|
||||
option(LIBICSNEO_BUILD_C_LEGACY_EXAMPLE "Build the command-line simple C example." ON)
|
||||
option(LIBICSNEO_BUILD_C2_SIMPLE_EXAMPLE "Build the command-line simple C example." ON)
|
||||
option(LIBICSNEO_BUILD_CPP_SIMPLE_EXAMPLE "Build the simple C++ example." ON)
|
||||
option(LIBICSNEO_BUILD_CPP_INTERACTIVE_EXAMPLE "Build the command-line interactive C++ example." ON)
|
||||
option(LIBICSNEO_BUILD_CPP_A2B_EXAMPLE "Build the A2B example." ON)
|
||||
@@ -12,10 +11,6 @@ option(LIBICSNEO_BUILD_CPP_MDIO_EXAMPLE "Build the MDIO example." ON)
|
||||
option(LIBICSNEO_BUILD_CPP_VSA_EXAMPLE "Build the VSA example." ON)
|
||||
option(LIBICSNEO_BUILD_CPP_APP_ERROR_EXAMPLE "Build the app error example." ON)
|
||||
|
||||
# Disabled until we properly build these in-tree
|
||||
# option(LIBICSNEO_BUILD_CSHARP_INTERACTIVE_EXAMPLE "Build the command-line interactive C# example." OFF)
|
||||
# option(LIBICSNEO_BUILD_JAVA_INTERACTIVE_EXAMPLE "Build the command-line interactive Java example." OFF)
|
||||
|
||||
if(LIBICSNEO_BUILD_C_INTERACTIVE_EXAMPLE)
|
||||
add_subdirectory(c/interactive)
|
||||
endif()
|
||||
@@ -28,10 +23,6 @@ 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_CPP_SIMPLE_EXAMPLE)
|
||||
add_subdirectory(cpp/simple)
|
||||
endif()
|
||||
@@ -67,11 +58,3 @@ endif()
|
||||
if(LIBICSNEO_BUILD_CPP_APP_ERROR_EXAMPLE)
|
||||
add_subdirectory(cpp/apperror)
|
||||
endif()
|
||||
|
||||
# if(LIBICSNEO_BUILD_CSHARP_INTERACTIVE_EXAMPLE)
|
||||
# add_subdirectory(csharp)
|
||||
# endif()
|
||||
|
||||
# if(LIBICSNEO_BUILD_JAVA_INTERACTIVE_EXAMPLE)
|
||||
# add_subdirectory(java)
|
||||
# endif()
|
||||
@@ -52,7 +52,7 @@ Although the example program will build without successfully completing the step
|
||||
|
||||
First, we are going to build the icsneoc library into a .so file that we can later use in order to access the library functions.
|
||||
|
||||
1. Install dependencies with `sudo apt update` then `sudo apt install build-essential cmake libusb-1.0-0-dev libpcap0.8-dev`
|
||||
1. Install dependencies with `sudo apt update` then `sudo apt install build-essential cmake libpcap0.8-dev`
|
||||
2. Change directories to `libicsneo-examples/third-party/libicsneo` and create a build directory by running `mkdir -p build`
|
||||
3. Enter the build directory with `cd build`
|
||||
4. Run `cmake ..` to generate your Makefile.
|
||||
|
||||
@@ -128,7 +128,7 @@ void printAPIEvents() {
|
||||
void printDeviceEvents(neodevice_t* device) {
|
||||
neoevent_t events[99];
|
||||
size_t eventCount = 99;
|
||||
if(icsneo_getDeviceEvents(selectedDevice, events, &eventCount)) {
|
||||
if(icsneo_getDeviceEvents(device, events, &eventCount)) {
|
||||
if(eventCount == 1) {
|
||||
printf("1 device event found!\n");
|
||||
printf("Event 0x%x: %s\n", events[0].eventNumber, events[0].description);
|
||||
@@ -160,7 +160,7 @@ char getCharInput(int numArgs, ...) {
|
||||
|
||||
char* list = (char*) calloc(numArgs, sizeof(char));
|
||||
for(int i = 0; i < numArgs; ++i) {
|
||||
*(list + i) = va_arg(vaList, int);
|
||||
*(list + i) = (char)va_arg(vaList, int);
|
||||
}
|
||||
|
||||
va_end(vaList);
|
||||
@@ -285,10 +285,10 @@ int main() {
|
||||
printf("Would you like to open or close %s?\n", productDescription);
|
||||
printf("[1] Open\n[2] Close\n[3] Cancel\n\n");
|
||||
|
||||
char input = getCharInput(3, '1', '2', '3');
|
||||
char userSelection = getCharInput(3, '1', '2', '3');
|
||||
printf("\n");
|
||||
|
||||
switch(input) {
|
||||
switch(userSelection) {
|
||||
case '1':
|
||||
// Attempt to open the selected device
|
||||
if(icsneo_openDevice(selectedDevice)) {
|
||||
@@ -346,10 +346,10 @@ int main() {
|
||||
printf("Would you like to have %s go online or offline?\n", productDescription);
|
||||
printf("[1] Online\n[2] Offline\n[3] Cancel\n\n");
|
||||
|
||||
char input = getCharInput(3, '1', '2', '3');
|
||||
char userSelection = getCharInput(3, '1', '2', '3');
|
||||
printf("\n");
|
||||
|
||||
switch(input) {
|
||||
switch(userSelection) {
|
||||
case '1':
|
||||
// Attempt to go online
|
||||
if(icsneo_goOnline(selectedDevice)) {
|
||||
@@ -394,10 +394,10 @@ int main() {
|
||||
printf("Would you like to enable or disable message polling for %s?\n", productDescription);
|
||||
printf("[1] Enable\n[2] Disable\n[3] Cancel\n\n");
|
||||
|
||||
char input = getCharInput(3, '1', '2', '3');
|
||||
char userSelection = getCharInput(3, '1', '2', '3');
|
||||
printf("\n");
|
||||
|
||||
switch(input) {
|
||||
switch(userSelection) {
|
||||
case '1':
|
||||
// Attempt to enable message polling
|
||||
if(icsneo_enableMessagePolling(selectedDevice)) {
|
||||
@@ -481,8 +481,8 @@ int main() {
|
||||
case ICSNEO_NETWORK_TYPE_CAN: {
|
||||
neomessage_can_t* canMsg = (neomessage_can_t*)frame;
|
||||
printf("\t0x%03x [%zu] ", canMsg->arbid, canMsg->length);
|
||||
for(size_t i = 0; i < canMsg->length; i++) {
|
||||
printf("%02x ", canMsg->data[i]);
|
||||
for(size_t j = 0; j < canMsg->length; j++) {
|
||||
printf("%02x ", canMsg->data[j]);
|
||||
}
|
||||
if(canMsg->status.transmitMessage)
|
||||
printf("TX%s %04x ", canMsg->status.globalError ? " ERR" : "", canMsg->description);
|
||||
@@ -495,18 +495,18 @@ int main() {
|
||||
size_t dataLen = (frameLen > 2) ? (frameLen - 2) : 0;
|
||||
size_t numberBytesHeader = (dataLen > 1) ? 3 : 1;
|
||||
size_t numberBytesData = frameLen - numberBytesHeader;
|
||||
if(linMsg->netid == ICSNEO_NETID_LIN) {
|
||||
if(linMsg->netid == ICSNEO_NETID_LIN_01) {
|
||||
printf("LIN 1 | ID: 0x%02x [%zu] ", linMsg->header[0], dataLen);
|
||||
}
|
||||
else if (linMsg->netid == ICSNEO_NETID_LIN2) {
|
||||
else if (linMsg->netid == ICSNEO_NETID_LIN_02) {
|
||||
printf("LIN 2 | ID: 0x%02x [%zu] ", linMsg->header[0], dataLen);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < dataLen; ++i) {
|
||||
if (i < 2) {
|
||||
printf("%02x ", linMsg->header[i+1]);
|
||||
for(size_t j = 0; j < dataLen; ++j) {
|
||||
if (j < 2) {
|
||||
printf("%02x ", linMsg->header[j+1]);
|
||||
} else {
|
||||
printf("%02x ", linMsg->data[i-2]);
|
||||
printf("%02x ", linMsg->data[j-2]);
|
||||
}
|
||||
}
|
||||
if(numberBytesData > 0)
|
||||
@@ -562,7 +562,7 @@ int main() {
|
||||
neomessage_can_t msg = {0};
|
||||
msg.arbid = 0x120;
|
||||
msg.length = 6;
|
||||
msg.netid = ICSNEO_NETID_HSCAN;
|
||||
msg.netid = ICSNEO_NETID_DWCAN_01;
|
||||
msg.data = sendMessageData;
|
||||
msg.description = 0x1c5; // Random description to match the receipt
|
||||
msg.status.canfdFDF = false;
|
||||
@@ -606,7 +606,7 @@ int main() {
|
||||
icsneo_describeDevice(selectedDevice, productDescription, &descriptionLength);
|
||||
|
||||
// Attempt to set baudrate and apply settings
|
||||
if(icsneo_setBaudrate(selectedDevice, ICSNEO_NETID_HSCAN, 250000) && icsneo_settingsApply(selectedDevice)) {
|
||||
if(icsneo_setBaudrate(selectedDevice, ICSNEO_NETID_DWCAN_01, 250000) && icsneo_settingsApply(selectedDevice)) {
|
||||
printf("Successfully set HS CAN baudrate for %s to 250k!\n\n", productDescription);
|
||||
} else {
|
||||
printf("Failed to set HS CAN for %s to 250k!\n\n", productDescription);
|
||||
@@ -632,7 +632,7 @@ int main() {
|
||||
icsneo_describeDevice(selectedDevice, productDescription, &descriptionLength);
|
||||
|
||||
// Attempt to set baudrate and apply settings
|
||||
if(icsneo_setBaudrate(selectedDevice, ICSNEO_NETID_HSCAN, 500000) && icsneo_settingsApply(selectedDevice)) {
|
||||
if(icsneo_setBaudrate(selectedDevice, ICSNEO_NETID_DWCAN_01, 500000) && icsneo_settingsApply(selectedDevice)) {
|
||||
printf("Successfully set HS CAN baudrate for %s to 500k!\n\n", productDescription);
|
||||
} else {
|
||||
printf("Failed to set HS CAN for %s to 500k!\n\n", productDescription);
|
||||
@@ -725,7 +725,7 @@ int main() {
|
||||
}
|
||||
|
||||
const bool set = selection2 == '1';
|
||||
neoio_t type;
|
||||
neoio_t type = ICSNEO_IO_ETH_ACTIVATION;
|
||||
switch (selection)
|
||||
{
|
||||
case '1': type = ICSNEO_IO_ETH_ACTIVATION; break;
|
||||
@@ -758,7 +758,7 @@ int main() {
|
||||
icsneo_describeDevice(selectedDevice, productDescription, &descriptionLength);
|
||||
|
||||
printf("Termination is ");
|
||||
const bool val = icsneo_isTerminationEnabledFor(selectedDevice, ICSNEO_NETID_HSCAN);
|
||||
const bool val = icsneo_isTerminationEnabledFor(selectedDevice, ICSNEO_NETID_DWCAN_01);
|
||||
neoevent_t err = { 0 };
|
||||
if(icsneo_getLastError(&err)) {
|
||||
printf("not available at this time: %s\n\n", err.description);
|
||||
@@ -776,7 +776,7 @@ int main() {
|
||||
}
|
||||
|
||||
// Attempt to set baudrate and apply settings
|
||||
if(icsneo_setTerminationFor(selectedDevice, ICSNEO_NETID_HSCAN, selection2 == '1') && icsneo_settingsApply(selectedDevice)) {
|
||||
if(icsneo_setTerminationFor(selectedDevice, ICSNEO_NETID_DWCAN_01, selection2 == '1') && icsneo_settingsApply(selectedDevice)) {
|
||||
printf("Successfully set HS CAN termination for %s!\n\n", productDescription);
|
||||
} else {
|
||||
printf("Failed to set HS CAN termination for %s!\n\n", productDescription);
|
||||
|
||||
@@ -52,7 +52,7 @@ Although the example program will build without successfully completing the step
|
||||
|
||||
First, we are going to build the icsneoc library into a .so file that we can later use in order to access the library functions.
|
||||
|
||||
1. Install dependencies with `sudo apt update` then `sudo apt install build-essential cmake libusb-1.0-0-dev libpcap0.8-dev`
|
||||
1. Install dependencies with `sudo apt update` then `sudo apt install build-essential cmake libpcap0.8-dev`
|
||||
2. Change directories to `libicsneo-examples/third-party/libicsneo` and create a build directory by running `mkdir -p build`
|
||||
3. Enter the build directory with `cd build`
|
||||
4. Run `cmake ..` to generate your Makefile.
|
||||
|
||||
@@ -11,7 +11,7 @@ e.g. pSettings.Settings.red2 -> pSettings.Settings.fire3
|
||||
#include <stdbool.h>
|
||||
|
||||
#if defined _WIN32
|
||||
#include "icsneo/platform/windows.h"
|
||||
#include <windows.h>
|
||||
#define SLEEP(msecs) Sleep(msecs)
|
||||
#elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
|
||||
#include <time.h>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#if defined _WIN32
|
||||
#include "icsneo/platform/windows.h"
|
||||
#include <windows.h>
|
||||
#define SLEEP(msecs) Sleep(msecs)
|
||||
#elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
|
||||
#include <time.h>
|
||||
@@ -58,7 +58,7 @@ int main() {
|
||||
msg1.Protocol = SPY_PROTOCOL_LIN;
|
||||
msg1.StatusBitField = 0;
|
||||
msg1.StatusBitField2 = 0;
|
||||
lNetworkID = NETID_LIN2;
|
||||
lNetworkID = NETID_LIN_02;
|
||||
msg1.Header[0] = 0x11; //protected ID
|
||||
msg1.Header[1] = 0xaa;
|
||||
msg1.Header[2] = 0xbb;
|
||||
@@ -80,7 +80,7 @@ int main() {
|
||||
icsSpyMessageJ1850 msg2 = {0};
|
||||
msg2.Protocol = SPY_PROTOCOL_LIN;
|
||||
msg2.StatusBitField = SPY_STATUS_INIT_MESSAGE;
|
||||
lNetworkID = NETID_LIN;
|
||||
lNetworkID = NETID_LIN_01;
|
||||
msg2.Header[0] = 0x11; //protected ID
|
||||
msg2.NumberBytesData = 0;
|
||||
msg2.NumberBytesHeader = 1;
|
||||
@@ -96,7 +96,7 @@ int main() {
|
||||
msg3.Protocol = SPY_PROTOCOL_LIN;
|
||||
msg3.StatusBitField = SPY_STATUS_INIT_MESSAGE;
|
||||
msg3.StatusBitField2 = 0;
|
||||
lNetworkID = NETID_LIN;
|
||||
lNetworkID = NETID_LIN_01;
|
||||
msg3.Header[0] = 0xe2; //protected ID
|
||||
msg3.Header[1] = 0x44;
|
||||
msg3.Header[2] = 0x33;
|
||||
@@ -131,10 +131,10 @@ int main() {
|
||||
const icsSpyMessageJ1850* linMsg = (icsSpyMessageJ1850*)&rxMsg[idx];
|
||||
size_t frameLen = (linMsg->NumberBytesHeader + linMsg->NumberBytesData);
|
||||
size_t dataLen = (frameLen > 2) ? (frameLen - 2) : 0;
|
||||
if(linMsg->NetworkID == NETID_LIN) {
|
||||
if(linMsg->NetworkID == NETID_LIN_01) {
|
||||
printf("LIN 1 | ID: 0x%02x [%zu] ", linMsg->Header[0], dataLen);
|
||||
}
|
||||
else if (linMsg->NetworkID == NETID_LIN2) {
|
||||
else if (linMsg->NetworkID == NETID_LIN_02) {
|
||||
printf("LIN 2 | ID: 0x%02x [%zu] ", linMsg->Header[0], dataLen);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ Although the example program will build without successfully completing the step
|
||||
|
||||
First, we are going to build the icsneoc library into a .so file that we can later use in order to access the library functions.
|
||||
|
||||
1. Install dependencies with `sudo apt update` then `sudo apt install build-essential cmake libusb-1.0-0-dev libpcap0.8-dev`
|
||||
1. Install dependencies with `sudo apt update` then `sudo apt install build-essential cmake libpcap0.8-dev`
|
||||
2. Change directories to `libicsneo-examples/third-party/libicsneo` and create a build directory by running `mkdir -p build`
|
||||
3. Enter the build directory with `cd build`
|
||||
4. Run `cmake ..` to generate your Makefile.
|
||||
|
||||
@@ -123,7 +123,7 @@ void printAPIEvents() {
|
||||
void printDeviceEvents(neodevice_t* device) {
|
||||
neoevent_t events[99];
|
||||
size_t eventCount = 99;
|
||||
if(icsneo_getDeviceEvents(selectedDevice, events, &eventCount)) {
|
||||
if(icsneo_getDeviceEvents(device, events, &eventCount)) {
|
||||
if(eventCount == 1) {
|
||||
printf("1 device event found!\n");
|
||||
printf("Event 0x%x: %s\n", events[0].eventNumber, events[0].description);
|
||||
@@ -155,7 +155,7 @@ char getCharInput(int numArgs, ...) {
|
||||
|
||||
char* list = (char*) calloc(numArgs, sizeof(char));
|
||||
for(int i = 0; i < numArgs; ++i) {
|
||||
*(list + i) = va_arg(vaList, int);
|
||||
*(list + i) = (char)va_arg(vaList, int);
|
||||
}
|
||||
|
||||
va_end(vaList);
|
||||
@@ -285,7 +285,7 @@ int main() {
|
||||
msg.header[1] = 0x11;
|
||||
msg.header[2] = 0x22;
|
||||
msg.length = 10;
|
||||
msg.netid = ICSNEO_NETID_LIN;
|
||||
msg.netid = ICSNEO_NETID_LIN_01;
|
||||
msg.data = sendMessageData;
|
||||
msg.linStatus.txCommander = 1;
|
||||
msg.linStatus.txChecksumEnhanced = 1;
|
||||
@@ -335,8 +335,8 @@ int main() {
|
||||
case ICSNEO_NETWORK_TYPE_CAN: {
|
||||
neomessage_can_t* canMsg = (neomessage_can_t*)frame;
|
||||
printf("\t0x%03x [%zu] ", canMsg->arbid, canMsg->length);
|
||||
for(size_t i = 0; i < canMsg->length; i++) {
|
||||
printf("%02x ", canMsg->data[i]);
|
||||
for(size_t j = 0; i < canMsg->length; j++) {
|
||||
printf("%02x ", canMsg->data[j]);
|
||||
}
|
||||
if(canMsg->status.transmitMessage)
|
||||
printf("TX%s %04x ", canMsg->status.globalError ? " ERR" : "", canMsg->description);
|
||||
@@ -347,20 +347,18 @@ int main() {
|
||||
neomessage_lin_t* linMsg = (neomessage_lin_t*)frame;
|
||||
size_t frameLen = linMsg->length;
|
||||
size_t dataLen = (frameLen > 2) ? (frameLen - 2) : 0;
|
||||
size_t numberBytesHeader = (dataLen > 1) ? 3 : 1;
|
||||
size_t numberBytesData = frameLen - numberBytesHeader;
|
||||
if(linMsg->netid == ICSNEO_NETID_LIN) {
|
||||
if(linMsg->netid == ICSNEO_NETID_LIN_01) {
|
||||
printf("LIN 1 | ID: 0x%02x [%zu] ", linMsg->header[0], dataLen);
|
||||
}
|
||||
else if (linMsg->netid == ICSNEO_NETID_LIN2) {
|
||||
else if (linMsg->netid == ICSNEO_NETID_LIN_02) {
|
||||
printf("LIN 2 | ID: 0x%02x [%zu] ", linMsg->header[0], dataLen);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < dataLen; ++i) {
|
||||
if (i < 2) {
|
||||
printf("%02x ", linMsg->header[i+1]);
|
||||
for(size_t j = 0; j < dataLen; ++j) {
|
||||
if (j < 2) {
|
||||
printf("%02x ", linMsg->header[j+1]);
|
||||
} else {
|
||||
printf("%02x ", linMsg->data[i-2]);
|
||||
printf("%02x ", linMsg->data[j-2]);
|
||||
}
|
||||
}
|
||||
printf("| Checksum: 0x%02x\n", linMsg->checksum);
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
add_executable(libicsneo-simple-example src/main.c)
|
||||
target_link_libraries(libicsneo-simple-example icsneoc2)
|
||||
@@ -1,454 +0,0 @@
|
||||
#include <icsneo/icsneoc2.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sleeps for a specified number of milliseconds.
|
||||
*
|
||||
* Sleeps for a specified number of milliseconds using Sleep() on Windows and sleep() on *nix.
|
||||
*
|
||||
* @param ms The number of milliseconds to sleep.
|
||||
*/
|
||||
void sleep_ms(uint32_t ms) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
Sleep(ms);
|
||||
#else
|
||||
sleep(ms / 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Prints an error message with the given string and error code.
|
||||
*
|
||||
* If the error code is not 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[256] = {0};
|
||||
uint32_t error_length = 256;
|
||||
icsneoc2_error_t res = icsneoc2_error_code_get(error, error_str, &error_length);
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Processes a list of messages from a device.
|
||||
*
|
||||
* This function iterates over a given array of messages received from a specified device.
|
||||
* For each message in the array, it retrieves and prints the message type and bus type.
|
||||
* If an error occurs while retrieving these details, an error message is printed.
|
||||
*
|
||||
* @param device A pointer to the icsneoc2_device_t structure representing the device.
|
||||
* @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_device_t* device, icsneoc2_message_t** messages, uint32_t messages_count);
|
||||
|
||||
/**
|
||||
* @brief Prints device and global events for a given device.
|
||||
*
|
||||
* This function retrieves and prints all current events associated with the specified device,
|
||||
* as well as any global events not tied to a specific device. For each event, it retrieves
|
||||
* and prints a description. If retrieving events or their descriptions fails, an error
|
||||
* message is printed. The function also prints a summary of the count of device-specific
|
||||
* and global events processed.
|
||||
*
|
||||
* @param device A pointer to the icsneoc2_device_t structure representing the device to get events from.
|
||||
* @param device_description A description of the device used in the output.
|
||||
*/
|
||||
void print_device_events(icsneoc2_device_t* device, const char* device_description);
|
||||
|
||||
/**
|
||||
* @brief Transmits a series of CAN messages from a device.
|
||||
*
|
||||
* This function creates and transmits 100 CAN messages with incrementing payload data.
|
||||
* Each message is configured with specific attributes such as network ID, arbitration
|
||||
* ID, CANFD status, extended status, and baudrate switch. After successfully transmitting
|
||||
* each message, it is freed from memory.
|
||||
*
|
||||
* @param device A pointer to the 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);
|
||||
|
||||
/**
|
||||
* @brief Get the RTC (Real time clock) of a device and print it.
|
||||
*
|
||||
* @param[in] device The device to get the RTC of.
|
||||
* @param[in] description A description of the device for printing purpose.
|
||||
*
|
||||
* @return icsneoc2_error_t icsneoc2_error_success if successful, icsneoc2_error_invalid_parameters otherwise.
|
||||
*/
|
||||
icsneoc2_error_t get_and_print_rtc(icsneoc2_device_t* device, const char* description);
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
icsneoc2_device_t* devices[255] = {0};
|
||||
uint32_t devices_count = 255;
|
||||
|
||||
printf("Finding devices...\n");
|
||||
icsneoc2_error_t res = icsneoc2_device_find_all(devices, &devices_count, NULL);
|
||||
if (res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to find devices", res);
|
||||
};
|
||||
printf("OK, %u device%s found\n", devices_count, devices_count == 1 ? "" : "s");
|
||||
// List off the devices
|
||||
for (uint32_t i = 0; i < devices_count; i++) {
|
||||
icsneoc2_device_t* device = devices[i];
|
||||
// Get description of the device
|
||||
const char description[255] = {0};
|
||||
uint32_t description_length = 255;
|
||||
res = icsneoc2_device_description_get(device, description, &description_length);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
return print_error_code("\tFailed to get device description", res);
|
||||
};
|
||||
printf("%.*s @ Handle %p\n", description_length, description, device);
|
||||
// Get/Set open options
|
||||
icsneoc2_open_options_t options = icsneoc2_open_options_none;
|
||||
res = icsneoc2_device_open_options_get(device, &options);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
return print_error_code("\tFailed to get open options", res);
|
||||
}
|
||||
// Disable Syncing RTC and going online
|
||||
options &= ~icsneoc2_open_options_sync_rtc;
|
||||
options &= ~icsneoc2_open_options_go_online;
|
||||
printf("\tDevice open options: 0x%x\n", options);
|
||||
res = icsneoc2_device_open_options_set(device, options);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
return print_error_code("\tFailed to set open options", res);
|
||||
}
|
||||
// Open the device
|
||||
printf("\tOpening device: %s...\n", description);
|
||||
res = icsneoc2_device_open(device);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
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(device, ×tamp_resolution);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
return print_error_code("\tFailed to get timestamp resolution", res);
|
||||
}
|
||||
printf("%uns\n", timestamp_resolution);
|
||||
// Get baudrates for HSCAN
|
||||
printf("\tGetting HSCAN Baudrate... ");
|
||||
uint64_t baudrate = 0;
|
||||
res = icsneoc2_device_baudrate_get(device, icsneoc2_netid_hscan, &baudrate);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
return print_error_code("\tFailed to get baudrate", res);
|
||||
};
|
||||
printf("%llumbit/s\n", baudrate);
|
||||
// Get FDbaudrates for HSCAN
|
||||
printf("\tGetting FD HSCAN Baudrate... ");
|
||||
uint64_t fd_baudrate = 0;
|
||||
res = icsneoc2_device_canfd_baudrate_get(device, icsneoc2_netid_hscan, &fd_baudrate);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
return print_error_code("\tFailed to get FD baudrate", res);
|
||||
};
|
||||
printf("%llumbit/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
|
||||
bool save_to_device = false;
|
||||
printf("\tSetting HSCAN Baudrate... ");
|
||||
res = icsneoc2_device_baudrate_set(device, icsneoc2_netid_hscan, baudrate, save_to_device);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
return print_error_code("\tFailed to set baudrate", res);
|
||||
};
|
||||
printf("Ok\n");
|
||||
// Set FDbaudrates for HSCAN
|
||||
printf("\tSetting FD HSCAN Baudrate... ");
|
||||
res = icsneoc2_device_canfd_baudrate_set(device, icsneoc2_netid_hscan, fd_baudrate, save_to_device);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
return print_error_code("\tFailed to set FD baudrate", res);
|
||||
};
|
||||
printf("Ok\n");
|
||||
// Get RTC
|
||||
printf("\tGetting RTC... ");
|
||||
res = get_and_print_rtc(device, description);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
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(device, current_time);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
return print_error_code("\tFailed to set RTC", res);
|
||||
}
|
||||
printf("Ok\n");
|
||||
// Get RTC
|
||||
printf("\tGetting RTC... ");
|
||||
res = get_and_print_rtc(device, description);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
return print_error_code("\tFailed to get RTC", res);
|
||||
}
|
||||
// Go online, start acking traffic
|
||||
printf("\tGoing online... ");
|
||||
res = icsneoc2_device_go_online(device, true);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
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(device, &is_online);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
return print_error_code("\tFailed to check if online", res);
|
||||
}
|
||||
printf("%s\n", is_online ? "Online" : "Offline");
|
||||
// Transmit CAN messages
|
||||
res = transmit_can_messages(device);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
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};
|
||||
uint32_t message_count = 20000;
|
||||
printf("\tGetting messages from device with timeout of 3000ms on %s...\n", description);
|
||||
res = icsneoc2_device_messages_get(device, messages, &message_count, 3000);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
return print_error_code("\tFailed to get messages from device", res);
|
||||
};
|
||||
// Process the messages
|
||||
res = process_messages(device, messages, message_count);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
return print_error_code("\tFailed to process messages", res);
|
||||
}
|
||||
// Finally, close the device.
|
||||
printf("\tClosing device: %s...\n", description);
|
||||
res = icsneoc2_device_close(device);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_device_events(device, description);
|
||||
return print_error_code("\tFailed to close device", res);
|
||||
};
|
||||
// Print device events
|
||||
print_device_events(device, description);
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
icsneoc2_error_t get_and_print_rtc(icsneoc2_device_t* device, const char* description) {
|
||||
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", unix_epoch, rtc_time);
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
void print_device_events(icsneoc2_device_t* device, const char* device_description) {
|
||||
// Get device events
|
||||
icsneoc2_event_t* events[1024] = {0};
|
||||
uint32_t events_count = 1024;
|
||||
icsneoc2_error_t res = icsneoc2_device_events_get(device, events, &events_count);
|
||||
if (res != icsneoc2_error_success) {
|
||||
(void)print_error_code("\tFailed to get device events", res);
|
||||
return;
|
||||
}
|
||||
// Loop over each event and describe it.
|
||||
for (uint32_t i = 0; i < events_count; i++) {
|
||||
const char event_description[255] = {0};
|
||||
uint32_t event_description_length = 255;
|
||||
res = 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 %u: %s\n", device_description, i, event_description);
|
||||
}
|
||||
|
||||
// Get global events
|
||||
icsneoc2_event_t* global_events[1024] = {0};
|
||||
uint32_t global_events_count = 1024;
|
||||
res = icsneoc2_events_get(global_events, &global_events_count);
|
||||
if (res != icsneoc2_error_success) {
|
||||
(void)print_error_code("\tFailed to get global events", res);
|
||||
return;
|
||||
}
|
||||
// Loop over each event and describe it.
|
||||
for (uint32_t i = 0; i < global_events_count; i++) {
|
||||
const char event_description[255] = {0};
|
||||
uint32_t event_description_length = 255;
|
||||
res = icsneoc2_event_description_get(global_events[i], event_description, &event_description_length);
|
||||
if (res != icsneoc2_error_success) {
|
||||
print_error_code("\tFailed to get global event description", res);
|
||||
continue;
|
||||
}
|
||||
printf("\t%s: Global Event %u: %s\n", device_description, i, event_description);
|
||||
}
|
||||
printf("\t%s: Received %u events and %u global events\n", device_description, events_count, global_events_count);
|
||||
}
|
||||
|
||||
int process_messages(icsneoc2_device_t* device, icsneoc2_message_t** messages, uint32_t messages_count) {
|
||||
// Print the type and bus type of each message
|
||||
uint32_t tx_count = 0;
|
||||
for (uint32_t i = 0; i < messages_count; i++) {
|
||||
icsneoc2_message_t* message = messages[i];
|
||||
// Get the message type
|
||||
icsneoc2_msg_type_t msg_type = 0;
|
||||
icsneoc2_error_t res = icsneoc2_message_type_get(device, message, &msg_type);
|
||||
if (res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to get message type", res);
|
||||
}
|
||||
// Get the message type name
|
||||
char msg_type_name[128] = {0};
|
||||
uint32_t msg_type_name_length = 128;
|
||||
res = icsneoc2_message_type_name_get(msg_type, msg_type_name, &msg_type_name_length);
|
||||
if (res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to get message type name", res);
|
||||
}
|
||||
// Check if the message is a bus message, ignore otherwise
|
||||
if (msg_type != icsneoc2_msg_type_bus) {
|
||||
printf("Ignoring message type: %u (%s)\n", msg_type, msg_type_name);
|
||||
continue;
|
||||
}
|
||||
icsneoc2_msg_bus_type_t bus_type = 0;
|
||||
res = icsneoc2_message_bus_type_get(device, message, &bus_type);
|
||||
if (res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to get message bus type", res);
|
||||
}
|
||||
const char bus_name[128] = {0};
|
||||
uint32_t bus_name_length = 128;
|
||||
res = icsneoc2_bus_type_name_get(bus_type, bus_name, &bus_name_length);
|
||||
if (res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to get message bus type name", res);
|
||||
}
|
||||
bool is_tx = false;
|
||||
res = icsneoc2_message_is_transmit(device, 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%d) Message type: %u bus type: %s (%u)\n", i, msg_type, bus_name, bus_type);
|
||||
if (bus_type == icsneoc2_msg_bus_type_can) {
|
||||
uint32_t arbid = 0;
|
||||
int32_t dlc = 0;
|
||||
icsneoc2_netid_t netid = 0;
|
||||
bool is_remote = false;
|
||||
bool is_canfd = false;
|
||||
bool is_extended = false;
|
||||
uint8_t data[64] = {0};
|
||||
uint32_t data_length = 64;
|
||||
const char netid_name[128] = {0};
|
||||
uint32_t netid_name_length = 128;
|
||||
uint32_t result = icsneoc2_message_netid_get(device, message, &netid);
|
||||
result += icsneoc2_netid_name_get(netid, netid_name, &netid_name_length);
|
||||
result += icsneoc2_message_can_arbid_get(device, message, &arbid);
|
||||
result += icsneoc2_message_can_dlc_get(device, message, &dlc);
|
||||
result += icsneoc2_message_can_is_remote(device, message, &is_remote);
|
||||
result += icsneoc2_message_can_is_canfd(device, message, &is_canfd);
|
||||
result += icsneoc2_message_can_is_extended(device, message, &is_extended);
|
||||
result += icsneoc2_message_data_get(device, message, data, &data_length);
|
||||
if (result != icsneoc2_error_success) {
|
||||
printf("\tFailed get get CAN parameters (error: %u) for index %u\n", result, i);
|
||||
continue;
|
||||
}
|
||||
printf("\t NetID: %s (0x%x)\tArbID: 0x%x\t DLC: %u\t Remote: %d\t CANFD: %d\t Extended: %d\t Data length: %u\n", netid_name, netid, arbid, dlc, is_remote, is_canfd, is_extended, data_length);
|
||||
printf("\t Data: [");
|
||||
for (uint32_t x = 0; x < data_length; x++) {
|
||||
printf(" 0x%x", data[x]);
|
||||
}
|
||||
printf(" ]\n");
|
||||
}
|
||||
}
|
||||
printf("\tReceived %u messages total, %u were TX messages\n", messages_count, tx_count);
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
int transmit_can_messages(icsneoc2_device_t* device) {
|
||||
uint64_t counter = 0;
|
||||
const uint32_t msg_count = 100;
|
||||
printf("\tTransmitting %d messages...\n", msg_count);
|
||||
for (uint32_t i = 0; i < msg_count; i++) {
|
||||
// Create the message
|
||||
icsneoc2_message_t* message = NULL;
|
||||
uint32_t message_count = 1;
|
||||
icsneoc2_error_t res = icsneoc2_message_can_create(device, &message, message_count);
|
||||
if (res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to create messages", res);
|
||||
}
|
||||
// Set the message attributes
|
||||
res = icsneoc2_message_netid_set(device, message, icsneoc2_netid_hscan);
|
||||
res += icsneoc2_message_can_arbid_set(device, message, 0x10);
|
||||
res += icsneoc2_message_can_canfd_set(device, message, true);
|
||||
res += icsneoc2_message_can_extended_set(device, message, true);
|
||||
res += icsneoc2_message_can_baudrate_switch_set(device, message, true);
|
||||
// Create the payload
|
||||
uint8_t data[8] = {0};
|
||||
data[0] = (uint8_t)(counter >> 56);
|
||||
data[1] = (uint8_t)(counter >> 48);
|
||||
data[2] = (uint8_t)(counter >> 40);
|
||||
data[3] = (uint8_t)(counter >> 32);
|
||||
data[4] = (uint8_t)(counter >> 24);
|
||||
data[5] = (uint8_t)(counter >> 16);
|
||||
data[6] = (uint8_t)(counter >> 8);
|
||||
data[7] = (uint8_t)(counter >> 0);
|
||||
res += icsneoc2_message_data_set(device, message, data, sizeof(data));
|
||||
res += icsneoc2_message_can_dlc_set(device, message, -1);
|
||||
if (res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to modify message", res);
|
||||
}
|
||||
res = icsneoc2_device_messages_transmit(device, &message, &message_count);
|
||||
res += icsneoc2_message_can_free(device, message);
|
||||
if (res != icsneoc2_error_success) {
|
||||
return print_error_code("\tFailed to transmit messages", res);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
@@ -79,7 +79,7 @@ void example0(const std::shared_ptr<icsneo::Device>& rada2b) {
|
||||
true /* true if we want 16 bit channels in the message, false for 32 bit. This should match the RAD-A2B device setting */
|
||||
);
|
||||
msg->txmsg = true;
|
||||
msg->network = icsneo::Network(icsneo::Network::NetID::A2B2);
|
||||
msg->network = icsneo::Network(icsneo::Network::NetID::A2B_02);
|
||||
|
||||
// Load the WAV audio data into the desired channel, break if we fail to load
|
||||
if(!msg->loadAudioBuffer(wavStream, channelMap)) {
|
||||
@@ -192,7 +192,7 @@ void example3(const std::shared_ptr<icsneo::Device>& rada2b) {
|
||||
std::shared_ptr<icsneo::A2BMessage> a2bmsgPtr = std::make_shared<icsneo::A2BMessage>(numFrames, icsneo::A2BMessage::TDMMode::TDM4, true);
|
||||
|
||||
icsneo::A2BMessage& a2bmsg = *a2bmsgPtr.get();
|
||||
a2bmsg.network = icsneo::Network(icsneo::Network::NetID::A2B2);
|
||||
a2bmsg.network = icsneo::Network(icsneo::Network::NetID::A2B_02);
|
||||
a2bmsg.txmsg = true;
|
||||
|
||||
for(size_t frame = 0; frame < a2bmsg.getNumFrames(); frame++) {
|
||||
@@ -241,13 +241,13 @@ void example3(const std::shared_ptr<icsneo::Device>& rada2b) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Example 4: Retrieving A2B bus status using I2C messaages.
|
||||
* Example 4: Retrieving A2B bus status using I2C messages.
|
||||
*/
|
||||
void example4(const std::shared_ptr<icsneo::Device>& rada2b) {
|
||||
std::shared_ptr<icsneo::I2CMessage> msg = std::make_shared<icsneo::I2CMessage>();
|
||||
std::shared_ptr<icsneo::MessageFilter> msgFilter = std::make_shared<icsneo::MessageFilter>(icsneo::Network::NetID::I2C2);
|
||||
std::shared_ptr<icsneo::MessageFilter> msgFilter = std::make_shared<icsneo::MessageFilter>(icsneo::Network::NetID::I2C_02);
|
||||
|
||||
msg->network = icsneo::Network(icsneo::Network::NetID::I2C2);
|
||||
msg->network = icsneo::Network(icsneo::Network::NetID::I2C_02);
|
||||
msg->controlBytes.resize(1);
|
||||
msg->controlBytes[0] = static_cast<uint8_t>(0x17u); // Register address for A2B INTTYPE
|
||||
msg->dataBytes.resize(1, 0);
|
||||
@@ -259,9 +259,9 @@ void example4(const std::shared_ptr<icsneo::Device>& rada2b) {
|
||||
auto handler = rada2b->addMessageCallback(std::make_shared<icsneo::MessageCallback>(
|
||||
[] (std::shared_ptr<icsneo::Message> newMsg) {
|
||||
|
||||
if(newMsg->type == icsneo::Message::Type::BusMessage) {
|
||||
const auto& frame = std::dynamic_pointer_cast<icsneo::BusMessage>(newMsg);
|
||||
if(frame && frame->network.getNetID() == icsneo::Network::NetID::I2C2) {
|
||||
if(newMsg->type == icsneo::Message::Type::Frame) {
|
||||
const auto& frame = std::dynamic_pointer_cast<icsneo::Frame>(newMsg);
|
||||
if(frame && frame->network.getNetID() == icsneo::Network::NetID::I2C_02) {
|
||||
const auto& i2cMessage = std::dynamic_pointer_cast<icsneo::I2CMessage>(frame);
|
||||
|
||||
if(!i2cMessage) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "icsneo/communication/message/message.h"
|
||||
/*
|
||||
* App errors are responses from the device indicating internal runtime errors
|
||||
* NOTE: To trigger the app error in this example, disable the HSCAN network on the device
|
||||
* NOTE: To trigger the app error in this example, disable the DW CAN 01 network on the device
|
||||
* (e.g. with neoVI Explorer)
|
||||
*/
|
||||
int main() {
|
||||
@@ -58,14 +58,14 @@ int main() {
|
||||
// Prepare a CAN message
|
||||
std::cout << std::endl << "Transmitting a CAN frame... ";
|
||||
auto txMessage = std::make_shared<icsneo::CANMessage>();
|
||||
txMessage->network = icsneo::Network::NetID::HSCAN;
|
||||
txMessage->network = icsneo::Network::NetID::DWCAN_01;
|
||||
txMessage->arbid = 0x22;
|
||||
txMessage->data.insert(txMessage->data.end(), {0xaa, 0xbb, 0xcc});
|
||||
// The DLC will come from the length of the data vector
|
||||
txMessage->isExtended = false;
|
||||
txMessage->isCANFD = false;
|
||||
|
||||
// Transmit a CAN message on HSCAN, even though HSCAN is disabled on the device!
|
||||
// Transmit a CAN message on DW CAN 01, even though DW CAN 01 is disabled on the device!
|
||||
// Expect to see an app error caught in the callback defined above
|
||||
ret = device->transmit(txMessage);
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
@@ -32,7 +32,7 @@ If you haven't done this, `third-party/libicsneo` will be empty and you won't be
|
||||
|
||||
### Ubuntu 18.04 LTS
|
||||
|
||||
1. Install dependencies with `sudo apt update` then `sudo apt install build-essential cmake libusb-1.0-0-dev libpcap0.8-dev`
|
||||
1. Install dependencies with `sudo apt update` then `sudo apt install build-essential cmake libpcap0.8-dev`
|
||||
2. Change directories to your `libicsneo-examples/libicsneocpp-example` folder and create a build directory by running `mkdir -p build`
|
||||
3. Enter the build directory with `cd build`
|
||||
4. Run `cmake ..` to generate your Makefile.
|
||||
|
||||
@@ -184,9 +184,9 @@ std::shared_ptr<icsneo::Device> selectDevice(const std::vector<std::shared_ptr<i
|
||||
|
||||
void printMessage(const std::shared_ptr<icsneo::Message>& message) {
|
||||
switch(message->type) {
|
||||
case icsneo::Message::Type::BusMessage: {
|
||||
case icsneo::Message::Type::Frame: {
|
||||
// A message of type Frame is guaranteed to be a Frame, so we can static cast safely
|
||||
auto frame = std::static_pointer_cast<icsneo::BusMessage>(message);
|
||||
auto frame = std::static_pointer_cast<icsneo::Frame>(message);
|
||||
switch(frame->network.getType()) {
|
||||
case icsneo::Network::Type::CAN: {
|
||||
// A message of type CAN is guaranteed to be a CANMessage, so we can static cast safely
|
||||
@@ -264,7 +264,7 @@ void printMessage(const std::shared_ptr<icsneo::Message>& message) {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
} // end of icsneo::Message::Type::BusMessage
|
||||
} // end of icsneo::Message::Type::Frame
|
||||
case icsneo::Message::Type::CANErrorCount: {
|
||||
// A message of type CANErrorCount is guaranteed to be a CANErrorCount, so we can static cast safely
|
||||
auto cec = std::static_pointer_cast<icsneo::CANErrorMessage>(message);
|
||||
@@ -508,7 +508,7 @@ int main() {
|
||||
|
||||
std::cout << "Transmitting a normal CAN frame..." << std::endl;
|
||||
auto msg = std::make_shared<icsneo::CANMessage>();
|
||||
msg->network = icsneo::Network::NetID::HSCAN;
|
||||
msg->network = icsneo::Network::NetID::DWCAN_01;
|
||||
msg->arbid = 0x120;
|
||||
msg->data.insert(msg->data.end(), {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff});
|
||||
msg->isExtended = false;
|
||||
@@ -525,7 +525,7 @@ int main() {
|
||||
/** Example of CAN FD
|
||||
std::cout << "Transmitting an extended CAN FD frame... " << std::endl;
|
||||
auto txMessage = std::make_shared<icsneo::CANMessage>();
|
||||
txMessage->network = icsneo::Network::NetID::HSCAN;
|
||||
txMessage->network = icsneo::Network::NetID::DWCAN_01;
|
||||
txMessage->arbid = 0x1C5001C5;
|
||||
txMessage->data.insert(txMessage->data.end(), {0xaa, 0xbb, 0xcc});
|
||||
// The DLC will come from the length of the data vector
|
||||
@@ -565,7 +565,7 @@ int main() {
|
||||
selectedDevice = selectDevice(devices);
|
||||
|
||||
// Attempt to set baudrate and apply settings
|
||||
if(selectedDevice->settings->setBaudrateFor(icsneo::Network::NetID::HSCAN, 250000) && selectedDevice->settings->apply()) {
|
||||
if(selectedDevice->settings->setBaudrateFor(icsneo::Network::NetID::DWCAN_01, 250000) && selectedDevice->settings->apply()) {
|
||||
std::cout << "Successfully set HS CAN baudrate for " << selectedDevice->describe() << " to 250k!" << std::endl;
|
||||
} else {
|
||||
std::cout << "Failed to set HS CAN baudrate for " << selectedDevice->describe() << " to 250k!" << std::endl << std::endl;
|
||||
@@ -586,7 +586,7 @@ int main() {
|
||||
selectedDevice = selectDevice(devices);
|
||||
|
||||
// Attempt to set baudrate and apply settings
|
||||
if(selectedDevice->settings->setBaudrateFor(icsneo::Network::NetID::LSFTCAN, 250000) && selectedDevice->settings->apply()) {
|
||||
if(selectedDevice->settings->setBaudrateFor(icsneo::Network::NetID::LSFTCAN_01, 250000) && selectedDevice->settings->apply()) {
|
||||
std::cout << "Successfully set LSFT CAN baudrate for " << selectedDevice->describe() << " to 250k!" << std::endl;
|
||||
} else {
|
||||
std::cout << "Failed to set LSFT CAN baudrate for " << selectedDevice->describe() << " to 250k!" << std::endl << std::endl;
|
||||
@@ -790,7 +790,7 @@ int main() {
|
||||
selectedDevice = selectDevice(devices);
|
||||
|
||||
std::cout << "Termination is ";
|
||||
const auto val = selectedDevice->settings->isTerminationEnabledFor(icsneo::Network::NetID::HSCAN);
|
||||
const auto val = selectedDevice->settings->isTerminationEnabledFor(icsneo::Network::NetID::DWCAN_01);
|
||||
if(!val.has_value()) {
|
||||
std::cout << "not available at this time: " << icsneo::GetLastError() << std::endl << std::endl;
|
||||
break;
|
||||
@@ -807,7 +807,7 @@ int main() {
|
||||
}
|
||||
|
||||
// Attempt to set termination and apply settings
|
||||
if(selectedDevice->settings->setTerminationFor(icsneo::Network::NetID::HSCAN, selection2 == '1') && selectedDevice->settings->apply()) {
|
||||
if(selectedDevice->settings->setTerminationFor(icsneo::Network::NetID::DWCAN_01, selection2 == '1') && selectedDevice->settings->apply()) {
|
||||
std::cout << "Successfully set HS CAN termination for " << selectedDevice->describe() << std::endl;
|
||||
} else {
|
||||
std::cout << "Failed to set HS CAN termination for " << selectedDevice->describe() << std::endl;
|
||||
|
||||
@@ -32,28 +32,28 @@ int main() {
|
||||
|
||||
int64_t baud = 19200;
|
||||
|
||||
std::cout << "Enable LIN commander resistor... ";
|
||||
ret = device->settings->setCommanderResistorFor(icsneo::Network::NetID::LIN, true);
|
||||
std::cout << "Enable LIN 01 commander resistor... ";
|
||||
ret = device->settings->setCommanderResistorFor(icsneo::Network::NetID::LIN_01, true);
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
std::cout << "Disable LIN2 commander resistor... ";
|
||||
ret = device->settings->setCommanderResistorFor(icsneo::Network::NetID::LIN2, false);
|
||||
std::cout << "Disable LIN 02 commander resistor... ";
|
||||
ret = device->settings->setCommanderResistorFor(icsneo::Network::NetID::LIN_02, false);
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
std::cout << "Setting LIN to operate at " << baud << "bit/s... ";
|
||||
ret = device->settings->setBaudrateFor(icsneo::Network::NetID::LIN, baud);
|
||||
std::cout << "Setting LIN 01 to operate at " << baud << "bit/s... ";
|
||||
ret = device->settings->setBaudrateFor(icsneo::Network::NetID::LIN_01, baud);
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
std::cout << "Setting LIN2 to operate at " << baud << "bit/s... ";
|
||||
ret = device->settings->setBaudrateFor(icsneo::Network::NetID::LIN2, baud);
|
||||
std::cout << "Setting LIN 02 to operate at " << baud << "bit/s... ";
|
||||
ret = device->settings->setBaudrateFor(icsneo::Network::NetID::LIN_02, baud);
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
std::cout << "Setting LIN mode to NORMAL... ";
|
||||
ret = device->settings->setLINModeFor(icsneo::Network::NetID::LIN, NORMAL_MODE);
|
||||
std::cout << "Setting LIN 01 mode to NORMAL... ";
|
||||
ret = device->settings->setLINModeFor(icsneo::Network::NetID::LIN_01, NORMAL_MODE);
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
std::cout << "Setting LIN2 mode to NORMAL... ";
|
||||
ret = device->settings->setLINModeFor(icsneo::Network::NetID::LIN2, NORMAL_MODE);
|
||||
std::cout << "Setting LIN 02 mode to NORMAL... ";
|
||||
ret = device->settings->setLINModeFor(icsneo::Network::NetID::LIN_02, NORMAL_MODE);
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
std::cout << "Applying settings... ";
|
||||
@@ -61,14 +61,14 @@ int main() {
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
std::cout << "Getting LIN Baudrate... ";
|
||||
int64_t readBaud = device->settings->getBaudrateFor(icsneo::Network::NetID::LIN);
|
||||
int64_t readBaud = device->settings->getBaudrateFor(icsneo::Network::NetID::LIN_01);
|
||||
if(readBaud < 0)
|
||||
std::cout << "FAIL" << std::endl;
|
||||
else
|
||||
std::cout << "OK, " << (readBaud) << "bit/s" << std::endl;
|
||||
|
||||
std::cout << "Getting LIN2 Baudrate... ";
|
||||
readBaud = device->settings->getBaudrateFor(icsneo::Network::NetID::LIN2);
|
||||
std::cout << "Getting LIN 02 Baudrate... ";
|
||||
readBaud = device->settings->getBaudrateFor(icsneo::Network::NetID::LIN_02);
|
||||
if(readBaud < 0)
|
||||
std::cout << "FAIL" << std::endl;
|
||||
else
|
||||
@@ -96,8 +96,8 @@ int main() {
|
||||
std::cout << "OK" << std::endl << std::endl;
|
||||
|
||||
auto handler = device->addMessageCallback(std::make_shared<icsneo::MessageCallback>([&](std::shared_ptr<icsneo::Message> message) {
|
||||
if(icsneo::Message::Type::BusMessage == message->type) {
|
||||
auto frame = std::static_pointer_cast<icsneo::BusMessage>(message);
|
||||
if(icsneo::Message::Type::Frame == message->type) {
|
||||
auto frame = std::static_pointer_cast<icsneo::Frame>(message);
|
||||
if(icsneo::Network::Type::LIN == frame->network.getType()) {
|
||||
auto msg = std::static_pointer_cast<icsneo::LINMessage>(message);
|
||||
std::cout << msg->network << " RX frame | ID: 0x" << std::hex << static_cast<int>(msg->ID) << " | ";
|
||||
@@ -113,18 +113,18 @@ int main() {
|
||||
}));
|
||||
|
||||
// We can transmit messages
|
||||
std::cout << "Transmitting a LIN responder data frame... ";
|
||||
std::cout << "Transmitting a LIN 02 responder data frame... ";
|
||||
auto lin_r = std::make_shared<icsneo::LINMessage>();
|
||||
lin_r->network = icsneo::Network::NetID::LIN2;
|
||||
lin_r->network = icsneo::Network::NetID::LIN_02;
|
||||
lin_r->ID = 0x11;
|
||||
lin_r->linMsgType = icsneo::LINMessage::Type::LIN_UPDATE_RESPONDER;
|
||||
lin_r->data = {0xaa, 0xbb, 0xcc, 0xdd, 0x11, 0x22, 0x33, 0x44};
|
||||
ret = device->transmit(lin_r); // This will return false if the device does not support LIN
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
std::cout << "Transmitting a LIN commander header... ";
|
||||
std::cout << "Transmitting a LIN 01 commander header... ";
|
||||
auto lin_c = std::make_shared<icsneo::LINMessage>();
|
||||
lin_c->network = icsneo::Network::NetID::LIN;
|
||||
lin_c->network = icsneo::Network::NetID::LIN_01;
|
||||
lin_c->ID = 0x11;
|
||||
lin_c->linMsgType = icsneo::LINMessage::Type::LIN_HEADER_ONLY;
|
||||
ret = device->transmit(lin_c);
|
||||
@@ -132,9 +132,9 @@ int main() {
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
std::cout << "Transmitting a LIN commander frame with responder data... ";
|
||||
std::cout << "Transmitting a LIN 01 commander frame with responder data... ";
|
||||
auto lin_d = std::make_shared<icsneo::LINMessage>();
|
||||
lin_d->network = icsneo::Network::NetID::LIN;
|
||||
lin_d->network = icsneo::Network::NetID::LIN_01;
|
||||
lin_d->ID = 0x22;
|
||||
lin_d->isEnhancedChecksum = true;
|
||||
lin_d->linMsgType = icsneo::LINMessage::Type::LIN_COMMANDER_MSG;
|
||||
|
||||
@@ -35,6 +35,8 @@ int main() {
|
||||
msg->appendSignalArg(icsneo::LiveDataValueType::GPS_LATITUDE);
|
||||
msg->appendSignalArg(icsneo::LiveDataValueType::GPS_LONGITUDE);
|
||||
msg->appendSignalArg(icsneo::LiveDataValueType::GPS_ACCURACY);
|
||||
msg->appendSignalArg(icsneo::LiveDataValueType::DAQ_ENABLE);
|
||||
msg->appendSignalArg(icsneo::LiveDataValueType::MANUAL_TRIGGER);
|
||||
msg->cmd = icsneo::LiveDataCommand::SUBSCRIBE;
|
||||
msg->handle = icsneo::LiveDataUtil::getNewHandle();
|
||||
msg->updatePeriod = std::chrono::milliseconds(100);
|
||||
@@ -77,6 +79,26 @@ int main() {
|
||||
}));
|
||||
// Run handler for three seconds to observe the signal data
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
double val = 0;
|
||||
for (unsigned int i = 0; i < 10; ++i) {
|
||||
// Set the values of signals we're watching so we can see them change live
|
||||
auto setValMsg = std::make_shared<icsneo::LiveDataSetValueMessage>();
|
||||
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)) {
|
||||
break;
|
||||
}
|
||||
setValMsg->appendSetValue(icsneo::LiveDataValueType::DAQ_ENABLE, ldValueDAQEnable);
|
||||
setValMsg->appendSetValue(icsneo::LiveDataValueType::MANUAL_TRIGGER, ldValueManTrig);
|
||||
device->setValueLiveData(setValMsg);
|
||||
++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
|
||||
ret = device->unsubscribeLiveData(msg->handle);
|
||||
|
||||
@@ -92,8 +92,8 @@ int main()
|
||||
|
||||
auto handler = device->addMessageCallback(std::make_shared<icsneo::MessageCallback>([&](std::shared_ptr<icsneo::Message> message)
|
||||
{
|
||||
if(icsneo::Message::Type::BusMessage == message->type) {
|
||||
auto frame = std::static_pointer_cast<icsneo::BusMessage>(message);
|
||||
if(icsneo::Message::Type::Frame == message->type) {
|
||||
auto frame = std::static_pointer_cast<icsneo::Frame>(message);
|
||||
if(icsneo::Network::Type::MDIO == frame->network.getType()) {
|
||||
auto msg = std::static_pointer_cast<icsneo::MDIOMessage>(message);
|
||||
std::cout << msg->network << " " << ((msg->isTXMsg)? "TX" : "RX") << " frame\n";
|
||||
@@ -117,7 +117,7 @@ int main()
|
||||
// We can transmit messages to read the PHY ID of BCM89810 PHY
|
||||
std::cout << "\tTransmitting a MDIO request to read ID on BCM89810...\n";
|
||||
auto mdio_r = std::make_shared<icsneo::MDIOMessage>();
|
||||
mdio_r->network = icsneo::Network::NetID::MDIO1;
|
||||
mdio_r->network = icsneo::Network::NetID::MDIO_01;
|
||||
mdio_r->phyAddress = 0x00u;
|
||||
mdio_r->regAddress = 0x02u;
|
||||
mdio_r->direction = icsneo::MDIOMessage::Direction::Read;
|
||||
@@ -128,7 +128,7 @@ int main()
|
||||
// We can transmit messages to write to arbitrary register
|
||||
std::cout << "\tTransmitting a MDIO request to write register on BCM89810...\n";
|
||||
mdio_r = std::make_shared<icsneo::MDIOMessage>();
|
||||
mdio_r->network = icsneo::Network::NetID::MDIO1;
|
||||
mdio_r->network = icsneo::Network::NetID::MDIO_01;
|
||||
mdio_r->phyAddress = 0x00u;
|
||||
mdio_r->regAddress = 0x1Bu;
|
||||
mdio_r->data = {0xAA, 0xAF};
|
||||
@@ -140,7 +140,7 @@ int main()
|
||||
// We can transmit messages to read back to arbitrary register
|
||||
std::cout << "\tTransmitting a MDIO request to read register on BCM89810...\n";
|
||||
mdio_r = std::make_shared<icsneo::MDIOMessage>();
|
||||
mdio_r->network = icsneo::Network::NetID::MDIO1;
|
||||
mdio_r->network = icsneo::Network::NetID::MDIO_01;
|
||||
mdio_r->phyAddress = 0x00u;
|
||||
mdio_r->regAddress = 0x1Bu;
|
||||
mdio_r->direction = icsneo::MDIOMessage::Direction::Read;
|
||||
@@ -154,7 +154,7 @@ int main()
|
||||
// We can transmit messages to read the PHY ID of BCM89810 PHY
|
||||
std::cout << "\tTransmitting a MDIO request to read ID on 88Q2112...\n";
|
||||
mdio_r = std::make_shared<icsneo::MDIOMessage>();
|
||||
mdio_r->network = icsneo::Network::NetID::MDIO1;
|
||||
mdio_r->network = icsneo::Network::NetID::MDIO_01;
|
||||
mdio_r->phyAddress = 0x06u;
|
||||
mdio_r->devAddress = 0x01u;
|
||||
mdio_r->regAddress = 0x0002u;
|
||||
@@ -166,7 +166,7 @@ int main()
|
||||
// We can transmit messages to write to arbitrary register
|
||||
std::cout << "\tTransmitting a MDIO request to write register on 88Q2112...\n";
|
||||
mdio_r = std::make_shared<icsneo::MDIOMessage>();
|
||||
mdio_r->network = icsneo::Network::NetID::MDIO1;
|
||||
mdio_r->network = icsneo::Network::NetID::MDIO_01;
|
||||
mdio_r->phyAddress = 0x06u;
|
||||
mdio_r->devAddress = 0x01u;
|
||||
mdio_r->regAddress = 0x0902u;
|
||||
@@ -179,7 +179,7 @@ int main()
|
||||
// We can transmit messages to read back to arbitrary register
|
||||
std::cout << "\tTransmitting a MDIO request to read register on 88Q2112...\n";
|
||||
mdio_r = std::make_shared<icsneo::MDIOMessage>();
|
||||
mdio_r->network = icsneo::Network::NetID::MDIO1;
|
||||
mdio_r->network = icsneo::Network::NetID::MDIO_01;
|
||||
mdio_r->phyAddress = 0x06u;
|
||||
mdio_r->devAddress = 0x01u;
|
||||
mdio_r->regAddress = 0x0902u;
|
||||
|
||||
@@ -32,7 +32,7 @@ If you haven't done this, `third-party/libicsneo` will be empty and you won't be
|
||||
|
||||
### Ubuntu 18.04 LTS
|
||||
|
||||
1. Install dependencies with `sudo apt update` then `sudo apt install build-essential cmake libusb-1.0-0-dev libpcap0.8-dev`
|
||||
1. Install dependencies with `sudo apt update` then `sudo apt install build-essential cmake libpcap0.8-dev`
|
||||
2. Change directories to your `libicsneo-examples/libicsneocpp-example` folder and create a build directory by running `mkdir -p build`
|
||||
3. Enter the build directory with `cd build`
|
||||
4. Run `cmake ..` to generate your Makefile.
|
||||
|
||||
@@ -37,39 +37,39 @@ int main() {
|
||||
}
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
std::cout << "\tGetting HSCAN Baudrate... ";
|
||||
int64_t baud = device->settings->getBaudrateFor(icsneo::Network::NetID::HSCAN);
|
||||
std::cout << "\tGetting DW CAN 01 Baudrate... ";
|
||||
int64_t baud = device->settings->getBaudrateFor(icsneo::Network::NetID::DWCAN_01);
|
||||
if(baud < 0)
|
||||
std::cout << "FAIL" << std::endl;
|
||||
else
|
||||
std::cout << "OK, " << (baud/1000) << "kbit/s" << std::endl;
|
||||
|
||||
std::cout << "\tSetting HSCAN to operate at 125kbit/s... ";
|
||||
ret = device->settings->setBaudrateFor(icsneo::Network::NetID::HSCAN, 125000);
|
||||
std::cout << "\tSetting DW CAN 01 to operate at 125kbit/s... ";
|
||||
ret = device->settings->setBaudrateFor(icsneo::Network::NetID::DWCAN_01, 125000);
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
// Changes to the settings do not take affect until you call settings->apply()!
|
||||
// When you get the baudrate here, you're reading what the device is currently operating on
|
||||
std::cout << "\tGetting HSCAN Baudrate... (expected to be unchanged) ";
|
||||
baud = device->settings->getBaudrateFor(icsneo::Network::NetID::HSCAN);
|
||||
std::cout << "\tGetting DW CAN 01 Baudrate... (expected to be unchanged) ";
|
||||
baud = device->settings->getBaudrateFor(icsneo::Network::NetID::DWCAN_01);
|
||||
if(baud < 0)
|
||||
std::cout << "FAIL" << std::endl;
|
||||
else
|
||||
std::cout << "OK, " << (baud/1000) << "kbit/s" << std::endl;
|
||||
|
||||
std::cout << "\tGetting HSCANFD Baudrate... ";
|
||||
baud = device->settings->getFDBaudrateFor(icsneo::Network::NetID::HSCAN);
|
||||
std::cout << "\tGetting DW CAN 01 FD Baudrate... ";
|
||||
baud = device->settings->getFDBaudrateFor(icsneo::Network::NetID::DWCAN_01);
|
||||
if(baud < 0)
|
||||
std::cout << "FAIL" << std::endl;
|
||||
else
|
||||
std::cout << "OK, " << (baud/1000) << "kbit/s" << std::endl;
|
||||
|
||||
std::cout << "\tSetting HSCANFD to operate at 8Mbit/s... ";
|
||||
ret = device->settings->setFDBaudrateFor(icsneo::Network::NetID::HSCAN, 8000000);
|
||||
std::cout << "\tSetting DW CAN 01 FD to operate at 8Mbit/s... ";
|
||||
ret = device->settings->setFDBaudrateFor(icsneo::Network::NetID::DWCAN_01, 8000000);
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
std::cout << "\tGetting HSCANFD Baudrate... (expected to be unchanged) ";
|
||||
baud = device->settings->getFDBaudrateFor(icsneo::Network::NetID::HSCAN);
|
||||
std::cout << "\tGetting DW CAN 01 FD Baudrate... (expected to be unchanged) ";
|
||||
baud = device->settings->getFDBaudrateFor(icsneo::Network::NetID::DWCAN_01);
|
||||
if(baud < 0)
|
||||
std::cout << "FAIL" << std::endl;
|
||||
else
|
||||
@@ -83,15 +83,15 @@ int main() {
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
// Now that we have applied, we expect that our operating baudrates have changed
|
||||
std::cout << "\tGetting HSCAN Baudrate... ";
|
||||
baud = device->settings->getBaudrateFor(icsneo::Network::NetID::HSCAN);
|
||||
std::cout << "\tGetting DW CAN 01 Baudrate... ";
|
||||
baud = device->settings->getBaudrateFor(icsneo::Network::NetID::DWCAN_01);
|
||||
if(baud < 0)
|
||||
std::cout << "FAIL" << std::endl;
|
||||
else
|
||||
std::cout << "OK, " << (baud/1000) << "kbit/s" << std::endl;
|
||||
|
||||
std::cout << "\tGetting HSCANFD Baudrate... ";
|
||||
baud = device->settings->getFDBaudrateFor(icsneo::Network::NetID::HSCAN);
|
||||
std::cout << "\tGetting DW CAN 01 (FD) Baudrate... ";
|
||||
baud = device->settings->getFDBaudrateFor(icsneo::Network::NetID::DWCAN_01);
|
||||
if(baud < 0)
|
||||
std::cout << "FAIL" << std::endl;
|
||||
else
|
||||
@@ -155,13 +155,13 @@ int main() {
|
||||
// We can transmit messages
|
||||
std::cout << "\n\tTransmitting an extended CAN FD frame... ";
|
||||
auto txMessage5 = std::make_shared<icsneo::CANMessage>();
|
||||
txMessage5->network = icsneo::Network::NetID::HSCAN;
|
||||
txMessage5->network = icsneo::Network::NetID::DWCAN_01;
|
||||
txMessage5->arbid = 0x1C5001C5;
|
||||
txMessage5->data.insert(txMessage5->data.end(), {0xaa, 0xbb, 0xcc});
|
||||
// The DLC will come from the length of the data vector
|
||||
txMessage5->isExtended = true;
|
||||
txMessage5->isCANFD = true;
|
||||
ret = device->transmit(txMessage5); // This will return false if the device does not support CAN FD, or does not have HSCAN
|
||||
ret = device->transmit(txMessage5); // This will return false if the device does not support CAN FD, or does not have DWCAN_01
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
// We can also register a handler
|
||||
@@ -169,9 +169,9 @@ int main() {
|
||||
// MessageCallbacks are powerful, and can filter on things like ArbID for you. See the documentation
|
||||
auto handler = device->addMessageCallback(std::make_shared<icsneo::MessageCallback>([](std::shared_ptr<icsneo::Message> message) {
|
||||
switch(message->type) {
|
||||
case icsneo::Message::Type::BusMessage: {
|
||||
// A message of type BusMessage is guaranteed to be a BusMessage, so we can static cast safely
|
||||
auto frame = std::static_pointer_cast<icsneo::BusMessage>(message);
|
||||
case icsneo::Message::Type::Frame: {
|
||||
// A message of type Frame is guaranteed to be a Frame, so we can static cast safely
|
||||
auto frame = std::static_pointer_cast<icsneo::Frame>(message);
|
||||
switch(frame->network.getType()) {
|
||||
case icsneo::Network::Type::CAN: {
|
||||
// A message of type CAN is guaranteed to be a CANMessage, so we can static cast safely
|
||||
@@ -202,7 +202,7 @@ int main() {
|
||||
case icsneo::Network::Type::Ethernet: {
|
||||
auto ethMessage = std::static_pointer_cast<icsneo::EthernetMessage>(message);
|
||||
|
||||
std::cout << "\t\t" << ethMessage->network << " BusMessage - " << std::dec
|
||||
std::cout << "\t\t" << ethMessage->network << " Frame - " << std::dec
|
||||
<< ethMessage->data.size() << " bytes on wire\n";
|
||||
std::cout << "\t\t Timestamped:\t"<< ethMessage->timestamp << " ns since 1/1/2007\n";
|
||||
|
||||
@@ -249,7 +249,7 @@ int main() {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
} // end of icsneo::Message::Type::BusMessage
|
||||
} // end of icsneo::Message::Type::Frame
|
||||
case icsneo::Message::Type::CANErrorCount: {
|
||||
// A message of type CANErrorCount is guaranteed to be a CANErrorCount, so we can static cast safely
|
||||
auto cec = std::static_pointer_cast<icsneo::CANErrorMessage>(message);
|
||||
@@ -290,25 +290,25 @@ int main() {
|
||||
// We can transmit messages
|
||||
std::cout << "\tTransmitting an extended CAN FD frame... ";
|
||||
auto txMessage = std::make_shared<icsneo::CANMessage>();
|
||||
txMessage->network = icsneo::Network::NetID::HSCAN;
|
||||
txMessage->network = icsneo::Network::NetID::DWCAN_01;
|
||||
txMessage->arbid = 0x1C5001C5;
|
||||
txMessage->data.insert(txMessage->data.end(), {0xaa, 0xbb, 0xcc});
|
||||
// The DLC will come from the length of the data vector
|
||||
txMessage->isExtended = true;
|
||||
txMessage->isCANFD = true;
|
||||
ret = device->transmit(txMessage); // This will return false if the device does not support CAN FD, or does not have HSCAN
|
||||
ret = device->transmit(txMessage); // This will return false if the device does not support CAN FD, or does not have DWCAN_01
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
std::cout << "\tTransmitting an ethernet frame on OP (BR) Ethernet 2... ";
|
||||
std::cout << "\tTransmitting an ethernet frame on AE 02... ";
|
||||
auto ethTxMessage = std::make_shared<icsneo::EthernetMessage>();
|
||||
ethTxMessage->network = icsneo::Network::NetID::OP_Ethernet2;
|
||||
ethTxMessage->network = icsneo::Network::NetID::AE_02;
|
||||
ethTxMessage->data.insert(ethTxMessage->data.end(), {
|
||||
0x00, 0xFC, 0x70, 0x00, 0x01, 0x02, /* Destination MAC */
|
||||
0x00, 0xFC, 0x70, 0x00, 0x01, 0x01, /* Source MAC */
|
||||
0x00, 0x00, /* Ether Type */
|
||||
0x01, 0xC5, 0x01, 0xC5 /* Payload (will automatically be padded on transmit unless you set `ethTxMessage->noPadding`) */
|
||||
});
|
||||
ret = device->transmit(ethTxMessage); // This will return false if the device does not support OP (BR) Ethernet 2
|
||||
ret = device->transmit(ethTxMessage); // This will return false if the device does not support AE 02
|
||||
std::cout << (ret ? "OK" : "FAIL") << std::endl;
|
||||
|
||||
std::vector<icsneo::MiscIO> emisc = device->getEMiscIO();
|
||||
|
||||
@@ -16,13 +16,13 @@ void onEvent(std::shared_ptr<icsneo::APIEvent> event) {
|
||||
std::cout << event->describe() << std::endl;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<icsneo::BusMessage>> constructRandomFrames(size_t frameCount, MessageType frameType) {
|
||||
std::vector<std::shared_ptr<icsneo::Frame>> constructRandomFrames(size_t frameCount, MessageType frameType) {
|
||||
static constexpr size_t ClassicCANSize = 8;
|
||||
static constexpr size_t CANFDSize = 64;
|
||||
static constexpr size_t ShortEthSize = 500;
|
||||
static constexpr size_t LongEthSize = 1500;
|
||||
|
||||
std::vector<std::shared_ptr<icsneo::BusMessage>> frames;
|
||||
std::vector<std::shared_ptr<icsneo::Frame>> frames;
|
||||
std::random_device randDev;
|
||||
std::mt19937 randEngine(randDev());
|
||||
std::uniform_int_distribution randByteDist(0,255);
|
||||
@@ -36,7 +36,7 @@ std::vector<std::shared_ptr<icsneo::BusMessage>> constructRandomFrames(size_t fr
|
||||
// Short Ethernet
|
||||
{
|
||||
auto frame = std::make_shared<icsneo::EthernetMessage>();
|
||||
frame->network = icsneo::Network::NetID::Ethernet;
|
||||
frame->network = icsneo::Network::NetID::ETHERNET_01;
|
||||
frames.push_back(frame);
|
||||
frame->data.resize(ShortEthSize);
|
||||
std::generate(frame->data.begin(), frame->data.end(), randByteGen);
|
||||
@@ -46,7 +46,7 @@ std::vector<std::shared_ptr<icsneo::BusMessage>> constructRandomFrames(size_t fr
|
||||
// Long Ethernet
|
||||
{
|
||||
auto frame = std::make_shared<icsneo::EthernetMessage>();
|
||||
frame->network = icsneo::Network::NetID::Ethernet;
|
||||
frame->network = icsneo::Network::NetID::ETHERNET_01;
|
||||
frames.push_back(frame);
|
||||
frame->data.resize(LongEthSize);
|
||||
std::generate(frame->data.begin(), frame->data.end(), randByteGen);
|
||||
@@ -56,7 +56,7 @@ std::vector<std::shared_ptr<icsneo::BusMessage>> constructRandomFrames(size_t fr
|
||||
// Classic CAN
|
||||
{
|
||||
auto frame = std::make_shared<icsneo::CANMessage>();
|
||||
frame->network = icsneo::Network::NetID::HSCAN2;
|
||||
frame->network = icsneo::Network::NetID::DWCAN_02;
|
||||
frames.push_back(frame);
|
||||
frame->data.resize(ClassicCANSize);
|
||||
|
||||
@@ -67,7 +67,7 @@ std::vector<std::shared_ptr<icsneo::BusMessage>> constructRandomFrames(size_t fr
|
||||
// CAN FD
|
||||
{
|
||||
auto frame = std::make_shared<icsneo::CANMessage>();
|
||||
frame->network = icsneo::Network::NetID::HSCAN3;
|
||||
frame->network = icsneo::Network::NetID::DWCAN_03;
|
||||
frames.push_back(frame);
|
||||
frame->data.resize(CANFDSize);
|
||||
std::generate(frame->data.begin(), frame->data.end(), randByteGen);
|
||||
@@ -166,10 +166,10 @@ int main(int argc, char* argv[]) {
|
||||
uint64_t canFrameCount = 0;
|
||||
uint64_t ethFrameCount = 0;
|
||||
rxDevice->addMessageCallback(std::make_shared<icsneo::MessageCallback>([&](std::shared_ptr<icsneo::Message> msg) {
|
||||
if(msg->type != icsneo::Message::Type::BusMessage) {
|
||||
if(msg->type != icsneo::Message::Type::Frame) {
|
||||
return;
|
||||
}
|
||||
const auto frame = std::static_pointer_cast<icsneo::BusMessage>(msg);
|
||||
const auto frame = std::static_pointer_cast<icsneo::Frame>(msg);
|
||||
if(frame->network.getType() == icsneo::Network::Type::CAN) {
|
||||
++canFrameCount;
|
||||
} else if(frame->network.getType() == icsneo::Network::Type::Ethernet) {
|
||||
@@ -200,7 +200,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
const uint8_t NumFrameTypes = 4;
|
||||
const size_t FrameCountPerType = 2500;
|
||||
std::vector<std::shared_ptr<icsneo::BusMessage>> frames;
|
||||
std::vector<std::shared_ptr<icsneo::Frame>> frames;
|
||||
for(uint8_t i = 0; i < NumFrameTypes; i++) {
|
||||
std::cout << "info: transmitting " << FrameCountPerType << " random " << MessageTypeLabels[i] << " frames" << std::endl;
|
||||
auto tempFrames = constructRandomFrames(FrameCountPerType, static_cast<MessageType>(i));
|
||||
@@ -216,10 +216,10 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
size_t currentMessage = 0;
|
||||
rxDevice->addMessageCallback(std::make_shared<icsneo::MessageCallback>([&](std::shared_ptr<icsneo::Message> msg) {
|
||||
if(msg->type != icsneo::Message::Type::BusMessage) {
|
||||
if(msg->type != icsneo::Message::Type::Frame) {
|
||||
return;
|
||||
}
|
||||
auto frame = std::static_pointer_cast<icsneo::BusMessage>(msg);
|
||||
auto frame = std::static_pointer_cast<icsneo::Frame>(msg);
|
||||
if(frames[currentMessage]->data == frame->data) {
|
||||
currentMessage++;
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
project(icsneocsharp VERSION 0.2.0)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# Add an include directory like so if desired
|
||||
#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
# Enable Warnings
|
||||
if(MSVC)
|
||||
# Force to always compile with W4
|
||||
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
||||
endif()
|
||||
else() #if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-switch -Wno-unknown-pragmas")
|
||||
endif()
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third-party/libicsneo ${CMAKE_CURRENT_BINARY_DIR}/third-party/libicsneo)
|
||||
|
||||
add_library(icsneocsharp SHARED ${CMAKE_CURRENT_SOURCE_DIR}/csharp_wrap.c)
|
||||
target_link_libraries(icsneocsharp icsneoc)
|
||||
@@ -1,520 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace libicsneocsharp_example {
|
||||
class InteractiveExample {
|
||||
|
||||
private uint msgLimit = 50000;
|
||||
private neodevice_t selectedDevice;
|
||||
private List<neodevice_t> devices = new List<neodevice_t>();
|
||||
private uint numDevices = 0;
|
||||
|
||||
private void PrintAllDevices() {
|
||||
if(numDevices == 0) {
|
||||
System.Console.WriteLine("No devices found! Please scan for new devices.");
|
||||
}
|
||||
|
||||
for(int i = 0; i < numDevices; i++) {
|
||||
System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION);
|
||||
int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION;
|
||||
|
||||
if(icsneocsharp.icsneo_describeDevice(devices[i], description, ref maxLength)) {
|
||||
System.Console.Write("[" + (i + 1) + "] " + description.ToString() + "\tConnected: ");
|
||||
|
||||
if(icsneocsharp.icsneo_isOpen(devices[i])) {
|
||||
System.Console.Write("Yes\t");
|
||||
} else System.Console.Write("No\t");
|
||||
|
||||
System.Console.Write("Online: ");
|
||||
if(icsneocsharp.icsneo_isOnline(devices[i])) {
|
||||
System.Console.Write("Yes\t");
|
||||
} else System.Console.Write("No\t");
|
||||
|
||||
System.Console.Write("Msg Polling: ");
|
||||
if(icsneocsharp.icsneo_isMessagePollingEnabled(devices[i])) {
|
||||
System.Console.Write("On\n");
|
||||
} else System.Console.Write("Off\n");
|
||||
} else {
|
||||
System.Console.WriteLine("Description for device " + (i + 1) + " not available!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private uint ScanNewDevices() {
|
||||
neodevice_t newDevices = icsneocsharp.new_neodevice_t_array(99);
|
||||
|
||||
int count = 10;
|
||||
|
||||
icsneocsharp.icsneo_findAllDevices(newDevices, ref count);
|
||||
|
||||
numDevices += (uint) count;
|
||||
|
||||
for(int i = 0; i < numDevices; i++) {
|
||||
devices.Add(icsneocsharp.neodevice_t_array_getitem(newDevices, i));
|
||||
}
|
||||
icsneocsharp.delete_neodevice_t_array(newDevices);
|
||||
return (uint) count;
|
||||
}
|
||||
|
||||
private void PrintMainMenu() {
|
||||
System.Console.WriteLine("Press the letter next to the function you want to use:");
|
||||
System.Console.WriteLine("A - List all devices");
|
||||
System.Console.WriteLine("B - Scan for new devices");
|
||||
System.Console.WriteLine("C - Open/close");
|
||||
System.Console.WriteLine("D - Go online/offline");
|
||||
System.Console.WriteLine("E - Enable/disable message polling");
|
||||
System.Console.WriteLine("F - Get messages");
|
||||
System.Console.WriteLine("G - Send message");
|
||||
System.Console.WriteLine("H - Get events");
|
||||
System.Console.WriteLine("I - Set HS CAN to 250K");
|
||||
System.Console.WriteLine("J - Set HS CAN to 500K");
|
||||
System.Console.WriteLine("X - Exit");
|
||||
}
|
||||
|
||||
void PrintLastError() {
|
||||
neoevent_t error = new neoevent_t();
|
||||
if(icsneocsharp.icsneo_getLastError(error))
|
||||
System.Console.WriteLine("Error 0x" + error.eventNumber + ": " + error.description);
|
||||
else
|
||||
System.Console.WriteLine("No errors found!");
|
||||
}
|
||||
|
||||
void PrintAPIEvents() {
|
||||
neoevent_t events = icsneocsharp.new_neoevent_t_array(99);
|
||||
int eventCount = 99;
|
||||
if(icsneocsharp.icsneo_getEvents(events, ref eventCount)) {
|
||||
if(eventCount == 1) {
|
||||
neoevent_t evt = icsneocsharp.neoevent_t_array_getitem(events, 0);
|
||||
System.Console.WriteLine("1 API event found!");
|
||||
System.Console.WriteLine("Event 0x" + evt.eventNumber + ": " + evt.description);
|
||||
} else {
|
||||
System.Console.WriteLine(eventCount + " API events found!");
|
||||
for(var i = 0; i < eventCount; ++i) {
|
||||
neoevent_t evt = icsneocsharp.neoevent_t_array_getitem(events, i);
|
||||
System.Console.WriteLine("Event 0x" + evt.eventNumber + ": " + evt.description);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.Console.WriteLine("Failed to get API events!");
|
||||
}
|
||||
icsneocsharp.delete_neoevent_t_array(events);
|
||||
}
|
||||
|
||||
void PrintDeviceEvents(neodevice_t device) {
|
||||
neoevent_t events = icsneocsharp.new_neoevent_t_array(99);
|
||||
int eventCount = 99;
|
||||
if(icsneocsharp.icsneo_getDeviceEvents(device, events, ref eventCount)) {
|
||||
if(eventCount == 1) {
|
||||
neoevent_t evt = icsneocsharp.neoevent_t_array_getitem(events, 0);
|
||||
System.Console.WriteLine("1 device event found!");
|
||||
System.Console.WriteLine("Event 0x" + evt.eventNumber + ": " + evt.description);
|
||||
} else {
|
||||
System.Console.WriteLine(eventCount + " device events found!");
|
||||
for(var i = 0; i < eventCount; ++i) {
|
||||
neoevent_t evt = icsneocsharp.neoevent_t_array_getitem(events, i);
|
||||
System.Console.WriteLine("Event 0x" + evt.eventNumber + ": " + evt.description);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.Console.WriteLine("Failed to get API events!");
|
||||
}
|
||||
icsneocsharp.delete_neoevent_t_array(events);
|
||||
}
|
||||
|
||||
private char GetCharInput(List<char> allowed) {
|
||||
bool found = false;
|
||||
char key = '0';
|
||||
while(!found) {
|
||||
key = System.Console.ReadKey().KeyChar;
|
||||
System.Console.WriteLine();
|
||||
foreach(char compare in allowed) {
|
||||
if(compare == key) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found) {
|
||||
System.Console.WriteLine("Input did not match expected options. Please try again.");
|
||||
}
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
neodevice_t SelectDevice() {
|
||||
System.Console.WriteLine("Please select a device:");
|
||||
PrintAllDevices();
|
||||
System.Console.WriteLine();
|
||||
|
||||
int selectedDeviceNum = 10;
|
||||
while(selectedDeviceNum > numDevices) {
|
||||
char deviceSelection = GetCharInput(new List<char> { '1', '2', '3', '4', '5', '6', '7', '8', '9' });
|
||||
selectedDeviceNum = (int)char.GetNumericValue(deviceSelection);
|
||||
if(selectedDeviceNum > numDevices) {
|
||||
System.Console.WriteLine("Selected device out of range!");
|
||||
}
|
||||
}
|
||||
|
||||
System.Console.WriteLine();
|
||||
|
||||
return devices[selectedDeviceNum - 1];
|
||||
}
|
||||
|
||||
public void Run() {
|
||||
neoversion_t version = icsneocsharp.icsneo_getVersion();
|
||||
System.Console.WriteLine("ICS icsneocsharp.dll version " + version.major + "." + version.minor + "." + version.patch);
|
||||
System.Console.WriteLine();
|
||||
|
||||
while(true) {
|
||||
PrintMainMenu();
|
||||
System.Console.WriteLine();
|
||||
char input = GetCharInput(new List<char> { 'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'X', 'x' });
|
||||
System.Console.WriteLine();
|
||||
switch(input) {
|
||||
// List current devices
|
||||
case 'A':
|
||||
goto case 'a';
|
||||
case 'a':
|
||||
PrintAllDevices();
|
||||
System.Console.WriteLine();
|
||||
break;
|
||||
// Scan for new devices
|
||||
case 'B':
|
||||
goto case 'b';
|
||||
case 'b': {
|
||||
var numNewDevices = ScanNewDevices();
|
||||
if(numNewDevices == 1) {
|
||||
System.Console.WriteLine("1 new device found!");
|
||||
} else {
|
||||
System.Console.WriteLine(numNewDevices + " new devices found!");
|
||||
}
|
||||
PrintAllDevices();
|
||||
System.Console.WriteLine();
|
||||
break;
|
||||
}
|
||||
// Open/close a device
|
||||
case 'C':
|
||||
goto case 'c';
|
||||
case 'c': {
|
||||
// Select a device and get its description
|
||||
if(numDevices == 0) {
|
||||
System.Console.WriteLine("No devices found! Please scan for new devices.\n");
|
||||
break;
|
||||
}
|
||||
selectedDevice = SelectDevice();
|
||||
|
||||
// Get the product description for the device
|
||||
System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION);
|
||||
int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION;
|
||||
|
||||
icsneocsharp.icsneo_describeDevice(selectedDevice, description, ref maxLength);
|
||||
|
||||
System.Console.WriteLine("Would you like to open or close " + description + "?");
|
||||
System.Console.WriteLine("[1] Open\n[2] Close\n[3] Cancel\n");
|
||||
|
||||
char option = GetCharInput(new List<char> { '1', '2', '3' });
|
||||
System.Console.WriteLine();
|
||||
|
||||
switch(option) {
|
||||
case '1':
|
||||
// Attempt to open the selected device
|
||||
if(icsneocsharp.icsneo_openDevice(selectedDevice)) {
|
||||
System.Console.WriteLine(description + " successfully opened!\n");
|
||||
} else {
|
||||
System.Console.WriteLine(description + " failed to open!\n");
|
||||
PrintLastError();
|
||||
System.Console.WriteLine();
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
// Attempt to close the device
|
||||
if(icsneocsharp.icsneo_closeDevice(selectedDevice)) {
|
||||
numDevices--;
|
||||
System.Console.WriteLine("Successfully closed " + description + "!\n");
|
||||
devices.Remove(selectedDevice);
|
||||
selectedDevice = null;
|
||||
} else {
|
||||
System.Console.WriteLine("Failed to close " + description.ToString() + "!\n");
|
||||
PrintLastError();
|
||||
System.Console.WriteLine();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.Console.WriteLine("Canceling!\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Go online/offline
|
||||
case 'D':
|
||||
goto case 'd';
|
||||
case 'd': {
|
||||
// Select a device and get its description
|
||||
if(numDevices == 0) {
|
||||
System.Console.WriteLine("No devices found! Please scan for new devices.\n");
|
||||
break;
|
||||
}
|
||||
selectedDevice = SelectDevice();
|
||||
|
||||
// Get the product description for the device
|
||||
System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION);
|
||||
int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION;
|
||||
|
||||
icsneocsharp.icsneo_describeDevice(selectedDevice, description, ref maxLength);
|
||||
|
||||
System.Console.WriteLine("Would you like to have " + description.ToString() + " go online or offline?");
|
||||
System.Console.WriteLine("[1] Online\n[2] Offline\n[3] Cancel\n");
|
||||
|
||||
char option = GetCharInput(new List<char> { '1', '2', '3' });
|
||||
System.Console.WriteLine();
|
||||
|
||||
switch(option) {
|
||||
case '1':
|
||||
// Attempt to go online
|
||||
if(icsneocsharp.icsneo_goOnline(selectedDevice)) {
|
||||
System.Console.WriteLine(description + " successfully went online!\n");
|
||||
} else {
|
||||
System.Console.WriteLine(description + " failed to go online!\n");
|
||||
PrintLastError();
|
||||
System.Console.WriteLine();
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
// Attempt to go offline
|
||||
if(icsneocsharp.icsneo_goOffline(selectedDevice)) {
|
||||
System.Console.WriteLine(description + " successfully went offline!\n");
|
||||
} else {
|
||||
System.Console.WriteLine(description + " failed to go offline!\n");
|
||||
PrintLastError();
|
||||
System.Console.WriteLine();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.Console.WriteLine("Canceling!\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Enable/disable message polling
|
||||
case 'E':
|
||||
goto case 'e';
|
||||
case 'e': {
|
||||
// Select a device and get its description
|
||||
if(numDevices == 0) {
|
||||
System.Console.WriteLine("No devices found! Please scan for new devices.\n");
|
||||
break;
|
||||
}
|
||||
selectedDevice = SelectDevice();
|
||||
|
||||
// Get the product description for the device
|
||||
System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION);
|
||||
int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION;
|
||||
|
||||
icsneocsharp.icsneo_describeDevice(selectedDevice, description, ref maxLength);
|
||||
|
||||
System.Console.WriteLine("Would you like to enable or disable message polling for " + description.ToString() + "?");
|
||||
System.Console.WriteLine("[1] Enable\n[2] Disable\n[3] Cancel\n");
|
||||
|
||||
char option = GetCharInput(new List<char> { '1', '2', '3' });
|
||||
System.Console.WriteLine();
|
||||
|
||||
switch(option) {
|
||||
case '1':
|
||||
// Attempt to enable message polling
|
||||
if(icsneocsharp.icsneo_enableMessagePolling(selectedDevice)) {
|
||||
System.Console.WriteLine("Successfully enabled message polling for " + description.ToString() + "!\n");
|
||||
} else {
|
||||
System.Console.WriteLine("Failed to enable message polling for " + description.ToString() + "!\n");
|
||||
PrintLastError();
|
||||
System.Console.WriteLine();
|
||||
}
|
||||
|
||||
// Manually setting the polling message limit as done below is optional
|
||||
// It will default to 20k if not set
|
||||
// Attempt to set the polling message limit
|
||||
if(icsneocsharp.icsneo_setPollingMessageLimit(selectedDevice, msgLimit)) {
|
||||
System.Console.WriteLine("Successfully set message polling limit for " + description.ToString() + "!\n");
|
||||
} else {
|
||||
System.Console.WriteLine("Failed to set polling message limit for " + description.ToString() + "!\n");
|
||||
PrintLastError();
|
||||
System.Console.WriteLine();
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
// Attempt to disable message polling
|
||||
if(icsneocsharp.icsneo_disableMessagePolling(selectedDevice)) {
|
||||
System.Console.WriteLine("Successfully disabled message polling for " + description.ToString() + "!\n");
|
||||
} else {
|
||||
System.Console.WriteLine("Failed to disable message polling for " + description.ToString() + "!\n");
|
||||
PrintLastError();
|
||||
System.Console.WriteLine();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.Console.WriteLine("Canceling!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'F':
|
||||
goto case 'f';
|
||||
case 'f': {
|
||||
// Select a device and get its description
|
||||
if(numDevices == 0) {
|
||||
System.Console.WriteLine("No devices found! Please scan for new devices.\n");
|
||||
break;
|
||||
}
|
||||
selectedDevice = SelectDevice();
|
||||
|
||||
// Get the product description for the device
|
||||
System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION);
|
||||
int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION;
|
||||
|
||||
icsneocsharp.icsneo_describeDevice(selectedDevice, description, ref maxLength);
|
||||
|
||||
// Prepare the neomessage_t array and size for reading in the messages
|
||||
neomessage_t msgs = icsneocsharp.new_neomessage_t_array((int)msgLimit);
|
||||
int msgCount = (int)msgLimit;
|
||||
|
||||
if(!icsneocsharp.icsneo_getMessages(selectedDevice, msgs, ref msgCount, 0)) {
|
||||
System.Console.WriteLine("Failed to get messages for " + description.ToString() + "!\n");
|
||||
PrintLastError();
|
||||
icsneocsharp.delete_neomessage_t_array(msgs);
|
||||
System.Console.WriteLine();
|
||||
break;
|
||||
}
|
||||
|
||||
if(msgCount == 1) {
|
||||
System.Console.WriteLine("1 message received from " + description.ToString() + "!");
|
||||
} else {
|
||||
System.Console.WriteLine(msgCount + " messages received from " + description.ToString() + "!");
|
||||
}
|
||||
|
||||
// Print out the received messages
|
||||
for(int i = 0; i < msgCount; i++) {
|
||||
neomessage_t msg = icsneocsharp.neomessage_t_array_getitem(msgs, i);
|
||||
if(msg.type == icsneocsharp.ICSNEO_NETWORK_TYPE_CAN) {
|
||||
System.Console.Write("\t0x" + "{0:x}" + " [" + msg.length + "] ", icsneocsharp.neomessage_can_t_cast(msg).arbid);
|
||||
for(int j = 0; j < msg.length; j++) {
|
||||
System.Console.Write("{0:x} ", icsneocsharp.neomessage_can_t_cast(msg).data[j]);
|
||||
}
|
||||
System.Console.WriteLine("(" + msg.timestamp + ")");
|
||||
} else {
|
||||
if(msg.netid != 0)
|
||||
System.Console.WriteLine("\tMessage on netid " + msg.netid + " with length " + msg.length);
|
||||
}
|
||||
}
|
||||
icsneocsharp.delete_neomessage_t_array(msgs);
|
||||
break;
|
||||
}
|
||||
// Send message
|
||||
case 'G':
|
||||
goto case 'g';
|
||||
case 'g': {
|
||||
// Select a device and get its description
|
||||
if(numDevices == 0) {
|
||||
System.Console.WriteLine("No devices found! Please scan for new devices.\n");
|
||||
break;
|
||||
}
|
||||
selectedDevice = SelectDevice();
|
||||
|
||||
// Get the product description for the device
|
||||
System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION);
|
||||
int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION;
|
||||
|
||||
icsneocsharp.icsneo_describeDevice(selectedDevice, description, ref maxLength);
|
||||
|
||||
// Start generating sample msg
|
||||
neomessage_can_t msg = new neomessage_can_t();
|
||||
msg.arbid = 0x120;
|
||||
msg.length = 6;
|
||||
msg.netid = (ushort)icsneocsharp.ICSNEO_NETID_HSCAN;
|
||||
msg.data = new byte[6] { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
|
||||
msg.status.canfdFDF = 0;
|
||||
msg.status.extendedFrame = 0;
|
||||
msg.status.canfdBRS = 0;
|
||||
// End generating sample msg
|
||||
|
||||
// Attempt to transmit the sample msg
|
||||
if(icsneocsharp.icsneo_transmit(selectedDevice, icsneocsharp.from_can_neomessage_t_cast(msg))) {
|
||||
System.Console.WriteLine("Message transmit successful!");
|
||||
} else {
|
||||
System.Console.WriteLine("Failed to transmit message to " + description.ToString() + "!\n");
|
||||
PrintLastError();
|
||||
System.Console.WriteLine();
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Get events
|
||||
case 'H':
|
||||
goto case 'h';
|
||||
case 'h':
|
||||
PrintAPIEvents();
|
||||
System.Console.WriteLine();
|
||||
break;
|
||||
// Set HS CAN to 250k
|
||||
case 'I':
|
||||
goto case 'i';
|
||||
case 'i': {
|
||||
// Select a device and get its description
|
||||
if(numDevices == 0) {
|
||||
System.Console.WriteLine("No devices found! Please scan for new devices.\n");
|
||||
break;
|
||||
}
|
||||
selectedDevice = SelectDevice();
|
||||
|
||||
// Get the product description for the device
|
||||
System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION);
|
||||
int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION;
|
||||
|
||||
icsneocsharp.icsneo_describeDevice(selectedDevice, description, ref maxLength);
|
||||
|
||||
// Attempt to set baudrate and apply settings
|
||||
if(icsneocsharp.icsneo_setBaudrate(selectedDevice, (ushort)icsneocsharp.ICSNEO_NETID_HSCAN, 250000) && icsneocsharp.icsneo_settingsApply(selectedDevice)) {
|
||||
System.Console.WriteLine("Successfully set HS CAN baudrate for " + description.ToString() + "to 250k!\n");
|
||||
} else {
|
||||
System.Console.WriteLine("Failed to set HS CAN for " + description.ToString() + " to 250k!\n");
|
||||
PrintLastError();
|
||||
System.Console.WriteLine();
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Set HS CAN to 500k
|
||||
case 'J':
|
||||
goto case 'j';
|
||||
case 'j': {
|
||||
// Select a device and get its description
|
||||
if(numDevices == 0) {
|
||||
System.Console.WriteLine("No devices found! Please scan for new devices.\n");
|
||||
break;
|
||||
}
|
||||
selectedDevice = SelectDevice();
|
||||
|
||||
// Get the product description for the device
|
||||
System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION);
|
||||
int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION;
|
||||
|
||||
icsneocsharp.icsneo_describeDevice(selectedDevice, description, ref maxLength);
|
||||
|
||||
// Attempt to set baudrate and apply settings
|
||||
if(icsneocsharp.icsneo_setBaudrate(selectedDevice, (ushort)icsneocsharp.ICSNEO_NETID_HSCAN, 500000) && icsneocsharp.icsneo_settingsApply(selectedDevice)) {
|
||||
System.Console.WriteLine("Successfully set HS CAN baudrate for " + description.ToString() + "to 500k!\n");
|
||||
} else {
|
||||
System.Console.WriteLine("Failed to set HS CAN for " + description.ToString() + " to 500k!\n");
|
||||
PrintLastError();
|
||||
System.Console.WriteLine();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'X':
|
||||
goto case 'x';
|
||||
case 'x':
|
||||
System.Console.WriteLine("Exiting program");
|
||||
return;
|
||||
default:
|
||||
System.Console.WriteLine("Unexpected input, exiting!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace libicsneocsharp_example {
|
||||
class Program {
|
||||
static void Main(string[] args) {
|
||||
InteractiveExample example = new InteractiveExample();
|
||||
example.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
# libicsneo C# Example
|
||||
|
||||
This is an example console application that uses the icsneocsharp library to control an Intrepid Control Systems hardware device.
|
||||
|
||||
## Cloning
|
||||
|
||||
This will create a copy of the repository on your local machine.
|
||||
|
||||
Run:
|
||||
|
||||
```shell
|
||||
git clone https://github.com/intrepidcs/libicsneo-examples --recursive
|
||||
```
|
||||
|
||||
Alternatively, if you cloned without the `--recursive` flag, you must enter the `libicsneo-examples` folder and run the following:
|
||||
|
||||
```shell
|
||||
git submodule update --recursive --init
|
||||
```
|
||||
|
||||
If you haven't done this, `third-party/libicsneo` will be empty and you won't be able to build!
|
||||
|
||||
## Windows using Visual Studio 2017+
|
||||
|
||||
### Building the DLLs
|
||||
|
||||
#### icsneoc
|
||||
|
||||
First, we are going to build the icsneoc library into a .dll file that is used by the C# wrapper to access the library functions.
|
||||
|
||||
1. Launch Visual Studio and open the `libicsneo-examples` folder.
|
||||
2. Choose `File->Open->Cmake...`
|
||||
3. Navigate to `third-party/libicsneo` and select the `CMakeLists.txt` there.
|
||||
4. Visual Studio will process the CMake project.
|
||||
5. Select `Build->Rebuild All`
|
||||
6. Visual Studio will generate the `icsneoc.dll` file, which can then be found by selecting `Project->Cmake Cache (x64-Debug Only)->Open in Explorer`. If the file cannot be found, search in `libicsneo-examples/third-party/libicsneo/out/build/x64-Debug` and double-check that the build succeeded in step 5.
|
||||
7. Move the `icsneoc.dll` file to the `/C/Windows/System32` folder.
|
||||
|
||||
#### icsneocsharp
|
||||
|
||||
Next, we are going to build the wrapper functions into a .dll file that is used to access the library functions in C#.
|
||||
|
||||
1. Launch a terminal window and change directories into `libicsneo-examples/libicsneocsharp-example`, then create a build directory by running `mkdir -p build`
|
||||
2. Enter the build directory with `cd build`
|
||||
3. Run `cmake ..`
|
||||
4. Run `cmake --build .`
|
||||
5. The `icsneocsharp.dll` file will be generated in `libicsneo-examples/libicsneocsharp-example/build/Debug`
|
||||
6. Move the `icsneocsharp.dll` file to the `/C/Windows/System32` folder.
|
||||
|
||||
### Building the example program
|
||||
|
||||
1. Choose `File->Open->Project/Solution...`
|
||||
2. Navigate to `libicsneo-examples/libicsneocsharp-example` and select the `libicsneocsharp-example.sln` there.
|
||||
3. Visual Studio will process the project.
|
||||
4. Select `Build->Rebuild Solution`
|
||||
5. Click on the dropdown arrow attached to the green play button (labelled "Select Startup Item") and select `libicsneocsharp-example`
|
||||
6. Click on the green play button to run the example.
|
||||
@@ -1,26 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated />
|
||||
//
|
||||
// This file was automatically generated by SWIG (http://www.swig.org).
|
||||
// Version 4.0.0
|
||||
//
|
||||
// Do not make changes to this file unless you know what you are doing--modify
|
||||
// the SWIG interface file instead.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
public class SWIGTYPE_p_time_t {
|
||||
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
|
||||
|
||||
internal SWIGTYPE_p_time_t(global::System.IntPtr cPtr, bool futureUse) {
|
||||
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
|
||||
}
|
||||
|
||||
protected SWIGTYPE_p_time_t() {
|
||||
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
|
||||
}
|
||||
|
||||
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SWIGTYPE_p_time_t obj) {
|
||||
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated />
|
||||
//
|
||||
// This file was automatically generated by SWIG (http://www.swig.org).
|
||||
// Version 4.0.0
|
||||
//
|
||||
// Do not make changes to this file unless you know what you are doing--modify
|
||||
// the SWIG interface file instead.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
public class SWIGTYPE_p_unsigned_char {
|
||||
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
|
||||
|
||||
internal SWIGTYPE_p_unsigned_char(global::System.IntPtr cPtr, bool futureUse) {
|
||||
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
|
||||
}
|
||||
|
||||
protected SWIGTYPE_p_unsigned_char() {
|
||||
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
|
||||
}
|
||||
|
||||
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SWIGTYPE_p_unsigned_char obj) {
|
||||
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated />
|
||||
//
|
||||
// This file was automatically generated by SWIG (http://www.swig.org).
|
||||
// Version 4.0.0
|
||||
//
|
||||
// Do not make changes to this file unless you know what you are doing--modify
|
||||
// the SWIG interface file instead.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
public class SWIGTYPE_p_unsigned_int {
|
||||
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
|
||||
|
||||
internal SWIGTYPE_p_unsigned_int(global::System.IntPtr cPtr, bool futureUse) {
|
||||
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
|
||||
}
|
||||
|
||||
protected SWIGTYPE_p_unsigned_int() {
|
||||
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
|
||||
}
|
||||
|
||||
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SWIGTYPE_p_unsigned_int obj) {
|
||||
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated />
|
||||
//
|
||||
// This file was automatically generated by SWIG (http://www.swig.org).
|
||||
// Version 4.0.0
|
||||
//
|
||||
// Do not make changes to this file unless you know what you are doing--modify
|
||||
// the SWIG interface file instead.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
public class SWIGTYPE_p_unsigned_short {
|
||||
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
|
||||
|
||||
internal SWIGTYPE_p_unsigned_short(global::System.IntPtr cPtr, bool futureUse) {
|
||||
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
|
||||
}
|
||||
|
||||
protected SWIGTYPE_p_unsigned_short() {
|
||||
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
|
||||
}
|
||||
|
||||
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SWIGTYPE_p_unsigned_short obj) {
|
||||
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated />
|
||||
//
|
||||
// This file was automatically generated by SWIG (http://www.swig.org).
|
||||
// Version 4.0.0
|
||||
//
|
||||
// Do not make changes to this file unless you know what you are doing--modify
|
||||
// the SWIG interface file instead.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
public class SWIGTYPE_p_void {
|
||||
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
|
||||
|
||||
internal SWIGTYPE_p_void(global::System.IntPtr cPtr, bool futureUse) {
|
||||
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
|
||||
}
|
||||
|
||||
protected SWIGTYPE_p_void() {
|
||||
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
|
||||
}
|
||||
|
||||
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SWIGTYPE_p_void obj) {
|
||||
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
%module icsneocsharp
|
||||
%include <windows.i>
|
||||
%include <typemaps.i>
|
||||
%include <stdint.i>
|
||||
%include <carrays.i>
|
||||
%include <arrays_csharp.i>
|
||||
|
||||
#define DLLExport
|
||||
|
||||
%typemap(ctype) uint8_t const *data "unsigned char *"
|
||||
%typemap(imtype, out="System.IntPtr") uint8_t const *data "byte[]"
|
||||
%typemap(cstype) uint8_t const *data "byte[]"
|
||||
|
||||
%typemap(in) uint8_t const *data %{
|
||||
$1 = $input;
|
||||
%}
|
||||
|
||||
%typemap(csvarin) uint8_t const *data %{
|
||||
set {
|
||||
icsneocsharpPINVOKE.$csclazznamedata_set(swigCPtr, value);
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(csvarout, excode=SWIGEXCODE2) uint8_t const *data %{
|
||||
get {
|
||||
byte[] ret = new byte[this.length];
|
||||
System.IntPtr data = $imcall;
|
||||
System.Runtime.InteropServices.Marshal.Copy(data, ret, 0, (int)this.length)$excode;
|
||||
return ret;
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(ctype) char *str "char *"
|
||||
%typemap(imtype) char *str "System.Text.StringBuilder"
|
||||
%typemap(cstype) char *str "System.Text.StringBuilder"
|
||||
|
||||
%{
|
||||
#include "icsneo/icsneoc.h"
|
||||
%}
|
||||
|
||||
%apply int *INOUT {size_t *};
|
||||
|
||||
%ignore icsneo_addMessageCallback;
|
||||
%ignore icsneo_removeMessageCallback;
|
||||
%ignore icsneo_addEventCallback;
|
||||
%ignore icsneo_removeEventCallback;
|
||||
|
||||
%include "icsneo/icsneoc.h"
|
||||
%include "icsneo/device/neodevice.h"
|
||||
%include "icsneo/communication/message/neomessage.h"
|
||||
%include "icsneo/device/devicetype.h"
|
||||
%include "icsneo/api/version.h"
|
||||
%include "icsneo/api/event.h"
|
||||
%include "icsneo/communication/network.h"
|
||||
|
||||
%inline %{
|
||||
static neomessage_can_t* neomessage_can_t_cast(neomessage_t* msg) {
|
||||
return (neomessage_can_t*) msg;
|
||||
}
|
||||
|
||||
static neomessage_eth_t* neomessage_eth_t_cast(neomessage_t* msg) {
|
||||
return (neomessage_eth_t*) msg;
|
||||
}
|
||||
|
||||
static neomessage_t* from_can_neomessage_t_cast(neomessage_can_t* msg) {
|
||||
return (neomessage_t*) msg;
|
||||
}
|
||||
|
||||
static neomessage_t* from_eth_neomessage_t_cast(neomessage_eth_t* msg) {
|
||||
return (neomessage_t*) msg;
|
||||
}
|
||||
%}
|
||||
|
||||
%array_functions(neodevice_t, neodevice_t_array);
|
||||
%array_functions(neoevent_t, neoevent_t_array);
|
||||
%array_functions(neomessage_t, neomessage_t_array);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user