48 strcpy(this->filename,filename);
49 mindset_fp = open(filename,O_RDWR);
50 is_open = mindset_fp >= 0;
79 status = SendCommand(
READY).io_hdr.masked_status==0;
112 return GetStatus().sample_rate;
117 return GetStatus().block_size;
132 unsigned char *reply = mr.
reply;
139 static const int DeviceBufferBegin = 0x2000;
140 static const int DeviceBufferEnd = 0x9DFF;
141 unsigned short shortHead;
142 unsigned short shortTail;
145 shortHead = reply[1] << 8 | reply[2];
146 shortTail = reply[3] << 8 | reply[4];
148 if (shortHead <= shortTail)
149 numBytes = shortTail - shortHead;
151 numBytes = shortTail - DeviceBufferBegin + DeviceBufferEnd - shortHead;
158 void Mindset24::CheckInquiry()
163 unsigned char *dest = mr.
reply;
164 char product[31-15+1];
165 memcpy(product,dest+16,16);product[16]=
'\0';
171 is_mindset = strstr(product,
"MINDSET") !=NULL;
178 return "Error - Mindset Not Opened";
180 std::stringstream ss;
183 unsigned char *dest = mr.
reply;
185 char product[31-15+1];
186 char firmware[35-31+1];
187 memcpy(product,dest+16,16);product[16]=
'\0';
188 memcpy(vendor,dest+8,8);vendor[8]=
'\0';
189 memcpy(firmware,dest+32,4);firmware[4]=
'\0';
191 ss <<
"Product ID:\t\t" << product << std::endl;
192 ss <<
"Vendor ID:\t\t" << vendor << std::endl;
193 ss <<
"Firmware version:\t" << firmware << std::endl;
194 ss <<
"Device type:\t\t" << int(dest[0]) << std::endl;
195 ss <<
"Type Qualifier:\t\t" << int(dest[1]) << std::endl;
196 ss <<
"ANSI Version:\t\t" << int(dest[2]) << std::endl;
197 ss <<
"Additional Length:\t" << int(dest[4]) << std::endl;
198 ss <<
"Firmware Year:\t\t" << int(dest[5]);
213 ublas::matrix<double> ret;
221 bytes_per_block = ActualBlockSize(bsize);
226 if(bytes_available < bytes_per_block || bytes_available > 30000)
233 if(bytes_per_block != 0)
234 output_len = (int)(bytes_available/bytes_per_block) * bytes_per_block;
236 throw "Error reading from mindset.";
239 printf(
"DEBUG: inside GetAllData(), bytes_available = %d, bytes_per_block = %d, output_len = %d\n",bytes_available, bytes_per_block, output_len);
248 ret = (CreateEEGMatrix(mr));
264 bytes_per_block = ActualBlockSize(bsize);
267 while (bytes_available < bytes_per_block)
269 status = GetStatus();
272 bytes_per_block = ActualBlockSize(bsize);
275 ublas::matrix<double> ret(0,0);
280 ret = CreateEEGMatrix(mr);
289 int Mindset24::ActualBlockSize(
BlockSize b)
303 ublas::matrix<double> Mindset24::CreateEEGMatrix(
const MindsetReply &mr)
306 int nsamples = numBytes / 24 / 2;
311 ublas::matrix<double> ret_matrix;
313 printf(
"DEBUG: inside CreateEEGMatrix, nsamples = %d, ret_matrix size1 = %d, reply_len = %d\n",
315 int(ret_matrix.size1()),
319 ret_matrix.resize(24,nsamples);
320 for (sample = 0; sample < nsamples; sample++)
321 for (chan = 0; chan < 24; chan++)
323 ret_matrix(chan, sample) = ((mr.
reply[b] << 8 | mr.
reply[b+1]) - 0x7000) / 363.63;
347 throw(
"Failed to read from mindset.");
351 static unsigned char commandBlock[6];
352 memset(&commandBlock,0,6);
357 unsigned char *reply = ret.
reply;
360 memset(&io_hdr,0,
sizeof(sg_io_hdr_t));
361 io_hdr.interface_id =
'S';
363 io_hdr.cmd_len =
sizeof(commandBlock);
364 io_hdr.dxfer_len = bytes;
365 io_hdr.dxferp = reply;
366 io_hdr.cmdp = commandBlock;
367 io_hdr.sbp = sense_buffer;
368 io_hdr.timeout = 5000;
374 commandBlock[0] = 0x12;
375 commandBlock[4] = bytes;
376 io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
379 commandBlock[0] = 0xc0;
380 commandBlock[1] = 0x04;
381 commandBlock[2] = value;
382 io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
385 commandBlock[0] = 0xc0;
386 commandBlock[1] = 0x06;
387 commandBlock[4] = 0x1e;
388 io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
391 commandBlock[0] = 0x00;
392 io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
395 commandBlock[0] = 0xc0;
396 commandBlock[1] = 0x03;
397 commandBlock[2] = value;
398 io_hdr.dxfer_direction = SG_DXFER_TO_DEV;
401 commandBlock[0] = 0xc0;
402 commandBlock[1] = 0x05;
403 commandBlock[2] = value;
404 io_hdr.dxfer_direction = SG_DXFER_TO_DEV;
407 printf(
"Mindset SCSI: Incorrect command %d sent to Mindset.\n",command);
411 if(ioctl(mindset_fp, SG_IO, &io_hdr) < 0)
413 throw(
"Mindset SCSI: ioctl error\n");
417 if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK)
419 printf(
"Mindset SCSI: io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK\n");
420 if (io_hdr.sb_len_wr > 0)
424 if (io_hdr.masked_status)
425 printf(
"Mindset SCSI status=0x%x\n", io_hdr.status);
426 if (io_hdr.host_status)
427 printf(
"Mindset SCSI host_status=0x%x\n", io_hdr.host_status);
428 if (io_hdr.driver_status)
429 printf(
"Mindset driver_status=0x%x\n", io_hdr.driver_status);
432 printf(
"Mindst SCSI command duration=%u millisecs, resid=%d\n",
433 io_hdr.duration, io_hdr.resid);