Skip to content

Commit

Permalink
More idiomatic handling of ipv4 addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerZ committed Sep 1, 2024
1 parent c3c853e commit bac2f78
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 38 deletions.
42 changes: 22 additions & 20 deletions examples/multi_thread_demo/multi_thread_demo.a2l
Original file line number Diff line number Diff line change
Expand Up @@ -132,42 +132,44 @@

/end IF_DATA

/begin GROUP Cal "" /begin REF_CHARACTERISTIC /end REF_CHARACTERISTIC /end GROUP

/begin CHARACTERISTIC CalPage1.ampl "Amplitude of the sine signal" VALUE 0x80010000 F64 0 NO_COMPU_METHOD 0 500 PHYS_UNIT "Volt" /end CHARACTERISTIC
/begin CHARACTERISTIC CalPage1.counter_max "Counter maximum value" VALUE 0x80010010 U32 0 NO_COMPU_METHOD 0 255 /end CHARACTERISTIC
/begin CHARACTERISTIC CalPage1.period "Period of the sine signal" VALUE 0x80010008 F64 0 NO_COMPU_METHOD 0.001 10 PHYS_UNIT "s" /end CHARACTERISTIC
/begin GROUP calseg "" /begin REF_CHARACTERISTIC CalPage1.ampl CalPage1.counter_max CalPage1.period /end REF_CHARACTERISTIC /end GROUP


/begin MEASUREMENT counter_1 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x0 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_10 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x90000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 9 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_2 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x10000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 1 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_3 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x20000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 2 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_4 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x30000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 3 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_5 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x40000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 4 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_6 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x50000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 5 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_7 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x60000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 6 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_8 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x70000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 7 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_9 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x80000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 8 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_1 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x0 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_10 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x90000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 9 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_2 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x10000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 1 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_3 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x20000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 2 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_4 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x30000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 3 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_5 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x40000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 4 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_6 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x50000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 5 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_7 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x60000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 6 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_8 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x70000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 7 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT counter_9 "" ULONG NO_COMPU_METHOD 0 0 0 4294967295 PHYS_UNIT "" ECU_ADDRESS 0x80000 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 8 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin COMPU_METHOD sine_1.Conv "" LINEAR "%6.3" "Volt" COEFFS_LINEAR 1 0 /end COMPU_METHOD
/begin MEASUREMENT sine_1 "sine: f64" FLOAT64_IEEE sine_1.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x4 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT sine_1 "sine: f64" FLOAT64_IEEE sine_1.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x4 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 0 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin COMPU_METHOD sine_10.Conv "" LINEAR "%6.3" "Volt" COEFFS_LINEAR 1 0 /end COMPU_METHOD
/begin MEASUREMENT sine_10 "sine: f64" FLOAT64_IEEE sine_10.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x90004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 9 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT sine_10 "sine: f64" FLOAT64_IEEE sine_10.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x90004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 9 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin COMPU_METHOD sine_2.Conv "" LINEAR "%6.3" "Volt" COEFFS_LINEAR 1 0 /end COMPU_METHOD
/begin MEASUREMENT sine_2 "sine: f64" FLOAT64_IEEE sine_2.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x10004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 1 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT sine_2 "sine: f64" FLOAT64_IEEE sine_2.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x10004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 1 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin COMPU_METHOD sine_3.Conv "" LINEAR "%6.3" "Volt" COEFFS_LINEAR 1 0 /end COMPU_METHOD
/begin MEASUREMENT sine_3 "sine: f64" FLOAT64_IEEE sine_3.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x20004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 2 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT sine_3 "sine: f64" FLOAT64_IEEE sine_3.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x20004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 2 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin COMPU_METHOD sine_4.Conv "" LINEAR "%6.3" "Volt" COEFFS_LINEAR 1 0 /end COMPU_METHOD
/begin MEASUREMENT sine_4 "sine: f64" FLOAT64_IEEE sine_4.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x30004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 3 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT sine_4 "sine: f64" FLOAT64_IEEE sine_4.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x30004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 3 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin COMPU_METHOD sine_5.Conv "" LINEAR "%6.3" "Volt" COEFFS_LINEAR 1 0 /end COMPU_METHOD
/begin MEASUREMENT sine_5 "sine: f64" FLOAT64_IEEE sine_5.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x40004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 4 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT sine_5 "sine: f64" FLOAT64_IEEE sine_5.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x40004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 4 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin COMPU_METHOD sine_6.Conv "" LINEAR "%6.3" "Volt" COEFFS_LINEAR 1 0 /end COMPU_METHOD
/begin MEASUREMENT sine_6 "sine: f64" FLOAT64_IEEE sine_6.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x50004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 5 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT sine_6 "sine: f64" FLOAT64_IEEE sine_6.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x50004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 5 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin COMPU_METHOD sine_7.Conv "" LINEAR "%6.3" "Volt" COEFFS_LINEAR 1 0 /end COMPU_METHOD
/begin MEASUREMENT sine_7 "sine: f64" FLOAT64_IEEE sine_7.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x60004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 6 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT sine_7 "sine: f64" FLOAT64_IEEE sine_7.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x60004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 6 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin COMPU_METHOD sine_8.Conv "" LINEAR "%6.3" "Volt" COEFFS_LINEAR 1 0 /end COMPU_METHOD
/begin MEASUREMENT sine_8 "sine: f64" FLOAT64_IEEE sine_8.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x70004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 7 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT sine_8 "sine: f64" FLOAT64_IEEE sine_8.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x70004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 7 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin COMPU_METHOD sine_9.Conv "" LINEAR "%6.3" "Volt" COEFFS_LINEAR 1 0 /end COMPU_METHOD
/begin MEASUREMENT sine_9 "sine: f64" FLOAT64_IEEE sine_9.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x80004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 8 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT
/begin MEASUREMENT sine_9 "sine: f64" FLOAT64_IEEE sine_9.Conv 0 0 -1000000000000 1000000000000 PHYS_UNIT "Volt" ECU_ADDRESS 0x80004 ECU_ADDRESS_EXTENSION 2 /begin IF_DATA XCP /begin DAQ_EVENT FIXED_EVENT_LIST EVENT 8 /end DAQ_EVENT /end IF_DATA /end MEASUREMENT

/begin GROUP task1 "" /begin REF_MEASUREMENT counter_1 counter_10 counter_2 counter_3 counter_4 counter_5 counter_6 counter_7 counter_8 counter_9 sine_1 sine_10 sine_2 sine_3 sine_4 sine_5 sine_6 sine_7 sine_8 sine_9 /end REF_MEASUREMENT /end GROUP

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ fn main() {
// .set_epk(build_info::format!("{}", $.timestamp)); // Create new EPK from build info
.set_epk("EPK_");

let xcp = match xcp_builder.start_server(if args.tcp { XcpTransportLayer::Tcp } else { XcpTransportLayer::Udp }, args.bind.octets(), args.port, args.segment_size) {
let xcp = match xcp_builder.start_server(if args.tcp { XcpTransportLayer::Tcp } else { XcpTransportLayer::Udp }, args.bind, args.port, args.segment_size) {
Err(res) => {
error!("XCP server initialization failed: {:?}", res);
return;
Expand Down
16 changes: 8 additions & 8 deletions src/reg/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Module registry
// Registry for calibration segments, parameters and measurement signals

mod a2l_writer;

use core::panic;
use std::net::Ipv4Addr;

mod a2l_writer;
use a2l_writer::A2lWriter;

use crate::xcp;
Expand Down Expand Up @@ -231,15 +231,15 @@ impl RegDataTypeProperties for RegistryDataType {
#[derive(Clone, Copy, Debug)]
struct RegistryXcpTransportLayer {
protocol_name: &'static str,
ip: [u8; 4],
addr: Ipv4Addr,
port: u16,
}

impl Default for RegistryXcpTransportLayer {
fn default() -> Self {
RegistryXcpTransportLayer {
protocol_name: "UDP",
ip: [127, 0, 0, 1],
addr: Ipv4Addr::new(127, 0, 0, 1),
port: 5555,
}
}
Expand Down Expand Up @@ -578,11 +578,11 @@ impl Registry {
}

// Set transport layer parameters
pub fn set_tl_params(&mut self, protocol_name: &'static str, ip: [u8; 4], port: u16) {
debug!("set_tl_params: {} {:?} {}", protocol_name, ip, port);
pub fn set_tl_params(&mut self, protocol_name: &'static str, addr: Ipv4Addr, port: u16) {
debug!("set_tl_params: {} {} {}", protocol_name, addr, port);
assert!(self.name.is_some(), "Registry is closed");

self.tl_params = Some(RegistryXcpTransportLayer { protocol_name, ip, port });
self.tl_params = Some(RegistryXcpTransportLayer { protocol_name, addr, port });
}

// Add an event
Expand Down Expand Up @@ -727,7 +727,7 @@ mod registry_tests {

r.set_name("test");
r.set_epk("TEST_EPK", 0x80000000);
r.set_tl_params("UDP", [127, 0, 0, 1], 5555);
r.set_tl_params("UDP", Ipv4Addr::new(127, 0, 0, 1), 5555);
r.add_cal_seg("test_memory_segment_1", 0x80010000, 0, 4);
r.add_cal_seg("test_memory_segment_2", 0x80020000, 0, 4);

Expand Down
6 changes: 3 additions & 3 deletions src/reg/registry/a2l_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ impl GenerateA2l for RegistryXcpTransportLayer {
fn to_a2l_string(&self) -> String {
let protocol = self.protocol_name.to_uppercase();
let port = self.port;
let ip = format!("{}.{}.{}.{}", self.ip[0], self.ip[1], self.ip[2], self.ip[3]);
trace!("write transport layer: {protocol} {ip}:{port}");
format!(r#"/begin XCP_ON_{protocol}_IP 0x104 {port} ADDRESS "{ip}" /end XCP_ON_UDP_IP"#)
let addr = self.addr;
trace!("write transport layer: {protocol} {addr}:{port}");
format!(r#"/begin XCP_ON_{protocol}_IP 0x104 {port} ADDRESS "{addr}" /end XCP_ON_UDP_IP"#)
}
}

Expand Down
21 changes: 15 additions & 6 deletions src/xcp.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//----------------------------------------------------------------------------------------------
// Module xcp

use std::sync::{
atomic::{AtomicU8, Ordering},
Arc, Mutex,
use std::{
net::Ipv4Addr,
sync::{
atomic::{AtomicU8, Ordering},
Arc, Mutex,
},
};

// Using sync version of OnceCell from once_cell crate for the static event remapping array
Expand Down Expand Up @@ -383,7 +386,12 @@ impl XcpBuilder {

/// Start the XCP on Ethernet Transport Layer
/// segment_size must fit the maximum UDP MTU supported by the system
pub fn start_server(self, tl: XcpTransportLayer, addr: [u8; 4], port: u16, segment_size: u16) -> Result<&'static Xcp, &'static str> {
pub fn start_server<A>(self, tl: XcpTransportLayer, addr: A, port: u16, segment_size: u16) -> Result<&'static Xcp, &'static str>
where
A: Into<Ipv4Addr>,
{
let ipv4_addr: Ipv4Addr = addr.into();
let xcp = Xcp::get();

// Server parameters from XcpBuilder
Expand All @@ -394,14 +402,15 @@ impl XcpBuilder {
{
let mut r = xcp.registry.lock().unwrap();
r.set_name(self.name);
r.set_tl_params(tl.protocol_name(), addr, port); // Transport layer parameters
r.set_tl_params(tl.protocol_name(), ipv4_addr, port); // Transport layer parameters
r.set_epk(self.epk, Xcp::XCP_EPK_ADDR); // EPK
}

// @@@@ unsafe - C library call
unsafe {
// Initialize the XCP Server and ETH transport layer
if 0 == xcplib::XcpEthServerInit(addr.as_ptr(), port, if tl == XcpTransportLayer::Tcp { 1 } else { 0 }, segment_size) {
let a: [u8; 4] = ipv4_addr.octets();
if 0 == xcplib::XcpEthServerInit(&a as *const u8, port, if tl == XcpTransportLayer::Tcp { 1 } else { 0 }, segment_size) {
return Err("Error: XcpEthServerInit() failed");
}
}
Expand Down

0 comments on commit bac2f78

Please sign in to comment.