-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
254 lines (140 loc) · 7.72 KB
/
index.html
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Home</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Home</h1>
<h3> </h3>
<section>
<article><h1>cbusLibrary</h1>
<h3>Library for decoding and encoding CBUS Layout Control Bus (LCB) messages, including extended messages used for firmware download</h3>
<p>There is a very comprehensive set of tests for this - see <strong>tests</strong> section further below. <br>
The decoding and encoding of standard (11 bit) CAN ID messages follows the CBUS specification available here
<a href="https://www.merg.org.uk/merg_wiki/doku.php?id=public:cbuspublic:developerguide">CBUS dev guide</a><br>
At the time of writing, there isn't a formal definition of extended (29 bit) CAN ID message formats, so the methods are based on current implementations</p>
<h3>Full API details available <a href="cbusLibrary.html">here</a></h3>
<h2>Installation</h2>
<pre><code>npm install cbuslibrary
</code></pre>
<p>(note all lower case - npm no longer allows uppercase)</p>
<h2>Usage</h2>
<pre><code>const cbusLib = require('cbusLibrary')
</code></pre>
<p>An instance of the class is created automatically, so can be used immediately</p>
<h2>General information</h2>
<h3>decoding</h3>
<p>for decoding, there's one common function (as the opcode is embedded in the message)
var cbusMsg = cbusLib.decode(<message to be decoded>)</p>
<p>The decode function returns a collection of values, with "encoded", "ID_TYPE" and "text" being standard for all messages
See an expanded description of 'eventName' further below</p>
<p>example CBUS (11 bit Id) message decode:</p>
<pre><code>{
"encoded": ":SB780ND200010000FF00;",
"ID_TYPE":"S",
"mnemonic": "EVLRN",
"opCode": "D2",
"nodeNumber": 1,
"eventNumber": 0,
"eventName": "00010000",
"eventVariableIndex": 255,
"eventVariableValue": 0,
"text": "EVLRN (D2) nodeNumber 1 eventNumber 0 eventName 00010000 Event Variable Index 255 Event Variable Value 0"
}
</code></pre>
<p>Note that some properties have full names to avoid confusion (e.g. eventVariableIndex, rather than EV#)</p>
<p>example extended (29 bit Id) message decode:</p>
<pre><code>{
"encoded":":X00080004N000000000D040000;",
"ID_TYPE":"X",
"operation":"PUT",
"type":"CONTROL",
"address":"000000",
"RESVD":0,
"CTLBT":13,
"SPCMD":4,
"CPDTL":0,
"CPDTH":0
"text": {"encoded":":X00080004N000000000D040000;","ID_TYPE":"X","operation":"PUT","type":"CONTROL","address":"000000","RESVD":0,"CTLBT":13,"SPCMD":4,"CPDTL":0,"CPDTH":0}
}
</code></pre>
<h3>encoding</h3>
<p>For encoding standard CBUS messages, there's one function encode() thats takes a JSON object, which needs the 'mnemonic' for the specific opcode, and any parameters the opcode requires<br>
The format of the JSON object follows exactly the same syntax as the result from the decode() function above<br>
Each opcode also it's own function, that has individual parameters, as the type & number of parameters vary with opCode</p>
<ul style="list-style-type:none;"><li>var encode = cbusLib.encodeEVLRN(nodeNumber, eventNumber, VariableIndex, eventVariableValue);</li></ul>
<p>There are only separate functions for encoding extended CBUS messages currently</p>
<h3>eventIdentifier</h3>
<p>An event is identified by 4 bytes made up from either the node number plus the event number in the case of a 'long' event,
or in a 'short' event just the 2 byte device number (with the top bytes set to zero)<br>
The 'eventIdentifier' is used to provide the correct value depending on the type of event ('long' or 'short'), in an 8 digit hexadecimal string with leading zero's<br>
i.e.<br>
'long' event = node number + event number<br>
'short' event = 0000 + device number<br>
<br>
The command 'ENRSP' also expects this four byte 'eventIdentifier' as a parameter as well as the node number<br></p>
<h3>CAN header (11 bit CAN identifier)</h3>
<p>There are default values for the 11 bit CAN header used when encoding messages, but these can be changed using the following function</p>
<ul style="list-style-type:none;"><li>setCanHeader(MjPri, CAN_ID)</li></ul>
<p>Once set, the new values will continue to be used for subsequent encodes (or until the program is restarted)<br></p>
<p>Note that MinPri is specifically defined for each opCode, so is set for each individual opCode and not expected to be changed</p>
<h3>CAN header (29 bit CAN identifier)</h3>
<p>The absence of a definition for the 29 bit identifier means that the identifier is hard coded to match existing</p>
<ul style="list-style-type:none;">
<li>0000N000<A> for FCU originated messages</li>
<li>8000N000<A> for module originated messages</li>
</ul>
where: <A> is a bit mapped character, bit 0 being control/data, and bit 1 being put/get
<h2>Tests</h2>
<p>There is a comprehensive suite of unit tests for all the message decode/encodes, which also create a log file</p>
<h3>How to run all tests</h3>
<ul style="list-style-type:none;"><li>npm test</li></ul>
Will run al the tests - note there are more than 27,000 tests, and although doesn't take too long, it does create a huge log file
<h3>How to run specific test</h3>
<p>You can also run a specific test, which produces a much more workable log file</p>
<ul style="list-style-type:none;"><li>npm test -- --grep "EVLRN"</li></ul>
<h3>Tests log file</h3>
<p>For all tests, the log file is created in /tests/logs, and is overwritten on each test run</p>
<h2>Documentation</h2>
<p>The project uses JSDocs to generate most of the documentation</p>
<h3>How to run jsdoc</h3>
<ul style="list-style-type:none;"><li>npm run jsdoc</li></ul>
This creates the documents in the 'out' folder, and are copied manually in the root project directory when finalised</article>
</section>
<section>
<header>
<h2>cbuslibrary.js</h2>
</header>
<article>
<div class="container-overview">
<div class="description"><strong>Module to decode & encode CBUS message strings</strong></br></div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="cbuslibrary.js.html">cbuslibrary.js</a>, <a href="cbuslibrary.js.html#line3">line 3</a>
</li></ul></dd>
</dl>
</div>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="cbusLibrary.html">cbusLibrary</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Nov 07 2022 18:56:05 GMT+0000 (Greenwich Mean Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>