-
Notifications
You must be signed in to change notification settings - Fork 2
/
routes.js
69 lines (63 loc) · 2.01 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright (c) 2017, Mathias Küsel
* MIT License <https://github.com/mathiask88/node-snap7-testsuite/blob/master/LICENSE>
*/
/**
* Module dependencies.
*/
var m_snap7 = require('node-snap7');
var m_os = require('os');
/**
* Routes
*/
module.exports.index = function(req, res) {
res.render('index', {
title: "nodeSnap7",
'CONNTYPE_PG': m_snap7.S7Client.prototype.CONNTYPE_PG,
'CONNTYPE_OP': m_snap7.S7Client.prototype.CONNTYPE_OP,
'CONNTYPE_BASIC': m_snap7.S7Client.prototype.CONNTYPE_BASIC
});
}
module.exports.systemInfo = function(req, res) {
res.render('systemInfo');
}
module.exports.dataRW = function(req, res) {
res.render('dataRW', {
'S7WLBit': m_snap7.S7Client.prototype.S7WLBit,
'S7WLByte': m_snap7.S7Client.prototype.S7WLByte,
'S7WLWord': m_snap7.S7Client.prototype.S7WLWord,
'S7WLDWord': m_snap7.S7Client.prototype.S7WLDWord,
'S7WLReal': m_snap7.S7Client.prototype.S7WLReal,
'S7WLCounter': m_snap7.S7Client.prototype.S7WLCounter,
'S7WLTimer': m_snap7.S7Client.prototype.S7WLTimer,
'S7AreaDB': m_snap7.S7Client.prototype.S7AreaDB,
'S7AreaPE': m_snap7.S7Client.prototype.S7AreaPE,
'S7AreaPA': m_snap7.S7Client.prototype.S7AreaPA,
'S7AreaMK': m_snap7.S7Client.prototype.S7AreaMK,
'S7AreaTM': m_snap7.S7Client.prototype.S7AreaTM,
'S7AreaCT': m_snap7.S7Client.prototype.S7AreaCT
});
}
module.exports.scanDevices = function(req, res) {
var interfaces = m_os.networkInterfaces();
var addresses = [];
for (var k in interfaces) {
for (var k2 in interfaces[k]) {
var address = interfaces[k][k2];
if (address.family == 'IPv4' && !address.internal) {
addresses.push(address.address);
}
}
}
var startAddresses = addresses.map(function(ip) {
ip = ip.split('.');
ip[3] = '1';
return ip.join('.');
});
var endAddresses = addresses.map(function(ip) {
ip = ip.split('.');
ip[3] = '255';
return ip.join('.');
});
res.render('scanDevices', { startIPv4: startAddresses, endIPv4: endAddresses });
}