aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/serialhdl.py
Commit message (Collapse)AuthorAgeFilesLines
* msgproto: Convert static strings to a more generic enumeration systemKevin O'Connor2019-03-171-1/+0
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* Revert "serialhdl: Enforce exclusive access on POSIX, this is default ↵Kevin O'Connor2019-02-101-2/+2
| | | | | | | | behavior on windows. (#1216)" This reverts commit fdbbda948419932be2bf93a932ae91ffc7f94e7f. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Enforce exclusive access on POSIX, this is default behavior on ↵Daniel2019-02-101-2/+2
| | | | | windows. (#1216) Signed-off-by: Daniel Joyce <daniel.a.joyce@gmail.com>
* serialqueue: Limit message transmission to available receive buffer sizeKevin O'Connor2018-05-281-0/+4
| | | | | | | | | If the mcu is using a traditional serial port, then only send a new message block if there is space available in the mcu receive buffer. This should make it significantly less likely that high load on the mcu will result in retransmits. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Automatically clear rollover_info on each restartKevin O'Connor2018-04-031-5/+0
| | | | | | | Automatically clear the information printed at the start of each log file rollover on a klippy internal restart. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Add a wrapper around the results of lookup_command()Kevin O'Connor2018-02-271-15/+27
| | | | | | | | Add a lookup_command() method to the SerialReader class that provides a wrapper that stores the serial and commandqueue references. This makes it easier to run the send() method. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* msgproto: Support default values in get_constant() callsKevin O'Connor2018-01-291-2/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* build: Add gcc and binutils version to mcu data dictionaryKevin O'Connor2017-12-211-2/+3
| | | | | | | | Store the gcc and binutils versions used in the compilation of the firmware in the firmware data dictionary. Forward that information to the log so it is available during debugging. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Don't open port at 1200 baudKevin O'Connor2017-10-121-3/+3
| | | | | | | The 1200 baud trick on the Arduino Due does both a reset and an erase. The erase is not desired. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Avoid using '%' syntax when calling logging moduleKevin O'Connor2017-09-271-12/+12
| | | | | | | The logging module can build strings directly from printf syntax - no need to build the string first. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Make dump_debug() output atomicKevin O'Connor2017-09-271-6/+8
| | | | | | | Build a single (very large) logging message with the debug state. This prevents the output from being fragmented. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* clocksync: Move clock synchronization code into new fileKevin O'Connor2017-09-191-96/+6
| | | | | | | Move the low-level clock synchronization code from serialhdl.py to a new file clocksync.py. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Reduce calculations done while holding the lockKevin O'Connor2017-09-191-3/+5
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Sometimes we get an IOError when serial port not foundKevin O'Connor2017-08-141-1/+1
| | | | | | Catch IOError when opening the serial port. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Dump serial stats in dump_debug()Kevin O'Connor2017-07-241-0/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Rework mcu clock synchronizationKevin O'Connor2017-06-301-52/+68
| | | | | | | | | | | | | | | | | | | | | | The existing clock synchronization code has two flaws: intermittent transmission latency during get_status requests can cause the estimated clock to be too low, and the estimated clock calculation did not take into account possible clock drift between samples. The former could potentially lead to "Timer too close" errors and the latter could potentially lead to "Move queue empty" errors. Rework the code to avoid the above problems. It's not necessary to estimate the micro-controller clock as an excellent estimate is reported by the micro-controller (via the CLOCK_FREQ constant). Account for a small drift from the reported value, and check on each sample if the drift exceeds the expected limits. With a good starting estimated clock, only the offset needs to be calculated. Use previous offsets (and the estimated clock) in calculation of new offsets to avoid intermittent latency from badly skewing the results. Finally, add an additional time offset of one millisecond to account for any minor inaccuracies. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Use newer "except XYZError as e" python syntaxKevin O'Connor2017-06-101-1/+1
| | | | | | Use the newer syntax for python exceptions. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Prefer python dictionary comprehension to dict() callKevin O'Connor2017-06-061-1/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Support working with pseudo serial devicesKevin O'Connor2017-05-151-2/+7
| | | | | | | Support working with devices that aren't really serial ports and thus do not have a baud rate. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Support pause() command even when the reactor is not runningKevin O'Connor2017-04-011-4/+4
| | | | | | | If the reactor isn't running then implement pause using the system sleep command. This simplifies the users of pause(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Make sure to calculate est_clock before connect() finishesKevin O'Connor2017-03-241-4/+10
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Catch SerialException as well as OSError on serial openKevin O'Connor2017-03-161-1/+1
| | | | | | | Catch the right exceptions so that a retry is possible when attempting to open the serial port. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* stepper: Introduce stepper_get_position command and remove from endstop.cKevin O'Connor2017-03-091-5/+6
| | | | | | | | Move the logic to calculate and report the stepper's current position from endstop.c to stepper.c. This localizes the stepper code into stepper.c. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Support FIRMWARE_RESTART commandKevin O'Connor2017-03-081-1/+14
| | | | | | | | Add initial support for micro-controller resets via the Arduino reset mechanism. Also, automatically attempt a firmware restart if the printer CRC does not match. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Make sure to close the serial port on disconnect()Kevin O'Connor2017-03-081-9/+9
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Detect timeout in SerialReader.send_with_response()Kevin O'Connor2017-03-081-2/+11
| | | | | | Raise an error if the response is never received. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Load the mcu's 64bit clock at start of connectionKevin O'Connor2017-03-031-5/+9
| | | | | | | | Store a full 64bit uptime in the mcu and query it at the start of each connection. This ensures the host's 64bit clock is always in synch with the mcu's clock. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Use the system monotonic clock instead of the normal system clockKevin O'Connor2017-02-061-8/+8
| | | | | | | | | | | | | The normal system clock can have sudden jumps if the system clock is changed. Use the system monotonic clock to avoid these sudden changes in time. It appears the Raspbian OS (which is used by OctoPi) is setup to update the system clock upon network connectivity. This could cause sudden system clock changes which could lead to Klippy processing errors. Using the monotonic clock eliminates these issues. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialqueue: Remove serialqueue_flush_ready()Kevin O'Connor2016-12-301-2/+0
| | | | | | | | | The serialqueue_flush_ready() code was used to flush queue_step commands during a homing operation. It's no longer necessary now that moves during a homing operation use the normal message priority system. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Log the MCU configuration during connect phaseKevin O'Connor2016-12-241-0/+2
| | | | | | | Log the constants reported by the MCU and log the number of move items allocated after configuration. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* build: Define DECL_CONSTANT mechanism for defining exported constantsKevin O'Connor2016-12-231-1/+1
| | | | | | | | | Add a DECL_CONSTANT macro to allow the firmware to define constants that are to be exported to the host during the "identify" phase. This replaces the existing hardcoded mechanism of scanning the Kconfig header file for certain constants. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Clear "hupcl" bit from serial portKevin O'Connor2016-12-091-1/+2
| | | | | | | | The arduino style serial port interfaces can reset the MCU when the serial port is opened. Clearing the HUPCL flag makes this less likely. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Detect if the communication channel to the firmware is lostKevin O'Connor2016-11-301-1/+1
| | | | | | Detect a comms loss and report it to the user. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Be careful to free memory allocated in C codeKevin O'Connor2016-11-301-3/+4
| | | | | | Free steppersync, stepcompress, and commandqueue objects. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Retry opening of serial portKevin O'Connor2016-11-291-10/+27
| | | | | | | Continually retry to open the serial port. This helps with connecting to some micro-controllers. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Fully deallocate serialqueue on disconnectKevin O'Connor2016-11-291-2/+5
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Make SerialReader.send_with_response() blockingKevin O'Connor2016-11-291-10/+17
| | | | | | | Use the greenlet mechanism to wait for the response directly in the send_with_response() method. This simplifies the calling code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Make SerialReader.connect() blockingKevin O'Connor2016-11-291-27/+26
| | | | | | | Use the greenlet mechanism to wait for the connection to come up in the serial connect() method. This simplifies the calling code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Run the MCU connect code within the reactorKevin O'Connor2016-11-291-4/+4
| | | | | | | | Setup the reactor and run the MCU connection code as a timer within the reactor. The connection code will make use of reactor greenlets so that it can wait for events during the connection phase. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Calculate baudadjust from MCU's baud instead of host baudKevin O'Connor2016-07-161-8/+8
| | | | | | | Store the baud rate the MCU is configured for in the "identify" data and use that rate when calculating the baudadjust parameter. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Avoid using 1200 baud during serial resetKevin O'Connor2016-06-141-1/+1
| | | | | | | The Arduino Due uses a 1200 baud connection to signal an erase sequence, so avoid it during normal serial resets. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* Initial commit of source code.Kevin O'Connor2016-05-251-0/+286
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>