Пример #1
0
        public GpsModuleStatusResponse GetStatus()
        {
            var response = new GpsModuleStatusResponse {
                Enabled = false
            };
            var command = $"{BASE_COMMAND}{GET_STATUS_COMMAND}";

            _logger.LogInformation(command);
            _serialPort.WriteLine(command);
            Thread.Sleep(500);
            var rawResponse = _serialPort.ReadExisting();

            _logger.LogInformation(rawResponse);
            if (rawResponse.Contains("OK"))
            {
                try
                {
                    var parsedResponse = ParseStatusResponse(rawResponse);
                    response = new GpsModuleStatusResponse
                    {
                        Enabled = parsedResponse[0] == "1",
                        Mode    = (GpsModuleModes)int.Parse(parsedResponse[1])
                    };
                    _statusReportService.DisplayStatus(response);
                    return(response);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Error parsing GPS Status Response");
                    _statusReportService.DisplayStatus(response);
                }
            }
            return(response);
        }
Пример #2
0
        public bool SetStatus(GpsModuleStatusResponse status)
        {
            var command = $"{BASE_COMMAND}{SET_STATUS_COMMAND}{status}";

            _logger.LogInformation(command);
            _serialPort.WriteLine(command);
            Thread.Sleep(5000);
            var rawResponse = _serialPort.ReadExisting();

            _logger.LogInformation(rawResponse);
            var response = new GpsModuleStatusResponse
            {
                Enabled = rawResponse.Contains("OK")
            };

            _statusReportService.DisplayStatus(response);
            return(true);
        }