Skip to content

Commit

Permalink
Support 64-bit unsigned ints in the JavaScript version of libsbp. All…
Browse files Browse the repository at this point in the history
… messages are round-tripped through construction and decoding, even if there aren't any test yaml files for them.
  • Loading branch information
JoshuaGross committed Oct 27, 2016
1 parent 7c74e9a commit 27f6f3c
Show file tree
Hide file tree
Showing 25 changed files with 758 additions and 105 deletions.
51 changes: 45 additions & 6 deletions c/include/libsbp/tracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,48 @@

#include "common.h"
#include "gnss_signal.h"
#include "observation.h"


/** Satellite tracking channel state
/** Detailed signal tracking channel states
*
* The tracking message returns a set tracking channel parameters for a
* single tracking channel useful for debugging issues.
*/
#define SBP_MSG_TRACKING_STATE_DETAILED 0x0011
typedef struct __attribute__((packed)) {
u64 recv_time; /**< Receiver clock time. [ns] */
obs_gps_time_t tot; /**< Time of transmission of signal from satellite. */
u32 P; /**< Pseudorange observation. [2 cm] */
u16 P_std; /**< Pseudorange observation standard deviation. [2 cm] */
carrier_phase_t L; /**< Carrier phase observation with typical sign convention. Only valid
when PLL pessimistic lock is achieved.
[cycles] */
u8 cn0; /**< Carrier-to-Noise density [dB Hz * 4] */
u16 lock; /**< Lock indicator. This value changes whenever a satellite
signal has lost and regained lock, indicating that the
carrier phase ambiguity may have changed.
*/
sbp_gnss_signal_t sid; /**< GNSS signal identifier. */
s32 doppler; /**< Carrier Doppler frequency. [Hz * 10] */
u16 doppler_std; /**< Carrier Doppler frequency standard deviation. [Hz * 10] */
u32 uptime; /**< Number of seconds of continuous tracking. Specifies how much time
signal is in continuous track.
[s] */
u16 clock_offset; /**< TCXO clock offset. [ppb * 10] */
u16 clock_drift; /**< TCXO clock drift. [(ppb * 10) / s] */
u16 corr_spacing; /**< Early-Prompt (EP) and Prompt-Late (PL) correlators spacing. [ns] */
u8 acceleration; /**< Acceleration. Valid only when acceleration valid flag is set. [g * 10] */
u8 sync_flags; /**< Synchronization status flags. */
u8 tow_flags; /**< TOW status flags. */
u8 track_flags; /**< Tracking loop status flags. */
u8 nav_flags; /**< Navigation data status flags. */
u8 pset_flags; /**< Parameters sets flags. */
u8 misc_flags; /**< Miscellaneous flags. */
} msg_tracking_state_detailed_t;


/** Signal tracking channel state
*
* Tracking channel state for a specific satellite signal and
* measured signal power.
Expand All @@ -39,15 +78,15 @@ typedef struct __attribute__((packed)) {
} tracking_channel_state_t;


/** Satellite tracking channel states
/** Signal tracking channel states
*
* The tracking message returns a variable-length array of tracking
* channel states. It reports status and carrier-to-noise density
* measurements for all tracked satellites.
*/
#define SBP_MSG_TRACKING_STATE 0x0013
#define SBP_MSG_TRACKING_STATE 0x0013
typedef struct __attribute__((packed)) {
tracking_channel_state_t states[0]; /**< Satellite tracking channel state */
tracking_channel_state_t states[0]; /**< Signal tracking channel state */
} msg_tracking_state_t;


Expand All @@ -66,7 +105,7 @@ typedef struct __attribute__((packed)) {
* When enabled, a tracking channel can output the correlations at each
* update interval.
*/
#define SBP_MSG_TRACKING_IQ 0x001C
#define SBP_MSG_TRACKING_IQ 0x001C
typedef struct __attribute__((packed)) {
u8 channel; /**< Tracking channel of origin */
sbp_gnss_signal_t sid; /**< GNSS signal identifier */
Expand All @@ -89,7 +128,7 @@ typedef struct __attribute__((packed)) {
*
* Deprecated.
*/
#define SBP_MSG_TRACKING_STATE_DEP_A 0x0016
#define SBP_MSG_TRACKING_STATE_DEP_A 0x0016
typedef struct __attribute__((packed)) {
tracking_channel_state_dep_a_t states[0]; /**< Satellite tracking channel state */
} msg_tracking_state_dep_a_t;
Expand Down
25 changes: 22 additions & 3 deletions generator/sbpg/targets/javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
'u8': 'writeUInt8',
'u16': 'writeUInt16LE',
'u32': 'writeUInt32LE',
'u64': 'writeUIntLE', # only supports up to 48 bits of accuracy
'u64': 'writeUInt64LE', # only supports up to 48 bits of accuracy
's8': 'writeInt8',
's16': 'writeInt16LE',
's32': 'writeInt32LE',
's64': 'writeIntLE', # only supports up to 48 bits of accuracy
's64': 'writeInt64LE', # only supports up to 48 bits of accuracy
'float': 'writeFloatLE',
'double': 'writeDoubleLE',
}
Expand Down Expand Up @@ -97,6 +97,19 @@ def buffer_size(type_id, type_map=BUFFER_SIZE_MAP):
else:
return "this.fields.%s.length" % type_id.identifier

def array_fill_size(f):
if builtin_type(f.options['fill'].value):
return buffer_size(f.options['fill'].value)
else:
return buffer_size(f.type_id)

def array_length(f):
if 'size' in f.options:
return f.options.get('size').value
if 'size_fn' in f.options:
return "'%s'" % f.options.get('size_fn').value
return 'null'

def jsdoc_format(type_id, jsdoc=JSDOC_CODE):
"""
Formats type for jsdoc.
Expand Down Expand Up @@ -151,11 +164,17 @@ def star_wordwrap(s):
def star_wordwrap_indent(s):
return "\n * ".join(textwrap.wrap(' '.join(s.split('\n')), 80))

def islist(x):
return isinstance(x, list)

JENV.tests['builtinType'] = builtin_type
JENV.tests['list'] = islist

JENV.filters['js_classnameify'] = js_classnameify
JENV.filters['writeBuffer'] = write_buffer
JENV.filters['bufferSize'] = buffer_size
JENV.filters['arrayFillSize'] = array_fill_size
JENV.filters['arrayLength'] = array_length
JENV.filters['construct_js'] = construct_format
JENV.filters['jsdoc'] = jsdoc_format
JENV.filters['starWordWrap'] = star_wordwrap
Expand All @@ -171,7 +190,7 @@ def render_source(output_dir, package_spec, jenv=JENV):
destination_filename = "%s/%s.js" % (directory, name)
py_template = jenv.get_template(TEMPLATE_NAME)
module_path = ".".join(package_spec.identifier.split(".")[1:-1])
includeMap = {'gnss_signal':'GnssSignal'}
includeMap = {'gnss_signal':'GnssSignal', 'observation': ['ObsGPSTime', 'CarrierPhase'] }
includes = [".".join(i.split(".")[:-1]) for i in package_spec.includes]
includes = [(i, includeMap.get(i)) for i in includes if i != "types"]
with open(destination_filename, 'w') as f:
Expand Down
16 changes: 12 additions & 4 deletions generator/sbpg/targets/resources/sbp_js.js.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@
***********************/

var SBP = require('./sbp');
var Parser = require('binary-parser').Parser;
var Parser = require('./parser');
var Int64 = require('node-int64');
var UInt64 = require('cuint').UINT64;
((*- for (file, ident) in include *))
((*- if ident is list *))
((*- for ident2 in ident *))
var (((ident2))) = require("./(((file)))").(((ident2)));
((*- endfor *))
((*- else *))
var (((ident))) = require("./(((file)))").(((ident)));
((*- endif *))
((*- endfor *))

((*- for m in msgs *))
Expand Down Expand Up @@ -60,11 +68,11 @@ var ((( m.identifier | js_classnameify ))) = function (sbp, fields) {
((*- if f.type_id is builtinType *))
((( m.identifier | js_classnameify ))).prototype.fieldSpec.push(['(((f.identifier)))', '(((f.type_id | writeBuffer)))', (((f.type_id | bufferSize)))]);
((*- elif f.type_id == 'array' and f.options['fill'].value is builtinType *))
((( m.identifier | js_classnameify ))).prototype.fieldSpec.push(['(((f.identifier)))', 'array', '(((f.options['fill'].value | writeBuffer)))', function () { return (((f.options['fill'].value | bufferSize))); }]);
((( m.identifier | js_classnameify ))).prototype.fieldSpec.push(['(((f.identifier)))', 'array', '(((f.options['fill'].value | writeBuffer)))', function () { return (((f | arrayFillSize))); }, ((( f | arrayLength )))]);
((*- elif f.type_id == 'array' *))
((( m.identifier | js_classnameify ))).prototype.fieldSpec.push(['(((f.identifier)))', 'array', ((( f.options['fill'].value ))).prototype.fieldSpec, function () { return (((f.type_id | bufferSize))); }]);
((( m.identifier | js_classnameify ))).prototype.fieldSpec.push(['(((f.identifier)))', 'array', ((( f.options['fill'].value ))).prototype.fieldSpec, function () { return (((f | arrayFillSize))); }, ((( f | arrayLength )))]);
((*- elif f.type_id == 'string' *))
((( m.identifier | js_classnameify ))).prototype.fieldSpec.push(['(((f.identifier)))', 'string']);
((( m.identifier | js_classnameify ))).prototype.fieldSpec.push(['(((f.identifier)))', 'string', ((( f | arrayLength )))]);
((*- else *))
((( m.identifier | js_classnameify ))).prototype.fieldSpec.push(['(((f.identifier)))', ((( f.type_id ))).prototype.fieldSpec]);
((*- endif *))
Expand Down
24 changes: 13 additions & 11 deletions javascript/sbp/acquisition.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
***********************/

var SBP = require('./sbp');
var Parser = require('binary-parser').Parser;
var Parser = require('./parser');
var Int64 = require('node-int64');
var UInt64 = require('cuint').UINT64;
var GnssSignal = require("./gnss_signal").GnssSignal;

/**
Expand Down Expand Up @@ -115,9 +117,9 @@ MsgAcqResultDepA.prototype.fieldSpec.push(['prn', 'writeUInt8', 1]);
* @field bin_width number (unsigned 16-bit int, 2 bytes) Acq frequency bin width
* @field timestamp number (unsigned 32-bit int, 4 bytes) Timestamp of the job complete event
* @field time_spent number (unsigned 32-bit int, 4 bytes) Time spent to search for sid.code
* @field cf_min number (unsigned 32-bit int, 4 bytes) Doppler range lowest frequency
* @field cf_max number (unsigned 32-bit int, 4 bytes) Doppler range highest frequency
* @field cf number (unsigned 32-bit int, 4 bytes) Doppler value of detected peak. Only valid if status is '1'
* @field cf_min number (signed 32-bit int, 4 bytes) Doppler range lowest frequency
* @field cf_max number (signed 32-bit int, 4 bytes) Doppler range highest frequency
* @field cf number (signed 32-bit int, 4 bytes) Doppler value of detected peak. Only valid if status is '1'
* @field cp number (unsigned 32-bit int, 4 bytes) Codephase of detected peak. Only valid if status is '1'
*
* @param sbp An SBP object with a payload to be decoded.
Expand All @@ -142,9 +144,9 @@ AcqSvProfile.prototype.parser = new Parser()
.uint16('bin_width')
.uint32('timestamp')
.uint32('time_spent')
.uint32('cf_min')
.uint32('cf_max')
.uint32('cf')
.int32('cf_min')
.int32('cf_max')
.int32('cf')
.uint32('cp');
AcqSvProfile.prototype.fieldSpec = [];
AcqSvProfile.prototype.fieldSpec.push(['job_type', 'writeUInt8', 1]);
Expand All @@ -155,9 +157,9 @@ AcqSvProfile.prototype.fieldSpec.push(['sid', GnssSignal.prototype.fieldSpec]);
AcqSvProfile.prototype.fieldSpec.push(['bin_width', 'writeUInt16LE', 2]);
AcqSvProfile.prototype.fieldSpec.push(['timestamp', 'writeUInt32LE', 4]);
AcqSvProfile.prototype.fieldSpec.push(['time_spent', 'writeUInt32LE', 4]);
AcqSvProfile.prototype.fieldSpec.push(['cf_min', 'writeUInt32LE', 4]);
AcqSvProfile.prototype.fieldSpec.push(['cf_max', 'writeUInt32LE', 4]);
AcqSvProfile.prototype.fieldSpec.push(['cf', 'writeUInt32LE', 4]);
AcqSvProfile.prototype.fieldSpec.push(['cf_min', 'writeInt32LE', 4]);
AcqSvProfile.prototype.fieldSpec.push(['cf_max', 'writeInt32LE', 4]);
AcqSvProfile.prototype.fieldSpec.push(['cf', 'writeInt32LE', 4]);
AcqSvProfile.prototype.fieldSpec.push(['cp', 'writeUInt32LE', 4]);

/**
Expand Down Expand Up @@ -186,7 +188,7 @@ MsgAcqSvProfile.prototype.parser = new Parser()
.endianess('little')
.array('acq_sv_profile', { type: AcqSvProfile.prototype.parser, readUntil: 'eof' });
MsgAcqSvProfile.prototype.fieldSpec = [];
MsgAcqSvProfile.prototype.fieldSpec.push(['acq_sv_profile', 'array', AcqSvProfile.prototype.fieldSpec, function () { return this.fields.array.length; }]);
MsgAcqSvProfile.prototype.fieldSpec.push(['acq_sv_profile', 'array', AcqSvProfile.prototype.fieldSpec, function () { return this.fields.array.length; }, null]);

module.exports = {
0x0014: MsgAcqResult,
Expand Down
10 changes: 6 additions & 4 deletions javascript/sbp/bootload.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
***********************/

var SBP = require('./sbp');
var Parser = require('binary-parser').Parser;
var Parser = require('./parser');
var Int64 = require('node-int64');
var UInt64 = require('cuint').UINT64;

/**
* SBP class for message MSG_BOOTLOADER_HANDSHAKE_REQ (0x00B3).
Expand Down Expand Up @@ -78,7 +80,7 @@ MsgBootloaderHandshakeResp.prototype.parser = new Parser()
.string('version', { greedy: true });
MsgBootloaderHandshakeResp.prototype.fieldSpec = [];
MsgBootloaderHandshakeResp.prototype.fieldSpec.push(['flags', 'writeUInt32LE', 4]);
MsgBootloaderHandshakeResp.prototype.fieldSpec.push(['version', 'string']);
MsgBootloaderHandshakeResp.prototype.fieldSpec.push(['version', 'string', null]);

/**
* SBP class for message MSG_BOOTLOADER_JUMP_TO_APP (0x00B1).
Expand Down Expand Up @@ -162,7 +164,7 @@ MsgNapDeviceDnaResp.prototype.parser = new Parser()
.endianess('little')
.array('dna', { length: 8, type: 'uint8' });
MsgNapDeviceDnaResp.prototype.fieldSpec = [];
MsgNapDeviceDnaResp.prototype.fieldSpec.push(['dna', 'array', 'writeUInt8', function () { return 1; }]);
MsgNapDeviceDnaResp.prototype.fieldSpec.push(['dna', 'array', 'writeUInt8', function () { return 1; }, 8]);

/**
* SBP class for message MSG_BOOTLOADER_HANDSHAKE_DEP_A (0x00B0).
Expand All @@ -189,7 +191,7 @@ MsgBootloaderHandshakeDepA.prototype.parser = new Parser()
.endianess('little')
.array('handshake', { type: 'uint8', readUntil: 'eof' });
MsgBootloaderHandshakeDepA.prototype.fieldSpec = [];
MsgBootloaderHandshakeDepA.prototype.fieldSpec.push(['handshake', 'array', 'writeUInt8', function () { return 1; }]);
MsgBootloaderHandshakeDepA.prototype.fieldSpec.push(['handshake', 'array', 'writeUInt8', function () { return 1; }, null]);

module.exports = {
0x00B3: MsgBootloaderHandshakeReq,
Expand Down
4 changes: 3 additions & 1 deletion javascript/sbp/ext_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
***********************/

var SBP = require('./sbp');
var Parser = require('binary-parser').Parser;
var Parser = require('./parser');
var Int64 = require('node-int64');
var UInt64 = require('cuint').UINT64;

/**
* SBP class for message MSG_EXT_EVENT (0x0101).
Expand Down
18 changes: 10 additions & 8 deletions javascript/sbp/file_io.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
***********************/

var SBP = require('./sbp');
var Parser = require('binary-parser').Parser;
var Parser = require('./parser');
var Int64 = require('node-int64');
var UInt64 = require('cuint').UINT64;

/**
* SBP class for message MSG_FILEIO_READ_REQ (0x00A8).
Expand Down Expand Up @@ -66,7 +68,7 @@ MsgFileioReadReq.prototype.fieldSpec = [];
MsgFileioReadReq.prototype.fieldSpec.push(['sequence', 'writeUInt32LE', 4]);
MsgFileioReadReq.prototype.fieldSpec.push(['offset', 'writeUInt32LE', 4]);
MsgFileioReadReq.prototype.fieldSpec.push(['chunk_size', 'writeUInt8', 1]);
MsgFileioReadReq.prototype.fieldSpec.push(['filename', 'string']);
MsgFileioReadReq.prototype.fieldSpec.push(['filename', 'string', null]);

/**
* SBP class for message MSG_FILEIO_READ_RESP (0x00A3).
Expand Down Expand Up @@ -99,7 +101,7 @@ MsgFileioReadResp.prototype.parser = new Parser()
.array('contents', { type: 'uint8', readUntil: 'eof' });
MsgFileioReadResp.prototype.fieldSpec = [];
MsgFileioReadResp.prototype.fieldSpec.push(['sequence', 'writeUInt32LE', 4]);
MsgFileioReadResp.prototype.fieldSpec.push(['contents', 'array', 'writeUInt8', function () { return 1; }]);
MsgFileioReadResp.prototype.fieldSpec.push(['contents', 'array', 'writeUInt8', function () { return 1; }, null]);

/**
* SBP class for message MSG_FILEIO_READ_DIR_REQ (0x00A9).
Expand Down Expand Up @@ -139,7 +141,7 @@ MsgFileioReadDirReq.prototype.parser = new Parser()
MsgFileioReadDirReq.prototype.fieldSpec = [];
MsgFileioReadDirReq.prototype.fieldSpec.push(['sequence', 'writeUInt32LE', 4]);
MsgFileioReadDirReq.prototype.fieldSpec.push(['offset', 'writeUInt32LE', 4]);
MsgFileioReadDirReq.prototype.fieldSpec.push(['dirname', 'string']);
MsgFileioReadDirReq.prototype.fieldSpec.push(['dirname', 'string', null]);

/**
* SBP class for message MSG_FILEIO_READ_DIR_RESP (0x00AA).
Expand Down Expand Up @@ -173,7 +175,7 @@ MsgFileioReadDirResp.prototype.parser = new Parser()
.array('contents', { type: 'uint8', readUntil: 'eof' });
MsgFileioReadDirResp.prototype.fieldSpec = [];
MsgFileioReadDirResp.prototype.fieldSpec.push(['sequence', 'writeUInt32LE', 4]);
MsgFileioReadDirResp.prototype.fieldSpec.push(['contents', 'array', 'writeUInt8', function () { return 1; }]);
MsgFileioReadDirResp.prototype.fieldSpec.push(['contents', 'array', 'writeUInt8', function () { return 1; }, null]);

/**
* SBP class for message MSG_FILEIO_REMOVE (0x00AC).
Expand Down Expand Up @@ -203,7 +205,7 @@ MsgFileioRemove.prototype.parser = new Parser()
.endianess('little')
.string('filename', { greedy: true });
MsgFileioRemove.prototype.fieldSpec = [];
MsgFileioRemove.prototype.fieldSpec.push(['filename', 'string']);
MsgFileioRemove.prototype.fieldSpec.push(['filename', 'string', null]);

/**
* SBP class for message MSG_FILEIO_WRITE_REQ (0x00AD).
Expand Down Expand Up @@ -243,8 +245,8 @@ MsgFileioWriteReq.prototype.parser = new Parser()
MsgFileioWriteReq.prototype.fieldSpec = [];
MsgFileioWriteReq.prototype.fieldSpec.push(['sequence', 'writeUInt32LE', 4]);
MsgFileioWriteReq.prototype.fieldSpec.push(['offset', 'writeUInt32LE', 4]);
MsgFileioWriteReq.prototype.fieldSpec.push(['filename', 'string']);
MsgFileioWriteReq.prototype.fieldSpec.push(['data', 'array', 'writeUInt8', function () { return 1; }]);
MsgFileioWriteReq.prototype.fieldSpec.push(['filename', 'string', null]);
MsgFileioWriteReq.prototype.fieldSpec.push(['data', 'array', 'writeUInt8', function () { return 1; }, null]);

/**
* SBP class for message MSG_FILEIO_WRITE_RESP (0x00AB).
Expand Down
Loading

0 comments on commit 27f6f3c

Please sign in to comment.