Skip to content

Commit

Permalink
stop/start by sms - fix double request to remote controler
Browse files Browse the repository at this point in the history
  • Loading branch information
jrkf committed Apr 2, 2020
1 parent a761807 commit b4fd7ec
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
19 changes: 17 additions & 2 deletions src/app/shared/data-facade.service.js

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion src/app/shared/data-facade.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { SmsFacadeService } from '~/app/shared/sms-facade.service';
})
export class DataFacadeService {
btData: string;
bolhour: number;
int0: number;
stanPump: string = "W TRAKCIE...";
ww = /zakres\s(\d{1}):\s(.\W\d{3})\sJ\/WW\sstart\sgodz.\s(\d{2}:\d{2})/g;
Expand Down Expand Up @@ -416,8 +417,23 @@ export class DataFacadeService {
this.pumpBluetoothApiService.sendCommand("bolus " + r);
setTimeout( () => this.pumpBluetoothApiService.read6().subscribe(btdane => {
console.log("btdane: !!!!!!!!!!!!!" + btdane.toString() + "koniec!!!" + new Date().getDay().toString() + '-' + new Date().getMonth().toString() );
const d = new Date();
d.setMinutes(d.getMinutes() - 6);
const bolhours = btdane.toString().match(/(\d{2}:\d{2})/);
if (bolhours !== null && bolhours.length > 1) {
console.log("to jest [1] " + bolhours[1] + " a to zero: " + bolhours[0] + "A to po zrzutowaniu do numbera: " + Number(bolhours[1].replace(':', '')));
this.bolhour = Number(bolhours[1].replace(':', ''));
console.log("Takie cos wyszlo: " + Number(('0' + d.getHours()).slice(-2) + ('0' + d.getMinutes()).slice(-2)));
console.log("btdane1: !!!!!!!!!!!!! " + this.bolhour + Number(('0' + d.getHours()).slice(-2) + ('0' + d.getMinutes()).slice(-2)) + " koniec!!!" + new Date().getDate().toString() + '-' + ('0' + (Number(new Date().getMonth()) + 1).toString()).slice(-2).toString());
}
else {
this.bolhour = 9999;
console.log("Takie cos wyszlo: " + Number(('0' + d.getHours()).slice(-2) + ('0' + d.getMinutes()).slice(-2)));
console.log("btdane2 : !!!!!!!!!!!!! " + this.bolhour + Number(('0' + d.getHours()).slice(-2) + ('0' + d.getMinutes()).slice(-2)) + " koniec!!!" + new Date().getDate().toString() + '-' + ('0' + (Number(new Date().getMonth()) + 1).toString()).slice(-2).toString());
}
//console.log(" godzina: " + ('0' + d.getHours()).slice(-2) + ":" + ('0' + d.getMinutes()).slice(-2) + " Taki bolus zostal nastawiony: " + r + 'z taka data: ' + new Date().getDate().toString() + '-' + ('0' + (Number(new Date().getMonth()) + 1 ).toString()).slice(-2).toString());
if ((btdane.includes("pompa podaje") && btdane.includes("BL: " + r.toString() + "J")) ||
(btdane.includes("pompa nie podaje") && btdane.includes("BL: " + r.toString() + "J") && btdane.includes(new Date().getDate().toString() + '-' + ('0' + (Number(new Date().getMonth()) + 1).toString()).slice(-2).toString()))){
(btdane.includes("pompa nie podaje") && btdane.includes("BL: " + r.toString() + "J") && btdane.includes(new Date().getDate().toString() + '-' + ('0' + (Number(new Date().getMonth()) + 1).toString()).slice(-2).toString()) && this.bolhour > Number(('0' + d.getHours()).slice(-2) + ('0' + d.getMinutes()).slice(-2)))){
this.successLog(r.toString());
clearTimeout(timeoutAlert);
}
Expand Down
16 changes: 2 additions & 14 deletions src/app/shared/sms-facade.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ export class SmsFacadeService {

scanAndConnectStop(arg){
return new Promise((resolve, reject) => {
this.setBtConnection()
.then(
() => {
const timeoutAlert = setTimeout(() => this.errorPumpStan(), 68 * 1000);
this.pumpBluetoothApiService.read().subscribe(() => {
this.pumpBluetoothApiService.sendCommand2("a");
setTimeout(() => this.pumpBluetoothApiService.read3()
.subscribe( dane => {
Expand Down Expand Up @@ -93,14 +89,6 @@ export class SmsFacadeService {
}
}, () => this.errorPumpStan())
, 400);
}, () => this.errorPumpStan());
},
() => {
console.log("zatem nie czekam na ready");
this.errorPumpStan();
reject();
}
)
})
}
scanAndConnectBOL(r) {
Expand All @@ -110,13 +98,13 @@ export class SmsFacadeService {
this.pumpBluetoothApiService.sendCommand2("x");
setTimeout(() => this.pumpBluetoothApiService.read3()
.subscribe(dane => {
console.log("To jest wynik" + dane + "koniec danych");
console.log("To jest wynik: " + dane + "koniec danych");
if (dane.toString().includes("ustaw")){
const d = new Date();
d.setMinutes(d.getMinutes() - 6);
console.log(" godzina: " + ('0' + d.getHours()).slice(-2) + ":" + ('0' + d.getMinutes()).slice(-2) + " Taki bolus zostal nastawiony: " + r + 'z taka data: ' + new Date().getDate().toString() + '-' + ('0' + (Number(new Date().getMonth()) + 1 ).toString()).slice(-2).toString());
this.pumpBluetoothApiService.sendCommand("bolus " + r);
setTimeout( () => this.pumpBluetoothApiService.read6().subscribe(btdane => {
setTimeout(() => this.pumpBluetoothApiService.read6().subscribe(btdane => {
const bolhours = btdane.toString().match(/(\d{2}:\d{2})/);
if (bolhours !== null && bolhours.length > 1) {
console.log("to jest [1] " + bolhours[1] + " a to zero: " + bolhours[0] + "A to po zrzutowaniu do numbera: " + Number(bolhours[1].replace(':', '')));
Expand Down

0 comments on commit b4fd7ec

Please sign in to comment.