@@ -37,6 +37,82 @@ describe('openBCIUtilities', function () {
37
37
accelArray = [ 0 , 0 , 0 ] ;
38
38
} ) ;
39
39
afterEach ( ( ) => bluebirdChecks . noPendingPromises ( ) ) ;
40
+ describe ( '#convertGanglionArrayToBuffer' , function ( ) {
41
+ it ( 'should fill the packet with values from data' , function ( ) {
42
+ const numChannels = k . numberOfChannelsForBoardType ( k . OBCIBoardGanglion ) ;
43
+ let arr = [ 0 , 1 , 2 , 3 ] ;
44
+ let rawDataPacket = k . rawDataToSampleObjectDefault ( numChannels ) . rawDataPacket ;
45
+ rawDataPacket . fill ( 0 ) ; // fill with zeros
46
+ let bleRawBuf = openBCIUtilities . convertGanglionArrayToBuffer ( arr , data ) ;
47
+ const sampleNumber = 23 ;
48
+ openBCIUtilities . ganglionFillRawDataPacket ( {
49
+ data : bleRawBuf ,
50
+ rawDataPacket,
51
+ sampleNumber
52
+ } ) ;
53
+ expect ( bufferEqual ( rawDataPacket . slice ( 2 , 2 + k . OBCIPacketSizeBLERaw ) , bleRawBuf ) , `expected ${ bleRawBuf . toString ( 'hex' ) } but got ${ rawDataPacket . slice ( 2 , 2 + k . OBCIPacketSizeBLERaw ) . toString ( 'hex' ) } ` ) . to . be . true ( ) ;
54
+ expect ( rawDataPacket [ k . OBCIPacketPositionSampleNumber ] ) . to . equal ( sampleNumber ) ;
55
+ expect ( rawDataPacket [ k . OBCIPacketPositionStartByte ] ) . to . equal ( k . OBCIByteStart ) ;
56
+ expect ( rawDataPacket [ k . OBCIPacketPositionStopByte ] ) . to . equal ( k . OBCIStreamPacketStandardRawAux ) ;
57
+ } ) ;
58
+ describe ( '#errorConditions' , function ( ) {
59
+ it ( 'send undefined data buffer' , function ( ) {
60
+ expect ( openBCIUtilities . ganglionFillRawDataPacket . bind ( openBCIUtilities , {
61
+ rawDataPacket : Buffer . alloc ( k . OBCIPacketSize ) ,
62
+ sampleNumber : 0
63
+ } ) ) . to . throw ( k . OBCIErrorUndefinedOrNullInput ) ;
64
+ } ) ;
65
+ it ( 'send null data buffer' , function ( ) {
66
+ expect ( openBCIUtilities . ganglionFillRawDataPacket . bind ( openBCIUtilities , {
67
+ data : null ,
68
+ rawDataPacket : Buffer . alloc ( k . OBCIPacketSize ) ,
69
+ sampleNumber : 0
70
+ } ) ) . to . throw ( k . OBCIErrorUndefinedOrNullInput ) ;
71
+ } ) ;
72
+ it ( 'send undefined rawDataPacket buffer' , function ( ) {
73
+ expect ( openBCIUtilities . ganglionFillRawDataPacket . bind ( openBCIUtilities , {
74
+ data : Buffer . alloc ( k . OBCIPacketSizeBLERaw ) ,
75
+ sampleNumber : 0
76
+ } ) ) . to . throw ( k . OBCIErrorUndefinedOrNullInput ) ;
77
+ } ) ;
78
+ it ( 'send null rawDataPacket buffer' , function ( ) {
79
+ expect ( openBCIUtilities . ganglionFillRawDataPacket . bind ( openBCIUtilities , {
80
+ data : Buffer . alloc ( k . OBCIPacketSizeBLERaw ) ,
81
+ rawDataPacket : null ,
82
+ sampleNumber : 0
83
+ } ) ) . to . throw ( k . OBCIErrorUndefinedOrNullInput ) ;
84
+ } ) ;
85
+ it ( 'no sample number' , function ( ) {
86
+ expect ( openBCIUtilities . ganglionFillRawDataPacket . bind ( openBCIUtilities , {
87
+ data : Buffer . alloc ( k . OBCIPacketSizeBLERaw ) ,
88
+ rawDataPacket : Buffer . alloc ( k . OBCIPacketSize )
89
+ } ) ) . to . throw ( k . OBCIErrorUndefinedOrNullInput ) ;
90
+ } ) ;
91
+ it ( 'wrong number of bytes rawDataPacket' , function ( ) {
92
+ expect ( openBCIUtilities . ganglionFillRawDataPacket . bind ( openBCIUtilities , {
93
+ data : Buffer . alloc ( k . OBCIPacketSizeBLERaw ) ,
94
+ rawDataPacket : Buffer . alloc ( 5 ) ,
95
+ sampleNumber : 0
96
+ } ) ) . to . throw ( k . OBCIErrorInvalidByteLength ) ;
97
+ } ) ;
98
+ it ( 'wrong number of bytes data' , function ( ) {
99
+ expect ( openBCIUtilities . ganglionFillRawDataPacket . bind ( openBCIUtilities , {
100
+ data : Buffer . alloc ( 5 ) ,
101
+ rawDataPacket : Buffer . alloc ( k . OBCIPacketSize ) ,
102
+ sampleNumber : 0
103
+ } ) ) . to . throw ( k . OBCIErrorInvalidByteLength ) ;
104
+ } ) ;
105
+ it ( 'undefined' , function ( ) {
106
+ expect ( openBCIUtilities . ganglionFillRawDataPacket . bind ( openBCIUtilities ) ) . to . throw ( k . OBCIErrorUndefinedOrNullInput ) ;
107
+ expect ( openBCIUtilities . ganglionFillRawDataPacket . bind ( openBCIUtilities ) , {
108
+ rawDataPacket : Buffer . alloc ( k . OBCIPacketSize )
109
+ } ) . to . throw ( k . OBCIErrorUndefinedOrNullInput ) ;
110
+ expect ( openBCIUtilities . ganglionFillRawDataPacket . bind ( openBCIUtilities ) , {
111
+ data : Buffer . alloc ( k . OBCIPacketSizeBLERaw )
112
+ } ) . to . throw ( k . OBCIErrorUndefinedOrNullInput ) ;
113
+ } ) ;
114
+ } ) ;
115
+ } ) ;
40
116
describe ( '#ganglionFillRawDataPacket' , function ( ) {
41
117
it ( 'should fill the packet with values from data' , function ( ) {
42
118
const numChannels = k . numberOfChannelsForBoardType ( k . OBCIBoardGanglion ) ;
0 commit comments