-
Notifications
You must be signed in to change notification settings - Fork 5
/
tekelec_tek766_codec.js
150 lines (108 loc) · 3.97 KB
/
tekelec_tek766_codec.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//*****************************************************************************
// Javascript codec functions for Tekelec TEK766 endpoints
// Authors: Didier Donsez, Vivien Quéma
// Licence: EPL 1.0
//*****************************************************************************
const PORT_SONIC_MEASUREMENT = 0x10;
const PORT_STATUS = 0x30;
const PORT_ALARM_NOTOFICATION = 0x45;
Tekelec_Tek766_Payload = {
'decodeUp': function (port,payload) {
// TODO check port
var p = payload;
if ( port===PORT_SONIC_MEASUREMENT && p.length === 20) {
var value = {};
value["type"]="measurement";
//var type=p.readUInt8(0); // same as the port
var prodId=p.readUInt8(1);
value["prodId"]=prodId;
var alarms=p.readUInt8(2);
value["alarm0"]=alarms & 0x01;
value["alarm1"]=alarms & 0x02;
value["alarm2"]=alarms & 0x04;
// var reserved = p.readUInt8(3);
var ullage0=p.readUInt16BE(4);
var temp0=p.readInt8(6);
var sonicrssi0=p.readUInt8(7) >> 4;
var sonicsrc0=p.readUInt8(7) & 0x0F;
value["ullage0"]=ullage0;
value["temperature0"]=temp0;
value["sonicrssi0"]=sonicrssi0;
value["sonicsrc0"]=sonicsrc0;
var ullage1=p.readUInt16BE(8);
var temp1=p.readInt8(10);
var sonicrssi1=p.readUInt8(11) >> 4;
var sonicsrc1=p.readUInt8(11) & 0x0F;
value["ullage1"]=ullage1;
value["temperature1"]=temp1;
value["sonicrssi1"]=sonicrssi1;
value["sonicsrc1"]=sonicsrc1;
var ullage2=p.readUInt16BE(12);
var temp2=p.readInt8(14);
var sonicrssi2=p.readUInt8(15) >> 4;
var sonicsrc2=p.readUInt8(15) & 0x0F;
value["ullage2"]=ullage2;
value["temperature2"]=temp2;
value["sonicrssi2"]=sonicrssi2;
value["sonicsrc2"]=sonicsrc2;
return value;
} else if (port===PORT_STATUS && p.length === 18) {
// console.log(port, p.length, p.toString('hex'));
var value = {};
value["type"]="status";
var prodId=p.readUInt8(1);
value["prodId"]=prodId;
var hwId=p.readUInt8(4);
value["hwId"]=hwId;
var swId=p.readUInt16BE(5);
value["swId"]=hwId;
var rssi=p.readUInt8(8);
value["rssi"]=-rssi;
var battery=p.readUInt8(10);
value["batteryLevel"]=battery;
var measurementSteps=p.readUInt16BE(11);
value["measurementSteps"]=measurementSteps;
var txPeriod=p.readUInt8(13);
value["txPeriod"]=txPeriod;
var ullage=p.readUInt16BE(14);
value["ullage"]=ullage;
var temperature=p.readInt8(16);
value["temperature"]=temperature;
var sonicrssi=p.readUInt8(17) >> 4;
var sonicsrc=p.readUInt8(17) & 0x0F;
value["sonicrssi"]=sonicrssi;
value["sonicsrc"]=sonicsrc;
return value;
} else if (port===PORT_ALARM_NOTOFICATION && p.length === 12) {
// console.log(port, p.length, p.toString('hex'));
var value = {};
value["type"]="alarm";
//var type=p.readUInt8(0); // same as the port
var prodId=p.readUInt8(1);
value["prodId"]=prodId;
var alarms=p.readUInt8(2);
value["alarm0"]=alarms & 0x01;
value["alarm1"]=alarms & 0x02;
value["alarm2"]=alarms & 0x04;
// var reserved = p.readUInt8(3);
var ullage=p.readUInt16BE(4);
var temp=p.readInt8(6);
var sonicrssi=p.readUInt8(7) >> 4;
var sonicsrc=p.readUInt8(7) & 0x0F;
value["ullage"]=ullage;
value["temperature"]=temp;
value["sonicrssi"]=sonicrssi;
value["sonicsrc"]=sonicsrc;
return value;
} else {
// console.log(port, p.length, p.toString('hex'));
return undefined;
}
},
// encodes the given object into an array of bytes
'encodeDn': function (port,value) {
// TO BE IMPLEMENTED
return null;
}
}
module.exports.Decoder = Tekelec_Tek766_Payload;