mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-09-20 07:58:39 +02:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6dd4456f9a |
@@ -15,4 +15,3 @@ third-party/concurrentqueue/tests
|
||||
examples/csharp/bin
|
||||
examples/csharp/obj
|
||||
test/system
|
||||
.env
|
||||
|
||||
+213
-81
@@ -1,10 +1,10 @@
|
||||
variables:
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
LIBICSNEO_ICSPB_REPO: https://gitlab-ci-token:${CI_JOB_TOKEN}@${LIBICSNEO_ICSPB_GIT}
|
||||
|
||||
stages:
|
||||
- build
|
||||
- unit_test
|
||||
- hardware_test
|
||||
- deploy
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -14,7 +14,7 @@ stages:
|
||||
build windows/x64:
|
||||
stage: build
|
||||
script:
|
||||
- cmd /C ci\build-windows64.bat
|
||||
- CMD.EXE /C ci\build-windows64.bat
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
@@ -38,7 +38,7 @@ unit_test windows/x64:
|
||||
build windows/x86:
|
||||
stage: build
|
||||
script:
|
||||
- cmd /C ci\build-windows32.bat
|
||||
- CMD.EXE /C ci\build-windows32.bat
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
@@ -68,9 +68,7 @@ unit_test windows/x86:
|
||||
script:
|
||||
- apt update -y
|
||||
- apt upgrade -y
|
||||
- apt install -y g++ ninja-build cmake libpcap-dev git ca-certificates
|
||||
- echo "$ICS_IPA_CA_CRT" >/usr/local/share/ca-certificates/ica-ipa-ca.crt
|
||||
- update-ca-certificates --fresh
|
||||
- apt install -y g++ ninja-build cmake libusb-1.0-0-dev libpcap-dev git
|
||||
- sh ci/build-posix.sh
|
||||
artifacts:
|
||||
when: always
|
||||
@@ -85,7 +83,7 @@ unit_test windows/x86:
|
||||
script:
|
||||
- apt update -y
|
||||
- apt upgrade -y
|
||||
- apt install -y libpcap-dev
|
||||
- apt install -y libusb-1.0-0-dev libpcap-dev
|
||||
- build/libicsneo-unit-tests
|
||||
tags:
|
||||
- linux-build
|
||||
@@ -96,9 +94,7 @@ unit_test windows/x86:
|
||||
script:
|
||||
- apt update -y
|
||||
- apt upgrade -y
|
||||
- apt install -y clang lld ninja-build cmake libpcap-dev git ca-certificates
|
||||
- echo "$ICS_IPA_CA_CRT" >/usr/local/share/ca-certificates/ica-ipa-ca.crt
|
||||
- update-ca-certificates --fresh
|
||||
- apt install -y clang lld ninja-build cmake libusb-1.0-0-dev libpcap-dev git
|
||||
- CC=clang CXX=clang++ LDFLAGS=-fuse-ld=lld sh ci/build-posix.sh
|
||||
artifacts:
|
||||
when: always
|
||||
@@ -113,59 +109,59 @@ unit_test windows/x86:
|
||||
script:
|
||||
- apt update -y
|
||||
- apt upgrade -y
|
||||
- apt install -y libpcap-dev
|
||||
- apt install -y libusb-1.0-0-dev libpcap-dev
|
||||
- build/libicsneo-unit-tests
|
||||
tags:
|
||||
- linux-build
|
||||
timeout: 5m
|
||||
|
||||
build linux/ubuntu/2404/amd64/gcc:
|
||||
build linux/ubuntu/2004/amd64/gcc:
|
||||
<<: *build_linux_ubuntu_gcc
|
||||
image: ubuntu:24.04
|
||||
image: ubuntu:20.04
|
||||
|
||||
unit_test linux/ubuntu/2404/amd64/gcc:
|
||||
unit_test linux/ubuntu/2004/amd64/gcc:
|
||||
<<: *test_linux_ubuntu_gcc
|
||||
image: ubuntu:24.04
|
||||
image: ubuntu:20.04
|
||||
dependencies:
|
||||
- build linux/ubuntu/2404/amd64/gcc
|
||||
- build linux/ubuntu/2004/amd64/gcc
|
||||
needs:
|
||||
- build linux/ubuntu/2404/amd64/gcc
|
||||
- build linux/ubuntu/2004/amd64/gcc
|
||||
|
||||
build linux/ubuntu/2404/amd64/clang:
|
||||
build linux/ubuntu/2004/amd64/clang:
|
||||
<<: *build_linux_ubuntu_clang
|
||||
image: ubuntu:24.04
|
||||
image: ubuntu:20.04
|
||||
|
||||
unit_test linux/ubuntu/2404/amd64/clang:
|
||||
unit_test linux/ubuntu/2004/amd64/clang:
|
||||
<<: *test_linux_ubuntu_clang
|
||||
image: ubuntu:24.04
|
||||
image: ubuntu:20.04
|
||||
dependencies:
|
||||
- build linux/ubuntu/2404/amd64/clang
|
||||
- build linux/ubuntu/2004/amd64/clang
|
||||
needs:
|
||||
- build linux/ubuntu/2404/amd64/clang
|
||||
- build linux/ubuntu/2004/amd64/clang
|
||||
|
||||
build linux/ubuntu/2604/amd64/gcc:
|
||||
build linux/ubuntu/2204/amd64/gcc:
|
||||
<<: *build_linux_ubuntu_gcc
|
||||
image: ubuntu:26.04
|
||||
image: ubuntu:22.04
|
||||
|
||||
unit_test linux/ubuntu/2604/amd64/gcc:
|
||||
unit_test linux/ubuntu/2204/amd64/gcc:
|
||||
<<: *test_linux_ubuntu_gcc
|
||||
image: ubuntu:26.04
|
||||
image: ubuntu:22.04
|
||||
dependencies:
|
||||
- build linux/ubuntu/2604/amd64/gcc
|
||||
- build linux/ubuntu/2204/amd64/gcc
|
||||
needs:
|
||||
- build linux/ubuntu/2604/amd64/gcc
|
||||
- build linux/ubuntu/2204/amd64/gcc
|
||||
|
||||
build linux/ubuntu/2604/amd64/clang:
|
||||
build linux/ubuntu/2204/amd64/clang:
|
||||
<<: *build_linux_ubuntu_clang
|
||||
image: ubuntu:26.04
|
||||
image: ubuntu:22.04
|
||||
|
||||
unit_test linux/ubuntu/2604/amd64/clang:
|
||||
unit_test linux/ubuntu/2204/amd64/clang:
|
||||
<<: *test_linux_ubuntu_clang
|
||||
image: ubuntu:26.04
|
||||
image: ubuntu:22.04
|
||||
dependencies:
|
||||
- build linux/ubuntu/2604/amd64/clang
|
||||
- build linux/ubuntu/2204/amd64/clang
|
||||
needs:
|
||||
- build linux/ubuntu/2604/amd64/clang
|
||||
- build linux/ubuntu/2204/amd64/clang
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Fedora
|
||||
@@ -180,9 +176,7 @@ unit_test linux/ubuntu/2604/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 git ca-certificates
|
||||
- echo "$ICS_IPA_CA_CRT" >/etc/pki/ca-trust/source/anchors/ica-ipa-ca.crt
|
||||
- update-ca-trust
|
||||
- dnf install -y g++ libpcap-devel cmake ninja-build libusb1-devel git
|
||||
- sh ci/build-posix.sh
|
||||
artifacts:
|
||||
when: always
|
||||
@@ -201,7 +195,7 @@ unit_test linux/ubuntu/2604/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
|
||||
- dnf install -y libpcap-devel libusb1-devel
|
||||
- build/libicsneo-unit-tests
|
||||
tags:
|
||||
- linux-build
|
||||
@@ -216,9 +210,7 @@ unit_test linux/ubuntu/2604/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 git ca-certificates
|
||||
- echo "$ICS_IPA_CA_CRT" >/etc/pki/ca-trust/source/anchors/ica-ipa-ca.crt
|
||||
- update-ca-trust
|
||||
- dnf install -y clang lld libpcap-devel cmake ninja-build libusb1-devel git
|
||||
- CC=clang CXX=clang++ LDFLAGS=-fuse-ld=lld sh ci/build-posix.sh
|
||||
artifacts:
|
||||
when: always
|
||||
@@ -237,59 +229,196 @@ unit_test linux/ubuntu/2604/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
|
||||
- dnf install -y libpcap-devel libusb1-devel
|
||||
- build/libicsneo-unit-tests
|
||||
tags:
|
||||
- linux-build
|
||||
timeout: 5m
|
||||
|
||||
build linux/fedora/43/amd64/gcc:
|
||||
build linux/fedora/37/amd64/gcc:
|
||||
<<: *build_linux_fedora_gcc
|
||||
image: fedora:43
|
||||
image: fedora:37
|
||||
|
||||
unit_test linux/fedora/43/amd64/gcc:
|
||||
unit_test linux/fedora/37/amd64/gcc:
|
||||
<<: *test_linux_fedora_gcc
|
||||
image: fedora:43
|
||||
image: fedora:37
|
||||
dependencies:
|
||||
- build linux/fedora/43/amd64/gcc
|
||||
- build linux/fedora/37/amd64/gcc
|
||||
needs:
|
||||
- build linux/fedora/43/amd64/gcc
|
||||
- build linux/fedora/37/amd64/gcc
|
||||
|
||||
build linux/fedora/43/amd64/clang:
|
||||
build linux/fedora/37/amd64/clang:
|
||||
<<: *build_linux_fedora_clang
|
||||
image: fedora:43
|
||||
image: fedora:37
|
||||
|
||||
unit_test linux/fedora/43/amd64/clang:
|
||||
unit_test linux/fedora/37/amd64/clang:
|
||||
<<: *test_linux_fedora_clang
|
||||
image: fedora:43
|
||||
image: fedora:37
|
||||
dependencies:
|
||||
- build linux/fedora/43/amd64/clang
|
||||
- build linux/fedora/37/amd64/clang
|
||||
needs:
|
||||
- build linux/fedora/43/amd64/clang
|
||||
- build linux/fedora/37/amd64/clang
|
||||
|
||||
build linux/fedora/44/amd64/gcc:
|
||||
build linux/fedora/38/amd64/gcc:
|
||||
<<: *build_linux_fedora_gcc
|
||||
image: fedora:44
|
||||
image: fedora:38
|
||||
|
||||
unit_test linux/fedora/44/amd64/gcc:
|
||||
unit_test linux/fedora/38/amd64/gcc:
|
||||
<<: *test_linux_fedora_gcc
|
||||
image: fedora:44
|
||||
image: fedora:38
|
||||
dependencies:
|
||||
- build linux/fedora/44/amd64/gcc
|
||||
- build linux/fedora/38/amd64/gcc
|
||||
needs:
|
||||
- build linux/fedora/44/amd64/gcc
|
||||
- build linux/fedora/38/amd64/gcc
|
||||
|
||||
build linux/fedora/44/amd64/clang:
|
||||
build linux/fedora/38/amd64/clang:
|
||||
<<: *build_linux_fedora_clang
|
||||
image: fedora:44
|
||||
image: fedora:38
|
||||
|
||||
unit_test linux/fedora/44/amd64/clang:
|
||||
unit_test linux/fedora/38/amd64/clang:
|
||||
<<: *test_linux_fedora_clang
|
||||
image: fedora:44
|
||||
image: fedora:38
|
||||
dependencies:
|
||||
- build linux/fedora/44/amd64/clang
|
||||
- build linux/fedora/38/amd64/clang
|
||||
needs:
|
||||
- build linux/fedora/44/amd64/clang
|
||||
- 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
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Python Module
|
||||
@@ -298,14 +427,22 @@ unit_test linux/fedora/44/amd64/clang:
|
||||
build python/linux/amd64:
|
||||
stage: build
|
||||
tags:
|
||||
- linux-native-amd64
|
||||
- linux-build
|
||||
image: python:3.12
|
||||
services:
|
||||
- name: docker:dind
|
||||
entrypoint: ["env", "-u", "DOCKER_HOST"]
|
||||
command: ["dockerd-entrypoint.sh"]
|
||||
variables:
|
||||
CIBW_BEFORE_ALL: sh ci/bootstrap-cibuildwheel.sh && sh ci/bootstrap-libpcap.sh
|
||||
CIBW_BEFORE_ALL: yum install -y flex && sh ci/bootstrap-libpcap.sh && sh ci/bootstrap-libusb.sh
|
||||
CIBW_BUILD: "*manylinux*" # no musl
|
||||
CIBW_ARCHS: x86_64
|
||||
CIBW_ENVIRONMENT: PCAP_ROOT=/project/libpcap/install
|
||||
SKBUILD_CMAKE_DEFINE: ICSPB_BOOTSTRAP_DIR=/project/icspb
|
||||
DOCKER_HOST: unix:///var/run/docker.sock
|
||||
DOCKER_DRIVER: overlay2
|
||||
DOCKER_TLS_CERTDIR: ""
|
||||
CIBW_ENVIRONMENT: CMAKE_PREFIX_PATH=/project/libpcap/install:/project/libusb/install
|
||||
script:
|
||||
- curl -sSL https://get.docker.com/ | sh
|
||||
- sh ci/build-wheel-posix.sh
|
||||
artifacts:
|
||||
paths:
|
||||
@@ -316,11 +453,10 @@ build python/linux/arm64:
|
||||
tags:
|
||||
- arm64-linux-build
|
||||
variables:
|
||||
CIBW_BEFORE_ALL: sh ci/bootstrap-cibuildwheel.sh && sh ci/bootstrap-libpcap.sh
|
||||
CIBW_BEFORE_ALL: yum install -y flex && sh ci/bootstrap-libpcap.sh && sh ci/bootstrap-libusb.sh
|
||||
CIBW_BUILD: "*manylinux*" # no musl
|
||||
CIBW_ARCHS: aarch64
|
||||
CIBW_ENVIRONMENT: PCAP_ROOT=/project/libpcap/install
|
||||
SKBUILD_CMAKE_DEFINE: ICSPB_BOOTSTRAP_DIR=/project/icspb
|
||||
CIBW_ENVIRONMENT: CMAKE_PREFIX_PATH=/project/libpcap/install:/project/libusb/install
|
||||
script:
|
||||
- sh ci/build-wheel-posix.sh
|
||||
artifacts:
|
||||
@@ -332,10 +468,9 @@ build python/macos:
|
||||
tags:
|
||||
- macos-arm64
|
||||
variables:
|
||||
CIBW_BEFORE_ALL: sh ci/bootstrap-libpcap.sh
|
||||
CIBW_BEFORE_ALL: sh ci/bootstrap-libpcap.sh && sh ci/bootstrap-libusb.sh
|
||||
CIBW_ARCHS: arm64
|
||||
CIBW_ENVIRONMENT: PCAP_ROOT=$CI_PROJECT_DIR/libpcap/install
|
||||
SKBUILD_CMAKE_DEFINE: ICSPB_BOOTSTRAP_DIR=$CI_PROJECT_DIR/icspb
|
||||
CIBW_ENVIRONMENT: CMAKE_PREFIX_PATH=$CI_PROJECT_DIR/libpcap/install:$CI_PROJECT_DIR/libusb/install
|
||||
MACOSX_DEPLOYMENT_TARGET: 10.14
|
||||
script:
|
||||
- sh ci/build-wheel-posix.sh
|
||||
@@ -350,7 +485,6 @@ build python/windows:
|
||||
variables:
|
||||
CIBW_ARCHS: AMD64
|
||||
CIBW_ENVIRONMENT: CMAKE_GENERATOR=Ninja
|
||||
SKBUILD_CMAKE_DEFINE: ICSPB_BOOTSTRAP_DIR=$CI_PROJECT_DIR/icspb
|
||||
script:
|
||||
- cmd /c ci\build-wheel-windows.bat
|
||||
artifacts:
|
||||
@@ -364,7 +498,7 @@ deploy python/pypi:
|
||||
TWINE_PASSWORD: $PYPI_TOKEN
|
||||
tags:
|
||||
- linux-build
|
||||
image: python:3.13
|
||||
image: python:3.12
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
||||
script:
|
||||
@@ -388,8 +522,6 @@ push github:
|
||||
image: alpine:latest
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
||||
when: delayed
|
||||
start_in: 10 minutes
|
||||
dependencies:
|
||||
- deploy python/pypi
|
||||
needs:
|
||||
|
||||
+21
-5
@@ -3,8 +3,24 @@ SUBSYSTEM=="usb", ATTRS{idVendor}=="093c", GROUP="users", MODE="0666"
|
||||
KERNEL=="ttyUSB?", ATTRS{idVendor}=="093c", GROUP="users", MODE="0666"
|
||||
KERNEL=="ttyACM?", ATTRS{idVendor}=="093c", GROUP="users", MODE="0666"
|
||||
|
||||
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="093c", KERNEL=="ttyUSB*", \
|
||||
RUN+="/bin/sh -c 'echo $id:1.0>/sys/bus/usb/drivers/ftdi_sio/unbind'"
|
||||
|
||||
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="093c", DRIVER=="usbhid", \
|
||||
RUN+="/bin/sh -c 'echo $id:1.0>/sys/bus/usb/drivers/usbhid/unbind'"
|
||||
# neoVI ION/PLASMA PIDs are not in the latest ftdi_sio driver so lets make a
|
||||
# rule to add it when we see a new unclaimed device.
|
||||
# PLASMA = 0x0801, ION = 0x0901
|
||||
ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_interface", \
|
||||
ATTRS{idVendor}=="093c", ATTRS{idProduct}=="0801", \
|
||||
DRIVER=="", \
|
||||
RUN+="/sbin/modprobe -b ftdi_sio"
|
||||
ACTION=="add", SUBSYSTEM=="drivers", \
|
||||
ENV{DEVPATH}=="/bus/usb-serial/drivers/ftdi_sio", \
|
||||
ATTR{new_id}="093c 0801"
|
||||
ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_interface", \
|
||||
ATTRS{idVendor}=="093c", ATTRS{idProduct}=="0901", \
|
||||
DRIVER=="", \
|
||||
RUN+="/sbin/modprobe -b ftdi_sio"
|
||||
ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_interface", \
|
||||
ATTRS{idVendor}=="093c", ATTRS{idProduct}=="1000", \
|
||||
DRIVER=="", \
|
||||
RUN+="/sbin/modprobe -b ftdi_sio"
|
||||
ACTION=="add", SUBSYSTEM=="drivers", \
|
||||
ENV{DEVPATH}=="/bus/usb-serial/drivers/ftdi_sio", \
|
||||
ATTR{new_id}="093c 0901"
|
||||
|
||||
+141
-126
@@ -1,43 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
function(git_tag_version VERSION_RESULT)
|
||||
set(${VERSION_RESULT} "0.0.0.0" PARENT_SCOPE)
|
||||
find_package(Git)
|
||||
if(NOT Git_FOUND)
|
||||
return()
|
||||
endif()
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE LAST_TAG
|
||||
RESULT_VARIABLE RESULT
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
if(NOT RESULT EQUAL 0)
|
||||
return()
|
||||
endif()
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} rev-list ${LAST_TAG}..HEAD --count
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE COMMIT_COUNT_SINCE_TAG
|
||||
RESULT_VARIABLE RESULT
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
if(NOT RESULT EQUAL 0)
|
||||
return()
|
||||
endif()
|
||||
set(${VERSION_RESULT} "${LAST_TAG}.${COMMIT_COUNT_SINCE_TAG}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
git_tag_version(LIBICSNEO_VERSION)
|
||||
|
||||
if(LIBICSNEO_VERSION STREQUAL "0.0.0.0")
|
||||
message(WARNING "Unable to parse version from git history")
|
||||
endif()
|
||||
|
||||
project(libicsneo VERSION ${LIBICSNEO_VERSION})
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(libicsneo VERSION 0.3.0)
|
||||
|
||||
cmake_policy(SET CMP0074 NEW)
|
||||
if(POLICY CMP0135)
|
||||
@@ -45,6 +7,7 @@ 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)
|
||||
@@ -62,13 +25,16 @@ 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_DXX "Enable devices which communicate over D2XX/D3XX via libredxx" ON)
|
||||
option(LIBICSNEO_ENABLE_FTD3XX "Enable devices which communicate over USB FTD3XX" ON)
|
||||
|
||||
option(LIBICSNEO_ENABLE_BINDINGS_PYTHON "Enable Python library" OFF)
|
||||
option(LIBICSNEO_ENABLE_BINDINGS_RUST "Enable Rust library" OFF)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
|
||||
if(NOT CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
endif()
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
@@ -76,13 +42,17 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
# Enable Warnings
|
||||
if(MSVC)
|
||||
set(LIBICSNEO_COMPILER_WARNINGS /W4)
|
||||
# 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()
|
||||
# http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0618r0.html
|
||||
# Still supported until a suitable replacement is standardized
|
||||
add_definitions(-D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
|
||||
add_definitions(-D_ITERATOR_DEBUG_LEVEL=0)
|
||||
else() #if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(LIBICSNEO_COMPILER_WARNINGS -Wall -Wno-switch -Wno-unknown-pragmas)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-switch -Wno-unknown-pragmas")
|
||||
endif()
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
@@ -144,7 +114,6 @@ endif()
|
||||
|
||||
if(WIN32)
|
||||
set(PLATFORM_SRC
|
||||
platform/windows/strings.cpp
|
||||
platform/windows/registry.cpp
|
||||
)
|
||||
|
||||
@@ -155,9 +124,9 @@ if(WIN32)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_ENABLE_CDCACM)
|
||||
if(LIBICSNEO_ENABLE_CDCACM OR LIBICSNEO_ENABLE_FTDI)
|
||||
list(APPEND PLATFORM_SRC
|
||||
platform/windows/cdcacm.cpp
|
||||
platform/windows/vcp.cpp
|
||||
)
|
||||
endif()
|
||||
else() # Darwin or Linux
|
||||
@@ -175,6 +144,12 @@ 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
|
||||
@@ -198,9 +173,51 @@ else() # Darwin or Linux
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_ENABLE_DXX)
|
||||
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)
|
||||
list(APPEND PLATFORM_SRC
|
||||
platform/dxx.cpp
|
||||
platform/ftd3xx.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -210,6 +227,10 @@ if(LIBICSNEO_ENABLE_TCP)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
|
||||
# Extensions
|
||||
set(LIBICSNEO_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
foreach(EXT_PATH ${LIBICSNEO_EXTENSION_DIRS})
|
||||
@@ -227,18 +248,12 @@ 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/allmacaddressesmessage.cpp
|
||||
communication/message/ethernetstatusmessage.cpp
|
||||
communication/message/networkmutexmessage.cpp
|
||||
communication/message/clientidmessage.cpp
|
||||
communication/message/transmitmessage.cpp
|
||||
communication/packet/flexraypacket.cpp
|
||||
communication/packet/canpacket.cpp
|
||||
communication/packet/a2bpacket.cpp
|
||||
communication/packet/spipacket.cpp
|
||||
communication/packet/ethernetpacket.cpp
|
||||
communication/packet/versionpacket.cpp
|
||||
communication/packet/iso9141packet.cpp
|
||||
@@ -262,9 +277,7 @@ set(SRC_FILES
|
||||
communication/communication.cpp
|
||||
communication/driver.cpp
|
||||
communication/livedata.cpp
|
||||
core/ringbuffer.cpp
|
||||
core/crc32.cpp
|
||||
core/macseccfg.cpp
|
||||
communication/ringbuffer.cpp
|
||||
device/extensions/flexray/extension.cpp
|
||||
device/extensions/flexray/controller.cpp
|
||||
device/idevicesettings.cpp
|
||||
@@ -278,7 +291,6 @@ 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
|
||||
@@ -295,7 +307,6 @@ set(SRC_FILES
|
||||
disk/vsa/vsa0f.cpp
|
||||
disk/vsa/vsa6a.cpp
|
||||
disk/vsa/vsaparser.cpp
|
||||
platform/servd.cpp
|
||||
${PLATFORM_SRC}
|
||||
)
|
||||
|
||||
@@ -357,10 +368,9 @@ target_include_directories(icsneocpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${LIBICSNEO_EXTENSION_INCLUDE_PATHS}
|
||||
)
|
||||
target_link_libraries(icsneocpp PUBLIC Threads::Threads $<$<BOOL:${WIN32}>:ws2_32 iphlpapi>)
|
||||
target_link_libraries(icsneocpp PUBLIC Threads::Threads)
|
||||
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)
|
||||
target_compile_options(icsneocpp PRIVATE ${LIBICSNEO_COMPILER_WARNINGS})
|
||||
message("Loaded extensions: " ${LIBICSNEO_EXTENSION_TARGETS})
|
||||
target_link_libraries(icsneocpp PUBLIC ${LIBICSNEO_EXTENSION_TARGETS})
|
||||
if(LIBICSNEO_ENABLE_FIRMIO)
|
||||
@@ -371,15 +381,13 @@ if(LIBICSNEO_ENABLE_RAW_ETHERNET)
|
||||
endif()
|
||||
if(LIBICSNEO_ENABLE_CDCACM)
|
||||
target_compile_definitions(icsneocpp PRIVATE ICSNEO_ENABLE_CDCACM)
|
||||
if(APPLE)
|
||||
find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation REQUIRED)
|
||||
find_library(IO_KIT_FRAMEWORK IOKit REQUIRED)
|
||||
target_link_libraries(icsneocpp PRIVATE ${CORE_FOUNDATION_FRAMEWORK} ${IO_KIT_FRAMEWORK})
|
||||
endif()
|
||||
endif()
|
||||
if(LIBICSNEO_ENABLE_DXX)
|
||||
target_compile_definitions(icsneocpp PRIVATE ICSNEO_ENABLE_DXX)
|
||||
target_link_libraries(icsneocpp PRIVATE libredxx::libredxx)
|
||||
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)
|
||||
endif()
|
||||
if(LIBICSNEO_ENABLE_TCP)
|
||||
target_compile_definitions(icsneocpp PRIVATE ICSNEO_ENABLE_TCP)
|
||||
@@ -393,25 +401,35 @@ add_subdirectory(third-party/fatfs)
|
||||
set_property(TARGET fatfs PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
target_link_libraries(icsneocpp PRIVATE fatfs)
|
||||
|
||||
# dxx
|
||||
if(LIBICSNEO_ENABLE_DXX)
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(libredxx
|
||||
GIT_REPOSITORY https://github.com/Zeranoe/libredxx.git
|
||||
GIT_TAG e823a96c39a64ab41b7d1632dbe8f86bb854df83
|
||||
)
|
||||
set(LIBREDXX_DISABLE_INSTALL ON)
|
||||
FetchContent_MakeAvailable(libredxx)
|
||||
endif()
|
||||
# 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)
|
||||
|
||||
# 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)
|
||||
add_definitions(-DWPCAP -DHAVE_REMOTE -DWIN32_LEAN_AND_MEAN)
|
||||
else()
|
||||
target_include_directories(icsneocpp PUBLIC AFTER ${LIBICSNEO_NPCAP_INCLUDE_DIR})
|
||||
add_definitions(-DNPCAP -DWIN32_LEAN_AND_MEAN)
|
||||
endif()
|
||||
else()
|
||||
find_package(PCAP REQUIRED)
|
||||
@@ -420,21 +438,6 @@ if(LIBICSNEO_ENABLE_RAW_ETHERNET)
|
||||
endif(WIN32)
|
||||
endif(LIBICSNEO_ENABLE_RAW_ETHERNET)
|
||||
|
||||
# protobuf
|
||||
if(DEFINED ENV{LIBICSNEO_ICSPB_REPO})
|
||||
set(LIBICSNEO_ICSPB_REPO "$ENV{LIBICSNEO_ICSPB_REPO}")
|
||||
endif()
|
||||
if(NOT LIBICSNEO_ICSPB_REPO)
|
||||
set(LIBICSNEO_ICSPB_REPO https://github.com/intrepidcs/icspb.git)
|
||||
endif()
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(icspb
|
||||
GIT_REPOSITORY ${LIBICSNEO_ICSPB_REPO}
|
||||
GIT_TAG 3339fa6b83a6b3e7704d41f5c2f2175cfc761a1f
|
||||
)
|
||||
FetchContent_MakeAvailable(icspb)
|
||||
target_link_libraries(icsneocpp PRIVATE icspb::icspb)
|
||||
|
||||
if(LIBICSNEO_BUILD_ICSNEOC)
|
||||
add_library(icsneoc SHARED api/icsneoc/icsneoc.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated/icsneoc/version.rc)
|
||||
target_include_directories(icsneoc
|
||||
@@ -446,7 +449,6 @@ if(LIBICSNEO_BUILD_ICSNEOC)
|
||||
)
|
||||
target_link_libraries(icsneoc PRIVATE icsneocpp)
|
||||
target_compile_features(icsneoc PRIVATE cxx_auto_type cxx_constexpr cxx_lambdas cxx_nullptr cxx_range_for cxx_rvalue_references cxx_sizeof_member cxx_strong_enums)
|
||||
target_compile_options(icsneoc PRIVATE ${LIBICSNEO_COMPILER_WARNINGS})
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_ICSNEOC_STATIC)
|
||||
@@ -461,11 +463,10 @@ if(LIBICSNEO_BUILD_ICSNEOC_STATIC)
|
||||
target_link_libraries(icsneoc-static PUBLIC icsneocpp)
|
||||
target_compile_features(icsneoc-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(icsneoc-static PUBLIC ICSNEOC_BUILD_STATIC)
|
||||
target_compile_options(icsneoc-static PRIVATE ${LIBICSNEO_COMPILER_WARNINGS})
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_ICSNEOC2)
|
||||
add_library(icsneoc2 SHARED api/icsneoc2/icsneoc2.cpp api/icsneoc2/icsneoc2settings.cpp api/icsneoc2/icsneoc2messages.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated/icsneoc2/version.rc)
|
||||
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>
|
||||
@@ -474,15 +475,20 @@ if(LIBICSNEO_BUILD_ICSNEOC2)
|
||||
${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_options(icsneoc2 PRIVATE ${LIBICSNEO_COMPILER_WARNINGS})
|
||||
if(WIN32)
|
||||
set_target_properties(icsneoc2 PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
endif()
|
||||
target_compile_definitions(icsneoc2 PUBLIC ICSNEOC2_BUILD_DYNAMIC)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_ICSNEOC2_STATIC)
|
||||
add_library(icsneoc2-static STATIC api/icsneoc2/icsneoc2.cpp api/icsneoc2/icsneoc2settings.cpp api/icsneoc2/icsneoc2messages.cpp)
|
||||
add_library(icsneoc2-static STATIC api/icsneoc2/icsneoc2.cpp)
|
||||
target_include_directories(icsneoc2-static
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
@@ -493,7 +499,6 @@ if(LIBICSNEO_BUILD_ICSNEOC2_STATIC)
|
||||
target_link_libraries(icsneoc2-static PUBLIC icsneocpp)
|
||||
target_compile_features(icsneoc2-static PUBLIC cxx_auto_type cxx_constexpr cxx_lambdas cxx_nullptr cxx_range_for cxx_rvalue_references cxx_sizeof_member cxx_strong_enums)
|
||||
target_compile_definitions(icsneoc2-static PUBLIC ICSNEOC2_BUILD_STATIC)
|
||||
target_compile_options(icsneoc2-static PRIVATE ${LIBICSNEO_COMPILER_WARNINGS})
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_ICSNEOLEGACY)
|
||||
@@ -512,7 +517,6 @@ if(LIBICSNEO_BUILD_ICSNEOLEGACY)
|
||||
)
|
||||
target_link_libraries(icsneolegacy PRIVATE icsneocpp)
|
||||
target_compile_features(icsneolegacy PRIVATE cxx_auto_type cxx_constexpr cxx_lambdas cxx_nullptr cxx_range_for cxx_rvalue_references cxx_sizeof_member cxx_strong_enums)
|
||||
target_compile_options(icsneolegacy PRIVATE ${LIBICSNEO_COMPILER_WARNINGS})
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_BUILD_ICSNEOLEGACY_STATIC)
|
||||
@@ -532,24 +536,23 @@ if(LIBICSNEO_BUILD_ICSNEOLEGACY_STATIC)
|
||||
target_link_libraries(icsneolegacy-static PUBLIC icsneocpp)
|
||||
target_compile_features(icsneolegacy-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(icsneolegacy-static PUBLIC ICSNEOC_BUILD_STATIC)
|
||||
target_compile_options(icsneolegacy-static PRIVATE ${LIBICSNEO_COMPILER_WARNINGS})
|
||||
endif()
|
||||
|
||||
add_subdirectory(bindings)
|
||||
|
||||
if(LIBICSNEO_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
|
||||
# googletest
|
||||
if(LIBICSNEO_BUILD_UNIT_TESTS)
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(googletest
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
GIT_TAG 6986c2b575f77135401a4e1c65a7a42f20e18fef
|
||||
)
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
include(GoogleTest)
|
||||
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()
|
||||
|
||||
add_executable(libicsneo-unit-tests
|
||||
test/unit/main.cpp
|
||||
@@ -565,12 +568,8 @@ if(LIBICSNEO_BUILD_UNIT_TESTS)
|
||||
test/unit/ringbuffertest.cpp
|
||||
test/unit/apperrordecodertest.cpp
|
||||
test/unit/icsneoc2.cpp
|
||||
test/unit/windowsstrings.cpp
|
||||
test/unit/periodictest.cpp
|
||||
)
|
||||
|
||||
target_compile_options(libicsneo-unit-tests PRIVATE ${LIBICSNEO_COMPILER_WARNINGS})
|
||||
|
||||
target_link_libraries(libicsneo-unit-tests gtest gtest_main)
|
||||
target_link_libraries(libicsneo-unit-tests icsneocpp)
|
||||
target_link_libraries(libicsneo-unit-tests icsneoc2-static)
|
||||
@@ -579,9 +578,25 @@ if(LIBICSNEO_BUILD_UNIT_TESTS)
|
||||
|
||||
enable_testing()
|
||||
|
||||
gtest_discover_tests(libicsneo-unit-tests TEST_PREFIX "unit/" PROPERTIES LABELS "unit")
|
||||
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)
|
||||
include(CPack)
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2018-2026 Intrepid Control Systems, Inc.
|
||||
Copyright (c) 2018-2025 Intrepid Control Systems, Inc.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
@@ -4,20 +4,11 @@ libicsneo is the [Intrepid Control Systems](https://intrepidcs.com/) device
|
||||
communication library. Installation and usage documentation can be found within
|
||||
each of the respective APIs.
|
||||
|
||||
## Installation
|
||||
|
||||
libicsneo relies on Servd, IntrepidCS's device communication server.
|
||||
|
||||
Servd can be installed for all platforms from https://cdn.intrepidcs.net/servd/.
|
||||
|
||||
Instructions for installing each API can be found in its respective documentation.
|
||||
|
||||
## Documentation
|
||||
|
||||
- [C++](https://libicsneo.readthedocs.io/en/latest/icsneocpp/)
|
||||
- [Python](https://libicsneo.readthedocs.io/en/latest/icsneopy/)
|
||||
- [C](https://libicsneo.readthedocs.io/en/latest/icsneoc/) (deprecated, use C2)
|
||||
- [C2](https://libicsneo.readthedocs.io/en/latest/icsneoc2/)
|
||||
- [C](https://libicsneo.readthedocs.io/en/latest/icsneoc/)
|
||||
|
||||
## Hardware Support
|
||||
|
||||
@@ -32,11 +23,8 @@ Instructions for installing each API can be found in its respective documentatio
|
||||
- RAD-A2B
|
||||
- RAD-Comet 2
|
||||
- RAD-Comet 3
|
||||
- RAD-Epsilon
|
||||
- RAD-EpsilonXL
|
||||
- RAD-Galaxy
|
||||
- RAD-Galaxy 2
|
||||
- RAD-Gemini
|
||||
- RAD-Gigastar
|
||||
- RAD-Gigastar 2
|
||||
- RAD-Moon 2
|
||||
@@ -45,7 +33,7 @@ Instructions for installing each API can be found in its respective documentatio
|
||||
- RAD-Pluto
|
||||
- RAD-Star 2
|
||||
- RAD-SuperMoon
|
||||
- RAD-wBMS
|
||||
- RADComet
|
||||
- ValueCAN 3
|
||||
- ValueCAN 4
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#define VER_FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@
|
||||
#define VER_FILEVERSION_STR "v@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@@BUILD_METADATA_PLUS@ @BUILD_GIT_INFO@"
|
||||
|
||||
#define VER_PRODUCTVERSION VER_FILEVERSION
|
||||
#define VER_PRODUCTVERSION_STR VER_FILEVERSION_STR
|
||||
|
||||
#ifndef DEBUG
|
||||
#define VER_DEBUG 0
|
||||
#else
|
||||
#define VER_DEBUG VS_FF_DEBUG
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION VER_FILEVERSION
|
||||
PRODUCTVERSION VER_PRODUCTVERSION
|
||||
FILEFLAGSMASK (VS_FF_DEBUG)
|
||||
FILEFLAGS (VER_DEBUG)
|
||||
FILEOS VOS__WINDOWS32
|
||||
FILETYPE VFT_DLL
|
||||
FILESUBTYPE VFT2_UNKNOWN
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904E4"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Intrepid Control Systems, Inc."
|
||||
VALUE "FileDescription", "Intrepid Control Systems Open Device Communication C API"
|
||||
VALUE "FileVersion", VER_FILEVERSION_STR
|
||||
VALUE "InternalName", "icsneo.dll"
|
||||
VALUE "LegalCopyright", "Intrepid Control Systems, Inc. (C) 2018-2024"
|
||||
VALUE "OriginalFilename", "icsneo.dll"
|
||||
VALUE "ProductName", "libicsneo"
|
||||
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
|
||||
END
|
||||
END
|
||||
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
/* The following line should only be modified for localized versions. */
|
||||
/* It consists of any number of WORD,WORD pairs, with each pair */
|
||||
/* describing a language,codepage combination supported by the file. */
|
||||
/* */
|
||||
/* For example, a file might have values "0x409,1252" indicating that it */
|
||||
/* supports English language (0x409) in the Windows ANSI codepage (1252). */
|
||||
|
||||
VALUE "Translation", 0x409, 1252
|
||||
|
||||
END
|
||||
END
|
||||
+2
-32
@@ -462,7 +462,7 @@ bool icsneo_transmit(const neodevice_t* device, const neomessage_t* message) {
|
||||
if(!icsneo_isValidNeoDevice(device))
|
||||
return false;
|
||||
|
||||
if(auto frame = std::dynamic_pointer_cast<icsneo::Frame>(CreateMessageFromNeoMessage(message)))
|
||||
if(auto frame = std::dynamic_pointer_cast<icsneo::BusMessage>(CreateMessageFromNeoMessage(message)))
|
||||
return device->device->transmit(frame);
|
||||
|
||||
return false;
|
||||
@@ -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<RawMessage>(msg);
|
||||
auto rawMessage = std::static_pointer_cast<InternalMessage>(msg);
|
||||
if(!rawMessage || (rawMessage->network.getNetID() != Network::NetID::DeviceStatus))
|
||||
return false;
|
||||
|
||||
@@ -757,33 +757,3 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ BEGIN
|
||||
VALUE "FileDescription", "Intrepid Control Systems Open Device Communication C API"
|
||||
VALUE "FileVersion", VER_FILEVERSION_STR
|
||||
VALUE "InternalName", "icsneoc.dll"
|
||||
VALUE "LegalCopyright", "Intrepid Control Systems, Inc. (C) 2018-2026"
|
||||
VALUE "LegalCopyright", "Intrepid Control Systems, Inc. (C) 2018-2025"
|
||||
VALUE "OriginalFilename", "icsneoc.dll"
|
||||
VALUE "ProductName", "libicsneo"
|
||||
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
|
||||
|
||||
+1402
-1464
File diff suppressed because it is too large
Load Diff
@@ -1,74 +0,0 @@
|
||||
// This header is for internal icsneoc2 use only, it should not be included by users of the API.
|
||||
#pragma once
|
||||
|
||||
#include "icsneo/icsneoc2.h"
|
||||
#include "icsneo/device/device.h"
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/communication/message/scriptstatusmessage.h"
|
||||
#include "icsneo/api/event.h"
|
||||
#include "icsneo/disk/diskdetails.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
typedef struct icsneoc2_supported_device_t {
|
||||
DeviceType device_type;
|
||||
icsneoc2_supported_device_t* next;
|
||||
} icsneoc2_supported_device_t;
|
||||
|
||||
typedef struct icsneoc2_message_t {
|
||||
std::shared_ptr<Message> message;
|
||||
} icsneoc2_message_t;
|
||||
|
||||
typedef struct icsneoc2_event_t {
|
||||
APIEvent event;
|
||||
} icsneoc2_event_t;
|
||||
|
||||
typedef struct icsneoc2_device_info_t {
|
||||
std::shared_ptr<Device> device;
|
||||
icsneoc2_device_info_t* next;
|
||||
} icsneoc2_device_info_t;
|
||||
|
||||
typedef struct icsneoc2_device_t {
|
||||
std::shared_ptr<Device> device;
|
||||
} icsneoc2_device_t;
|
||||
|
||||
typedef struct icsneoc2_disk_details_t {
|
||||
std::shared_ptr<DiskDetails> details;
|
||||
} icsneoc2_disk_details_t;
|
||||
|
||||
typedef struct icsneoc2_script_status_t {
|
||||
std::shared_ptr<ScriptStatusMessage> status;
|
||||
} icsneoc2_script_status_t;
|
||||
|
||||
typedef struct icsneoc2_chip_versions_t {
|
||||
VersionReport version_report;
|
||||
icsneoc2_chip_versions_t* next;
|
||||
} icsneoc2_chip_versions_t;
|
||||
|
||||
typedef struct icsneoc2_termination_group_t {
|
||||
std::vector<icsneoc2_netid_t> netids;
|
||||
icsneoc2_termination_group_t* next;
|
||||
} icsneoc2_termination_group_t;
|
||||
|
||||
typedef struct icsneoc2_mac_addr_entry_t {
|
||||
uint16_t network_id;
|
||||
uint8_t address[ICSNEO_MAC_ADDRESS_LEN];
|
||||
icsneoc2_mac_addr_entry_t* next;
|
||||
} icsneoc2_mac_addr_entry_t;
|
||||
|
||||
/**
|
||||
* Safely copies a std::string to a char array.
|
||||
*
|
||||
* @param dest The buffer to copy the string into
|
||||
* @param dest_size* The size of the buffer. Will be modified to the length of the string without the null terminator.
|
||||
* @param src The string to copy
|
||||
*
|
||||
* @return true if the string was successfully copied, false otherwise
|
||||
*
|
||||
* @note This function always null terminates the buffer, even if the string is too long.
|
||||
* In the case of truncation, dest_size will reflect the truncated length (not including the null terminator).
|
||||
*/
|
||||
bool safe_str_copy(char* dest, size_t* dest_size, std::string_view src);
|
||||
@@ -1,710 +0,0 @@
|
||||
#include "icsneo/icsneoc2messages.h" // TODO: Remove this after the complete refactor
|
||||
|
||||
#include "icsneo/icsneoc2.h"
|
||||
#include "icsneoc2_internal.h"
|
||||
|
||||
#include "icsneo/icsneocpp.h"
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/communication/message/canmessage.h"
|
||||
#include "icsneo/communication/message/canerrormessage.h"
|
||||
#include "icsneo/communication/message/apperrormessage.h"
|
||||
#include "icsneo/communication/message/linmessage.h"
|
||||
#include "icsneo/communication/message/ethernetmessage.h"
|
||||
#include "icsneo/communication/message/ethernetstatusmessage.h"
|
||||
#include "icsneo/communication/packet/canpacket.h"
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_valid(icsneoc2_message_t* message, bool* is_valid) {
|
||||
if(!message || !is_valid) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
|
||||
*is_valid = (bool)message->message;
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_transmit(icsneoc2_message_t* message, bool* value) {
|
||||
if(!message || !value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
// We can static cast here because we are relying on the type being correct at this point
|
||||
auto frame = std::dynamic_pointer_cast<Frame>(message->message);
|
||||
if(!frame) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
*value = frame->transmitted;
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_error(icsneoc2_message_t* message, bool* value) {
|
||||
if(!message || !value) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto frame = std::dynamic_pointer_cast<Frame>(message->message);
|
||||
if(!frame) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
*value = frame->error;
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_netid_get(icsneoc2_message_t* message, icsneoc2_netid_t* netid) {
|
||||
if(!message || !netid) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto raw = std::dynamic_pointer_cast<RawMessage>(message->message);
|
||||
if(!raw) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
*netid = static_cast<icsneoc2_netid_t>(raw->network.getNetID());
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_netid_name_get(icsneoc2_netid_t netid, char* value, size_t* value_length) {
|
||||
if(!value || !value_length) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto netid_str = std::string(Network::GetNetIDString(static_cast<Network::NetID>(netid), true));
|
||||
// Copy the string into value
|
||||
return safe_str_copy(value, value_length, netid_str) ? icsneoc2_error_success : icsneoc2_error_string_copy_failed;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_netid_network_type_get(icsneoc2_netid_t netid, icsneoc2_network_type_t* network_type) {
|
||||
if(!network_type) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*network_type = static_cast<icsneoc2_network_type_t>(Network::GetTypeOfNetID(static_cast<Network::NetID>(netid), true));
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_netid_set(icsneoc2_message_t* message, icsneoc2_netid_t netid) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto raw = std::dynamic_pointer_cast<RawMessage>(message->message);
|
||||
if(!raw) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
raw->network = Network(static_cast<neonetid_t>(netid), true);
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_data_set(icsneoc2_message_t* message, uint8_t* data, size_t data_length) {
|
||||
if(!message || !data) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
// Make sure the message has the data field (RawMessage or Frame)
|
||||
auto raw_message = std::dynamic_pointer_cast<RawMessage>(message->message);
|
||||
if(!raw_message) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
raw_message->data.resize(data_length);
|
||||
std::copy(data, data + data_length, raw_message->data.begin());
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_data_get(icsneoc2_message_t* message, uint8_t* data, size_t* data_length) {
|
||||
if(!message || !data_length) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
// Make sure the message has the data field (RawMessage or Frame)
|
||||
auto raw_message = std::dynamic_pointer_cast<RawMessage>(message->message);
|
||||
if(!raw_message) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(!data) {
|
||||
*data_length = raw_message->data.size();
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
if(*data_length < raw_message->data.size()) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
std::copy(raw_message->data.begin(), raw_message->data.begin() + raw_message->data.size(), data);
|
||||
*data_length = raw_message->data.size();
|
||||
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_timestamp_set(icsneoc2_message_t* message, uint64_t timestamp) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
if(!message->message) {
|
||||
return icsneoc2_error_invalid_message;
|
||||
}
|
||||
message->message->timestamp = timestamp;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_timestamp_get(icsneoc2_message_t* message, uint64_t* timestamp) {
|
||||
if(!message || !timestamp) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
if(!message->message) {
|
||||
return icsneoc2_error_invalid_message;
|
||||
}
|
||||
*timestamp = message->message->timestamp;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_can_create(icsneoc2_message_t** message) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
try {
|
||||
*message = new icsneoc2_message_t;
|
||||
// Initialize the internal message as a CANMessage so that all icsneoc2_message_can_*_set
|
||||
// functions work correctly on user-created transmit messages.
|
||||
(*message)->message = std::make_shared<CANMessage>();
|
||||
} catch(const std::bad_alloc&) {
|
||||
return icsneoc2_error_out_of_memory;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_free(icsneoc2_message_t* message) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
delete message;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_can_props_set(icsneoc2_message_t* message, const uint64_t* arb_id, const uint64_t* flags) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto can_msg = std::dynamic_pointer_cast<CANMessage>(message->message);
|
||||
if(!can_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(arb_id) {
|
||||
can_msg->arbid = static_cast<uint32_t>(*arb_id);
|
||||
}
|
||||
if(flags) {
|
||||
can_msg->isRemote = (*flags & ICSNEOC2_MESSAGE_CAN_FLAGS_RTR);
|
||||
can_msg->isExtended = (*flags & ICSNEOC2_MESSAGE_CAN_FLAGS_IDE);
|
||||
can_msg->isCANFD = (*flags & ICSNEOC2_MESSAGE_CAN_FLAGS_FDF);
|
||||
can_msg->baudrateSwitch = (*flags & ICSNEOC2_MESSAGE_CAN_FLAGS_BRS);
|
||||
can_msg->errorStateIndicator = (*flags & ICSNEOC2_MESSAGE_CAN_FLAGS_ESI);
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_can_props_get(icsneoc2_message_t* message, uint64_t* arb_id, uint64_t* flags) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto can_msg = std::dynamic_pointer_cast<CANMessage>(message->message);
|
||||
if(!can_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(arb_id) {
|
||||
*arb_id = can_msg->arbid;
|
||||
}
|
||||
if(flags) {
|
||||
*flags = 0;
|
||||
if(can_msg->isRemote) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_RTR;
|
||||
}
|
||||
if(can_msg->isExtended) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_IDE;
|
||||
}
|
||||
if(can_msg->isCANFD) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_FDF;
|
||||
}
|
||||
if(can_msg->baudrateSwitch) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_BRS;
|
||||
}
|
||||
if(can_msg->errorStateIndicator) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_ESI;
|
||||
}
|
||||
if(can_msg->txAborted) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_TX_ABORTED;
|
||||
}
|
||||
if(can_msg->txLostArb) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_TX_LOST_ARB;
|
||||
}
|
||||
if(can_msg->txError) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_FLAGS_TX_ERROR;
|
||||
}
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_network_type_get(icsneoc2_message_t* message, icsneoc2_network_type_t* network_type) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto raw = std::dynamic_pointer_cast<RawMessage>(message->message);
|
||||
if(!raw) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
*network_type = (icsneoc2_network_type_t)raw->network.getType();
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_raw(icsneoc2_message_t* message, bool* is_raw) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*is_raw = std::dynamic_pointer_cast<RawMessage>(message->message) != nullptr;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_frame(icsneoc2_message_t* message, bool* is_frame) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*is_frame = std::dynamic_pointer_cast<Frame>(message->message) != nullptr;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_can(icsneoc2_message_t* message, bool* is_can) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*is_can = std::dynamic_pointer_cast<CANMessage>(message->message) != nullptr;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_can_error(icsneoc2_message_t* message, bool* is_can_error) {
|
||||
if(!message || !is_can_error) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*is_can_error = std::dynamic_pointer_cast<CANErrorMessage>(message->message) != nullptr;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_can_error_props_get(
|
||||
icsneoc2_message_t *message, uint8_t *tx_err_count, uint8_t *rx_err_count,
|
||||
icsneoc2_can_error_code_t *error_code,
|
||||
icsneoc2_can_error_code_t *data_error_code,
|
||||
icsneoc2_message_can_error_flags_t *flags) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto can_err = std::dynamic_pointer_cast<CANErrorMessage>(message->message);
|
||||
if(!can_err) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(tx_err_count) {
|
||||
*tx_err_count = can_err->transmitErrorCount;
|
||||
}
|
||||
if(rx_err_count) {
|
||||
*rx_err_count = can_err->receiveErrorCount;
|
||||
}
|
||||
if(error_code) {
|
||||
*error_code = static_cast<icsneoc2_can_error_code_t>(can_err->errorCode);
|
||||
}
|
||||
if(data_error_code) {
|
||||
*data_error_code = static_cast<icsneoc2_can_error_code_t>(can_err->dataErrorCode);
|
||||
}
|
||||
if(flags) {
|
||||
*flags = 0;
|
||||
if(can_err->busOff) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_BUS_OFF;
|
||||
}
|
||||
if(can_err->errorPassive) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_ERROR_PASSIVE;
|
||||
}
|
||||
if(can_err->errorWarn) {
|
||||
*flags |= ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_ERROR_WARN;
|
||||
}
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_app_error(icsneoc2_message_t* message, bool* is_app_error) {
|
||||
if(!message || !is_app_error) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*is_app_error = std::dynamic_pointer_cast<AppErrorMessage>(message->message) != nullptr;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_app_error_props_get(icsneoc2_message_t* message,
|
||||
icsneoc2_app_error_type_t* error_type, icsneoc2_netid_t* error_netid) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto app_err = std::dynamic_pointer_cast<AppErrorMessage>(message->message);
|
||||
if(!app_err) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(error_type) {
|
||||
*error_type = static_cast<icsneoc2_app_error_type_t>(app_err->getAppErrorType());
|
||||
}
|
||||
if(error_netid) {
|
||||
*error_netid = static_cast<icsneoc2_netid_t>(app_err->errorNetID);
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_app_error_string_get(icsneoc2_message_t* message,
|
||||
char* value, size_t* value_length) {
|
||||
if(!message || !value_length) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto app_err = std::dynamic_pointer_cast<AppErrorMessage>(message->message);
|
||||
if(!app_err) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
return safe_str_copy(value, value_length, app_err->getAppErrorString()) ? icsneoc2_error_success : icsneoc2_error_string_copy_failed;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_lin(icsneoc2_message_t* message, bool* is_lin) {
|
||||
if(!message || !is_lin) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*is_lin = std::dynamic_pointer_cast<LINMessage>(message->message) != nullptr;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_lin_create(icsneoc2_message_t** message, uint8_t id) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
try {
|
||||
*message = new icsneoc2_message_t;
|
||||
(*message)->message = std::make_shared<LINMessage>(id);
|
||||
} catch(const std::bad_alloc&) {
|
||||
return icsneoc2_error_out_of_memory;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_lin_props_get(const icsneoc2_message_t* message,
|
||||
uint8_t* id, uint8_t* protected_id, uint8_t* checksum,
|
||||
icsneoc2_lin_msg_type_t* msg_type, bool* is_enhanced_checksum) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto lin_msg = std::dynamic_pointer_cast<LINMessage>(message->message);
|
||||
if(!lin_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(id) {
|
||||
*id = lin_msg->ID;
|
||||
}
|
||||
if(protected_id) {
|
||||
*protected_id = lin_msg->protectedID;
|
||||
}
|
||||
if(checksum) {
|
||||
*checksum = lin_msg->checksum;
|
||||
}
|
||||
if(msg_type) {
|
||||
*msg_type = static_cast<icsneoc2_lin_msg_type_t>(lin_msg->linMsgType);
|
||||
}
|
||||
if(is_enhanced_checksum) {
|
||||
*is_enhanced_checksum = lin_msg->isEnhancedChecksum;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_lin_props_set(icsneoc2_message_t* message,
|
||||
const uint8_t* id, const uint8_t* checksum,
|
||||
const icsneoc2_lin_msg_type_t* msg_type, const bool* is_enhanced_checksum) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto lin_msg = std::dynamic_pointer_cast<LINMessage>(message->message);
|
||||
if(!lin_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(id) {
|
||||
lin_msg->ID = *id & 0x3Fu;
|
||||
lin_msg->protectedID = lin_msg->calcProtectedID(lin_msg->ID);
|
||||
}
|
||||
if(checksum) {
|
||||
lin_msg->checksum = *checksum;
|
||||
}
|
||||
if(msg_type) {
|
||||
lin_msg->linMsgType = static_cast<LINMessage::Type>(*msg_type);
|
||||
}
|
||||
if(is_enhanced_checksum) {
|
||||
lin_msg->isEnhancedChecksum = *is_enhanced_checksum;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_lin_err_flags_get(const icsneoc2_message_t* message, icsneoc2_lin_err_flags_t* err_flags) {
|
||||
if(!message || !err_flags) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto lin_msg = std::dynamic_pointer_cast<LINMessage>(message->message);
|
||||
if(!lin_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
*err_flags = 0;
|
||||
if(lin_msg->errFlags.ErrRxBreakOnly) *err_flags |= ICSNEOC2_LIN_ERR_RX_BREAK_ONLY;
|
||||
if(lin_msg->errFlags.ErrRxBreakSyncOnly) *err_flags |= ICSNEOC2_LIN_ERR_RX_BREAK_SYNC_ONLY;
|
||||
if(lin_msg->errFlags.ErrTxRxMismatch) *err_flags |= ICSNEOC2_LIN_ERR_TX_RX_MISMATCH;
|
||||
if(lin_msg->errFlags.ErrRxBreakNotZero) *err_flags |= ICSNEOC2_LIN_ERR_RX_BREAK_NOT_ZERO;
|
||||
if(lin_msg->errFlags.ErrRxBreakTooShort) *err_flags |= ICSNEOC2_LIN_ERR_RX_BREAK_TOO_SHORT;
|
||||
if(lin_msg->errFlags.ErrRxSyncNot55) *err_flags |= ICSNEOC2_LIN_ERR_RX_SYNC_NOT_55;
|
||||
if(lin_msg->errFlags.ErrRxDataLenOver8) *err_flags |= ICSNEOC2_LIN_ERR_RX_DATA_LEN_OVER_8;
|
||||
if(lin_msg->errFlags.ErrFrameSync) *err_flags |= ICSNEOC2_LIN_ERR_FRAME_SYNC;
|
||||
if(lin_msg->errFlags.ErrFrameMessageID) *err_flags |= ICSNEOC2_LIN_ERR_FRAME_MESSAGE_ID;
|
||||
if(lin_msg->errFlags.ErrFrameResponderData) *err_flags |= ICSNEOC2_LIN_ERR_FRAME_RESPONDER_DATA;
|
||||
if(lin_msg->errFlags.ErrChecksumMatch) *err_flags |= ICSNEOC2_LIN_ERR_CHECKSUM_MATCH;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_lin_status_flags_get(const icsneoc2_message_t* message, icsneoc2_lin_status_flags_t* status_flags) {
|
||||
if(!message || !status_flags) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto lin_msg = std::dynamic_pointer_cast<LINMessage>(message->message);
|
||||
if(!lin_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
*status_flags = 0;
|
||||
if(lin_msg->statusFlags.TxChecksumEnhanced) *status_flags |= ICSNEOC2_LIN_STATUS_TX_CHECKSUM_ENHANCED;
|
||||
if(lin_msg->statusFlags.TxCommander) *status_flags |= ICSNEOC2_LIN_STATUS_TX_COMMANDER;
|
||||
if(lin_msg->statusFlags.TxResponder) *status_flags |= ICSNEOC2_LIN_STATUS_TX_RESPONDER;
|
||||
if(lin_msg->statusFlags.TxAborted) *status_flags |= ICSNEOC2_LIN_STATUS_TX_ABORTED;
|
||||
if(lin_msg->statusFlags.UpdateResponderOnce) *status_flags |= ICSNEOC2_LIN_STATUS_UPDATE_RESPONDER_ONCE;
|
||||
if(lin_msg->statusFlags.HasUpdatedResponderOnce) *status_flags |= ICSNEOC2_LIN_STATUS_HAS_UPDATED_RESPONDER_ONCE;
|
||||
if(lin_msg->statusFlags.BusRecovered) *status_flags |= ICSNEOC2_LIN_STATUS_BUS_RECOVERED;
|
||||
if(lin_msg->statusFlags.BreakOnly) *status_flags |= ICSNEOC2_LIN_STATUS_BREAK_ONLY;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_lin_calc_checksum(icsneoc2_message_t* message) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto lin_msg = std::dynamic_pointer_cast<LINMessage>(message->message);
|
||||
if(!lin_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
LINMessage::calcChecksum(*lin_msg);
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_eth_create(icsneoc2_message_t** message) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
try {
|
||||
*message = new icsneoc2_message_t;
|
||||
(*message)->message = std::make_shared<EthernetMessage>();
|
||||
} catch(const std::bad_alloc&) {
|
||||
return icsneoc2_error_out_of_memory;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_eth_props_set(icsneoc2_message_t* message, const icsneoc2_message_eth_flags_t* flags, const bool* has_fcs, const uint32_t* fcs) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto eth_msg = std::dynamic_pointer_cast<EthernetMessage>(message->message);
|
||||
if(!eth_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(flags) {
|
||||
eth_msg->frameTooShort = (*flags & ICSNEOC2_MESSAGE_ETH_FLAGS_FRAME_TOO_SHORT);
|
||||
eth_msg->noPadding = (*flags & ICSNEOC2_MESSAGE_ETH_FLAGS_NO_PADDING);
|
||||
eth_msg->fcsVerified = (*flags & ICSNEOC2_MESSAGE_ETH_FLAGS_FCS_VERIFIED);
|
||||
eth_msg->txAborted = (*flags & ICSNEOC2_MESSAGE_ETH_FLAGS_TX_ABORTED);
|
||||
eth_msg->crcError = (*flags & ICSNEOC2_MESSAGE_ETH_FLAGS_CRC_ERROR);
|
||||
}
|
||||
if(has_fcs && !*has_fcs) {
|
||||
eth_msg->fcs = std::nullopt;
|
||||
} else if(has_fcs && *has_fcs) {
|
||||
// I'm pretty sure we can leave this alone, setting fcs below will take care of the behavior,
|
||||
// otherwise we get into a weird state where we have to set fcs to zero if fcs is null but has_fcs is true.
|
||||
}
|
||||
if (fcs) {
|
||||
eth_msg->fcs = *fcs;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_eth_props_get(icsneoc2_message_t* message, icsneoc2_message_eth_flags_t* flags, bool* has_fcs, uint32_t* fcs) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto eth_msg = std::dynamic_pointer_cast<EthernetMessage>(message->message);
|
||||
if(!eth_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(flags) {
|
||||
*flags = 0;
|
||||
if(eth_msg->noPadding)
|
||||
*flags |= ICSNEOC2_MESSAGE_ETH_FLAGS_NO_PADDING;
|
||||
if(eth_msg->fcsVerified)
|
||||
*flags |= ICSNEOC2_MESSAGE_ETH_FLAGS_FCS_VERIFIED;
|
||||
if(eth_msg->txAborted)
|
||||
*flags |= ICSNEOC2_MESSAGE_ETH_FLAGS_TX_ABORTED;
|
||||
if(eth_msg->crcError)
|
||||
*flags |= ICSNEOC2_MESSAGE_ETH_FLAGS_CRC_ERROR;
|
||||
if(eth_msg->frameTooShort)
|
||||
*flags |= ICSNEOC2_MESSAGE_ETH_FLAGS_FRAME_TOO_SHORT;
|
||||
}
|
||||
if(has_fcs) {
|
||||
*has_fcs = eth_msg->fcs.has_value();
|
||||
}
|
||||
if(fcs) {
|
||||
if(eth_msg->fcs) {
|
||||
*fcs = eth_msg->fcs.value();
|
||||
} else {
|
||||
*fcs = 0;
|
||||
}
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_eth_mac_get(icsneoc2_message_t* message, uint8_t* dst_mac, uint8_t* src_mac) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto eth_msg = std::dynamic_pointer_cast<EthernetMessage>(message->message);
|
||||
if(!eth_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(dst_mac) {
|
||||
if(auto mac = eth_msg->getDestinationMAC(); mac.has_value()) {
|
||||
const auto& mac_value = mac.value();
|
||||
std::memcpy(dst_mac, mac_value.data(), mac_value.size());
|
||||
} else {
|
||||
return icsneoc2_error_invalid_data;
|
||||
}
|
||||
}
|
||||
if(src_mac) {
|
||||
if(auto mac = eth_msg->getSourceMAC(); mac.has_value()) {
|
||||
const auto& mac_value = mac.value();
|
||||
std::memcpy(src_mac, mac_value.data(), mac_value.size());
|
||||
} else {
|
||||
return icsneoc2_error_invalid_data;
|
||||
}
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_eth_ether_type_get(icsneoc2_message_t* message, uint16_t* ether_type) {
|
||||
if(!message || !ether_type) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto eth_msg = std::dynamic_pointer_cast<EthernetMessage>(message->message);
|
||||
if(!eth_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if (auto et = eth_msg->getEtherType(); et.has_value()) {
|
||||
*ether_type = et.value();
|
||||
} else {
|
||||
return icsneoc2_error_invalid_data;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_eth_t1s_props_set(icsneoc2_message_t* message, const icsneoc2_message_eth_t1s_flags_t* flags, const uint8_t* node_id, const uint8_t* burst_count, const uint8_t* symbol_type) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto eth_msg = std::dynamic_pointer_cast<EthernetMessage>(message->message);
|
||||
if(!eth_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
// If all parameters are null/zero, clear the T1S state. Otherwise, if any parameters are set and we don't have a T1S state, create it.
|
||||
if(!flags && !node_id && !burst_count && !symbol_type) {
|
||||
eth_msg->t1s = std::nullopt;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
if((flags || node_id || burst_count || symbol_type) && !eth_msg->t1s.has_value()) {
|
||||
eth_msg->t1s.emplace();
|
||||
}
|
||||
if(flags) {
|
||||
eth_msg->t1s->isSymbol = (*flags & ICSNEOC2_MESSAGE_ETH_T1S_FLAGS_IS_T1S_SYMBOL);
|
||||
eth_msg->t1s->isBurst = (*flags & ICSNEOC2_MESSAGE_ETH_T1S_FLAGS_IS_T1S_BURST);
|
||||
eth_msg->t1s->txCollision = (*flags & ICSNEOC2_MESSAGE_ETH_T1S_FLAGS_TX_COLLISION);
|
||||
eth_msg->t1s->isWake = (*flags & ICSNEOC2_MESSAGE_ETH_T1S_FLAGS_IS_T1S_WAKE);
|
||||
}
|
||||
if(node_id) {
|
||||
eth_msg->t1s->nodeId = *node_id;
|
||||
}
|
||||
if(burst_count) {
|
||||
eth_msg->t1s->burstCount = *burst_count;
|
||||
}
|
||||
if(symbol_type) {
|
||||
eth_msg->t1s->symbolType = *symbol_type;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_eth_t1s_props_get(icsneoc2_message_t* message, icsneoc2_message_eth_t1s_flags_t* flags, uint8_t* node_id, uint8_t* burst_count, uint8_t* symbol_type) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto eth_msg = std::dynamic_pointer_cast<EthernetMessage>(message->message);
|
||||
if(!eth_msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(flags) {
|
||||
*flags = 0;
|
||||
if(eth_msg->t1s.has_value()) {
|
||||
if(eth_msg->t1s->isSymbol)
|
||||
*flags |= ICSNEOC2_MESSAGE_ETH_T1S_FLAGS_IS_T1S_SYMBOL;
|
||||
if(eth_msg->t1s->isBurst)
|
||||
*flags |= ICSNEOC2_MESSAGE_ETH_T1S_FLAGS_IS_T1S_BURST;
|
||||
if(eth_msg->t1s->txCollision)
|
||||
*flags |= ICSNEOC2_MESSAGE_ETH_T1S_FLAGS_TX_COLLISION;
|
||||
if(eth_msg->t1s->isWake)
|
||||
*flags |= ICSNEOC2_MESSAGE_ETH_T1S_FLAGS_IS_T1S_WAKE;
|
||||
}
|
||||
}
|
||||
if(node_id) {
|
||||
*node_id = eth_msg->t1s.has_value() ? eth_msg->t1s->nodeId : 0;
|
||||
}
|
||||
if(burst_count) {
|
||||
*burst_count = eth_msg->t1s.has_value() ? eth_msg->t1s->burstCount : 0;
|
||||
}
|
||||
if(symbol_type) {
|
||||
*symbol_type = eth_msg->t1s.has_value() ? eth_msg->t1s->symbolType : 0;
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_ethernet(icsneoc2_message_t* message, bool* is_ethernet) {
|
||||
if(!message || !is_ethernet) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*is_ethernet = std::dynamic_pointer_cast<EthernetMessage>(message->message) != nullptr;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_is_ethernet_status(icsneoc2_message_t* message, bool* is_ethernet_status) {
|
||||
if(!message || !is_ethernet_status) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
*is_ethernet_status = std::dynamic_pointer_cast<EthernetStatusMessage>(message->message) != nullptr;
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
|
||||
icsneoc2_error_t icsneoc2_message_eth_status_props_get(icsneoc2_message_t* message, bool* link_state, bool* duplex, icsneoc2_link_speed_t* link_speed, icsneoc2_link_mode_t* link_mode) {
|
||||
if(!message) {
|
||||
return icsneoc2_error_invalid_parameters;
|
||||
}
|
||||
auto msg = std::dynamic_pointer_cast<EthernetStatusMessage>(message->message);
|
||||
if(!msg) {
|
||||
return icsneoc2_error_invalid_type;
|
||||
}
|
||||
if(link_state) {
|
||||
*link_state = msg->state;
|
||||
}
|
||||
if(duplex) {
|
||||
*duplex = msg->duplex;
|
||||
}
|
||||
if(link_speed) {
|
||||
*link_speed = static_cast<icsneoc2_link_speed_t>(msg->speed);
|
||||
}
|
||||
if(link_mode) {
|
||||
*link_mode = static_cast<icsneoc2_link_mode_t>(msg->mode);
|
||||
}
|
||||
return icsneoc2_error_success;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -28,9 +28,9 @@ BEGIN
|
||||
VALUE "CompanyName", "Intrepid Control Systems, Inc."
|
||||
VALUE "FileDescription", "Intrepid Control Systems Open Device Communication C API"
|
||||
VALUE "FileVersion", VER_FILEVERSION_STR
|
||||
VALUE "InternalName", "icsneoc2.dll"
|
||||
VALUE "LegalCopyright", "Intrepid Control Systems, Inc. (C) 2018-2026"
|
||||
VALUE "OriginalFilename", "icsneoc2.dll"
|
||||
VALUE "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
|
||||
|
||||
+138
-188
@@ -4,10 +4,10 @@
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
APIEvent::APIEvent(Type type, APIEvent::Severity severity, std::weak_ptr<Device> device) : eventStruct({}), device(device) {
|
||||
auto shared = device.lock();
|
||||
if(shared) {
|
||||
serial = shared->getSerial();
|
||||
APIEvent::APIEvent(Type type, APIEvent::Severity severity, const Device* device) : eventStruct({}) {
|
||||
this->device = device;
|
||||
if(device) {
|
||||
serial = device->getSerial();
|
||||
eventStruct.serial[serial.copy(eventStruct.serial, sizeof(eventStruct.serial))] = '\0';
|
||||
}
|
||||
|
||||
@@ -22,15 +22,37 @@ void APIEvent::init(Type event, APIEvent::Severity severity) {
|
||||
eventStruct.timestamp = EventClock::to_time_t(timepoint);
|
||||
}
|
||||
|
||||
std::string APIEvent::describe() const noexcept {
|
||||
std::stringstream ss;
|
||||
if(device)
|
||||
ss << *device; // Makes use of device.describe()
|
||||
else
|
||||
ss << "API";
|
||||
|
||||
Severity severity = getSeverity();
|
||||
if(severity == Severity::EventInfo) {
|
||||
ss << " Info: ";
|
||||
} else if(severity == Severity::EventWarning) {
|
||||
ss << " Warning: ";
|
||||
} else if(severity == Severity::Error) {
|
||||
ss << " Error: ";
|
||||
} else {
|
||||
// Should never get here, since Severity::Any should only be used for filtering
|
||||
ss << " Any: ";
|
||||
}
|
||||
|
||||
ss << getDescription();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void APIEvent::downgradeFromError() noexcept {
|
||||
eventStruct.severity = (uint8_t) APIEvent::Severity::EventWarning;
|
||||
}
|
||||
|
||||
bool APIEvent::isForDevice(std::string filterSerial) const noexcept {
|
||||
auto shared = device.lock();
|
||||
if(!shared || filterSerial.length() == 0)
|
||||
if(!device || filterSerial.length() == 0)
|
||||
return false;
|
||||
return shared->getSerial() == filterSerial;
|
||||
return device->getSerial() == filterSerial;
|
||||
}
|
||||
|
||||
// API Errors
|
||||
@@ -52,9 +74,6 @@ 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!";
|
||||
@@ -64,8 +83,8 @@ static constexpr const char* NO_SERIAL_NUMBER_12V = "Communication could not be
|
||||
static constexpr const char* NO_SERIAL_NUMBER = "Communication could not be established with the device. Perhaps it is not powered or requires a firmware update using Vehicle Spy.";
|
||||
static constexpr const char* INCORRECT_SERIAL_NUMBER = "The device did not return the expected serial number!";
|
||||
static constexpr const char* SETTINGS_READ = "The device settings could not be read.";
|
||||
static constexpr const char* SETTINGS_VERSION = "The settings version is incorrect, please update your firmware with ICS Device Manager.";
|
||||
static constexpr const char* SETTINGS_LENGTH = "The settings length is incorrect, please update your firmware with ICS Device Manager.";
|
||||
static constexpr const char* SETTINGS_VERSION = "The settings version is incorrect, please update your firmware with neoVI Explorer.";
|
||||
static constexpr const char* SETTINGS_LENGTH = "The settings length is incorrect, please update your firmware with neoVI Explorer.";
|
||||
static constexpr const char* SETTINGS_CHECKSUM = "The settings checksum is incorrect, attempting to set defaults may remedy this issue.";
|
||||
static constexpr const char* SETTINGS_NOT_AVAILABLE = "Settings are not available for this device.";
|
||||
static constexpr const char* SETTINGS_READONLY = "Settings are read-only for this device.";
|
||||
@@ -95,28 +114,13 @@ static constexpr const char* ATOMIC_OPERATION_RETRIED = "An operation failed to
|
||||
static constexpr const char* ATOMIC_OPERATION_COMPLETED_NONATOMICALLY = "An ideally-atomic operation was completed nonatomically.";
|
||||
static constexpr const char* WIVI_STACK_REFRESH_FAILED = "The Wireless neoVI stack encountered a communication error.";
|
||||
static constexpr const char* WIVI_UPLOAD_STACK_OVERFLOW = "The Wireless neoVI upload stack has encountered an overflow condition.";
|
||||
static constexpr const char* A2B_MESSAGE_INCOMPLETE_FRAME = "At least one of the frames of the A2B message does not contain samples for each channel and stream.";
|
||||
static constexpr const char* I2C_MESSAGE_EXCEED_MAX_LENGTH = "The I2C message was too long.";
|
||||
static constexpr const char* A2B_MESSAGE_INCOMPLETE_FRAME = "At least one of the frames of the A2B message does not contain samples for each channel and stream.";
|
||||
static constexpr const char* COREMINI_UPLOAD_VERSION_MISMATCH = "The version of the coremini engine on the device and the script uploaded are not the same.";
|
||||
static constexpr const char* DISK_NOT_CONNECTED = "The program tried to access a disk that is not connected.";
|
||||
static constexpr const char* UNEXPECTED_RESPONSE = "Received an unexpected or invalid response from the device.";
|
||||
static constexpr const char* LIVE_DATA_INVALID_HANDLE = "The live data handle was invalid.";
|
||||
static constexpr const char* LIVE_DATA_INVALID_COMMAND = "The live data command was invalid.";
|
||||
static constexpr const char* LIVE_DATA_INVALID_ARGUMENT = "The live data argument was invalid.";
|
||||
static constexpr const char* LIVE_DATA_VERSION_MISMATCH = "The live data version between libicsneo and firmware are not the same.";
|
||||
static constexpr const char* LIVE_DATA_NO_DEVICE_RESPONSE = "Expected a response from the device for live data but none were found.";
|
||||
static constexpr const char* LIVE_DATA_MAX_SIGNALS_REACHED = "The max amound of signals to subscribe to for live data has been reached.";
|
||||
static constexpr const char* LIVE_DATA_COMMAND_FAILED = "The live data command failed.";
|
||||
static constexpr const char* LIVE_DATA_ENCODER_ERROR = "Failure to encode live data message.";
|
||||
static constexpr const char* LIVE_DATA_DECODER_ERROR = "Failure to decode live data message.";
|
||||
static constexpr const char* LIVE_DATA_NOT_SUPPORTED = "Live data is not supported on this device.";
|
||||
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* APP_ERROR_PARSING_FAILED = "Failure to decode app error message.";
|
||||
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.";
|
||||
@@ -134,7 +138,41 @@ static constexpr const char* FAILED_TO_BIND = "Unable to bind socket.";
|
||||
static constexpr const char* ERROR_SETTING_SOCKET_OPTION = "A call to setsockopt() failed.";
|
||||
static constexpr const char* GETIFADDRS_ERROR = "A call to getifaddrs() failed.";
|
||||
static constexpr const char* SEND_TO_ERROR = "A call to sendto() failed.";
|
||||
static constexpr const char* MDIO_MESSAGE_EXCEED_MAX_LENGTH = "The MDIO message was too long.";
|
||||
|
||||
// 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.";
|
||||
@@ -145,38 +183,6 @@ 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.";
|
||||
|
||||
// MACSEC
|
||||
static constexpr const char* MACSEC_SECY_LIMIT = "Attempted to exceed the limit of SecY additions to this port";
|
||||
static constexpr const char* MACSEC_RULE_LIMIT = "Attempted to exceed the limit of rule additions to this port";
|
||||
static constexpr const char* MACSEC_SA_LIMIT = "Attempted to exceed the limit of SA additions to this port";
|
||||
static constexpr const char* MACSEC_INVALID_SECY_INDEX = "Attempted to access an invalid SecY index";
|
||||
static constexpr const char* MACSEC_INVALID_SA_INDEX = "Attempted to access an invalid SA index";
|
||||
static constexpr const char* MACSEC_INVALID_RULE_INDEX = "Attempted to access an invalid rule index";
|
||||
static constexpr const char* MACSEC_REKEY_NOT_ENABLED = "Attempted to set rekey SA when rekey was not enabled";
|
||||
static constexpr const char* MACSEC_NOT_SUPPORTED = "MACsec is not supported on this device";
|
||||
static constexpr const char* MACSEC_CONFIG_MISMATCH = "Attempted to configure device with a macsec configuration for a different device";
|
||||
// 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";
|
||||
static constexpr const char* SERVD_NOT_REACHABLE = "Could not reach Servd; ensure it is installed and running";
|
||||
|
||||
// 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* NO_ERROR_FOUND = "No errors were found.";
|
||||
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.";
|
||||
@@ -220,12 +226,6 @@ 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:
|
||||
@@ -304,8 +304,6 @@ const char* APIEvent::DescriptionForType(Type type) {
|
||||
return WIVI_STACK_REFRESH_FAILED;
|
||||
case Type::WiVIUploadStackOverflow:
|
||||
return WIVI_UPLOAD_STACK_OVERFLOW;
|
||||
case Type::I2CMessageExceedsMaxLength:
|
||||
return I2C_MESSAGE_EXCEED_MAX_LENGTH;
|
||||
case Type::A2BMessageIncompleteFrame:
|
||||
return A2B_MESSAGE_INCOMPLETE_FRAME;
|
||||
case Type::CoreminiUploadVersionMismatch:
|
||||
@@ -314,34 +312,10 @@ const char* APIEvent::DescriptionForType(Type type) {
|
||||
return DISK_NOT_CONNECTED;
|
||||
case Type::UnexpectedResponse:
|
||||
return UNEXPECTED_RESPONSE;
|
||||
case Type::LiveDataInvalidHandle:
|
||||
return LIVE_DATA_INVALID_HANDLE;
|
||||
case Type::LiveDataInvalidCommand:
|
||||
return LIVE_DATA_INVALID_COMMAND;
|
||||
case Type::LiveDataInvalidArgument:
|
||||
return LIVE_DATA_INVALID_ARGUMENT;
|
||||
case Type::LiveDataVersionMismatch:
|
||||
return LIVE_DATA_VERSION_MISMATCH;
|
||||
case Type::LiveDataNoDeviceResponse:
|
||||
return LIVE_DATA_NO_DEVICE_RESPONSE;
|
||||
case Type::LiveDataMaxSignalsReached:
|
||||
return LIVE_DATA_MAX_SIGNALS_REACHED;
|
||||
case Type::LiveDataCommandFailed:
|
||||
return LIVE_DATA_COMMAND_FAILED;
|
||||
case Type::LiveDataEncoderError:
|
||||
return LIVE_DATA_ENCODER_ERROR;
|
||||
case Type::LiveDataDecoderError:
|
||||
return LIVE_DATA_DECODER_ERROR;
|
||||
case Type::LiveDataNotSupported:
|
||||
return LIVE_DATA_NOT_SUPPORTED;
|
||||
case Type::LINSettingsNotAvailable:
|
||||
return LIN_SETTINGS_NOT_AVAILABLE;
|
||||
case Type::ModeNotFound:
|
||||
return MODE_NOT_FOUND;
|
||||
case Type::AppErrorParsingFailed:
|
||||
return APP_ERROR_PARSING_FAILED;
|
||||
case Type::SettingNotAvaiableDevice:
|
||||
return SETTING_NOT_AVAILABLE;
|
||||
// Transport Errors
|
||||
case Type::FailedToRead:
|
||||
return FAILED_TO_READ;
|
||||
@@ -373,14 +347,76 @@ const char* APIEvent::DescriptionForType(Type type) {
|
||||
return GETIFADDRS_ERROR;
|
||||
case Type::SendToError:
|
||||
return SEND_TO_ERROR;
|
||||
case Type::MDIOMessageExceedsMaxLength:
|
||||
return MDIO_MESSAGE_EXCEED_MAX_LENGTH;
|
||||
case Type::GPTPNotSupported:
|
||||
return GPTP_NOT_SUPPORTED;
|
||||
case Type::DiskFormatNotSupported:
|
||||
return DISK_FORMAT_NOT_SUPPORTED;
|
||||
case Type::DiskFormatInvalidCount:
|
||||
return DISK_FORMAT_INVALID_COUNT;
|
||||
|
||||
// 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;
|
||||
|
||||
// VSA
|
||||
case Type::VSABufferCorrupted:
|
||||
@@ -398,106 +434,20 @@ const char* APIEvent::DescriptionForType(Type type) {
|
||||
case Type::VSAOtherError:
|
||||
return VSA_OTHER_ERROR;
|
||||
|
||||
// MACSEC
|
||||
case Type::MACsecSecYLimit:
|
||||
return MACSEC_SECY_LIMIT;
|
||||
case Type::MACsecSaLimit:
|
||||
return MACSEC_SA_LIMIT;
|
||||
case Type::MACsecRuleLimit:
|
||||
return MACSEC_RULE_LIMIT;
|
||||
case Type::MACsecInvalidSecYIndex:
|
||||
return MACSEC_INVALID_SECY_INDEX;
|
||||
case Type::MACsecInvalidSaIndex:
|
||||
return MACSEC_INVALID_SA_INDEX;
|
||||
case Type::MACsecInvalidRuleIndex:
|
||||
return MACSEC_INVALID_RULE_INDEX;
|
||||
case Type::MACsecRekeyNotEnabled:
|
||||
return MACSEC_REKEY_NOT_ENABLED;
|
||||
case Type::MACsecNotSupported:
|
||||
return MACSEC_NOT_SUPPORTED;
|
||||
case Type::MACsecConfigMismatch:
|
||||
return MACSEC_CONFIG_MISMATCH;
|
||||
// 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;
|
||||
case Type::ServdNotReachable:
|
||||
return SERVD_NOT_REACHABLE;
|
||||
|
||||
// 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::NoErrorFound:
|
||||
return NO_ERROR_FOUND;
|
||||
case Type::TooManyEvents:
|
||||
return TOO_MANY_EVENTS;
|
||||
case Type::Unknown:
|
||||
return UNKNOWN;
|
||||
default:
|
||||
return INVALID;
|
||||
}
|
||||
return INVALID;
|
||||
}
|
||||
|
||||
std::string APIEvent::describe() const noexcept {
|
||||
std::stringstream ss;
|
||||
auto shared = device.lock();
|
||||
if(shared)
|
||||
ss << *shared; // Makes use of device.describe()
|
||||
else
|
||||
ss << "API";
|
||||
|
||||
Severity severity = getSeverity();
|
||||
if(severity == Severity::EventInfo) {
|
||||
ss << " Info: ";
|
||||
} else if(severity == Severity::EventWarning) {
|
||||
ss << " Warning: ";
|
||||
} else if(severity == Severity::Error) {
|
||||
ss << " Error: ";
|
||||
} else {
|
||||
// Should never get here, since Severity::Any should only be used for filtering
|
||||
ss << " Any: ";
|
||||
}
|
||||
|
||||
const char* description = DescriptionForType(getType());
|
||||
if(description == INVALID)
|
||||
ss << description << " (0x" << std::hex << eventStruct.eventNumber << ")";
|
||||
else
|
||||
ss << description;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool EventFilter::match(const APIEvent& event) const noexcept {
|
||||
if(type != APIEvent::Type::Any && type != event.getType())
|
||||
return false;
|
||||
|
||||
|
||||
if(matchOnDevicePtr && !event.isForDevice(device))
|
||||
return false;
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
using namespace icsneo;
|
||||
|
||||
EventManager& EventManager::GetInstance() {
|
||||
static EventManager* inst = new EventManager();
|
||||
return *inst;
|
||||
static EventManager inst;
|
||||
return inst;
|
||||
}
|
||||
|
||||
void EventManager::downgradeErrorsOnCurrentThread() {
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
//FILE: icsneo40DLLAPI.H
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#include "icsneo/icsnVC40.h"
|
||||
|
||||
// Vehicle Spy 3.26.3.9 removed these legacy settings structure definitions from
|
||||
// icsnVC40.h. The corresponding functions only ever treat them as opaque
|
||||
// buffers, so forward declarations keep the existing API/ABI intact.
|
||||
typedef struct _SFireSettings SFireSettings;
|
||||
typedef struct _SVCAN3Settings SVCAN3Settings;
|
||||
typedef struct _SVCANRFSettings SVCANRFSettings;
|
||||
|
||||
|
||||
|
||||
bool LoadDLLAPI(HINSTANCE &hAPIDLL);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#error "icsneolegacy.cpp must be compiled with a C++ compiler!"
|
||||
#endif
|
||||
|
||||
#define NOMINMAX
|
||||
|
||||
#define ICSNEOC_MAKEDLL
|
||||
#include "icsneo/icsneolegacy.h"
|
||||
#include "icsneo/J2534.h"
|
||||
@@ -27,25 +29,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_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},
|
||||
{NETID_HSCAN, 1},
|
||||
{NETID_MSCAN, 2},
|
||||
{NETID_HSCAN2, 18},
|
||||
{NETID_HSCAN3, 19},
|
||||
{NETID_HSCAN4, 32},
|
||||
{NETID_HSCAN5, 33},
|
||||
{NETID_HSCAN6, 47},
|
||||
{NETID_HSCAN7, 48},
|
||||
};
|
||||
|
||||
static const std::map<size_t, size_t> mp_HWnetIDToCMnetID = {
|
||||
{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},
|
||||
{NETID_HSCAN, 0},
|
||||
{NETID_MSCAN, 1},
|
||||
{NETID_HSCAN2, 5},
|
||||
{NETID_HSCAN3, 8},
|
||||
{NETID_HSCAN4, 14},
|
||||
{NETID_HSCAN5, 15},
|
||||
{NETID_HSCAN6, 32},
|
||||
{NETID_HSCAN7, 33},
|
||||
};
|
||||
|
||||
static unsigned long vnet_table[] = {0, PLASMA_SLAVE1_OFFSET, PLASMA_SLAVE2_OFFSET};
|
||||
@@ -90,7 +92,6 @@ static bool NeoMessageToSpyMessage(const neodevice_t* device, const neomessage_t
|
||||
copyFrameData();
|
||||
break;
|
||||
case Network::Type::Ethernet:
|
||||
case Network::Type::AutomotiveEthernet:
|
||||
oldmsg.Protocol = SPY_PROTOCOL_ETHERNET;
|
||||
oldmsg.NumberBytesData = static_cast<uint8_t>(frame.length & 0xFF);
|
||||
oldmsg.NumberBytesHeader = static_cast<uint8_t>(frame.length >> 8);
|
||||
@@ -1035,10 +1036,10 @@ int LegacyDLLExport icsneoGetDeviceSettingsType(void* hObject, EPlasmaIonVnetCha
|
||||
case NEODEVICE_ION:
|
||||
*pDeviceSettingsType = DeviceFire2SettingsType; //defaults to FIRE2 vnets with libicsneo - no firevnets!
|
||||
break;
|
||||
case NEODEVICE_VCAN3_DEPRECATED:
|
||||
*pDeviceSettingsType = DeviceVCAN3SettingsTypeDeprecated;
|
||||
case NEODEVICE_VCAN3:
|
||||
*pDeviceSettingsType = DeviceVCAN3SettingsType;
|
||||
break;
|
||||
case NEODEVICE_FIRE_DEPRECATED:
|
||||
case NEODEVICE_FIRE:
|
||||
*pDeviceSettingsType = DeviceFireSettingsType;
|
||||
break;
|
||||
case NEODEVICE_FIRE2:
|
||||
@@ -1061,24 +1062,21 @@ int LegacyDLLExport icsneoGetDeviceSettingsType(void* hObject, EPlasmaIonVnetCha
|
||||
case NEODEVICE_VIVIDCAN:
|
||||
*pDeviceSettingsType = DeviceVividCANSettingsType;
|
||||
break;
|
||||
case NEODEVICE_ECU_AVB_DEPRECATED:
|
||||
*pDeviceSettingsType = DeviceECU_AVBSettingsTypeDeprecated;
|
||||
case NEODEVICE_ECU_AVB:
|
||||
*pDeviceSettingsType = DeviceECU_AVBSettingsType;
|
||||
break;
|
||||
case NEODEVICE_RADSUPERMOON_DEPRECATED:
|
||||
*pDeviceSettingsType = DeviceRADSuperMoonSettingsTypeDeprecated;
|
||||
case NEODEVICE_RADSUPERMOON:
|
||||
*pDeviceSettingsType = DeviceRADSuperMoonSettingsType;
|
||||
break;
|
||||
case NEODEVICE_RADMOON2:
|
||||
*pDeviceSettingsType = DeviceRADMoon2SettingsType;
|
||||
break;
|
||||
case NEODEVICE_RADGIGALOG_DEPRECATED:
|
||||
*pDeviceSettingsType = DeviceRADGigalogSettingsTypeDeprecated;
|
||||
case NEODEVICE_RADGIGALOG:
|
||||
*pDeviceSettingsType = DeviceRADGigalogSettingsType;
|
||||
break;
|
||||
case NEODEVICE_RADMOON3:
|
||||
*pDeviceSettingsType = DeviceRADMoon3SettingsType;
|
||||
break;
|
||||
case NEODEVICE_RADGEMINI:
|
||||
*pDeviceSettingsType = DeviceRADGeminiSettingsType;
|
||||
break;
|
||||
case NEODEVICE_RED2:
|
||||
*pDeviceSettingsType = DeviceRed2SettingsType;
|
||||
break;
|
||||
@@ -1088,8 +1086,6 @@ int LegacyDLLExport icsneoGetDeviceSettingsType(void* hObject, EPlasmaIonVnetCha
|
||||
case NEODEVICE_FIRE3_FLEXRAY:
|
||||
*pDeviceSettingsType = DeviceFire3FlexraySettingsType;
|
||||
break;
|
||||
case NEODEVICE_RAD_BMS:
|
||||
*pDeviceSettingsType = DeviceRADBMSSettingsType;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
if(LIBICSNEO_ENABLE_BINDINGS_PYTHON)
|
||||
add_subdirectory(python)
|
||||
endif()
|
||||
|
||||
if(LIBICSNEO_ENABLE_BINDINGS_RUST)
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
Corrosion
|
||||
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
|
||||
GIT_TAG v0.5 # Optionally specify a commit hash, version tag or branch here
|
||||
)
|
||||
FetchContent_MakeAvailable(Corrosion)
|
||||
|
||||
corrosion_import_crate(MANIFEST_PATH ${CMAKE_SOURCE_DIR}/bindings/rust/icsneoc2rs/Cargo.toml)
|
||||
else()
|
||||
message(STATUS "Not building rust bindings")
|
||||
endif()
|
||||
@@ -1,18 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
set(PYBIND11_FINDPYTHON ON)
|
||||
|
||||
if(PYBIND11_ROOT)
|
||||
find_package(pybind11 CONFIG REQUIRED)
|
||||
else()
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
pybind11
|
||||
GIT_REPOSITORY https://github.com/pybind/pybind11.git
|
||||
GIT_TAG v3.0.3
|
||||
)
|
||||
FetchContent_MakeAvailable(pybind11)
|
||||
endif()
|
||||
find_package(pybind11 CONFIG REQUIRED)
|
||||
|
||||
pybind11_add_module(icsneopy
|
||||
icsneopy/api/event.cpp
|
||||
@@ -21,8 +10,6 @@ pybind11_add_module(icsneopy
|
||||
icsneopy/api/version.cpp
|
||||
icsneopy/device/devicetype.cpp
|
||||
icsneopy/communication/network.cpp
|
||||
icsneopy/communication/io.cpp
|
||||
icsneopy/communication/livedata.cpp
|
||||
icsneopy/communication/message/message.cpp
|
||||
icsneopy/communication/message/canmessage.cpp
|
||||
icsneopy/communication/message/canerrormessage.cpp
|
||||
@@ -31,34 +18,17 @@ pybind11_add_module(icsneopy
|
||||
icsneopy/communication/message/tc10statusmessage.cpp
|
||||
icsneopy/communication/message/mdiomessage.cpp
|
||||
icsneopy/communication/message/gptpstatusmessage.cpp
|
||||
icsneopy/communication/message/allmacaddressesmessage.cpp
|
||||
icsneopy/communication/message/apperrormessage.cpp
|
||||
icsneopy/communication/message/ethernetstatusmessage.cpp
|
||||
icsneopy/communication/message/spimessage.cpp
|
||||
icsneopy/communication/message/scriptstatusmessage.cpp
|
||||
icsneopy/communication/message/ethphymessage.cpp
|
||||
icsneopy/communication/message/livedatamessage.cpp
|
||||
icsneopy/communication/message/callback/messagecallback.cpp
|
||||
icsneopy/communication/message/filter/messagefilter.cpp
|
||||
icsneopy/core/macseccfg.cpp
|
||||
icsneopy/flexray/flexray.cpp
|
||||
icsneopy/disk/diskdriver.cpp
|
||||
icsneopy/disk/diskdetails.cpp
|
||||
icsneopy/device/chipid.cpp
|
||||
icsneopy/device/versionreport.cpp
|
||||
icsneopy/device/device.cpp
|
||||
icsneopy/device/extensions/deviceextension.cpp
|
||||
icsneopy/device/idevicesettings.cpp
|
||||
icsneopy/icsneocpp.cpp
|
||||
)
|
||||
target_link_libraries(icsneopy PRIVATE icsneocpp)
|
||||
|
||||
install(TARGETS icsneopy LIBRARY DESTINATION icsneopy)
|
||||
|
||||
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()
|
||||
find_program(STUBGEN stubgen REQUIRED)
|
||||
add_custom_command(TARGET icsneopy POST_BUILD COMMAND ${STUBGEN} -m icsneopy -o .)
|
||||
|
||||
install(FILES __init__.py DESTINATION icsneopy)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/icsneopy.pyi __init__.py py.typed DESTINATION icsneopy)
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/api/event.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_event(pybind11::module_& m) {
|
||||
pybind11::classh<APIEvent> apiEvent(m, "APIEvent");
|
||||
pybind11::native_enum<APIEvent::Type>(apiEvent, "Type", "enum.IntEnum")
|
||||
pybind11::class_<APIEvent, std::shared_ptr<APIEvent>> apiEvent(m, "APIEvent");
|
||||
pybind11::enum_<APIEvent::Type>(apiEvent, "Type")
|
||||
.value("Any", APIEvent::Type::Any)
|
||||
.value("InvalidNeoDevice", APIEvent::Type::InvalidNeoDevice)
|
||||
.value("RequiredParameterNull", APIEvent::Type::RequiredParameterNull)
|
||||
@@ -29,9 +28,6 @@ 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)
|
||||
@@ -88,10 +84,6 @@ 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)
|
||||
@@ -108,6 +100,39 @@ 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)
|
||||
@@ -115,35 +140,16 @@ 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("ServdNotReachable", APIEvent::Type::ServdNotReachable)
|
||||
.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)
|
||||
.finalize();
|
||||
|
||||
pybind11::native_enum<APIEvent::Severity>(apiEvent, "Severity", "enum.IntEnum")
|
||||
.value("Unknown", APIEvent::Type::Unknown);
|
||||
|
||||
pybind11::enum_<APIEvent::Severity>(apiEvent, "Severity")
|
||||
.value("Any", APIEvent::Severity::Any)
|
||||
.value("EventInfo", APIEvent::Severity::EventInfo)
|
||||
.value("EventWarning", APIEvent::Severity::EventWarning)
|
||||
.value("Error", APIEvent::Severity::Error)
|
||||
.finalize();
|
||||
|
||||
.value("Error", APIEvent::Severity::Error);
|
||||
|
||||
apiEvent
|
||||
.def("get_type", &APIEvent::getType)
|
||||
.def("get_severity", &APIEvent::getSeverity)
|
||||
@@ -151,7 +157,7 @@ void init_event(pybind11::module_& m) {
|
||||
.def("describe", &APIEvent::describe)
|
||||
.def("__repr__", &APIEvent::describe);
|
||||
|
||||
pybind11::classh<EventFilter>(m, "EventFilter")
|
||||
pybind11::class_<EventFilter, std::shared_ptr<EventFilter>>(m, "EventFilter")
|
||||
.def(pybind11::init())
|
||||
.def(pybind11::init<APIEvent::Type>())
|
||||
.def(pybind11::init<APIEvent::Severity>())
|
||||
@@ -160,5 +166,5 @@ void init_event(pybind11::module_& m) {
|
||||
.def_readwrite("serial", &EventFilter::serial);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
} // namespace icsneo
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_eventcallback(pybind11::module_& m) {
|
||||
pybind11::classh<EventCallback>(m, "EventCallback")
|
||||
pybind11::class_<EventCallback>(m, "EventCallback")
|
||||
.def(pybind11::init<EventCallback::fn_eventCallback, EventFilter>())
|
||||
.def(pybind11::init<EventCallback::fn_eventCallback>());
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_eventmanager(pybind11::module_& m) {
|
||||
pybind11::classh<EventManager>(m, "EventManager")
|
||||
pybind11::class_<EventManager>(m, "EventManager")
|
||||
.def_static("get_instance", &EventManager::GetInstance, pybind11::return_value_policy::reference)
|
||||
.def("add_event_callback", &EventManager::addEventCallback)
|
||||
.def("remove_event_callback", &EventManager::removeEventCallback)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_version(pybind11::module_& m) {
|
||||
pybind11::classh<neoversion_t>(m, "NeoVersion")
|
||||
pybind11::class_<neoversion_t>(m, "NeoVersion")
|
||||
.def_readonly("major", &neoversion_t::major)
|
||||
.def_readonly("minor", &neoversion_t::minor)
|
||||
.def_readonly("patch", &neoversion_t::patch)
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#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
|
||||
@@ -1,79 +0,0 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/communication/livedata.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_livedata(pybind11::module_& m) {
|
||||
// LiveDataValue struct
|
||||
pybind11::classh<LiveDataValue>(m, "LiveDataValue")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("value", &LiveDataValue::value);
|
||||
|
||||
// LiveDataArgument struct
|
||||
pybind11::classh<LiveDataArgument>(m, "LiveDataArgument")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("object_type", &LiveDataArgument::objectType)
|
||||
.def_readwrite("object_index", &LiveDataArgument::objectIndex)
|
||||
.def_readwrite("signal_index", &LiveDataArgument::signalIndex)
|
||||
.def_readwrite("value_type", &LiveDataArgument::valueType);
|
||||
|
||||
// LiveDataCommand enum
|
||||
pybind11::native_enum<LiveDataCommand>(m, "LiveDataCommand", "enum.IntEnum")
|
||||
.value("STATUS", LiveDataCommand::STATUS)
|
||||
.value("SUBSCRIBE", LiveDataCommand::SUBSCRIBE)
|
||||
.value("UNSUBSCRIBE", LiveDataCommand::UNSUBSCRIBE)
|
||||
.value("RESPONSE", LiveDataCommand::RESPONSE)
|
||||
.value("CLEAR_ALL", LiveDataCommand::CLEAR_ALL)
|
||||
.value("SET_VALUE", LiveDataCommand::SET_VALUE)
|
||||
.finalize();
|
||||
|
||||
// LiveDataStatus enum
|
||||
pybind11::native_enum<LiveDataStatus>(m, "LiveDataStatus", "enum.IntEnum")
|
||||
.value("SUCCESS", LiveDataStatus::SUCCESS)
|
||||
.value("ERR_UNKNOWN_COMMAND", LiveDataStatus::ERR_UNKNOWN_COMMAND)
|
||||
.value("ERR_HANDLE", LiveDataStatus::ERR_HANDLE)
|
||||
.value("ERR_DUPLICATE", LiveDataStatus::ERR_DUPLICATE)
|
||||
.value("ERR_FULL", LiveDataStatus::ERR_FULL)
|
||||
.finalize();
|
||||
|
||||
// LiveDataObjectType enum
|
||||
pybind11::enum_<LiveDataObjectType>(m, "LiveDataObjectType")
|
||||
.value("MISC", LiveDataObjectType::MISC)
|
||||
.value("SNA", LiveDataObjectType::SNA)
|
||||
.export_values();
|
||||
|
||||
// LiveDataValueType enum
|
||||
pybind11::native_enum<LiveDataValueType>(m, "LiveDataValueType", "enum.IntEnum")
|
||||
.value("GPS_LATITUDE", LiveDataValueType::GPS_LATITUDE)
|
||||
.value("GPS_LONGITUDE", LiveDataValueType::GPS_LONGITUDE)
|
||||
.value("GPS_ALTITUDE", LiveDataValueType::GPS_ALTITUDE)
|
||||
.value("GPS_SPEED", LiveDataValueType::GPS_SPEED)
|
||||
.value("GPS_VALID", LiveDataValueType::GPS_VALID)
|
||||
.value("GPS_ENABLE", LiveDataValueType::GPS_ENABLE)
|
||||
.value("MANUAL_TRIGGER", LiveDataValueType::MANUAL_TRIGGER)
|
||||
.value("TIME_SINCE_MSG", LiveDataValueType::TIME_SINCE_MSG)
|
||||
.value("GPS_ACCURACY", LiveDataValueType::GPS_ACCURACY)
|
||||
.value("GPS_BEARING", LiveDataValueType::GPS_BEARING)
|
||||
.value("GPS_TIME", LiveDataValueType::GPS_TIME)
|
||||
.value("GPS_TIME_VALID", LiveDataValueType::GPS_TIME_VALID)
|
||||
.value("DAQ_ENABLE", LiveDataValueType::DAQ_ENABLE)
|
||||
.finalize();
|
||||
|
||||
// LiveDataUtil namespace functions
|
||||
m.def("get_new_handle", &LiveDataUtil::getNewHandle,
|
||||
"Generate a new unique LiveData handle");
|
||||
|
||||
m.def("livedata_value_to_double", &LiveDataUtil::liveDataValueToDouble,
|
||||
pybind11::arg("val"),
|
||||
"Convert LiveDataValue to double (32.32 fixed-point to floating-point)");
|
||||
|
||||
m.def("livedata_double_to_value", &LiveDataUtil::liveDataDoubleToValue,
|
||||
pybind11::arg("d"),
|
||||
"Convert double to LiveDataValue (32.32 fixed-point format). Returns LiveDataValue or None on failure.");
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -1,13 +0,0 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
#include "icsneo/communication/message/allmacaddressesmessage.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_allmacaddressesmessage(pybind11::module_& m) {
|
||||
pybind11::classh<AllMACAddressesMessage, Message>(m, "AllMACAddressesMessage")
|
||||
.def_readonly("addresses", &AllMACAddressesMessage::addresses);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -1,71 +0,0 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/communication/message/apperrormessage.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_errortypes(pybind11::module_& m) {
|
||||
pybind11::native_enum<AppErrorType>(m, "AppErrorType", "enum.IntEnum")
|
||||
.value("RxMessagesFull", AppErrorType::AppErrorRxMessagesFull)
|
||||
.value("TxMessagesFull", AppErrorType::AppErrorTxMessagesFull)
|
||||
.value("TxReportMessagesFull", AppErrorType::AppErrorTxReportMessagesFull)
|
||||
.value("BadCommWithDspIC", AppErrorType::AppErrorBadCommWithDspIC)
|
||||
.value("DriverOverflow", AppErrorType::AppErrorDriverOverflow)
|
||||
.value("PCBuffOverflow", AppErrorType::AppErrorPCBuffOverflow)
|
||||
.value("PCChksumError", AppErrorType::AppErrorPCChksumError)
|
||||
.value("PCMissedByte", AppErrorType::AppErrorPCMissedByte)
|
||||
.value("PCOverrunError", AppErrorType::AppErrorPCOverrunError)
|
||||
.value("SettingFailure", AppErrorType::AppErrorSettingFailure)
|
||||
.value("TooManySelectedNetworks", AppErrorType::AppErrorTooManySelectedNetworks)
|
||||
.value("NetworkNotEnabled", AppErrorType::AppErrorNetworkNotEnabled)
|
||||
.value("RtcNotCorrect", AppErrorType::AppErrorRtcNotCorrect)
|
||||
.value("LoadedDefaultSettings", AppErrorType::AppErrorLoadedDefaultSettings)
|
||||
.value("FeatureNotUnlocked", AppErrorType::AppErrorFeatureNotUnlocked)
|
||||
.value("FeatureRtcCmdDropped", AppErrorType::AppErrorFeatureRtcCmdDropped)
|
||||
.value("TxMessagesFlushed", AppErrorType::AppErrorTxMessagesFlushed)
|
||||
.value("TxMessagesHalfFull", AppErrorType::AppErrorTxMessagesHalfFull)
|
||||
.value("NetworkNotValid", AppErrorType::AppErrorNetworkNotValid)
|
||||
.value("TxInterfaceNotImplemented", AppErrorType::AppErrorTxInterfaceNotImplemented)
|
||||
.value("TxMessagesCommEnableIsOff", AppErrorType::AppErrorTxMessagesCommEnableIsOff)
|
||||
.value("RxFilterMatchCountExceeded", AppErrorType::AppErrorRxFilterMatchCountExceeded)
|
||||
.value("EthPreemptionNotEnabled", AppErrorType::AppErrorEthPreemptionNotEnabled)
|
||||
.value("TxNotSupportedInMode", AppErrorType::AppErrorTxNotSupportedInMode)
|
||||
.value("JumboFramesNotSupported", AppErrorType::AppErrorJumboFramesNotSupported)
|
||||
.value("EthernetIpFragment", AppErrorType::AppErrorEthernetIpFragment)
|
||||
.value("TxMessagesUnderrun", AppErrorType::AppErrorTxMessagesUnderrun)
|
||||
.value("DeviceFanFailure", AppErrorType::AppErrorDeviceFanFailure)
|
||||
.value("DeviceOvertemperature", AppErrorType::AppErrorDeviceOvertemperature)
|
||||
.value("TxMessageIndexOutOfRange", AppErrorType::AppErrorTxMessageIndexOutOfRange)
|
||||
.value("UndersizedFrameDropped", AppErrorType::AppErrorUndersizedFrameDropped)
|
||||
.value("OversizedFrameDropped", AppErrorType::AppErrorOversizedFrameDropped)
|
||||
.value("WatchdogEvent", AppErrorType::AppErrorWatchdogEvent)
|
||||
.value("SystemClockFailure", AppErrorType::AppErrorSystemClockFailure)
|
||||
.value("SystemClockRecovered", AppErrorType::AppErrorSystemClockRecovered)
|
||||
.value("SystemPeripheralReset", AppErrorType::AppErrorSystemPeripheralReset)
|
||||
.value("SystemCommunicationFailure", AppErrorType::AppErrorSystemCommunicationFailure)
|
||||
.value("TxMessagesUnsupportedSourceOrPacketId", AppErrorType::AppErrorTxMessagesUnsupportedSourceOrPacketId)
|
||||
.value("WbmsManagerConnectFailed", AppErrorType::AppErrorWbmsManagerConnectFailed)
|
||||
.value("WbmsManagerConnectBadState", AppErrorType::AppErrorWbmsManagerConnectBadState)
|
||||
.value("WbmsManagerConnectTimeout", AppErrorType::AppErrorWbmsManagerConnectTimeout)
|
||||
.value("FailedToInitializeLoggerDisk", AppErrorType::AppErrorFailedToInitializeLoggerDisk)
|
||||
.value("InvalidSetting", AppErrorType::AppErrorInvalidSetting)
|
||||
.value("SystemFailureRequestedReset", AppErrorType::AppErrorSystemFailureRequestedReset)
|
||||
.value("PortKeyMistmatch", AppErrorType::AppErrorPortKeyMistmatch)
|
||||
.value("BusFailure", AppErrorType::AppErrorBusFailure)
|
||||
.value("TapOverflow", AppErrorType::AppErrorTapOverflow)
|
||||
.value("EthTxNoLink", AppErrorType::AppErrorEthTxNoLink)
|
||||
.value("ErrorBufferOverflow", AppErrorType::AppErrorErrorBufferOverflow)
|
||||
.value("NoError", AppErrorType::AppNoError)
|
||||
.finalize();
|
||||
}
|
||||
|
||||
void init_apperrormessage(pybind11::module_& m) {
|
||||
init_errortypes(m);
|
||||
pybind11::classh<AppErrorMessage, Message>(m, "AppErrorMessage")
|
||||
.def("get_app_error_type", &AppErrorMessage::getAppErrorType)
|
||||
.def("get_app_error_string", &AppErrorMessage::getAppErrorString);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_messagecallback(pybind11::module_& m) {
|
||||
pybind11::classh<MessageCallback>(m, "MessageCallback")
|
||||
pybind11::class_<MessageCallback, std::shared_ptr<MessageCallback>>(m, "MessageCallback")
|
||||
.def(pybind11::init<MessageCallback::fn_messageCallback, std::shared_ptr<MessageFilter>>());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/communication/message/canerrormessage.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_errorcodes(pybind11::module_& m) {
|
||||
pybind11::native_enum<CANErrorCode>(m, "CANErrorCode", "enum.IntEnum")
|
||||
pybind11::enum_<CANErrorCode>(m, "CANErrorCode")
|
||||
.value("NoError", CANErrorCode::NoError)
|
||||
.value("StuffError", CANErrorCode::StuffError)
|
||||
.value("FormError", CANErrorCode::FormError)
|
||||
@@ -16,13 +15,12 @@ void init_errorcodes(pybind11::module_& m) {
|
||||
.value("Bit1Error", CANErrorCode::Bit1Error)
|
||||
.value("Bit0Error", CANErrorCode::Bit0Error)
|
||||
.value("CRCError", CANErrorCode::CRCError)
|
||||
.value("NoChange", CANErrorCode::NoChange)
|
||||
.finalize();
|
||||
.value("NoChange", CANErrorCode::NoChange);
|
||||
}
|
||||
|
||||
void init_canerrormessage(pybind11::module_& m) {
|
||||
init_errorcodes(m);
|
||||
pybind11::classh<CANErrorMessage, Message>(m, "CANErrorMessage")
|
||||
pybind11::class_<CANErrorMessage, std::shared_ptr<CANErrorMessage>, Message>(m, "CANErrorMessage")
|
||||
.def_readonly("network", &CANErrorMessage::network)
|
||||
.def_readonly("transmitErrorCount", &CANErrorMessage::transmitErrorCount)
|
||||
.def_readonly("receiveErrorCount", &CANErrorMessage::receiveErrorCount)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_canmessage(pybind11::module_& m) {
|
||||
pybind11::classh<CANMessage, Frame>(m, "CANMessage")
|
||||
pybind11::class_<CANMessage, std::shared_ptr<CANMessage>, BusMessage>(m, "CANMessage")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("arbid", &CANMessage::arbid)
|
||||
.def_readwrite("dlcOnWire", &CANMessage::dlcOnWire)
|
||||
@@ -15,10 +15,7 @@ void init_canmessage(pybind11::module_& m) {
|
||||
.def_readwrite("isExtended", &CANMessage::isExtended)
|
||||
.def_readwrite("isCANFD", &CANMessage::isCANFD)
|
||||
.def_readwrite("baudrateSwitch", &CANMessage::baudrateSwitch)
|
||||
.def_readwrite("errorStateIndicator", &CANMessage::errorStateIndicator)
|
||||
.def_readwrite("txAborted", &CANMessage::txAborted)
|
||||
.def_readwrite("txLostArb", &CANMessage::txLostArb)
|
||||
.def_readwrite("txError", &CANMessage::txError);
|
||||
.def_readwrite("errorStateIndicator", &CANMessage::errorStateIndicator);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -7,29 +7,21 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_ethernetmessage(pybind11::module_& m) {
|
||||
pybind11::classh<EthernetMessage::T1S>(m, "EthernetMessageT1S")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("isSymbol", &EthernetMessage::T1S::isSymbol)
|
||||
.def_readwrite("isBurst", &EthernetMessage::T1S::isBurst)
|
||||
.def_readwrite("txCollision", &EthernetMessage::T1S::txCollision)
|
||||
.def_readwrite("isWake", &EthernetMessage::T1S::isWake)
|
||||
.def_readwrite("nodeId", &EthernetMessage::T1S::nodeId)
|
||||
.def_readwrite("burstCount", &EthernetMessage::T1S::burstCount)
|
||||
.def_readwrite("symbolType", &EthernetMessage::T1S::symbolType);
|
||||
|
||||
pybind11::classh<EthernetMessage, Frame>(m, "EthernetMessage")
|
||||
pybind11::class_<MACAddress>(m, "MACAddress")
|
||||
.def("to_string", &MACAddress::toString)
|
||||
.def("__repr__", &MACAddress::toString);
|
||||
|
||||
pybind11::class_<EthernetMessage, std::shared_ptr<EthernetMessage>, BusMessage>(m, "EthernetMessage")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("preemptionEnabled", &EthernetMessage::preemptionEnabled)
|
||||
.def_readwrite("preemptionFlags", &EthernetMessage::preemptionFlags)
|
||||
.def_readwrite("fcs", &EthernetMessage::fcs)
|
||||
.def_readwrite("frameTooShort", &EthernetMessage::frameTooShort)
|
||||
.def_readwrite("noPadding", &EthernetMessage::noPadding)
|
||||
.def_readwrite("fcsVerified", &EthernetMessage::fcsVerified)
|
||||
.def_readwrite("txAborted", &EthernetMessage::txAborted)
|
||||
.def_readwrite("crcError", &EthernetMessage::crcError)
|
||||
.def_readwrite("t1s", &EthernetMessage::t1s)
|
||||
.def_readwrite("preemptionFlags", &EthernetMessage::preemptionFlags)
|
||||
.def("get_destination_mac", &EthernetMessage::getDestinationMAC)
|
||||
.def("get_source_mac", &EthernetMessage::getSourceMAC)
|
||||
.def("get_destination_mac", &EthernetMessage::getDestinationMAC, pybind11::return_value_policy::reference)
|
||||
.def("get_source_mac", &EthernetMessage::getSourceMAC, pybind11::return_value_policy::reference)
|
||||
.def("get_ether_type", &EthernetMessage::getEtherType);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_ethernetstatusmessage(pybind11::module_& m) {
|
||||
pybind11::classh<EthernetStatusMessage, RawMessage> ethernetStatusMessage(m, "EthernetStatusMessage");
|
||||
pybind11::class_<EthernetStatusMessage, std::shared_ptr<EthernetStatusMessage>, Message> ethernetStatusMessage(m, "EthernetStatusMessage");
|
||||
|
||||
pybind11::enum_<EthernetStatusMessage::LinkSpeed>(ethernetStatusMessage, "LinkSpeed")
|
||||
.value("LinkSpeedAuto", EthernetStatusMessage::LinkSpeed::LinkSpeedAuto)
|
||||
@@ -22,8 +22,7 @@ void init_ethernetstatusmessage(pybind11::module_& m) {
|
||||
.value("LinkModeAuto", EthernetStatusMessage::LinkMode::LinkModeAuto)
|
||||
.value("LinkModeMaster", EthernetStatusMessage::LinkMode::LinkModeMaster)
|
||||
.value("LinkModeSlave", EthernetStatusMessage::LinkMode::LinkModeSlave)
|
||||
.value("LinkModeInvalid", EthernetStatusMessage::LinkMode::LinkModeInvalid)
|
||||
.value("LinkModeNone", EthernetStatusMessage::LinkMode::LinkModeNone);
|
||||
.value("LinkModeInvalid", EthernetStatusMessage::LinkMode::LinkModeInvalid);
|
||||
|
||||
ethernetStatusMessage
|
||||
.def_readonly("network", &EthernetStatusMessage::network)
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
#include "icsneo/communication/message/ethphymessage.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_ethphymessage(pybind11::module_& m) {
|
||||
pybind11::classh<Clause22Message>(m, "Clause22Message")
|
||||
.def_readwrite("phyAddr", &Clause22Message::phyAddr)
|
||||
.def_readwrite("page", &Clause22Message::page)
|
||||
.def_readwrite("regAddr", &Clause22Message::regAddr)
|
||||
.def_readwrite("regVal", &Clause22Message::regVal);
|
||||
pybind11::classh<Clause45Message>(m, "Clause45Message")
|
||||
.def_readwrite("port", &Clause45Message::port)
|
||||
.def_readwrite("device", &Clause45Message::device)
|
||||
.def_readwrite("regAddr", &Clause45Message::regAddr)
|
||||
.def_readwrite("regVal", &Clause45Message::regVal);
|
||||
pybind11::classh<PhyMessage>(m, "PhyMessage")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("Enabled", &PhyMessage::Enabled)
|
||||
.def_readwrite("WriteEnable", &PhyMessage::WriteEnable)
|
||||
.def_readwrite("Clause45Enable", &PhyMessage::Clause45Enable)
|
||||
.def_readwrite("Version", &PhyMessage::Version)
|
||||
.def_readwrite("BusIndex", &PhyMessage::BusIndex)
|
||||
.def_readwrite("Clause22", &PhyMessage::Clause22)
|
||||
.def_readwrite("Clause45", &PhyMessage::Clause45);
|
||||
pybind11::classh<EthPhyMessage, Message>(m, "EthPhyMessage")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("messages", &EthPhyMessage::messages);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_messagefilter(pybind11::module_& m) {
|
||||
pybind11::classh<MessageFilter>(m, "MessageFilter")
|
||||
pybind11::class_<MessageFilter, std::shared_ptr<MessageFilter>>(m, "MessageFilter")
|
||||
.def(pybind11::init())
|
||||
.def(pybind11::init<Message::Type>())
|
||||
.def(pybind11::init<Network::NetID>());
|
||||
|
||||
@@ -7,73 +7,72 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_gptpstatusmessage(pybind11::module_& m) {
|
||||
pybind11::classh<GPTPStatus, Message> gptpStatus(m, "GPTPStatus");
|
||||
pybind11::class_<GPTPStatus, std::shared_ptr<GPTPStatus>, Message> gptpStatus(m, "GPTPStatus");
|
||||
|
||||
pybind11::classh<GPTPStatus::Timestamp>(gptpStatus, "Timestamp")
|
||||
pybind11::class_<GPTPStatus::Timestamp>(gptpStatus, "Timestamp")
|
||||
.def_readonly("seconds", &GPTPStatus::Timestamp::seconds)
|
||||
.def_readonly("nanoseconds", &GPTPStatus::Timestamp::nanoseconds)
|
||||
.def("to_seconds", &GPTPStatus::Timestamp::toSeconds, pybind11::call_guard<pybind11::gil_scoped_release>());
|
||||
|
||||
pybind11::classh<GPTPStatus::ScaledNanoSeconds>(gptpStatus, "ScaledNanoSeconds")
|
||||
.def_readonly("nanoseconds_msb", &GPTPStatus::ScaledNanoSeconds::nanosecondsMSB)
|
||||
.def_readonly("nanoseconds_lsb", &GPTPStatus::ScaledNanoSeconds::nanosecondsLSB)
|
||||
.def_readonly("fractional_nanoseconds", &GPTPStatus::ScaledNanoSeconds::fractionalNanoseconds);
|
||||
pybind11::class_<GPTPStatus::ScaledNanoSeconds>(gptpStatus, "ScaledNanoSeconds")
|
||||
.def_readonly("nanosecondsMSB", &GPTPStatus::ScaledNanoSeconds::nanosecondsMSB)
|
||||
.def_readonly("nanosecondsLSB", &GPTPStatus::ScaledNanoSeconds::nanosecondsLSB)
|
||||
.def_readonly("fractionalNanoseconds", &GPTPStatus::ScaledNanoSeconds::fractionalNanoseconds);
|
||||
|
||||
pybind11::classh<GPTPStatus::PortID>(gptpStatus, "PortID")
|
||||
.def_readonly("clock_identity", &GPTPStatus::PortID::clockIdentity)
|
||||
.def_readonly("port_number", &GPTPStatus::PortID::portNumber);
|
||||
pybind11::class_<GPTPStatus::PortID>(gptpStatus, "PortID")
|
||||
.def_readonly("clockIdentity", &GPTPStatus::PortID::clockIdentity)
|
||||
.def_readonly("portNumber", &GPTPStatus::PortID::portNumber);
|
||||
|
||||
pybind11::classh<GPTPStatus::ClockQuality>(gptpStatus, "ClockQuality")
|
||||
.def_readonly("clock_class", &GPTPStatus::ClockQuality::clockClass)
|
||||
.def_readonly("clock_accuracy", &GPTPStatus::ClockQuality::clockAccuracy)
|
||||
.def_readonly("offset_scaled_log_variance", &GPTPStatus::ClockQuality::offsetScaledLogVariance);
|
||||
pybind11::class_<GPTPStatus::ClockQuality>(gptpStatus, "ClockQuality")
|
||||
.def_readonly("clockClass", &GPTPStatus::ClockQuality::clockClass)
|
||||
.def_readonly("clockAccuracy", &GPTPStatus::ClockQuality::clockAccuracy)
|
||||
.def_readonly("offsetScaledLogVariance", &GPTPStatus::ClockQuality::offsetScaledLogVariance);
|
||||
|
||||
pybind11::classh<GPTPStatus::SystemID>(gptpStatus, "SystemID")
|
||||
pybind11::class_<GPTPStatus::SystemID>(gptpStatus, "SystemID")
|
||||
.def_readonly("priority1", &GPTPStatus::SystemID::priority1)
|
||||
.def_readonly("clock_quality", &GPTPStatus::SystemID::clockQuality)
|
||||
.def_readonly("clockQuality", &GPTPStatus::SystemID::clockQuality)
|
||||
.def_readonly("priority2", &GPTPStatus::SystemID::priority2)
|
||||
.def_readonly("clock_id", &GPTPStatus::SystemID::clockID);
|
||||
.def_readonly("clockID", &GPTPStatus::SystemID::clockID);
|
||||
|
||||
pybind11::classh<GPTPStatus::PriorityVector>(gptpStatus, "PriorityVector")
|
||||
.def_readonly("sys_id", &GPTPStatus::PriorityVector::sysID)
|
||||
.def_readonly("steps_removed", &GPTPStatus::PriorityVector::stepsRemoved)
|
||||
.def_readonly("port_id", &GPTPStatus::PriorityVector::portID)
|
||||
.def_readonly("port_number", &GPTPStatus::PriorityVector::portNumber);
|
||||
pybind11::class_<GPTPStatus::PriorityVector>(gptpStatus, "PriorityVector")
|
||||
.def_readonly("sysID", &GPTPStatus::PriorityVector::sysID)
|
||||
.def_readonly("stepsRemoved", &GPTPStatus::PriorityVector::stepsRemoved)
|
||||
.def_readonly("portID", &GPTPStatus::PriorityVector::portID)
|
||||
.def_readonly("portNumber", &GPTPStatus::PriorityVector::portNumber);
|
||||
|
||||
pybind11::classh<GPTPStatus::ParentDS>(gptpStatus, "ParentDS")
|
||||
.def_readonly("parent_port_identity", &GPTPStatus::ParentDS::parentPortIdentity)
|
||||
.def_readonly("cumulative_rate_ratio", &GPTPStatus::ParentDS::cumulativeRateRatio)
|
||||
.def_readonly("grandmaster_identity", &GPTPStatus::ParentDS::grandmasterIdentity)
|
||||
.def_readonly("gm_clock_quality_clock_class", &GPTPStatus::ParentDS::gmClockQualityClockClass)
|
||||
.def_readonly("gm_clock_quality_clock_accuracy", &GPTPStatus::ParentDS::gmClockQualityClockAccuracy)
|
||||
.def_readonly("gm_clock_quality_offset_scaled_log_variance", &GPTPStatus::ParentDS::gmClockQualityOffsetScaledLogVariance)
|
||||
.def_readonly("gm_priority1", &GPTPStatus::ParentDS::gmPriority1)
|
||||
.def_readonly("gm_priority2", &GPTPStatus::ParentDS::gmPriority2);
|
||||
pybind11::class_<GPTPStatus::ParentDS>(gptpStatus, "ParentDS")
|
||||
.def_readonly("parentPortIdentity", &GPTPStatus::ParentDS::parentPortIdentity)
|
||||
.def_readonly("cumulativeRateRatio", &GPTPStatus::ParentDS::cumulativeRateRatio)
|
||||
.def_readonly("grandmasterIdentity", &GPTPStatus::ParentDS::grandmasterIdentity)
|
||||
.def_readonly("gmClockQualityClockClass", &GPTPStatus::ParentDS::gmClockQualityClockClass)
|
||||
.def_readonly("gmClockQualityClockAccuracy", &GPTPStatus::ParentDS::gmClockQualityClockAccuracy)
|
||||
.def_readonly("gmClockQualityOffsetScaledLogVariance", &GPTPStatus::ParentDS::gmClockQualityOffsetScaledLogVariance)
|
||||
.def_readonly("gmPriority1", &GPTPStatus::ParentDS::gmPriority1)
|
||||
.def_readonly("gmPriority2", &GPTPStatus::ParentDS::gmPriority2);
|
||||
|
||||
pybind11::classh<GPTPStatus::CurrentDS>(gptpStatus, "CurrentDS")
|
||||
.def_readonly("steps_removed", &GPTPStatus::CurrentDS::stepsRemoved)
|
||||
.def_readonly("offset_from_master", &GPTPStatus::CurrentDS::offsetFromMaster)
|
||||
.def_readonly("lastgm_phase_change", &GPTPStatus::CurrentDS::lastgmPhaseChange)
|
||||
.def_readonly("lastgm_freq_change", &GPTPStatus::CurrentDS::lastgmFreqChange)
|
||||
.def_readonly("gm_time_base_indicator", &GPTPStatus::CurrentDS::gmTimeBaseIndicator)
|
||||
.def_readonly("gm_change_count", &GPTPStatus::CurrentDS::gmChangeCount)
|
||||
.def_readonly("time_of_lastgm_change_event", &GPTPStatus::CurrentDS::timeOfLastgmChangeEvent)
|
||||
.def_readonly("time_of_lastgm_phase_change_event", &GPTPStatus::CurrentDS::timeOfLastgmPhaseChangeEvent)
|
||||
.def_readonly("time_of_lastgm_freq_change_event", &GPTPStatus::CurrentDS::timeOfLastgmFreqChangeEvent);
|
||||
pybind11::class_<GPTPStatus::CurrentDS>(gptpStatus, "CurrentDS")
|
||||
.def_readonly("stepsRemoved", &GPTPStatus::CurrentDS::stepsRemoved)
|
||||
.def_readonly("offsetFromMaster", &GPTPStatus::CurrentDS::offsetFromMaster)
|
||||
.def_readonly("lastgmPhaseChange", &GPTPStatus::CurrentDS::lastgmPhaseChange)
|
||||
.def_readonly("lastgmFreqChange", &GPTPStatus::CurrentDS::lastgmFreqChange)
|
||||
.def_readonly("gmTimeBaseIndicator", &GPTPStatus::CurrentDS::gmTimeBaseIndicator)
|
||||
.def_readonly("gmChangeCount", &GPTPStatus::CurrentDS::gmChangeCount)
|
||||
.def_readonly("timeOfLastgmChangeEvent", &GPTPStatus::CurrentDS::timeOfLastgmChangeEvent)
|
||||
.def_readonly("timeOfLastgmPhaseChangeEvent", &GPTPStatus::CurrentDS::timeOfLastgmPhaseChangeEvent)
|
||||
.def_readonly("timeOfLastgmFreqChangeEvent", &GPTPStatus::CurrentDS::timeOfLastgmFreqChangeEvent);
|
||||
|
||||
gptpStatus.def_readonly("current_time", &GPTPStatus::currentTime)
|
||||
.def_readonly("gm_priority", &GPTPStatus::gmPriority)
|
||||
.def_readonly("ms_offset_ns", &GPTPStatus::msOffsetNs)
|
||||
.def_readonly("is_sync", &GPTPStatus::isSync)
|
||||
.def_readonly("link_status", &GPTPStatus::linkStatus)
|
||||
.def_readonly("link_delay_ns", &GPTPStatus::linkDelayNS)
|
||||
.def_readonly("selected_role", &GPTPStatus::selectedRole)
|
||||
.def_readonly("as_capable", &GPTPStatus::asCapable)
|
||||
.def_readonly("is_syntonized", &GPTPStatus::isSyntonized)
|
||||
.def_readonly("last_rx_sync_ts", &GPTPStatus::lastRXSyncTS)
|
||||
.def_readonly("current_ds", &GPTPStatus::currentDS)
|
||||
.def_readonly("parent_ds", &GPTPStatus::parentDS)
|
||||
.def_readonly("short_format", &GPTPStatus::shortFormat);
|
||||
gptpStatus.def_readonly("currentTime", &GPTPStatus::currentTime)
|
||||
.def_readonly("gmPriority", &GPTPStatus::gmPriority)
|
||||
.def_readonly("msOffsetNs", &GPTPStatus::msOffsetNs)
|
||||
.def_readonly("isSync", &GPTPStatus::isSync)
|
||||
.def_readonly("linkStatus", &GPTPStatus::linkStatus)
|
||||
.def_readonly("linkDelayNS", &GPTPStatus::linkDelayNS)
|
||||
.def_readonly("selectedRole", &GPTPStatus::selectedRole)
|
||||
.def_readonly("asCapable", &GPTPStatus::asCapable)
|
||||
.def_readonly("isSyntonized", &GPTPStatus::isSyntonized)
|
||||
.def_readonly("lastRXSyncTS", &GPTPStatus::lastRXSyncTS)
|
||||
.def_readonly("currentDS", &GPTPStatus::currentDS)
|
||||
.def_readonly("parentDS", &GPTPStatus::parentDS);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_linmessage(pybind11::module_& m) {
|
||||
pybind11::classh<LINErrorFlags>(m, "LINErrorFlags")
|
||||
pybind11::class_<LINErrorFlags>(m, "LINErrorFlags")
|
||||
.def_readwrite("ErrRxBreakOnly", &LINErrorFlags::ErrRxBreakOnly)
|
||||
.def_readwrite("ErrRxBreakSyncOnly", &LINErrorFlags::ErrRxBreakSyncOnly)
|
||||
.def_readwrite("ErrTxRxMismatch", &LINErrorFlags::ErrTxRxMismatch)
|
||||
@@ -20,7 +20,7 @@ void init_linmessage(pybind11::module_& m) {
|
||||
.def_readwrite("ErrFrameResponderData", &LINErrorFlags::ErrFrameResponderData)
|
||||
.def_readwrite("ErrChecksumMatch", &LINErrorFlags::ErrChecksumMatch);
|
||||
|
||||
pybind11::classh<LINStatusFlags>(m, "LINStatusFlags")
|
||||
pybind11::class_<LINStatusFlags>(m, "LINStatusFlags")
|
||||
.def_readwrite("TxChecksumEnhanced", &LINStatusFlags::TxChecksumEnhanced)
|
||||
.def_readwrite("TxCommander", &LINStatusFlags::TxCommander)
|
||||
.def_readwrite("TxResponder", &LINStatusFlags::TxResponder)
|
||||
@@ -30,7 +30,7 @@ void init_linmessage(pybind11::module_& m) {
|
||||
.def_readwrite("BusRecovered", &LINStatusFlags::BusRecovered)
|
||||
.def_readwrite("BreakOnly", &LINStatusFlags::BreakOnly);
|
||||
|
||||
pybind11::classh<LINMessage, Frame> linMessage(m, "LINMessage");
|
||||
pybind11::class_<LINMessage, std::shared_ptr<LINMessage>, BusMessage> linMessage(m, "LINMessage");
|
||||
|
||||
pybind11::enum_<LINMessage::Type>(linMessage, "Type")
|
||||
.value("NOT_SET", LINMessage::Type::NOT_SET)
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/chrono.h>
|
||||
|
||||
#include "icsneo/communication/message/livedatamessage.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_livedatamessage(pybind11::module_& m) {
|
||||
// LiveDataMessage base class
|
||||
pybind11::classh<LiveDataMessage, RawMessage>(m, "LiveDataMessage")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("handle", &LiveDataMessage::handle)
|
||||
.def_readwrite("cmd", &LiveDataMessage::cmd);
|
||||
|
||||
// LiveDataCommandMessage (for subscribe/unsubscribe)
|
||||
pybind11::classh<LiveDataCommandMessage, LiveDataMessage>(m, "LiveDataCommandMessage")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("update_period", &LiveDataCommandMessage::updatePeriod)
|
||||
.def_readwrite("expiration_time", &LiveDataCommandMessage::expirationTime)
|
||||
.def_readwrite("args", &LiveDataCommandMessage::args)
|
||||
.def("append_signal_arg", &LiveDataCommandMessage::appendSignalArg,
|
||||
pybind11::arg("value_type"),
|
||||
"Append a signal argument to the command message");
|
||||
|
||||
// LiveDataValueMessage (received values)
|
||||
pybind11::classh<LiveDataValueMessage, LiveDataMessage>(m, "LiveDataValueMessage")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("num_args", &LiveDataValueMessage::numArgs)
|
||||
.def_readwrite("values", &LiveDataValueMessage::values);
|
||||
|
||||
// LiveDataStatusMessage (status responses)
|
||||
pybind11::classh<LiveDataStatusMessage, LiveDataMessage>(m, "LiveDataStatusMessage")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("requested_command", &LiveDataStatusMessage::requestedCommand)
|
||||
.def_readwrite("status", &LiveDataStatusMessage::status);
|
||||
|
||||
// LiveDataSetValueMessage (for setting values)
|
||||
pybind11::classh<LiveDataSetValueMessage, LiveDataMessage>(m, "LiveDataSetValueMessage")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("args", &LiveDataSetValueMessage::args)
|
||||
.def_readwrite("values", &LiveDataSetValueMessage::values)
|
||||
.def("append_set_value", &LiveDataSetValueMessage::appendSetValue,
|
||||
pybind11::arg("value_type"),
|
||||
pybind11::arg("value"),
|
||||
"Append a value to set in the message");
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace icsneo {
|
||||
|
||||
void init_mdiomessage(pybind11::module_& m) {
|
||||
pybind11::classh<MDIOMessage, Frame> mdioMessage(m, "MDIOMessage");
|
||||
pybind11::class_<MDIOMessage, std::shared_ptr<MDIOMessage>, BusMessage> mdioMessage(m, "MDIOMessage");
|
||||
pybind11::enum_<MDIOMessage::Clause>(mdioMessage, "Clause")
|
||||
.value("Clause45", MDIOMessage::Clause::Clause45)
|
||||
.value("Clause22", MDIOMessage::Clause::Clause22);
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/communication/message/message.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_message(pybind11::module_& m) {
|
||||
// Using py::smart_holder for safer lifetime management
|
||||
pybind11::classh<Message> message(m, "Message");
|
||||
pybind11::native_enum<Message::Type>(message, "Type", "enum.IntEnum")
|
||||
.value("Frame", Message::Type::Frame)
|
||||
pybind11::class_<Message, std::shared_ptr<Message>> message(m, "Message");
|
||||
pybind11::enum_<Message::Type>(message, "Type")
|
||||
.value("BusMessage", Message::Type::BusMessage)
|
||||
.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("RawMessage", Message::Type::RawMessage)
|
||||
.value("InternalMessage", Message::Type::InternalMessage)
|
||||
.value("ReadSettings", Message::Type::ReadSettings)
|
||||
.value("ResetStatus", Message::Type::ResetStatus)
|
||||
.value("DeviceVersion", Message::Type::DeviceVersion)
|
||||
@@ -36,21 +34,20 @@ void init_message(pybind11::module_& m) {
|
||||
.value("TC10Status", Message::Type::TC10Status)
|
||||
.value("AppError", Message::Type::AppError)
|
||||
.value("GPTPStatus", Message::Type::GPTPStatus)
|
||||
.value("EthernetStatus", Message::Type::EthernetStatus)
|
||||
.finalize();
|
||||
.value("EthernetStatus", Message::Type::EthernetStatus);
|
||||
|
||||
message.def(pybind11::init<Message::Type>());
|
||||
message.def_readonly("type", &Message::type);
|
||||
message.def_readwrite("timestamp", &Message::timestamp);
|
||||
|
||||
pybind11::classh<RawMessage, Message>(m, "RawMessage")
|
||||
.def_readwrite("network", &RawMessage::network)
|
||||
.def_readwrite("data", &RawMessage::data);
|
||||
pybind11::class_<InternalMessage, std::shared_ptr<InternalMessage>, Message>(m, "InternalMessage")
|
||||
.def_readwrite("network", &InternalMessage::network)
|
||||
.def_readwrite("data", &InternalMessage::data);
|
||||
|
||||
pybind11::classh<Frame, RawMessage>(m, "Frame")
|
||||
.def_readwrite("description", &Frame::description)
|
||||
.def_readwrite("transmitted", &Frame::transmitted)
|
||||
.def_readwrite("error", &Frame::error);
|
||||
pybind11::class_<BusMessage, std::shared_ptr<BusMessage>, InternalMessage>(m, "BusMessage")
|
||||
.def_readwrite("description", &BusMessage::description)
|
||||
.def_readwrite("transmitted", &BusMessage::transmitted)
|
||||
.def_readwrite("error", &BusMessage::error);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#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::classh<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
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
#include "icsneo/communication/message/spimessage.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_spimessage(pybind11::module_& m) {
|
||||
pybind11::classh<SPIMessage, Frame> spiMessage(m, "SPIMessage");
|
||||
pybind11::enum_<SPIMessage::Direction>(spiMessage, "Direction")
|
||||
.value("Write", SPIMessage::Direction::Write)
|
||||
.value("Read", SPIMessage::Direction::Read);
|
||||
spiMessage
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("direction", &SPIMessage::direction)
|
||||
.def_readwrite("address", &SPIMessage::address)
|
||||
.def_readwrite("mms", &SPIMessage::mms)
|
||||
.def_readwrite("stats", &SPIMessage::stats)
|
||||
.def_readwrite("payload", &SPIMessage::payload);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -17,7 +17,7 @@ void init_tc10statusmessage(pybind11::module_& m) {
|
||||
.value("SleepFailed", TC10SleepStatus::SleepFailed)
|
||||
.value("SleepAborted", TC10SleepStatus::SleepAborted);
|
||||
|
||||
pybind11::classh<TC10StatusMessage, Message>(m, "TC10StatusMessage")
|
||||
pybind11::class_<TC10StatusMessage, std::shared_ptr<TC10StatusMessage>, Message>(m, "TC10StatusMessage")
|
||||
.def_readonly("wakeStatus", &TC10StatusMessage::wakeStatus)
|
||||
.def_readonly("sleepStatus", &TC10StatusMessage::sleepStatus);
|
||||
}
|
||||
|
||||
@@ -1,36 +1,35 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/communication/network.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_network(pybind11::module_& m) {
|
||||
pybind11::classh<Network> network(m, "Network");
|
||||
pybind11::class_<Network> network(m, "Network");
|
||||
|
||||
pybind11::native_enum<Network::NetID>(network, "NetID", "enum.IntEnum")
|
||||
pybind11::enum_<Network::NetID>(network, "NetID")
|
||||
.value("Device", Network::NetID::Device)
|
||||
.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("HSCAN", Network::NetID::HSCAN)
|
||||
.value("MSCAN", Network::NetID::MSCAN)
|
||||
.value("SWCAN", Network::NetID::SWCAN)
|
||||
.value("LSFTCAN", Network::NetID::LSFTCAN)
|
||||
.value("FordSCP", Network::NetID::FordSCP)
|
||||
.value("J1708", Network::NetID::J1708)
|
||||
.value("Aux", Network::NetID::Aux)
|
||||
.value("J1850VPW", Network::NetID::J1850VPW)
|
||||
.value("ISO9141_01", Network::NetID::ISO9141_01)
|
||||
.value("ISO9141", Network::NetID::ISO9141)
|
||||
.value("DiskData", Network::NetID::DiskData)
|
||||
.value("Main51", Network::NetID::Main51)
|
||||
.value("RED", Network::NetID::RED)
|
||||
.value("SCI", Network::NetID::SCI)
|
||||
.value("ISO9141_02", Network::NetID::ISO9141_02)
|
||||
.value("ISO9141_2", Network::NetID::ISO9141_2)
|
||||
.value("ISO14230", Network::NetID::ISO14230)
|
||||
.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("LIN", Network::NetID::LIN)
|
||||
.value("OP_Ethernet1", Network::NetID::OP_Ethernet1)
|
||||
.value("OP_Ethernet2", Network::NetID::OP_Ethernet2)
|
||||
.value("OP_Ethernet3", Network::NetID::OP_Ethernet3)
|
||||
.value("RED_EXT_MEMORYREAD", Network::NetID::RED_EXT_MEMORYREAD)
|
||||
.value("RED_INT_MEMORYREAD", Network::NetID::RED_INT_MEMORYREAD)
|
||||
.value("RED_DFLASH_READ", Network::NetID::RED_DFLASH_READ)
|
||||
@@ -52,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_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("ISO9141_3", Network::NetID::ISO9141_3)
|
||||
.value("HSCAN2", Network::NetID::HSCAN2)
|
||||
.value("HSCAN3", Network::NetID::HSCAN3)
|
||||
.value("OP_Ethernet4", Network::NetID::OP_Ethernet4)
|
||||
.value("OP_Ethernet5", Network::NetID::OP_Ethernet5)
|
||||
.value("ISO9141_4", Network::NetID::ISO9141_4)
|
||||
.value("LIN2", Network::NetID::LIN2)
|
||||
.value("LIN3", Network::NetID::LIN3)
|
||||
.value("LIN4", Network::NetID::LIN4)
|
||||
.value("RED_App_Error", Network::NetID::RED_App_Error)
|
||||
.value("CGI", Network::NetID::CGI)
|
||||
.value("Reset_Status", Network::NetID::Reset_Status)
|
||||
@@ -70,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("DWCAN_04", Network::NetID::DWCAN_04)
|
||||
.value("DWCAN_05", Network::NetID::DWCAN_05)
|
||||
.value("HSCAN4", Network::NetID::HSCAN4)
|
||||
.value("HSCAN5", Network::NetID::HSCAN5)
|
||||
.value("RS232", Network::NetID::RS232)
|
||||
.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("UART", Network::NetID::UART)
|
||||
.value("UART2", Network::NetID::UART2)
|
||||
.value("UART3", Network::NetID::UART3)
|
||||
.value("UART4", Network::NetID::UART4)
|
||||
.value("SWCAN2", Network::NetID::SWCAN2)
|
||||
.value("Ethernet_DAQ", Network::NetID::Ethernet_DAQ)
|
||||
.value("Data_To_Host", Network::NetID::Data_To_Host)
|
||||
.value("TextAPI_To_Host", Network::NetID::TextAPI_To_Host)
|
||||
.value("SPI_01", Network::NetID::SPI_01)
|
||||
.value("AE_06", Network::NetID::AE_06)
|
||||
.value("SPI1", Network::NetID::SPI1)
|
||||
.value("OP_Ethernet6", Network::NetID::OP_Ethernet6)
|
||||
.value("Red_VBat", Network::NetID::Red_VBat)
|
||||
.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("OP_Ethernet7", Network::NetID::OP_Ethernet7)
|
||||
.value("OP_Ethernet8", Network::NetID::OP_Ethernet8)
|
||||
.value("OP_Ethernet9", Network::NetID::OP_Ethernet9)
|
||||
.value("OP_Ethernet10", Network::NetID::OP_Ethernet10)
|
||||
.value("OP_Ethernet11", Network::NetID::OP_Ethernet11)
|
||||
.value("FlexRay1a", Network::NetID::FlexRay1a)
|
||||
.value("FlexRay1b", Network::NetID::FlexRay1b)
|
||||
.value("FlexRay2a", Network::NetID::FlexRay2a)
|
||||
.value("FlexRay2b", Network::NetID::FlexRay2b)
|
||||
.value("LIN5", Network::NetID::LIN5)
|
||||
.value("FlexRay", Network::NetID::FlexRay)
|
||||
.value("FlexRay2", Network::NetID::FlexRay2)
|
||||
.value("OP_Ethernet12", Network::NetID::OP_Ethernet12)
|
||||
.value("I2C", Network::NetID::I2C)
|
||||
.value("MOST25", Network::NetID::MOST25)
|
||||
.value("MOST50", Network::NetID::MOST50)
|
||||
.value("MOST150", Network::NetID::MOST150)
|
||||
.value("Ethernet", Network::NetID::Ethernet)
|
||||
.value("GMFSA", Network::NetID::GMFSA)
|
||||
.value("TCP", Network::NetID::TCP)
|
||||
.value("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("HSCAN6", Network::NetID::HSCAN6)
|
||||
.value("HSCAN7", Network::NetID::HSCAN7)
|
||||
.value("LIN6", Network::NetID::LIN6)
|
||||
.value("LSFTCAN2", Network::NetID::LSFTCAN2)
|
||||
.value("LogicalDiskInfo", Network::NetID::LogicalDiskInfo)
|
||||
.value("WiVICommand", Network::NetID::WiVICommand)
|
||||
.value("ScriptStatus", Network::NetID::ScriptStatus)
|
||||
@@ -120,57 +119,55 @@ void init_network(pybind11::module_& m) {
|
||||
.value("DeviceStatus", Network::NetID::DeviceStatus)
|
||||
.value("UDP", Network::NetID::UDP)
|
||||
.value("ForwardedMessage", Network::NetID::ForwardedMessage)
|
||||
.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("I2C2", Network::NetID::I2C2)
|
||||
.value("I2C3", Network::NetID::I2C3)
|
||||
.value("I2C4", Network::NetID::I2C4)
|
||||
.value("Ethernet2", Network::NetID::Ethernet2)
|
||||
.value("A2B1", Network::NetID::A2B1)
|
||||
.value("A2B2", Network::NetID::A2B2)
|
||||
.value("Ethernet3", Network::NetID::Ethernet3)
|
||||
.value("WBMS", Network::NetID::WBMS)
|
||||
.value("DWCAN9", Network::NetID::DWCAN9)
|
||||
.value("DWCAN10", Network::NetID::DWCAN10)
|
||||
.value("DWCAN11", Network::NetID::DWCAN11)
|
||||
.value("DWCAN12", Network::NetID::DWCAN12)
|
||||
.value("DWCAN13", Network::NetID::DWCAN13)
|
||||
.value("DWCAN14", Network::NetID::DWCAN14)
|
||||
.value("DWCAN15", Network::NetID::DWCAN15)
|
||||
.value("DWCAN16", Network::NetID::DWCAN16)
|
||||
.value("LIN7", Network::NetID::LIN7)
|
||||
.value("LIN8", Network::NetID::LIN8)
|
||||
.value("SPI2", Network::NetID::SPI2)
|
||||
.value("MDIO1", Network::NetID::MDIO1)
|
||||
.value("MDIO2", Network::NetID::MDIO2)
|
||||
.value("MDIO3", Network::NetID::MDIO3)
|
||||
.value("MDIO4", Network::NetID::MDIO4)
|
||||
.value("MDIO5", Network::NetID::MDIO5)
|
||||
.value("MDIO6", Network::NetID::MDIO6)
|
||||
.value("MDIO7", Network::NetID::MDIO7)
|
||||
.value("MDIO8", Network::NetID::MDIO8)
|
||||
.value("OP_Ethernet13", Network::NetID::OP_Ethernet13)
|
||||
.value("OP_Ethernet14", Network::NetID::OP_Ethernet14)
|
||||
.value("OP_Ethernet15", Network::NetID::OP_Ethernet15)
|
||||
.value("OP_Ethernet16", Network::NetID::OP_Ethernet16)
|
||||
.value("SPI3", Network::NetID::SPI3)
|
||||
.value("SPI4", Network::NetID::SPI4)
|
||||
.value("SPI5", Network::NetID::SPI5)
|
||||
.value("SPI6", Network::NetID::SPI6)
|
||||
.value("SPI7", Network::NetID::SPI7)
|
||||
.value("SPI8", Network::NetID::SPI8)
|
||||
.value("LIN9", Network::NetID::LIN9)
|
||||
.value("LIN10", Network::NetID::LIN10)
|
||||
.value("LIN11", Network::NetID::LIN11)
|
||||
.value("LIN12", Network::NetID::LIN12)
|
||||
.value("LIN13", Network::NetID::LIN13)
|
||||
.value("LIN14", Network::NetID::LIN14)
|
||||
.value("LIN15", Network::NetID::LIN15)
|
||||
.value("LIN16", Network::NetID::LIN16)
|
||||
.value("Any", Network::NetID::Any)
|
||||
.value("Invalid", Network::NetID::Invalid)
|
||||
.finalize();
|
||||
.value("Invalid", Network::NetID::Invalid);
|
||||
|
||||
pybind11::native_enum<Network::Type>(network, "Type", "enum.Enum")
|
||||
pybind11::enum_<Network::Type>(network, "Type")
|
||||
.value("Invalid", Network::Type::Invalid)
|
||||
.value("Internal", Network::Type::Internal)
|
||||
.value("CAN", Network::Type::CAN)
|
||||
@@ -185,10 +182,8 @@ void init_network(pybind11::module_& m) {
|
||||
.value("A2B", Network::Type::A2B)
|
||||
.value("SPI", Network::Type::SPI)
|
||||
.value("MDIO", Network::Type::MDIO)
|
||||
.value("AutomotiveEthernet", Network::Type::AutomotiveEthernet)
|
||||
.value("Any", Network::Type::Any)
|
||||
.value("Other", Network::Type::Other)
|
||||
.finalize();
|
||||
.value("Other", Network::Type::Other);
|
||||
|
||||
network
|
||||
.def(pybind11::init<Network::NetID>())
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
#include "icsneo/core/macseccfg.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_macsecconfig(pybind11::module_ & m)
|
||||
{
|
||||
pybind11::enum_<MACsecPacketType>(m, "MACsecPacketType")
|
||||
.value("DEFAULT", MACsecPacketType::Default)
|
||||
.value("SINGLE_VLAN", MACsecPacketType::SingleVLAN)
|
||||
.value("DUAL_VLAN", MACsecPacketType::DualVLAN)
|
||||
.value("MPLS", MACsecPacketType::MPLS)
|
||||
.value("SINGLE_VLAN_FOLLOWED_BY_MPLS", MACsecPacketType::SingleVLANFollowedByMPLS)
|
||||
.value("DUAL_VLAN_FOLLOWED_BY_MPLS", MACsecPacketType::DualVLANFollowedByMPLS)
|
||||
.value("UNSUPPORTED", MACsecPacketType::Unsupported);
|
||||
|
||||
pybind11::enum_<MACsecValidation>(m, "MACsecValidation")
|
||||
.value("DISABLED", MACsecValidation::Disabled)
|
||||
.value("CHECK", MACsecValidation::Check)
|
||||
.value("STRICT", MACsecValidation::Strict)
|
||||
.value("NA", MACsecValidation::NA);
|
||||
|
||||
pybind11::enum_<MACsecStrip>(m, "MACsecStrip")
|
||||
.value("STRIP_SECTAG_AND_ICV", MACsecStrip::StripSecTagAndIcv)
|
||||
.value("STRIP_SECTAG_PRESERVE_ICV", MACsecStrip::StripSecTagPreserveICV)
|
||||
.value("PRESERVE_SECTAG_STRIP_ICV", MACsecStrip::PreserveSecTagStripICV)
|
||||
.value("NO_STRIP", MACsecStrip::NoStrip);
|
||||
|
||||
pybind11::enum_<MACsecCipherSuite>(m, "MACsecCipherSuite")
|
||||
.value("GCM_AES_128", MACsecCipherSuite::GcmAes128)
|
||||
.value("GCM_AES_256", MACsecCipherSuite::GcmAes256)
|
||||
.value("GCM_AES_128_XPN", MACsecCipherSuite::GcmAes128Xpn)
|
||||
.value("GCM_AES_256_XPN", MACsecCipherSuite::GcmAes256Xpn);
|
||||
|
||||
pybind11::classh<MACsecVLANTag>(m, "MACsecVLANTag")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("vid", &MACsecVLANTag::vid)
|
||||
.def_readwrite("pri_cfi", &MACsecVLANTag::priCfi);
|
||||
|
||||
pybind11::classh<MACsecMPLSOuter>(m, "MACsecMPLSOuter")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("mpls_label", &MACsecMPLSOuter::mplsLabel)
|
||||
.def_readwrite("exp", &MACsecMPLSOuter::exp);
|
||||
|
||||
pybind11::classh<MACsecTci>(m, "MACsecTci")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("es", &MACsecTci::es)
|
||||
.def_readwrite("sc", &MACsecTci::sc)
|
||||
.def_readwrite("scb", &MACsecTci::scb)
|
||||
.def_readwrite("e", &MACsecTci::e)
|
||||
.def_readwrite("c", &MACsecTci::c);
|
||||
|
||||
pybind11::classh<MACsecRxRule>(m, "MACsecRxRule")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("key_mac_da", &MACsecRxRule::keyMacDa)
|
||||
.def_readwrite("mask_mac_da", &MACsecRxRule::maskMacDa)
|
||||
.def_readwrite("key_mask_sa", &MACsecRxRule::keyMacSa)
|
||||
.def_readwrite("mask_mac_sa", &MACsecRxRule::maskMacSa)
|
||||
.def_readwrite("key_ether_type", &MACsecRxRule::keyEthertype)
|
||||
.def_readwrite("mask_ether_type", &MACsecRxRule::maskEthertype)
|
||||
.def_readwrite("key_vlan_tag_outer1", &MACsecRxRule::keyVlanTagOuter1)
|
||||
.def_readwrite("key_mpls_outer1", &MACsecRxRule::keyMplsOuter1)
|
||||
.def_readwrite("mask_vlan_tag_outer1", &MACsecRxRule::maskVlanTagOuter1)
|
||||
.def_readwrite("mask_mpls_outer1", &MACsecRxRule::maskMplsOuter1)
|
||||
.def_readwrite("key_vlan_tag_outer2", &MACsecRxRule::keyVlanTagOuter2)
|
||||
.def_readwrite("key_mpls_outer2", &MACsecRxRule::keyMplsOuter2)
|
||||
.def_readwrite("mask_vlan_tag_outer2", &MACsecRxRule::maskVlanTagOuter2)
|
||||
.def_readwrite("mask_mpls_outer2", &MACsecRxRule::maskMplsOuter2)
|
||||
.def_readwrite("key_bonus_data", &MACsecRxRule::keyBonusData)
|
||||
.def_readwrite("mask_bonus_data", &MACsecRxRule::maskBonusData)
|
||||
.def_readwrite("key_tag_match_bitmap", &MACsecRxRule::keyTagMatchBitmap)
|
||||
.def_readwrite("mask_tag_match_bitmap", &MACsecRxRule::maskTagMatchBitmap)
|
||||
.def_readwrite("key_packet_type", &MACsecRxRule::keyPacketType)
|
||||
.def_readwrite("mask_packet_type", &MACsecRxRule::maskPacketType)
|
||||
.def_readwrite("key_inner_vlan_type", &MACsecRxRule::keyInnerVlanType)
|
||||
.def_readwrite("mask_inner_vlan_type", &MACsecRxRule::maskInnerVlanType)
|
||||
.def_readwrite("key_outer_vlan_type", &MACsecRxRule::keyOuterVlanType)
|
||||
.def_readwrite("mask_outer_vlan_type", &MACsecRxRule::maskOuterVlanType)
|
||||
.def_readwrite("key_num_tags", &MACsecRxRule::keyNumTags)
|
||||
.def_readwrite("mask_num_tags", &MACsecRxRule::maskNumTags)
|
||||
.def_readwrite("key_express", &MACsecRxRule::keyExpress)
|
||||
.def_readwrite("mask_express", &MACsecRxRule::maskExpress)
|
||||
.def_readwrite("is_mpls", &MACsecRxRule::isMpls);
|
||||
|
||||
pybind11::classh<MACsecTxSecY>(m, "MACsecTxSecY")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("enable_control_port", &MACsecTxSecY::enableControlPort)
|
||||
.def_readwrite("cipher", &MACsecTxSecY::cipher)
|
||||
.def_readwrite("confidentiality_offset", &MACsecTxSecY::confidentialityOffset)
|
||||
.def_readwrite("icv_includes_da_sa", &MACsecTxSecY::icvIncludesDaSa)
|
||||
.def_readwrite("protect_frames", &MACsecTxSecY::protectFrames)
|
||||
.def_readwrite("sec_tag_offset", &MACsecTxSecY::secTagOffset)
|
||||
.def_readwrite("sec_tag_tci", &MACsecTxSecY::tci)
|
||||
.def_readwrite("mtu", &MACsecTxSecY::mtu)
|
||||
.def_readwrite("is_control_packet", &MACsecTxSecY::isControlPacket)
|
||||
.def_readwrite("auxiliary_policy", &MACsecTxSecY::auxiliaryPolicy)
|
||||
.def_readwrite("sci", &MACsecTxSecY::sci);
|
||||
|
||||
pybind11::classh<MACsecRxSecY>(m, "MACsecRxSecY")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("enable_control_port", &MACsecRxSecY::enableControlPort)
|
||||
.def_readwrite("frame_validation", &MACsecRxSecY::frameValidation)
|
||||
.def_readwrite("frame_strip", &MACsecRxSecY::frameStrip)
|
||||
.def_readwrite("cipher", &MACsecRxSecY::cipher)
|
||||
.def_readwrite("confidentiality_offset", &MACsecRxSecY::confidentialityOffset)
|
||||
.def_readwrite("icv_includes_da_sa", &MACsecRxSecY::icvIncludesDaSa)
|
||||
.def_readwrite("replay_protect", &MACsecRxSecY::replayProtect)
|
||||
.def_readwrite("replay_window", &MACsecRxSecY::replayWindow)
|
||||
.def_readwrite("is_control_packet", &MACsecRxSecY::isControlPacket)
|
||||
.def_readwrite("sci", &MACsecRxSecY::sci);
|
||||
|
||||
pybind11::classh<MACsecTxSa>(m, "MACsecTxSa")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("sak", &MACsecTxSa::sak)
|
||||
.def_readwrite("hash_key", &MACsecTxSa::hashKey)
|
||||
.def_readwrite("salt", &MACsecTxSa::salt)
|
||||
.def_readwrite("ssci", &MACsecTxSa::ssci)
|
||||
.def_readwrite("next_pn", &MACsecTxSa::nextPn)
|
||||
.def_readwrite("an", &MACsecTxSa::an);
|
||||
|
||||
pybind11::classh<MACsecRxSa>(m, "MACsecRxSa")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("sak", &MACsecRxSa::sak)
|
||||
.def_readwrite("hash_key", &MACsecRxSa::hashKey)
|
||||
.def_readwrite("salt", &MACsecRxSa::salt)
|
||||
.def_readwrite("ssci", &MACsecRxSa::ssci)
|
||||
.def_readwrite("next_pn", &MACsecRxSa::nextPn);
|
||||
|
||||
pybind11::classh<MACsecConfig>(m, "MACsecConfig")
|
||||
.def(pybind11::init<icsneo::DeviceType>())
|
||||
.def("add_rx_secy", &MACsecConfig::addRxSecY, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("add_tx_secY", &MACsecConfig::addTxSecY, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("add_rx_rule", &MACsecConfig::addRxRule, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("add_rx_sa", &MACsecConfig::addRxSa, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("add_tx_sa", &MACsecConfig::addTxSa, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_rx_secy", [](MACsecConfig& cfg, uint8_t index) -> MACsecRxSecY& { return cfg.getRxSecY(index); }, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_tx_secy", [](MACsecConfig& cfg, uint8_t index) -> MACsecTxSecY& { return cfg.getTxSecY(index); }, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_rx_sa", [](MACsecConfig& cfg, uint8_t index) -> MACsecRxSa& { return cfg.getRxSa(index); }, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_tx_sa", [](MACsecConfig& cfg, uint8_t index) -> MACsecTxSa& { return cfg.getTxSa(index); }, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_rx_rule", [](MACsecConfig& cfg, uint8_t index) -> MACsecRxRule& { return cfg.getRxRule(index); }, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_tx_sa_index", &MACsecConfig::setTxSaIndex, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("enable_tx_rekey", &MACsecConfig::enableTxRekey, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_tx_sa_rekey_index", &MACsecConfig::setTxSaRekeyIndex, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("disable_tx_rekey", &MACsecConfig::disableTxRekey, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_rx_sa_index", &MACsecConfig::setRxSaIndex, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("enable_rx_rekey", &MACsecConfig::enableRxRekey, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_rx_sa_rekey_index", &MACsecConfig::setRxSaRekeyIndex, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("disable_rx_rekey", &MACsecConfig::disableRxRekey, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_rx_enable", &MACsecConfig::setRxEnable, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_tx_enable", &MACsecConfig::setTxEnable, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_storage", &MACsecConfig::setStorage, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("clear", &MACsecConfig::clear, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("serialize", &MACsecConfig::serialize, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_bin_index", &MACsecConfig::getBinIndex, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_type", &MACsecConfig::getType, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_max_num_rule", &MACsecConfig::getMaxNumRule, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_max_num_secy", &MACsecConfig::getMaxNumSecY, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_max_num_sa", &MACsecConfig::getMaxNumSa, pybind11::call_guard<pybind11::gil_scoped_release>());
|
||||
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/device/chipid.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_chipid(pybind11::module_& m) {
|
||||
pybind11::native_enum<ChipID>(m, "ChipID", "enum.IntEnum")
|
||||
.value("neoVIFIRE_MCHIP", ChipID::neoVIFIRE_MCHIP)
|
||||
.value("neoVIFIRE_LCHIP", ChipID::neoVIFIRE_LCHIP)
|
||||
.value("neoVIFIRE_UCHIP", ChipID::neoVIFIRE_UCHIP)
|
||||
.value("neoVIFIRE_JCHIP", ChipID::neoVIFIRE_JCHIP)
|
||||
.value("ValueCAN3_MCHIP", ChipID::ValueCAN3_MCHIP)
|
||||
.value("neoVIECU_MPIC", ChipID::neoVIECU_MPIC)
|
||||
.value("neoVIIEVB_MPIC", ChipID::neoVIIEVB_MPIC)
|
||||
.value("neoVIPENDANT_MPIC", ChipID::neoVIPENDANT_MPIC)
|
||||
.value("neoVIFIRE_VNET_MCHIP", ChipID::neoVIFIRE_VNET_MCHIP)
|
||||
.value("neoVIFIRE_VNET_LCHIP", ChipID::neoVIFIRE_VNET_LCHIP)
|
||||
.value("neoVIPLASMA_Core", ChipID::neoVIPLASMA_Core)
|
||||
.value("neoVIPLASMA_HID", ChipID::neoVIPLASMA_HID)
|
||||
.value("neoVIANALOG_MPIC", ChipID::neoVIANALOG_MPIC)
|
||||
.value("neoVIPLASMA_ANALOG_Core", ChipID::neoVIPLASMA_ANALOG_Core)
|
||||
.value("neoVIPLASMA_FlexRay_Core", ChipID::neoVIPLASMA_FlexRay_Core)
|
||||
.value("neoVIPLASMA_Core_1_12", ChipID::neoVIPLASMA_Core_1_12)
|
||||
.value("neoVIFIRE_Slave_VNET_MCHIP", ChipID::neoVIFIRE_Slave_VNET_MCHIP)
|
||||
.value("neoVIFIRE_Slave_VNET_LCHIP", ChipID::neoVIFIRE_Slave_VNET_LCHIP)
|
||||
.value("neoVIION_Core", ChipID::neoVIION_Core)
|
||||
.value("neoVIION_HID", ChipID::neoVIION_HID)
|
||||
.value("neoVIION_Core_Loader", ChipID::neoVIION_Core_Loader)
|
||||
.value("neoVIION_HID_Loader", ChipID::neoVIION_HID_Loader)
|
||||
.value("neoVIION_FPGA_BIT", ChipID::neoVIION_FPGA_BIT)
|
||||
.value("neoVIFIRE_VNET_EP_MCHIP", ChipID::neoVIFIRE_VNET_EP_MCHIP)
|
||||
.value("neoVIFIRE_VNET_EP_LCHIP", ChipID::neoVIFIRE_VNET_EP_LCHIP)
|
||||
.value("neoVIAnalogOut_MCHIP", ChipID::neoVIAnalogOut_MCHIP)
|
||||
.value("neoVIMOST25_MCHIP", ChipID::neoVIMOST25_MCHIP)
|
||||
.value("neoVIMOST50_MCHIP", ChipID::neoVIMOST50_MCHIP)
|
||||
.value("neoVIMOST150_MCHIP", ChipID::neoVIMOST150_MCHIP)
|
||||
.value("ValueCAN4_4_MCHIP", ChipID::ValueCAN4_4_MCHIP)
|
||||
.value("ValueCAN4_4_SCHIP", ChipID::ValueCAN4_4_SCHIP)
|
||||
.value("cmProbe_ZYNQ", ChipID::cmProbe_ZYNQ)
|
||||
.value("EEVB_STM32", ChipID::EEVB_STM32)
|
||||
.value("neoVIFIRE_Slave_VNET_EP_MCHIP", ChipID::neoVIFIRE_Slave_VNET_EP_MCHIP)
|
||||
.value("neoVIFIRE_Slave_VNET_EP_LCHIP", ChipID::neoVIFIRE_Slave_VNET_EP_LCHIP)
|
||||
.value("RADStar_MCHIP", ChipID::RADStar_MCHIP)
|
||||
.value("ValueCANrf_MCHIP", ChipID::ValueCANrf_MCHIP)
|
||||
.value("neoVIFIRE2_MCHIP", ChipID::neoVIFIRE2_MCHIP)
|
||||
.value("neoVIFIRE2_CCHIP", ChipID::neoVIFIRE2_CCHIP)
|
||||
.value("neoVIFIRE2_Core", ChipID::neoVIFIRE2_Core)
|
||||
.value("neoVIFIRE2_BLECHIP", ChipID::neoVIFIRE2_BLECHIP)
|
||||
.value("neoVIFIRE2_ZYNQ", ChipID::neoVIFIRE2_ZYNQ)
|
||||
.value("neoVIFIRE2_SECURITYCHIP", ChipID::neoVIFIRE2_SECURITYCHIP)
|
||||
.value("RADGalaxy_ZYNQ", ChipID::RADGalaxy_ZYNQ)
|
||||
.value("neoVIFIRE2_VNET_MCHIP", ChipID::neoVIFIRE2_VNET_MCHIP)
|
||||
.value("neoVIFIRE2_Slave_VNET_A_MCHIP", ChipID::neoVIFIRE2_Slave_VNET_A_MCHIP)
|
||||
.value("neoVIFIRE2_Slave_VNET_A_CCHIP", ChipID::neoVIFIRE2_Slave_VNET_A_CCHIP)
|
||||
.value("neoVIFIRE2_VNET_CCHIP", ChipID::neoVIFIRE2_VNET_CCHIP)
|
||||
.value("neoVIFIRE2_VNET_Core", ChipID::neoVIFIRE2_VNET_Core)
|
||||
.value("RADStar2_ZYNQ", ChipID::RADStar2_ZYNQ)
|
||||
.value("VividCAN_MCHIP", ChipID::VividCAN_MCHIP)
|
||||
.value("neoOBD2SIM_MCHIP", ChipID::neoOBD2SIM_MCHIP)
|
||||
.value("neoVIFIRE2_VNETZ_MCHIP", ChipID::neoVIFIRE2_VNETZ_MCHIP)
|
||||
.value("neoVIFIRE2_VNETZ_ZYNQ", ChipID::neoVIFIRE2_VNETZ_ZYNQ)
|
||||
.value("neoVIFIRE2_Slave_VNETZ_A_MCHIP", ChipID::neoVIFIRE2_Slave_VNETZ_A_MCHIP)
|
||||
.value("neoVIFIRE2_Slave_VNETZ_A_ZYNQ", ChipID::neoVIFIRE2_Slave_VNETZ_A_ZYNQ)
|
||||
.value("VividCAN_EXT_FLASH", ChipID::VividCAN_EXT_FLASH)
|
||||
.value("VividCAN_NRF52", ChipID::VividCAN_NRF52)
|
||||
.value("cmProbe_ZYNQ_Unused", ChipID::cmProbe_ZYNQ_Unused)
|
||||
.value("neoOBD2PRO_MCHIP", ChipID::neoOBD2PRO_MCHIP)
|
||||
.value("ValueCAN4_1_MCHIP", ChipID::ValueCAN4_1_MCHIP)
|
||||
.value("ValueCAN4_2_MCHIP", ChipID::ValueCAN4_2_MCHIP)
|
||||
.value("ValueCAN4_4_2EL_Core", ChipID::ValueCAN4_4_2EL_Core)
|
||||
.value("neoOBD2PRO_SCHIP", ChipID::neoOBD2PRO_SCHIP)
|
||||
.value("ValueCAN4_2EL_MCHIP", ChipID::ValueCAN4_2EL_MCHIP)
|
||||
.value("neoECUAVBTSN_MCHIP", ChipID::neoECUAVBTSN_MCHIP)
|
||||
.value("neoOBD2PRO_Core", ChipID::neoOBD2PRO_Core)
|
||||
.value("RADSupermoon_ZYNQ", ChipID::RADSupermoon_ZYNQ)
|
||||
.value("RADMoon2_ZYNQ", ChipID::RADMoon2_ZYNQ)
|
||||
.value("VividCANPRO_MCHIP", ChipID::VividCANPRO_MCHIP)
|
||||
.value("VividCANPRO_EXT_FLASH", ChipID::VividCANPRO_EXT_FLASH)
|
||||
.value("RADPluto_MCHIP", ChipID::RADPluto_MCHIP)
|
||||
.value("RADMars_ZYNQ", ChipID::RADMars_ZYNQ)
|
||||
.value("neoECU12_MCHIP", ChipID::neoECU12_MCHIP)
|
||||
.value("RADIOCANHUB_MCHIP", ChipID::RADIOCANHUB_MCHIP)
|
||||
.value("FlexRay_VNETZ_ZCHIP", ChipID::FlexRay_VNETZ_ZCHIP)
|
||||
.value("neoOBD2_LCBADGE_MCHIP", ChipID::neoOBD2_LCBADGE_MCHIP)
|
||||
.value("neoOBD2_LCBADGE_SCHIP", ChipID::neoOBD2_LCBADGE_SCHIP)
|
||||
.value("RADMoonDuo_MCHIP", ChipID::RADMoonDuo_MCHIP)
|
||||
.value("neoVIFIRE3_ZCHIP", ChipID::neoVIFIRE3_ZCHIP)
|
||||
.value("FlexRay_VNETZ_FCHIP", ChipID::FlexRay_VNETZ_FCHIP)
|
||||
.value("RADJupiter_MCHIP", ChipID::RADJupiter_MCHIP)
|
||||
.value("ValueCAN4Industrial_MCHIP", ChipID::ValueCAN4Industrial_MCHIP)
|
||||
.value("EtherBADGE_MCHIP", ChipID::EtherBADGE_MCHIP)
|
||||
.value("RADMars_3_ZYNQ", ChipID::RADMars_3_ZYNQ)
|
||||
.value("RADGigastar_USBZ_ZYNQ", ChipID::RADGigastar_USBZ_ZYNQ)
|
||||
.value("RADGigastar_ZYNQ", ChipID::RADGigastar_ZYNQ)
|
||||
.value("RAD4G_MCHIP", ChipID::RAD4G_MCHIP)
|
||||
.value("neoVIFIRE3_SCHIP", ChipID::neoVIFIRE3_SCHIP)
|
||||
.value("RADEpsilon_MCHIP", ChipID::RADEpsilon_MCHIP)
|
||||
.value("RADA2B_ZCHIP", ChipID::RADA2B_ZCHIP)
|
||||
.value("neoOBD2Dev_MCHIP", ChipID::neoOBD2Dev_MCHIP)
|
||||
.value("neoOBD2Dev_SCHIP", ChipID::neoOBD2Dev_SCHIP)
|
||||
.value("neoOBD2SIMDoIP_MCHIP", ChipID::neoOBD2SIMDoIP_MCHIP)
|
||||
.value("SFPModule_88q2112_MCHIP", ChipID::SFPModule_88q2112_MCHIP)
|
||||
.value("RADEpsilonT_MCHIP", ChipID::RADEpsilonT_MCHIP)
|
||||
.value("RADEpsilonExpress_MCHIP", ChipID::RADEpsilonExpress_MCHIP)
|
||||
.value("RADProxima_MCHIP", ChipID::RADProxima_MCHIP)
|
||||
.value("NewDevice57_ZCHIP", ChipID::NewDevice57_ZCHIP)
|
||||
.value("RAD_GALAXY_2_ZMPCHIP_ID", ChipID::RAD_GALAXY_2_ZMPCHIP_ID)
|
||||
.value("NewDevice59_MCHIP", ChipID::NewDevice59_MCHIP)
|
||||
.value("RADMoon2_Z7010_ZYNQ", ChipID::RADMoon2_Z7010_ZYNQ)
|
||||
.value("neoVIFIRE2_Core_SG4", ChipID::neoVIFIRE2_Core_SG4)
|
||||
.value("RADBMS_MCHIP", ChipID::RADBMS_MCHIP)
|
||||
.value("RADMoon2_ZL_MCHIP", ChipID::RADMoon2_ZL_MCHIP)
|
||||
.value("RADGigastar_USBZ_Z7010_ZYNQ", ChipID::RADGigastar_USBZ_Z7010_ZYNQ)
|
||||
.value("neoVIFIRE3_LINUX", ChipID::neoVIFIRE3_LINUX)
|
||||
.value("RADGigastar_USBZ_Z7007S_ZYNQ", ChipID::RADGigastar_USBZ_Z7007S_ZYNQ)
|
||||
.value("VEM_01_8DW_ZCHIP", ChipID::VEM_01_8DW_ZCHIP)
|
||||
.value("RADGalaxy_FFG_Zynq", ChipID::RADGalaxy_FFG_Zynq)
|
||||
.value("RADMoon3_MCHIP", ChipID::RADMoon3_MCHIP)
|
||||
.value("RADComet2_ZYNQ", ChipID::RADComet2_ZYNQ)
|
||||
.value("VEM_02_FR_ZCHIP", ChipID::VEM_02_FR_ZCHIP)
|
||||
.value("RADA2B_REVB_ZCHIP", ChipID::RADA2B_REVB_ZCHIP)
|
||||
.value("RADGigastar_FFG_ZYNQ", ChipID::RADGigastar_FFG_ZYNQ)
|
||||
.value("VEM_02_FR_FCHIP", ChipID::VEM_02_FR_FCHIP)
|
||||
.value("Connect_ZCHIP", ChipID::Connect_ZCHIP)
|
||||
.value("SFPModule_88q2221_MCHIP", ChipID::SFPModule_88q2221_MCHIP)
|
||||
.value("RADGALAXY2_SYSMON_CHIP", ChipID::RADGALAXY2_SYSMON_CHIP)
|
||||
.value("SFPModule_88q3244_MCHIP", ChipID::SFPModule_88q3244_MCHIP)
|
||||
.value("RADCOMET3_ZCHIP", ChipID::RADCOMET3_ZCHIP)
|
||||
.value("Connect_LINUX", ChipID::Connect_LINUX)
|
||||
.value("SFPModule_lan8670_MCHIP", ChipID::SFPModule_lan8670_MCHIP)
|
||||
.value("RADGigastar2_ZYNQ", ChipID::RADGigastar2_ZYNQ)
|
||||
.value("SFPModule_ent11100_MCHIP", ChipID::SFPModule_ent11100_MCHIP)
|
||||
.value("RADGemini_MCHIP", ChipID::RADGemini_MCHIP)
|
||||
.value("Invalid", ChipID::Invalid)
|
||||
.finalize();
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -4,75 +4,43 @@
|
||||
#include <pybind11/chrono.h>
|
||||
|
||||
#include "icsneo/device/device.h"
|
||||
#include "icsneo/device/extensions/deviceextension.h"
|
||||
#include "icsneo/disk/diskdetails.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_device(pybind11::module_& m) {
|
||||
pybind11::classh<Device>(m, "Device")
|
||||
.def("__repr__", &Device::describe)
|
||||
.def("add_message_callback", &Device::addMessageCallback, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("clear_script", &Device::clearScript, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.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_extension", static_cast<std::shared_ptr<DeviceExtension>(Device::*)(const std::string&) const>(&Device::getExtension)) // This has to be static_casted rather than overload_casted because DeviceExtension is forward declared in device.h
|
||||
.def("get_flexray_controllers", &Device::getFlexRayControllers)
|
||||
.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)
|
||||
pybind11::class_<Device, std::shared_ptr<Device>>(m, "Device")
|
||||
.def("get_type", &Device::getType)
|
||||
.def("get_serial", &Device::getSerial)
|
||||
.def("get_pcb_serial", &Device::getPCBSerial, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_mac_addresses", &Device::getMACAddresses, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.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("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("get_supported_rx_networks", &Device::getSupportedRXNetworks, pybind11::return_value_policy::reference)
|
||||
.def("get_supported_tx_networks", &Device::getSupportedTXNetworks, pybind11::return_value_policy::reference)
|
||||
.def("get_tc10_status", &Device::getTC10Status, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.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("get_rtc", &Device::getRTC, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_rtc", &Device::setRTC, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("reboot", &Device::reboot, pybind11::arg("safe") = false, 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("describe", &Device::describe)
|
||||
.def("is_online_supported", &Device::isOnlineSupported)
|
||||
.def("supports_tc10", &Device::supportsTC10)
|
||||
.def("supports_reboot", &Device::supportsReboot)
|
||||
.def("supports_live_data", &Device::supportsLiveData)
|
||||
.def("subscribe_live_data", &Device::subscribeLiveData, pybind11::arg("message"), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("unsubscribe_live_data", &Device::unsubscribeLiveData, pybind11::arg("handle"), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("clear_all_live_data", &Device::clearAllLiveData, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_value_live_data", &Device::setValueLiveData, pybind11::arg("message"), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("transmit", pybind11::overload_cast<std::shared_ptr<Frame>>(&Device::transmit), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("upload_coremini", [](Device& device, std::string& path, Disk::MemoryType memType) { std::ifstream ifs(path, std::ios::binary); return device.uploadCoremini(ifs, memType); }, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("write_macsec_config", &Device::writeMACsecConfig, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("send_eth_phy_msg", &Device::sendEthPhyMsg, pybind11::arg("message"), pybind11::arg("timeout") = std::chrono::milliseconds(50), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_chip_versions", &Device::getChipVersions, pybind11::arg("refreshComponents") = true, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("supports_disk_formatting", &Device::supportsDiskFormatting, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_disk_count", &Device::getDiskCount, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_disk_details", &Device::getDiskDetails, pybind11::arg("timeout") = std::chrono::milliseconds(100), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("force_disk_config_update", &Device::forceDiskConfigUpdate, pybind11::arg("config"), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("format_disk", [](Device& device, const DiskDetails& config) -> bool { return device.formatDisk(config); }, pybind11::arg("config"), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def_readonly("settings", &Device::settings);
|
||||
.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);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/device/devicetype.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_devicetype(pybind11::module_& m) {
|
||||
pybind11::classh<DeviceType> deviceType(m, "DeviceType");
|
||||
pybind11::native_enum<DeviceType::Enum>(deviceType, "Enum", "enum.IntEnum")
|
||||
pybind11::class_<DeviceType> deviceType(m, "DeviceType");
|
||||
pybind11::enum_<DeviceType::Enum>(deviceType, "Enum")
|
||||
.value("Unknown", DeviceType::Enum::Unknown)
|
||||
.value("BLUE", DeviceType::Enum::BLUE)
|
||||
.value("ECU_AVB", DeviceType::Enum::ECU_AVB)
|
||||
@@ -34,15 +33,10 @@ 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("RADwBMS", DeviceType::Enum::RADwBMS)
|
||||
.value("RADMoon3", DeviceType::Enum::RADMoon3)
|
||||
.value("RADGemini", DeviceType::Enum::RADGemini)
|
||||
.value("RADComet2", DeviceType::Enum::RADComet2)
|
||||
.value("RADComet", DeviceType::Enum::RADComet)
|
||||
.value("FIRE3_FlexRay", DeviceType::Enum::FIRE3_FlexRay)
|
||||
.value("FIRE3_T1S_LIN", DeviceType::Enum::FIRE3_T1S_LIN)
|
||||
.value("FIRE3_T1S_SENT", DeviceType::Enum::FIRE3_T1S_SENT)
|
||||
.value("Connect", DeviceType::Enum::Connect)
|
||||
.value("RADComet3", DeviceType::Enum::RADComet3)
|
||||
.value("RADMoonT1S", DeviceType::Enum::RADMoonT1S)
|
||||
@@ -54,14 +48,10 @@ 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)
|
||||
@@ -72,8 +62,7 @@ void init_devicetype(pybind11::module_& m) {
|
||||
.value("RADGalaxy", DeviceType::Enum::RADGalaxy)
|
||||
.value("RADStar2", DeviceType::Enum::RADStar2)
|
||||
.value("VividCAN", DeviceType::Enum::VividCAN)
|
||||
.value("OBD2_SIM", DeviceType::Enum::OBD2_SIM)
|
||||
.finalize();
|
||||
.value("OBD2_SIM", DeviceType::Enum::OBD2_SIM);
|
||||
deviceType.def(pybind11::init<DeviceType::Enum>());
|
||||
deviceType.def("get_device_type", &DeviceType::getDeviceType);
|
||||
deviceType.def("get_generic_product_name", &DeviceType::getGenericProductName);
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
#include "icsneo/device/extensions/deviceextension.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_deviceextension(pybind11::module_& m) {
|
||||
pybind11::classh<DeviceExtension>(m, "DeviceExtension")
|
||||
.def("get_name", &DeviceExtension::getName);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -1,164 +0,0 @@
|
||||
#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;
|
||||
};
|
||||
|
||||
void init_idevicesettings(pybind11::module_& m) {
|
||||
pybind11::classh<DeviceSettingsNamespace> settings(m, "Settings");
|
||||
|
||||
pybind11::enum_<DeviceSettingsNamespace::EthLinkMode>(settings, "EthernetLinkMode")
|
||||
.value("Auto", DeviceSettingsNamespace::EthLinkMode::AE_LINK_AUTO)
|
||||
.value("Slave", DeviceSettingsNamespace::EthLinkMode::AE_LINK_SLAVE)
|
||||
.value("Master", DeviceSettingsNamespace::EthLinkMode::AE_LINK_MASTER);
|
||||
|
||||
pybind11::enum_<EthPhyLinkMode>(settings, "PhyLinkMode")
|
||||
.value("ETH_LINK_MODE_AUTO_NEGOTIATION", ETH_LINK_MODE_AUTO_NEGOTIATION)
|
||||
.value("ETH_LINK_MODE_10MBPS_HALFDUPLEX", ETH_LINK_MODE_10MBPS_HALFDUPLEX)
|
||||
.value("ETH_LINK_MODE_10MBPS_FULLDUPLEX", ETH_LINK_MODE_10MBPS_FULLDUPLEX)
|
||||
.value("ETH_LINK_MODE_100MBPS_HALFDUPLEX", ETH_LINK_MODE_100MBPS_HALFDUPLEX)
|
||||
.value("ETH_LINK_MODE_100MBPS_FULLDUPLEX", ETH_LINK_MODE_100MBPS_FULLDUPLEX)
|
||||
.value("ETH_LINK_MODE_1GBPS_HALFDUPLEX", ETH_LINK_MODE_1GBPS_HALFDUPLEX)
|
||||
.value("ETH_LINK_MODE_1GBPS_FULLDUPLEX", ETH_LINK_MODE_1GBPS_FULLDUPLEX)
|
||||
.value("ETH_LINK_MODE_2_5GBPS_FULLDUPLEX", ETH_LINK_MODE_2_5GBPS_FULLDUPLEX)
|
||||
.value("ETH_LINK_MODE_5GBPS_FULLDUPLEX", ETH_LINK_MODE_5GBPS_FULLDUPLEX)
|
||||
.value("ETH_LINK_MODE_10GBPS_FULLDUPLEX", ETH_LINK_MODE_10GBPS_FULLDUPLEX);
|
||||
|
||||
pybind11::enum_<LINMode>(settings, "LINMode")
|
||||
.value("Sleep", LINMode::SLEEP_MODE)
|
||||
.value("Slow", LINMode::SLOW_MODE)
|
||||
.value("Normal", LINMode::NORMAL_MODE)
|
||||
.value("Fast", LINMode::FAST_MODE);
|
||||
|
||||
pybind11::enum_<RADGPTPProfile>(settings, "GPTPProfile")
|
||||
.value("Standard", RADGPTPProfile::RAD_GPTP_PROFILE_STANDARD)
|
||||
.value("Automotive", RADGPTPProfile::RAD_GPTP_PROFILE_AUTOMOTIVE);
|
||||
|
||||
pybind11::enum_<RADGPTPRole>(settings, "GPTPRole")
|
||||
.value("Disabled", RADGPTPRole::RAD_GPTP_ROLE_DISABLED)
|
||||
.value("Passive", RADGPTPRole::RAD_GPTP_ROLE_PASSIVE)
|
||||
.value("Master", RADGPTPRole::RAD_GPTP_ROLE_MASTER)
|
||||
.value("Slave", RADGPTPRole::RAD_GPTP_ROLE_SLAVE);
|
||||
|
||||
pybind11::enum_<MiscIOAnalogVoltage>(settings, "MiscIOAnalogVoltage")
|
||||
.value("V0", MiscIOAnalogVoltage::V0)
|
||||
.value("V1", MiscIOAnalogVoltage::V1)
|
||||
.value("V2", MiscIOAnalogVoltage::V2)
|
||||
.value("V3", MiscIOAnalogVoltage::V3)
|
||||
.value("V4", MiscIOAnalogVoltage::V4)
|
||||
.value("V5", MiscIOAnalogVoltage::V5);
|
||||
|
||||
pybind11::enum_<LinuxConfigurationPort>(settings, "LinuxConfigurationPort")
|
||||
.value("USB", LinuxConfigurationPort::USB)
|
||||
.value("ETH01", LinuxConfigurationPort::ETH01);
|
||||
|
||||
pybind11::classh<IDeviceSettings>(m, "IDeviceSettings")
|
||||
.def("apply", &IDeviceSettings::apply, pybind11::arg("temporary") = 0, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("apply_defaults", &IDeviceSettings::applyDefaults, pybind11::arg("temporary") = 0, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("refresh", &IDeviceSettings::refresh, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// Baudrate methods
|
||||
.def("get_baudrate", &IDeviceSettings::getBaudrateFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_baudrate", &IDeviceSettings::setBaudrateFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_fd_baudrate", &IDeviceSettings::getFDBaudrateFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_fd_baudrate", &IDeviceSettings::setFDBaudrateFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// Termination methods
|
||||
.def("is_termination_supported", &IDeviceSettings::isTerminationSupportedFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("can_termination_be_enabled", &IDeviceSettings::canTerminationBeEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("is_termination_enabled", &IDeviceSettings::isTerminationEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_termination", &IDeviceSettings::setTerminationFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_termination_groups", &IDeviceSettings::getTerminationGroups, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// LIN methods
|
||||
.def("is_commander_resistor_enabled", &IDeviceSettings::isCommanderResistorEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_commander_resistor", &IDeviceSettings::setCommanderResistorFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_lin_mode", &IDeviceSettings::getLINModeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_lin_mode", &IDeviceSettings::setLINModeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_lin_commander_response_time", &IDeviceSettings::getLINCommanderResponseTimeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_lin_commander_response_time", &IDeviceSettings::setLINCommanderResponseTimeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// Ethernet PHY methods (index-based for switch devices)
|
||||
.def("get_phy_enable", &IDeviceSettings::getPhyEnable, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_phy_mode", &IDeviceSettings::getPhyMode, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_phy_speed", &IDeviceSettings::getPhySpeed, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_phy_enable", &IDeviceSettings::setPhyEnable, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_phy_mode", &IDeviceSettings::setPhyMode, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_phy_speed", &IDeviceSettings::setPhySpeed, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// Ethernet PHY methods (network-based for multi-interface devices)
|
||||
.def("get_phy_enable_for", &IDeviceSettings::getPhyEnableFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_phy_role_for", &IDeviceSettings::getPhyRoleFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_phy_link_mode_for", &IDeviceSettings::getPhyLinkModeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_phy_enable_for", &IDeviceSettings::setPhyEnableFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_phy_role_for", &IDeviceSettings::setPhyRoleFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_phy_link_mode_for", &IDeviceSettings::setPhyLinkModeFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_supported_phy_link_modes_for", &IDeviceSettings::getSupportedPhyLinkModesFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// 10BASE-T1S methods
|
||||
.def("is_t1s_plca_enabled", &IDeviceSettings::isT1SPLCAEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_plca", &IDeviceSettings::setT1SPLCAFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_local_id", &IDeviceSettings::getT1SLocalIDFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_local_id", &IDeviceSettings::setT1SLocalIDFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_max_nodes", &IDeviceSettings::getT1SMaxNodesFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_max_nodes", &IDeviceSettings::setT1SMaxNodesFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_tx_opp_timer", &IDeviceSettings::getT1STxOppTimerFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_tx_opp_timer", &IDeviceSettings::setT1STxOppTimerFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_max_burst", &IDeviceSettings::getT1SMaxBurstFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_max_burst", &IDeviceSettings::setT1SMaxBurstFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_burst_timer", &IDeviceSettings::getT1SBurstTimerFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_burst_timer", &IDeviceSettings::setT1SBurstTimerFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_local_id_alternate", &IDeviceSettings::getT1SLocalIDAlternateFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_local_id_alternate", &IDeviceSettings::setT1SLocalIDAlternateFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("is_t1s_termination_enabled", &IDeviceSettings::isT1STerminationEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_termination", &IDeviceSettings::setT1STerminationFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("is_t1s_bus_decoding_beacons_enabled", &IDeviceSettings::isT1SBusDecodingBeaconsEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_bus_decoding_beacons", &IDeviceSettings::setT1SBusDecodingBeaconsFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("is_t1s_bus_decoding_all_enabled", &IDeviceSettings::isT1SBusDecodingAllEnabledFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_bus_decoding_all", &IDeviceSettings::setT1SBusDecodingAllFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_multi_id_enable_mask", &IDeviceSettings::getT1SMultiIDEnableMaskFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_multi_id_enable_mask", &IDeviceSettings::setT1SMultiIDEnableMaskFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_t1s_multi_id", &IDeviceSettings::getT1SMultiIDFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_t1s_multi_id", &IDeviceSettings::setT1SMultiIDFor, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
.def("set_misc_io_analog_output_enabled", &IDeviceSettings::setMiscIOAnalogOutputEnabled, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_misc_io_analog_output", &IDeviceSettings::setMiscIOAnalogOutput, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// Performance blast
|
||||
.def("is_perf_test_enabled", &IDeviceSettings::isPerfTestEnabled, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_perf_test_enable", &IDeviceSettings::setPerfTestEnable, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
// gPTP methods
|
||||
.def("get_gptp_profile", &IDeviceSettings::getGPTPProfile, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_gptp_profile", &IDeviceSettings::setGPTPProfile, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_gptp_role", &IDeviceSettings::getGPTPRole, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_gptp_role", &IDeviceSettings::setGPTPRole, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_gptp_enabled_port", &IDeviceSettings::getGPTPEnabledPort, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_gptp_enabled_port", &IDeviceSettings::setGPTPEnabledPort, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("is_gptp_clock_syntonization_enabled", &IDeviceSettings::isGPTPClockSyntonizationEnabled, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_gptp_clock_syntonization_enabled", &IDeviceSettings::setGPTPClockSyntonizationEnabled, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// Linux operating-system settings (Fire3 family devices)
|
||||
.def("get_linux_boot_enabled", &IDeviceSettings::getLinuxBootEnabled, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_linux_boot_enabled", &IDeviceSettings::setLinuxBootEnabled, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_external_wifi_antenna_enabled", &IDeviceSettings::getExternalWifiAntennaEnabled, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_external_wifi_antenna_enabled", &IDeviceSettings::setExternalWifiAntennaEnabled, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("get_linux_configuration_port", &IDeviceSettings::getLinuxConfigurationPort, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
.def("set_linux_configuration_port", &IDeviceSettings::setLinuxConfigurationPort, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||
|
||||
// Status properties
|
||||
.def_readonly("disabled", &IDeviceSettings::disabled)
|
||||
.def_readonly("readonly", &IDeviceSettings::readonly);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
#include "icsneo/device/versionreport.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_versionreport(pybind11::module_& m) {
|
||||
pybind11::classh<VersionReport>(m, "VersionReport")
|
||||
.def_readonly("id", &VersionReport::id)
|
||||
.def_readonly("name", &VersionReport::name)
|
||||
.def_readonly("major", &VersionReport::major)
|
||||
.def_readonly("minor", &VersionReport::minor)
|
||||
.def_readonly("maintenance", &VersionReport::maintenance)
|
||||
.def_readonly("build", &VersionReport::build);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -1,29 +0,0 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
#include "icsneo/disk/diskdetails.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_diskdetails(pybind11::module_& m) {
|
||||
pybind11::enum_<DiskLayout>(m, "DiskLayout")
|
||||
.value("Spanned", DiskLayout::Spanned)
|
||||
.value("RAID0", DiskLayout::RAID0);
|
||||
|
||||
pybind11::classh<DiskInfo>(m, "DiskInfo")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("present", &DiskInfo::present)
|
||||
.def_readwrite("initialized", &DiskInfo::initialized)
|
||||
.def_readwrite("formatted", &DiskInfo::formatted)
|
||||
.def_readwrite("sectors", &DiskInfo::sectors)
|
||||
.def_readwrite("bytes_per_sector", &DiskInfo::bytesPerSector)
|
||||
.def("size", &DiskInfo::size);
|
||||
|
||||
pybind11::classh<DiskDetails>(m, "DiskDetails")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("layout", &DiskDetails::layout)
|
||||
.def_readwrite("full_format", &DiskDetails::fullFormat)
|
||||
.def_readwrite("disks", &DiskDetails::disks);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -1,26 +0,0 @@
|
||||
#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::classh<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
|
||||
@@ -1,195 +0,0 @@
|
||||
#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"
|
||||
#include "icsneo/device/extensions/flexray/controller.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
struct FlexRayNamespace {
|
||||
using Symbol = icsneo::FlexRay::Symbol;
|
||||
using CRCStatus = icsneo::FlexRay::CRCStatus;
|
||||
using Channel = icsneo::FlexRay::Channel;
|
||||
};
|
||||
|
||||
namespace FlexRay {
|
||||
|
||||
struct ClusterNamespace {
|
||||
using SpeedType = icsneo::FlexRay::Cluster::SpeedType;
|
||||
using SPPType = icsneo::FlexRay::Cluster::SPPType;
|
||||
};
|
||||
|
||||
void init_extension(pybind11::classh<FlexRayNamespace>& c) {
|
||||
pybind11::classh<MessageBuffer>(c, "MessageBuffer")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("is_dynamic", &MessageBuffer::isDynamic)
|
||||
.def_readwrite("is_sync", &MessageBuffer::isSync)
|
||||
.def_readwrite("is_startup", &MessageBuffer::isStartup)
|
||||
.def_readwrite("is_network_management_frame", &MessageBuffer::isNetworkManagementFrame)
|
||||
.def_readwrite("is_transmit", &MessageBuffer::isTransmit)
|
||||
.def_readwrite("frame_id", &MessageBuffer::frameID)
|
||||
.def_readwrite("channel_a", &MessageBuffer::channelA)
|
||||
.def_readwrite("channel_b", &MessageBuffer::channelB)
|
||||
.def_readwrite("frame_length_bytes", &MessageBuffer::frameLengthBytes)
|
||||
.def_readwrite("base_cycle", &MessageBuffer::baseCycle)
|
||||
.def_readwrite("cycle_repetition", &MessageBuffer::cycleRepetition)
|
||||
.def_readwrite("continuous_mode", &MessageBuffer::continuousMode);
|
||||
|
||||
auto controller = pybind11::classh<Controller>(c, "Controller")
|
||||
.def("get_network", &Controller::getNetwork)
|
||||
.def("get_configuration", &Controller::getConfiguration)
|
||||
.def("set_configuration", &Controller::setConfiguration)
|
||||
.def("get_start_when_going_online", &Controller::getStartWhenGoingOnline)
|
||||
.def("set_start_when_going_online", &Controller::setStartWhenGoingOnline)
|
||||
.def("get_allow_coldstart", &Controller::getAllowColdstart)
|
||||
.def("set_allow_coldstart", &Controller::setAllowColdstart)
|
||||
.def("get_wakeup_before_start", &Controller::getWakeupBeforeStart)
|
||||
.def("set_wakeup_before_start", &Controller::setWakeupBeforeStart)
|
||||
.def("add_message_buffer", &Controller::addMessageBuffer)
|
||||
.def("clear_message_buffers", &Controller::clearMessageBuffers)
|
||||
.def("wakeup", &Controller::wakeup)
|
||||
.def("configure", &Controller::getReady)
|
||||
.def("start", &Controller::start)
|
||||
.def("transmit", &Controller::transmit)
|
||||
.def("halt", &Controller::halt)
|
||||
.def("freeze", &Controller::freeze)
|
||||
.def("trigger_mts", &Controller::triggerMTS);
|
||||
|
||||
pybind11::classh<Controller::Configuration>(controller, "Configuration")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("accept_startup_range_microticks", &Controller::Configuration::AcceptStartupRangeMicroticks)
|
||||
.def_readwrite("allow_passive_to_active_cycle_pairs", &Controller::Configuration::AllowPassiveToActiveCyclePairs)
|
||||
.def_readwrite("cluster_drift_damping", &Controller::Configuration::ClusterDriftDamping)
|
||||
.def_readwrite("allow_halt_due_to_clock", &Controller::Configuration::AllowHaltDueToClock)
|
||||
.def_readwrite("channel_a", &Controller::Configuration::ChannelA)
|
||||
.def_readwrite("channel_b", &Controller::Configuration::ChannelB)
|
||||
.def_readwrite("decoding_correction_microticks", &Controller::Configuration::DecodingCorrectionMicroticks)
|
||||
.def_readwrite("delay_compensation_a_microticks", &Controller::Configuration::DelayCompensationAMicroticks)
|
||||
.def_readwrite("delay_compensation_b_microticks", &Controller::Configuration::DelayCompensationBMicroticks)
|
||||
.def_readwrite("extern_offset_correction_control", &Controller::Configuration::ExternOffsetCorrectionControl)
|
||||
.def_readwrite("extern_rate_correction_control", &Controller::Configuration::ExternRateCorrectionControl)
|
||||
.def_readwrite("extern_offset_correction_microticks", &Controller::Configuration::ExternOffsetCorrectionMicroticks)
|
||||
.def_readwrite("extern_rate_correction_microticks", &Controller::Configuration::ExternRateCorrectionMicroticks)
|
||||
.def_readwrite("key_slot_id", &Controller::Configuration::KeySlotID)
|
||||
.def_readwrite("key_slot_only_enabled", &Controller::Configuration::KeySlotOnlyEnabled)
|
||||
.def_readwrite("key_slot_used_for_startup", &Controller::Configuration::KeySlotUsedForStartup)
|
||||
.def_readwrite("key_slot_used_for_sync", &Controller::Configuration::KeySlotUsedForSync)
|
||||
.def_readwrite("latest_tx_minislot", &Controller::Configuration::LatestTxMinislot)
|
||||
.def_readwrite("listen_timeout", &Controller::Configuration::ListenTimeout)
|
||||
.def_readwrite("macro_initial_offset_a", &Controller::Configuration::MacroInitialOffsetA)
|
||||
.def_readwrite("macro_initial_offset_b", &Controller::Configuration::MacroInitialOffsetB)
|
||||
.def_readwrite("micro_initial_offset_a", &Controller::Configuration::MicroInitialOffsetA)
|
||||
.def_readwrite("micro_initial_offset_b", &Controller::Configuration::MicroInitialOffsetB)
|
||||
.def_readwrite("micro_per_cycle", &Controller::Configuration::MicroPerCycle)
|
||||
.def_readwrite("mts_on_a", &Controller::Configuration::MTSOnA)
|
||||
.def_readwrite("mts_on_b", &Controller::Configuration::MTSOnB)
|
||||
.def_readwrite("offset_correction_out_microticks", &Controller::Configuration::OffsetCorrectionOutMicroticks)
|
||||
.def_readwrite("rate_correction_out_microticks", &Controller::Configuration::RateCorrectionOutMicroticks)
|
||||
.def_readwrite("second_key_slot_id", &Controller::Configuration::SecondKeySlotID)
|
||||
.def_readwrite("two_key_slot_mode", &Controller::Configuration::TwoKeySlotMode)
|
||||
.def_readwrite("wakeup_pattern", &Controller::Configuration::WakeupPattern)
|
||||
.def_readwrite("wakeup_on_channel_b", &Controller::Configuration::WakeupOnChannelB);
|
||||
|
||||
// Dummy class for cluster namespace
|
||||
pybind11::classh<ClusterNamespace> cluster(c, "Cluster");
|
||||
|
||||
pybind11::enum_<Cluster::SpeedType>(cluster, "SpeedType")
|
||||
.value("FLEXRAY_BAUDRATE_10M", Cluster::SpeedType::FLEXRAY_BAUDRATE_10M)
|
||||
.value("FLEXRAY_BAUDRATE_5M", Cluster::SpeedType::FLEXRAY_BAUDRATE_5M)
|
||||
.value("FLEXRAY_BAUDRATE_2M5", Cluster::SpeedType::FLEXRAY_BAUDRATE_2M5)
|
||||
.value("FLEXRAY_BAUDRATE_2M5_ALT", Cluster::SpeedType::FLEXRAY_BAUDRATE_2M5_ALT);
|
||||
|
||||
pybind11::enum_<Cluster::SPPType>(cluster, "SPPType")
|
||||
.value("FLEXRAY_SPP_5", Cluster::SPPType::FLEXRAY_SPP_5)
|
||||
.value("FLEXRAY_SPP_4", Cluster::SPPType::FLEXRAY_SPP_4)
|
||||
.value("FLEXRAY_SPP_6", Cluster::SPPType::FLEXRAY_SPP_6)
|
||||
.value("FLEXRAY_SPP_5_ALT", Cluster::SPPType::FLEXRAY_SPP_5_ALT);
|
||||
|
||||
pybind11::classh<Cluster::Configuration>(cluster, "Configuration")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("speed", &Cluster::Configuration::Speed)
|
||||
.def_readwrite("strobe_point_position", &Cluster::Configuration::StrobePointPosition)
|
||||
.def_readwrite("action_point_offset", &Cluster::Configuration::ActionPointOffset)
|
||||
.def_readwrite("casr_x_low_max", &Cluster::Configuration::CASRxLowMax)
|
||||
.def_readwrite("cold_start_attempts", &Cluster::Configuration::ColdStartAttempts)
|
||||
.def_readwrite("cycle_duration_micro_sec", &Cluster::Configuration::CycleDurationMicroSec)
|
||||
.def_readwrite("dynamic_slot_idle_phase_minislots", &Cluster::Configuration::DynamicSlotIdlePhaseMinislots)
|
||||
.def_readwrite("listen_noise_macroticks", &Cluster::Configuration::ListenNoiseMacroticks)
|
||||
.def_readwrite("macroticks_per_cycle", &Cluster::Configuration::MacroticksPerCycle)
|
||||
.def_readwrite("macrotick_duration_micro_sec", &Cluster::Configuration::MacrotickDurationMicroSec)
|
||||
.def_readwrite("max_without_clock_correction_fatal", &Cluster::Configuration::MaxWithoutClockCorrectionFatal)
|
||||
.def_readwrite("max_without_clock_correction_passive", &Cluster::Configuration::MaxWithoutClockCorrectionPassive)
|
||||
.def_readwrite("minislot_action_point_offset_macroticks", &Cluster::Configuration::MinislotActionPointOffsetMacroticks)
|
||||
.def_readwrite("minislot_duration_macroticks", &Cluster::Configuration::MinislotDurationMacroticks)
|
||||
.def_readwrite("network_idle_time_macroticks", &Cluster::Configuration::NetworkIdleTimeMacroticks)
|
||||
.def_readwrite("network_management_vector_length_bytes", &Cluster::Configuration::NetworkManagementVectorLengthBytes)
|
||||
.def_readwrite("number_of_minislots", &Cluster::Configuration::NumberOfMinislots)
|
||||
.def_readwrite("number_of_static_slots", &Cluster::Configuration::NumberOfStaticSlots)
|
||||
.def_readwrite("offset_correction_start_macroticks", &Cluster::Configuration::OffsetCorrectionStartMacroticks)
|
||||
.def_readwrite("payload_length_of_static_slot_in_words", &Cluster::Configuration::PayloadLengthOfStaticSlotInWords)
|
||||
.def_readwrite("static_slot_macroticks", &Cluster::Configuration::StaticSlotMacroticks)
|
||||
.def_readwrite("symbol_window_macroticks", &Cluster::Configuration::SymbolWindowMacroticks)
|
||||
.def_readwrite("symbol_window_action_point_offset_macroticks", &Cluster::Configuration::SymbolWindowActionPointOffsetMacroticks)
|
||||
.def_readwrite("sync_frame_id_count_max", &Cluster::Configuration::SyncFrameIDCountMax)
|
||||
.def_readwrite("transmission_start_sequence_duration_bits", &Cluster::Configuration::TransmissionStartSequenceDurationBits)
|
||||
.def_readwrite("wakeup_rx_idle_bits", &Cluster::Configuration::WakeupRxIdleBits)
|
||||
.def_readwrite("wakeup_rx_low_bits", &Cluster::Configuration::WakeupRxLowBits)
|
||||
.def_readwrite("wakeup_rx_window_bits", &Cluster::Configuration::WakeupRxWindowBits)
|
||||
.def_readwrite("wakeup_tx_active_bits", &Cluster::Configuration::WakeupTxActiveBits)
|
||||
.def_readwrite("wakeup_tx_idle_bits", &Cluster::Configuration::WakeupTxIdleBits);
|
||||
}
|
||||
|
||||
} // namespace FlexRay
|
||||
|
||||
void init_flexraymessage(pybind11::module_& m) {
|
||||
pybind11::classh<FlexRayMessage, Frame>(m, "FlexRayMessage")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("slotid", &FlexRayMessage::slotid)
|
||||
.def_readwrite("tsslen", &FlexRayMessage::tsslen)
|
||||
.def_readwrite("framelen", &FlexRayMessage::framelen)
|
||||
.def_readwrite("symbol", &FlexRayMessage::symbol)
|
||||
.def_readwrite("header_crc_status", &FlexRayMessage::headerCRCStatus)
|
||||
.def_readwrite("header_crc", &FlexRayMessage::headerCRC)
|
||||
.def_readwrite("frame_crc_status", &FlexRayMessage::crcStatus)
|
||||
.def_readwrite("frame_crc", &FlexRayMessage::frameCRC)
|
||||
.def_readwrite("channel", &FlexRayMessage::channel)
|
||||
.def_readwrite("null_frame", &FlexRayMessage::nullFrame)
|
||||
.def_readwrite("payload_preamble", &FlexRayMessage::payloadPreamble)
|
||||
.def_readwrite("sync_frame", &FlexRayMessage::sync)
|
||||
.def_readwrite("startup_frame", &FlexRayMessage::startup)
|
||||
.def_readwrite("dynamic_frame", &FlexRayMessage::dynamic)
|
||||
.def_readwrite("cycle", &FlexRayMessage::cycle)
|
||||
.def_readwrite("cycle_repetition", &FlexRayMessage::cycleRepetition);
|
||||
|
||||
//// TODO: Eliminate FlexRayControlMessage class references in controller class and eliminate getStatus function in bindings
|
||||
}
|
||||
|
||||
void init_flexray(pybind11::module_& m) {
|
||||
// Dummy class to act as FlexRay namespace
|
||||
pybind11::classh<FlexRayNamespace> flexray(m, "FlexRay");
|
||||
|
||||
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);
|
||||
|
||||
init_flexraymessage(m);
|
||||
FlexRay::init_extension(flexray);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
@@ -10,7 +10,6 @@ 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_&);
|
||||
@@ -19,27 +18,12 @@ void init_ethernetmessage(pybind11::module_&);
|
||||
void init_linmessage(pybind11::module_&);
|
||||
void init_tc10statusmessage(pybind11::module_&);
|
||||
void init_gptpstatusmessage(pybind11::module_&);
|
||||
void init_allmacaddressesmessage(pybind11::module_&);
|
||||
void init_apperrormessage(pybind11::module_&);
|
||||
void init_mdiomessage(pybind11::module_&);
|
||||
void init_spimessage(pybind11::module_&);
|
||||
void init_ethernetstatusmessage(pybind11::module_&);
|
||||
void init_macsecconfig(pybind11::module_&);
|
||||
void init_scriptstatusmessage(pybind11::module_&);
|
||||
void init_diskdriver(pybind11::module_&);
|
||||
void init_diskdetails(pybind11::module_&);
|
||||
void init_deviceextension(pybind11::module_&);
|
||||
void init_chipid(pybind11::module_&);
|
||||
void init_versionreport(pybind11::module_&);
|
||||
void init_device(pybind11::module_&);
|
||||
void init_messagefilter(pybind11::module_&);
|
||||
void init_messagecallback(pybind11::module_&);
|
||||
void init_version(pybind11::module_&);
|
||||
void init_flexray(pybind11::module_& m);
|
||||
void init_idevicesettings(pybind11::module_&);
|
||||
void init_ethphymessage(pybind11::module_&);
|
||||
void init_livedata(pybind11::module_&);
|
||||
void init_livedatamessage(pybind11::module_&);
|
||||
|
||||
PYBIND11_MODULE(icsneopy, m) {
|
||||
pybind11::options options;
|
||||
@@ -52,8 +36,6 @@ PYBIND11_MODULE(icsneopy, m) {
|
||||
init_version(m);
|
||||
init_devicetype(m);
|
||||
init_network(m);
|
||||
init_io(m);
|
||||
init_livedata(m);
|
||||
init_message(m);
|
||||
init_canmessage(m);
|
||||
init_canerrormessage(m);
|
||||
@@ -61,25 +43,11 @@ PYBIND11_MODULE(icsneopy, m) {
|
||||
init_linmessage(m);
|
||||
init_tc10statusmessage(m);
|
||||
init_gptpstatusmessage(m);
|
||||
init_allmacaddressesmessage(m);
|
||||
init_apperrormessage(m);
|
||||
init_mdiomessage(m);
|
||||
init_ethernetstatusmessage(m);
|
||||
init_macsecconfig(m);
|
||||
init_scriptstatusmessage(m);
|
||||
init_spimessage(m);
|
||||
init_livedatamessage(m);
|
||||
init_messagefilter(m);
|
||||
init_messagecallback(m);
|
||||
init_diskdriver(m);
|
||||
init_diskdetails(m);
|
||||
init_flexray(m);
|
||||
init_ethphymessage(m);
|
||||
init_chipid(m);
|
||||
init_versionreport(m);
|
||||
init_device(m);
|
||||
init_deviceextension(m);
|
||||
init_idevicesettings(m);
|
||||
|
||||
m.def("find_all_devices", &FindAllDevices);
|
||||
m.def("get_supported_devices", &GetSupportedDevices);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# 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
@@ -0,0 +1,293 @@
|
||||
# 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"
|
||||
@@ -0,0 +1,22 @@
|
||||
[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"
|
||||
@@ -0,0 +1,40 @@
|
||||
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!");
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
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(())
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
@@ -0,0 +1,902 @@
|
||||
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,7 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
yum install -y flex ca-certificates || exit 1
|
||||
|
||||
echo "$ICS_IPA_CA_CRT" >/etc/pki/ca-trust/source/anchors/ica-ipa-ca.crt
|
||||
|
||||
update-ca-trust || exit 1
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/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
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release -DLIBICSNEO_BUILD_EXAMPLES=ON \
|
||||
-DLIBICSNEO_BUILD_UNIT_TESTS=ON -DLIBICSNEO_ENABLE_TCP=OFF || exit 1
|
||||
-DLIBICSNEO_BUILD_UNIT_TESTS=ON -DLIBICSNEO_BUILD_SYSTEM_TESTS=ON -DLIBICSNEO_ENABLE_TCP=OFF || exit 1
|
||||
|
||||
cmake --build build || exit 1
|
||||
|
||||
|
||||
+11
-8
@@ -1,9 +1,12 @@
|
||||
@setlocal
|
||||
@echo off
|
||||
REM clean intermediate directories
|
||||
rmdir /s /q build
|
||||
mkdir build
|
||||
|
||||
mkdir build >nul 2>&1
|
||||
|
||||
cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release -DLIBICSNEO_BUILD_UNIT_TESTS=ON ^
|
||||
-DLIBICSNEO_ENABLE_TCP=ON || exit /b 1
|
||||
|
||||
cmake --build build || exit /b 1
|
||||
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 ..
|
||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
cmake --build .
|
||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
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()
|
||||
@@ -14,12 +14,6 @@
|
||||
#include "icsneo/communication/message/readsettingsmessage.h"
|
||||
#include "icsneo/communication/message/versionmessage.h"
|
||||
#include "icsneo/communication/message/componentversionsmessage.h"
|
||||
#include "icsneo/communication/message/filter/extendedresponsefilter.h"
|
||||
#include "icsneo/communication/message/clientidmessage.h"
|
||||
#include "icsneo/communication/icspb.h"
|
||||
|
||||
#include <commands/generic/v1/client_id.pb.h>
|
||||
#include <commands/network/v1/mutex.pb.h>
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
@@ -43,28 +37,29 @@ 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();
|
||||
}
|
||||
|
||||
@@ -319,32 +314,3 @@ std::optional< std::vector<ComponentVersion> > Communication::getComponentVersio
|
||||
|
||||
return std::make_optional< std::vector<ComponentVersion> >(std::move(ver->versions));
|
||||
}
|
||||
|
||||
std::optional<uint32_t> Communication::getClientIDSync() {
|
||||
constexpr auto timeout = std::chrono::milliseconds(250);
|
||||
commands::generic::v1::ClientId msg;
|
||||
msg.Clear();
|
||||
|
||||
std::vector<uint8_t> payload = protoapi::getPayload(protoapi::Command::GET, msg);
|
||||
|
||||
std::shared_ptr<Message> response = waitForMessageSync(
|
||||
[this, payload](){
|
||||
return sendCommand(ExtendedCommand::ProtobufAPI, payload);
|
||||
},
|
||||
std::make_shared<MessageFilter>(Message::Type::ClientId),
|
||||
timeout
|
||||
);
|
||||
|
||||
if(!response) {
|
||||
report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto clientIdMessage = std::dynamic_pointer_cast<ClientIdMessage>(response);
|
||||
if(!clientIdMessage) {
|
||||
report(APIEvent::Type::UnexpectedResponse, APIEvent::Severity::Error);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return clientIdMessage->clientId;
|
||||
}
|
||||
|
||||
@@ -16,16 +16,12 @@
|
||||
#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"
|
||||
#include "icsneo/communication/message/gptpstatusmessage.h"
|
||||
#include "icsneo/communication/message/allmacaddressesmessage.h"
|
||||
#include "icsneo/communication/message/apperrormessage.h"
|
||||
#include "icsneo/communication/message/ethernetstatusmessage.h"
|
||||
#include "icsneo/communication/message/networkmutexmessage.h"
|
||||
#include "icsneo/communication/message/clientidmessage.h"
|
||||
#include "icsneo/communication/command.h"
|
||||
#include "icsneo/device/device.h"
|
||||
#include "icsneo/communication/packet/canpacket.h"
|
||||
@@ -46,9 +42,6 @@
|
||||
#include "icsneo/communication/packet/genericbinarystatuspacket.h"
|
||||
#include "icsneo/communication/packet/livedatapacket.h"
|
||||
#include "icsneo/communication/packet/hardwareinfopacket.h"
|
||||
#include "icsneo/communication/packet/spipacket.h"
|
||||
#include "icsneo/communication/icspb.h"
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -63,9 +56,8 @@ uint64_t Decoder::GetUInt64FromLEBytes(const uint8_t* bytes) {
|
||||
|
||||
bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Packet>& packet) {
|
||||
switch(packet->network.getType()) {
|
||||
case Network::Type::Ethernet:
|
||||
case Network::Type::AutomotiveEthernet: {
|
||||
result = HardwareEthernetPacket::DecodeToMessage(packet->data);
|
||||
case Network::Type::Ethernet: {
|
||||
result = HardwareEthernetPacket::DecodeToMessage(packet->data, report);
|
||||
if(!result) {
|
||||
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
|
||||
return false; // A nullptr was returned, the packet was not long enough to decode
|
||||
@@ -97,7 +89,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||
result->timestamp *= timestampResolution;
|
||||
|
||||
switch(result->type) {
|
||||
case Message::Type::Frame: {
|
||||
case Message::Type::BusMessage: {
|
||||
CANMessage& can = *static_cast<CANMessage*>(result.get());
|
||||
can.network = packet->network;
|
||||
break;
|
||||
@@ -191,19 +183,6 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||
msg.timestamp *= timestampResolution;
|
||||
return true;
|
||||
}
|
||||
case Network::Type::SPI: {
|
||||
result = HardwareSPIPacket::DecodeToMessage(packet->data);
|
||||
|
||||
if(!result) {
|
||||
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
|
||||
return false; // A nullptr was returned, the packet was not long enough to decode
|
||||
}
|
||||
|
||||
SPIMessage& msg = *static_cast<SPIMessage*>(result.get());
|
||||
msg.network = packet->network;
|
||||
msg.timestamp *= timestampResolution;
|
||||
return true;
|
||||
}
|
||||
case Network::Type::MDIO: {
|
||||
result = HardwareMDIOPacket::DecodeToMessage(packet->data);
|
||||
|
||||
@@ -254,7 +233,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<RawMessage>(Network::NetID::Device);
|
||||
auto rawmsg = std::make_shared<InternalMessage>(Network::NetID::Device);
|
||||
result = rawmsg;
|
||||
rawmsg->data = packet->data;
|
||||
return true;
|
||||
@@ -279,12 +258,12 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||
result = can;
|
||||
}
|
||||
|
||||
result->timestamp = can->timestamp * timestampResolution;
|
||||
result->timestamp *= timestampResolution;
|
||||
return true;
|
||||
}
|
||||
case Network::NetID::DeviceStatus: {
|
||||
// Just pass along the data, the device needs to handle this itself
|
||||
result = std::make_shared<RawMessage>(packet->network, packet->data);
|
||||
result = std::make_shared<InternalMessage>(packet->network, packet->data);
|
||||
return true;
|
||||
}
|
||||
case Network::NetID::RED_INT_MEMORYREAD: {
|
||||
@@ -327,15 +306,11 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||
case ExtendedCommand::GenericBinaryInfo:
|
||||
result = GenericBinaryStatusPacket::DecodeToMessage(packet->data);
|
||||
return true;
|
||||
case ExtendedCommand::SoftwareUpdate: {
|
||||
result = std::make_shared<ExtendedResponseMessage>(ExtendedCommand::SoftwareUpdate, ExtendedResponse::OperationPending, packet->data);
|
||||
return true;
|
||||
}
|
||||
case ExtendedCommand::GenericReturn: {
|
||||
if(packet->data.size() < sizeof(ExtendedResponseMessage::PackedGenericResponse))
|
||||
break;
|
||||
const auto& packedResp = *reinterpret_cast<ExtendedResponseMessage::PackedGenericResponse*>(packet->data.data());
|
||||
result = std::make_shared<ExtendedResponseMessage>(packedResp.command, packedResp.returnCode, packet->data);
|
||||
result = std::make_shared<ExtendedResponseMessage>(packedResp.command, packedResp.returnCode);
|
||||
return true;
|
||||
}
|
||||
case ExtendedCommand::LiveData:
|
||||
@@ -344,45 +319,12 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||
case ExtendedCommand::GetTC10Status:
|
||||
result = TC10StatusMessage::DecodeToMessage(packet->data);
|
||||
return true;
|
||||
case ExtendedCommand::GetAllMACAddresses:
|
||||
result = AllMACAddressesMessage::DecodeToMessage(packet->data);
|
||||
return true;
|
||||
case ExtendedCommand::GetGPTPStatus: {
|
||||
result = GPTPStatus::DecodeToMessage(packet->data, report);
|
||||
return true;
|
||||
}
|
||||
case ExtendedCommand::ProtobufAPI: {
|
||||
// get the proto id
|
||||
std::vector<uint8_t> responseBody(
|
||||
packet->data.begin() + sizeof(ExtendedResponseMessage::ResponseHeader),
|
||||
packet->data.end()
|
||||
);
|
||||
protoapi::Id protoId = protoapi::getProtoId(responseBody.data(), responseBody.size());
|
||||
switch(protoId) {
|
||||
case protoapi::Id::NetworkMutex:
|
||||
result = NetworkMutexMessage::DecodeToMessage(responseBody);
|
||||
return true;
|
||||
case protoapi::Id::ClientId:
|
||||
result = ClientIdMessage::DecodeToMessage(responseBody);
|
||||
return true;
|
||||
default:
|
||||
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
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 RawMessage
|
||||
// No defined handler, treat this as a InternalMessage
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -549,16 +491,7 @@ 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;
|
||||
@@ -566,6 +499,6 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||
}
|
||||
|
||||
// For the moment other types of messages will automatically be decoded as raw messages
|
||||
result = std::make_shared<RawMessage>(packet->network, packet->data);
|
||||
result = std::make_shared<InternalMessage>(packet->network, packet->data);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,10 +38,18 @@ bool Driver::waitForRx(std::function<bool()> predicate, std::chrono::millisecond
|
||||
}
|
||||
|
||||
bool Driver::readWait(std::vector<uint8_t>& bytes, std::chrono::milliseconds timeout, size_t limit) {
|
||||
// wait until we have enough data, or the timeout occurs
|
||||
// A limit of zero indicates no limit
|
||||
if(limit == 0)
|
||||
limit = (size_t)-1;
|
||||
|
||||
if(limit > (readBuffer.size() + 4))
|
||||
limit = (readBuffer.size() + 4);
|
||||
|
||||
|
||||
// wait until we have enough data, or the timout occurs
|
||||
waitForRx(limit, timeout);
|
||||
|
||||
size_t actuallyRead = readBuffer.size();
|
||||
size_t actuallyRead = std::min(readBuffer.size(), limit);
|
||||
bytes.resize(actuallyRead);
|
||||
|
||||
readBuffer.read(bytes.data(), 0, actuallyRead);
|
||||
@@ -71,12 +79,8 @@ bool Driver::write(const std::vector<uint8_t>& bytes) {
|
||||
|
||||
if(writeBlocks) {
|
||||
if(writeQueueFull()) {
|
||||
while(writeQueueAlmostFull() && !isDisconnected() && !isClosing()) // Wait until we have some decent amount of space
|
||||
while(writeQueueAlmostFull()) // Wait until we have some decent amount of space
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
|
||||
if(isDisconnected() || isClosing()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(writeQueueFull()) {
|
||||
|
||||
+10
-36
@@ -13,7 +13,6 @@
|
||||
#include "icsneo/communication/packet/a2bpacket.h"
|
||||
#include "icsneo/communication/packet/linpacket.h"
|
||||
#include "icsneo/communication/packet/mdiopacket.h"
|
||||
#include "icsneo/communication/packet/spipacket.h"
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
@@ -24,39 +23,27 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
|
||||
result.clear();
|
||||
|
||||
switch(message->type) {
|
||||
case Message::Type::Frame: {
|
||||
auto frame = std::dynamic_pointer_cast<Frame>(message);
|
||||
case Message::Type::BusMessage: {
|
||||
auto frame = std::dynamic_pointer_cast<BusMessage>(message);
|
||||
|
||||
// Frame uses frame->data as the buffer unless directed otherwise
|
||||
buffer = &frame->data;
|
||||
netid = uint16_t(frame->network.getNetID());
|
||||
|
||||
switch(frame->network.getType()) {
|
||||
case Network::Type::Ethernet:
|
||||
case Network::Type::AutomotiveEthernet: {
|
||||
case Network::Type::Ethernet: {
|
||||
auto ethmsg = std::dynamic_pointer_cast<EthernetMessage>(message);
|
||||
if(!ethmsg) {
|
||||
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
|
||||
return false;
|
||||
return false; // The message was not a properly formed EthernetMessage
|
||||
}
|
||||
|
||||
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)) {
|
||||
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
|
||||
if(!HardwareEthernetPacket::EncodeFromMessage(*ethmsg, result, report))
|
||||
return false;
|
||||
}
|
||||
|
||||
if(result.empty()) {
|
||||
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case Network::Type::Internal:
|
||||
} // End of Network::Type::Ethernet
|
||||
case Network::Type::CAN:
|
||||
case Network::Type::SWCAN:
|
||||
case Network::Type::LSFTCAN: {
|
||||
@@ -136,17 +123,6 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
|
||||
}
|
||||
break;
|
||||
} // End of Network::Type::MDIO
|
||||
case Network::Type::SPI: {
|
||||
auto msg = std::dynamic_pointer_cast<SPIMessage>(message);
|
||||
if(!msg) {
|
||||
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
|
||||
return false; // The message was not a properly formed LiveDataMessage
|
||||
}
|
||||
if(!HardwareSPIPacket::EncodeFromMessage(*msg, result, report))
|
||||
return false;
|
||||
result = packetizer.packetWrap(result, false);
|
||||
return true;
|
||||
} // End of Network::Type::SPI
|
||||
default:
|
||||
report(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error);
|
||||
return false;
|
||||
@@ -154,8 +130,8 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
|
||||
|
||||
break;
|
||||
}
|
||||
case Message::Type::RawMessage: {
|
||||
auto raw = std::dynamic_pointer_cast<RawMessage>(message);
|
||||
case Message::Type::InternalMessage: {
|
||||
auto raw = std::dynamic_pointer_cast<InternalMessage>(message);
|
||||
|
||||
// Raw message uses raw->data as the buffer unless directed otherwise
|
||||
buffer = &raw->data;
|
||||
@@ -254,6 +230,7 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
|
||||
(uint8_t)(netid >> 8)
|
||||
});
|
||||
}
|
||||
|
||||
result = packetizer.packetWrap(*buffer, shortFormat);
|
||||
return true;
|
||||
}
|
||||
@@ -266,7 +243,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<RawMessage>(Network::NetID::Device);
|
||||
auto canmsg = std::make_shared<InternalMessage>(Network::NetID::Device);
|
||||
msg = canmsg;
|
||||
if(arguments.empty()) {
|
||||
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
|
||||
@@ -285,12 +262,9 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
|
||||
case Command::RequestSerialNumber:
|
||||
case Command::EnableNetworkCommunication:
|
||||
case Command::EnableNetworkCommunicationEx:
|
||||
case Command::KeepAlive:
|
||||
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,5 +1,4 @@
|
||||
#include "icsneo/communication/livedata.h"
|
||||
#include <cmath>
|
||||
namespace icsneo {
|
||||
|
||||
namespace LiveDataUtil {
|
||||
@@ -19,62 +18,5 @@ double liveDataValueToDouble(const LiveDataValue& val) {
|
||||
return val.value * liveDataFixedPointToDouble;
|
||||
}
|
||||
|
||||
std::optional<LiveDataValue> 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 value;
|
||||
|
||||
//check if double can be stored as 32.32
|
||||
// 0x1 0000 0000 0000 0000 * CM_FIXED_POINT_TO_DOUBLEVALUE = 0x1 0000 0000
|
||||
if(dFloat > INT32_MAX_DOUBLE || dFloat < INT32_MIN_DOUBLE) {
|
||||
EventManager::GetInstance().add(APIEvent::Type::FixedPointOverflow, APIEvent::Severity::Error);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Use absolute value for minimum fixed point check
|
||||
double absFloat = (dFloat < 0.0) ? -dFloat : dFloat;
|
||||
if(absFloat < MIN_FIXED_POINT_DOUBLE) {
|
||||
EventManager::GetInstance().add(APIEvent::Type::FixedPointPrecision, APIEvent::Severity::Error);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
} // namespace LiveDataUtil
|
||||
} // namespace icsneo
|
||||
@@ -1,51 +0,0 @@
|
||||
#include "icsneo/communication/message/allmacaddressesmessage.h"
|
||||
#include "icsneo/communication/command.h"
|
||||
#include "icsneo/communication/network.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
#pragma pack(push, 2)
|
||||
struct ResponseHeader {
|
||||
ExtendedCommand command;
|
||||
uint16_t length;
|
||||
uint16_t count;
|
||||
};
|
||||
|
||||
struct MacAddrEntryPacket {
|
||||
uint16_t networkId;
|
||||
uint8_t address[MACAddressLength];
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
std::shared_ptr<AllMACAddressesMessage> AllMACAddressesMessage::DecodeToMessage(const std::vector<uint8_t>& bytestream) {
|
||||
if(bytestream.size() < sizeof(ResponseHeader))
|
||||
return nullptr;
|
||||
|
||||
const auto* hdr = reinterpret_cast<const ResponseHeader*>(bytestream.data());
|
||||
|
||||
if(hdr->command != ExtendedCommand::GetAllMACAddresses)
|
||||
return nullptr;
|
||||
|
||||
if(hdr->count > MaxMACAddressCount)
|
||||
return nullptr;
|
||||
|
||||
const size_t required = sizeof(ResponseHeader) + hdr->count * sizeof(MacAddrEntryPacket);
|
||||
if(bytestream.size() < required)
|
||||
return nullptr;
|
||||
|
||||
auto msg = std::make_shared<AllMACAddressesMessage>();
|
||||
|
||||
const auto* entries = reinterpret_cast<const MacAddrEntryPacket*>(bytestream.data() + sizeof(ResponseHeader));
|
||||
for(uint16_t i = 0; i < hdr->count; ++i) {
|
||||
// The firmware sends CoreMini network IDs — convert to NetID for consistent use in libicsneo
|
||||
Network::NetID netId = Network::GetNetIDFromCoreMiniNetwork(static_cast<Network::CoreMini>(entries[i].networkId));
|
||||
auto addr = entries[i].address;
|
||||
MACAddress arrAddr;
|
||||
std::copy(addr, addr + MACAddressLength, arrAddr.begin());
|
||||
msg->addresses.emplace(std::make_pair(netId, arrAddr));
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
@@ -102,11 +102,11 @@ bool A2BWAVOutput::callIfMatch(const std::shared_ptr<Message>& message) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(message->type != Message::Type::Frame) {
|
||||
if(message->type != Message::Type::BusMessage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& frameMsg = std::dynamic_pointer_cast<Frame>(message);
|
||||
const auto& frameMsg = std::dynamic_pointer_cast<BusMessage>(message);
|
||||
|
||||
if(!frameMsg) {
|
||||
return false;
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#include "icsneo/communication/message/clientidmessage.h"
|
||||
#include "icsneo/communication/icspb.h"
|
||||
#include "icsneo/communication/command.h"
|
||||
#include "icsneo/communication/message/extendedresponsemessage.h"
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
std::shared_ptr<ClientIdMessage> ClientIdMessage::DecodeToMessage(const std::vector<uint8_t>& bytestream) {
|
||||
ClientIdMessage decoded;
|
||||
commands::generic::v1::ClientId msg;
|
||||
|
||||
if(!protoapi::processResponse(bytestream.data(), bytestream.size(), msg)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if(msg.has_client_id()) {
|
||||
decoded.clientId.emplace(msg.client_id());
|
||||
}
|
||||
|
||||
return std::make_shared<ClientIdMessage>(decoded);
|
||||
}
|
||||
@@ -13,19 +13,11 @@ enum LinkSpeed {
|
||||
ethSpeed10000,
|
||||
};
|
||||
|
||||
enum TLinkMode {
|
||||
T_LINK_NONE,
|
||||
T_LINK_MASTER,
|
||||
T_LINK_SLAVE,
|
||||
T_LINK_AUTO,
|
||||
T_LINK_INVALID = 255,
|
||||
};
|
||||
|
||||
enum AELinkMode {
|
||||
AE_LINK_AUTO,
|
||||
AE_LINK_MASTER,
|
||||
AE_LINK_SLAVE,
|
||||
AE_LINK_INVALID = 255,
|
||||
enum LinkMode {
|
||||
OPETH_LINK_AUTO,
|
||||
OPETH_LINK_MASTER,
|
||||
OPETH_LINK_SLAVE,
|
||||
OPETH_LINK_INVALID = 255,
|
||||
};
|
||||
|
||||
struct Packet {
|
||||
@@ -37,7 +29,7 @@ struct Packet {
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
std::shared_ptr<RawMessage> EthernetStatusMessage::DecodeToMessage(const std::vector<uint8_t>& bytestream) {
|
||||
std::shared_ptr<Message> EthernetStatusMessage::DecodeToMessage(const std::vector<uint8_t>& bytestream) {
|
||||
if(bytestream.size() < sizeof(Packet)) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -54,27 +46,12 @@ std::shared_ptr<RawMessage> EthernetStatusMessage::DecodeToMessage(const std::ve
|
||||
default: return nullptr;
|
||||
}
|
||||
LinkMode mode;
|
||||
switch(Network::GetTypeOfNetID((Network::NetID)packet->network, false)) {
|
||||
case Network::Type::Ethernet:
|
||||
switch(packet->mode) {
|
||||
case T_LINK_NONE: mode = EthernetStatusMessage::LinkMode::LinkModeNone; break;
|
||||
case T_LINK_MASTER: mode = EthernetStatusMessage::LinkMode::LinkModeMaster; break;
|
||||
case T_LINK_SLAVE: mode = EthernetStatusMessage::LinkMode::LinkModeSlave; break;
|
||||
case T_LINK_AUTO: mode = EthernetStatusMessage::LinkMode::LinkModeAuto; break;
|
||||
case T_LINK_INVALID: mode = EthernetStatusMessage::LinkMode::LinkModeInvalid; break;
|
||||
default: return nullptr;
|
||||
}
|
||||
break;
|
||||
case Network::Type::AutomotiveEthernet:
|
||||
switch(packet->mode) {
|
||||
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;
|
||||
case AE_LINK_INVALID: mode = EthernetStatusMessage::LinkMode::LinkModeInvalid; break;
|
||||
default: return nullptr;
|
||||
}
|
||||
break;
|
||||
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;
|
||||
default: return nullptr;
|
||||
}
|
||||
return std::make_shared<EthernetStatusMessage>(packet->network, packet->state != 0, speed, packet->duplex != 0, mode);
|
||||
}
|
||||
return std::make_shared<EthernetStatusMessage>(packet->network, packet->state, speed, packet->duplex, mode);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ bool EthPhyMessage::appendPhyMessage(bool writeEnable, bool clause45, uint8_t ph
|
||||
msg->Clause45Enable = clause45;
|
||||
msg->Enabled = enabled;
|
||||
msg->WriteEnable = writeEnable;
|
||||
msg->Version = 1u;
|
||||
msg->version = 1u;
|
||||
if( (FiveBits < phyAddrOrPort) ||
|
||||
(clause45 && (FiveBits < pageOrDevice)) ||
|
||||
(!clause45 && (FiveBits < regAddr)) )
|
||||
@@ -18,17 +18,17 @@ bool EthPhyMessage::appendPhyMessage(bool writeEnable, bool clause45, uint8_t ph
|
||||
|
||||
if(clause45)
|
||||
{
|
||||
msg->Clause45.port = phyAddrOrPort;
|
||||
msg->Clause45.device = pageOrDevice;
|
||||
msg->Clause45.regAddr = regAddr;
|
||||
msg->Clause45.regVal = regVal;
|
||||
msg->clause45.port = phyAddrOrPort;
|
||||
msg->clause45.device = pageOrDevice;
|
||||
msg->clause45.regAddr = regAddr;
|
||||
msg->clause45.regVal = regVal;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg->Clause22.phyAddr = phyAddrOrPort;
|
||||
msg->Clause22.page = pageOrDevice;
|
||||
msg->Clause22.regAddr = regAddr;
|
||||
msg->Clause22.regVal = regVal;
|
||||
msg->clause22.phyAddr = phyAddrOrPort;
|
||||
msg->clause22.page = pageOrDevice;
|
||||
msg->clause22.regAddr = regAddr;
|
||||
msg->clause22.regVal = regVal;
|
||||
}
|
||||
return appendPhyMessage(msg);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@ 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);
|
||||
ret.push_back(controller);
|
||||
const uint16_t size = static_cast<uint16_t>(std::min(args.size() + 1, size_t(std::numeric_limits<uint16_t>::max()))); // Add 1 for the opcode
|
||||
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));
|
||||
ret.push_back(uint8_t(size >> 8));
|
||||
ret.push_back(uint8_t(op));
|
||||
|
||||
@@ -12,14 +12,4 @@ 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
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#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));
|
||||
}
|
||||
@@ -14,9 +14,9 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
|
||||
neomsg.timestamp = message->timestamp;
|
||||
switch (message->type)
|
||||
{
|
||||
case Message::Type::Frame: {
|
||||
case Message::Type::BusMessage: {
|
||||
neomessage_frame_t& frame = *(neomessage_frame_t*)&neomsg;
|
||||
auto framemsg = std::static_pointer_cast<Frame>(message);
|
||||
auto framemsg = std::static_pointer_cast<BusMessage>(message);
|
||||
const auto netType = framemsg->network.getType();
|
||||
|
||||
frame.netid = (neonetid_t)framemsg->network.getNetID();
|
||||
@@ -44,11 +44,10 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
|
||||
can.status.canfdESI = canmsg->errorStateIndicator;
|
||||
break;
|
||||
}
|
||||
case Network::Type::Ethernet:
|
||||
case Network::Type::AutomotiveEthernet: {
|
||||
case Network::Type::Ethernet: {
|
||||
neomessage_eth_t& eth = *(neomessage_eth_t*)&neomsg;
|
||||
auto ethmsg = std::static_pointer_cast<EthernetMessage>(message);
|
||||
eth.preemptionFlags = ethmsg->preemptionFlags.value_or(0);
|
||||
eth.preemptionFlags = ethmsg->preemptionFlags;
|
||||
eth.status.incompleteFrame = ethmsg->frameTooShort;
|
||||
// TODO Fill in extra status bits
|
||||
//eth.status.xyz = ethmsg->preemptionEnabled;
|
||||
@@ -76,15 +75,13 @@ neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
|
||||
lin.length = 1;
|
||||
|
||||
lin.linStatus = {
|
||||
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
|
||||
|
||||
linmsg->statusFlags.TxChecksumEnhanced,
|
||||
linmsg->statusFlags.TxCommander,
|
||||
linmsg->statusFlags.TxResponder,
|
||||
linmsg->statusFlags.UpdateResponderOnce,
|
||||
linmsg->statusFlags.HasUpdatedResponderOnce,
|
||||
linmsg->statusFlags.BusRecovered,
|
||||
linmsg->statusFlags.BreakOnly
|
||||
};
|
||||
|
||||
lin.status.linJustBreakSync = linmsg->errFlags.ErrRxBreakSyncOnly;
|
||||
@@ -123,7 +120,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::Frame: {
|
||||
case Message::Type::BusMessage: {
|
||||
const Network network = ((neomessage_frame_t*)neomessage)->netid;
|
||||
switch(network.getType()) {
|
||||
case Network::Type::CAN:
|
||||
@@ -143,8 +140,7 @@ std::shared_ptr<Message> icsneo::CreateMessageFromNeoMessage(const neomessage_t*
|
||||
canmsg->errorStateIndicator = can.status.canfdESI;
|
||||
return canmsg;
|
||||
}
|
||||
case Network::Type::Ethernet:
|
||||
case Network::Type::AutomotiveEthernet: {
|
||||
case Network::Type::Ethernet: {
|
||||
neomessage_eth_t& eth = *(neomessage_eth_t*)neomessage;
|
||||
auto ethmsg = std::make_shared<EthernetMessage>();
|
||||
ethmsg->network = network;
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
#include "icsneo/communication/message/networkmutexmessage.h"
|
||||
#include "icsneo/communication/icspb.h"
|
||||
#include "icsneo/communication/command.h"
|
||||
#include "icsneo/communication/message/extendedresponsemessage.h"
|
||||
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
std::shared_ptr<NetworkMutexMessage> NetworkMutexMessage::DecodeToMessage(const std::vector<uint8_t>& bytestream) {
|
||||
NetworkMutexMessage decoded;
|
||||
commands::network::v1::NetworkMutex msg;
|
||||
|
||||
if(!protoapi::processResponse(bytestream.data(), bytestream.size(), msg)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if(msg.has_client_id()) {
|
||||
decoded.owner_id.emplace(msg.client_id());
|
||||
}
|
||||
if(msg.has_type()) {
|
||||
decoded.type.emplace(static_cast<NetworkMutexType>(msg.type()));
|
||||
}
|
||||
if(msg.has_priority()) {
|
||||
decoded.priority.emplace(msg.priority());
|
||||
}
|
||||
if(msg.has_ttl()){
|
||||
decoded.ttlMs.emplace(msg.ttl());
|
||||
}
|
||||
if(msg.has_event()){
|
||||
decoded.event.emplace(static_cast<NetworkMutexEvent>(msg.event()));
|
||||
}
|
||||
for(int i = 0 ; i < msg.network_ids_size(); ++i){
|
||||
decoded.networks.emplace(static_cast<Network::NetID>(msg.network_ids(i)));
|
||||
}
|
||||
return std::make_shared<NetworkMutexMessage>(decoded);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> NetworkMutexMessage::EncodeArgumentsForLock(uint32_t client_id, NetworkMutexType type, uint32_t priority, uint32_t ttlMs, const std::set<Network::NetID>& networks, const device_eventhandler_t& /* report */) {
|
||||
commands::network::v1::NetworkMutex msg;
|
||||
for(auto&& network_id : networks) {
|
||||
msg.add_network_ids(static_cast<commands::network::v1::NetworkId>(network_id));
|
||||
}
|
||||
msg.set_client_id(client_id);
|
||||
msg.set_priority(priority);
|
||||
msg.set_ttl(ttlMs);
|
||||
msg.set_type(static_cast<commands::network::v1::MutexType>(type));
|
||||
|
||||
return protoapi::getPayload(protoapi::Command::PUT, msg);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> NetworkMutexMessage::EncodeArgumentsForLockAll(uint32_t client_id, NetworkMutexType type, uint32_t priority, uint32_t ttlMs, const device_eventhandler_t& /* report */) {
|
||||
commands::network::v1::NetworkMutex msg;
|
||||
msg.set_client_id(client_id);
|
||||
msg.set_priority(priority);
|
||||
msg.set_ttl(ttlMs);
|
||||
msg.set_type(static_cast<commands::network::v1::MutexType>(type));
|
||||
msg.set_global(true);
|
||||
|
||||
return protoapi::getPayload(protoapi::Command::PUT, msg);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> NetworkMutexMessage::EncodeArgumentsForUnlock(uint32_t client_id, const std::set<Network::NetID>& networks, const device_eventhandler_t& /* report */) {
|
||||
commands::network::v1::NetworkMutex msg;
|
||||
msg.Clear();
|
||||
for(auto&& network_id : networks)
|
||||
{
|
||||
msg.add_network_ids(static_cast<commands::network::v1::NetworkId>(network_id));
|
||||
}
|
||||
msg.set_client_id(client_id);
|
||||
msg.set_release(true);
|
||||
|
||||
return protoapi::getPayload(protoapi::Command::PUT, msg);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> NetworkMutexMessage::EncodeArgumentsForUnlockAll(uint32_t client_id, const device_eventhandler_t& /* report */) {
|
||||
commands::network::v1::NetworkMutex msg;
|
||||
msg.Clear();
|
||||
msg.set_client_id(client_id);
|
||||
msg.set_release(true);
|
||||
msg.set_global(true);
|
||||
|
||||
return protoapi::getPayload(protoapi::Command::PUT, msg);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> NetworkMutexMessage::EncodeArgumentsForStatus(Network::NetID network, const device_eventhandler_t& /* report */) {
|
||||
commands::network::v1::NetworkMutex msg;
|
||||
msg.add_network_ids(static_cast<commands::network::v1::NetworkId>(network));
|
||||
return protoapi::getPayload(protoapi::Command::GET, msg);
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
#include "icsneo/communication/message/transmitmessage.h"
|
||||
|
||||
// packet defs
|
||||
#include "icsneo/communication/packet/ethernetpacket.h"
|
||||
#include "icsneo/communication/packet/canpacket.h"
|
||||
#include "icsneo/communication/packet/linpacket.h"
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
static std::vector<uint8_t> EncodeFromMessageEthernet(std::shared_ptr<Frame> frame, const device_eventhandler_t& report) {
|
||||
auto ethmsg = std::dynamic_pointer_cast<EthernetMessage>(frame);
|
||||
if(!ethmsg) {
|
||||
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
|
||||
return {};
|
||||
}
|
||||
std::vector<uint8_t> encoded;
|
||||
size_t messageLen = ethmsg->data.size();
|
||||
encoded.resize(sizeof(TransmitMessage) + messageLen);
|
||||
|
||||
TransmitMessage* const msg = (TransmitMessage*)encoded.data();
|
||||
HardwareEthernetPacket* const ethpacket = (HardwareEthernetPacket*)(msg->commonHeader);
|
||||
uint8_t* const payload = encoded.data() + sizeof(TransmitMessage);
|
||||
|
||||
ethpacket->header.ENABLE_PADDING = ethmsg->noPadding ? 0 : 1;
|
||||
ethpacket->header.FCS_OVERRIDE = ethmsg->fcs ? 1 : 0;
|
||||
ethpacket->eid.txlen = static_cast<uint16_t>(messageLen);
|
||||
ethpacket->Length = static_cast<uint16_t>(messageLen);
|
||||
ethpacket->stats = ethmsg->description;
|
||||
ethpacket->NetworkID = static_cast<uint16_t>(ethmsg->network.getNetID());
|
||||
std::copy(ethmsg->data.begin(), ethmsg->data.end(), payload);
|
||||
return encoded;
|
||||
}
|
||||
|
||||
static std::vector<uint8_t> EncodeFromMessageCAN(std::shared_ptr<Frame> frame, const device_eventhandler_t& report) {
|
||||
auto canmsg = std::dynamic_pointer_cast<CANMessage>(frame);
|
||||
if(!canmsg) {
|
||||
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
|
||||
return {};
|
||||
}
|
||||
if(canmsg->isCANFD && canmsg->isRemote) {
|
||||
report(APIEvent::Type::RTRNotSupported, APIEvent::Severity::Error);
|
||||
return {}; // RTR frames can not be used with CAN FD
|
||||
}
|
||||
std::vector<uint8_t> encoded;
|
||||
size_t messageLen = canmsg->data.size();
|
||||
size_t extraLen = 0;
|
||||
if(messageLen > 8) {
|
||||
extraLen = messageLen - 8;
|
||||
}
|
||||
encoded.resize(sizeof(TransmitMessage) + extraLen);
|
||||
|
||||
TransmitMessage* const msg = (TransmitMessage*)encoded.data();
|
||||
HardwareCANPacket* const canpacket = (HardwareCANPacket*)(msg->commonHeader);
|
||||
uint8_t* const extra_payload = encoded.data() + sizeof(TransmitMessage);
|
||||
|
||||
const size_t dataSize = canmsg->data.size();
|
||||
std::optional<uint8_t> dlc = CAN_LengthToDLC(dataSize, canmsg->isCANFD);
|
||||
if(!dlc.has_value()) {
|
||||
report(APIEvent::Type::MessageMaxLengthExceeded, APIEvent::Severity::Error);
|
||||
return {}; // Too much data for the protocol
|
||||
}
|
||||
// arb id
|
||||
if(canmsg->isExtended) {
|
||||
canpacket->header.IDE = 1;
|
||||
canpacket->header.SID = (canmsg->arbid >> 18) & 0x7FF;
|
||||
canpacket->eid.EID = (canmsg->arbid >> 6) & 0xfff;
|
||||
canpacket->dlc.EID2 = canmsg->arbid & 0x3f;
|
||||
} else {
|
||||
canpacket->header.IDE = 0;
|
||||
canpacket->header.SID = canmsg->arbid & 0x7FF;
|
||||
}
|
||||
|
||||
// DLC
|
||||
canpacket->dlc.DLC = dlc.value();
|
||||
|
||||
// FDF/BRS or remote frames
|
||||
if(canmsg->isCANFD) {
|
||||
canpacket->header.EDL = 1;
|
||||
canpacket->header.BRS = canmsg->baudrateSwitch ? 1 : 0;
|
||||
canpacket->header.ESI = canmsg->errorStateIndicator ? 1 : 0;
|
||||
canpacket->dlc.RTR = 0;
|
||||
canpacket->timestamp.IsExtended = 1;
|
||||
|
||||
} else {
|
||||
canpacket->header.EDL = 0;
|
||||
canpacket->header.BRS = 0;
|
||||
canpacket->header.ESI = 0;
|
||||
canpacket->dlc.RTR = canmsg->isRemote ? 1 : 0;
|
||||
}
|
||||
// network
|
||||
canpacket->NetworkID = static_cast<uint16_t>(canmsg->network.getNetID());
|
||||
canpacket->Length = static_cast<uint16_t>(extraLen);
|
||||
// description id
|
||||
canpacket->stats = canmsg->description;
|
||||
// first 8 bytes
|
||||
std::copy(canmsg->data.begin(), canmsg->data.begin() + (messageLen > 8 ? 8 : messageLen), canpacket->data);
|
||||
// extra bytes
|
||||
if(extraLen > 0) {
|
||||
// copy extra data after the can packet
|
||||
std::copy(canmsg->data.begin() + 8, canmsg->data.end(), extra_payload);
|
||||
}
|
||||
return encoded;
|
||||
}
|
||||
|
||||
static std::vector<uint8_t> EncodeFromMessageLIN(std::shared_ptr<Frame> frame, const device_eventhandler_t& report) {
|
||||
auto linmsg = std::dynamic_pointer_cast<LINMessage>(frame);
|
||||
if(!linmsg) {
|
||||
report(APIEvent::Type::MessageFormattingError, APIEvent::Severity::Error);
|
||||
return {};
|
||||
}
|
||||
if(linmsg->linMsgType == LINMessage::Type::NOT_SET) {
|
||||
report(APIEvent::Type::RequiredParameterNull, APIEvent::Severity::Error);
|
||||
return {};
|
||||
}
|
||||
|
||||
size_t dataLen = std::min<size_t>(8, linmsg->data.size());
|
||||
std::vector<uint8_t> encoded;
|
||||
encoded.resize(sizeof(TransmitMessage));
|
||||
|
||||
TransmitMessage* const msg = (TransmitMessage*)encoded.data();
|
||||
HardwareLINPacket* const linpacket = (HardwareLINPacket*)(msg->commonHeader);
|
||||
memset(linpacket, 0, sizeof(HardwareLINPacket));
|
||||
|
||||
// Protected ID and ID
|
||||
linmsg->protectedID = linmsg->calcProtectedID(linmsg->ID);
|
||||
linpacket->CoreMiniBitsLIN.ID = linmsg->protectedID & 0x3F;
|
||||
|
||||
// LIN message type flags
|
||||
switch(linmsg->linMsgType) {
|
||||
case LINMessage::Type::LIN_COMMANDER_MSG:
|
||||
linpacket->CoreMiniBitsLIN.TXCommander = 1;
|
||||
break;
|
||||
case LINMessage::Type::LIN_HEADER_ONLY:
|
||||
linpacket->CoreMiniBitsLIN.TXCommander = 1;
|
||||
break;
|
||||
case LINMessage::Type::LIN_UPDATE_RESPONDER:
|
||||
linpacket->CoreMiniBitsLIN.TXResponder = 1;
|
||||
break;
|
||||
case LINMessage::Type::LIN_BREAK_ONLY:
|
||||
linpacket->CoreMiniBitsLIN.BreakOnly = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Enhanced checksum
|
||||
linpacket->CoreMiniBitsLIN.TxChkSumEnhanced = linmsg->isEnhancedChecksum ? 1 : 0;
|
||||
|
||||
// Data and checksum
|
||||
bool hasData = (linmsg->linMsgType == LINMessage::Type::LIN_COMMANDER_MSG ||
|
||||
linmsg->linMsgType == LINMessage::Type::LIN_UPDATE_RESPONDER) && dataLen > 0;
|
||||
|
||||
if(hasData) {
|
||||
// len includes data bytes + 1 checksum byte
|
||||
linpacket->CoreMiniBitsLIN.len = static_cast<uint16_t>(dataLen + 1);
|
||||
std::copy(linmsg->data.begin(), linmsg->data.begin() + dataLen, linpacket->data);
|
||||
// Checksum goes after data: in data[dataLen] if < 8, otherwise in LINByte9
|
||||
if(dataLen < 8)
|
||||
linpacket->data[dataLen] = linmsg->checksum;
|
||||
else
|
||||
linpacket->CoreMiniBitsLIN.LINByte9 = linmsg->checksum;
|
||||
} else {
|
||||
linpacket->CoreMiniBitsLIN.len = 0;
|
||||
}
|
||||
|
||||
// Description/stats and network
|
||||
linpacket->stats = linmsg->description;
|
||||
|
||||
return encoded;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> TransmitMessage::EncodeFromMessage(std::shared_ptr<Frame> frame, uint32_t client_id, const device_eventhandler_t& report) {
|
||||
std::vector<uint8_t> result;
|
||||
switch(frame->network.getType()) {
|
||||
case Network::Type::Ethernet:
|
||||
case Network::Type::AutomotiveEthernet:
|
||||
result = EncodeFromMessageEthernet(frame, report);
|
||||
break;
|
||||
case Network::Type::Internal:
|
||||
case Network::Type::CAN:
|
||||
result = EncodeFromMessageCAN(frame, report);
|
||||
break;
|
||||
case Network::Type::LIN:
|
||||
result = EncodeFromMessageLIN(frame, report);
|
||||
break;
|
||||
default:
|
||||
report(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error);
|
||||
return result;
|
||||
}
|
||||
// common fields
|
||||
if(result.empty())
|
||||
return result;
|
||||
TransmitMessage* const msg = (TransmitMessage*)result.data();
|
||||
msg->options.clientId = client_id;
|
||||
msg->options.networkId = static_cast<uint32_t>(frame->network.getNetID());
|
||||
msg->options.reserved[0] = 0;
|
||||
msg->options.reserved[1] = 0;
|
||||
msg->options.reserved[2] = 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using namespace icsneo;
|
||||
MultiChannelCommunication::MultiChannelCommunication(device_eventhandler_t err, std::unique_ptr<Driver> com,
|
||||
std::function<std::unique_ptr<Packetizer>()> makeConfiguredPacketizer, std::unique_ptr<Encoder> e,
|
||||
std::unique_ptr<Decoder> md, size_t vnetCount) :
|
||||
Communication(err, std::move(com), makeConfiguredPacketizer, std::move(e), std::move(md)), numVnets(vnetCount), packetRB(2048) {
|
||||
Communication(err, std::move(com), makeConfiguredPacketizer, std::move(e), std::move(md)), numVnets(vnetCount) {
|
||||
vnetThreads.resize(numVnets);
|
||||
vnetQueues.resize(numVnets);
|
||||
}
|
||||
@@ -24,7 +24,6 @@ void MultiChannelCommunication::spawnThreads() {
|
||||
|
||||
void MultiChannelCommunication::joinThreads() {
|
||||
closing = true;
|
||||
ringBufCV.notify_all();
|
||||
if(hidReadThread.joinable())
|
||||
hidReadThread.join();
|
||||
for(auto& thread : vnetThreads) {
|
||||
@@ -149,13 +148,9 @@ void MultiChannelCommunication::hidReadTask() {
|
||||
break;
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_lock lk(ringBufMutex);
|
||||
if(!packetRB.write(std::move(payloadBytes)) && gotPacket)
|
||||
EventManager::GetInstance().add(APIEvent(APIEvent::Type::FailedToRead, APIEvent::Severity::Error));
|
||||
payloadBytes.clear();
|
||||
}
|
||||
ringBufCV.notify_all();
|
||||
if(!currentQueue->enqueue(std::move(payloadBytes)) && gotPacket)
|
||||
EventManager::GetInstance().add(APIEvent(APIEvent::Type::FailedToRead, APIEvent::Severity::Error));
|
||||
payloadBytes.clear();
|
||||
gotPacket = true;
|
||||
state = PreprocessState::SearchForCommand;
|
||||
break;
|
||||
@@ -165,6 +160,7 @@ void MultiChannelCommunication::hidReadTask() {
|
||||
}
|
||||
|
||||
void MultiChannelCommunication::vnetReadTask(size_t vnetIndex) {
|
||||
moodycamel::BlockingReaderWriterQueue< std::vector<uint8_t> >& queue = vnetQueues[vnetIndex];
|
||||
std::vector<uint8_t> payloadBytes;
|
||||
std::unique_ptr<Packetizer> packetizerLifetime;
|
||||
Packetizer* vnetPacketizer;
|
||||
@@ -178,19 +174,14 @@ void MultiChannelCommunication::vnetReadTask(size_t vnetIndex) {
|
||||
EventManager::GetInstance().downgradeErrorsOnCurrentThread();
|
||||
|
||||
while(!closing) {
|
||||
std::unique_lock lk(ringBufMutex);
|
||||
ringBufCV.wait(lk);
|
||||
if(closing) {
|
||||
break;
|
||||
}
|
||||
if(vnetPacketizer->input(packetRB)) {
|
||||
for(const auto& packet : vnetPacketizer->output()) {
|
||||
std::shared_ptr<Message> msg;
|
||||
if(!decoder->decode(msg, packet))
|
||||
continue;
|
||||
if(queue.wait_dequeue_timed(payloadBytes, std::chrono::milliseconds(250))) {
|
||||
if(closing)
|
||||
break;
|
||||
|
||||
dispatchMessage(msg);
|
||||
}
|
||||
}
|
||||
auto& ringBuffer = driver->getReadBuffer();
|
||||
ringBuffer.write(payloadBytes);
|
||||
|
||||
handleInput(*vnetPacketizer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
static std::optional<uint8_t> CAN_DLCToLength(uint8_t length, bool fd) {
|
||||
std::optional<uint8_t> icsneo::CAN_DLCToLength(uint8_t length, bool fd) {
|
||||
if (length <= 8)
|
||||
return length;
|
||||
|
||||
@@ -29,7 +29,8 @@ static std::optional<uint8_t> CAN_DLCToLength(uint8_t length, bool fd) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<uint8_t> icsneo::CAN_LengthToDLC(size_t dataLength, bool fd) {
|
||||
std::optional<uint8_t> icsneo::CAN_LengthToDLC(size_t dataLength, bool fd)
|
||||
{
|
||||
if (dataLength <= 8)
|
||||
return uint8_t(dataLength);
|
||||
|
||||
@@ -113,18 +114,13 @@ std::shared_ptr<Message> HardwareCANPacket::DecodeToMessage(const std::vector<ui
|
||||
msg->data.insert(msg->data.end(), data->data, data->data + (length > 8 ? 8 : length));
|
||||
if(length > 8) { // If there are more than 8 bytes, they come at the end of the message
|
||||
// Messages with extra data are formatted as message, then uint16_t netid, then uint16_t length, then extra data
|
||||
const auto extraDataStart = bytestream.begin() + sizeof(HardwareCANPacket);
|
||||
const auto extraDataStart = bytestream.begin() + sizeof(HardwareCANPacket) + 2 + 2;
|
||||
msg->data.insert(msg->data.end(), extraDataStart, extraDataStart + (length - 8));
|
||||
}
|
||||
}
|
||||
|
||||
msg->transmitted = data->eid.TXMSG;
|
||||
// Set the generic frame error state
|
||||
msg->error = data->eid.TXAborted || data->eid.TXError || data->eid.TXLostArb;
|
||||
// Set specific error states for CANError
|
||||
msg->txAborted = data->eid.TXAborted;
|
||||
msg->txLostArb = data->eid.TXLostArb;
|
||||
msg->txError = data->eid.TXError;
|
||||
msg->description = data->stats;
|
||||
|
||||
return msg;
|
||||
|
||||
@@ -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(PackedComponentVersion));
|
||||
auto expectedSize = sizeof(ExtendedResponseMessage::ResponseHeader) + 2 + (response.numVersions * sizeof(ComponentVersion));
|
||||
// If the response is malformed (too small), return an empty message.
|
||||
if(bytes.size() < expectedSize) {
|
||||
return msg; // Empty
|
||||
@@ -39,14 +39,7 @@ 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,
|
||||
packedVersion.expansionSlot
|
||||
);
|
||||
msg->versions.emplace_back(packedVersion.valid, packedVersion.componentInfo, packedVersion.identifier, packedVersion.dotVersion, packedVersion.commitHash);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
@@ -1,63 +1,54 @@
|
||||
#include "icsneo/communication/packet/ethernetpacket.h"
|
||||
#include <algorithm>
|
||||
#include <cstring> // memcpy
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
std::shared_ptr<EthernetMessage> HardwareEthernetPacket::DecodeToMessage(const std::vector<uint8_t>& bytestream) {
|
||||
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;
|
||||
const size_t fcsSize = packet->header.FCS_AVAIL ? 4 : 0;
|
||||
// Ensure Length is sufficient for FCS extraction to avoid invalid iterator arithmetic
|
||||
if(packet->Length < fcsSize)
|
||||
|
||||
// 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;
|
||||
// Standard Ethernet fields
|
||||
|
||||
message.transmitted = packet->eid.TXMSG;
|
||||
if(message.transmitted)
|
||||
message.description = packet->stats;
|
||||
message.frameTooShort = packet->header.RUNT_FRAME;
|
||||
message.noPadding = !packet->header.ENABLE_PADDING;
|
||||
message.fcsVerified = packet->header.FCS_VERIFIED;
|
||||
message.txAborted = packet->eid.TXAborted;
|
||||
message.crcError = packet->header.CRC_ERROR;
|
||||
|
||||
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;
|
||||
|
||||
// Ethernet Frame Preemption for TSN
|
||||
if(packet->header.PREEMPTION_ENABLED) {
|
||||
message.preemptionFlags = static_cast<uint8_t>((rawWords[0] & 0x03F8) >> 4);
|
||||
}
|
||||
|
||||
// Check if this is a T1S packet and populate T1S-specific fields
|
||||
if(packet->header.T1S_ETHERNET) {
|
||||
auto& t1s = message.t1s.emplace();
|
||||
|
||||
t1s.isSymbol = packet->eid.T1S_SYMBOL;
|
||||
t1s.isBurst = packet->eid.T1S_BURST;
|
||||
t1s.txCollision = packet->t1s_status.TXCollision;
|
||||
t1s.isWake = packet->t1s_status.T1SWake;
|
||||
t1s.nodeId = packet->t1s_node.T1S_NODE_ID;
|
||||
t1s.burstCount = packet->t1s_node.T1S_BURST_COUNT;
|
||||
}
|
||||
|
||||
const std::vector<uint8_t>::const_iterator databegin = bytestream.begin() + sizeof(HardwareEthernetPacket);
|
||||
const std::vector<uint8_t>::const_iterator dataend = databegin + packet->Length - fcsSize;
|
||||
message.data.insert(message.data.begin(), databegin, dataend);
|
||||
|
||||
|
||||
if(fcsSize) {
|
||||
uint32_t& fcs = message.fcs.emplace();
|
||||
std::copy(dataend, dataend + fcsSize, (uint8_t*)&fcs);
|
||||
@@ -68,86 +59,41 @@ 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();
|
||||
if(unpaddedSize == 0)
|
||||
return false;
|
||||
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
|
||||
|
||||
// Description ID Most Significant bit is used to identify preemption frames
|
||||
uint16_t description = message.description;
|
||||
if(description & 0x8000)
|
||||
return false;
|
||||
|
||||
const bool preempt = message.preemptionFlags.has_value();
|
||||
// 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)
|
||||
if(message.preemptionEnabled) {
|
||||
sizeWithHeader++; // Make space for the preemption flags
|
||||
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.preemptionFlags.has_value()) {
|
||||
flags |= FLAG_PREEMPTION;
|
||||
}
|
||||
|
||||
bytestream.reserve(sizeWithHeader + 8); // Also reserve space for the bytes we'll use later on
|
||||
bytestream.resize(sizeWithHeader);
|
||||
size_t index = 0;
|
||||
|
||||
bytestream.push_back(flags);
|
||||
// Padded size, little endian
|
||||
bytestream[index++] = uint8_t(paddedSize);
|
||||
bytestream[index++] = uint8_t(paddedSize >> 8);
|
||||
|
||||
if(preempt) {
|
||||
bytestream.push_back(message.preemptionFlags.value());
|
||||
}
|
||||
// Description ID, big endian
|
||||
bytestream[index++] = uint8_t(description >> 8);
|
||||
bytestream[index++] = uint8_t(description);
|
||||
|
||||
bytestream.insert(bytestream.end(), message.data.begin(), message.data.end());
|
||||
// The header is one byte larger if preemption is enabled, shifting the data
|
||||
if(message.preemptionEnabled)
|
||||
bytestream[index++] = message.preemptionFlags;
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
// We only copy in the unpadded size, the rest will be 0
|
||||
memcpy(bytestream.data() + index, message.data.data(), unpaddedSize);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -34,12 +34,11 @@ std::shared_ptr<EthPhyMessage> HardwareEthernetPhyRegisterPacket::DecodeToMessag
|
||||
phyMessage->Enabled = (pEntry->Enabled != 0u);
|
||||
phyMessage->WriteEnable = (pEntry->WriteEnable != 0u);
|
||||
phyMessage->Clause45Enable = (pEntry->Clause45Enable != 0u);
|
||||
phyMessage->BusIndex = static_cast<uint8_t>(pEntry->BusIndex);
|
||||
phyMessage->Version = static_cast<uint8_t>(pEntry->version);
|
||||
phyMessage->version = static_cast<uint8_t>(pEntry->version);
|
||||
if(phyMessage->Clause45Enable)
|
||||
phyMessage->Clause45 = pEntry->clause45;
|
||||
phyMessage->clause45 = pEntry->clause45;
|
||||
else
|
||||
phyMessage->Clause22 = pEntry->clause22;
|
||||
phyMessage->clause22 = pEntry->clause22;
|
||||
msg->messages.push_back(phyMessage);
|
||||
}
|
||||
}
|
||||
@@ -70,35 +69,34 @@ bool HardwareEthernetPhyRegisterPacket::EncodeFromMessage(const EthPhyMessage& m
|
||||
PhyRegisterPacket_t tempPacket;
|
||||
tempPacket.Enabled = phyMessage->Enabled ? 0x1u : 0x0u;
|
||||
tempPacket.WriteEnable = phyMessage->WriteEnable ? 0x1u : 0x0u;
|
||||
tempPacket.BusIndex = (phyMessage->BusIndex & 0xF);
|
||||
tempPacket.version = (phyMessage->Version & 0xF);
|
||||
tempPacket.version = (phyMessage->version & 0xF);
|
||||
if(phyMessage->Clause45Enable)
|
||||
{
|
||||
if( (FiveBits < phyMessage->Clause45.port) ||
|
||||
(FiveBits < phyMessage->Clause45.device) )
|
||||
if( (FiveBits < phyMessage->clause45.port) ||
|
||||
(FiveBits < phyMessage->clause45.device) )
|
||||
{
|
||||
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
tempPacket.Clause45Enable = 0x1u;
|
||||
tempPacket.clause45.port = phyMessage->Clause45.port;
|
||||
tempPacket.clause45.device = phyMessage->Clause45.device;
|
||||
tempPacket.clause45.regAddr = phyMessage->Clause45.regAddr;
|
||||
tempPacket.clause45.regVal = phyMessage->Clause45.regVal;
|
||||
tempPacket.clause45.port = phyMessage->clause45.port;
|
||||
tempPacket.clause45.device = phyMessage->clause45.device;
|
||||
tempPacket.clause45.regAddr = phyMessage->clause45.regAddr;
|
||||
tempPacket.clause45.regVal = phyMessage->clause45.regVal;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( (FiveBits < phyMessage->Clause22.phyAddr) ||
|
||||
(FiveBits < phyMessage->Clause22.regAddr) )
|
||||
if( (FiveBits < phyMessage->clause22.phyAddr) ||
|
||||
(FiveBits < phyMessage->clause22.regAddr) )
|
||||
{
|
||||
report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
tempPacket.Clause45Enable = 0x0u;
|
||||
tempPacket.clause22.phyAddr = phyMessage->Clause22.phyAddr;
|
||||
tempPacket.clause22.page = phyMessage->Clause22.page;
|
||||
tempPacket.clause22.regAddr = phyMessage->Clause22.regAddr;
|
||||
tempPacket.clause22.regVal = phyMessage->Clause22.regVal;
|
||||
tempPacket.clause22.phyAddr = phyMessage->clause22.phyAddr;
|
||||
tempPacket.clause22.page = phyMessage->clause22.page;
|
||||
tempPacket.clause22.regAddr = phyMessage->clause22.regAddr;
|
||||
tempPacket.clause22.regVal = phyMessage->clause22.regVal;
|
||||
}
|
||||
uint8_t* pktPtr = reinterpret_cast<uint8_t*>(&tempPacket);
|
||||
bytestream.insert(bytestream.end(), pktPtr, pktPtr + sizeof(PhyRegisterPacket_t));
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace icsneo
|
||||
report(APIEvent::Type::I2CMessageExceedsMaxLength, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
if(message.controlBytes.empty() && message.dataBytes.empty())
|
||||
if(message.controlBytes.empty() || message.dataBytes.empty())
|
||||
{
|
||||
//You'll need to provide a target R/W register in controlBytes
|
||||
//alternatively, you're expecting to read without providing a dataBytes payload
|
||||
|
||||
@@ -9,7 +9,7 @@ std::shared_ptr<Message> HardwareLINPacket::DecodeToMessage(const std::vector<ui
|
||||
size_t numDataBytes = packet->CoreMiniBitsLIN.len;
|
||||
size_t numHeaderBytes = sizeof(HardwareLINPacket::CoreMiniBitsLIN);
|
||||
|
||||
if( (sizeof(HardwareLINPacket) > bytestream.size()) ||
|
||||
if( (sizeof(HardwareLINPacket) != bytestream.size()) ||
|
||||
((numDataBytes + numHeaderBytes) > bytestream.size()) )
|
||||
return nullptr;
|
||||
|
||||
@@ -17,6 +17,7 @@ std::shared_ptr<Message> HardwareLINPacket::DecodeToMessage(const std::vector<ui
|
||||
--numDataBytes; //If data is present, there will be a checksum included
|
||||
|
||||
auto msg = std::make_shared<LINMessage>(static_cast<uint8_t>(packet->CoreMiniBitsLIN.ID));
|
||||
msg->network = Network::GetNetIDFromCoreMiniNetwork(static_cast<Network::CoreMini>(packet->networkID));
|
||||
msg->isEnhancedChecksum = static_cast<bool>(packet->CoreMiniBitsLIN.TxChkSumEnhanced);
|
||||
|
||||
/* Minimum one responder byte and one checksum byte. */
|
||||
@@ -30,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 false;
|
||||
return true;
|
||||
|
||||
uint8_t checkSum = (8 > numDataBytes) ? *(dataStart + numDataBytes) : packet->CoreMiniBitsLIN.LINByte9;
|
||||
LINMessage::calcChecksum(*msg);
|
||||
|
||||
@@ -99,33 +99,6 @@ 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;
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
#include "icsneo/communication/packet/spipacket.h"
|
||||
#include "icsneo/communication/command.h"
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
static size_t SPISubHeaderLength = 5u;
|
||||
|
||||
std::shared_ptr<Message> HardwareSPIPacket::DecodeToMessage(const std::vector<uint8_t>& bytestream) {
|
||||
if(bytestream.size() < sizeof(HardwareSPIPacket)) {
|
||||
return nullptr;
|
||||
}
|
||||
const HardwareSPIPacket* packet = (const HardwareSPIPacket*)bytestream.data();
|
||||
size_t totalPackedLength = static_cast<size_t>(bytestream.size()) - sizeof(HardwareSPIPacket); // First 28 bytes are message header.
|
||||
if(totalPackedLength < SPISubHeaderLength) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const uint8_t* bytes = bytestream.data() + sizeof(HardwareSPIPacket);
|
||||
std::shared_ptr<SPIMessage> msg = std::make_shared<SPIMessage>();
|
||||
msg->direction = static_cast<SPIMessage::Direction>(bytes[0]);
|
||||
msg->address = *reinterpret_cast<const uint16_t*>(&bytes[1]);
|
||||
msg->mms = bytes[3];
|
||||
msg->stats = packet->stats;
|
||||
msg->timestamp = packet->timestamp.TS;
|
||||
|
||||
size_t numWords = (totalPackedLength - SPISubHeaderLength) / 4;
|
||||
msg->payload.reserve(numWords);
|
||||
for(size_t offset = SPISubHeaderLength; offset < totalPackedLength; offset += 4) {
|
||||
msg->payload.push_back(*reinterpret_cast<const uint32_t*>(bytes + offset));
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
bool HardwareSPIPacket::EncodeFromMessage(const SPIMessage& message, std::vector<uint8_t>& bytestream, const device_eventhandler_t& /*report*/) {
|
||||
// Payload length is everything excluding cmdHeader (note at the beginning there is an offset of 2)
|
||||
uint16_t payloadLength = static_cast<uint16_t>(
|
||||
2 +
|
||||
sizeof(HardwareSPIPacket) +
|
||||
SPISubHeaderLength +
|
||||
message.payload.size() * sizeof(uint32_t)
|
||||
);
|
||||
if(payloadLength % 2) {
|
||||
// Pad payload to even number
|
||||
payloadLength++;
|
||||
}
|
||||
// +1 for AA, another +1 for firmware nuance
|
||||
uint16_t fullSize = 1 + sizeof(ExtendedCommandHeader) + payloadLength + 1;
|
||||
uint16_t unwrappedSize = sizeof(ExtendedCommandHeader) + payloadLength; // fullSize without AA and firmware nuance
|
||||
|
||||
bytestream.resize(unwrappedSize, 0);
|
||||
uint32_t offset = 0;
|
||||
auto* cmdHeader = reinterpret_cast<ExtendedCommandHeader*>(bytestream.data() + offset);
|
||||
cmdHeader->netid = static_cast<uint8_t>(Network::NetID::Main51);
|
||||
cmdHeader->fullLength = fullSize;
|
||||
cmdHeader->command = static_cast<uint8_t>(Command::Extended);
|
||||
cmdHeader->extendedCommand = static_cast<uint16_t>(ExtendedCommand::TransmitCoreminiMessage);
|
||||
cmdHeader->payloadLength = payloadLength;
|
||||
|
||||
offset += sizeof(ExtendedCommandHeader) + 2; // Offset of 2 between header and packet
|
||||
auto* packet = reinterpret_cast<HardwareSPIPacket*>(bytestream.data() + offset);
|
||||
packet->header.frameLength = static_cast<uint16_t>(SPISubHeaderLength + message.payload.size() * sizeof(uint32_t));
|
||||
packet->networkID = static_cast<uint16_t>(message.network.getNetID());
|
||||
packet->length = packet->header.frameLength;
|
||||
packet->timestamp.IsExtended = 1;
|
||||
|
||||
offset += sizeof(HardwareSPIPacket);
|
||||
// Write the sub header details
|
||||
bytestream[offset++] = static_cast<uint8_t>(message.direction);
|
||||
bytestream[offset++] = static_cast<uint8_t>(message.address & 0xFF);
|
||||
bytestream[offset++] = static_cast<uint8_t>((message.address >> 8) & 0xFF);
|
||||
bytestream[offset++] = static_cast<uint8_t>(message.mms);
|
||||
bytestream[offset++] = static_cast<uint8_t>(message.payload.size());
|
||||
|
||||
// Write the words
|
||||
for(uint32_t word : message.payload) {
|
||||
*reinterpret_cast<uint32_t*>(bytestream.data() + offset) = word;
|
||||
offset += sizeof(uint32_t);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -31,46 +31,24 @@ std::shared_ptr<WiVI::ResponseMessage> WiVI::CommandPacket::DecodeToMessage(cons
|
||||
break;
|
||||
}
|
||||
case WiVI::Command::GetAll: {
|
||||
if(bytestream.size() < sizeof(WiVI::CommandPacket::GetAllHeader))
|
||||
if(bytestream.size() < sizeof(WiVI::CommandPacket::GetAll))
|
||||
return {};
|
||||
|
||||
const auto& getAll = *reinterpret_cast<const WiVI::CommandPacket::GetAllHeader*>(bytestream.data());
|
||||
const auto& getAll = *reinterpret_cast<const WiVI::CommandPacket::GetAll*>(bytestream.data());
|
||||
msg->responseTo = WiVI::Command::GetAll;
|
||||
msg->info.emplace();
|
||||
msg->info->sleepRequest = getAll.sleepRequest;
|
||||
msg->info->connectionTimeoutMinutes = getAll.connectionTimeoutMinutes;
|
||||
|
||||
// Check that we have enough data for the capture infos
|
||||
size_t captureInfosSize = sizeof(WiVI::CaptureInfo) * getAll.numCaptureInfos;
|
||||
if(bytestream.size() < sizeof(WiVI::CommandPacket::GetAllHeader) + captureInfosSize)
|
||||
if(bytestream.size() < sizeof(WiVI::CommandPacket::GetAll) + (sizeof(WiVI::CaptureInfo) * getAll.numCaptureInfos))
|
||||
return {};
|
||||
|
||||
const WiVI::CaptureInfo* const captureInfos = (const WiVI::CaptureInfo*)(bytestream.data() + sizeof(WiVI::CommandPacket::GetAllHeader));
|
||||
msg->info->captures.resize(getAll.numCaptureInfos);
|
||||
for(uint16_t i = 0; i < getAll.numCaptureInfos; i++)
|
||||
msg->info->captures[i] = captureInfos[i];
|
||||
|
||||
|
||||
// New field vinAvail was added - check if it is present:
|
||||
if(bytestream.size() >= sizeof(WiVI::CommandPacket::GetAllHeader) + captureInfosSize + 2) {
|
||||
msg->info->vinAvailable = *(bytestream.data() + sizeof(WiVI::CommandPacket::GetAllHeader) + captureInfosSize);
|
||||
} else {
|
||||
msg->info->vinAvailable = 0;
|
||||
}
|
||||
|
||||
msg->info->captures[i] = getAll.captureInfos[i];
|
||||
break;
|
||||
}
|
||||
case WiVI::Command::GetVIN: {
|
||||
if (bytestream.size() < sizeof(WiVI::CommandPacket::GetVIN))
|
||||
return {};
|
||||
|
||||
const auto& getVIN = *reinterpret_cast<const WiVI::CommandPacket::GetVIN*>(bytestream.data());
|
||||
msg->responseTo = WiVI::Command::GetVIN;
|
||||
msg->vin = getVIN.VIN;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default: // Unknown command response
|
||||
return {};
|
||||
}
|
||||
@@ -100,9 +78,9 @@ std::vector<uint8_t> WiVI::CommandPacket::SetSignal::Encode(WiVI::SignalType typ
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> WiVI::CommandPacket::GetAllHeader::Encode() {
|
||||
std::vector<uint8_t> ret(sizeof(WiVI::CommandPacket::GetAllHeader));
|
||||
auto& frame = *reinterpret_cast<WiVI::CommandPacket::GetAllHeader*>(ret.data());
|
||||
std::vector<uint8_t> WiVI::CommandPacket::GetAll::Encode() {
|
||||
std::vector<uint8_t> ret(sizeof(WiVI::CommandPacket::GetAll));
|
||||
auto& frame = *reinterpret_cast<WiVI::CommandPacket::GetAll*>(ret.data());
|
||||
|
||||
frame.header.cmd = WiVI::Command::GetAll;
|
||||
frame.header.length = sizeof(frame) - sizeof(frame.header);
|
||||
@@ -120,15 +98,3 @@ std::vector<uint8_t> WiVI::CommandPacket::ClearUploads::Encode(const std::vector
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> WiVI::CommandPacket::GetVIN::Encode()
|
||||
{
|
||||
std::vector<uint8_t> ret(sizeof(WiVI::CommandPacket::GetVIN));
|
||||
auto& frame = *reinterpret_cast<WiVI::CommandPacket::GetVIN*>(ret.data());
|
||||
|
||||
frame.header.cmd = WiVI::Command::GetVIN;
|
||||
frame.header.length = sizeof(frame) - sizeof(frame.header);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ bool Packetizer::input(RingBuffer& bytes) {
|
||||
* end of the payload. The short packet length, for reference, only encompasses the length of the actual
|
||||
* payload, and not the header or checksum.
|
||||
*/
|
||||
if(packetLength < 6 || packetLength > std::numeric_limits<uint16_t>::max()) {
|
||||
if(packetLength < 6 || packetLength > 4000) {
|
||||
bytes.pop_front();
|
||||
EventManager::GetInstance().add(APIEvent::Type::FailedToRead, APIEvent::Severity::Error);
|
||||
state = ReadState::SearchForHeader;
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
#include "icsneo/communication/ringbuffer.h"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
RingBuffer::RingBuffer(size_t bufferSize) : readCursor(0), writeCursor(0) {
|
||||
// round the buffer size to the nearest power of 2
|
||||
bufferSize = RoundUp(bufferSize);
|
||||
mask = bufferSize - 1;
|
||||
buf = new uint8_t[bufferSize];
|
||||
}
|
||||
|
||||
RingBuffer::~RingBuffer() {
|
||||
delete[] buf;
|
||||
buf = nullptr;
|
||||
}
|
||||
|
||||
const uint8_t& RingBuffer::operator[](size_t offset) const {
|
||||
return get(offset);
|
||||
}
|
||||
|
||||
size_t RingBuffer::size() const {
|
||||
// The values in the cursors are monotonic, i.e. they only ever increment. They can be considered to be the total number of elements ever written or read
|
||||
auto currentWriteCursor = writeCursor.load(std::memory_order_relaxed);
|
||||
auto currentReadCursor = readCursor.load(std::memory_order_relaxed);
|
||||
// Using unmasked values, writeCursor is guaranteed to be >= readCursor. If they are equal that means the buffer is empty
|
||||
return currentWriteCursor - currentReadCursor;
|
||||
}
|
||||
|
||||
void RingBuffer::pop_front() {
|
||||
pop(1);
|
||||
}
|
||||
|
||||
void RingBuffer::pop(size_t count) {
|
||||
if (size() < count) {
|
||||
throw std::runtime_error("RingBuffer: Underflow");
|
||||
}
|
||||
readCursor.fetch_add(count, std::memory_order_release);
|
||||
}
|
||||
|
||||
const uint8_t& RingBuffer::get(size_t offset) const {
|
||||
if (offset >= size()) {
|
||||
throw std::runtime_error("RingBuffer: Index out of range");
|
||||
}
|
||||
auto currentReadCursor = readCursor.load(std::memory_order_acquire);
|
||||
return *resolve(currentReadCursor, offset);
|
||||
}
|
||||
|
||||
bool RingBuffer::write(const uint8_t* addr, size_t length) {
|
||||
const auto freeSpace = (capacity() - size());
|
||||
if (length > freeSpace) {
|
||||
return false;
|
||||
}
|
||||
auto currentWriteCursor = writeCursor.load(std::memory_order_relaxed);
|
||||
auto spaceAtEnd = std::min(freeSpace, capacity() - (currentWriteCursor & mask)); // number of bytes from (masked) writeCursor to the end of the writable space (i.e. we reach the masked read cursor or the end of the buffer)
|
||||
auto firstCopySize = std::min(spaceAtEnd, length);
|
||||
(void)memcpy(resolve(currentWriteCursor, 0), addr, firstCopySize);
|
||||
if (firstCopySize < length)
|
||||
{
|
||||
(void)memcpy(buf, &addr[firstCopySize], length - firstCopySize);
|
||||
}
|
||||
|
||||
writeCursor.store(currentWriteCursor + length, std::memory_order_release);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RingBuffer::write(const std::vector<uint8_t>& source) {
|
||||
return write(source.data(), source.size());
|
||||
}
|
||||
|
||||
bool RingBuffer::read(uint8_t* dest, size_t startIndex, size_t length) const {
|
||||
auto currentSize = size();
|
||||
if ((startIndex >= currentSize) || ((startIndex + length) > size())) {
|
||||
return false;
|
||||
}
|
||||
auto currentReadCursor = readCursor.load(std::memory_order_relaxed);
|
||||
auto bytesAtEnd = std::min<size_t>(capacity() - ((currentReadCursor + startIndex) & mask), length);
|
||||
const auto bytesAtStart = (length - bytesAtEnd);
|
||||
|
||||
(void)memcpy(dest, resolve(currentReadCursor, startIndex), bytesAtEnd);
|
||||
if (bytesAtStart > 0) {
|
||||
(void)memcpy(&dest[bytesAtEnd], buf, bytesAtStart);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RingBuffer::clear() {
|
||||
pop(size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* crc32.c
|
||||
*
|
||||
* Created on: Jun 22, 2020
|
||||
* Author: BJones
|
||||
*/
|
||||
#include "icsneo/core/crc32.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 icsneo::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)
|
||||
{
|
||||
uint16_t k;
|
||||
|
||||
for (k = 0; k < 256; k++)
|
||||
rev_crc32_table[crc32_table[k] >> 24] = (unsigned char)k;
|
||||
}
|
||||
|
||||
uint32_t icsneo::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;
|
||||
}
|
||||
@@ -1,832 +0,0 @@
|
||||
#include "icsneo/core/macseccfg.h"
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
#include "icsneo/core/crc32.h"
|
||||
#include <cstring>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4201) // nameless struct/union
|
||||
#endif
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t VID; /*!< 12 bits */
|
||||
uint8_t PRI_CFI; /*!< PRI - 3 bits, CFI - 1bit */
|
||||
} MACSEC_VLANTAG_t;
|
||||
/**
|
||||
* @brief Structure of MPLS
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MPLS_label; /*!< 20 bits */
|
||||
uint8_t exp; /*!< 3 bits */
|
||||
} MACSEC_MPLS_OUTER_t;
|
||||
|
||||
#define MACSEC_SETTINGS_RULE_SIZE (88)
|
||||
typedef union _MACSecRule
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t index;
|
||||
uint8_t key_MAC_DA[6]; /*!< MAC DA field extracted from the packet */
|
||||
uint8_t mask_MAC_DA[6]; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint8_t key_MAC_SA[6]; /*!< MAC SA field extracted from the packet */
|
||||
uint8_t mask_MAC_SA[6]; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint16_t key_Ethertype; /*!< First E-Type found in the packet that doesn't match one of the preconfigured custom tag. */
|
||||
uint16_t mask_Ethertype; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
MACSEC_VLANTAG_t key_vlantag_outer1; /*!< outermost/1st VLAN ID {8'd0, VLAN_ID[11:0]}, or 20-bit MPLS label. */
|
||||
MACSEC_MPLS_OUTER_t key_MPLS_outer1;
|
||||
MACSEC_VLANTAG_t mask_vlantag_outer1; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
MACSEC_MPLS_OUTER_t mask_MPLS_outer1;
|
||||
MACSEC_VLANTAG_t key_vlantag_outer2; /*!< 2nd outermost VLAN ID {8'd0, VLAN_ID[11:0]}, or 20-bit MPLS label. */
|
||||
MACSEC_MPLS_OUTER_t key_MPLS_outer2;
|
||||
MACSEC_VLANTAG_t mask_vlantag_outer2; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
MACSEC_MPLS_OUTER_t mask_MPLS_outer2;
|
||||
uint16_t key_bonus_data; /*!< 2 bytes of additional bonus data extracted from one of the custom tags. */
|
||||
uint16_t mask_bonus_data; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint8_t
|
||||
key_tag_match_bitmap; /*!< 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 mask_tag_match_bitmap; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
MACsecPacketType key_packet_type; /*!< Encoded Packet Type, see MACSEC_PACKET_TYPE */
|
||||
uint8_t mask_packet_type; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint16_t
|
||||
key_inner_vlan_type; /*!< 3 bits total. Encoded value indicating which VLAN TPID value matched for the second outermost VLAN Tag. */
|
||||
uint16_t mask_inner_vlan_type; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint16_t key_outer_vlan_type; /*!< 3 bits total. Encoded value indicating which VLAN TPID value matched for the outermost VLAN Tag. */
|
||||
uint16_t mask_outer_vlan_type; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint8_t
|
||||
key_num_tags; /*!< 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 mask_num_tags; /*!< Set bits to 1 to mask/exclude corresponding flowid_tcam_data bit from compare */
|
||||
uint8_t key_express; /*!< 1 bits. Express packet. */
|
||||
uint8_t mask_express; /*!< 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 */
|
||||
#define MACSEC_SETTINGS_MAP_SIZE (20)
|
||||
typedef union _MACSecMap
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t index;
|
||||
uint64_t sectag_sci; /*!< 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 auxiliary_plcy; /*!< 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 */
|
||||
|
||||
#define MACSEC_SETTINGS_SECY_SIZE (24)
|
||||
typedef union _MACSecSecY
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t index; /*!< Identifies the SecY for this Flow. */
|
||||
uint8_t controlled_port_enabled; /*!< Enable (or disable) operation of the Controlled port associated with this SecY */
|
||||
MACsecValidation validate_frames; /*!< see MACSEC_VALIDATEFRAME */
|
||||
MACsecStrip strip_sectag_icv; /*!< see MACSEC_STRIP_SECTAG_ICV */
|
||||
MACsecCipherSuite cipher; /*!< Define the cipher suite to use for this SecY */
|
||||
uint8_t confidential_offset; /*!< Define the number of bytes that are unencrypted following the SecTag. */
|
||||
uint8_t icv_includes_da_sa; /*!< When set, the outer DA/SA bytes are included in the authentication GHASH calculation */
|
||||
uint8_t replay_protect; /*!< Enables Anti-Replay protection */
|
||||
uint32_t replay_window; /*!< Unsigned value indicating the size of the anti-replay window. */
|
||||
uint8_t
|
||||
protect_frames; /*!< 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
|
||||
sectag_offset; /*!< Define the offset in bytes from either the start of the packet or a matching Etype depending on SecTag_Insertion_Mode. */
|
||||
uint8_t sectag_tci; /*!< 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 */
|
||||
#define 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 sa_index0; /*!< Define the 1st SA to use */
|
||||
uint8_t sa_index1; /*!< Define the 2nd SA to use */
|
||||
uint8_t sa_index0_in_use; /*!< Specifies whether 1st SA is in use or not. */
|
||||
uint8_t sa_index1_in_use; /*!< Specifies whether 2nd SA is in use or not. */
|
||||
uint8_t enable_auto_rekey; /*!< 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 */
|
||||
#define MACSEC_SETTINGS_SA_SIZE (80)
|
||||
typedef union _MACSecSa
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t index; /*!< SA index */
|
||||
uint8_t
|
||||
sak[32]; /*!< SAK: All 32 bytes are written to the firmware. For AES-128 the firmware requires bytes [0..15] == bytes [16..31] (mirrored); serialize() handles this automatically. */
|
||||
uint8_t hashKey[16]; /*!< 128b Hash Key: Key used for authentication. */
|
||||
uint8_t salt[12]; /*!< 96b Salt value: Salt value used in XPN ciphers. */
|
||||
uint32_t ssci; /*!< 32b SSCI value: Short Secure Channel Identifier, used in XPN ciphers. */
|
||||
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 */
|
||||
#define MACSEC_SETTINGS_FLAGS_SIZE (4)
|
||||
typedef union _MACSecFlags
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t en : 1; // '1' = enable; '0' = disable
|
||||
uint32_t reserved : 31;
|
||||
};
|
||||
uint32_t flags_32b;
|
||||
} MACSecFlags_t;
|
||||
/* MACSec Settings for 1 port/phy */
|
||||
#define MACSEC_NUM_FLAGS_PER_CONFIG (1)
|
||||
#define MACSEC_NUM_RULES_PER_CONFIG (2)
|
||||
#define MACSEC_NUM_MAPS_PER_CONFIG (2)
|
||||
#define MACSEC_NUM_SECY_PER_CONFIG (2)
|
||||
#define MACSEC_NUM_SC_PER_CONFIG (2)
|
||||
#define MACSEC_NUM_SA_PER_CONFIG (4)
|
||||
typedef struct MACSEC_CONFIG_t
|
||||
{
|
||||
MACSecFlags_t flags;
|
||||
MACSecRule_t rule[MACSEC_NUM_RULES_PER_CONFIG];
|
||||
MACSecMap_t map[MACSEC_NUM_MAPS_PER_CONFIG];
|
||||
MACSecSecY_t secy[MACSEC_NUM_SECY_PER_CONFIG];
|
||||
MACSecSc_t sc[MACSEC_NUM_SC_PER_CONFIG];
|
||||
MACSecSa_t sa[MACSEC_NUM_SA_PER_CONFIG];
|
||||
} 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
|
||||
typedef struct MACSEC_SETTINGS_W_HDR
|
||||
{
|
||||
uint16_t version;
|
||||
uint16_t len;
|
||||
uint32_t crc32;
|
||||
MACSEC_SETTINGS macsec;
|
||||
} MACSEC_SETTINGS_W_HDR;
|
||||
#define MACSEC_SETTINGS_W_HDR_SIZE (2048)
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
static void ReportEvent(APIEvent::Type event, APIEvent::Severity severity) {
|
||||
auto& em = EventManager::GetInstance();
|
||||
em.add(APIEvent(event, severity));
|
||||
}
|
||||
|
||||
MACsecConfig::MACsecConfig(const DeviceType& deviceType) : type(deviceType) {
|
||||
switch(deviceType.getDeviceType()) {
|
||||
case icsneo::DeviceType::Enum::RADMoon2:
|
||||
case icsneo::DeviceType::Enum::RADMoon3:
|
||||
case icsneo::DeviceType::Enum::RADEpsilon:
|
||||
case icsneo::DeviceType::Enum::RADGigastar2:
|
||||
maxSecY = 2;
|
||||
maxRule = 2;
|
||||
maxSa = 4;
|
||||
binIndex = 0;
|
||||
break;
|
||||
default:
|
||||
maxSecY = 0;
|
||||
maxSa = 0;
|
||||
maxRule = 0;
|
||||
binIndex = 0;
|
||||
ReportEvent(APIEvent::Type::MACsecNotSupported, APIEvent::Severity::Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int MACsecConfig::addRxSecY(const MACsecRxSecY& secY, uint8_t saIndex) {
|
||||
if(rxSecY.size() >= maxSecY) {
|
||||
ReportEvent(APIEvent::Type::MACsecSecYLimit, APIEvent::Severity::Error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(saIndex >= rxSa.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSaIndex, APIEvent::Severity::Error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = static_cast<int>(rxSecY.size());
|
||||
rxSecY.emplace_back(secY);
|
||||
rxSecYSaIndices.emplace_back(saIndex, saIndex + 1);
|
||||
rxSecYRekey.emplace_back(false);
|
||||
rxRuleIndices.emplace_back(0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int MACsecConfig::addTxSecY(const MACsecTxSecY& secY, uint8_t saIndex) {
|
||||
if(txSecY.size() >= maxSecY) {
|
||||
ReportEvent(APIEvent::Type::MACsecSecYLimit, APIEvent::Severity::Error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(saIndex >= txSa.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSaIndex, APIEvent::Severity::Error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = static_cast<int>(txSecY.size());
|
||||
txSecY.emplace_back(secY);
|
||||
txSecYSaIndices.emplace_back(saIndex, saIndex + 1);
|
||||
txSecYRekey.emplace_back(false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int MACsecConfig::addRxSa(const MACsecRxSa& sa) {
|
||||
// Validate AN is in valid range
|
||||
if(sa.an > 3) {
|
||||
ReportEvent(APIEvent::Type::MACsecSaLimit, APIEvent::Severity::Error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if we've exceeded the maximum SA count
|
||||
if(rxSa.size() >= maxSa) {
|
||||
ReportEvent(APIEvent::Type::MACsecSaLimit, APIEvent::Severity::Error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Ensure vector is large enough to hold index sa.an (sparse array)
|
||||
// This allows SA index to match the AN value from the MACsec SecTAG
|
||||
if(rxSa.size() <= sa.an) {
|
||||
rxSa.resize(sa.an + 1);
|
||||
}
|
||||
|
||||
// Mark it enabled; padding slots created by resize() above default to enabled=false.
|
||||
rxSa[sa.an] = sa;
|
||||
rxSa[sa.an].enabled = true;
|
||||
|
||||
return sa.an;
|
||||
}
|
||||
|
||||
int MACsecConfig::addTxSa(const MACsecTxSa& sa) {
|
||||
if(txSa.size() >= maxSa) {
|
||||
ReportEvent(APIEvent::Type::MACsecSaLimit, APIEvent::Severity::Error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = static_cast<int>(txSa.size());
|
||||
txSa.emplace_back(sa);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int MACsecConfig::addRxRule(const MACsecRxRule& rule, uint8_t secYIndex) {
|
||||
if(rxRule.size() >= maxRule) {
|
||||
ReportEvent(APIEvent::Type::MACsecSaLimit, APIEvent::Severity::Error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(maxSecY >= rxRule.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecSecYLimit, APIEvent::Severity::Error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = static_cast<int>(rxRule.size());
|
||||
rxRuleIndices[secYIndex] = static_cast<uint8_t>(rxRule.size());
|
||||
rxRule.emplace_back(rule);
|
||||
return ret;
|
||||
}
|
||||
|
||||
MACsecRxRule& MACsecConfig::getRxRule(uint8_t ruleIndex) {
|
||||
return rxRule[ruleIndex];
|
||||
}
|
||||
|
||||
const MACsecRxRule& MACsecConfig::getRxRule(uint8_t ruleIndex) const {
|
||||
return rxRule[ruleIndex];
|
||||
}
|
||||
|
||||
MACsecRxSecY& MACsecConfig::getRxSecY(uint8_t secYIndex) {
|
||||
return rxSecY[secYIndex];
|
||||
}
|
||||
|
||||
const MACsecRxSecY& MACsecConfig::getRxSecY(uint8_t secYIndex) const {
|
||||
return rxSecY[secYIndex];
|
||||
}
|
||||
|
||||
MACsecTxSecY& MACsecConfig::getTxSecY(uint8_t secYIndex) {
|
||||
return txSecY[secYIndex];
|
||||
}
|
||||
|
||||
const MACsecTxSecY& MACsecConfig::getTxSecY(uint8_t secYIndex) const {
|
||||
return txSecY[secYIndex];
|
||||
}
|
||||
|
||||
MACsecRxSa& MACsecConfig::getRxSa(uint8_t saIndex) {
|
||||
return rxSa[saIndex];
|
||||
}
|
||||
|
||||
const MACsecRxSa& MACsecConfig::getRxSa(uint8_t saIndex) const {
|
||||
return rxSa[saIndex];
|
||||
}
|
||||
|
||||
MACsecTxSa& MACsecConfig::getTxSa(uint8_t saIndex) {
|
||||
return txSa[saIndex];
|
||||
}
|
||||
|
||||
const MACsecTxSa& MACsecConfig::getTxSa(uint8_t saIndex) const {
|
||||
return txSa[saIndex];
|
||||
}
|
||||
|
||||
bool MACsecConfig::setTxSaIndex(uint8_t secYIndex, uint8_t saIndex) {
|
||||
if(secYIndex >= txSecY.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSecYIndex, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
if(saIndex >= txSa.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSaIndex, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
txSecYSaIndices[secYIndex].first = saIndex;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MACsecConfig::enableTxRekey(uint8_t secYIndex, uint8_t rekeySaIndex) {
|
||||
if(secYIndex >= txSecY.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSecYIndex, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
if(rekeySaIndex >= txSa.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSaIndex, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
txSecYSaIndices[secYIndex].second = rekeySaIndex;
|
||||
txSecYRekey[secYIndex] = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MACsecConfig::setTxSaRekeyIndex(uint8_t secYIndex, uint8_t saIndex) {
|
||||
if(secYIndex >= txSecY.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSecYIndex, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
if(saIndex >= txSa.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSaIndex, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
txSecYSaIndices[secYIndex].second = saIndex;
|
||||
return true;
|
||||
}
|
||||
|
||||
void MACsecConfig::disableTxRekey(uint8_t secYIndex) {
|
||||
if(secYIndex >= txSecY.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSecYIndex, APIEvent::Severity::EventWarning);
|
||||
return;
|
||||
}
|
||||
txSecYRekey[secYIndex] = false;
|
||||
}
|
||||
|
||||
bool MACsecConfig::setRxSaIndex(uint8_t secYIndex, uint8_t saIndex) {
|
||||
if(secYIndex >= rxSecY.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSecYIndex, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
if(saIndex >= rxSa.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSaIndex, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
rxSecYSaIndices[secYIndex].first = saIndex;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MACsecConfig::enableRxRekey(uint8_t secYIndex, uint8_t rekeySaIndex) {
|
||||
if(secYIndex >= rxSecY.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSecYIndex, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
if(rekeySaIndex >= rxSa.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSaIndex, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
rxSecYSaIndices[secYIndex].second = rekeySaIndex;
|
||||
rxSecYRekey[secYIndex] = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MACsecConfig::setRxSaRekeyIndex(uint8_t secYIndex, uint8_t saIndex) {
|
||||
if(secYIndex >= rxSecY.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSecYIndex, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
if(saIndex >= rxSa.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSaIndex, APIEvent::Severity::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
rxSecYSaIndices[secYIndex].second = saIndex;
|
||||
return true;
|
||||
}
|
||||
|
||||
void MACsecConfig::disableRxRekey(uint8_t secYIndex) {
|
||||
if(secYIndex >= rxSecY.size()) {
|
||||
ReportEvent(APIEvent::Type::MACsecInvalidSecYIndex, APIEvent::Severity::EventWarning);
|
||||
return;
|
||||
}
|
||||
rxSecYRekey[secYIndex] = false;
|
||||
}
|
||||
|
||||
void MACsecConfig::setRxEnable(bool newRxEnable) {
|
||||
enableRx = newRxEnable;
|
||||
}
|
||||
|
||||
void MACsecConfig::setTxEnable(bool newTxEnable) {
|
||||
enableTx = newTxEnable;
|
||||
}
|
||||
|
||||
void MACsecConfig::setStorage(bool temporary) {
|
||||
nvm = !temporary;
|
||||
}
|
||||
|
||||
|
||||
void MACsecConfig::clear() {
|
||||
// Set everything back to default, except device maximums
|
||||
rxSecY.clear();
|
||||
txSecY.clear();
|
||||
rxSa.clear();
|
||||
txSa.clear();
|
||||
rxRule.clear();
|
||||
rxSecYRekey.clear();
|
||||
txSecYRekey.clear();
|
||||
rxSecYSaIndices.clear();
|
||||
txSecYSaIndices.clear();
|
||||
rxRuleIndices.clear();
|
||||
enableRx = false;
|
||||
enableTx = false;
|
||||
nvm = false;
|
||||
}
|
||||
|
||||
MACsecConfig::operator bool() const {
|
||||
return (maxSa != 0) || (maxSecY != 0) || (maxRule != 0);
|
||||
}
|
||||
|
||||
uint16_t MACsecConfig::getBinIndex() const {
|
||||
return binIndex;
|
||||
}
|
||||
|
||||
DeviceType MACsecConfig::getType() const {
|
||||
return type;
|
||||
}
|
||||
|
||||
uint8_t MACsecConfig::getMaxNumRule() const {
|
||||
return maxRule;
|
||||
}
|
||||
|
||||
uint8_t MACsecConfig::getMaxNumSecY() const {
|
||||
return maxSecY;
|
||||
}
|
||||
|
||||
uint8_t MACsecConfig::getMaxNumSa() const {
|
||||
return maxSa;
|
||||
}
|
||||
|
||||
|
||||
static uint8_t TCItoInt(const MACsecTci& tci) {
|
||||
uint8_t res = 0;
|
||||
res |= tci.c ? 0x01u : 0;
|
||||
res |= tci.e ? 0x02u : 0;
|
||||
res |= tci.scb ? 0x04u : 0;
|
||||
res |= tci.sc ? 0x08u : 0;
|
||||
res |= tci.es ? 0x10u : 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
static void SetHardwareTxSecY(
|
||||
MACSEC_SETTINGS_W_HDR* hwSettings,
|
||||
const MACsecTxSecY& secY,
|
||||
bool rekeyEnabled,
|
||||
const std::pair<uint8_t, uint8_t>& saIndices,
|
||||
uint8_t index
|
||||
) {
|
||||
|
||||
MACSecSecY_t* hwSecY = &hwSettings->macsec.tx.secy[index];
|
||||
MACSecSc_t* hwSc = &hwSettings->macsec.tx.sc[index];
|
||||
MACSecMap_t* hwMap = &hwSettings->macsec.tx.map[index];
|
||||
|
||||
hwSecY->index = index;
|
||||
hwSecY->enable = true;
|
||||
hwSecY->controlled_port_enabled = secY.enableControlPort ? 0x1u : 0x0u;
|
||||
hwSecY->cipher = secY.cipher;
|
||||
hwSecY->confidential_offset = secY.confidentialityOffset;
|
||||
hwSecY->icv_includes_da_sa = secY.icvIncludesDaSa ? 0x1u : 0x0u;
|
||||
hwSecY->mtu = secY.mtu;
|
||||
hwSecY->sectag_tci = TCItoInt(secY.tci);
|
||||
hwSecY->sectag_offset = secY.secTagOffset;
|
||||
hwSecY->protect_frames = secY.protectFrames;
|
||||
|
||||
hwSc->index = index;
|
||||
hwSc->enable = true;
|
||||
hwSc->secYIndex = index;
|
||||
hwSc->enable_auto_rekey = rekeyEnabled ? 0x1u : 0x0u;
|
||||
hwSc->sa_index0 = saIndices.first;
|
||||
hwSc->sa_index1 = saIndices.second;
|
||||
hwSc->sa_index0_in_use = true;
|
||||
hwSc->sa_index1_in_use = rekeyEnabled ? true : false;
|
||||
hwSc->isActiveSA1 = rekeyEnabled ? true : false;
|
||||
hwSc->sci = secY.sci;
|
||||
|
||||
hwMap->index = index;
|
||||
hwMap->enable = true;
|
||||
hwMap->auxiliary_plcy = secY.auxiliaryPolicy;
|
||||
hwMap->secYIndex = index;
|
||||
hwMap->isControlPacket = secY.isControlPacket ? 0x1u : 0x0u;
|
||||
hwMap->scIndex = index;
|
||||
hwMap->sectag_sci = secY.sci;
|
||||
|
||||
}
|
||||
|
||||
static void SetHardwareRxSecY(
|
||||
MACSEC_SETTINGS_W_HDR* hwSettings,
|
||||
const MACsecRxSecY& secY,
|
||||
bool rekeyEnabled,
|
||||
uint8_t ruleIndex,
|
||||
const std::pair<uint8_t, uint8_t>& saIndices,
|
||||
uint8_t index
|
||||
) {
|
||||
|
||||
MACSecSecY_t* hwSecY = &hwSettings->macsec.rx.secy[index];
|
||||
MACSecSc_t* hwSc = &hwSettings->macsec.rx.sc[index];
|
||||
MACSecMap_t* hwMap = &hwSettings->macsec.rx.map[index];
|
||||
|
||||
hwSecY->index = index;
|
||||
hwSecY->enable = 0x1u;
|
||||
hwSecY->controlled_port_enabled = secY.enableControlPort ? 0x1u : 0x0u;
|
||||
hwSecY->cipher = secY.cipher;
|
||||
hwSecY->confidential_offset = secY.confidentialityOffset;
|
||||
hwSecY->icv_includes_da_sa = secY.icvIncludesDaSa ? 0x1u : 0x0u;
|
||||
hwSecY->replay_protect = secY.replayProtect ? 0x1u : 0x0u;
|
||||
hwSecY->replay_window = secY.replayWindow;
|
||||
hwSecY->validate_frames = secY.frameValidation;
|
||||
hwSecY->strip_sectag_icv = secY.frameStrip;
|
||||
hwSecY->sectag_offset = 12;
|
||||
|
||||
hwSc->index = index;
|
||||
hwSc->enable = 0x1u;
|
||||
hwSc->secYIndex = index;
|
||||
hwSc->enable_auto_rekey = rekeyEnabled ? 0x1u : 0x0u;
|
||||
hwSc->sci = secY.sci;
|
||||
|
||||
|
||||
if(saIndices.first & 0x1u) {
|
||||
hwSc->sa_index0 = rekeyEnabled ? saIndices.second : saIndices.first;
|
||||
hwSc->sa_index1 = saIndices.first;
|
||||
hwSc->sa_index0_in_use = rekeyEnabled ? 0x1u : 0x0u;
|
||||
hwSc->sa_index1_in_use = 0x1u;
|
||||
hwSc->isActiveSA1 = rekeyEnabled ? 0x0u : 0x1u;
|
||||
} else {
|
||||
hwSc->sa_index0 = saIndices.first;
|
||||
hwSc->sa_index1 = saIndices.second;
|
||||
hwSc->sa_index0_in_use = 0x1u;
|
||||
hwSc->sa_index1_in_use = rekeyEnabled ? 0x1u : 0x0u;
|
||||
hwSc->isActiveSA1 = rekeyEnabled ? 0x1u : 0x0u;
|
||||
}
|
||||
|
||||
hwMap->index = index;
|
||||
hwMap->enable = 0x1u;
|
||||
hwMap->secYIndex = index;
|
||||
hwMap->ruleId = ruleIndex;
|
||||
hwMap->isControlPacket = secY.isControlPacket ? 0x1u : 0x0u;
|
||||
hwMap->scIndex = index;
|
||||
hwMap->sectag_sci = secY.sci;
|
||||
|
||||
}
|
||||
|
||||
static void SetHardwareTxSa(MACSEC_SETTINGS_W_HDR* hwSettings, const MACsecTxSa& sa, uint8_t index) {
|
||||
MACSecSa_t* hwSa = &hwSettings->macsec.tx.sa[index];
|
||||
|
||||
hwSa->index = index;
|
||||
hwSa->enable = 0x1u;
|
||||
memcpy(hwSa->sak, sa.sak.data(), 32);
|
||||
memcpy(hwSa->hashKey, sa.hashKey.data(), 16);
|
||||
memcpy(hwSa->salt, sa.salt.data(), 12);
|
||||
hwSa->ssci = sa.ssci;
|
||||
hwSa->AN = sa.an;
|
||||
hwSa->nextPN = sa.nextPn;
|
||||
|
||||
}
|
||||
|
||||
static void SetHardwareRxSa(MACSEC_SETTINGS_W_HDR* hwSettings, const MACsecRxSa& sa, uint8_t index) {
|
||||
MACSecSa_t* hwSa = &hwSettings->macsec.rx.sa[index];
|
||||
|
||||
hwSa->index = index;
|
||||
hwSa->enable = sa.enabled ? 0x1u : 0x0u;
|
||||
if(!sa.enabled)
|
||||
return;
|
||||
memcpy(hwSa->sak, sa.sak.data(), 32);
|
||||
memcpy(hwSa->hashKey, sa.hashKey.data(), 16);
|
||||
memcpy(hwSa->salt, sa.salt.data(), 12);
|
||||
hwSa->ssci = sa.ssci;
|
||||
hwSa->nextPN = sa.nextPn;
|
||||
|
||||
}
|
||||
|
||||
static void SetHardwareRxRule(MACSecRule_t* hwRule, const MACsecRxRule& rule, uint8_t index) {
|
||||
|
||||
hwRule->enable = 0x1u;
|
||||
hwRule->index = index;
|
||||
memcpy(hwRule->key_MAC_DA, rule.keyMacDa.data(), 6);
|
||||
memcpy(hwRule->mask_MAC_DA, rule.maskMacDa.data(), 6);
|
||||
memcpy(hwRule->key_MAC_SA, rule.keyMacSa.data(), 6);
|
||||
memcpy(hwRule->mask_MAC_SA, rule.maskMacSa.data(), 6);
|
||||
hwRule->key_Ethertype = rule.keyEthertype;
|
||||
hwRule->mask_Ethertype = rule.maskEthertype;
|
||||
hwRule->key_vlantag_outer1.PRI_CFI = rule.keyVlanTagOuter1.priCfi;
|
||||
hwRule->key_vlantag_outer1.VID = rule.keyVlanTagOuter1.vid;
|
||||
hwRule->key_MPLS_outer1.exp = rule.keyMplsOuter1.exp;
|
||||
hwRule->key_MPLS_outer1.MPLS_label = rule.keyMplsOuter1.mplsLabel;
|
||||
hwRule->mask_vlantag_outer1.PRI_CFI = rule.maskVlanTagOuter1.priCfi;
|
||||
hwRule->mask_vlantag_outer1.VID = rule.maskVlanTagOuter1.vid;
|
||||
hwRule->mask_MPLS_outer1.exp = rule.maskMplsOuter1.exp;
|
||||
hwRule->mask_MPLS_outer1.MPLS_label = rule.maskMplsOuter1.mplsLabel;
|
||||
hwRule->key_vlantag_outer2.PRI_CFI = rule.keyVlanTagOuter2.priCfi;
|
||||
hwRule->key_vlantag_outer2.VID = rule.keyVlanTagOuter2.vid;
|
||||
hwRule->key_MPLS_outer2.exp = rule.keyMplsOuter2.exp;
|
||||
hwRule->key_MPLS_outer2.MPLS_label = rule.keyMplsOuter2.mplsLabel;
|
||||
hwRule->mask_vlantag_outer2.PRI_CFI = rule.maskVlanTagOuter2.priCfi;
|
||||
hwRule->mask_vlantag_outer2.VID = rule.maskVlanTagOuter2.vid;
|
||||
hwRule->mask_MPLS_outer2.exp = rule.maskMplsOuter2.exp;
|
||||
hwRule->mask_MPLS_outer2.MPLS_label = rule.maskMplsOuter2.mplsLabel;
|
||||
hwRule->key_bonus_data = rule.keyBonusData;
|
||||
hwRule->mask_bonus_data = rule.maskBonusData;
|
||||
hwRule->key_tag_match_bitmap = rule.keyTagMatchBitmap;
|
||||
hwRule->mask_tag_match_bitmap = rule.maskTagMatchBitmap;
|
||||
hwRule->key_packet_type = rule.keyPacketType;
|
||||
hwRule->mask_packet_type = rule.maskPacketType;
|
||||
hwRule->key_inner_vlan_type = rule.keyInnerVlanType;
|
||||
hwRule->mask_inner_vlan_type = rule.maskInnerVlanType;
|
||||
hwRule->key_outer_vlan_type = rule.keyOuterVlanType;
|
||||
hwRule->mask_outer_vlan_type = rule.maskOuterVlanType;
|
||||
hwRule->key_num_tags = rule.keyNumTags;
|
||||
hwRule->mask_num_tags = rule.maskNumTags;
|
||||
hwRule->key_express = rule.keyExpress ? 0x1u : 0x0u;
|
||||
hwRule->mask_express = rule.maskExpress ? 0x1u : 0x0u;
|
||||
hwRule->isMPLS = rule.isMpls ? 0x1u : 0x0u;
|
||||
|
||||
}
|
||||
|
||||
std::vector<uint8_t> MACsecConfig::serialize() const {
|
||||
std::vector<uint8_t> res(sizeof(MACSEC_SETTINGS_W_HDR), 0);
|
||||
MACSEC_SETTINGS_W_HDR* hwSettings = (MACSEC_SETTINGS_W_HDR*)(res.data());
|
||||
|
||||
for(uint8_t i = 0; i < maxSecY; i++) {
|
||||
if(i < rxSecY.size()) {
|
||||
SetHardwareRxSecY(
|
||||
hwSettings,
|
||||
rxSecY[i],
|
||||
rxSecYRekey[i],
|
||||
rxRuleIndices[i],
|
||||
rxSecYSaIndices[i],
|
||||
i
|
||||
);
|
||||
} else {
|
||||
hwSettings->macsec.rx.secy[i].enable = false;
|
||||
hwSettings->macsec.rx.map[i].enable = false;
|
||||
hwSettings->macsec.rx.sc[i].enable = false;
|
||||
}
|
||||
|
||||
if(i < txSecY.size()) {
|
||||
SetHardwareTxSecY(
|
||||
hwSettings,
|
||||
txSecY[i],
|
||||
txSecYRekey[i],
|
||||
txSecYSaIndices[i],
|
||||
i
|
||||
);
|
||||
} else {
|
||||
hwSettings->macsec.tx.secy[i].enable = false;
|
||||
hwSettings->macsec.tx.map[i].enable = false;
|
||||
hwSettings->macsec.tx.sc[i].enable = false;
|
||||
}
|
||||
}
|
||||
|
||||
for(uint8_t i = 0; i < maxSa; i++) {
|
||||
if(i < rxSa.size()) {
|
||||
SetHardwareRxSa(hwSettings, rxSa[i], i);
|
||||
} else {
|
||||
hwSettings->macsec.rx.sa[i].enable = false;
|
||||
}
|
||||
|
||||
if(i < txSa.size()) {
|
||||
SetHardwareTxSa(hwSettings, txSa[i], i);
|
||||
} else {
|
||||
hwSettings->macsec.tx.sa[i].enable = false;
|
||||
}
|
||||
}
|
||||
|
||||
// AES-128 SAK normalization: the firmware expects the 16-byte SAK mirrored
|
||||
// into both halves of the 32-byte hardware SAK field. Callers only populate
|
||||
// bytes [0..15]; copy them into [16..31] here, transparent to all callers.
|
||||
for(uint8_t i = 0; i < static_cast<uint8_t>(rxSecY.size()); i++) {
|
||||
if(rxSecY[i].cipher == MACsecCipherSuite::GcmAes128 || rxSecY[i].cipher == MACsecCipherSuite::GcmAes128Xpn) {
|
||||
uint8_t primaryIdx = rxSecYSaIndices[i].first;
|
||||
if(primaryIdx < maxSa)
|
||||
memcpy(hwSettings->macsec.rx.sa[primaryIdx].sak + 16, hwSettings->macsec.rx.sa[primaryIdx].sak, 16);
|
||||
if(rxSecYRekey[i]) {
|
||||
uint8_t rekeyIdx = rxSecYSaIndices[i].second;
|
||||
if(rekeyIdx < maxSa)
|
||||
memcpy(hwSettings->macsec.rx.sa[rekeyIdx].sak + 16, hwSettings->macsec.rx.sa[rekeyIdx].sak, 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(uint8_t i = 0; i < static_cast<uint8_t>(txSecY.size()); i++) {
|
||||
if(txSecY[i].cipher == MACsecCipherSuite::GcmAes128 || txSecY[i].cipher == MACsecCipherSuite::GcmAes128Xpn) {
|
||||
uint8_t primaryIdx = txSecYSaIndices[i].first;
|
||||
if(primaryIdx < maxSa)
|
||||
memcpy(hwSettings->macsec.tx.sa[primaryIdx].sak + 16, hwSettings->macsec.tx.sa[primaryIdx].sak, 16);
|
||||
if(txSecYRekey[i]) {
|
||||
uint8_t rekeyIdx = txSecYSaIndices[i].second;
|
||||
if(rekeyIdx < maxSa)
|
||||
memcpy(hwSettings->macsec.tx.sa[rekeyIdx].sak + 16, hwSettings->macsec.tx.sa[rekeyIdx].sak, 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(rxRule.size() == 0) {
|
||||
MACsecRxRule defaultRule;
|
||||
MACSecRule_t* hwRxRule = &hwSettings->macsec.rx.rule[0];
|
||||
MACSecRule_t* hwTxRule = &hwSettings->macsec.tx.rule[0];
|
||||
SetHardwareRxRule(hwRxRule, defaultRule, 0);
|
||||
SetHardwareRxRule(hwTxRule, defaultRule, 0);
|
||||
//hwSettings->macsec.tx.rule[0].enable = false;
|
||||
for(uint8_t i = 1; i < maxRule; i++) {
|
||||
hwSettings->macsec.rx.rule[i].enable = false;
|
||||
hwSettings->macsec.tx.rule[i].enable = false;
|
||||
}
|
||||
} else {
|
||||
for(uint8_t i = 0; i < maxRule; i++) {
|
||||
if(i < rxRule.size()) {
|
||||
auto* hwRxRule = &hwSettings->macsec.rx.rule[i];
|
||||
SetHardwareRxRule(hwRxRule, rxRule[i], i);
|
||||
} else {
|
||||
hwSettings->macsec.rx.rule[i].enable = false;
|
||||
hwSettings->macsec.tx.rule[i].enable = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hwSettings->len = sizeof(MACSEC_SETTINGS_W_HDR);
|
||||
hwSettings->version = MACSEC_SETTINGS_VERSION;
|
||||
hwSettings->macsec.flags.en = (enableRx || enableTx) ? 1u : 0u;
|
||||
hwSettings->macsec.flags.nvm = nvm ? 1u : 0u;
|
||||
hwSettings->macsec.rx.flags.en = enableRx ? 1u : 0u;
|
||||
hwSettings->macsec.tx.flags.en = enableTx ? 1u : 0u;
|
||||
hwSettings->crc32 = crc32(0, (uint8_t*)&hwSettings->macsec, sizeof(MACSEC_SETTINGS));
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
#include "icsneo/core/ringbuffer.h"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
RingBuffer::RingBuffer(size_t bufferSize) : readCursor(0), writeCursor(0) {
|
||||
// round the buffer size to the nearest power of 2
|
||||
bufferSize = RoundUp(bufferSize);
|
||||
mask = bufferSize - 1;
|
||||
buf = new uint8_t[bufferSize];
|
||||
}
|
||||
|
||||
RingBuffer::~RingBuffer() {
|
||||
delete[] buf;
|
||||
buf = nullptr;
|
||||
}
|
||||
|
||||
const uint8_t& RingBuffer::operator[](size_t offset) const {
|
||||
return get(offset);
|
||||
}
|
||||
|
||||
size_t RingBuffer::size() const {
|
||||
// The values in the cursors are monotonic, i.e. they only ever increment. They can be considered to be the total number of elements ever written or read
|
||||
auto currentWriteCursor = writeCursor.load(std::memory_order_relaxed);
|
||||
auto currentReadCursor = readCursor.load(std::memory_order_relaxed);
|
||||
// Using unmasked values, writeCursor is guaranteed to be >= readCursor. If they are equal that means the buffer is empty
|
||||
return currentWriteCursor - currentReadCursor;
|
||||
}
|
||||
|
||||
void RingBuffer::pop_front() {
|
||||
pop(1);
|
||||
}
|
||||
|
||||
void RingBuffer::pop(size_t count) {
|
||||
if (size() < count) {
|
||||
throw std::runtime_error("RingBuffer: Underflow");
|
||||
}
|
||||
readCursor.fetch_add(count, std::memory_order_release);
|
||||
}
|
||||
|
||||
const uint8_t& RingBuffer::get(size_t offset) const {
|
||||
if (offset >= size()) {
|
||||
throw std::runtime_error("RingBuffer: Index out of range");
|
||||
}
|
||||
auto currentReadCursor = readCursor.load(std::memory_order_acquire);
|
||||
return *resolve(currentReadCursor, offset);
|
||||
}
|
||||
|
||||
bool RingBuffer::write(const uint8_t* addr, size_t length) {
|
||||
const auto freeSpace = (capacity() - size());
|
||||
if (length > freeSpace) {
|
||||
return false;
|
||||
}
|
||||
auto currentWriteCursor = writeCursor.load(std::memory_order_relaxed);
|
||||
auto spaceAtEnd = std::min(freeSpace, capacity() - (currentWriteCursor & mask)); // number of bytes from (masked) writeCursor to the end of the writable space (i.e. we reach the masked read cursor or the end of the buffer)
|
||||
auto firstCopySize = std::min(spaceAtEnd, length);
|
||||
(void)memcpy(resolve(currentWriteCursor, 0), addr, firstCopySize);
|
||||
if (firstCopySize < length)
|
||||
{
|
||||
(void)memcpy(buf, &addr[firstCopySize], length - firstCopySize);
|
||||
}
|
||||
|
||||
writeCursor.store(currentWriteCursor + length, std::memory_order_release);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RingBuffer::write(const std::vector<uint8_t>& source) {
|
||||
return write(source.data(), source.size());
|
||||
}
|
||||
|
||||
bool RingBuffer::read(uint8_t* dest, size_t startIndex, size_t length) const {
|
||||
auto currentSize = size();
|
||||
if ((startIndex >= currentSize) || ((startIndex + length) > size())) {
|
||||
return false;
|
||||
}
|
||||
auto currentReadCursor = readCursor.load(std::memory_order_relaxed);
|
||||
auto bytesAtEnd = std::min<size_t>(capacity() - ((currentReadCursor + startIndex) & mask), length);
|
||||
const auto bytesAtStart = (length - bytesAtEnd);
|
||||
|
||||
(void)memcpy(dest, resolve(currentReadCursor, startIndex), bytesAtEnd);
|
||||
if (bytesAtStart > 0) {
|
||||
(void)memcpy(&dest[bytesAtEnd], buf, bytesAtStart);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RingBuffer::clear() {
|
||||
pop(size());
|
||||
}
|
||||
|
||||
}
|
||||
+99
-886
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user