Skip to content

Commit 8d5b4c7

Browse files
authored
Merge pull request #364 from JoshuaGross/jgross-1.1.0
v1.1.0 release: settings message, javascript message construction
2 parents 4fea66d + c2622af commit 8d5b4c7

32 files changed

+579
-210
lines changed

RELEASE_NOTES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ For a detailed index of changes, please see the
66

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

15+
v1.1.0 <a name="v1.1.0"></a>
16+
--------------------------
17+
* Added `MSG_SETTINGS_REGISTER` message
18+
* More improvements to JavaScript to add a `constructMsg` interface (`sbp/construct.js`).
19+
1420
v1.0.2 <a name="v1.0.2"></a>
1521
--------------------------
1622
Minor release: changes JavaScript bindings to simplify constructing

c/include/libsbp/settings.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,20 @@ typedef struct __attribute__((packed)) {
120120
#define SBP_MSG_SETTINGS_READ_BY_INDEX_DONE 0x00A6
121121

122122

123+
/** Register setting and default value (device => host)
124+
*
125+
* This message registers the presence and default value of a setting
126+
* with a settings daemon. The host should reply with MSG_SETTINGS_WRITE
127+
* for this setting to set the initial value.
128+
*/
129+
#define SBP_MSG_SETTINGS_REGISTER 0x00AE
130+
typedef struct __attribute__((packed)) {
131+
char setting[0]; /**< A NULL-terminated and delimited string with contents
132+
[SECTION_SETTING, SETTING, VALUE].
133+
*/
134+
} msg_settings_register_t;
135+
136+
123137
/** \} */
124138

125139
#endif /* LIBSBP_SETTINGS_MESSAGES_H */

c/include/libsbp/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/** Protocol major version. */
2424
#define SBP_MAJOR_VERSION 1
2525
/** Protocol minor version. */
26-
#define SBP_MINOR_VERSION 0
26+
#define SBP_MINOR_VERSION 1
2727

2828
/** \} */
2929

docs/sbp.pdf

1.26 KB
Binary file not shown.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ var (((ident))) = require("./(((file)))").(((ident)));
3838
*((*- endif *))
3939
* @param sbp An SBP object with a payload to be decoded.
4040
*/
41-
var ((( m.identifier | js_classnameify ))) = function (sbp) {
41+
var ((( m.identifier | js_classnameify ))) = function (sbp, fields) {
4242
SBP.call(this, sbp);
4343
this.messageType = "(((m.identifier)))";
44-
this.fields = this.parser.parse(sbp.payload);
44+
this.fields = (fields || this.parser.parse(sbp.payload));
4545

4646
return this;
4747
};

haskell/sbp.cabal

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

haskell/src/SwiftNav/SBP.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ data SBPMsg =
109109
| SBPMsgSettingsReadByIndexResp MsgSettingsReadByIndexResp Msg
110110
| SBPMsgSettingsReadReq MsgSettingsReadReq Msg
111111
| SBPMsgSettingsReadResp MsgSettingsReadResp Msg
112+
| SBPMsgSettingsRegister MsgSettingsRegister Msg
112113
| SBPMsgSettingsSave MsgSettingsSave Msg
113114
| SBPMsgSettingsWrite MsgSettingsWrite Msg
114115
| SBPMsgStartup MsgStartup Msg
@@ -194,6 +195,7 @@ instance Binary SBPMsg where
194195
| _msgSBPType == msgSettingsReadByIndexResp = SBPMsgSettingsReadByIndexResp (decode (fromStrict _msgSBPPayload)) m
195196
| _msgSBPType == msgSettingsReadReq = SBPMsgSettingsReadReq (decode (fromStrict _msgSBPPayload)) m
196197
| _msgSBPType == msgSettingsReadResp = SBPMsgSettingsReadResp (decode (fromStrict _msgSBPPayload)) m
198+
| _msgSBPType == msgSettingsRegister = SBPMsgSettingsRegister (decode (fromStrict _msgSBPPayload)) m
197199
| _msgSBPType == msgSettingsSave = SBPMsgSettingsSave (decode (fromStrict _msgSBPPayload)) m
198200
| _msgSBPType == msgSettingsWrite = SBPMsgSettingsWrite (decode (fromStrict _msgSBPPayload)) m
199201
| _msgSBPType == msgStartup = SBPMsgStartup (decode (fromStrict _msgSBPPayload)) m
@@ -271,6 +273,7 @@ instance Binary SBPMsg where
271273
encode' (SBPMsgSettingsReadByIndexResp _ m) = put m
272274
encode' (SBPMsgSettingsReadReq _ m) = put m
273275
encode' (SBPMsgSettingsReadResp _ m) = put m
276+
encode' (SBPMsgSettingsRegister _ m) = put m
274277
encode' (SBPMsgSettingsSave _ m) = put m
275278
encode' (SBPMsgSettingsWrite _ m) = put m
276279
encode' (SBPMsgStartup _ m) = put m
@@ -351,6 +354,7 @@ instance FromJSON SBPMsg where
351354
| msgType == msgSettingsReadByIndexResp = SBPMsgSettingsReadByIndexResp <$> parseJSON obj <*> parseJSON obj
352355
| msgType == msgSettingsReadReq = SBPMsgSettingsReadReq <$> parseJSON obj <*> parseJSON obj
353356
| msgType == msgSettingsReadResp = SBPMsgSettingsReadResp <$> parseJSON obj <*> parseJSON obj
357+
| msgType == msgSettingsRegister = SBPMsgSettingsRegister <$> parseJSON obj <*> parseJSON obj
354358
| msgType == msgSettingsSave = SBPMsgSettingsSave <$> parseJSON obj <*> parseJSON obj
355359
| msgType == msgSettingsWrite = SBPMsgSettingsWrite <$> parseJSON obj <*> parseJSON obj
356360
| msgType == msgStartup = SBPMsgStartup <$> parseJSON obj <*> parseJSON obj
@@ -433,6 +437,7 @@ instance ToJSON SBPMsg where
433437
toJSON (SBPMsgSettingsReadByIndexResp n m) = toJSON n `mergeValues` toJSON m
434438
toJSON (SBPMsgSettingsReadReq n m) = toJSON n `mergeValues` toJSON m
435439
toJSON (SBPMsgSettingsReadResp n m) = toJSON n `mergeValues` toJSON m
440+
toJSON (SBPMsgSettingsRegister n m) = toJSON n `mergeValues` toJSON m
436441
toJSON (SBPMsgSettingsSave n m) = toJSON n `mergeValues` toJSON m
437442
toJSON (SBPMsgSettingsWrite n m) = toJSON n `mergeValues` toJSON m
438443
toJSON (SBPMsgStartup n m) = toJSON n `mergeValues` toJSON m
@@ -509,6 +514,7 @@ instance HasMsg SBPMsg where
509514
msg f (SBPMsgSettingsReadByIndexResp n m) = SBPMsgSettingsReadByIndexResp n <$> f m
510515
msg f (SBPMsgSettingsReadReq n m) = SBPMsgSettingsReadReq n <$> f m
511516
msg f (SBPMsgSettingsReadResp n m) = SBPMsgSettingsReadResp n <$> f m
517+
msg f (SBPMsgSettingsRegister n m) = SBPMsgSettingsRegister n <$> f m
512518
msg f (SBPMsgSettingsSave n m) = SBPMsgSettingsSave n <$> f m
513519
msg f (SBPMsgSettingsWrite n m) = SBPMsgSettingsWrite n <$> f m
514520
msg f (SBPMsgStartup n m) = SBPMsgStartup n <$> f m

haskell/src/SwiftNav/SBP/Settings.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,31 @@ $(deriveSBP 'msgSettingsReadByIndexDone ''MsgSettingsReadByIndexDone)
217217
$(deriveJSON defaultOptions {fieldLabelModifier = fromMaybe "_msgSettingsReadByIndexDone_" . stripPrefix "_msgSettingsReadByIndexDone_"}
218218
''MsgSettingsReadByIndexDone)
219219
$(makeLenses ''MsgSettingsReadByIndexDone)
220+
221+
msgSettingsRegister :: Word16
222+
msgSettingsRegister = 0x00AE
223+
224+
-- | SBP class for message MSG_SETTINGS_REGISTER (0x00AE).
225+
--
226+
-- This message registers the presence and default value of a setting with a
227+
-- settings daemon. The host should reply with MSG_SETTINGS_WRITE for this
228+
-- setting to set the initial value.
229+
data MsgSettingsRegister = MsgSettingsRegister
230+
{ _msgSettingsRegister_setting :: ByteString
231+
-- ^ A NULL-terminated and delimited string with contents [SECTION_SETTING,
232+
-- SETTING, VALUE].
233+
} deriving ( Show, Read, Eq )
234+
235+
instance Binary MsgSettingsRegister where
236+
get = do
237+
_msgSettingsRegister_setting <- liftM toStrict getRemainingLazyByteString
238+
return MsgSettingsRegister {..}
239+
240+
put MsgSettingsRegister {..} = do
241+
putByteString _msgSettingsRegister_setting
242+
243+
$(deriveSBP 'msgSettingsRegister ''MsgSettingsRegister)
244+
245+
$(deriveJSON defaultOptions {fieldLabelModifier = fromMaybe "_msgSettingsRegister_" . stripPrefix "_msgSettingsRegister_"}
246+
''MsgSettingsRegister)
247+
$(makeLenses ''MsgSettingsRegister)

java/src/com/swiftnav/sbp/client/MessageTable.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import com.swiftnav.sbp.settings.MsgSettingsReadByIndexReq;
5656
import com.swiftnav.sbp.settings.MsgSettingsReadByIndexResp;
5757
import com.swiftnav.sbp.settings.MsgSettingsReadByIndexDone;
58+
import com.swiftnav.sbp.settings.MsgSettingsRegister;
5859
import com.swiftnav.sbp.navigation.MsgGPSTime;
5960
import com.swiftnav.sbp.navigation.MsgDops;
6061
import com.swiftnav.sbp.navigation.MsgPosECEF;
@@ -171,6 +172,8 @@ static SBPMessage dispatch(SBPMessage msg) throws SBPBinaryException {
171172
return new MsgSettingsReadByIndexResp(msg);
172173
case MsgSettingsReadByIndexDone.TYPE:
173174
return new MsgSettingsReadByIndexDone(msg);
175+
case MsgSettingsRegister.TYPE:
176+
return new MsgSettingsRegister(msg);
174177
case MsgGPSTime.TYPE:
175178
return new MsgGPSTime(msg);
176179
case MsgDops.TYPE:
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (C) 2015 Swift Navigation Inc.
3+
* Contact: Gareth McMullin <[email protected]>
4+
* Contact: Bhaskar Mookerji <[email protected]>
5+
*
6+
* This source is subject to the license found in the file 'LICENSE' which must
7+
* be be distributed together with this source. All other rights reserved.
8+
*
9+
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
10+
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
11+
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
12+
*/
13+
14+
package com.swiftnav.sbp.settings;
15+
16+
import com.swiftnav.sbp.SBPMessage;
17+
import com.swiftnav.sbp.SBPBinaryException;
18+
import com.swiftnav.sbp.SBPStruct;
19+
20+
import org.json.JSONObject;
21+
import org.json.JSONArray;
22+
23+
24+
/** SBP class for message MSG_SETTINGS_REGISTER (0x00AE).
25+
*
26+
* You can have MSG_SETTINGS_REGISTER inherent its fields directly from
27+
* an inherited SBP object, or construct it inline using a dict of its
28+
* fields.
29+
*
30+
* This message registers the presence and default value of a setting
31+
* with a settings daemon. The host should reply with MSG_SETTINGS_WRITE
32+
* for this setting to set the initial value. */
33+
34+
public class MsgSettingsRegister extends SBPMessage {
35+
public static final int TYPE = 0x00AE;
36+
37+
38+
/** A NULL-terminated and delimited string with contents
39+
[SECTION_SETTING, SETTING, VALUE].
40+
*/
41+
public String setting;
42+
43+
44+
public MsgSettingsRegister (int sender) { super(sender, TYPE); }
45+
public MsgSettingsRegister () { super(TYPE); }
46+
public MsgSettingsRegister (SBPMessage msg) throws SBPBinaryException {
47+
super(msg);
48+
assert msg.type != TYPE;
49+
}
50+
51+
@Override
52+
protected void parse(Parser parser) throws SBPBinaryException {
53+
/* Parse fields from binary */
54+
setting = parser.getString();
55+
}
56+
57+
@Override
58+
protected void build(Builder builder) {
59+
builder.putString(setting);
60+
}
61+
62+
@Override
63+
public JSONObject toJSON() {
64+
JSONObject obj = super.toJSON();
65+
obj.put("setting", setting);
66+
return obj;
67+
}
68+
}

javascript/sbp/acquisition.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ var GnssSignal = require("./gnss_signal").GnssSignal;
3939
*
4040
* @param sbp An SBP object with a payload to be decoded.
4141
*/
42-
var MsgAcqResult = function (sbp) {
42+
var MsgAcqResult = function (sbp, fields) {
4343
SBP.call(this, sbp);
4444
this.messageType = "MSG_ACQ_RESULT";
45-
this.fields = this.parser.parse(sbp.payload);
45+
this.fields = (fields || this.parser.parse(sbp.payload));
4646

4747
return this;
4848
};
@@ -75,10 +75,10 @@ MsgAcqResult.prototype.fieldSpec.push(['sid', GnssSignal.prototype.fieldSpec]);
7575
*
7676
* @param sbp An SBP object with a payload to be decoded.
7777
*/
78-
var MsgAcqResultDepA = function (sbp) {
78+
var MsgAcqResultDepA = function (sbp, fields) {
7979
SBP.call(this, sbp);
8080
this.messageType = "MSG_ACQ_RESULT_DEP_A";
81-
this.fields = this.parser.parse(sbp.payload);
81+
this.fields = (fields || this.parser.parse(sbp.payload));
8282

8383
return this;
8484
};

javascript/sbp/bootload.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ var Parser = require('binary-parser').Parser;
3232
*
3333
* @param sbp An SBP object with a payload to be decoded.
3434
*/
35-
var MsgBootloaderHandshakeReq = function (sbp) {
35+
var MsgBootloaderHandshakeReq = function (sbp, fields) {
3636
SBP.call(this, sbp);
3737
this.messageType = "MSG_BOOTLOADER_HANDSHAKE_REQ";
38-
this.fields = this.parser.parse(sbp.payload);
38+
this.fields = (fields || this.parser.parse(sbp.payload));
3939

4040
return this;
4141
};
@@ -60,10 +60,10 @@ MsgBootloaderHandshakeReq.prototype.fieldSpec = [];
6060
*
6161
* @param sbp An SBP object with a payload to be decoded.
6262
*/
63-
var MsgBootloaderHandshakeResp = function (sbp) {
63+
var MsgBootloaderHandshakeResp = function (sbp, fields) {
6464
SBP.call(this, sbp);
6565
this.messageType = "MSG_BOOTLOADER_HANDSHAKE_RESP";
66-
this.fields = this.parser.parse(sbp.payload);
66+
this.fields = (fields || this.parser.parse(sbp.payload));
6767

6868
return this;
6969
};
@@ -88,10 +88,10 @@ MsgBootloaderHandshakeResp.prototype.fieldSpec.push(['version', 'string']);
8888
*
8989
* @param sbp An SBP object with a payload to be decoded.
9090
*/
91-
var MsgBootloaderJumpToApp = function (sbp) {
91+
var MsgBootloaderJumpToApp = function (sbp, fields) {
9292
SBP.call(this, sbp);
9393
this.messageType = "MSG_BOOTLOADER_JUMP_TO_APP";
94-
this.fields = this.parser.parse(sbp.payload);
94+
this.fields = (fields || this.parser.parse(sbp.payload));
9595

9696
return this;
9797
};
@@ -115,10 +115,10 @@ MsgBootloaderJumpToApp.prototype.fieldSpec.push(['jump', 'writeUInt8', 1]);
115115
*
116116
* @param sbp An SBP object with a payload to be decoded.
117117
*/
118-
var MsgNapDeviceDnaReq = function (sbp) {
118+
var MsgNapDeviceDnaReq = function (sbp, fields) {
119119
SBP.call(this, sbp);
120120
this.messageType = "MSG_NAP_DEVICE_DNA_REQ";
121-
this.fields = this.parser.parse(sbp.payload);
121+
this.fields = (fields || this.parser.parse(sbp.payload));
122122

123123
return this;
124124
};
@@ -143,10 +143,10 @@ MsgNapDeviceDnaReq.prototype.fieldSpec = [];
143143
*
144144
* @param sbp An SBP object with a payload to be decoded.
145145
*/
146-
var MsgNapDeviceDnaResp = function (sbp) {
146+
var MsgNapDeviceDnaResp = function (sbp, fields) {
147147
SBP.call(this, sbp);
148148
this.messageType = "MSG_NAP_DEVICE_DNA_RESP";
149-
this.fields = this.parser.parse(sbp.payload);
149+
this.fields = (fields || this.parser.parse(sbp.payload));
150150

151151
return this;
152152
};
@@ -169,10 +169,10 @@ MsgNapDeviceDnaResp.prototype.fieldSpec.push(['dna', 'array', 'writeUInt8', func
169169
*
170170
* @param sbp An SBP object with a payload to be decoded.
171171
*/
172-
var MsgBootloaderHandshakeDepA = function (sbp) {
172+
var MsgBootloaderHandshakeDepA = function (sbp, fields) {
173173
SBP.call(this, sbp);
174174
this.messageType = "MSG_BOOTLOADER_HANDSHAKE_DEP_A";
175-
this.fields = this.parser.parse(sbp.payload);
175+
this.fields = (fields || this.parser.parse(sbp.payload));
176176

177177
return this;
178178
};

javascript/sbp/construct.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright (C) 2015 Swift Navigation Inc.
3+
* Contact: Joshua Gross <[email protected]>
4+
* This source is subject to the license found in the file 'LICENSE' which must
5+
* be distributed together with this source. All other rights reserved.
6+
*
7+
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
8+
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
9+
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
10+
*
11+
* This module is for constructing arbitrary SBP messages.
12+
*/
13+
14+
var sbp = require('./index.js');
15+
var SBP = require('./sbp.js');
16+
var crc = sbp.crc16;
17+
18+
/**
19+
* Construct a full SBP message, including the message envelope
20+
* and internal fields. Also calculates the CRC for you.
21+
*
22+
* @param MsgType {Function} The message type you want to construct.
23+
* @param fields {Object} Optional key-value pairs of message fields.
24+
*/
25+
module.exports = function constructMsg (MsgType, fields) {
26+
if (typeof MsgType !== 'function') {
27+
throw new Error('The MsgType parameter must be a valid SBP message type constructor.');
28+
}
29+
30+
if (typeof MsgType.prototype.msg_type !== 'number') {
31+
throw new Error('The MsgType must have a valid `msg_type` field.');
32+
}
33+
34+
fields = fields || {};
35+
36+
// Msg envelope
37+
var msgEnvelope = new SBP({});
38+
39+
// Message
40+
var msg = new MsgType(msgEnvelope, fields);
41+
msgEnvelope.payload = msg.payloadToBuffer();
42+
43+
// Construct message envelope
44+
msgEnvelope.preamble = sbp.preambleByte;
45+
msgEnvelope.msg_type = MsgType.prototype.msg_type;
46+
msgEnvelope.sender = 0; // see SBP.pdf documentation
47+
msgEnvelope.length = msgEnvelope.payload.length;
48+
msgEnvelope.crc = crc(msgEnvelope.payload,
49+
crc(msgEnvelope.getLengthBuffer(),
50+
crc(msgEnvelope.getSenderBuffer(),
51+
crc(msgEnvelope.getMsgTypeBuffer()))));
52+
53+
return msgEnvelope;
54+
};

0 commit comments

Comments
 (0)