@@ -102,7 +102,7 @@ const Buffer = require('safe-buffer').Buffer;
102
102
* @private
103
103
*/
104
104
var _options = {
105
- boardType : [ k . OBCIBoardDefault , k . OBCIBoardDaisy , k . OBCIBoardGanglion ] ,
105
+ boardType : [ k . OBCIBoardCyton , k . OBCIBoardDefault , k . OBCIBoardDaisy , k . OBCIBoardGanglion ] ,
106
106
baudRate : 115200 ,
107
107
hardSet : false ,
108
108
sendCounts : false ,
@@ -179,7 +179,7 @@ function Cyton (options) {
179
179
* @type {RawDataToSample }
180
180
* @private
181
181
*/
182
- this . _rawDataPacketToSample = k . rawDataToSampleObjectDefault ( 8 ) ;
182
+ this . _rawDataPacketToSample = k . rawDataToSampleObjectDefault ( k . numberOfChannelsForBoardType ( this . options . boardType ) ) ;
183
183
this . _rawDataPacketToSample . scale = ! this . options . sendCounts ;
184
184
this . _rawDataPacketToSample . protocol = k . OBCIProtocolSerial ;
185
185
this . _rawDataPacketToSample . verbose = this . options . verbose ;
@@ -194,15 +194,9 @@ function Cyton (options) {
194
194
// Objects
195
195
this . impedanceTest = obciUtils . impedanceTestObjDefault ( ) ;
196
196
this . info = {
197
- boardType : this . options . boardType ,
198
- sampleRate : k . OBCISampleRate250 ,
199
197
firmware : k . OBCIFirmwareV1 ,
200
- numberOfChannels : k . OBCINumberOfChannelsCyton ,
201
198
missedPackets : 0
202
199
} ;
203
- if ( this . options . boardType === k . OBCIBoardDefault ) {
204
- this . info . sampleRate = k . OBCISampleRate250 ;
205
- }
206
200
207
201
this . _lowerChannelsSampleObject = null ;
208
202
this . serial = null ;
@@ -259,7 +253,7 @@ util.inherits(Cyton, EventEmitter);
259
253
Cyton . prototype . connect = function ( portName ) {
260
254
return new Promise ( ( resolve , reject ) => {
261
255
if ( this . isConnected ( ) ) return reject ( Error ( 'already connected!' ) ) ;
262
-
256
+ this . overrideInfoForBoardType ( this . options . boardType ) ;
263
257
/* istanbul ignore else */
264
258
if ( this . options . simulate || portName === k . OBCISimulatorPortName ) {
265
259
this . options . simulate = true ;
@@ -1044,12 +1038,12 @@ Cyton.prototype.listPorts = function () {
1044
1038
* @return boardType: string
1045
1039
*/
1046
1040
Cyton . prototype . getBoardType = function ( ) {
1047
- return this . info . boardType ;
1041
+ return k . boardTypeForNumberOfChannels ( this . _rawDataPacketToSample . channelSettings . length ) ;
1048
1042
} ;
1049
1043
1050
1044
/**
1051
1045
* Get the core info object.
1052
- * @return {{boardType: string, sampleRate: number, firmware: string, numberOfChannels: number , missedPackets: number} }
1046
+ * @return {{firmware: string, missedPackets: number} }
1053
1047
*/
1054
1048
Cyton . prototype . getInfo = function ( ) {
1055
1049
return this . info ;
@@ -1063,19 +1057,14 @@ Cyton.prototype.getInfo = function () {
1063
1057
Cyton . prototype . overrideInfoForBoardType = function ( boardType ) {
1064
1058
switch ( boardType ) {
1065
1059
case k . OBCIBoardDaisy :
1066
- this . info . boardType = k . OBCIBoardDaisy ;
1067
- this . info . numberOfChannels = k . OBCINumberOfChannelsDaisy ;
1068
- this . info . sampleRate = k . OBCISampleRate125 ;
1069
- this . channelSettingsArray = k . channelSettingsArrayInit ( k . OBCINumberOfChannelsDaisy ) ;
1060
+ this . _rawDataPacketToSample . channelSettings = k . channelSettingsArrayInit ( k . OBCINumberOfChannelsDaisy ) ;
1070
1061
this . impedanceArray = obciUtils . impedanceArray ( k . OBCINumberOfChannelsDaisy ) ;
1071
1062
break ;
1063
+ case k . OBCIBoardCyton :
1072
1064
case k . OBCIBoardDefault :
1073
1065
default :
1074
- this . info . boardType = k . OBCIBoardDefault ;
1075
- this . info . numberOfChannels = k . OBCINumberOfChannelsDefault ;
1076
- this . info . sampleRate = k . OBCISampleRate250 ;
1077
- this . channelSettingsArray = k . channelSettingsArrayInit ( k . OBCINumberOfChannelsDefault ) ;
1078
- this . impedanceArray = obciUtils . impedanceArray ( k . OBCINumberOfChannelsDefault ) ;
1066
+ this . _rawDataPacketToSample . channelSettings = k . channelSettingsArrayInit ( k . OBCINumberOfChannelsCyton ) ;
1067
+ this . impedanceArray = obciUtils . impedanceArray ( k . OBCINumberOfChannelsCyton ) ;
1079
1068
break ;
1080
1069
}
1081
1070
} ;
@@ -1092,7 +1081,7 @@ Cyton.prototype.hardSetBoardType = function (boardType) {
1092
1081
const eotFunc = ( data ) => {
1093
1082
switch ( data . slice ( 0 , data . length - k . OBCIParseEOT . length ) . toString ( ) ) {
1094
1083
case k . OBCIChannelMaxNumber8SuccessDaisyRemoved :
1095
- this . overrideInfoForBoardType ( k . OBCIBoardDefault ) ;
1084
+ this . overrideInfoForBoardType ( k . OBCIBoardCyton ) ;
1096
1085
resolve ( 'daisy removed' ) ;
1097
1086
break ;
1098
1087
case k . OBCIChannelMaxNumber16DaisyAlreadyAttached :
@@ -1104,18 +1093,19 @@ Cyton.prototype.hardSetBoardType = function (boardType) {
1104
1093
resolve ( 'daisy attached' ) ;
1105
1094
break ;
1106
1095
case k . OBCIChannelMaxNumber16NoDaisyAttached :
1107
- this . overrideInfoForBoardType ( k . OBCIBoardDefault ) ;
1096
+ this . overrideInfoForBoardType ( k . OBCIBoardCyton ) ;
1108
1097
reject ( Error ( 'unable to attach daisy' ) ) ;
1109
1098
break ;
1110
1099
case k . OBCIChannelMaxNumber8NoDaisyToRemove :
1111
1100
default :
1112
- this . overrideInfoForBoardType ( k . OBCIBoardDefault ) ;
1101
+ this . overrideInfoForBoardType ( k . OBCIBoardCyton ) ;
1113
1102
resolve ( 'no daisy to remove' ) ;
1114
1103
break ;
1115
1104
}
1116
1105
} ;
1117
- if ( boardType === k . OBCIBoardDefault ) {
1106
+ if ( boardType === k . OBCIBoardCyton || boardType === k . OBCIBoardDefault ) {
1118
1107
this . curParsingMode = k . OBCIParsingEOT ;
1108
+ if ( this . options . verbose ) console . log ( 'Attempting to hardset board type' ) ;
1119
1109
this . once ( k . OBCIEmitterEot , eotFunc ) ;
1120
1110
this . write ( k . OBCIChannelMaxNumber8 )
1121
1111
. catch ( ( err ) => {
@@ -1228,7 +1218,7 @@ Cyton.prototype.channelSet = function (channelNumber, powerDown, gain, inputType
1228
1218
k . getChannelSetter ( channelNumber , powerDown , gain , inputType , bias , srb2 , srb1 )
1229
1219
. then ( ( val ) => {
1230
1220
arrayOfCommands = val . commandArray ;
1231
- this . channelSettingsArray [ channelNumber - 1 ] = val . newChannelSettingsObject ;
1221
+ this . _rawDataPacketToSample . channelSettings [ channelNumber - 1 ] = val . newChannelSettingsObject ;
1232
1222
return this . write ( arrayOfCommands ) ;
1233
1223
} ) . then ( resolve , reject ) ;
1234
1224
} ) ;
@@ -1318,7 +1308,7 @@ Cyton.prototype.impedanceTestContinuousStop = function () {
1318
1308
* @author AJ Keller (@pushtheworldllc)
1319
1309
*/
1320
1310
Cyton . prototype . impedanceTestAllChannels = function ( ) {
1321
- var upperLimit = k . OBCINumberOfChannelsDefault ;
1311
+ var upperLimit = k . OBCINumberOfChannelsCyton ;
1322
1312
1323
1313
/* istanbul ignore if */
1324
1314
if ( this . options . daisy ) {
@@ -1671,16 +1661,13 @@ Cyton.prototype.sampleRate = function () {
1671
1661
if ( this . options . simulate ) {
1672
1662
return this . options . simulatorSampleRate ;
1673
1663
} else {
1674
- if ( this . info ) {
1675
- return this . info . sampleRate ;
1676
- } else {
1677
- switch ( this . boardType ) {
1678
- case k . OBCIBoardDaisy :
1679
- return k . OBCISampleRate125 ;
1680
- case k . OBCIBoardDefault :
1681
- default :
1682
- return k . OBCISampleRate250 ;
1683
- }
1664
+ switch ( this . getBoardType ( ) ) {
1665
+ case k . OBCIBoardDaisy :
1666
+ return k . OBCISampleRate125 ;
1667
+ case k . OBCIBoardCyton :
1668
+ case k . OBCIBoardDefault :
1669
+ default :
1670
+ return k . OBCISampleRate250 ;
1684
1671
}
1685
1672
}
1686
1673
} ;
@@ -1693,17 +1680,7 @@ Cyton.prototype.sampleRate = function () {
1693
1680
* @author AJ Keller (@pushtheworldllc)
1694
1681
*/
1695
1682
Cyton . prototype . numberOfChannels = function ( ) {
1696
- if ( this . info ) {
1697
- return this . info . numberOfChannels ;
1698
- } else {
1699
- switch ( this . boardType ) {
1700
- case k . OBCIBoardDaisy :
1701
- return k . OBCINumberOfChannelsDaisy ;
1702
- case k . OBCIBoardDefault :
1703
- default :
1704
- return k . OBCINumberOfChannelsDefault ;
1705
- }
1706
- }
1683
+ return this . _rawDataPacketToSample . channelSettings . length ;
1707
1684
} ;
1708
1685
1709
1686
/**
@@ -1883,7 +1860,7 @@ Cyton.prototype._processParseBufferForReset = function (dataBuffer) {
1883
1860
if ( obciUtils . countADSPresent ( dataBuffer ) === 2 ) {
1884
1861
this . overrideInfoForBoardType ( k . OBCIBoardDaisy ) ;
1885
1862
} else {
1886
- this . overrideInfoForBoardType ( k . OBCIBoardDefault ) ;
1863
+ this . overrideInfoForBoardType ( k . OBCIBoardCyton ) ;
1887
1864
}
1888
1865
1889
1866
if ( obciUtils . findV2Firmware ( dataBuffer ) ) {
@@ -2096,7 +2073,7 @@ Cyton.prototype._finalizeNewSample = function (sampleObject) {
2096
2073
} else {
2097
2074
// With the daisy board attached, lower channels (1-8) come in packets with odd sample numbers and upper
2098
2075
// channels (9-16) come in packets with even sample numbers
2099
- if ( this . info . boardType === k . OBCIBoardDaisy ) {
2076
+ if ( this . getBoardType === k . OBCIBoardDaisy ) {
2100
2077
// Send the sample for downstream sample compaction
2101
2078
this . _finalizeNewSampleForDaisy ( sampleObject ) ;
2102
2079
} else {
0 commit comments