@@ -102,7 +102,7 @@ const Buffer = require('safe-buffer').Buffer;
102102 * @private
103103 */
104104var _options = {
105- boardType : [ k . OBCIBoardDefault , k . OBCIBoardDaisy , k . OBCIBoardGanglion ] ,
105+ boardType : [ k . OBCIBoardCyton , k . OBCIBoardDefault , k . OBCIBoardDaisy , k . OBCIBoardGanglion ] ,
106106 baudRate : 115200 ,
107107 hardSet : false ,
108108 sendCounts : false ,
@@ -179,7 +179,7 @@ function Cyton (options) {
179179 * @type {RawDataToSample }
180180 * @private
181181 */
182- this . _rawDataPacketToSample = k . rawDataToSampleObjectDefault ( 8 ) ;
182+ this . _rawDataPacketToSample = k . rawDataToSampleObjectDefault ( k . numberOfChannelsForBoardType ( this . options . boardType ) ) ;
183183 this . _rawDataPacketToSample . scale = ! this . options . sendCounts ;
184184 this . _rawDataPacketToSample . protocol = k . OBCIProtocolSerial ;
185185 this . _rawDataPacketToSample . verbose = this . options . verbose ;
@@ -194,15 +194,9 @@ function Cyton (options) {
194194 // Objects
195195 this . impedanceTest = obciUtils . impedanceTestObjDefault ( ) ;
196196 this . info = {
197- boardType : this . options . boardType ,
198- sampleRate : k . OBCISampleRate250 ,
199197 firmware : k . OBCIFirmwareV1 ,
200- numberOfChannels : k . OBCINumberOfChannelsCyton ,
201198 missedPackets : 0
202199 } ;
203- if ( this . options . boardType === k . OBCIBoardDefault ) {
204- this . info . sampleRate = k . OBCISampleRate250 ;
205- }
206200
207201 this . _lowerChannelsSampleObject = null ;
208202 this . serial = null ;
@@ -259,7 +253,7 @@ util.inherits(Cyton, EventEmitter);
259253Cyton . prototype . connect = function ( portName ) {
260254 return new Promise ( ( resolve , reject ) => {
261255 if ( this . isConnected ( ) ) return reject ( Error ( 'already connected!' ) ) ;
262-
256+ this . overrideInfoForBoardType ( this . options . boardType ) ;
263257 /* istanbul ignore else */
264258 if ( this . options . simulate || portName === k . OBCISimulatorPortName ) {
265259 this . options . simulate = true ;
@@ -1044,12 +1038,12 @@ Cyton.prototype.listPorts = function () {
10441038 * @return boardType: string
10451039 */
10461040Cyton . prototype . getBoardType = function ( ) {
1047- return this . info . boardType ;
1041+ return k . boardTypeForNumberOfChannels ( this . _rawDataPacketToSample . channelSettings . length ) ;
10481042} ;
10491043
10501044/**
10511045 * Get the core info object.
1052- * @return {{boardType: string, sampleRate: number, firmware: string, numberOfChannels: number , missedPackets: number} }
1046+ * @return {{firmware: string, missedPackets: number} }
10531047 */
10541048Cyton . prototype . getInfo = function ( ) {
10551049 return this . info ;
@@ -1063,19 +1057,14 @@ Cyton.prototype.getInfo = function () {
10631057Cyton . prototype . overrideInfoForBoardType = function ( boardType ) {
10641058 switch ( boardType ) {
10651059 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 ) ;
10701061 this . impedanceArray = obciUtils . impedanceArray ( k . OBCINumberOfChannelsDaisy ) ;
10711062 break ;
1063+ case k . OBCIBoardCyton :
10721064 case k . OBCIBoardDefault :
10731065 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 ) ;
10791068 break ;
10801069 }
10811070} ;
@@ -1092,7 +1081,7 @@ Cyton.prototype.hardSetBoardType = function (boardType) {
10921081 const eotFunc = ( data ) => {
10931082 switch ( data . slice ( 0 , data . length - k . OBCIParseEOT . length ) . toString ( ) ) {
10941083 case k . OBCIChannelMaxNumber8SuccessDaisyRemoved :
1095- this . overrideInfoForBoardType ( k . OBCIBoardDefault ) ;
1084+ this . overrideInfoForBoardType ( k . OBCIBoardCyton ) ;
10961085 resolve ( 'daisy removed' ) ;
10971086 break ;
10981087 case k . OBCIChannelMaxNumber16DaisyAlreadyAttached :
@@ -1104,18 +1093,19 @@ Cyton.prototype.hardSetBoardType = function (boardType) {
11041093 resolve ( 'daisy attached' ) ;
11051094 break ;
11061095 case k . OBCIChannelMaxNumber16NoDaisyAttached :
1107- this . overrideInfoForBoardType ( k . OBCIBoardDefault ) ;
1096+ this . overrideInfoForBoardType ( k . OBCIBoardCyton ) ;
11081097 reject ( Error ( 'unable to attach daisy' ) ) ;
11091098 break ;
11101099 case k . OBCIChannelMaxNumber8NoDaisyToRemove :
11111100 default :
1112- this . overrideInfoForBoardType ( k . OBCIBoardDefault ) ;
1101+ this . overrideInfoForBoardType ( k . OBCIBoardCyton ) ;
11131102 resolve ( 'no daisy to remove' ) ;
11141103 break ;
11151104 }
11161105 } ;
1117- if ( boardType === k . OBCIBoardDefault ) {
1106+ if ( boardType === k . OBCIBoardCyton || boardType === k . OBCIBoardDefault ) {
11181107 this . curParsingMode = k . OBCIParsingEOT ;
1108+ if ( this . options . verbose ) console . log ( 'Attempting to hardset board type' ) ;
11191109 this . once ( k . OBCIEmitterEot , eotFunc ) ;
11201110 this . write ( k . OBCIChannelMaxNumber8 )
11211111 . catch ( ( err ) => {
@@ -1228,7 +1218,7 @@ Cyton.prototype.channelSet = function (channelNumber, powerDown, gain, inputType
12281218 k . getChannelSetter ( channelNumber , powerDown , gain , inputType , bias , srb2 , srb1 )
12291219 . then ( ( val ) => {
12301220 arrayOfCommands = val . commandArray ;
1231- this . channelSettingsArray [ channelNumber - 1 ] = val . newChannelSettingsObject ;
1221+ this . _rawDataPacketToSample . channelSettings [ channelNumber - 1 ] = val . newChannelSettingsObject ;
12321222 return this . write ( arrayOfCommands ) ;
12331223 } ) . then ( resolve , reject ) ;
12341224 } ) ;
@@ -1318,7 +1308,7 @@ Cyton.prototype.impedanceTestContinuousStop = function () {
13181308 * @author AJ Keller (@pushtheworldllc)
13191309 */
13201310Cyton . prototype . impedanceTestAllChannels = function ( ) {
1321- var upperLimit = k . OBCINumberOfChannelsDefault ;
1311+ var upperLimit = k . OBCINumberOfChannelsCyton ;
13221312
13231313 /* istanbul ignore if */
13241314 if ( this . options . daisy ) {
@@ -1671,16 +1661,13 @@ Cyton.prototype.sampleRate = function () {
16711661 if ( this . options . simulate ) {
16721662 return this . options . simulatorSampleRate ;
16731663 } 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 ;
16841671 }
16851672 }
16861673} ;
@@ -1693,17 +1680,7 @@ Cyton.prototype.sampleRate = function () {
16931680 * @author AJ Keller (@pushtheworldllc)
16941681 */
16951682Cyton . 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 ;
17071684} ;
17081685
17091686/**
@@ -1883,7 +1860,7 @@ Cyton.prototype._processParseBufferForReset = function (dataBuffer) {
18831860 if ( obciUtils . countADSPresent ( dataBuffer ) === 2 ) {
18841861 this . overrideInfoForBoardType ( k . OBCIBoardDaisy ) ;
18851862 } else {
1886- this . overrideInfoForBoardType ( k . OBCIBoardDefault ) ;
1863+ this . overrideInfoForBoardType ( k . OBCIBoardCyton ) ;
18871864 }
18881865
18891866 if ( obciUtils . findV2Firmware ( dataBuffer ) ) {
@@ -2096,7 +2073,7 @@ Cyton.prototype._finalizeNewSample = function (sampleObject) {
20962073 } else {
20972074 // With the daisy board attached, lower channels (1-8) come in packets with odd sample numbers and upper
20982075 // channels (9-16) come in packets with even sample numbers
2099- if ( this . info . boardType === k . OBCIBoardDaisy ) {
2076+ if ( this . getBoardType === k . OBCIBoardDaisy ) {
21002077 // Send the sample for downstream sample compaction
21012078 this . _finalizeNewSampleForDaisy ( sampleObject ) ;
21022079 } else {
0 commit comments