Esempio n. 1
0
__declspec(dllexport) void __stdcall StopAcquisitionThread( int device, int channel)
{
	StopAcquisition(device, channel);
}
Esempio n. 2
0
void
Messenger::ProcessMessage(SocketMessage m, int sid)
{
  if (m.GetKey()==REMOVE_CLIENT) {
    if (m.GetIntValue()==GetSocketId()) {
      std::ostringstream o;
      o << "Some client (id=" << sid << ") asked for this master's disconnection!"
        << "\n\tIgnoring this request...";
      throw Exception(__PRETTY_FUNCTION__, o.str(), JustWarning);
      return;
    }
    const MessageKey key = (sid==m.GetIntValue()) ? THIS_CLIENT_DELETED : OTHER_CLIENT_DELETED;
    DisconnectClient(m.GetIntValue(), key);
    throw Exception(__PRETTY_FUNCTION__, "Removing socket client", Info, 11001);
  }
  else if (m.GetKey()==PING_CLIENT) {
    const int toping = m.GetIntValue();
    Send(SocketMessage(PING_CLIENT), toping);
    SocketMessage msg; int i=0;
    do { msg = FetchMessage(toping); i++; } while (msg.GetKey()!=PING_ANSWER && i<MAX_SOCKET_ATTEMPTS);
    try { Send(SocketMessage(PING_ANSWER, msg.GetValue()), sid); } catch (Exception& e) { e.Dump(); }
  }
  else if (m.GetKey()==GET_CLIENTS) {
    int i = 0; std::ostringstream os;
    for (SocketCollection::const_iterator it=fSocketsConnected.begin(); it!=fSocketsConnected.end(); it++, i++) {
      if (i!=0) os << ";";
      os << it->first << " (type " << static_cast<int>(it->second) << ")";
    }
    try { Send(SocketMessage(CLIENTS_LIST, os.str()), sid); } catch (Exception& e) { e.Dump(); }
  }
  else if (m.GetKey()==WEB_GET_CLIENTS) {
    int i = 0; SocketType type; std::ostringstream os;
    for (SocketCollection::const_iterator it=fSocketsConnected.begin(); it!=fSocketsConnected.end(); it++, i++) {
      type = (it->first==GetSocketId()) ? MASTER : it->second;
      if (i!=0) os << ";";
      os << it->first << ",";
      if (it->first==GetSocketId()) os << "Master,";
      else os << "Client" << it->first << ",";
      os << static_cast<int>(type) << "\0";
    }
    try { Send(SocketMessage(CLIENTS_LIST, os.str()), sid); } catch (Exception& e) { e.Dump(); }
  }
  else if (m.GetKey()==START_ACQUISITION) {
    try { StartAcquisition(); } catch (Exception& e) {
      e.Dump();
      SendAll(DAQ, e);
    }
  }
  else if (m.GetKey()==STOP_ACQUISITION) {
    try { StopAcquisition(); } catch (Exception& e) {
      e.Dump();
      SendAll(DAQ, e);
    }
  }
  else if (m.GetKey()==NEW_RUN) {
    try {
      OnlineDBHandler().NewRun();
      int last_run = OnlineDBHandler().GetLastRun();
      SendAll(DQM, SocketMessage(RUN_NUMBER, last_run)); SendAll(DAQ, SocketMessage(RUN_NUMBER, last_run));
    } catch (Exception& e) {
      e.Dump();
    }
  }
  else if (m.GetKey()==GET_RUN_NUMBER) {
    int last_run = 0;
    try { last_run = OnlineDBHandler().GetLastRun(); } catch (Exception& e) { last_run = -1; }
    try { Send(SocketMessage(RUN_NUMBER, last_run), sid); } catch (Exception& e) { e.Dump(); }
  }
  else if (m.GetKey()==SET_NEW_FILENAME) {
    try {
      std::cout << "---> " << m.GetValue() << std::endl;
      SendAll(DQM, SocketMessage(NEW_FILENAME, m.GetValue().c_str()));
    } catch (Exception& e) { e.Dump(); }
  }
  else if (m.GetKey()==NUM_TRIGGERS or m.GetKey()==HV_STATUS) {
    try {
      SendAll(DAQ, m);
    } catch (Exception& e) { e.Dump(); }
  }
  else if (m.GetKey()==NEW_DQM_PLOT or m.GetKey()==UPDATED_DQM_PLOT) {
    try {
      SendAll(DAQ, m);
    } catch (Exception& e) { e.Dump(); }
  }
  else if (m.GetKey()==EXCEPTION) {
    try {
      SendAll(DAQ, m);
      std::cout << "--> " << m.GetValue() << std::endl;
    } catch (Exception& e) { e.Dump(); }
  }
  /*else {
    try { Send(SocketMessage(INVALID_KEY), sid); } catch (Exception& e) { e.Dump(); }
    std::ostringstream o;
    o << "Received an invalid message: " << m.GetString();
    throw Exception(__PRETTY_FUNCTION__, o.str(), JustWarning);
  }*/
}
Esempio n. 3
0
void InitBCI() {
    concurrency::critical_section::scoped_lock lock(bci_mutex);

    std::cout << "Initializing BCI" << std::endl;

    if (StopAcquisition() != ID_WRONG_SEQUENCY_OF_COMMAND) {
        std::cerr << "Stopped previous data acquisition" << std::endl;
    }

    _DEVICE_INFO *devInfo;
    if (!(devInfo = GetDeviceInfo())) {
        throw("GetDeviceInfo() failed");
    }

    std::cout << "ABM Device Info:" << std::endl;
    std::cout << "Device name: " << devInfo->chDeviceName << std::endl;
    std::cout << "COM Port: " << devInfo->nCommPort << std::endl;
    std::cout << "ECG Channel: " << devInfo->nECGPos << std::endl;
    std::cout << "Number of channels: " << devInfo->nNumberOfChannel << std::endl;

    num_channels = devInfo->nNumberOfChannel;

    if (num_channels < 0) {
        std::cerr << "ABM X10 not connected" << std::endl;
        ExitProcess(1);
    }

    std::stringstream destfilepath;
    SYSTEMTIME stime;
    GetLocalTime(&stime);

    int err;


    destfilepath << "data\\" << stime.wYear << "_" << stime.wMonth << "_" << stime.wDay << "_" << stime.wHour << "_" << stime.wMinute << "_" << stime.wSecond << ".ebs";
    std::string dfp = destfilepath.str();

    char fullpath[4096] = "";
    char *pszfn = NULL;

    err = GetFullPathNameA(dfp.c_str(), sizeof(fullpath), fullpath, &pszfn);

    std::cout << "Setting destination file path to " << fullpath << std::endl;

    if (!(err = SetDestinationFile(fullpath))) {
        std::cerr << "SetDestinationFile failed! err " << err << std::endl;
        ExitProcess(1);
    }

    std::cout << "Initiating session..." << std::endl;
    if ((err = InitSession(ABM_DEVICE_X10Standard, ABM_SESSION_RAW, -1, FALSE)) != INIT_SESSION_OK) {
        std::cerr << "InitSession failed! err " << err << std::endl;
        switch (err) {
        case ID_WRONG_SEQUENCY_OF_COMMAND:
            std::cerr << "Wrong command sequence" << std::endl;
            break;
        case INIT_SESSION_NO:
            std::cerr << "Session initiation failed" << std::endl;
            break;
        case INIT_SESSION_NO_DESTFILE_FAILED:
            std::cerr << "No destination file!" << std::endl;
            break;
        }
        ExitProcess(1);
    }

    std::cout << "Getting channel map info" << std::endl;
    _CHANNELMAP_INFO channelMap;
    if (!GetChannelMapInfo(channelMap)) {
        std::cerr << "GetChannelMapInfo failed!" << std::endl;
        ExitProcess(1);
    }

    if (channelMap.nDeviceTypeCode != 0) {
        std::cerr << "ABM X10 not found! :(" << std::endl;
        ExitProcess(1);
    }

    _EEGCHANNELS_INFO& eegChannels = channelMap.stEEGChannels;
    for (int i = 0; i < channelMap.nSize; ++i) {
        std::cout << eegChannels.cChName[i] << " " << eegChannels.bChUsed[i] << " " << eegChannels.bChUsedInQualityData[i] << std::endl;
    }

    std::cout << "Starting acquisition..." << std::endl;
    if (StartAcquisition() != ACQ_STARTED_OK) {
        std::cerr << "StartAcquisition failed!" << std::endl;
        ExitProcess(1);
    }

    running = true;

    std::cout << "BCI initialization done!" << std::endl;

}