• Hi all,

    Just as an example, I am doing that sort of things with a ublox sam-m8q gps using their binary protocol.
    The example below is for the paragraph 31.18.20 UBX-NAV-STATUS (0x01 0x03).
    Their messages are pure packed c struct with properly aligned words, dwords and so on and most of those have a fixed length. That was designed for C, C++ definitely.

    However, I am not using an array, just a buffer containing a single data packet.

    I would store more than one in an Array (javascript standard) of ArrayBuffer(s) and then getters or setters with this kind of Dataview code, not pre splitted buffers with their contents separated. Thats may be slower but it's memory savy.

    gps.Status = function() {
          if (this[0x0103]===undefined) return undefined;
          let d=new DataView(this[0x0103].buffer);
          return {
              iTOW: d.getUint32(6, true)/1000,
              gpsFix: d.getUint8(10, true), 
              flags: d.getUint8(5+6, true),
              fixStat: d.getUint8(6+6, true),
              flags2: d.getUint8(7+6, true),
              ttff: d.getUint32(8+6, true)/1000,
              msss: d.getUint32(12+6, true)/1000, 
              receivedAt : new Date(this.receivedAt[0x0103]*1000)
          };
    };
    
About

Avatar for asez73 @asez73 started