Skip to content

Commit

Permalink
Update comments and var names on packet.py (#218)
Browse files Browse the repository at this point in the history
Co-authored-by: Guilherme De Moura Araujo <[email protected]>
  • Loading branch information
guilhermedemouraa and Guilherme De Moura Araujo authored Sep 30, 2024
1 parent 03813d8 commit a999103
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions protos/farm_ng/canbus/tool_control.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ message PtoCommand {
// For commanding a BugDispenser device
message BugDispenserCommand {
uint32 id = 1; // Bug dispenser ID (e.g., 0x20 - 0x22)
float rate = 2; // Dispensing rate in meters between drops
float rate = 2; // Dispensing rate in mL/m
BugDispenserState state = 3; // Bug dispenser state (UNKNOWN, ACTIVE, STOPPED)
}

Expand Down Expand Up @@ -141,7 +141,7 @@ message BugDispenserStatus {
double stamp = 1; // Stamp of the bug dispenser RawCanbusMessage event
uint32 id = 2; // Bug dispenser ID (e.g., 0x20 - 0x22)
BugDispenserState state = 3; // UNKNOWN, ACTIVE, STOPPED
float rate = 4; // Dispensing rate in meters between drops
float rate = 4; // Dispensing rate in mL/m
bool bug_dispenser_is_dispensing = 5; // Whether the hopper is dispensing
float volume_dispensed = 6; // Volume of product dispensed in liters
}
Expand Down
15 changes: 7 additions & 8 deletions py/farm_ng/canbus/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,28 +540,27 @@ class BugDispenserCommand(Packet):
"""Bug dispenser rate in m/drop (request) sent to the Amiga dashboard."""

cob_id = 0x400
format = "<3B5x"
scale = 10.0

def __init__(self, rate0=0, rate1=0, rate2=0):
self.rate0 = rate0
self.rate1 = rate1
self.rate2 = rate2
self.format = '<3B5x' # 3 bytes for rates, 5 bytes padding
self.stamp_packet(time.monotonic())

def encode(self):
"""Returns the data contained by the class encoded as CAN message data."""

if any(rate > 25.5 or rate < 0.0 for rate in [self.rate0, self.rate1, self.rate2]):
raise ValueError("Rates must be between 0.0 and 25.5 m/drop")
raise ValueError("Rates must be between 0.0 and 25.5 mL/m")

return pack(
self.format, int(self.rate0 * self.scale), int(self.rate1 * self.scale), int(self.rate2 * self.scale)
)

def decode(self, data):
"""Decodes CAN message data and populates the values of the class."""

rate0, rate1, rate2 = unpack(self.format, data)

# Convert rates to m/drop
Expand All @@ -581,19 +580,19 @@ def to_raw_canbus_message(self) -> canbus_pb2.RawCanbusMessage:


class BugDispenserState(Packet):
"""Bug dispenser rate in m/drop, 8-bit counter (response) received from the Amiga dashboard."""
"""Bug dispenser rate in mL/m, 8-bit counter (response) received from the Amiga dashboard."""

cob_id = 0x380
format = "<6B2x"
scale = 10.0

def __init__(self, rate0=0, counter0=0, rate1=0, counter1=0, rate2=0, counter2=0):
self.rate0 = rate0
self.counter0 = counter0
self.rate1 = rate1
self.counter1 = counter1
self.rate2 = rate2
self.counter0 = counter0
self.counter1 = counter1
self.counter2 = counter2
self.format = '<6B2x' # 3 bytes for rates, 3 bytes for counters, 2 padding bytes
self.stamp_packet(time.monotonic())

def encode(self):
Expand All @@ -604,7 +603,7 @@ def encode(self):
"""

if any(rate > 25.5 or rate < 0.0 for rate in [self.rate0, self.rate1, self.rate2]):
raise ValueError("Rates must be between 0 and 25.5 m/drop")
raise ValueError("Rates must be between 0 and 25.5 mL/m")

if any(counter > 255 or counter < 0 for counter in [self.counter0, self.counter1, self.counter2]):
raise ValueError("Counters must be between 0 and 255")
Expand Down

0 comments on commit a999103

Please sign in to comment.