@@ -110,7 +110,7 @@ var _options = {
110110 simulatorBoardFailure : false ,
111111 simulatorDaisyModuleAttached : false ,
112112 simulatorDaisyModuleCanBeAttached : true ,
113- simulatorFirmwareVersion : [ k . OBCIFirmwareV1 , k . OBCIFirmwareV2 ] ,
113+ simulatorFirmwareVersion : [ k . OBCIFirmwareV1 , k . OBCIFirmwareV2 , k . OBCIFirmwareV3 ] ,
114114 simulatorFragmentation : [ k . OBCISimulatorFragmentationNone , k . OBCISimulatorFragmentationRandom , k . OBCISimulatorFragmentationFullBuffers , k . OBCISimulatorFragmentationOneByOne ] ,
115115 simulatorLatencyTime : 16 ,
116116 simulatorBufferSize : 4096 ,
@@ -254,6 +254,7 @@ Cyton.prototype.connect = function (portName) {
254254 return new Promise ( ( resolve , reject ) => {
255255 if ( this . isConnected ( ) ) return reject ( Error ( 'already connected!' ) ) ;
256256 this . overrideInfoForBoardType ( this . options . boardType ) ;
257+ this . buffer = null ;
257258 /* istanbul ignore else */
258259 if ( this . options . simulate || portName === k . OBCISimulatorPortName ) {
259260 this . options . simulate = true ;
@@ -637,6 +638,34 @@ Cyton.prototype.usingVersionTwoFirmware = function () {
637638 }
638639} ;
639640
641+ /**
642+ * @description Convenience method to determine if you can use firmware v2.x.x
643+ * or greater capabilities.
644+ * @returns {boolean } - True if using firmware version 2 or greater. Should
645+ * be called after a `.softReset()` because we can parse the output of that
646+ * to determine if we are using firmware version 2.
647+ * @author AJ Keller (@pushtheworldllc)
648+ */
649+ Cyton . prototype . usingAtLeastVersionTwoFirmware = function ( ) {
650+ return this . usingVersionTwoFirmware ( ) || this . usingVersionThreeFirmware ( ) ;
651+ } ;
652+
653+ /**
654+ * @description Convenience method to determine if you can use firmware v2.x.x
655+ * capabilities.
656+ * @returns {boolean } - True if using firmware version 2 or greater. Should
657+ * be called after a `.softReset()` because we can parse the output of that
658+ * to determine if we are using firmware version 2.
659+ * @author AJ Keller (@pushtheworldllc)
660+ */
661+ Cyton . prototype . usingVersionThreeFirmware = function ( ) {
662+ if ( this . options . simulate ) {
663+ return this . options . simulatorFirmwareVersion === k . OBCIFirmwareV3 ;
664+ } else {
665+ return this . info . firmware === k . OBCIFirmwareV3 ;
666+ }
667+ } ;
668+
640669/**
641670 * @description Used to set the system radio channel number. The function will reject if not
642671 * connected to the serial port of the dongle. Further the function should reject if currently streaming.
@@ -653,7 +682,7 @@ Cyton.prototype.radioChannelSet = function (channelNumber) {
653682 return new Promise ( ( resolve , reject ) => {
654683 if ( ! this . isConnected ( ) ) return reject ( Error ( 'Must be connected to Dongle. Pro tip: Call .connect()' ) ) ;
655684 if ( this . isStreaming ( ) ) return reject ( Error ( 'Don\'t query for the radio while streaming' ) ) ;
656- if ( ! this . usingVersionTwoFirmware ( ) ) return reject ( Error ( 'Must be using firmware version 2' ) ) ;
685+ if ( ! this . usingAtLeastVersionTwoFirmware ( ) ) return reject ( Error ( 'Must be using greater than firmware version 2' ) ) ;
657686 if ( channelNumber === undefined || channelNumber === null ) return reject ( Error ( 'Must input a new channel number to switch too!' ) ) ;
658687 if ( ! k . isNumber ( channelNumber ) ) return reject ( Error ( 'Must input type Number' ) ) ;
659688 if ( channelNumber > k . OBCIRadioChannelMax ) return reject ( Error ( `New channel number must be less than ${ k . OBCIRadioChannelMax } ` ) ) ;
@@ -755,7 +784,7 @@ Cyton.prototype.radioChannelGet = function () {
755784 return new Promise ( ( resolve , reject ) => {
756785 if ( ! this . isConnected ( ) ) return reject ( Error ( 'Must be connected to Dongle. Pro tip: Call .connect()' ) ) ;
757786 if ( this . isStreaming ( ) ) return reject ( Error ( "Don't query for the radio while streaming" ) ) ;
758- if ( ! this . usingVersionTwoFirmware ( ) ) return reject ( Error ( 'Must be using firmware v2 ' ) ) ;
787+ if ( ! this . usingAtLeastVersionTwoFirmware ( ) ) return reject ( Error ( 'Must be using greater than firmware version 2 ' ) ) ;
759788
760789 // Set a timeout. Since poll times can be max of 255 seconds, we should set that as our timeout. This is
761790 // important if the module was connected, not streaming and using the old firmware
@@ -803,7 +832,7 @@ Cyton.prototype.radioPollTimeGet = function () {
803832 return new Promise ( ( resolve , reject ) => {
804833 if ( ! this . isConnected ( ) ) return reject ( Error ( 'Must be connected to Dongle. Pro tip: Call .connect()' ) ) ;
805834 if ( this . isStreaming ( ) ) return reject ( Error ( "Don't query for the poll time while streaming" ) ) ;
806- if ( ! this . usingVersionTwoFirmware ( ) ) return reject ( Error ( 'Must be using firmware v2 ' ) ) ;
835+ if ( ! this . usingAtLeastVersionTwoFirmware ( ) ) return reject ( Error ( 'Must be using greater than firmware version 2 ' ) ) ;
807836 // Set a timeout. Since poll times can be max of 255 seconds, we should set that as our timeout. This is
808837 // important if the module was connected, not streaming and using the old firmware
809838 badCommsTimeout = setTimeout ( ( ) => {
@@ -850,7 +879,7 @@ Cyton.prototype.radioPollTimeSet = function (pollTime) {
850879 return new Promise ( ( resolve , reject ) => {
851880 if ( ! this . isConnected ( ) ) return reject ( Error ( 'Must be connected to Dongle. Pro tip: Call .connect()' ) ) ;
852881 if ( this . isStreaming ( ) ) return reject ( Error ( "Don't change the poll time while streaming" ) ) ;
853- if ( ! this . usingVersionTwoFirmware ( ) ) return reject ( Error ( 'Must be using firmware v2 ' ) ) ;
882+ if ( ! this . usingAtLeastVersionTwoFirmware ( ) ) return reject ( Error ( 'Must be using greater than firmware version 2 ' ) ) ;
854883 if ( pollTime === undefined || pollTime === null ) return reject ( Error ( 'Must input a new poll time to switch too!' ) ) ;
855884 if ( ! k . isNumber ( pollTime ) ) return reject ( Error ( 'Must input type Number' ) ) ;
856885 if ( pollTime > k . OBCIRadioPollTimeMax ) return reject ( Error ( `New polltime must be less than ${ k . OBCIRadioPollTimeMax } ` ) ) ;
@@ -904,7 +933,7 @@ Cyton.prototype.radioBaudRateSet = function (speed) {
904933 return new Promise ( ( resolve , reject ) => {
905934 if ( ! this . isConnected ( ) ) return reject ( Error ( 'Must be connected to Dongle. Pro tip: Call .connect()' ) ) ;
906935 if ( this . isStreaming ( ) ) return reject ( Error ( "Don't change the baud rate while streaming" ) ) ;
907- if ( ! this . usingVersionTwoFirmware ( ) ) return reject ( Error ( 'Must be using firmware v2 ' ) ) ;
936+ if ( ! this . usingAtLeastVersionTwoFirmware ( ) ) return reject ( Error ( 'Must be using greater than firmware version 2 ' ) ) ;
908937 if ( ! k . isString ( speed ) ) return reject ( Error ( 'Must input type String' ) ) ;
909938 // Set a timeout. Since poll times can be max of 255 seconds, we should set that as our timeout. This is
910939 // important if the module was connected, not streaming and using the old firmware
@@ -975,7 +1004,7 @@ Cyton.prototype.radioSystemStatusGet = function () {
9751004 return new Promise ( ( resolve , reject ) => {
9761005 if ( ! this . isConnected ( ) ) return reject ( Error ( 'Must be connected to Dongle. Pro tip: Call .connect()' ) ) ;
9771006 if ( this . isStreaming ( ) ) return reject ( Error ( "Don't check the radio status while streaming" ) ) ;
978- if ( ! this . usingVersionTwoFirmware ( ) ) return reject ( Error ( 'Must be using firmware version 2' ) ) ;
1007+ if ( ! this . usingAtLeastVersionTwoFirmware ( ) ) return reject ( Error ( 'Must be using greater than firmware version 2' ) ) ;
9791008
9801009 // Set a timeout. Since poll times can be max of 255 seconds, we should set that as our timeout. This is
9811010 // important if the module was connected, not streaming and using the old firmware
@@ -1695,7 +1724,7 @@ Cyton.prototype.syncClocks = function () {
16951724 return new Promise ( ( resolve , reject ) => {
16961725 if ( ! this . isConnected ( ) ) return reject ( Error ( 'Must be connected to the device' ) ) ;
16971726 if ( ! this . isStreaming ( ) ) return reject ( Error ( 'Must be streaming to sync clocks' ) ) ;
1698- if ( ! this . usingVersionTwoFirmware ( ) ) return reject ( Error ( 'Time sync not implemented on v1 firmware, please update to v2 ' ) ) ;
1727+ if ( ! this . usingAtLeastVersionTwoFirmware ( ) ) return reject ( Error ( 'Must be using greater than firmware version 2 ' ) ) ;
16991728 this . sync . curSyncObj = obciUtils . newSyncObject ( ) ;
17001729 this . sync . curSyncObj . timeSyncSent = this . time ( ) ;
17011730 this . curParsingMode = k . OBCIParsingTimeSyncSent ;
@@ -1716,7 +1745,7 @@ Cyton.prototype.syncClocksFull = function () {
17161745 return new Promise ( ( resolve , reject ) => {
17171746 if ( ! this . isConnected ( ) ) return reject ( Error ( 'Must be connected to the device' ) ) ;
17181747 if ( ! this . isStreaming ( ) ) return reject ( Error ( 'Must be streaming to sync clocks' ) ) ;
1719- if ( ! this . usingVersionTwoFirmware ( ) ) return reject ( Error ( 'Time sync not implemented on v1 firmware, please update to v2 ' ) ) ;
1748+ if ( ! this . usingAtLeastVersionTwoFirmware ( ) ) return reject ( Error ( 'Must be using greater than firmware version 2 ' ) ) ;
17201749 var timeout = setTimeout ( ( ) => {
17211750 return reject ( Error ( 'syncClocksFull timeout after 500ms with no sync' ) ) ;
17221751 } , 500 ) ; // Should not take more than 1s to sync up
@@ -1773,7 +1802,7 @@ Cyton.prototype._processBytes = function (data) {
17731802 if ( obciUtils . doesBufferHaveEOT ( data ) ) {
17741803 this . _processParseBufferForReset ( data ) ;
17751804 if ( this . options . hardSet ) {
1776- if ( this . getBoardType ( ) !== this . options . boardType ) {
1805+ if ( ! _ . eq ( this . getBoardType ( ) , this . options . boardType ) ) {
17771806 this . emit ( k . OBCIEmitterHardSet ) ;
17781807 this . hardSetBoardType ( this . options . boardType )
17791808 . then ( ( ) => {
@@ -1788,7 +1817,7 @@ Cyton.prototype._processBytes = function (data) {
17881817 this . buffer = obciUtils . stripToEOTBuffer ( data ) ;
17891818 }
17901819 } else {
1791- if ( this . getBoardType ( ) !== this . options . boardType && this . options . verbose ) {
1820+ if ( _ . eq ( this . getBoardType ( ) , this . options . boardType ) && this . options . verbose ) {
17921821 console . log ( `Module detected ${ this . getBoardType ( ) } board type but you specified ${ this . options . boardType } , use 'hardSet' to force the module to correct itself` ) ;
17931822 }
17941823 this . curParsingMode = k . OBCIParsingNormal ;
@@ -1863,8 +1892,13 @@ Cyton.prototype._processParseBufferForReset = function (dataBuffer) {
18631892 this . overrideInfoForBoardType ( k . OBCIBoardCyton ) ;
18641893 }
18651894
1866- if ( obciUtils . findV2Firmware ( dataBuffer ) ) {
1867- this . info . firmware = k . OBCIFirmwareV2 ;
1895+ const firmware = obciUtils . getFirmware ( dataBuffer ) ;
1896+ if ( firmware ) {
1897+ if ( firmware . major === 2 ) {
1898+ this . info . firmware = k . OBCIFirmwareV2 ;
1899+ } else {
1900+ this . info . firmware = k . OBCIFirmwareV3 ;
1901+ }
18681902 this . writeOutDelay = k . OBCIWriteIntervalDelayMSNone ;
18691903 } else {
18701904 this . info . firmware = k . OBCIFirmwareV1 ;
@@ -2073,7 +2107,7 @@ Cyton.prototype._finalizeNewSample = function (sampleObject) {
20732107 } else {
20742108 // With the daisy board attached, lower channels (1-8) come in packets with odd sample numbers and upper
20752109 // channels (9-16) come in packets with even sample numbers
2076- if ( this . getBoardType ( ) === k . OBCIBoardDaisy ) {
2110+ if ( _ . eq ( this . getBoardType ( ) , k . OBCIBoardDaisy ) ) {
20772111 // Send the sample for downstream sample compaction
20782112 this . _finalizeNewSampleForDaisy ( sampleObject ) ;
20792113 } else {
0 commit comments