Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
woodfell committed Dec 8, 2023
1 parent cc032f9 commit c9e6203
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 61 deletions.
4 changes: 2 additions & 2 deletions c/include/libsbp/legacy/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ typedef struct SBP_ATTR_PACKED {
u32 max; /**< Maximum execution time */
u64 return_addr; /**< Return address */
u64 id; /**< Unique ID */
s64 slice_time; /**< CPU slice time */
s16 line; /**< Line number */
u64 slice_time; /**< CPU slice time */
u16 line; /**< Line number */
char func[0]; /**< Function name */
} msg_measurement_point_t;

Expand Down
4 changes: 2 additions & 2 deletions c/include/libsbp/v4/system/MSG_MEASUREMENT_POINT.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ typedef struct {
/**
* CPU slice time
*/
s64 slice_time;
u64 slice_time;

/**
* Line number
*/
s16 line;
u16 line;

/**
* Function name
Expand Down
12 changes: 6 additions & 6 deletions c/src/v4/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -1945,10 +1945,10 @@ bool sbp_msg_measurement_point_encode_internal(
if (!sbp_u64_encode(ctx, &msg->id)) {
return false;
}
if (!sbp_s64_encode(ctx, &msg->slice_time)) {
if (!sbp_u64_encode(ctx, &msg->slice_time)) {
return false;
}
if (!sbp_s16_encode(ctx, &msg->line)) {
if (!sbp_u16_encode(ctx, &msg->line)) {
return false;
}
if (!sbp_null_terminated_string_encode(
Expand Down Expand Up @@ -1994,10 +1994,10 @@ bool sbp_msg_measurement_point_decode_internal(
if (!sbp_u64_decode(ctx, &msg->id)) {
return false;
}
if (!sbp_s64_decode(ctx, &msg->slice_time)) {
if (!sbp_u64_decode(ctx, &msg->slice_time)) {
return false;
}
if (!sbp_s16_decode(ctx, &msg->line)) {
if (!sbp_u16_decode(ctx, &msg->line)) {
return false;
}
if (!sbp_null_terminated_string_decode(
Expand Down Expand Up @@ -2071,12 +2071,12 @@ int sbp_msg_measurement_point_cmp(const sbp_msg_measurement_point_t *a,
return ret;
}

ret = sbp_s64_cmp(&a->slice_time, &b->slice_time);
ret = sbp_u64_cmp(&a->slice_time, &b->slice_time);
if (ret != 0) {
return ret;
}

ret = sbp_s16_cmp(&a->line, &b->line);
ret = sbp_u16_cmp(&a->line, &b->line);
if (ret != 0) {
return ret;
}
Expand Down
34 changes: 18 additions & 16 deletions haskell/src/SwiftNav/SBP/System.hs
Original file line number Diff line number Diff line change
Expand Up @@ -581,26 +581,28 @@ msgMeasurementPoint = 0xFF0B

-- | SBP class for message MSG_MEASUREMENT_POINT (0xFF0B).
--
-- Measurement point.
-- Tracks execution time of certain code paths in specially built products.
-- This message should only be expected and processed on the direction of
-- Swift's engineering teams.
data MsgMeasurementPoint = MsgMeasurementPoint
{ _msgMeasurementPoint_total_time :: !Word32
-- ^ total time
-- ^ Total time spent in measurement point
, _msgMeasurementPoint_num_executions :: !Word16
-- ^ num executions
-- ^ Number of times measurement point has executed
, _msgMeasurementPoint_min :: !Word32
-- ^ min
-- ^ Minimum execution time
, _msgMeasurementPoint_max :: !Word32
-- ^ max
-- ^ Maximum execution time
, _msgMeasurementPoint_return_addr :: !Word64
-- ^ return addr
-- ^ Return address
, _msgMeasurementPoint_id :: !Word64
-- ^ id
, _msgMeasurementPoint_slice_time :: !Int64
-- ^ slice_time
, _msgMeasurementPoint_line :: !Int16
-- ^ line
-- ^ Unique ID
, _msgMeasurementPoint_slice_time :: !Word64
-- ^ CPU slice time
, _msgMeasurementPoint_line :: !Word16
-- ^ Line number
, _msgMeasurementPoint_func :: !Text
-- ^ func
-- ^ Function name
} deriving ( Show, Read, Eq )

instance Binary MsgMeasurementPoint where
Expand All @@ -611,8 +613,8 @@ instance Binary MsgMeasurementPoint where
_msgMeasurementPoint_max <- getWord32le
_msgMeasurementPoint_return_addr <- getWord64le
_msgMeasurementPoint_id <- getWord64le
_msgMeasurementPoint_slice_time <- (fromIntegral <$> getWord64le)
_msgMeasurementPoint_line <- (fromIntegral <$> getWord16le)
_msgMeasurementPoint_slice_time <- getWord64le
_msgMeasurementPoint_line <- getWord16le
_msgMeasurementPoint_func <- decodeUtf8 . toStrict <$> getRemainingLazyByteString
pure MsgMeasurementPoint {..}

Expand All @@ -623,8 +625,8 @@ instance Binary MsgMeasurementPoint where
putWord32le _msgMeasurementPoint_max
putWord64le _msgMeasurementPoint_return_addr
putWord64le _msgMeasurementPoint_id
(putWord64le . fromIntegral) _msgMeasurementPoint_slice_time
(putWord16le . fromIntegral) _msgMeasurementPoint_line
putWord64le _msgMeasurementPoint_slice_time
putWord16le _msgMeasurementPoint_line
putByteString $ encodeUtf8 _msgMeasurementPoint_func

$(makeSBP 'msgMeasurementPoint ''MsgMeasurementPoint)
Expand Down
7 changes: 7 additions & 0 deletions java/src/com/swiftnav/sbp/SBPMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ public BigInteger getU64() {
return new BigInteger(1, tmp);
}

public BigInteger getS64() {
byte[] tmp = new byte[8];
buf.get(tmp, 0, 8);
tmp = new byte[] {tmp[7], tmp[6], tmp[5], tmp[4], tmp[3], tmp[2], tmp[1], tmp[0]};
return new BigInteger(tmp);
}

public float getFloat() {
return buf.getFloat();
}
Expand Down
8 changes: 4 additions & 4 deletions java/src/com/swiftnav/sbp/system/MsgMeasurementPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ protected void parse(Parser parser) throws SBPBinaryException {
max = parser.getU32();
return_addr = parser.getU64();
id = parser.getU64();
slice_time = parser.getS64();
line = parser.getS16();
slice_time = parser.getU64();
line = parser.getU16();
func = parser.getString();
}

Expand All @@ -95,8 +95,8 @@ protected void build(Builder builder) {
builder.putU32(max);
builder.putU64(return_addr);
builder.putU64(id);
builder.putS64(slice_time);
builder.putS16(line);
builder.putU64(slice_time);
builder.putU16(line);
builder.putString(func);
}

Expand Down
2 changes: 1 addition & 1 deletion javascript/sbp.bundle.js

Large diffs are not rendered by default.

30 changes: 16 additions & 14 deletions javascript/sbp/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,18 +586,20 @@ MsgGroupMeta.prototype.fieldSpec.push(['group_msgs', 'array', 'writeUInt16LE', f
/**
* SBP class for message MSG_MEASUREMENT_POINT (0xFF0B).
*
* Measurement point.
* Tracks execution time of certain code paths in specially built products. This
* message should only be expected and processed on the direction of Swift's
* engineering teams.
*
* Fields in the SBP payload (`sbp.payload`):
* @field total_time number (unsigned 32-bit int, 4 bytes) total time
* @field num_executions number (unsigned 16-bit int, 2 bytes) num executions
* @field min number (unsigned 32-bit int, 4 bytes) min
* @field max number (unsigned 32-bit int, 4 bytes) max
* @field return_addr number (unsigned 64-bit int, 8 bytes) return addr
* @field id number (unsigned 64-bit int, 8 bytes) id
* @field slice_time number (signed 64-bit int, 4 bytes) slice_time
* @field line number (signed 16-bit int, 2 bytes) line
* @field func string func
* @field total_time number (unsigned 32-bit int, 4 bytes) Total time spent in measurement point
* @field num_executions number (unsigned 16-bit int, 2 bytes) Number of times measurement point has executed
* @field min number (unsigned 32-bit int, 4 bytes) Minimum execution time
* @field max number (unsigned 32-bit int, 4 bytes) Maximum execution time
* @field return_addr number (unsigned 64-bit int, 8 bytes) Return address
* @field id number (unsigned 64-bit int, 8 bytes) Unique ID
* @field slice_time number (unsigned 64-bit int, 8 bytes) CPU slice time
* @field line number (unsigned 16-bit int, 2 bytes) Line number
* @field func string Function name
*
* @param sbp An SBP object with a payload to be decoded.
*/
Expand All @@ -620,8 +622,8 @@ MsgMeasurementPoint.prototype.parser = new Parser()
.uint32('max')
.uint64('return_addr')
.uint64('id')
.int64('slice_time')
.int16('line')
.uint64('slice_time')
.uint16('line')
.string('func', { greedy: true });
MsgMeasurementPoint.prototype.fieldSpec = [];
MsgMeasurementPoint.prototype.fieldSpec.push(['total_time', 'writeUInt32LE', 4]);
Expand All @@ -630,8 +632,8 @@ MsgMeasurementPoint.prototype.fieldSpec.push(['min', 'writeUInt32LE', 4]);
MsgMeasurementPoint.prototype.fieldSpec.push(['max', 'writeUInt32LE', 4]);
MsgMeasurementPoint.prototype.fieldSpec.push(['return_addr', 'writeUInt64LE', 8]);
MsgMeasurementPoint.prototype.fieldSpec.push(['id', 'writeUInt64LE', 8]);
MsgMeasurementPoint.prototype.fieldSpec.push(['slice_time', 'writeInt64LE', 8]);
MsgMeasurementPoint.prototype.fieldSpec.push(['line', 'writeInt16LE', 2]);
MsgMeasurementPoint.prototype.fieldSpec.push(['slice_time', 'writeUInt64LE', 8]);
MsgMeasurementPoint.prototype.fieldSpec.push(['line', 'writeUInt16LE', 2]);
MsgMeasurementPoint.prototype.fieldSpec.push(['func', 'string', null]);

module.exports = {
Expand Down
3 changes: 2 additions & 1 deletion javascript/tests/test_dispatch_decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ describe('test packages based on YAML descriptors, through the dispatcher', func

if (filename.indexOf('test_MsgFlashDone.yaml') === -1 &&
filename.indexOf('test_MsgM25FlashWriteStatus.yaml') === -1 &&
filename.indexOf('test_MsgBootloaderJumptoApp.yaml') === -1) {
filename.indexOf('test_MsgBootloaderJumptoApp.yaml') === -1 &&
filename.indexOf('test_MsgMeasurementPoint.yaml') === -1) {
it('should parse binary sbp and payload with leading truncated message', function (done) {
var rs = new Readable();
var packetBuf = new Buffer(testSpec['raw_packet'], 'base64');
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sbp",
"version": "5.0.5-alpha",
"version": "5.0.4-alpha",
"description": "libsbp bindings for JavaScript. More information here: http://swift-nav.github.io/libsbp/",
"files": [
"javascript/*",
Expand Down
2 changes: 1 addition & 1 deletion python/tests/sbp/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_table_count():
Test number of available messages to deserialize.
"""
number_of_messages = 233
number_of_messages = 234
assert len(_SBP_TABLE) == number_of_messages

def test_table_unqiue_count():
Expand Down
3 changes: 3 additions & 0 deletions python/tests/sbp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ def _assert_msg_roundtrip_json(msg, raw_json):
"""
to_json = json.loads(msg.to_json())
from_json = json.loads(raw_json)
if sorted(to_json.items()) != sorted(from_json.items()):
print("to_json: {}".format(to_json))
print("from_json: {}".format(from_json))
assert sorted(to_json.items()) == sorted(from_json.items())
assert msg == msg.from_json(raw_json)

Expand Down
8 changes: 4 additions & 4 deletions rust/sbp/src/messages/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1874,10 +1874,10 @@ pub mod msg_measurement_point {
pub id: u64,
/// CPU slice time
#[cfg_attr(feature = "serde", serde(rename = "slice_time"))]
pub slice_time: i64,
pub slice_time: u64,
/// Line number
#[cfg_attr(feature = "serde", serde(rename = "line"))]
pub line: i16,
pub line: u16,
/// Function name
#[cfg_attr(feature = "serde", serde(rename = "func"))]
pub func: SbpString<Vec<u8>, NullTerminated>,
Expand Down Expand Up @@ -1935,8 +1935,8 @@ pub mod msg_measurement_point {
+ <u32 as WireFormat>::MIN_LEN
+ <u64 as WireFormat>::MIN_LEN
+ <u64 as WireFormat>::MIN_LEN
+ <i64 as WireFormat>::MIN_LEN
+ <i16 as WireFormat>::MIN_LEN
+ <u64 as WireFormat>::MIN_LEN
+ <u16 as WireFormat>::MIN_LEN
+ <SbpString<Vec<u8>, NullTerminated> as WireFormat>::MIN_LEN;
fn len(&self) -> usize {
WireFormat::len(&self.total_time)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ fn test_auto_check_sbp_system_msg_measurement_point() {
#[cfg(feature = "json")]
fn test_json2sbp_auto_check_sbp_system_msg_measurement_point() {
{
let json_input = r#"{"crc": 18333, "preamble": 85, "sender": 4096, "length": 48, "total_time": 2042, "num_executions": 180, "min": 2, "max": 40, "return_addr": 93877475527042, "id": 2496234002, "slice_time": 261963842, "line": 18, "func": "route()\u0000", "payload": "+gcAALQAAgAAACgAAACCyZSNYVUAABKCyZQAAAAAQkCdDwAAAAASAHJvdXRlKCkA" }
"#.as_bytes();
let json_input = r#"{"crc": 18333, "preamble": 85, "sender": 4096, "length": 48, "msg_type": 65291, "total_time": 2042, "num_executions": 180, "min": 2, "max": 40, "return_addr": 93877475527042, "id": 2496234002, "slice_time": 261963842, "line": 18, "func": "route()\u0000", "payload": "+gcAALQAAgAAACgAAACCyZSNYVUAABKCyZQAAAAAQkCdDwAAAAASAHJvdXRlKCkA" }"#.as_bytes();

let sbp_msg = {
// JSON to SBP message from payload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ tests:
module: sbp.system
name: MsgMeasurementPoint
msg_type: '0xFF0B'
raw_json: >
{"crc": 18333, "preamble": 85, "sender": 4096, "length": 48,
raw_json: '{"crc": 18333, "preamble": 85, "sender": 4096, "length": 48, "msg_type": 65291,
"total_time": 2042, "num_executions": 180, "min": 2, "max": 40,
"return_addr": 93877475527042, "id": 2496234002,
"slice_time": 261963842, "line": 18, "func": "route()\u0000",
"payload": "+gcAALQAAgAAACgAAACCyZSNYVUAABKCyZQAAAAAQkCdDwAAAAASAHJvdXRlKCkA"
}
}'

raw_packet: VQv/ABAw+gcAALQAAgAAACgAAACCyZSNYVUAABKCyZQAAAAAQkCdDwAAAAASAHJvdXRlKCkAnUc=
sbp:
Expand Down
4 changes: 2 additions & 2 deletions spec/yaml/swiftnav/sbp/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,10 @@ definitions:
type: u64
desc: Unique ID
- slice_time:
type: s64
type: u64
desc: CPU slice time
- line:
type: s16
type: u16
desc: Line number
- func:
type: string
Expand Down

0 comments on commit c9e6203

Please sign in to comment.