2
2
* Created by ajk on 12/15/15.
3
3
*/
4
4
'use strict' ;
5
- let bluebirdChecks = require ( './bluebirdChecks' ) ;
6
- let openBCIUtilities = require ( '../openBCIUtilities' ) ;
7
- let chai = require ( 'chai' ) ;
8
- let expect = chai . expect ;
9
- let assert = chai . assert ;
10
- let should = chai . should ( ) ; // eslint-disable-line no-unused-lets
11
-
12
- let chaiAsPromised = require ( 'chai-as-promised' ) ;
13
- let sinonChai = require ( 'sinon-chai' ) ;
5
+ const bluebirdChecks = require ( './bluebirdChecks' ) ;
6
+ const openBCIUtilities = require ( '../openBCIUtilities' ) ;
7
+ const sinon = require ( 'sinon' ) ;
8
+ const chai = require ( 'chai' ) ;
9
+ const expect = chai . expect ;
10
+ const assert = chai . assert ;
11
+ const should = chai . should ( ) ; // eslint-disable-line no-unused-lets
12
+
13
+ const chaiAsPromised = require ( 'chai-as-promised' ) ;
14
+ const sinonChai = require ( 'sinon-chai' ) ;
14
15
chai . use ( chaiAsPromised ) ;
15
16
chai . use ( sinonChai ) ;
16
- let bufferEqual = require ( 'buffer-equal' ) ;
17
+ const bufferEqual = require ( 'buffer-equal' ) ;
17
18
18
19
let k = require ( '../openBCIConstants' ) ;
19
20
@@ -1784,156 +1785,137 @@ describe('#extractRawDataPackets', function () {
1784
1785
* Test the function that routes raw packets for processing
1785
1786
*/
1786
1787
describe ( '#transformRawDataPacketsToSamples' , function ( ) {
1787
- var ourBoard ;
1788
- var funcSpyTimeSyncSet , funcSpyTimeSyncedAccel , funcSpyTimeSyncedRawAux , funcSpyStandardRawAux , funcSpyStandardAccel ;
1788
+ var funcSpyTimeSyncedAccel , funcSpyTimeSyncedRawAux , funcSpyStandardRawAux , funcSpyStandardAccel ;
1789
1789
1790
1790
before ( function ( ) {
1791
- ourBoard = new openBCIBoard . OpenBCIBoard ( {
1792
- verbose : true
1793
- } ) ;
1794
1791
// Put watchers on all functions
1795
- funcSpyStandardAccel = sinon . spy ( ourBoard , '_processPacketStandardAccel' ) ;
1796
- funcSpyStandardRawAux = sinon . spy ( ourBoard , '_processPacketStandardRawAux' ) ;
1797
- funcSpyTimeSyncSet = sinon . spy ( ourBoard , '_processPacketTimeSyncSet' ) ;
1798
- funcSpyTimeSyncedAccel = sinon . spy ( ourBoard , '_processPacketTimeSyncedAccel' ) ;
1799
- funcSpyTimeSyncedRawAux = sinon . spy ( ourBoard , '_processPacketTimeSyncedRawAux' ) ;
1792
+ funcSpyStandardAccel = sinon . spy ( openBCIUtilities , 'parsePacketStandardAccel' ) ;
1793
+ funcSpyStandardRawAux = sinon . spy ( openBCIUtilities , 'parsePacketStandardRawAux' ) ;
1794
+ funcSpyTimeSyncedAccel = sinon . spy ( openBCIUtilities , 'parsePacketTimeSyncedAccel' ) ;
1795
+ funcSpyTimeSyncedRawAux = sinon . spy ( openBCIUtilities , 'parsePacketTimeSyncedRawAux' ) ;
1800
1796
} ) ;
1801
1797
beforeEach ( function ( ) {
1802
1798
funcSpyStandardAccel . reset ( ) ;
1803
1799
funcSpyStandardRawAux . reset ( ) ;
1804
- funcSpyTimeSyncSet . reset ( ) ;
1805
1800
funcSpyTimeSyncedAccel . reset ( ) ;
1806
1801
funcSpyTimeSyncedRawAux . reset ( ) ;
1807
-
1808
- ourBoard . sync . curSyncObj = openBCISample . newSyncObject ( ) ;
1809
1802
} ) ;
1810
1803
after ( function ( ) {
1811
1804
// ourBoard = null
1812
1805
} ) ;
1813
1806
after ( ( ) => bluebirdChecks . noPendingPromises ( ) ) ;
1814
1807
1815
1808
it ( 'should process a standard packet' , function ( ) {
1816
- var buffer = openBCISample . samplePacket ( 0 ) ;
1809
+ var buffer = openBCIUtilities . samplePacket ( 0 ) ;
1817
1810
1818
1811
// Call the function under test
1819
- ourBoard . _processQualifiedPacket ( buffer ) ;
1812
+ const samples = openBCIUtilities . transformRawDataPacketsToSample ( {
1813
+ rawDataPackets : [ buffer ] ,
1814
+ gains : defaultChannelSettingsArray
1815
+ } ) ;
1820
1816
1821
1817
// Ensure that we extracted only one buffer
1822
1818
funcSpyStandardAccel . should . have . been . calledOnce ;
1819
+ expect ( samples . length ) . to . equal ( 1 ) ;
1820
+ } ) ;
1821
+
1822
+ it ( 'should process a standard packet' , function ( ) {
1823
+ // Call the function under test
1824
+ const samples = openBCIUtilities . transformRawDataPacketsToSample ( {
1825
+ rawDataPackets : [
1826
+ openBCIUtilities . samplePacket ( 0 ) ,
1827
+ openBCIUtilities . samplePacket ( 1 ) ,
1828
+ openBCIUtilities . samplePacket ( 2 )
1829
+ ] ,
1830
+ gains : defaultChannelSettingsArray
1831
+ } ) ;
1832
+
1833
+ // Ensure that we extracted only one buffer
1834
+ funcSpyStandardAccel . should . have . been . calledThrice ;
1823
1835
} ) ;
1824
1836
it ( 'should process a standard packet with raw aux' , function ( ) {
1825
- var buffer = openBCISample . samplePacketStandardRawAux ( 0 ) ;
1837
+ var buffer = openBCIUtilities . samplePacketStandardRawAux ( 0 ) ;
1826
1838
1827
1839
// Call the function under test
1828
- ourBoard . _processQualifiedPacket ( buffer ) ;
1840
+ openBCIUtilities . transformRawDataPacketsToSample ( {
1841
+ rawDataPackets : [ buffer ]
1842
+ } ) ;
1829
1843
1830
1844
// Ensure that we extracted only one buffer
1831
1845
funcSpyStandardRawAux . should . have . been . calledOnce ;
1832
1846
} ) ;
1833
1847
it ( 'should call nothing for a user defined packet type ' , function ( ) {
1834
- var buffer = openBCISample . samplePacketUserDefined ( ) ;
1848
+ var buffer = openBCIUtilities . samplePacketUserDefined ( ) ;
1835
1849
1836
1850
// Call the function under test
1837
- ourBoard . _processQualifiedPacket ( buffer ) ;
1851
+ openBCIUtilities . transformRawDataPacketsToSample ( {
1852
+ rawDataPackets : [ buffer ]
1853
+ } ) ;
1838
1854
1839
1855
// Nothing should be called
1840
1856
funcSpyStandardAccel . should . not . have . been . called ;
1841
1857
funcSpyStandardRawAux . should . not . have . been . called ;
1842
- funcSpyTimeSyncSet . should . not . have . been . called ;
1843
1858
funcSpyTimeSyncedAccel . should . not . have . been . called ;
1844
1859
funcSpyTimeSyncedRawAux . should . not . have . been . called ;
1845
1860
} ) ;
1846
1861
it ( 'should process a time sync set packet with accel' , function ( ) {
1847
- var buffer = openBCISample . samplePacketAccelTimeSyncSet ( ) ;
1862
+ var buffer = openBCIUtilities . samplePacketAccelTimeSyncSet ( ) ;
1848
1863
1849
1864
// Call the function under test
1850
- ourBoard . _processQualifiedPacket ( buffer ) ;
1865
+ openBCIUtilities . transformRawDataPacketsToSample ( {
1866
+ rawDataPackets : [ buffer ]
1867
+ } ) ;
1851
1868
1852
- // We should call to sync up
1853
- funcSpyTimeSyncSet . should . have . been . calledOnce ;
1854
- funcSpyTimeSyncSet . should . have . been . calledWith ( buffer ) ;
1855
1869
// we should call to get a packet
1856
1870
funcSpyTimeSyncedAccel . should . have . been . calledOnce ;
1857
- funcSpyTimeSyncedAccel . should . have . been . calledWith ( buffer ) ;
1858
1871
} ) ;
1859
1872
it ( 'should process a time synced packet with accel' , function ( ) {
1860
- var buffer = openBCISample . samplePacketAccelTimeSynced ( 0 ) ;
1873
+ var buffer = openBCIUtilities . samplePacketAccelTimeSynced ( 0 ) ;
1861
1874
1862
1875
// Call the function under test
1863
- ourBoard . _processQualifiedPacket ( buffer ) ;
1876
+ openBCIUtilities . transformRawDataPacketsToSample ( {
1877
+ rawDataPackets : [ buffer ]
1878
+ } ) ;
1864
1879
1865
1880
// Ensure that we extracted only one buffer
1866
1881
funcSpyTimeSyncedAccel . should . have . been . calledOnce ;
1867
1882
} ) ;
1868
1883
it ( 'should process a time sync set packet with raw aux' , function ( ) {
1869
- var buffer = openBCISample . samplePacketRawAuxTimeSyncSet ( 0 ) ;
1884
+ var buffer = openBCIUtilities . samplePacketRawAuxTimeSyncSet ( 0 ) ;
1870
1885
1871
1886
// Call the function under test
1872
- ourBoard . _processQualifiedPacket ( buffer ) ;
1887
+ openBCIUtilities . transformRawDataPacketsToSample ( {
1888
+ rawDataPackets : [ buffer ]
1889
+ } ) ;
1873
1890
1874
- // We should call to sync up
1875
- funcSpyTimeSyncSet . should . have . been . calledOnce ;
1876
- funcSpyTimeSyncSet . should . have . been . calledWith ( buffer ) ;
1877
- // we should call to get a packet
1878
1891
funcSpyTimeSyncedRawAux . should . have . been . calledOnce ;
1879
- funcSpyTimeSyncedRawAux . should . have . been . calledWith ( buffer ) ;
1880
1892
} ) ;
1881
1893
it ( 'should process a time synced packet with raw aux' , function ( ) {
1882
- var buffer = openBCISample . samplePacketRawAuxTimeSynced ( 0 ) ;
1894
+ var buffer = openBCIUtilities . samplePacketRawAuxTimeSynced ( 0 ) ;
1883
1895
1884
1896
// Call the function under test
1885
- ourBoard . _processQualifiedPacket ( buffer ) ;
1897
+ openBCIUtilities . transformRawDataPacketsToSample ( {
1898
+ rawDataPackets : [ buffer ]
1899
+ } ) ;
1886
1900
1887
1901
// Ensure that we extracted only one buffer
1888
1902
funcSpyTimeSyncedRawAux . should . have . been . calledOnce ;
1889
1903
} ) ;
1890
1904
it ( 'should not identify any packet' , function ( ) {
1891
- var buffer = openBCISample . samplePacket ( 0 ) ;
1905
+ var buffer = openBCIUtilities . samplePacket ( 0 ) ;
1892
1906
1893
1907
// Set the stop byte to some number not yet defined
1894
1908
buffer [ k . OBCIPacketPositionStopByte ] = 0xCF ;
1895
1909
1896
1910
// Call the function under test
1897
- ourBoard . _processDataBuffer ( buffer ) ;
1911
+ openBCIUtilities . transformRawDataPacketsToSample ( {
1912
+ rawDataPackets : [ buffer ]
1913
+ } ) ;
1898
1914
1899
1915
// Nothing should be called
1900
1916
funcSpyStandardAccel . should . not . have . been . called ;
1901
1917
funcSpyStandardRawAux . should . not . have . been . called ;
1902
- funcSpyTimeSyncSet . should . not . have . been . called ;
1903
1918
funcSpyTimeSyncedAccel . should . not . have . been . called ;
1904
1919
funcSpyTimeSyncedRawAux . should . not . have . been . called ;
1905
1920
} ) ;
1906
- it ( 'should emit a dropped packet on dropped packet' , function ( done ) {
1907
- // Set to default state
1908
- ourBoard . previousSampleNumber = - 1 ;
1909
- var sampleNumber0 = openBCISample . samplePacket ( 0 ) ;
1910
- ourBoard . once ( 'droppedPacket' , ( ) => {
1911
- done ( ) ;
1912
- } ) ;
1913
- var sampleNumber2 = openBCISample . samplePacket ( 2 ) ;
1914
- // Call the function under test
1915
- ourBoard . _processDataBuffer ( sampleNumber0 ) ;
1916
- ourBoard . _processDataBuffer ( sampleNumber2 ) ;
1917
- } ) ;
1918
- it ( 'should emit a dropped packet on dropped packet with edge' , function ( done ) {
1919
- // Set to default state
1920
- var count = 0 ;
1921
- ourBoard . previousSampleNumber = 253 ;
1922
- var buf1 = openBCISample . samplePacket ( 254 ) ;
1923
- var countFunc = arr => {
1924
- count ++ ;
1925
- } ;
1926
- ourBoard . on ( 'droppedPacket' , countFunc ) ;
1927
- var buf2 = openBCISample . samplePacket ( 0 ) ;
1928
- var buf3 = openBCISample . samplePacket ( 1 ) ;
1929
- // Call the function under test
1930
- ourBoard . _processDataBuffer ( buf1 ) ;
1931
- ourBoard . _processDataBuffer ( buf2 ) ;
1932
- ourBoard . _processDataBuffer ( buf3 ) ;
1933
- setTimeout ( ( ) => {
1934
- ourBoard . removeListener ( 'droppedPacket' , countFunc ) ;
1935
- expect ( count ) . to . equal ( 1 ) ;
1936
- done ( ) ;
1937
- } , 10 ) ;
1938
- } ) ;
1939
1921
} ) ;
0 commit comments