Skip to content

Commit 33fa220

Browse files
committed
Fix bug with constructing SBP messages with fields in javascript. Augment all tests with constructMsg test. Add settings example.
1 parent 8d5b4c7 commit 33fa220

24 files changed

+172
-18
lines changed

RELEASE_NOTES.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ For a detailed index of changes, please see the
66

77
Contents
88
--------
9+
* [v1.1.1](#v1.1.1)
910
* [v1.1.0](#v1.1.0)
1011
* [v1.0.2](#v1.0.2)
1112
* [v1.0.1](#v1.0.1)
1213
* [v0.39](#v0.39)
1314
* [v0.33](#v0.33)
1415

16+
v1.1.1 <a name="v1.1.1"></a>
17+
--------------------------
18+
* Javascript: fixed bug with `constructMsg` and added more tests and examples for message construction.
19+
1520
v1.1.0 <a name="v1.1.0"></a>
1621
--------------------------
1722
* Added `MSG_SETTINGS_REGISTER` message

docs/sbp.pdf

-1 Bytes
Binary file not shown.

generator/sbpg/targets/resources/sbp_js.js.j2

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var ((( m.identifier | js_classnameify ))) = function (sbp, fields) {
4646
return this;
4747
};
4848
((( m.identifier | js_classnameify ))).prototype = Object.create(SBP.prototype);
49+
((( m.identifier | js_classnameify ))).prototype.messageType = "(((m.identifier)))";
4950
((*- if m.sbp_id *))
5051
((( m.identifier | js_classnameify ))).prototype.msg_type = ((('0x%04X'|format(m.sbp_id))));
5152
((*- endif *))

haskell/sbp.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sbp
2-
version: 1.1.0
2+
version: 1.1.1
33
synopsis: SwiftNav's SBP Library
44
homepage: https://github.com/swift-nav/libsbp
55
license: LGPL-3

javascript/sbp/acquisition.js

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var MsgAcqResult = function (sbp, fields) {
4747
return this;
4848
};
4949
MsgAcqResult.prototype = Object.create(SBP.prototype);
50+
MsgAcqResult.prototype.messageType = "MSG_ACQ_RESULT";
5051
MsgAcqResult.prototype.msg_type = 0x0014;
5152
MsgAcqResult.prototype.constructor = MsgAcqResult;
5253
MsgAcqResult.prototype.parser = new Parser()
@@ -83,6 +84,7 @@ var MsgAcqResultDepA = function (sbp, fields) {
8384
return this;
8485
};
8586
MsgAcqResultDepA.prototype = Object.create(SBP.prototype);
87+
MsgAcqResultDepA.prototype.messageType = "MSG_ACQ_RESULT_DEP_A";
8688
MsgAcqResultDepA.prototype.msg_type = 0x0015;
8789
MsgAcqResultDepA.prototype.constructor = MsgAcqResultDepA;
8890
MsgAcqResultDepA.prototype.parser = new Parser()

javascript/sbp/bootload.js

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var MsgBootloaderHandshakeReq = function (sbp, fields) {
4040
return this;
4141
};
4242
MsgBootloaderHandshakeReq.prototype = Object.create(SBP.prototype);
43+
MsgBootloaderHandshakeReq.prototype.messageType = "MSG_BOOTLOADER_HANDSHAKE_REQ";
4344
MsgBootloaderHandshakeReq.prototype.msg_type = 0x00B3;
4445
MsgBootloaderHandshakeReq.prototype.constructor = MsgBootloaderHandshakeReq;
4546
MsgBootloaderHandshakeReq.prototype.parser = new Parser()
@@ -68,6 +69,7 @@ var MsgBootloaderHandshakeResp = function (sbp, fields) {
6869
return this;
6970
};
7071
MsgBootloaderHandshakeResp.prototype = Object.create(SBP.prototype);
72+
MsgBootloaderHandshakeResp.prototype.messageType = "MSG_BOOTLOADER_HANDSHAKE_RESP";
7173
MsgBootloaderHandshakeResp.prototype.msg_type = 0x00B4;
7274
MsgBootloaderHandshakeResp.prototype.constructor = MsgBootloaderHandshakeResp;
7375
MsgBootloaderHandshakeResp.prototype.parser = new Parser()
@@ -96,6 +98,7 @@ var MsgBootloaderJumpToApp = function (sbp, fields) {
9698
return this;
9799
};
98100
MsgBootloaderJumpToApp.prototype = Object.create(SBP.prototype);
101+
MsgBootloaderJumpToApp.prototype.messageType = "MSG_BOOTLOADER_JUMP_TO_APP";
99102
MsgBootloaderJumpToApp.prototype.msg_type = 0x00B1;
100103
MsgBootloaderJumpToApp.prototype.constructor = MsgBootloaderJumpToApp;
101104
MsgBootloaderJumpToApp.prototype.parser = new Parser()
@@ -123,6 +126,7 @@ var MsgNapDeviceDnaReq = function (sbp, fields) {
123126
return this;
124127
};
125128
MsgNapDeviceDnaReq.prototype = Object.create(SBP.prototype);
129+
MsgNapDeviceDnaReq.prototype.messageType = "MSG_NAP_DEVICE_DNA_REQ";
126130
MsgNapDeviceDnaReq.prototype.msg_type = 0x00DE;
127131
MsgNapDeviceDnaReq.prototype.constructor = MsgNapDeviceDnaReq;
128132
MsgNapDeviceDnaReq.prototype.parser = new Parser()
@@ -151,6 +155,7 @@ var MsgNapDeviceDnaResp = function (sbp, fields) {
151155
return this;
152156
};
153157
MsgNapDeviceDnaResp.prototype = Object.create(SBP.prototype);
158+
MsgNapDeviceDnaResp.prototype.messageType = "MSG_NAP_DEVICE_DNA_RESP";
154159
MsgNapDeviceDnaResp.prototype.msg_type = 0x00DD;
155160
MsgNapDeviceDnaResp.prototype.constructor = MsgNapDeviceDnaResp;
156161
MsgNapDeviceDnaResp.prototype.parser = new Parser()
@@ -177,6 +182,7 @@ var MsgBootloaderHandshakeDepA = function (sbp, fields) {
177182
return this;
178183
};
179184
MsgBootloaderHandshakeDepA.prototype = Object.create(SBP.prototype);
185+
MsgBootloaderHandshakeDepA.prototype.messageType = "MSG_BOOTLOADER_HANDSHAKE_DEP_A";
180186
MsgBootloaderHandshakeDepA.prototype.msg_type = 0x00B0;
181187
MsgBootloaderHandshakeDepA.prototype.constructor = MsgBootloaderHandshakeDepA;
182188
MsgBootloaderHandshakeDepA.prototype.parser = new Parser()

javascript/sbp/construct.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var crc = sbp.crc16;
2222
* @param MsgType {Function} The message type you want to construct.
2323
* @param fields {Object} Optional key-value pairs of message fields.
2424
*/
25-
module.exports = function constructMsg (MsgType, fields) {
25+
module.exports = function constructMsg (MsgType, fields, sender) {
2626
if (typeof MsgType !== 'function') {
2727
throw new Error('The MsgType parameter must be a valid SBP message type constructor.');
2828
}
@@ -43,12 +43,12 @@ module.exports = function constructMsg (MsgType, fields) {
4343
// Construct message envelope
4444
msgEnvelope.preamble = sbp.preambleByte;
4545
msgEnvelope.msg_type = MsgType.prototype.msg_type;
46-
msgEnvelope.sender = 0; // see SBP.pdf documentation
46+
msgEnvelope.sender = sender || 0; // see SBP.pdf documentation
4747
msgEnvelope.length = msgEnvelope.payload.length;
4848
msgEnvelope.crc = crc(msgEnvelope.payload,
4949
crc(msgEnvelope.getLengthBuffer(),
5050
crc(msgEnvelope.getSenderBuffer(),
5151
crc(msgEnvelope.getMsgTypeBuffer()))));
5252

53-
return msgEnvelope;
53+
return msg;
5454
};

javascript/sbp/ext_events.js

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var MsgExtEvent = function (sbp, fields) {
4545
return this;
4646
};
4747
MsgExtEvent.prototype = Object.create(SBP.prototype);
48+
MsgExtEvent.prototype.messageType = "MSG_EXT_EVENT";
4849
MsgExtEvent.prototype.msg_type = 0x0101;
4950
MsgExtEvent.prototype.constructor = MsgExtEvent;
5051
MsgExtEvent.prototype.parser = new Parser()

javascript/sbp/file_io.js

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var MsgFileioReadReq = function (sbp, fields) {
5353
return this;
5454
};
5555
MsgFileioReadReq.prototype = Object.create(SBP.prototype);
56+
MsgFileioReadReq.prototype.messageType = "MSG_FILEIO_READ_REQ";
5657
MsgFileioReadReq.prototype.msg_type = 0x00A8;
5758
MsgFileioReadReq.prototype.constructor = MsgFileioReadReq;
5859
MsgFileioReadReq.prototype.parser = new Parser()
@@ -89,6 +90,7 @@ var MsgFileioReadResp = function (sbp, fields) {
8990
return this;
9091
};
9192
MsgFileioReadResp.prototype = Object.create(SBP.prototype);
93+
MsgFileioReadResp.prototype.messageType = "MSG_FILEIO_READ_RESP";
9294
MsgFileioReadResp.prototype.msg_type = 0x00A3;
9395
MsgFileioReadResp.prototype.constructor = MsgFileioReadResp;
9496
MsgFileioReadResp.prototype.parser = new Parser()
@@ -126,6 +128,7 @@ var MsgFileioReadDirReq = function (sbp, fields) {
126128
return this;
127129
};
128130
MsgFileioReadDirReq.prototype = Object.create(SBP.prototype);
131+
MsgFileioReadDirReq.prototype.messageType = "MSG_FILEIO_READ_DIR_REQ";
129132
MsgFileioReadDirReq.prototype.msg_type = 0x00A9;
130133
MsgFileioReadDirReq.prototype.constructor = MsgFileioReadDirReq;
131134
MsgFileioReadDirReq.prototype.parser = new Parser()
@@ -161,6 +164,7 @@ var MsgFileioReadDirResp = function (sbp, fields) {
161164
return this;
162165
};
163166
MsgFileioReadDirResp.prototype = Object.create(SBP.prototype);
167+
MsgFileioReadDirResp.prototype.messageType = "MSG_FILEIO_READ_DIR_RESP";
164168
MsgFileioReadDirResp.prototype.msg_type = 0x00AA;
165169
MsgFileioReadDirResp.prototype.constructor = MsgFileioReadDirResp;
166170
MsgFileioReadDirResp.prototype.parser = new Parser()
@@ -192,6 +196,7 @@ var MsgFileioRemove = function (sbp, fields) {
192196
return this;
193197
};
194198
MsgFileioRemove.prototype = Object.create(SBP.prototype);
199+
MsgFileioRemove.prototype.messageType = "MSG_FILEIO_REMOVE";
195200
MsgFileioRemove.prototype.msg_type = 0x00AC;
196201
MsgFileioRemove.prototype.constructor = MsgFileioRemove;
197202
MsgFileioRemove.prototype.parser = new Parser()
@@ -226,6 +231,7 @@ var MsgFileioWriteReq = function (sbp, fields) {
226231
return this;
227232
};
228233
MsgFileioWriteReq.prototype = Object.create(SBP.prototype);
234+
MsgFileioWriteReq.prototype.messageType = "MSG_FILEIO_WRITE_REQ";
229235
MsgFileioWriteReq.prototype.msg_type = 0x00AD;
230236
MsgFileioWriteReq.prototype.constructor = MsgFileioWriteReq;
231237
MsgFileioWriteReq.prototype.parser = new Parser()
@@ -261,6 +267,7 @@ var MsgFileioWriteResp = function (sbp, fields) {
261267
return this;
262268
};
263269
MsgFileioWriteResp.prototype = Object.create(SBP.prototype);
270+
MsgFileioWriteResp.prototype.messageType = "MSG_FILEIO_WRITE_RESP";
264271
MsgFileioWriteResp.prototype.msg_type = 0x00AB;
265272
MsgFileioWriteResp.prototype.constructor = MsgFileioWriteResp;
266273
MsgFileioWriteResp.prototype.parser = new Parser()

javascript/sbp/flash.js

+10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var MsgFlashProgram = function (sbp, fields) {
4848
return this;
4949
};
5050
MsgFlashProgram.prototype = Object.create(SBP.prototype);
51+
MsgFlashProgram.prototype.messageType = "MSG_FLASH_PROGRAM";
5152
MsgFlashProgram.prototype.msg_type = 0x00E6;
5253
MsgFlashProgram.prototype.constructor = MsgFlashProgram;
5354
MsgFlashProgram.prototype.parser = new Parser()
@@ -82,6 +83,7 @@ var MsgFlashDone = function (sbp, fields) {
8283
return this;
8384
};
8485
MsgFlashDone.prototype = Object.create(SBP.prototype);
86+
MsgFlashDone.prototype.messageType = "MSG_FLASH_DONE";
8587
MsgFlashDone.prototype.msg_type = 0x00E0;
8688
MsgFlashDone.prototype.constructor = MsgFlashDone;
8789
MsgFlashDone.prototype.parser = new Parser()
@@ -114,6 +116,7 @@ var MsgFlashReadReq = function (sbp, fields) {
114116
return this;
115117
};
116118
MsgFlashReadReq.prototype = Object.create(SBP.prototype);
119+
MsgFlashReadReq.prototype.messageType = "MSG_FLASH_READ_REQ";
117120
MsgFlashReadReq.prototype.msg_type = 0x00E7;
118121
MsgFlashReadReq.prototype.constructor = MsgFlashReadReq;
119122
MsgFlashReadReq.prototype.parser = new Parser()
@@ -150,6 +153,7 @@ var MsgFlashReadResp = function (sbp, fields) {
150153
return this;
151154
};
152155
MsgFlashReadResp.prototype = Object.create(SBP.prototype);
156+
MsgFlashReadResp.prototype.messageType = "MSG_FLASH_READ_RESP";
153157
MsgFlashReadResp.prototype.msg_type = 0x00E1;
154158
MsgFlashReadResp.prototype.constructor = MsgFlashReadResp;
155159
MsgFlashReadResp.prototype.parser = new Parser()
@@ -184,6 +188,7 @@ var MsgFlashErase = function (sbp, fields) {
184188
return this;
185189
};
186190
MsgFlashErase.prototype = Object.create(SBP.prototype);
191+
MsgFlashErase.prototype.messageType = "MSG_FLASH_ERASE";
187192
MsgFlashErase.prototype.msg_type = 0x00E2;
188193
MsgFlashErase.prototype.constructor = MsgFlashErase;
189194
MsgFlashErase.prototype.parser = new Parser()
@@ -213,6 +218,7 @@ var MsgStmFlashLockSector = function (sbp, fields) {
213218
return this;
214219
};
215220
MsgStmFlashLockSector.prototype = Object.create(SBP.prototype);
221+
MsgStmFlashLockSector.prototype.messageType = "MSG_STM_FLASH_LOCK_SECTOR";
216222
MsgStmFlashLockSector.prototype.msg_type = 0x00E3;
217223
MsgStmFlashLockSector.prototype.constructor = MsgStmFlashLockSector;
218224
MsgStmFlashLockSector.prototype.parser = new Parser()
@@ -240,6 +246,7 @@ var MsgStmFlashUnlockSector = function (sbp, fields) {
240246
return this;
241247
};
242248
MsgStmFlashUnlockSector.prototype = Object.create(SBP.prototype);
249+
MsgStmFlashUnlockSector.prototype.messageType = "MSG_STM_FLASH_UNLOCK_SECTOR";
243250
MsgStmFlashUnlockSector.prototype.msg_type = 0x00E4;
244251
MsgStmFlashUnlockSector.prototype.constructor = MsgStmFlashUnlockSector;
245252
MsgStmFlashUnlockSector.prototype.parser = new Parser()
@@ -265,6 +272,7 @@ var MsgStmUniqueIdReq = function (sbp, fields) {
265272
return this;
266273
};
267274
MsgStmUniqueIdReq.prototype = Object.create(SBP.prototype);
275+
MsgStmUniqueIdReq.prototype.messageType = "MSG_STM_UNIQUE_ID_REQ";
268276
MsgStmUniqueIdReq.prototype.msg_type = 0x00E8;
269277
MsgStmUniqueIdReq.prototype.constructor = MsgStmUniqueIdReq;
270278
MsgStmUniqueIdReq.prototype.parser = new Parser()
@@ -291,6 +299,7 @@ var MsgStmUniqueIdResp = function (sbp, fields) {
291299
return this;
292300
};
293301
MsgStmUniqueIdResp.prototype = Object.create(SBP.prototype);
302+
MsgStmUniqueIdResp.prototype.messageType = "MSG_STM_UNIQUE_ID_RESP";
294303
MsgStmUniqueIdResp.prototype.msg_type = 0x00E5;
295304
MsgStmUniqueIdResp.prototype.constructor = MsgStmUniqueIdResp;
296305
MsgStmUniqueIdResp.prototype.parser = new Parser()
@@ -318,6 +327,7 @@ var MsgM25FlashWriteStatus = function (sbp, fields) {
318327
return this;
319328
};
320329
MsgM25FlashWriteStatus.prototype = Object.create(SBP.prototype);
330+
MsgM25FlashWriteStatus.prototype.messageType = "MSG_M25_FLASH_WRITE_STATUS";
321331
MsgM25FlashWriteStatus.prototype.msg_type = 0x00F3;
322332
MsgM25FlashWriteStatus.prototype.constructor = MsgM25FlashWriteStatus;
323333
MsgM25FlashWriteStatus.prototype.parser = new Parser()

javascript/sbp/gnss_signal.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var GnssSignal = function (sbp, fields) {
4141
return this;
4242
};
4343
GnssSignal.prototype = Object.create(SBP.prototype);
44+
GnssSignal.prototype.messageType = "GnssSignal";
4445
GnssSignal.prototype.constructor = GnssSignal;
4546
GnssSignal.prototype.parser = new Parser()
4647
.endianess('little')

javascript/sbp/logging.js

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var MsgLog = function (sbp, fields) {
4242
return this;
4343
};
4444
MsgLog.prototype = Object.create(SBP.prototype);
45+
MsgLog.prototype.messageType = "MSG_LOG";
4546
MsgLog.prototype.msg_type = 0x0401;
4647
MsgLog.prototype.constructor = MsgLog;
4748
MsgLog.prototype.parser = new Parser()
@@ -70,6 +71,7 @@ var MsgTweet = function (sbp, fields) {
7071
return this;
7172
};
7273
MsgTweet.prototype = Object.create(SBP.prototype);
74+
MsgTweet.prototype.messageType = "MSG_TWEET";
7375
MsgTweet.prototype.msg_type = 0x0012;
7476
MsgTweet.prototype.constructor = MsgTweet;
7577
MsgTweet.prototype.parser = new Parser()
@@ -96,6 +98,7 @@ var MsgPrintDep = function (sbp, fields) {
9698
return this;
9799
};
98100
MsgPrintDep.prototype = Object.create(SBP.prototype);
101+
MsgPrintDep.prototype.messageType = "MSG_PRINT_DEP";
99102
MsgPrintDep.prototype.msg_type = 0x0010;
100103
MsgPrintDep.prototype.constructor = MsgPrintDep;
101104
MsgPrintDep.prototype.parser = new Parser()

javascript/sbp/msg.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ var sbpImports = {
9494
tracking: require('./tracking.js')
9595
};
9696

97-
var sbpTable = Object.keys(sbpImports).reduce(function (prev, key) {
97+
var sbpIdTable = Object.keys(sbpImports).reduce(function (prev, key) {
9898
var curr = sbpImports[key];
9999
var numericKeysDict = {};
100100
Object.keys(curr).map(function (key) {
@@ -105,6 +105,18 @@ var sbpTable = Object.keys(sbpImports).reduce(function (prev, key) {
105105
return mergeDict(prev, numericKeysDict);
106106
}, {});
107107

108+
var sbpMessageTypesTable = Object.keys(sbpImports).reduce(function (prev, key) {
109+
var curr = sbpImports[key];
110+
var nonNumericKeysDict = {};
111+
Object.keys(curr).map(function (key) {
112+
if (parseInt(key) != key) {
113+
var messageType = curr[key].prototype.messageType || key;
114+
nonNumericKeysDict[messageType] = curr[key];
115+
}
116+
});
117+
return mergeDict(prev, nonNumericKeysDict);
118+
}, {});
119+
108120
var parser = new Parser()
109121
.endianess('little')
110122
.uint8('preamble')
@@ -134,9 +146,12 @@ module.exports = {
134146
preambleByte: SBP_PREAMBLE,
135147
crc16: crc16,
136148

149+
sbpIdTable: sbpIdTable,
150+
sbpMessageTypesTable: sbpMessageTypesTable,
151+
137152
decode: function decode (msg) {
138153
var sbp = parser.parse(msg);
139-
var msgTypeDecoder = sbpTable[sbp['msg_type']];
154+
var msgTypeDecoder = sbpIdTable[sbp['msg_type']];
140155

141156
if (typeof msgTypeDecoder === 'undefined') {
142157
console.log("Unknown message type: ", sbp['msg_type']);

0 commit comments

Comments
 (0)