summaryrefslogtreecommitdiff
path: root/scripts/reset.py
blob: 8c07a66a57d5e331ef675b6cdd9d118db45d0b4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Author: Dylan Muller
# Copyright (c) 2025 
# All rights reserved.
# 
# - Commercial/IP use prohibited.
# - Attribution required.
# See License.txt

import serial
import socket
import time
import math
import sys
import os

from setup import *

RESET_DELAY = 2
EXIT_ERROR = 1

def serial_send(serial, data):
    serial.write(data.encode('utf-8'))

def serial_receive_line(serial):
    serial_data = serial.readline().decode('utf-8').rstrip() 
    return serial_data

def sys_reset(serial):
    serial_send(serial, SETUP_CMD_RESET)
    time.sleep(SETUP_CMD_TIMEOUT)
    response = serial_receive_line(serial)
    return response

sys_serial = serial.Serial(port=SETUP_SERIAL_PORT, baudrate=SETUP_SERIAL_BAUD, timeout=SETUP_SERIAL_TIMEOUT)

print("PRECOMPILE CONDITIONING")
print("EXEC SOFT RESET")
response = ""

try:
    response = sys_reset(sys_serial)
except:
    print("CRITICAL ERROR")

if ("RESET" in response):
    print("OK")
    time.sleep(RESET_DELAY)
    sys.exit(os.EX_OK)
else:
    sys.exit(EXIT_ERROR)