src/utilities.js
function processCompressedData (o) {
  // Save the packet counter
  o.lastSampleNumber = parseInt(o.rawDataPacket[0]);

  const samples = [];
  // Decompress the buffer into array
  if (o.lastSampleNumber <= k.OBCIGanglionByteId18Bit.max) {
    decompressSamples(o, decompressDeltas18Bit(o.rawDataPacket.slice(k.OBCIGanglionPacket18Bit.dataStart, k.OBCIGanglionPacket18Bit.dataStop)));
    samples.push(buildSample(o.lastSampleNumber * 2 - 1, o.decompressedSamples[1], o.sendCounts));
    samples.push(buildSample(o.lastSampleNumber * 2, o.decompressedSamples[2], o.sendCounts));

    switch (o.lastSampleNumber % 10) {
      case k.OBCIGanglionAccelAxisX:
        o.accelArray[0] = o.sendCounts ? o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) : o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) * k.OBCIGanglionAccelScaleFactor;
        break;
      case k.OBCIGanglionAccelAxisY:
        o.accelArray[1] = o.sendCounts ? o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) : o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) * k.OBCIGanglionAccelScaleFactor;
        break;
      case k.OBCIGanglionAccelAxisZ:
        o.accelArray[2] = o.sendCounts ? o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) : o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) * k.OBCIGanglionAccelScaleFactor;
        if (o.sendCounts) {
          samples[0].accelData = o.accelArray;
        } else {
          samples[0].accelDataCounts = o.accelArray;
        }
        break;
      default:
        break;
    }
  } else {
    decompressSamples(o, decompressDeltas19Bit(o.rawDataPacket.slice(k.OBCIGanglionPacket19Bit.dataStart, k.OBCIGanglionPacket19Bit.dataStop)));

    samples.push(buildSample((o.lastSampleNumber - 100) * 2 - 1, o.decompressedSamples[1], o.sendCounts));
    samples.push(buildSample((o.lastSampleNumber - 100) * 2, o.decompressedSamples[2], o.sendCounts));
  }

  // Rotate the 0 position for next time
  for (let i = 0; i < k.OBCINumberOfChannelsGanglion; i++) {
    o.decompressedSamples[0][i] = o.decompressedSamples[2][i];
  }

  return samples;
}
function processCompressedData (o) {
  // Save the packet counter
  o.lastSampleNumber = parseInt(o.rawDataPacket[0]);

  const samples = [];
  // Decompress the buffer into array
  if (o.lastSampleNumber <= k.OBCIGanglionByteId18Bit.max) {
    decompressSamples(o, decompressDeltas18Bit(o.rawDataPacket.slice(k.OBCIGanglionPacket18Bit.dataStart, k.OBCIGanglionPacket18Bit.dataStop)));
    samples.push(buildSample(o.lastSampleNumber * 2 - 1, o.decompressedSamples[1], o.sendCounts));
    samples.push(buildSample(o.lastSampleNumber * 2, o.decompressedSamples[2], o.sendCounts));

    switch (o.lastSampleNumber % 10) {
      case k.OBCIGanglionAccelAxisX:
        o.accelArray[0] = o.sendCounts ? o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) : o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) * k.OBCIGanglionAccelScaleFactor;
        break;
      case k.OBCIGanglionAccelAxisY:
        o.accelArray[1] = o.sendCounts ? o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) : o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) * k.OBCIGanglionAccelScaleFactor;
        break;
      case k.OBCIGanglionAccelAxisZ:
        o.accelArray[2] = o.sendCounts ? o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) : o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) * k.OBCIGanglionAccelScaleFactor;
        if (o.sendCounts) {
          samples[0].accelData = o.accelArray;
        } else {
          samples[0].accelDataCounts = o.accelArray;
        }
        break;
      default:
        break;
    }
  } else {
    decompressSamples(o, decompressDeltas19Bit(o.rawDataPacket.slice(k.OBCIGanglionPacket19Bit.dataStart, k.OBCIGanglionPacket19Bit.dataStop)));

    samples.push(buildSample((o.lastSampleNumber - 100) * 2 - 1, o.decompressedSamples[1], o.sendCounts));
    samples.push(buildSample((o.lastSampleNumber - 100) * 2, o.decompressedSamples[2], o.sendCounts));
  }

  // Rotate the 0 position for next time
  for (let i = 0; i < k.OBCINumberOfChannelsGanglion; i++) {
    o.decompressedSamples[0][i] = o.decompressedSamples[2][i];
  }

  return samples;
}
function processCompressedData ( o ) { // Save the packet counter o . lastSampleNumber = parseInt ( o . rawDataPacket [ 0 ] ) ; const samples = [ ] ; // Decompress the buffer into array if ( o . lastSampleNumber <= k . OBCIGanglionByteId18Bit . max ) { decompressSamples ( o , decompressDeltas18Bit ( o . rawDataPacket . slice ( k . OBCIGanglionPacket18Bit . dataStart , k . OBCIGanglionPacket18Bit . dataStop ) ) ) ; samples . push ( buildSample ( o . lastSampleNumber * 2 - 1 , o . decompressedSamples [ 1 ] , o . sendCounts ) ) ; samples . push ( buildSample ( o . lastSampleNumber * 2 , o . decompressedSamples [ 2 ] , o . sendCounts ) ) ; switch ( o . lastSampleNumber % 10 ) { case k . OBCIGanglionAccelAxisX : o . accelArray [ 0 ] = o . sendCounts ? o . rawDataPacket . readInt8 ( k . OBCIGanglionPacket18Bit . auxByte - 1 ) : o . rawDataPacket . readInt8 ( k . OBCIGanglionPacket18Bit . auxByte - 1 ) * k . OBCIGanglionAccelScaleFactor ; break ; case k . OBCIGanglionAccelAxisY : o . accelArray [ 1 ] = o . sendCounts ? o . rawDataPacket . readInt8 ( k . OBCIGanglionPacket18Bit . auxByte - 1 ) : o . rawDataPacket . readInt8 ( k . OBCIGanglionPacket18Bit . auxByte - 1 ) * k . OBCIGanglionAccelScaleFactor ; break ; case k . OBCIGanglionAccelAxisZ : o . accelArray [ 2 ] = o . sendCounts ? o . rawDataPacket . readInt8 ( k . OBCIGanglionPacket18Bit . auxByte - 1 ) : o . rawDataPacket . readInt8 ( k . OBCIGanglionPacket18Bit . auxByte - 1 ) * k . OBCIGanglionAccelScaleFactor ; if ( o . sendCounts ) { samples [ 0 ] . accelData = o . accelArray ; } else { samples [ 0 ] . accelDataCounts = o . accelArray ; } break ; default : break ; } } else { decompressSamples ( o , decompressDeltas19Bit ( o . rawDataPacket . slice ( k . OBCIGanglionPacket19Bit . dataStart , k . OBCIGanglionPacket19Bit . dataStop ) ) ) ; samples . push ( buildSample ( ( o . lastSampleNumber - 100 ) * 2 - 1 , o . decompressedSamples [ 1 ] , o . sendCounts ) ) ; samples . push ( buildSample ( ( o . lastSampleNumber - 100 ) * 2 , o . decompressedSamples [ 2 ] , o . sendCounts ) ) ; } // Rotate the 0 position for next time for ( let i = 0 ; i < k . OBCINumberOfChannelsGanglion ; i ++ ) { o . decompressedSamples [ 0 ] [ i ] = o . decompressedSamples [ 2 ] [ i ] ; } return samples ; }
Process an compressed packet of data.
@param o {RawDataToSample} - Used to hold data and configuration settings
@private
Process an compressed packet of data .