Commit 11c38220 by Пронин Евгений

initial commit

0 parents
node_modules
// подключение express
const express = require("express");
// создаем объект приложения
const app = express();
// определяем обработчик для маршрута "/"
var g_sign = "debug_sign";
//var g_card_sn = "04c6a56abf2282";
var g_card_sn = "04c6a56abf2211";
var g_terminal_id = -997616665;
var g_nocard = false;
//
//g_sign = "1571396701:b93dbf3232b7e85072f8a18dffc7043d";
//g_card_sn = "70eb011a";
//g_terminal_id = 271665294;
let state = {
devices: [
{
availableCards: [
makeCard(g_card_sn),
],
id: 31549,
model: "YHY632A-1004"
}
],
terminal_sn: g_terminal_id
};
function makeCard(card_sn) {
return {
id: card_sn,
type: "ULTRA_LIGHT",
sign: g_sign
};
}
function makeDevice(cards) {
return {
availableCards: cards,
id: 31549,
model: "YHY632A-1004"
}
}
app.get("/getRfid", (req, res) => {
var msg = JSON.stringify(state, null, '\t');
if (req.query.callback !== undefined) {
msg = req.query.callback + "(" + msg + ");";
return res.type('application/javascript').send(msg);
}
res.type('application/json').send(msg);
});
// положить карту
app.get("/", (req, res) => {
res.status(200).send(`<ul>
<li>
<a href="/getRfid">Get Rfid status</a>
</li>
<br>
<li>
<button onclick='doCmd("/ctl/put/04c6a56abf2211") '>Положить 1</button>
<button onclick='doCmd("/ctl/put/AABBCCDD") '> Положить 2</button>
<button onclick='doCmd("/ctl/put/BBAACCDD") '> Положить 3</button>
</li>
<br>
<li>
<button onclick='doCmd("/ctl/put") '> Положить </button>
<button onclick='doCmd("/ctl/take") '> Поднять </button>
</li>
<br>
<li>
<button onclick='doCmd("/ctl/connect")'>connect device</button>
<button onclick='doCmd("/ctl/disconnect")'>disconnect device</button>
</li>
</ul>
<textarea id="statustext" name="Text1" cols="40" rows="40" style="width:100%" ></textarea>
<script language="javascript">
async function doCmd(name) {
await fetch(name, { method: "POST" });
await updateStatus();
}
async function updateStatus() {
const response = await fetch("/getRfid")
const result = await response.json();
document.getElementById('statustext').value= JSON.stringify(result, null, ' ');
}
setInterval(updateStatus, 1000);
updateStatus();
</script>
`);
});
// положить карту
app.post("/ctl/put", (req, res) => {
state.devices = [makeDevice([makeCard(g_card_sn)])];
res.status(200).send("ok");
});
// положить карту
app.post("/ctl/put/:sn", (req, res) => {
g_card_sn= req.params.sn;
state.devices = [makeDevice([makeCard(g_card_sn)])];
res.status(200).send("ok");
});
// снять карту
app.post("/ctl/take", (req, res) => {
state.devices = [makeDevice([])];
res.status(200).send("ok");
});
app.post("/ctl/disconnect", (req, res) => {
state.devices = []
res.status(200).send("ok");
});
app.post("/ctl/connect", (req, res) => {
state.devices = makeDevice([]);
res.status(200).send("ok");
});
// начинаем прослушивать подключения на 3000 порту
app.listen(8888);
//setInterval( function() {
// g_nocard = !g_nocard;
// console.log("rfid change", g_nocard);
//}, 20000);
\ No newline at end of file \ No newline at end of file
{
"name": "daemon-rfid-fake",
"version": "0.0.2",
"private": true,
"scripts": {
"start": "node ./app",
"dev": "nodemon ./app"
},
"dependencies": {
"express": "~4.16.4"
},
"devDependencies": {
"nodemon": "^2.0.1"
}
}
#!/bin/sh
#export DISPLAY=:0.0
#xhost +
cd `dirname $0`
./stop.sh
echo $( date +"%m/%d/%Y %H:%M:%S $HOSTNAME")"run" >> log_run.txt
./run_daemon_rfid_fake.sh &
disown -h
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export DISPLAY=:0.0
cd $(dirname "$0")
while [ 1 ] ;
do
npm start >> log_std.txt 2>&1
echo "Restart at " $( date +"%m/%d/%Y %H:%M:%S $HOSTNAME") >> log_restart.txt
sleep 10
done
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export DISPLAY=:0.0
cd $(dirname "$0")
echo "stop" >> log_run.txt
killall -9 -g run_daemon_rfid_fake.sh
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!