Skip to content

Commit d628079

Browse files
committed
updated all the schemas.
1 parent 69d5082 commit d628079

File tree

9 files changed

+92
-85
lines changed

9 files changed

+92
-85
lines changed

apple/ldap_auth.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
*
55
* Created by jbockerstette on 11/8/16.
66
*/
7-
8-
var rest = require("./rest.js");
7+
const rest = require("./rest.js");
98

109
/**
1110
* Convenience function to create http options for our ldap auth service running at http://localhost:8888.
@@ -16,8 +15,7 @@ var rest = require("./rest.js");
1615
* Form 2: auth="Bearer jwt.web.token" where jwt.web.token is a valid webtoken which was originally returned by
1716
* successfully doing a GET -H "authorization:Basic amJvY2tlcnN0ZXR0ZTpjaGFyZ2VyLg==" http://localhost:8888
1817
*/
19-
var getAuthOptions = function(auth)
20-
{
18+
const getAuthOptions = function (auth) {
2119
return {
2220
host: 'localhost',
2321
port: 8888,
@@ -40,11 +38,11 @@ var getAuthOptions = function(auth)
4038
* successfully doing a GET -H "authorization:Basic amJvY2tlcnN0ZXR0ZTpjaGFyZ2VyLg==" http://localhost:8888
4139
* @returns {*} the user name passed in the base64 encoded auth parameter.
4240
*/
43-
var getUser = function (auth) {
44-
var parts = auth.split(" ");
45-
if (parts[1]){
46-
var userColonPw = Buffer.from(parts[1], 'base64').toString("ascii");
47-
var userAndPw = userColonPw.split(":");
41+
const getUser = function (auth) {
42+
const parts = auth.split(" ");
43+
if (parts[1]) {
44+
const userColonPw = Buffer.from(parts[1], 'base64').toString("ascii");
45+
const userAndPw = userColonPw.split(":");
4846
if (userAndPw[1])
4947
return userAndPw[0];
5048
}
@@ -65,7 +63,7 @@ exports.authorize = function(auth, onResults)
6563
{
6664
console.log("authorize: " + auth);
6765

68-
var options = getAuthOptions(auth);
66+
const options = getAuthOptions(auth);
6967

7068
rest.getJSON(options, onResults);
7169
};

apple/resources/alarmHistory.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ jsonApi.define({
1515
attributes: {
1616
id: jsonApi.Joi.string().default(jsonApi.Joi.ref('_id')),
1717
_id: jsonApi.Joi.string(),
18+
tagname: jsonApi.Joi.string().trim()
19+
.description("The unique tag name.")
20+
.example("MY_AWESOME_TAGNAME"),
21+
deviceName: jsonApi.Joi.string().trim()
22+
.description("The unique device name.")
23+
.example("MY_AWESOME_DEVICE"),
1824
tagId: jsonApi.Joi.string().required()
1925
.description("The tag this history is for."),
2026
device_id: jsonApi.Joi.string().required()
@@ -31,21 +37,21 @@ jsonApi.define({
3137
setpoint: jsonApi.Joi.number().default(0)
3238
.description("The value that triggers the alarm.")
3339
.example("10"),
40+
timestamp: jsonApi.Joi.date().required() // also, for javascript timestamp (milliseconds)
41+
.description("The Unix time in milliseconds of the tag.")
42+
.example("1463672736248"),
43+
alarmStatus: jsonApi.Joi.string().optional()
44+
.description("Is the activeAlarm clear, acked, unacked.")
45+
.example("Clear, acked, unacked"),
3446
dataQuality: jsonApi.Joi.string().optional()
3547
.description("The data quality from the tag.")
3648
.example("Ok"),
37-
value: jsonApi.Joi.any().optional()
38-
.description("The current value from the tag in engineering units.")
39-
.example("24.5"),
4049
units: jsonApi.Joi.string().optional()
4150
.description("The tag units.")
4251
.example("Volts"),
43-
timestamp: jsonApi.Joi.date().required() // also, for javascript timestamp (milliseconds)
44-
.description("The Unix time in milliseconds of the tag.")
45-
.example("1463672736248"),
46-
alarmStatus: jsonApi.Joi.string().optional()
47-
.description("Is the activeAlarm clear, acked, unacked.")
48-
.example("Clear, acked, unacked")
52+
value: jsonApi.Joi.any().optional()
53+
.description("The current value from the tag in engineering units.")
54+
.example("24.5")
4955
},
5056
examples: [{}]
5157
});

apple/resources/alarms.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ jsonApi.define({
1616
attributes: {
1717
id: jsonApi.Joi.string().default(jsonApi.Joi.ref('_id')),
1818
_id: jsonApi.Joi.string(),
19+
tagname: jsonApi.Joi.string().required()
20+
.description("The tag this alarm is for."),
21+
deviceName: jsonApi.Joi.string().required()
22+
.description("The tag this alarm is for."),
1923
tagId: jsonApi.Joi.string().required()
2024
.description("The tag id this alarm is for."),
2125
device_id: jsonApi.Joi.string().required()
2226
.description("The device id this alarm is for."),
23-
tagname: jsonApi.Joi.string().required()
24-
.description("The tag this alarm is for."),
2527
alarmDefId: jsonApi.Joi.string().required()
2628
.description("The alarm def id this alarm came from."),
2729
desc: jsonApi.Joi.string().trim()
@@ -39,16 +41,16 @@ jsonApi.define({
3941
dataQuality: jsonApi.Joi.string().optional()
4042
.description("The data quality from the tag.")
4143
.example("Ok"),
44+
units: jsonApi.Joi.string().optional()
45+
.description("The tag units.")
46+
.example("Volts"),
4247
value: jsonApi.Joi.any().optional()
4348
.description("The current value from the tag in engineering units.")
4449
.example("24.5"),
4550
valueType: jsonApi.Joi.string().trim().regex(REGEX_VALUE_TYPE)
4651
.default('real')
4752
.description('Can only be bool, real, integer or string.')
4853
.example('bool'),
49-
units: jsonApi.Joi.string().optional()
50-
.description("The tag units.")
51-
.example("Volts"),
5254
lastUpdate: jsonApi.Joi.date().optional() // also, for javascript timestamp (milliseconds)
5355
.description("The Unix time in milliseconds of when the alarm was updated.")
5456
.example("1463672736248"),

apple/resources/devices.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,33 @@ jsonApi.define({
1616
attributes: {
1717
id: jsonApi.Joi.string().default(jsonApi.Joi.ref('_id')),
1818
_id: jsonApi.Joi.string(),
19+
status: jsonApi.Joi.string().optional()
20+
.description("Is the plc up or down or some other status.")
21+
.example("OK"),
22+
hostnameOrIP: jsonApi.Joi.string().trim().hostname().required()
23+
.description("The hostname or ip of this device.")
24+
.example("my.cool.plc"),
1925
name: jsonApi.Joi.string().trim().regex(REGEX_NAME_STRING)
2026
.description("Whatever you want to call this device.")
2127
.example("MY_COOL_AB_PLC"),
22-
cabinet: jsonApi.Joi.string().required()
23-
.description("The cabinet number (0-5).")
24-
.example("1"),
25-
rack: jsonApi.Joi.string().required()
26-
.description("The rack number (1-50).")
27-
.example("1"),
28+
macAddress: jsonApi.Joi.string().trim().uppercase().regex(REGEX_MAC_ADDRESS).optional()
29+
.description("PLC mac address.")
30+
.example("00:00:00:00:00:00"),
2831
driver: jsonApi.Joi.string().trim().default('modbus').regex(REGEX_DRIVER)
2932
.description("The type of driver used to talk to this device.")
3033
.example("modbus"),
3134
port: jsonApi.Joi.number().min(1).max(65535).integer().required()
3235
.description("The port that the device listens on.")
3336
.example("502"),
34-
hostnameOrIP: jsonApi.Joi.string().trim().hostname().required()
35-
.description("The hostname or ip of this device.")
36-
.example("my.cool.plc"),
37-
macAddress: jsonApi.Joi.string().trim().uppercase().regex(REGEX_MAC_ADDRESS).optional()
38-
.description("PLC mac address.")
39-
.example("00:00:00:00:00:00"),
4037
desc: jsonApi.Joi.string().required()
4138
.description("The description <Country>.<Location>.<Building>.<Floor>.<Room>.<Row>.<DP>.<PrimaryOrSec>")
4239
.example("US.MSC.01.01.0001.01.02.1"),
43-
status: jsonApi.Joi.string().optional()
44-
.description("Is the plc up or down or some other status.")
45-
.example("OK"),
40+
cabinet: jsonApi.Joi.string().required()
41+
.description("The cabinet number (0-5).")
42+
.example("1"),
43+
rack: jsonApi.Joi.string().required()
44+
.description("The rack number (1-50).")
45+
.example("1"),
4646
scanEnabled: jsonApi.Joi.boolean().default(true)
4747
.description("Should the driver try to connect and scan the plc.")
4848
.example("FALSE")

apple/resources/history.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ jsonApi.define({
1313
attributes: {
1414
id: jsonApi.Joi.string().default(jsonApi.Joi.ref('_id')),
1515
_id: jsonApi.Joi.string(),
16+
tagId: jsonApi.Joi.string().required()
17+
.description("The tag this history is for."),
1618
timestamp: jsonApi.Joi.date().required() // also, for javascript timestamp (milliseconds)
1719
.description("The Unix time in milliseconds of the tag.")
1820
.example("1463672736248"),
1921
value: jsonApi.Joi.number().required()
2022
.description("The current value at the timestamp time of the tag.")
2123
.example("1245.76"),
22-
input: jsonApi.Joi.number().required()
23-
.description("The input value to write at the timestamp time of the tag.")
24-
.example("1245.76"),
2524
dataQuality: jsonApi.Joi.string().required()
2625
.description("Can only be OK or Bad")
2726
.example("OK"),
28-
tagId: jsonApi.Joi.string().required()
29-
.description("The tag this history is for.")
27+
input: jsonApi.Joi.number().required()
28+
.description("The input value to write at the timestamp time of the tag.")
29+
.example("1245.76")
3030
},
3131
examples: [{}]
3232
});

apple/resources/hosts.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ jsonApi.define({
1717
hostnameOrIP: jsonApi.Joi.string().trim().hostname().required()
1818
.description("The hostname or ip of the host which is running this scada software.")
1919
.example("my.cool.host.com"),
20+
isPrimary: jsonApi.Joi.boolean().default(true)
21+
.description("Is this the primary host.")
22+
.example("true"),
2023
macAddress: jsonApi.Joi.string().trim().uppercase().regex(REGEX_MAC_ADDRESS).optional()
2124
.description("The host mac address.")
2225
.example("00:00:00:00:00:00"),
2326
desc: jsonApi.Joi.string().required()
2427
.description("The description <Country>.<Location>.<Building>.<Floor>.<Room>.<Row>.<DP>.<PrimaryOrSec>")
25-
.example("US.MSC.01.01.0001.01.02.1"),
26-
isPrimary: jsonApi.Joi.boolean().default(true)
27-
.description("Is this the primary host.")
28-
.example("true")
28+
.example("US.MSC.01.01.0001.01.02.1")
2929
},
3030
examples: [{}]
3131
});

apple/resources/runs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jsonApi.define({
1515
_id: jsonApi.Joi.string(),
1616
objectId: jsonApi.Joi.string().required()
1717
.description("The tag or alarmDef this history is for."),
18+
device_id: jsonApi.Joi.string().required()
19+
.description("The device that the objectId belongs to."),
1820
timestamp: jsonApi.Joi.date().required() // also, for javascript timestamp (milliseconds)
1921
.description("The beginning hour.")
2022
.example("1463672736248"),

apple/resources/tags.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,40 @@ jsonApi.define({
1616
attributes: {
1717
id: jsonApi.Joi.string().default(jsonApi.Joi.ref('_id')),
1818
_id: jsonApi.Joi.string(),
19+
tagname: jsonApi.Joi.string().trim().regex(REGEX_NAME_STRING)
20+
.description("The unique tag name.")
21+
.example("MY_AWESOME_TAGNAME"),
22+
input: jsonApi.Joi.any().optional()
23+
.description("If tag is writeable, the value to write to the tag in engineering units.")
24+
.example("24.5"),
1925
memLocation: jsonApi.Joi.string().required()
2026
.description("PLC memory location.")
2127
.example("N21:0 or 40001 for modbus driver"),
28+
value: jsonApi.Joi.any().optional()
29+
.description("The current value of the tag in engineering units.")
30+
.example("24.5"),
31+
rawValue: jsonApi.Joi.number().integer().optional()
32+
.description("The current value of the tag in engineering units.")
33+
.example("24"),
2234
valueType: jsonApi.Joi.string().trim().regex(REGEX_VALUE_TYPE)
2335
.default('real')
2436
.description('Can only be bool, real, integer or string.')
2537
.example('bool'),
26-
tagname: jsonApi.Joi.string().trim().regex(REGEX_NAME_STRING)
27-
.description("The unique tag name.")
28-
.example("MY_AWESOME_TAGNAME"),
29-
desc: jsonApi.Joi.string().required()
30-
.description("The tag description.")
31-
.example("Volts from TrendPoint."),
32-
units: jsonApi.Joi.string().required()
33-
.description("The tag units.")
34-
.example("Volts"),
38+
dataQuality: jsonApi.Joi.string().optional()
39+
.description("The data quality of the value of this tag.")
40+
.example("Ok"),
3541
isWritable: jsonApi.Joi.boolean().default(false)
3642
.description("Can you write to this tag.")
3743
.example("FALSE"),
44+
lastUpdate: jsonApi.Joi.date().optional()
45+
.description("The last time the current value was updated in UNIX time (ms).")
46+
.example("1463776147123"),
3847
isHistorical: jsonApi.Joi.boolean().default(true)
3948
.description("Should we store historical data for this tag.")
4049
.example("TRUE"),
50+
histDeadbandPercent: jsonApi.Joi.number().default(.03)
51+
.description("The percent of change of value field required to trigger a history sample where .03 is 3%. 0 means collect everything.")
52+
.example(".03"),
4153
rawMin: jsonApi.Joi.number().default(0)
4254
.description("The minimum raw integer value that the PLC will return for this tag.")
4355
.example(0),
@@ -48,6 +60,12 @@ jsonApi.define({
4860
.example(0),
4961
engMax: jsonApi.Joi.number().min(jsonApi.Joi.ref('engMin')).required()
5062
.description("The maximum eng units value that corresponds to the rawMax value."),
63+
desc: jsonApi.Joi.string().required()
64+
.description("The tag description.")
65+
.example("Volts from TrendPoint."),
66+
units: jsonApi.Joi.string().required()
67+
.description("The tag units.")
68+
.example("Volts"),
5169
inputType: jsonApi.Joi.string().trim().lowercase().regex(REGEX_INPUT_TYPE).optional()
5270
.description("Only valid for writable tags. one_shot = write the value one time. force = " +
5371
"always do a write if the tag.value is not equal to tag.input. momentary = write a 1 and" +
@@ -57,24 +75,9 @@ jsonApi.define({
5775
.description("If true, then count the number of times this tag goes non-zero and track the " +
5876
"amount of time the tag stays non zero.")
5977
.example("true"),
60-
dataQuality: jsonApi.Joi.string().optional()
61-
.description("The data quality of the value of this tag.")
62-
.example("Ok"),
63-
value: jsonApi.Joi.any().optional()
64-
.description("The current value of the tag in engineering units.")
65-
.example("24.5"),
66-
rawValue: jsonApi.Joi.number().integer().optional()
67-
.description("The current value of the tag in engineering units.")
68-
.example("24"),
69-
input: jsonApi.Joi.any().optional()
70-
.description("If tag is writeable, the value to write to the tag in engineering units.")
71-
.example("24.5"),
72-
lastUpdate: jsonApi.Joi.date().optional()
73-
.description("The last time the current value was updated in UNIX time (ms).")
74-
.example("1463776147123"),
75-
histDeadbandPercent: jsonApi.Joi.number().default(.03)
76-
.description("The percent of change of value field required to trigger a history sample where .03 is 3%. 0 means collect everything.")
77-
.example(".03"),
78+
alarmStatus: jsonApi.Joi.string().optional()
79+
.description("Is the activeAlarm clear, acked, unacked.")
80+
.example("Clear, acked, unacked"),
7881
activeAlarm: jsonApi.Joi.string().optional()
7982
.description("Is the tag in an alarm state based on an alarmDefs definition for the tag.")
8083
.example("None, HH, HI, LO, LL, INVALID"),
@@ -84,9 +87,6 @@ jsonApi.define({
8487
alarmReset: jsonApi.Joi.boolean().default(false)
8588
.description("If true the alarm has been reset.")
8689
.example("true"),
87-
alarmStatus: jsonApi.Joi.string().optional()
88-
.description("Is the activeAlarm clear, acked, unacked.")
89-
.example("Clear, acked, unacked"),
9090
alarmDefId: jsonApi.Joi.string().optional()
9191
.description("If in alarm, then this will point to the alarm def id."),
9292
device_id: jsonApi.Joi.allow(null, '').optional()

apple/rest.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* REST request class
33
* Created by jbockerstette on 11/8/16.
44
*/
5-
var http = require("http");
6-
var https = require("https");
5+
const http = require("http");
6+
const https = require("https");
77

88
/**
99
* getJSON: REST get request returning JSON object(s)
@@ -15,18 +15,17 @@ exports.getJSON = function(options, onResult)
1515
console.log("rest::getJSON");
1616

1717
// var prot = options.port == 443 ? https : http;
18-
var prot = http;
19-
var req = prot.request(options, function(res)
20-
{
21-
var output = '';
18+
// const req = prot.request(options, function (res) {
19+
const req = http.request(options, function (res) {
20+
let output = '';
2221
console.log(options.host + ':' + res.statusCode);
2322
res.setEncoding('utf8');
2423

2524
res.on('data', function (chunk) {
2625
output += chunk;
2726
});
2827

29-
res.on('end', function() {
28+
res.on('end', function () {
3029
onResult(res.statusCode, output);
3130
});
3231
});

0 commit comments

Comments
 (0)