This commit is contained in:
2024-05-10 09:47:39 -04:00
parent 3b3c2bf206
commit b70e9ddb58
17 changed files with 296 additions and 0 deletions

131
Arduino-WDT/Arduino-WDT.ino Normal file
View File

@@ -0,0 +1,131 @@
const int statePin = 3; // Connect LattePanda's S3 pin to Arduino's D3
const int resetPin = 4; // Connect LattePanda's RST pin to Arduino's D4
const int D10 = 10;
const int D11 = 11;
const int D12 = 12;
bool watchdogActive = false;
unsigned long lastReceivedTime;
unsigned long currentTime;
bool lastLEDState = LOW;
unsigned long lastLEDTime;
unsigned long currentLEDTime;
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite (LED_BUILTIN, LOW);
lastLEDTime = millis ();
pinMode(statePin, INPUT); // Set as input to read the state pin's level
pinMode(resetPin, INPUT); // By default, the RST pin on LattePanda is 3.3V. Initialize Arduino pin as INPUT to match this level.
pinMode(D10, OUTPUT);
pinMode(D11, OUTPUT);
pinMode(D12, OUTPUT);
Serial.begin(9600);
}
void loop()
{
//-- Check to see if it's time to change the LED state.
currentLEDTime = millis ();
if (currentLEDTime > lastLEDTime) //-- Check for millis overflow
{
if (currentLEDTime - lastLEDTime > 1000U)
{
if (lastLEDState == LOW)
{
digitalWrite (LED_BUILTIN, HIGH);
lastLEDState = HIGH;
}
else
{
digitalWrite (LED_BUILTIN, LOW);
lastLEDState = LOW;
}
lastLEDTime = millis ();
}
}
else
lastLEDTime = currentLEDTime;
// Check if the watchdog should be activated
if (digitalRead (statePin) == HIGH)
{
if (Serial.available () > 0)
{
char receivedChar = Serial.read ();
if (receivedChar == 'A')
{
watchdogActive = true;
lastReceivedTime = millis();
}
else if (receivedChar == 'Q')
{
watchdogActive = false;
}
else if (receivedChar == '0')
{
digitalWrite (D10, LOW);
digitalWrite (D11, LOW);
digitalWrite (D12, LOW);
}
else if (receivedChar == '1')
{
digitalWrite (D10, LOW);
digitalWrite (D11, LOW);
digitalWrite (D12, LOW);
digitalWrite (D10, HIGH);
}
else if (receivedChar == '2')
{
digitalWrite (D10, LOW);
digitalWrite (D11, LOW);
digitalWrite (D12, LOW);
digitalWrite (D11, HIGH);
}
else if (receivedChar == '3')
{
digitalWrite (D10, LOW);
digitalWrite (D11, LOW);
digitalWrite (D12, LOW);
digitalWrite (D10, HIGH);
digitalWrite (D11, HIGH);
}
else if (receivedChar == '4')
{
digitalWrite (D10, LOW);
digitalWrite (D11, LOW);
digitalWrite (D12, LOW);
digitalWrite (D12, HIGH);
}
}
}
else
{
watchdogActive = false;
}
// If watchdog is active and 's' character isn't received within 1 minute, reboot LattePanda board
currentTime = millis ();
if (currentTime > lastReceivedTime) //-- Check for millis overflow and wait for the next cycle if it has
{
if (watchdogActive && (currentTime - lastReceivedTime > 60000U))
{
pinMode(resetPin,OUTPUT); // Set pin to OUTPUT mode
digitalWrite(resetPin, LOW); // Pull down the RST pin to reboot the LattePanda board
delay(50); // Maintain a LOW level for 50ms
pinMode(resetPin, INPUT); // Set pin back to INPUT mode to match default 3.3V level of LattePanda's RST pin
watchdogActive = false; // Stop the watchdog function after rebooting the LattePanda board
}
}
}

BIN
Desktop/QuitWDT.lnk Normal file

Binary file not shown.

BIN
Desktop/Reboot.lnk Normal file

Binary file not shown.

BIN
Desktop/TestWDT.lnk Normal file

Binary file not shown.

5
EMSAStartup.py Normal file
View File

@@ -0,0 +1,5 @@
import os
import time
time.sleep(30)
os.system('"C:\\Program Files\\Erisys\\EMSADiagnosticSoftware\\EMSADiagnosticSoftware.exe"')

108
Feed-WDT.py Normal file
View File

@@ -0,0 +1,108 @@
import serial
import serial.tools.list_ports
import socket
import sys
import time
import traceback
from threading import Timer
class RepeatedTimer(object):
def __init__(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()
def _run(self):
self.is_running = False
self.start()
self.function(*self.args, **self.kwargs)
def start(self):
if not self.is_running:
self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True
def stop(self):
self._timer.cancel()
self.is_running = False
def feedWDT (s):
sendSerChar (s, b'A')
def sendSerChar (s, c):
print ('Sending ' + str (c))
s.write(c)
def find_arduino_leonardo():
# Scan for available COM ports
ports = serial.tools.list_ports.comports()
for port in ports:
# Check if "LattePanda Leonardo" is in the description of any found port
if "LattePanda Leonardo" in port.description:
return port.device
return None
def main():
try:
# Locate the Arduino Leonardo on the LattePanda board
device = find_arduino_leonardo()
# Exit if the device is not found
if device is None:
print("LattePanda Leonardo device not found. Please check if the device is connected and drivers are installed.")
input("Press any key to exit...")
sys.exit(1)
# Open a Serial connection to the Arduino Leonardo
ser = serial.Serial(device, 9600)
# Start a repeating timer to feed the watchdog
rt = RepeatedTimer (30, feedWDT, ser) # it auto-starts, no need of rt.start()
# Setup a listening socket
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
s.bind (('localhost', 9999))
s.listen (5)
print ('Server is listening')
while True:
print ('Waiting for connection...')
c, addr = s.accept ()
print ('Got connection from', addr)
data = c.recv (1).decode ('utf-8')
if not data:
continue
print ('From online user: ' + data)
if (data == 'T'):
break
b = bytes (data, 'utf-8')
sendSerChar (ser, b)
c.close()
if (data == 'Q'):
break
RepeatedTimer.stop (rt)
except Exception as e:
# Handle exceptions and print the error message
print("An error occurred:")
print(str(e))
print(traceback.format_exc())
input("Press any key to exit...")
if __name__ == "__main__":
main()

6
QuitWDT.py Normal file
View File

@@ -0,0 +1,6 @@
import socket
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
s.connect (('localhost', 9999))
s.send (b'Q')
s.close

BIN
Startup/00-Feed-WDT.lnk Normal file

Binary file not shown.

BIN
Startup/01-SignalVu-PC.lnk Normal file

Binary file not shown.

BIN
Startup/02-EMSAStartup.lnk Normal file

Binary file not shown.

6
TestWDT.py Normal file
View File

@@ -0,0 +1,6 @@
import socket
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
s.connect (('localhost', 9999))
s.send (b'T')
s.close

6
port0.py Normal file
View File

@@ -0,0 +1,6 @@
import socket
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
s.connect (('localhost', 9999))
s.send (b'0')
s.close

6
port1.py Normal file
View File

@@ -0,0 +1,6 @@
import socket
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
s.connect (('localhost', 9999))
s.send (b'1')
s.close

6
port2.py Normal file
View File

@@ -0,0 +1,6 @@
import socket
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
s.connect (('localhost', 9999))
s.send (b'2')
s.close

6
port3.py Normal file
View File

@@ -0,0 +1,6 @@
import socket
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
s.connect (('localhost', 9999))
s.send (b'3')
s.close

6
port4.py Normal file
View File

@@ -0,0 +1,6 @@
import socket
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
s.connect (('localhost', 9999))
s.send (b'4')
s.close

10
reboot.py Normal file
View File

@@ -0,0 +1,10 @@
import socket
import os
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
s.connect (('localhost', 9999))
s.send (b'Q')
s.close
print("REBOOTING")
os.system("shutdown -t 0 -r -f")