Compare commits
No commits in common. "nodejs" and "observer-timers" have entirely different histories.
nodejs
...
observer-t
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +0,0 @@
|
||||||
node_modules
|
|
123
accx.js
123
accx.js
|
@ -1,123 +0,0 @@
|
||||||
class ACCX {
|
|
||||||
static parse() {
|
|
||||||
switch (line) {
|
|
||||||
case /(\d*) unlocked$/: // ends line
|
|
||||||
console.log(">Door #{$1} unlocked\n");
|
|
||||||
@events[:unlocked].send($1);
|
|
||||||
case /All Doors relocked/:
|
|
||||||
console.log(">All Doors relocked\n");
|
|
||||||
case /Door (\d*) locked$/: // ends line
|
|
||||||
console.log(">Door #{$1} locked\n");
|
|
||||||
case /User ([\dA-F]*) presented tag at reader (\d)/:
|
|
||||||
console.log(">User #{$1} presented tag at reader #{$2}\n");
|
|
||||||
case /User ([\dA-F]*) granted access at reader (\d)/:
|
|
||||||
console.log(">User #{$1} granted access at reader #{$2}\n");
|
|
||||||
case /User ([\dA-F]*) denied access at reader (\d)/:
|
|
||||||
console.log(">User #{$1} denied access at reader #{$2}\n");
|
|
||||||
case /Command ([\dA-F]*) entered at reader (\d)/:
|
|
||||||
console.log(">Command #{$1} entered at reader #{$2}\n");
|
|
||||||
case /Zone (\d?) sensor activated/:
|
|
||||||
console.log(">Zone #{$1} sensor activated\n");
|
|
||||||
case /User (\d?) unlocked door (\d)/:
|
|
||||||
console.log(">User #{$1} unlocked door #{$2}\n");
|
|
||||||
case /Door 1 locked for (\d+) bed time/:
|
|
||||||
console.log("Door 1 locked for #{$1} bed time\n");
|
|
||||||
case /User (\d+) locked out/:
|
|
||||||
console.log("User #{$1} locked out\n");
|
|
||||||
case /User (\d+) locked out/:
|
|
||||||
console.log("User #{$1} locked out\n");
|
|
||||||
case /Sensor (\d+) value:(\d+)/:
|
|
||||||
console.log("Sensor #{$1} value:#{$2}\n");
|
|
||||||
case /Alarm triggered/:
|
|
||||||
console.log("Alarm triggered\n");
|
|
||||||
case /Alarm level changed to (\d*)/:
|
|
||||||
console.log(">Alarm level changed to #{$1}\n");
|
|
||||||
case /Alarm armed level changed to (\d*)/:
|
|
||||||
console.log(">Alarm armed level changed to #{$1}\n");
|
|
||||||
case /User database erased/:
|
|
||||||
console.log("User database erased\n");
|
|
||||||
case /Invalid user modify attempted/:
|
|
||||||
console.log("Invalid user modify attempted\n");
|
|
||||||
case /User (\d*) successfully modified/:
|
|
||||||
console.log(">User #{$1} successfully modified\n");
|
|
||||||
case /Invalid user delete attempted/:
|
|
||||||
console.log("Invalid user delete attempted\n");
|
|
||||||
case /User deleted at position (\d*)/:
|
|
||||||
console.log("User deleted at position #{$1}\n");
|
|
||||||
case /User deleted at position (\d*)/:
|
|
||||||
console.log(">User deleted at position #{$1}\n");
|
|
||||||
case /User (\d+) authenticated/:
|
|
||||||
console.log("User #{$1} authenticated\n");
|
|
||||||
case /User not found/:
|
|
||||||
console.log("User not found\n");
|
|
||||||
case /Bad user number/:
|
|
||||||
console.log("Bad user number\n");
|
|
||||||
case /User dump started/:
|
|
||||||
console.log(">User dump started\n");
|
|
||||||
case /Invalid door number/:
|
|
||||||
console.log("Invalid door number\n");
|
|
||||||
case /Alarm armed state \(1=armed\):(\d*)/:
|
|
||||||
console.log(">Alarm armed state: #{$1}\n");
|
|
||||||
case /Alarm siren state \(1=activated\):(\d*)/:
|
|
||||||
console.log(">Alarm siren state: #{$1}\n");
|
|
||||||
case /Front door open state \(0=closed\):(\d*)/:
|
|
||||||
console.log(">Front door open state: #{$1}\n");
|
|
||||||
case /Roll up door open state \(0=closed\):(\d*)/:
|
|
||||||
console.log(">Roll up door open state: #{$1}\n");
|
|
||||||
case /Door 1 unlocked state\(1=locked\):(\d*)/:
|
|
||||||
console.log(">Door 1 unlocked state: #{$1}\n");
|
|
||||||
case /Door 2 unlocked state\(1=locked\):(\d*)/:
|
|
||||||
console.log(">Door 2 unlocked state: #{$1}\n");
|
|
||||||
case /^(\d+)\t+(\d+)\t+([\dA-Fa-f]+)$/:
|
|
||||||
console.log(">User #{$1} mask #{$2} tag #{$3}\n"); // User dump info
|
|
||||||
case /Priveleged mode enabled./:
|
|
||||||
console.log(">Priveleged mode enabled.\n");
|
|
||||||
case /Priveleged mode disabled./:
|
|
||||||
console.log(">Priveleged mode disabled.\n");
|
|
||||||
case /Access Denied. Priveleged mode is not enabled./:
|
|
||||||
console.log(">Access Denied. Priveleged mode is not enabled.\n");
|
|
||||||
case /Valid commands are/:
|
|
||||||
console.log("?Valid commands are\n"); // Help output
|
|
||||||
case /^\(/:
|
|
||||||
console.log("?"+sline+"\n"); // Help output
|
|
||||||
case /^ <day 0..31> <mon 0..12> <year 0.99>/:
|
|
||||||
console.log("?"+sline+"\n"); // Help output
|
|
||||||
case /^[\d:]{5,8}\s+[\d\/]{5,8}\s+[A-Z]{3}\s+$/:
|
|
||||||
console.log(">"+sline+"\n"); // Date output only
|
|
||||||
case /^Old time :([\d:]{5,8})\s+([\d\/]{5,8})\s+([A-Z]{3})\s+$/:
|
|
||||||
console.log(">Old time: #{$1} #{$2} #{$3}\n");
|
|
||||||
case /^New time :([\d:]{5,8})\s+([\d\/]{5,8})\s+([A-Z]{3})\s+$/:
|
|
||||||
console.log(">New time: #{$1} #{$2} #{$3}\n");
|
|
||||||
case /Reader1-0:(\d*)/:
|
|
||||||
console.log(">Reader1-0:#{$1}\n"); // Status output
|
|
||||||
case /Reader1-1:(\d*)/:
|
|
||||||
console.log(">Reader1-1:#{$1}\n"); // Status output
|
|
||||||
case /Reader2-0:(\d*)/:
|
|
||||||
console.log(">Reader2-0:#{$1}\n"); // Status output
|
|
||||||
case /Reader2-1:(\d*)/:
|
|
||||||
console.log(">Reader2-1:#{$1}\n"); // Status output
|
|
||||||
case /Zone 1:(\d*)/:
|
|
||||||
console.log(">Zone 1:#{$1}\n"); // Status output
|
|
||||||
case /Zone 2:(\d*)/:
|
|
||||||
console.log(">Zone 2:#{$1}\n"); // Status output
|
|
||||||
case /Zone 3:(\d*)/:
|
|
||||||
console.log(">Zone 3:#{$1}\n"); // Status output
|
|
||||||
case /Zone 4:(\d*)/:
|
|
||||||
console.log(">Zone 4:#{$1}\n"); // Status output
|
|
||||||
case /Zone TAMP:(\d*)/:
|
|
||||||
console.log(">Zone TAMP:#{$1}\n"); // Status output
|
|
||||||
case /Relays and LEDs ([a-z]*)/:
|
|
||||||
console.log(">Relays and LEDs #{$1}\n"); // Status output
|
|
||||||
case /Relays and LEDs ([a-z]*)/:
|
|
||||||
console.log(">Relays and LEDs #{$1}\n"); // Status output
|
|
||||||
case /UserNum: Usermask: TagNum:/:
|
|
||||||
// nothing, we don't care
|
|
||||||
case /Pass: /:
|
|
||||||
// nothing, we don't care
|
|
||||||
case /^\d+$/:
|
|
||||||
// nothing, we don't care
|
|
||||||
else
|
|
||||||
console.log("ERR: UNKNOWN: "+sline.inspect+"\n"); // Error output
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
47
index.html
47
index.html
|
@ -1,47 +0,0 @@
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<script src="/socket.io/socket.io.js"></script>
|
|
||||||
<script>
|
|
||||||
var socket = io();
|
|
||||||
// console.log("loaded socketio");
|
|
||||||
|
|
||||||
// connect to socketio
|
|
||||||
socket.on('connect', function(){
|
|
||||||
// send connect message
|
|
||||||
socket.send('hi '+window.location);
|
|
||||||
});
|
|
||||||
window.onload = function(){
|
|
||||||
cons = document.getElementById("console");
|
|
||||||
// handle user input
|
|
||||||
cons.onsubmit = function(){
|
|
||||||
inp = document.getElementById("input")
|
|
||||||
scr = document.getElementById("screen")
|
|
||||||
// send input to socketio
|
|
||||||
socket.emit('data',inp.value);
|
|
||||||
// console.log(inp.value);
|
|
||||||
scr.value += "> "+inp.value+"\r";
|
|
||||||
scr.scrollTop = scr.scrollHeight;
|
|
||||||
inp.value = "";
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
scr = document.getElementById("screen")
|
|
||||||
scr.value = ""; // reset input onload
|
|
||||||
// log data from socket
|
|
||||||
socket.on('data', function(data){
|
|
||||||
// console.log(data);
|
|
||||||
scr.value += "< "+data+"\r";
|
|
||||||
scr.scrollTop = scr.scrollHeight;
|
|
||||||
});
|
|
||||||
// log connect messages
|
|
||||||
socket.on('message', function(data){
|
|
||||||
console.log('message',window.location,data);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
<form id="console">
|
|
||||||
<textarea cols=80 rows=20 id="screen"></textarea><br/>
|
|
||||||
<input id="input" type="text" />
|
|
||||||
<input id="submit" type="button" value="Submit" />
|
|
||||||
</form>
|
|
||||||
</html>
|
|
11
package.json
11
package.json
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
"name": "Open_Access_Control_API",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"main": "serial.js",
|
|
||||||
"dependencies": {
|
|
||||||
"serialport": "*",
|
|
||||||
"express": "*",
|
|
||||||
"http": "*",
|
|
||||||
"socket.io": "*"
|
|
||||||
}
|
|
||||||
}
|
|
44
serial.js
44
serial.js
|
@ -1,44 +0,0 @@
|
||||||
const SerialPort = require('serialport');
|
|
||||||
const Readline = require('@serialport/parser-readline');
|
|
||||||
|
|
||||||
var express = require('express'),
|
|
||||||
app = express(),
|
|
||||||
http = require('http'),
|
|
||||||
server = http.createServer(app),
|
|
||||||
io = require('socket.io').listen(server),
|
|
||||||
scores = {};
|
|
||||||
|
|
||||||
// listen for new web clients:
|
|
||||||
server.listen(8080);
|
|
||||||
|
|
||||||
// open the serial port. Change the name to the name of your port, just like in Processing and Arduino:
|
|
||||||
const port = new SerialPort("/dev/ttyUSB0", { baudRate: 9600 });
|
|
||||||
|
|
||||||
const parser = new Readline({ delimiter: '\r\n' });
|
|
||||||
port.pipe(parser)
|
|
||||||
|
|
||||||
// respond to web GET requests with the index.html page:
|
|
||||||
app.get('/', function (req, res) {
|
|
||||||
res.sendFile(__dirname + '/index.html');
|
|
||||||
});
|
|
||||||
|
|
||||||
// listen for new serial data:
|
|
||||||
parser.on('data', line => console.log(`> ${line}`))
|
|
||||||
|
|
||||||
// listen for new socket.io connections:
|
|
||||||
io.on('connection', function (socket) {
|
|
||||||
// get data from serial and send it to socket
|
|
||||||
parser.on('data', line => {
|
|
||||||
socket.emit('data', line)
|
|
||||||
});
|
|
||||||
// get data from socket and send it to serial
|
|
||||||
socket.on('data', function (data) {
|
|
||||||
console.log('data', socket.conn.remoteAddress, data)
|
|
||||||
port.write(data+"\r") // we need to end each command with a CR
|
|
||||||
});
|
|
||||||
// send and log connect messages
|
|
||||||
socket.volatile.emit('message', "hi "+socket.conn.remoteAddress);
|
|
||||||
socket.on('message', function (data) {
|
|
||||||
console.log('message',socket.conn.remoteAddress,data)
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Reference in New Issue
Block a user