Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/openmv/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# This module provides the high-level Camera class that handles all
# camera operations and channel communications using the OpenMV Protocol.

import time
import struct
import sys
import serial
Expand Down Expand Up @@ -329,15 +330,24 @@ def update_capabilities(self):
self._send_cmd_wait_resp(Opcode.PROTO_SET_CAPS, 0, payload)

@retry_if_failed
def stop(self):
"""Stop running script"""
def stop(self, timeout=None):
"""Stop running script and wait for it to exit"""
# Stop running script
stdin_id = self.get_channel(name="stdin")
self._channel_ioctl(stdin_id, ChannelIOCTL.STDIN_STOP)
# Wait for the script to exit
timeout = self.timeout if timeout is None else timeout
start_time = time.time()
while self.read_status()["stdin"]:
if time.time() - start_time > timeout:
raise TimeoutException("Timeout waiting for the script to stop")

@retry_if_failed
def exec(self, script):
"""Write and execute a script"""
# Stop the running script first
if self.read_status()["stdin"]:
self.stop()
stdin_id = self.get_channel(name="stdin")
# Reset script buffer
self._channel_ioctl(stdin_id, ChannelIOCTL.STDIN_RESET)
Expand Down
6 changes: 3 additions & 3 deletions src/openmv/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ def recv_packet(self, poll_events=False):
if packet['flags'] & Flags.EVENT:
self.event_callback(packet['channel'], 0xFFFF if not packet['length']
else struct.unpack('<H', packet['payload'])[0])
start_time = time.time()
continue

# Update sequence after each packet (including fragments)
Expand Down Expand Up @@ -279,12 +278,13 @@ def _process(self):
if length > self.max_payload:
self.log(seq, chan, opcode, flags, length, "Rjct")
self.buf.consume(1)
elif not self._check_seq(seq, self.sequence, opcode, flags):
elif not self._check_crc(crc, header[:Protocol.HEADER_SIZE - 2], 16):
self.log(seq, chan, opcode, flags, length, "Rjct")
self.buf.consume(1)
elif not self._check_crc(crc, header[:Protocol.HEADER_SIZE - 2], 16):
elif not self._check_seq(seq, self.sequence, opcode, flags):
self.log(seq, chan, opcode, flags, length, "Rjct")
self.buf.consume(1)
raise SequenceException("")
else:
self.state = State.PAYLOAD
self.plength = Protocol.HEADER_SIZE + length
Expand Down
Loading