@@ -38,6 +38,7 @@ macro_rules! generate_servo {
3838 use pyo3:: prelude:: * ;
3939
4040 $crate:: generate_protocol_constructor!( $servo_name, $protocol) ;
41+ $crate:: generate_addr_read_write!( $servo_name) ;
4142
4243 $(
4344 $crate:: generate_reg_access!( $servo_name, $reg_name, $reg_access, $reg_addr, $reg_type, $conv) ;
@@ -111,6 +112,71 @@ macro_rules! generate_protocol_constructor {
111112 } ;
112113}
113114
115+ #[ macro_export]
116+ macro_rules! generate_addr_read_write {
117+ ( $servo_name: ident) => {
118+ paste:: paste! {
119+ impl [ <$servo_name: camel Controller >] {
120+ pub fn read_raw_data(
121+ & mut self ,
122+ ids: & [ u8 ] ,
123+ addr: u8 ,
124+ length: u8 ,
125+ ) -> $crate:: Result <Vec <Vec <u8 >>> {
126+ let dph = self . dph. as_ref( ) . unwrap( ) ;
127+ let serial_port = self . serial_port. as_mut( ) . unwrap( ) . as_mut( ) ;
128+ dph. sync_read( serial_port, ids, addr, length)
129+ }
130+
131+ pub fn write_raw_data(
132+ & mut self ,
133+ ids: & [ u8 ] ,
134+ addr: u8 ,
135+ data: & [ Vec <u8 >] ,
136+ ) -> $crate:: Result <( ) > {
137+ let dph = self . dph. as_ref( ) . unwrap( ) ;
138+ let serial_port = self . serial_port. as_mut( ) . unwrap( ) . as_mut( ) ;
139+ dph. sync_write( serial_port, ids, addr, data)
140+ }
141+ }
142+
143+ #[ cfg( feature = "python" ) ]
144+ #[ pymethods]
145+ impl [ <$servo_name: camel SyncController >] {
146+ pub fn read_raw_data(
147+ & self ,
148+ py: Python ,
149+ ids: & Bound <' _, pyo3:: types:: PyList >,
150+ addr: u8 ,
151+ length: u8 ,
152+ ) -> PyResult <PyObject > {
153+ let ids = ids. extract:: <Vec <u8 >>( ) ?;
154+
155+ let x = self . 0 . lock( ) . unwrap( ) . read_raw_data( & ids, addr, length)
156+ . map_err( |e| pyo3:: exceptions:: PyRuntimeError :: new_err( e. to_string( ) ) ) ?;
157+ let l = pyo3:: types:: PyList :: new( py, x. clone( ) ) ?;
158+
159+ Ok ( l. into( ) )
160+ }
161+
162+ pub fn write_raw_data(
163+ & self ,
164+ ids: & Bound <' _, pyo3:: types:: PyList >,
165+ addr: u8 ,
166+ data: & Bound <' _, pyo3:: types:: PyList >,
167+ ) -> PyResult <( ) > {
168+ let ids = ids. extract:: <Vec <u8 >>( ) ?;
169+ let data = data. extract:: <Vec <Vec <u8 >>>( ) ?;
170+
171+ self . 0 . lock( ) . unwrap( ) . write_raw_data( & ids, addr, & data)
172+ . map_err( |e| pyo3:: exceptions:: PyRuntimeError :: new_err( e. to_string( ) ) ) ?;
173+ Ok ( ( ) )
174+ }
175+ }
176+ }
177+ } ;
178+ }
179+
114180#[ macro_export]
115181macro_rules! generate_reg_access {
116182 ( $servo_name: ident, $reg_name: ident, r, $reg_addr: expr, $reg_type: ty, $conv: ident) => {
@@ -243,6 +309,18 @@ macro_rules! generate_reg_read {
243309 }
244310
245311 impl [ <$servo_name: camel Controller >] {
312+ #[ doc = concat!( "Read raw register *" , stringify!( $name) , "* (addr: " , stringify!( $addr) , ", type: " , stringify!( <$conv as Conversion >:: UsiType ) , ")" ) ]
313+ pub fn [ <read_raw_ $reg_name>] (
314+ & mut self ,
315+ ids: & [ u8 ] ,
316+ ) -> $crate:: Result <Vec <$reg_type>> {
317+ [ <sync_read_raw_ $reg_name>] (
318+ self . dph. as_ref( ) . unwrap( ) ,
319+ self . serial_port. as_mut( ) . unwrap( ) . as_mut( ) ,
320+ ids,
321+ )
322+ }
323+
246324 #[ doc = concat!( "Read register *" , stringify!( $name) , "* (addr: " , stringify!( $addr) , ", type: " , stringify!( $reg_type) , ")" ) ]
247325 pub fn [ <read_ $reg_name>] (
248326 & mut self ,
@@ -259,6 +337,20 @@ macro_rules! generate_reg_read {
259337 #[ cfg( feature = "python" ) ]
260338 #[ pymethods]
261339 impl [ <$servo_name: camel SyncController >] {
340+ #[ doc = concat!( "Read raw register *" , stringify!( $name) , "* (addr: " , stringify!( $addr) , ", type: " , stringify!( $reg_type) , ")" ) ]
341+ pub fn [ <read_raw_ $reg_name>] (
342+ & self ,
343+ py: Python ,
344+ ids: & Bound <' _, pyo3:: types:: PyList >,
345+ ) -> PyResult <PyObject > {
346+ let ids = ids. extract:: <Vec <u8 >>( ) ?;
347+
348+ let x = self . 0 . lock( ) . unwrap( ) . [ <read_raw_ $reg_name>] ( & ids)
349+ . map_err( |e| pyo3:: exceptions:: PyRuntimeError :: new_err( e. to_string( ) ) ) ?;
350+ let l = pyo3:: types:: PyList :: new( py, x. clone( ) ) ?;
351+ Ok ( l. into( ) )
352+ }
353+
262354 #[ doc = concat!( "Read register *" , stringify!( $name) , "* (addr: " , stringify!( $addr) , ", type: " , stringify!( $reg_type) , ")" ) ]
263355 pub fn [ <read_ $reg_name>] (
264356 & self ,
@@ -400,6 +492,20 @@ macro_rules! generate_reg_write {
400492 }
401493
402494 impl [ <$servo_name: camel Controller >] {
495+ #[ doc = concat!( "Write raw register *" , stringify!( $name) , "* (addr: " , stringify!( $addr) , ", type: " , stringify!( $reg_type) , ")" ) ]
496+ pub fn [ <write_raw_ $reg_name>] (
497+ & mut self ,
498+ ids: & [ u8 ] ,
499+ values: & [ $reg_type] ,
500+ ) -> $crate:: Result <( ) > {
501+ [ <sync_write_raw_ $reg_name>] (
502+ self . dph. as_ref( ) . unwrap( ) ,
503+ self . serial_port. as_mut( ) . unwrap( ) . as_mut( ) ,
504+ ids,
505+ values,
506+ )
507+ }
508+
403509 #[ doc = concat!( "Write register *" , stringify!( $name) , "* (addr: " , stringify!( $addr) , ", type: " , stringify!( <$conv as Conversion >:: UsiType ) , ")" ) ]
404510 pub fn [ <write_ $reg_name>] (
405511 & mut self ,
@@ -418,6 +524,20 @@ macro_rules! generate_reg_write {
418524 #[ cfg( feature = "python" ) ]
419525 #[ pymethods]
420526 impl [ <$servo_name: camel SyncController >] {
527+ #[ doc = concat!( "Write raw register *" , stringify!( $name) , "* (addr: " , stringify!( $addr) , ", type: " , stringify!( $reg_type) , ")" ) ]
528+ pub fn [ <write_raw_ $reg_name>] (
529+ & self ,
530+ ids: Bound <' _, pyo3:: types:: PyList >,
531+ values: Bound <' _, pyo3:: types:: PyList >,
532+ ) -> PyResult <( ) > {
533+ let ids = ids. extract:: <Vec <u8 >>( ) ?;
534+ let values = values. extract:: <Vec <$reg_type>>( ) ?;
535+
536+ self . 0 . lock( ) . unwrap( ) . [ <write_raw_ $reg_name>] ( & ids, & values) . map_err( |e| {
537+ pyo3:: exceptions:: PyRuntimeError :: new_err( e. to_string( ) )
538+ } )
539+ }
540+
421541 #[ doc = concat!( "Write register *" , stringify!( $name) , "* (addr: " , stringify!( $addr) , ", type: " , stringify!( $reg_type) , ")" ) ]
422542 pub fn [ <write_ $reg_name>] (
423543 & self ,
0 commit comments