fix some bugss

Took 23 minutes
This commit is contained in:
Tobias Hopp 2023-02-13 12:24:08 +01:00
parent 37c208af7c
commit 71d2590f7b
3 changed files with 48 additions and 34 deletions

View File

@ -12,23 +12,6 @@ export class ArduinoProxy {
private static callbacks: Record<string, { resolve: Function, reject: Function }> = {}; private static callbacks: Record<string, { resolve: Function, reject: Function }> = {};
private static encoding: string = "utf-8"; private static encoding: string = "utf-8";
private static onData(data) {
data = data.toString().trim();
try {
console.debug("Received ", data);
let json = JSON.parse(data) as ArduinoProxyPayload;
if (this.callbacks[json.id]) {
this.callbacks[json.id].resolve(json);
delete this.callbacks[json.id];
log("Answered request " + json.id);
} else {
log("ERROR - Got an response from arduino but we are not waiting for it?");
}
} catch (e) {
log("ERROR - Got an invalid response from arduino?");
}
}
public static connect() { public static connect() {
return new Promise<void>(async (resolve, reject) => { return new Promise<void>(async (resolve, reject) => {
log("Connecting to arduino..."); log("Connecting to arduino...");
@ -78,7 +61,16 @@ export class ArduinoProxy {
} }
public static sendRequest(request: ArduinoProxyPayload, timeout: number = 1000) { public static sendRequest(request: ArduinoProxyPayload, timeout: number = 1000) {
return new Promise<ArduinoProxyPayload>((resolve, reject) => { return new Promise<ArduinoProxyPayload>(async (resolve, reject) => {
// Pre Check if connection lost
if (!this.serialPort.isOpen)
try {
await this.connect();
} catch (e) {
}
let id = Utils.generateRandomString(8); let id = Utils.generateRandomString(8);
request.id = id; request.id = id;
@ -103,4 +95,21 @@ export class ArduinoProxy {
}); });
} }
private static onData(data) {
data = data.toString().trim();
try {
console.debug("Received ", data);
let json = JSON.parse(data) as ArduinoProxyPayload;
if (this.callbacks[json.id]) {
this.callbacks[json.id].resolve(json);
delete this.callbacks[json.id];
log("Answered request " + json.id);
} else {
log("ERROR - Got an response from arduino but we are not waiting for it?");
}
} catch (e) {
log("ERROR - Got an invalid response from arduino?");
}
}
} }

View File

@ -10,6 +10,7 @@ import debug from "debug";
import {ArduinoProxyPayload} from "./ArduinoProxyPayload"; import {ArduinoProxyPayload} from "./ArduinoProxyPayload";
import {ArduinoProxyPayloadType} from "./ArduinoProxyPayloadType"; import {ArduinoProxyPayloadType} from "./ArduinoProxyPayloadType";
import {ContainerHelper} from "./ContainerHelper"; import {ContainerHelper} from "./ContainerHelper";
import {ErrorHandler, InternalError} from "./ErrorHandler";
const isPI = require("detect-rpi"); const isPI = require("detect-rpi");
@ -75,9 +76,9 @@ export class Mixer {
console.debug(e); console.debug(e);
if (isPI()) { if (isPI()) {
log("[ERROR] GPIO I/O Error " + e); log("[ERROR] GPIO I/O Error " + e);
// Todo error handling to user
await this.cancelFill(); await this.cancelFill();
let error = new InternalError(e + "", "Mixer.ts catch on startFill", "GPIO Exception");
await ErrorHandler.sendError(error);
return; return;
} else { } else {
log("[WARNING] GPIO I/O Error, but it's normal cause you are not on raspberry"); log("[WARNING] GPIO I/O Error, but it's normal cause you are not on raspberry");
@ -109,6 +110,8 @@ export class Mixer {
if (isPI()) { if (isPI()) {
log("[ERROR] GPIO I/O Error " + e); log("[ERROR] GPIO I/O Error " + e);
await this.cancelFill(); await this.cancelFill();
let error = new InternalError(e + "", "Mixer.ts catch on stopFill", "GPIO Exception");
await ErrorHandler.sendError(error);
return; return;
} else { } else {
log("[WARNING] GPIO I/O Error, but it's normal cause you are not on raspberry"); log("[WARNING] GPIO I/O Error, but it's normal cause you are not on raspberry");
@ -181,7 +184,7 @@ export class Mixer {
} }
// ToDo v2 calc
let container: IContainer = jobIngredient.container; let container: IContainer = jobIngredient.container;
let deltaStartStop = (this._currentJob.endAt.getTime() - this._currentJob.startedAt.getTime()) / 1000; let deltaStartStop = (this._currentJob.endAt.getTime() - this._currentJob.startedAt.getTime()) / 1000;

View File

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
cd /home/itender/itender || exit -1 cd /home/itender/itender || exit -1
if [ -z "$1" ] if [ -z "$1" ]; then
then
git pull "https://tobiash:!IwedwrimmVeudiweN!@git.gaminggeneration.de/tobiash/itender.git" --quiet git pull "https://tobiash:!IwedwrimmVeudiweN!@git.gaminggeneration.de/tobiash/itender.git" --quiet
exit 1
./update.sh true ./update.sh true
else else
yarn yarn
@ -11,7 +11,9 @@ else
cd ./arduino/itender/ cd ./arduino/itender/
arduino-cli compile --fqbn arduino:avr:mega itender.ino || true arduino-cli compile --fqbn arduino:avr:mega itender.ino || true
sudo systemctl stop itender sudo systemctl stop itender
timeout 40 arduino-cli upload --port /dev/ttyACM0 --fqbn arduino:avr:mega itender.ino || true sleep 1
timeout 30 arduino-cli upload --port /dev/ttyACM0 --fqbn arduino:avr:mega itender.ino
sleep 1
sudo systemctl start itender sudo systemctl start itender
fi fi
exit 0 exit 0