@@ -881,7 +881,7 @@ function newSyncObject () {
881
881
* @description Used transform raw data packets into fully qualified packets
882
882
* @param o {Object}
883
883
* @param o.rawDataPackets {Array} - An array of rawDataPackets
884
- * @param o.gains {Array}
884
+ * @param o.channelSettings {Array}
885
885
* @param o.timeOffset {Number} (optional) for non time stamp use cases i.e. 0xC0 or 0xC1 (default and raw aux)
886
886
* @param o.accelArray {Array} (optional) for non time stamp use cases
887
887
* @param o.verbose {Boolean} (optional) for verbose output
@@ -900,22 +900,22 @@ function transformRawDataPacketsToSample (o) {
900
900
case k . OBCIStreamPacketStandardAccel :
901
901
sample = utilitiesModule . parsePacketStandardAccel ( {
902
902
rawDataPacket,
903
- gains : o . gains ,
903
+ channelSettings : o . channelSettings ,
904
904
scale : o . scale
905
905
} ) ;
906
906
break ;
907
907
case k . OBCIStreamPacketStandardRawAux :
908
908
sample = utilitiesModule . parsePacketStandardRawAux ( {
909
909
rawDataPacket,
910
- gains : o . gains ,
910
+ channelSettings : o . channelSettings ,
911
911
scale : o . scale
912
912
} ) ;
913
913
break ;
914
914
case k . OBCIStreamPacketAccelTimeSyncSet :
915
915
case k . OBCIStreamPacketAccelTimeSynced :
916
916
sample = utilitiesModule . parsePacketTimeSyncedAccel ( {
917
917
rawDataPacket,
918
- gains : o . gains ,
918
+ channelSettings : o . channelSettings ,
919
919
timeOffset : o . timeOffset ,
920
920
accelArray : o . accelArray
921
921
} ) ;
@@ -924,7 +924,7 @@ function transformRawDataPacketsToSample (o) {
924
924
case k . OBCIStreamPacketRawAuxTimeSynced :
925
925
sample = utilitiesModule . parsePacketTimeSyncedRawAux ( {
926
926
rawDataPacket,
927
- gains : o . gains ,
927
+ channelSettings : o . channelSettings ,
928
928
timeOffset : o . timeOffset
929
929
} ) ;
930
930
break ;
@@ -948,7 +948,7 @@ function transformRawDataPacketsToSample (o) {
948
948
* @description This method parses a 33 byte OpenBCI V3 packet and converts to a sample object
949
949
* @param o {Object} - The input object
950
950
* @param o.rawDataPacket {Buffer} - The 33byte raw packet
951
- * @param o.gains {Array} - An array of channel settings that is an Array that has shape similar to the one
951
+ * @param o.channelSettings {Array} - An array of channel settings that is an Array that has shape similar to the one
952
952
* calling k.channelSettingsArrayInit(). The most important rule here is that it is
953
953
* Array of objects that have key-value pair {gain:NUMBER}
954
954
* @param o.scale {Boolean} - Do you want to scale the results? Default true
@@ -966,7 +966,7 @@ function parsePacketStandardAccel (o) {
966
966
sampleObject . accelData = getDataArrayAccel ( o . rawDataPacket . slice ( k . OBCIPacketPositionStartAux , k . OBCIPacketPositionStopAux + 1 ) ) ;
967
967
968
968
if ( k . isUndefined ( o . scale ) || k . isNull ( o . scale ) ) o . scale = true ;
969
- if ( o . scale ) sampleObject . channelData = getChannelDataArray ( o . rawDataPacket , o . gains ) ;
969
+ if ( o . scale ) sampleObject . channelData = getChannelDataArray ( o . rawDataPacket , o . channelSettings ) ;
970
970
else sampleObject . channelDataCounts = getChannelDataArrayNoScale ( o . rawDataPacket ) ;
971
971
972
972
if ( k . getVersionNumber ( process . version ) >= 6 ) {
@@ -989,7 +989,7 @@ function parsePacketStandardAccel (o) {
989
989
* @description This method parses a 33 byte OpenBCI V3 packet and converts to a sample object
990
990
* @param o {Object} - The input object
991
991
* @param o.rawDataPacket {Buffer} - The 33byte raw packet
992
- * @param o.gains {Array} - An array of channel settings that is an Array that has shape similar to the one
992
+ * @param o.channelSettings {Array} - An array of channel settings that is an Array that has shape similar to the one
993
993
* calling k.channelSettingsArrayInit(). The most important rule here is that it is
994
994
* Array of objects that have key-value pair {gain:NUMBER}
995
995
* @param o.scale {Boolean} - Do you want to scale the results? Default is true
@@ -1007,7 +1007,7 @@ function parsePacketStandardRawAux (o) {
1007
1007
1008
1008
// Store the channel data
1009
1009
if ( k . isUndefined ( o . scale ) || k . isNull ( o . scale ) ) o . scale = true ;
1010
- if ( o . scale ) sampleObject . channelData = getChannelDataArray ( o . rawDataPacket , o . gains ) ;
1010
+ if ( o . scale ) sampleObject . channelData = getChannelDataArray ( o ) ;
1011
1011
else sampleObject . channelDataCounts = getChannelDataArrayNoScale ( o . rawDataPacket ) ;
1012
1012
1013
1013
// Slice the buffer for the aux data
@@ -1034,7 +1034,7 @@ function parsePacketStandardRawAux (o) {
1034
1034
* Z axis data is sent with every sampleNumber % 10 === 2
1035
1035
* @param o {Object} - The input object
1036
1036
* @param o.rawDataPacket {Buffer} - The 33byte raw time synced accel packet
1037
- * @param o.gains {Array} - An array of channel settings that is an Array that has shape similar to the one
1037
+ * @param o.channelSettings {Array} - An array of channel settings that is an Array that has shape similar to the one
1038
1038
* calling OpenBCIConstans.channelSettingsArrayInit(). The most important rule here is that it is
1039
1039
* Array of objects that have key-value pair {gain:NUMBER}
1040
1040
* @param o.timeOffset {Number} - The difference between board time and current time calculated with sync methods.
@@ -1075,24 +1075,22 @@ function parsePacketTimeSyncedAccel (o) {
1075
1075
}
1076
1076
1077
1077
if ( k . isUndefined ( o . scale ) || k . isNull ( o . scale ) ) o . scale = true ;
1078
- if ( o . scale ) sampleObject . channelData = getChannelDataArray ( o . rawDataPacket , o . gains ) ;
1078
+ if ( o . scale ) sampleObject . channelData = getChannelDataArray ( o . rawDataPacket , o . channelSettings ) ;
1079
1079
else sampleObject . channelDataCounts = getChannelDataArrayNoScale ( o . rawDataPacket ) ;
1080
1080
1081
1081
return sampleObject ;
1082
1082
}
1083
1083
1084
1084
/**
1085
- * @description Grabs an accel value from a raw but time synced packet. Important that this utilizes the fact that:
1086
- * X axis data is sent with every sampleNumber % 10 === 0
1087
- * Y axis data is sent with every sampleNumber % 10 === 1
1088
- * Z axis data is sent with every sampleNumber % 10 === 2
1085
+ * @description Raw aux
1089
1086
* @param o {Object} - The input object
1090
1087
* @param o.rawDataPacket {Buffer} - The 33byte raw time synced accel packet
1091
- * @param o.gains {Array} - An array of channel settings that is an Array that has shape similar to the one
1088
+ * @param o.channelSettings {Array} - An array of channel settings that is an Array that has shape similar to the one
1092
1089
* calling k.channelSettingsArrayInit(). The most important rule here is that it is
1093
1090
* Array of objects that have key-value pair {gain:NUMBER}
1094
1091
* @param o.timeOffset {Number} - The difference between board time and current time calculated with sync methods.
1095
1092
* @param o.scale {Boolean} - Do you want to scale the results? Default is true
1093
+ * @param o.lastSampleNumber {Number} - The last sample number
1096
1094
* @returns {Sample } - A sample object. NOTE: The aux data is placed in a 2 byte buffer
1097
1095
*/
1098
1096
function parsePacketTimeSyncedRawAux ( o ) {
@@ -1124,7 +1122,7 @@ function parsePacketTimeSyncedRawAux (o) {
1124
1122
1125
1123
// Grab the channel data.
1126
1124
if ( k . isUndefined ( o . scale ) || k . isNull ( o . scale ) ) o . scale = true ;
1127
- if ( o . scale ) sampleObject . channelData = getChannelDataArray ( o . rawDataPacket , o . gains ) ;
1125
+ if ( o . scale ) sampleObject . channelData = getChannelDataArray ( o ) ;
1128
1126
else sampleObject . channelDataCounts = getChannelDataArrayNoScale ( o . rawDataPacket ) ;
1129
1127
1130
1128
return sampleObject ;
@@ -1212,40 +1210,62 @@ function getDataArrayAccel (dataBuf) {
1212
1210
return accelData ;
1213
1211
}
1214
1212
/**
1215
- * @description Takes a buffer filled with 24 bit signed integers from an OpenBCI device with gain settings in
1216
- * channelSettingsArray[index].gain and converts based on settings of ADS1299... spits out an
1217
- * array of floats in VOLTS
1218
- * @param dataBuf {Buffer} - Buffer with 33 bit signed integers, number of elements is same as channelSettingsArray.length * 3
1219
- * @param channelSettingsArray {Array} - The channel settings array, see OpenBCIConstants.channelSettingsArrayInit() for specs
1220
- * @returns {Array } - Array filled with floats for each channel's voltage in VOLTS
1221
- * @author AJ Keller (@pushtheworldllc)
1222
- */
1223
- function getChannelDataArray ( dataBuf , channelSettingsArray ) {
1224
- if ( ! Array . isArray ( channelSettingsArray ) ) {
1213
+ * @description Takes a buffer filled with 24 bit signed integers from an OpenBCI device with gain settings in
1214
+ * channelSettingsArray[index].gain and converts based on settings of ADS1299... spits out an
1215
+ * array of floats in VOLTS
1216
+ * @param o {Object} - The input object
1217
+ * @param o.rawDataPacket {Buffer} - The 33byte raw time synced accel packet
1218
+ * @param o.channelSettings {Array} - An array of channel settings that is an Array that has shape similar to the one
1219
+ * calling k.channelSettingsArrayInit(). The most important rule here is that it is
1220
+ * Array of objects that have key-value pair {gain:NUMBER}
1221
+ * @param o.scale {Boolean} - Do you want to scale the results? Default is true
1222
+ * @param o.lastSampleNumber {Number} - The last sample number
1223
+ * @param o.protocol {String} - Either `Serial` or `Wifi` (Default is `Wifi`)
1224
+ * @returns {Array } - Array filled with floats for each channel's voltage in VOLTS
1225
+ * @author AJ Keller (@pushtheworldllc)
1226
+ */
1227
+ function getChannelDataArray ( o ) {
1228
+ if ( ! Array . isArray ( o . channelSettings ) ) {
1225
1229
throw new Error ( 'Error [getChannelDataArray]: Channel Settings must be an array!' ) ;
1226
1230
}
1227
1231
var channelData = [ ] ;
1228
1232
// Grab the sample number from the buffer
1229
- var sampleNumber = dataBuf [ k . OBCIPacketPositionSampleNumber ] ;
1230
- var daisy = channelSettingsArray . length > k . OBCINumberOfChannelsDefault ;
1233
+ var sampleNumber = o . rawDataPacket [ k . OBCIPacketPositionSampleNumber ] ;
1234
+ var daisy = o . channelSettings . length === k . OBCINumberOfChannelsDaisy ;
1231
1235
1232
1236
// Channel data arrays are always 8 long
1233
1237
for ( var i = 0 ; i < k . OBCINumberOfChannelsDefault ; i ++ ) {
1234
- if ( ! channelSettingsArray [ i ] . hasOwnProperty ( 'gain' ) ) {
1238
+ if ( ! o . channelSettings [ i ] . hasOwnProperty ( 'gain' ) ) {
1235
1239
throw new Error ( `Error [getChannelDataArray]: Invalid channel settings object at index ${ i } ` ) ;
1236
1240
}
1237
- if ( ! k . isNumber ( channelSettingsArray [ i ] . gain ) ) {
1241
+ if ( ! k . isNumber ( o . channelSettings [ i ] . gain ) ) {
1238
1242
throw new Error ( 'Error [getChannelDataArray]: Property gain of channelSettingsObject not or type Number' ) ;
1239
1243
}
1240
1244
1241
- var scaleFactor = 0 ;
1242
- if ( isEven ( sampleNumber ) && daisy ) {
1243
- scaleFactor = ADS1299_VREF / channelSettingsArray [ i + k . OBCINumberOfChannelsDefault ] . gain / ( Math . pow ( 2 , 23 ) - 1 ) ;
1244
- } else {
1245
- scaleFactor = ADS1299_VREF / channelSettingsArray [ i ] . gain / ( Math . pow ( 2 , 23 ) - 1 ) ;
1245
+ let scaleFactor = 0 ;
1246
+
1247
+ if ( o . protocol === k . OBCIProtocolSerial ) {
1248
+ if ( isEven ( sampleNumber ) && daisy ) {
1249
+ scaleFactor = ADS1299_VREF / o . channelSettings [ i + k . OBCINumberOfChannelsDefault ] . gain / ( Math . pow ( 2 , 23 ) - 1 ) ;
1250
+ } else {
1251
+ scaleFactor = ADS1299_VREF / o . channelSettings [ i ] . gain / ( Math . pow ( 2 , 23 ) - 1 ) ;
1252
+ }
1253
+ } else if ( o . protocol === k . OBCIProtocolWifi ) {
1254
+ if ( daisy ) {
1255
+ if ( o . lastSampleNumber === sampleNumber ) {
1256
+ scaleFactor = ADS1299_VREF / o . channelSettings [ i + k . OBCINumberOfChannelsDefault ] . gain / ( Math . pow ( 2 , 23 ) - 1 ) ;
1257
+ } else {
1258
+ scaleFactor = ADS1299_VREF / o . channelSettings [ i ] . gain / ( Math . pow ( 2 , 23 ) - 1 ) ;
1259
+ }
1260
+ } else if ( o . channelSettings . length === k . OBCINumberOfChannelsCyton ) {
1261
+ scaleFactor = ADS1299_VREF / o . channelSettings [ i ] . gain / ( Math . pow ( 2 , 23 ) - 1 ) ;
1262
+ } else {
1263
+ scaleFactor = k . OBCIGanglionScaleFactorPerCountVolts ;
1264
+ }
1246
1265
}
1266
+
1247
1267
// Convert the three byte signed integer and convert it
1248
- channelData . push ( scaleFactor * utilitiesModule . interpret24bitAsInt32 ( dataBuf . slice ( ( i * 3 ) + k . OBCIPacketPositionChannelDataStart , ( i * 3 ) + k . OBCIPacketPositionChannelDataStart + 3 ) ) ) ;
1268
+ channelData . push ( scaleFactor * utilitiesModule . interpret24bitAsInt32 ( o . rawDataPacket . slice ( ( i * 3 ) + k . OBCIPacketPositionChannelDataStart , ( i * 3 ) + k . OBCIPacketPositionChannelDataStart + 3 ) ) ) ;
1249
1269
}
1250
1270
return channelData ;
1251
1271
}
0 commit comments