From b565eca5856008d1ddc2c147b56516b4e783dc60 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sat, 15 Jan 2022 23:29:40 +0200 Subject: [PATCH] Fix CAN keyword arg. * sampling_point was renamed to sample_point in upstream. --- .../Arduino/Portenta-H7/02-Board-Control/can.py | 2 +- .../image_transfer_raw_as_the_controller_device.py | 4 ++-- .../image_transfer_raw_as_the_remote_device.py | 4 ++-- .../popular_features_as_the_controller_device.py | 4 ++-- .../popular_features_as_the_remote_device.py | 4 ++-- scripts/examples/OpenMV/02-Board-Control/can.py | 2 +- .../image_transfer_raw_as_the_controller_device.py | 4 ++-- .../image_transfer_raw_as_the_remote_device.py | 4 ++-- .../popular_features_as_the_controller_device.py | 4 ++-- .../popular_features_as_the_remote_device.py | 4 ++-- scripts/libraries/rpc.py | 14 +++++++------- 11 files changed, 25 insertions(+), 25 deletions(-) diff --git a/scripts/examples/Arduino/Portenta-H7/02-Board-Control/can.py b/scripts/examples/Arduino/Portenta-H7/02-Board-Control/can.py index 09dca35c5..2de3bb9ca 100644 --- a/scripts/examples/Arduino/Portenta-H7/02-Board-Control/can.py +++ b/scripts/examples/Arduino/Portenta-H7/02-Board-Control/can.py @@ -9,7 +9,7 @@ from pyb import CAN # NOTE: Set to False on receiving node. TRANSMITTER = True -can = CAN(2, CAN.NORMAL, baudrate=125_000, sampling_point=75) +can = CAN(2, CAN.NORMAL, baudrate=125_000, sample_point=75) # NOTE: uncomment to set bit timing manually, for example: #can.init(CAN.NORMAL, prescaler=32, sjw=1, bs1=8, bs2=3) can.restart() diff --git a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_controller_device.py b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_controller_device.py index f3b9d1a07..9a1eddc35 100644 --- a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_controller_device.py +++ b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_controller_device.py @@ -17,12 +17,12 @@ import image, network, omv, rpc, sensor, struct, time # # * message_id - CAN message to use for data transport on the can bus (11-bit). # * bit_rate - CAN bit rate. -# * sampling_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75.0, 87.5, etc.) +# * sample_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75.0, 87.5, etc.) # # NOTE: Master and slave message ids and can bit rates must match. Connect master can high to slave # can high and master can low to slave can lo. The can bus must be terminated with 120 ohms. # -# interface = rpc.rpc_can_master(message_id=0x7FF, bit_rate=1000000, sampling_point=75.0) +# interface = rpc.rpc_can_master(message_id=0x7FF, bit_rate=1000000, sample_point=75.0) # Uncomment the below line to setup your OpenMV Cam for controlling over I2C. # diff --git a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_remote_device.py b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_remote_device.py index c04ac7d66..01d6ed83d 100644 --- a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_remote_device.py +++ b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_remote_device.py @@ -22,12 +22,12 @@ sensor.skip_frames(time = 2000) # # * message_id - CAN message to use for data transport on the can bus (11-bit). # * bit_rate - CAN bit rate. -# * sampling_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75.0, 87.5, etc.) +# * sample_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75.0, 87.5, etc.) # # NOTE: Master and slave message ids and can bit rates must match. Connect master can high to slave # can high and master can low to slave can lo. The can bus must be terminated with 120 ohms. # -# interface = rpc.rpc_can_slave(message_id=0x7FF, bit_rate=1000000, sampling_point=75.0) +# interface = rpc.rpc_can_slave(message_id=0x7FF, bit_rate=1000000, sample_point=75.0) # Uncomment the below line to setup your OpenMV Cam for control over I2C. # diff --git a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/popular_features_as_the_controller_device.py b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/popular_features_as_the_controller_device.py index 60cb6161b..f8cd78014 100644 --- a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/popular_features_as_the_controller_device.py +++ b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/popular_features_as_the_controller_device.py @@ -19,12 +19,12 @@ import json, rpc, struct # # * message_id - CAN message to use for data transport on the can bus (11-bit). # * bit_rate - CAN bit rate. -# * sampling_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75, 87.5, etc.) +# * sample_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75, 87.5, etc.) # # NOTE: Master and slave message ids and can bit rates must match. Connect master can high to slave # can high and master can low to slave can lo. The can bus must be terminated with 120 ohms. # -# interface = rpc.rpc_can_master(message_id=0x7FF, bit_rate=250000, sampling_point=75) +# interface = rpc.rpc_can_master(message_id=0x7FF, bit_rate=250000, sample_point=75) # Uncomment the below line to setup your OpenMV Cam for controlling over I2C. # diff --git a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/popular_features_as_the_remote_device.py b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/popular_features_as_the_remote_device.py index dca20ca14..89fda9acf 100644 --- a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/popular_features_as_the_remote_device.py +++ b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/popular_features_as_the_remote_device.py @@ -24,12 +24,12 @@ sensor.skip_frames(time = 2000) # # * message_id - CAN message to use for data transport on the can bus (11-bit). # * bit_rate - CAN bit rate. -# * sampling_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75, 87.5, etc.) +# * sample_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75, 87.5, etc.) # # NOTE: Master and slave message ids and can bit rates must match. Connect master can high to slave # can high and master can low to slave can lo. The can bus must be terminated with 120 ohms. # -# interface = rpc.rpc_can_slave(message_id=0x7FF, bit_rate=250000, sampling_point=75) +# interface = rpc.rpc_can_slave(message_id=0x7FF, bit_rate=250000, sample_point=75) # Uncomment the below line to setup your OpenMV Cam for control over I2C. # diff --git a/scripts/examples/OpenMV/02-Board-Control/can.py b/scripts/examples/OpenMV/02-Board-Control/can.py index 09dca35c5..2de3bb9ca 100644 --- a/scripts/examples/OpenMV/02-Board-Control/can.py +++ b/scripts/examples/OpenMV/02-Board-Control/can.py @@ -9,7 +9,7 @@ from pyb import CAN # NOTE: Set to False on receiving node. TRANSMITTER = True -can = CAN(2, CAN.NORMAL, baudrate=125_000, sampling_point=75) +can = CAN(2, CAN.NORMAL, baudrate=125_000, sample_point=75) # NOTE: uncomment to set bit timing manually, for example: #can.init(CAN.NORMAL, prescaler=32, sjw=1, bs1=8, bs2=3) can.restart() diff --git a/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_controller_device.py b/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_controller_device.py index f3b9d1a07..9a1eddc35 100644 --- a/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_controller_device.py +++ b/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_controller_device.py @@ -17,12 +17,12 @@ import image, network, omv, rpc, sensor, struct, time # # * message_id - CAN message to use for data transport on the can bus (11-bit). # * bit_rate - CAN bit rate. -# * sampling_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75.0, 87.5, etc.) +# * sample_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75.0, 87.5, etc.) # # NOTE: Master and slave message ids and can bit rates must match. Connect master can high to slave # can high and master can low to slave can lo. The can bus must be terminated with 120 ohms. # -# interface = rpc.rpc_can_master(message_id=0x7FF, bit_rate=1000000, sampling_point=75.0) +# interface = rpc.rpc_can_master(message_id=0x7FF, bit_rate=1000000, sample_point=75.0) # Uncomment the below line to setup your OpenMV Cam for controlling over I2C. # diff --git a/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_remote_device.py b/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_remote_device.py index 77c3cd499..8cf24bef0 100644 --- a/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_remote_device.py +++ b/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_remote_device.py @@ -22,12 +22,12 @@ sensor.skip_frames(time = 2000) # # * message_id - CAN message to use for data transport on the can bus (11-bit). # * bit_rate - CAN bit rate. -# * sampling_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75.0, 87.5, etc.) +# * sample_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75.0, 87.5, etc.) # # NOTE: Master and slave message ids and can bit rates must match. Connect master can high to slave # can high and master can low to slave can lo. The can bus must be terminated with 120 ohms. # -# interface = rpc.rpc_can_slave(message_id=0x7FF, bit_rate=1000000, sampling_point=75.0) +# interface = rpc.rpc_can_slave(message_id=0x7FF, bit_rate=1000000, sample_point=75.0) # Uncomment the below line to setup your OpenMV Cam for control over I2C. # diff --git a/scripts/examples/OpenMV/34-Remote-Control/popular_features_as_the_controller_device.py b/scripts/examples/OpenMV/34-Remote-Control/popular_features_as_the_controller_device.py index 60cb6161b..f8cd78014 100644 --- a/scripts/examples/OpenMV/34-Remote-Control/popular_features_as_the_controller_device.py +++ b/scripts/examples/OpenMV/34-Remote-Control/popular_features_as_the_controller_device.py @@ -19,12 +19,12 @@ import json, rpc, struct # # * message_id - CAN message to use for data transport on the can bus (11-bit). # * bit_rate - CAN bit rate. -# * sampling_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75, 87.5, etc.) +# * sample_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75, 87.5, etc.) # # NOTE: Master and slave message ids and can bit rates must match. Connect master can high to slave # can high and master can low to slave can lo. The can bus must be terminated with 120 ohms. # -# interface = rpc.rpc_can_master(message_id=0x7FF, bit_rate=250000, sampling_point=75) +# interface = rpc.rpc_can_master(message_id=0x7FF, bit_rate=250000, sample_point=75) # Uncomment the below line to setup your OpenMV Cam for controlling over I2C. # diff --git a/scripts/examples/OpenMV/34-Remote-Control/popular_features_as_the_remote_device.py b/scripts/examples/OpenMV/34-Remote-Control/popular_features_as_the_remote_device.py index 6d7f8d8ce..47bc46e9b 100644 --- a/scripts/examples/OpenMV/34-Remote-Control/popular_features_as_the_remote_device.py +++ b/scripts/examples/OpenMV/34-Remote-Control/popular_features_as_the_remote_device.py @@ -24,12 +24,12 @@ sensor.skip_frames(time = 2000) # # * message_id - CAN message to use for data transport on the can bus (11-bit). # * bit_rate - CAN bit rate. -# * sampling_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75, 87.5, etc.) +# * sample_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75, 87.5, etc.) # # NOTE: Master and slave message ids and can bit rates must match. Connect master can high to slave # can high and master can low to slave can lo. The can bus must be terminated with 120 ohms. # -# interface = rpc.rpc_can_slave(message_id=0x7FF, bit_rate=250000, sampling_point=75) +# interface = rpc.rpc_can_slave(message_id=0x7FF, bit_rate=250000, sample_point=75) # Uncomment the below line to setup your OpenMV Cam for control over I2C. # diff --git a/scripts/libraries/rpc.py b/scripts/libraries/rpc.py index 5ec8089fb..7bf387289 100644 --- a/scripts/libraries/rpc.py +++ b/scripts/libraries/rpc.py @@ -282,20 +282,20 @@ class rpc_slave(rpc): self.__schedule_cb = None if self.__loop_cb is not None: self.__loop_cb() -def __get_can_settings(bit_rate, sampling_point): +def __get_can_settings(bit_rate, sample_point): clk = 48000000 if omv.board_type() == "H7" else pyb.freq()[2] for prescaler in range(8): for bs1 in range(16): for bs2 in range(8): - if bit_rate == ((clk >> prescaler) // (1 + bs1 + bs2)) and (sampling_point * 10) == (((1 + bs1) * 1000) // (1 + bs1 + bs2)): + if bit_rate == ((clk >> prescaler) // (1 + bs1 + bs2)) and (sample_point * 10) == (((1 + bs1) * 1000) // (1 + bs1 + bs2)): return (1 << prescaler, bs1, bs2) - raise ValueError("Invalid bit_rate and/or sampling_point!") + raise ValueError("Invalid bit_rate and/or sample_point!") class rpc_can_master(rpc_master): - def __init__(self, message_id=0x7FF, bit_rate=250000, sampling_point=75, can_bus=2): + def __init__(self, message_id=0x7FF, bit_rate=250000, sample_point=75, can_bus=2): self.__message_id = message_id - can_prescaler, can_bs1, can_bs2 = __get_can_settings(bit_rate, sampling_point) + can_prescaler, can_bs1, can_bs2 = __get_can_settings(bit_rate, sample_point) self.__can = pyb.CAN(can_bus, pyb.CAN.NORMAL, prescaler=can_prescaler, bs1=can_bs1, bs2=can_bs2, auto_restart=True) self.__can.setfilter(0, pyb.CAN.DUAL if omv.board_type() == "H7" else pyb.CAN.LIST32, 0, [message_id, message_id]) rpc_master.__init__(self) @@ -328,9 +328,9 @@ class rpc_can_master(rpc_master): class rpc_can_slave(rpc_slave): - def __init__(self, message_id=0x7FF, bit_rate=250000, sampling_point=75, can_bus=2): + def __init__(self, message_id=0x7FF, bit_rate=250000, sample_point=75, can_bus=2): self.__message_id = message_id - can_prescaler, can_bs1, can_bs2 = __get_can_settings(bit_rate, sampling_point) + can_prescaler, can_bs1, can_bs2 = __get_can_settings(bit_rate, sample_point) self.__can = pyb.CAN(can_bus, pyb.CAN.NORMAL, prescaler=can_prescaler, bs1=can_bs1, bs2=can_bs2, auto_restart=True) self.__can.setfilter(0, pyb.CAN.DUAL if omv.board_type() == "H7" else pyb.CAN.LIST32, 0, [message_id, message_id]) rpc_slave.__init__(self)