zlgcan 0.2.1b0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -74,9 +74,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
74
74
 
75
75
  [[package]]
76
76
  name = "indexmap"
77
- version = "2.9.0"
77
+ version = "2.10.0"
78
78
  source = "registry+https://github.com/rust-lang/crates.io-index"
79
- checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e"
79
+ checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661"
80
80
  dependencies = [
81
81
  "equivalent",
82
82
  "hashbrown",
@@ -210,7 +210,7 @@ dependencies = [
210
210
  [[package]]
211
211
  name = "rs-can"
212
212
  version = "0.3.0"
213
- source = "git+https://github.com/jesses2025smith/rust-can.git?rev=e76db38dd2e6d66f0afa9374e9a9513d984b6be2#e76db38dd2e6d66f0afa9374e9a9513d984b6be2"
213
+ source = "git+https://github.com/jesses2025smith/rust-can.git?rev=05a051f662385bcc33cd99bf195eedaa528983fe#05a051f662385bcc33cd99bf195eedaa528983fe"
214
214
  dependencies = [
215
215
  "bitflags",
216
216
  "derive-getters",
@@ -345,7 +345,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
345
345
  [[package]]
346
346
  name = "zlgcan"
347
347
  version = "0.3.0"
348
- source = "git+https://github.com/jesses2025smith/rust-can.git?rev=e76db38dd2e6d66f0afa9374e9a9513d984b6be2#e76db38dd2e6d66f0afa9374e9a9513d984b6be2"
348
+ source = "git+https://github.com/jesses2025smith/rust-can.git?rev=05a051f662385bcc33cd99bf195eedaa528983fe#05a051f662385bcc33cd99bf195eedaa528983fe"
349
349
  dependencies = [
350
350
  "dlopen2",
351
351
  "log",
@@ -357,7 +357,7 @@ dependencies = [
357
357
 
358
358
  [[package]]
359
359
  name = "zlgcan-driver"
360
- version = "0.2.1-beta"
360
+ version = "0.2.2"
361
361
  dependencies = [
362
362
  "anyhow",
363
363
  "pyo3",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "zlgcan-driver"
3
- version = "0.2.1-beta"
3
+ version = "0.2.2"
4
4
  edition = "2021"
5
5
 
6
6
  # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -13,8 +13,8 @@ pyo3 = "0.25"
13
13
  #iso15765-2 = { version = "0.1.0-alpha0" }
14
14
  #iso14229-1 = { version = "0.1.0-alpha0" }
15
15
  #docan = { version = "0.1.0-alpha0" }
16
- rs-can = { git = "https://github.com/jesses2025smith/rust-can.git", package = "rs-can", rev = "e76db38dd2e6d66f0afa9374e9a9513d984b6be2" }
17
- zlgcan = { git = "https://github.com/jesses2025smith/rust-can.git", package = "zlgcan", rev = "e76db38dd2e6d66f0afa9374e9a9513d984b6be2" }
16
+ rs-can = { git = "https://github.com/jesses2025smith/rust-can.git", rev = "05a051f662385bcc33cd99bf195eedaa528983fe", package = "rs-can" }
17
+ zlgcan = { git = "https://github.com/jesses2025smith/rust-can.git", rev = "05a051f662385bcc33cd99bf195eedaa528983fe", package = "zlgcan" }
18
18
 
19
19
  [dev-dependencies]
20
20
  anyhow = "1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zlgcan
3
- Version: 0.2.1b0
3
+ Version: 0.2.2
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -25,6 +25,8 @@ fn zlgcan_init_can(
25
25
  cfgs: Vec<ZCanChlCfgPy>,
26
26
  derive_info: Option<ZDeriveInfoPy>,
27
27
  ) -> PyResult<ZCanDriverWrap> {
28
+ let dev_type = ZCanDeviceType::try_from(dev_type)
29
+ .map_err(|e| exceptions::PyValueError::new_err(e.to_string()))?;
28
30
  let mut builder = DeviceBuilder::new();
29
31
  builder
30
32
  .add_other(LIBPATH, Box::new(libpath))
@@ -35,9 +37,13 @@ fn zlgcan_init_can(
35
37
  );
36
38
 
37
39
  for (i, cfg) in cfgs.into_iter().enumerate() {
40
+ let fdchl_type = ZCanFdChlType::try_from(cfg.fdchl_type)
41
+ .map_err(|e| exceptions::PyValueError::new_err(e.to_string()))?;
42
+ let chl_mode = ZCanChlMode::try_from(cfg.chl_mode)
43
+ .map_err(|e| exceptions::PyValueError::new_err(e.to_string()))?;
38
44
  let mut c = ChannelConfig::new(cfg.bitrate);
39
- c.add_other(CHANNEL_TYPE, Box::new(cfg.chl_type))
40
- .add_other(CHANNEL_MODE, Box::new(cfg.chl_mode));
45
+ c.add_other(FD_CHANNEL_TYPE, Box::new(fdchl_type))
46
+ .add_other(CHANNEL_MODE, Box::new(chl_mode));
41
47
 
42
48
  cfg.dbitrate.map(|dbitrate| c.set_data_bitrate(dbitrate));
43
49
  cfg.resistance.map(|resistance| c.set_resistance(resistance));
@@ -165,11 +171,7 @@ fn zlgcan_driver(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
165
171
 
166
172
  #[cfg(test)]
167
173
  mod tests {
168
- use std::time::Instant;
169
- use zlgcan::{
170
- can::{ZCanChlMode, ZCanChlType},
171
- device::ZCanDeviceType,
172
- };
174
+ use zlgcan::{can::ZCanChlMode, device::ZCanDeviceType};
173
175
  use super::*;
174
176
 
175
177
  #[test]
@@ -179,35 +181,42 @@ mod tests {
179
181
  let dev_type = ZCanDeviceType::ZCAN_USBCANFD_200U as u32;
180
182
  let dev_idx = 0;
181
183
  let cfg = ZCanChlCfgPy::new(
182
- ZCanChlType::CANFD_ISO as u8,
183
184
  ZCanChlMode::Normal as u8,
184
185
  500_000,
185
186
  None,
186
- Some(1_000_000),
187
+ None,
188
+ Some(true),
189
+ None,
190
+ None,
191
+ None,
192
+ None,
193
+ );
194
+ let cfg2 = ZCanChlCfgPy::new(
195
+ ZCanChlMode::Normal as u8,
196
+ 500_000,
197
+ None,
198
+ None,
199
+ Some(true),
187
200
  None,
188
201
  None,
189
202
  None,
190
203
  None,
191
204
  );
192
205
 
193
- let device = zlgcan_init_can("../../RustProjects/rust-can/zlgcan/library".into(), dev_type, dev_idx, vec![cfg, ], None)?;
206
+ let device = zlgcan_init_can("../../RustRoverProjects/rust-can/zlgcan/library".into(), dev_type, dev_idx, vec![cfg, cfg2], None)?;
194
207
  let dev_info = zlgcan_device_info(&device)?;
195
208
  println!("{}", dev_info);
196
209
  std::thread::sleep(std::time::Duration::from_secs(1));
197
210
 
198
- let start = Instant::now();
199
- let mut flag = false;
200
- while start.elapsed().as_secs() < 15 {
201
- let msgs = zlgcan_recv(&device, 0, None)?;
202
- if !msgs.is_empty() {
203
- println!("{:?}", msgs);
204
- flag = true;
205
- }
206
- drop(msgs);
207
-
208
- if flag {
209
- break;
210
- }
211
+ let mut msg = CanMessage::new(0x7df, &vec![0x02, 0x10, 0x01]).unwrap();
212
+ msg.set_channel(0);
213
+ let ret = zlgcan_send(&device, msg.into())?;
214
+ println!("send: {}", ret);
215
+
216
+ std::thread::sleep(std::time::Duration::from_micros(200));
217
+ let msgs = zlgcan_recv(&device, 1, None)?;
218
+ if !msgs.is_empty() {
219
+ println!("{:?}", msgs);
211
220
  }
212
221
 
213
222
  zlgcan_close(&device)?;
@@ -38,14 +38,14 @@ pub struct ZCanDriverWrap {
38
38
  }
39
39
 
40
40
  #[pyclass]
41
- #[derive(Clone)]
41
+ #[derive(Debug, Clone)]
42
42
  pub struct ZCanChlCfgPy {
43
- pub(crate) chl_type: u8,
44
43
  pub(crate) chl_mode: u8,
45
44
  pub(crate) bitrate: u32,
46
45
  pub(crate) filter: Option<u8>,
47
46
  pub(crate) dbitrate: Option<u32>,
48
47
  pub(crate) resistance: Option<bool>,
48
+ pub(crate) fdchl_type: u8,
49
49
  pub(crate) acc_code: Option<u32>,
50
50
  pub(crate) acc_mask: Option<u32>,
51
51
  pub(crate) brp: Option<u32>,
@@ -54,25 +54,25 @@ pub struct ZCanChlCfgPy {
54
54
  #[pymethods]
55
55
  impl ZCanChlCfgPy {
56
56
  #[new]
57
- #[pyo3(signature = (chl_type, chl_mode, bitrate, filter=None, dbitrate=None, resistance=None, acc_code=None, acc_mask=None, brp=None))]
57
+ #[pyo3(signature = (chl_mode, bitrate, filter=None, dbitrate=None, resistance=None, fdchl_type=None, acc_code=None, acc_mask=None, brp=None))]
58
58
  pub fn new(
59
- chl_type: u8,
60
59
  chl_mode: u8,
61
60
  bitrate: u32,
62
61
  filter: Option<u8>,
63
62
  dbitrate: Option<u32>,
64
63
  resistance: Option<bool>,
64
+ fdchl_type: Option<u8>,
65
65
  acc_code: Option<u32>,
66
66
  acc_mask: Option<u32>,
67
67
  brp: Option<u32>,
68
68
  ) -> Self {
69
69
  ZCanChlCfgPy {
70
- chl_type,
71
70
  chl_mode,
72
71
  bitrate,
73
72
  filter,
74
73
  dbitrate,
75
74
  resistance,
75
+ fdchl_type: fdchl_type.unwrap_or(0),
76
76
  acc_code,
77
77
  acc_mask,
78
78
  brp,
@@ -28,10 +28,9 @@ except ModuleNotFoundError:
28
28
  }.get(_platform, not_support)
29
29
 
30
30
 
31
- class ZCanChlType:
32
- CAN = 0
33
- CANFD_ISO = 1
34
- CANFD_NON_ISO = 2
31
+ class ZCanFdChlType:
32
+ ISO = 0
33
+ NON_ISO = 1
35
34
 
36
35
  class ZCanChlMode:
37
36
  Normal = 0
@@ -169,12 +168,12 @@ class ZCanBus(can.BusABC):
169
168
  dbitrate = cfg.get("dbitrate", None)
170
169
  assert bitrate is not None, "bitrate is required!"
171
170
  _cfg = ZCanChlCfgPy(
172
- chl_type=cfg.get("chl_type", ZCanChlType.CANFD_ISO if dbitrate else ZCanChlType.CAN),
173
- chl_mode=cfg.get("chl_mode", 0),
171
+ chl_mode=cfg.get("chl_mode", ZCanChlMode.Normal),
174
172
  bitrate=bitrate,
175
173
  filter=cfg.get("filter"),
176
174
  dbitrate=dbitrate,
177
175
  resistance=bool(cfg.get("resistance", 1)),
176
+ fdchl_type=cfg.get("fdchl_type", ZCanFdChlType.ISO),
178
177
  acc_code=cfg.get("acc_code"),
179
178
  acc_mask=cfg.get("acc_mask"),
180
179
  brp=cfg.get("brp")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes