示例#1
0
        private string Transmit(string[] items)
        {
            try
            {
                // Check if command is correct
                if (items.Length != 4)
                {
                    return("err,invalid command");
                }
                var channelId   = Convert.ToInt32(items[1]);
                var label       = Convert.ToByte(items[2], 8);
                var payloadData = (uint)Convert.ToInt32(items[3], 16);

                // Check if payload only contains 24 bit.
                if (payloadData > 0xffffff)
                {
                    logger.LogWarning($"Invalid data to transmit on channel {channelId} with label: {label} data: {payloadData}");
                    return("err,invalid data");
                }

                if (hardware.TransmitA429Data(channelId, label, payloadData))
                {
                    return("ok");
                }

                logger.LogInformation($"Failed to transmit data. ({Id})");
                return("err,hardware error");
            }
            catch (Exception ex)
            {
                logger.LogWarning($"Invalid format of request: {string.Join(",", items)} ({Id})", ex);
                return("err,invalid format");
            }
        }