Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Bagas Udi Sahsangka committed Jan 21, 2021
1 parent 1043ffa commit 70031df
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Kernel extends HttpKernel
],

'api' => [
'throttle:1000,1',
// 'throttle:1000,1',
'bindings',
],
];
Expand Down
16 changes: 16 additions & 0 deletions gate_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ async def open_gate(websocket, path):
await websocket.send(json.dumps({"status": True, "message": "Berhasil menampilkan display"}))
except Exception as e:
await websocket.send(json.dumps({"status": False, "message": "Gagal menampilkan display " + str(e)}))

elif (cmd[:3] == 'rrt'):
cfg = cmd.split(';')
try:
ser = Serial(cfg[1], int(cfg[2]), timeout=1)
except Exception as e:
await websocket.send(json.dumps({"status": False, "message": "Display tidak ditemukan " + str(e)}))
continue

try:
ser.write(b'\xa6U\xa9')
ser.close()
await websocket.send(json.dumps({"status": True, "message": "Berhasil menampilkan display"}))
except Exception as e:
await websocket.send(json.dumps({"status": False, "message": "Gagal menampilkan display " + str(e)}))

else:
await websocket.send(json.dumps({"status": False, "message": "Perintah tidak dikenal"}))

Expand Down
10 changes: 8 additions & 2 deletions parking.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ def save_data(gate, data):

def running_text(s, text):
line = text.split('|')
s.sendall(b'\xa6DS915050' +
s.sendall(b'\xa6DSD915050' +
line[0].encode() + b'|15050' + line[1].encode() + b'\xa9')


def reset_running_text(s):
s.sendall(b'\xa6DSU\xa9')


def gate_in_thread(gate):
while True:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
Expand Down Expand Up @@ -212,7 +216,7 @@ def gate_in_thread(gate):
try:
s.sendall(b'\xa6MT00012\xa9')
running_text(
s, 'MASA BERLAKU KARTU HABIS DALAM|5 HARI')
s, 'MASA BERLAKU KARTU HABIS DALAM|1 HARI')
time.sleep(6)
except Exception as e:
logging.error(
Expand Down Expand Up @@ -359,6 +363,8 @@ def gate_in_thread(gate):
# break loop cek kendaraan, sambung ulang controller
break

reset_running_text(s)


def start_app():
gates = get_gates()
Expand Down
2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

82 changes: 76 additions & 6 deletions resources/js/pages/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ export default {
totalBayar() {
return Number(this.formModel.tarif) + Number(this.formModel.denda);
},
duration() {
if (!this.formModel.time_in || !this.formModel.time_out) {
return "00:00:00";
}
let time_in = moment(this.formModel.time_in);
let time_out = moment(this.formModel.time_out);
let day = time_out.diff(time_in, "days");
let hour = time_out.diff(time_in, "hours");
let minute = time_out.diff(time_in, "minutes");
let second = time_out.diff(time_in, "seconds");
return `${day}H ${String(hour % 24).padStart(2, "0")}:${String(
minute % 60
).padStart(2, "0")}:${String(second % 60).padStart(2, "0")}`;
},
...mapState(["gateOutList", "gateInList", "jenisKendaraanList"])
},
Expand Down Expand Up @@ -324,7 +340,9 @@ export default {
if (durasiMenit <= tarif.menit_pertama) {
this.formModel.tarif = tarifMenitPertama;
document.getElementById("submit-btn").focus();
this.runningText(`BAYAR:|Rp. ${this.totalBayar}`);
this.runningText(
`DUR: ${this.duration}|Rp. ${this.formatNumber(this.totalBayar)},-`
);
return;
}
Expand Down Expand Up @@ -427,7 +445,9 @@ export default {
if (this.formModel.nomor_barcode.toLowerCase() == "xxxxx") {
document.getElementById("time-in").focus();
} else {
this.runningText(`BAYAR:|Rp. ${this.totalBayar}`);
this.runningText(
`DUR: ${this.duration}|Rp. ${this.formatNumber(this.totalBayar)},-`
);
document.getElementById("submit-btn").focus();
}
},
Expand Down Expand Up @@ -574,6 +594,7 @@ export default {
},
resetForm() {
this.resetRunningText();
this.formModel.gate_in_id = null;
this.formModel.gate_out_id = null;
this.formModel.jenis_kendaraan = null;
Expand All @@ -594,9 +615,6 @@ export default {
console.log("ke plat nomor");
document.getElementById("plat-nomor").focus();
}
this.runningText("TERIMAKASIH|ATAS KUNJUNGAN ANDA");
setTimeout(this.runningText("MOHON TUNGGU|SIAPKAN UANG PAS"), 3000);
},
submit(ticket) {
Expand Down Expand Up @@ -676,6 +694,22 @@ export default {
});
},
formatNumber(v) {
try {
v += "";
var x = v.split(".");
var x1 = x[0];
var x2 = x.length > 1 ? "." + x[1] : "";
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, "$1" + "," + "$2");
}
return x1 + x2;
} catch (error) {
return 0;
}
},
openGate(gate_out_id) {
const pos = this.posList.find(p => p.id == this.formModel.pos_id);
const gate = this.gateOutList.find(g => g.id == gate_out_id);
Expand Down Expand Up @@ -713,7 +747,9 @@ export default {
runningText(text) {
const pos = this.posList.find(p => p.id == this.formModel.pos_id);
const gate = this.gateOutList.find(g => g.id == this.formModel.gate_out_id);
const gate = this.gateOutList.find(
g => g.id == this.formModel.gate_out_id
);
if (!gate.running_text_device || !gate.running_text_baudrate) {
return;
Expand Down Expand Up @@ -746,6 +782,40 @@ export default {
};
},
resetRunningText() {
const pos = this.posList.find(p => p.id == this.formModel.pos_id);
const gate = this.gateOutList.find(
g => g.id == this.formModel.gate_out_id
);
if (!gate.running_text_device || !gate.running_text_baudrate) {
return;
}
const ws = new WebSocket(`ws://${pos.ip_address}:5678/`);
ws.onerror = event => {
this.$message({
message: "KONEKSI KE RUNNING TEXT GAGAL",
type: "error"
});
};
ws.onopen = event => {
ws.send(
["rrt", gate.running_text_device, gate.running_text_baudrate].join(
";"
)
);
};
ws.onmessage = event => {
let data = JSON.parse(event.data);
console.log(data);
ws.close();
};
},
printLastTrx() {
axios
.post("/parkingTransaction/printLastTransaction", {
Expand Down

0 comments on commit 70031df

Please sign in to comment.