Ejemplo n.º 1
0
        // Handle TCPIP server commands
        #region CommandServer

        /// <summary>
        /// Process a request from the TCPIP command server port
        /// </summary>
        private async Task <string> CommandServerProcessRequestAsync(string request)
        {
            try
            {
                UriArgParser args = new UriArgParser(request);
                switch (args.Request)
                {
                case "loglevel":
                    return(ProcessChangeLogLevel(args));

                case "recording":
                    return(await ProcessSetRecording(args));

                case "srbset":
                    return(ProcessSrbSet(args));

                case "streamset":
                    return(ProcessStreamSet(args));

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.AddLog(new LogEventArgs(this, "CommandServerProcessRequest", e, LogLevel.WARN));
            }

            Logger.AddLog(new LogEventArgs(this, "CommandServerProcessRequest", $"Invalid request {request}", LogLevel.WARN));
            return($"NAK?response=Invalid request&time={DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}\n");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Process set recording command
        /// </summary>
        private async Task <string> ProcessSetRecording(UriArgParser args)
        {
            try
            {
                var enable     = bool.Parse(args.GetArg("enable"));
                var fileName   = args.GetArg("filename");
                var formatType = args.GetArg("format");
                if (BrainflowBoard == null)
                {
                    return($"NAK?response=Board is not reading data.");
                }
                if (enable)
                {
                    if (FileWriter.IsLogging)
                    {
                        return($"NAK?response=You must close the current recording file before starting a new one.");
                    }


                    FileWriterType format = FileWriterType.Bdf;
                    switch (formatType)
                    {
                    case "txt":
                        format = FileWriterType.OpenBciTxt;
                        break;

                    case "bdf":
                        format = FileWriterType.Bdf;
                        break;
                    }

                    var recordingDir = ConfigurationManager.AppSettings.Get("defaultDir");
                    var path         = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), recordingDir);
                    await FileWriter.StartWritingToFileAsync(path, fileName, BrainflowBoard.BoardId, BrainflowBoard.SampleRate, format, new FileHeaderInfo()
                    {
                        SessionName = fileName
                    });

                    return($"ACK?response=File {Path.GetFileName(FileWriter.FileName)} started.");
                }
                else
                {
                    if (FileWriter != null && !FileWriter.IsLogging)
                    {
                        return($"NAK?response=No recording in progress.");
                    }
                    await FileWriter.StopWritingToFileAsync();

                    return($"ACK?response=Recording stopped.");
                }
            }
            catch (Exception)
            {
                return($"NAK?response=Invalid parameters");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Process change log level command
        /// </summary>
        private string ProcessChangeLogLevel(UriArgParser args)
        {
            Logger.LogLevelDisplay = (LogLevel)int.Parse(args.GetArg("level"));
            Logger.AddLog(new LogEventArgs(this, "CommandServerProcessRequest", $"Process request to set log level to {Logger.LogLevelDisplay}.", LogLevel.INFO));
            if (LoggingWindow != null)
            {
                LoggingWindow.ChangeLogLevel();
            }

            return($"ACK?response=Log level set to {Logger.LogLevelDisplay}.");
        }
Ejemplo n.º 4
0
 private string ProcessStreamSet(UriArgParser args)
 {
     try
     {
         var enable = bool.Parse(args.GetArg("enable"));
         BrainflowBoard.RequestEnableStreaming(enable);
         return($"ACK?response=Request enable stream {enable}");
     }
     catch (Exception e)
     {
         Logger.AddLog(new LogEventArgs(this, "ProcessStreamSet", e, LogLevel.ERROR));
     }
     return($"NAK?response=bad arguments");
 }
Ejemplo n.º 5
0
 private string ProcessSrbSet(UriArgParser args)
 {
     try
     {
         var enable = bool.Parse(args.GetArg("enable"));
         var board  = int.Parse(args.GetArg("board"));
         BrainflowBoard.RequestSetSrb1(board, enable);
         return($"ACK?response=Request set SRB1 {enable}");
     }
     catch (Exception e)
     {
         Logger.AddLog(new LogEventArgs(this, "ProcessSrbSet", e, LogLevel.ERROR));
     }
     return($"NAK?response=bad arguments");
 }