public InternalDeviceInfoPacket(BusResponse response)
        {
            DeviceProtocolId = response.ReadByte();
            DeviceTypeId     = response.ReadByte();
            int dataByte = response.ReadByte();

            LegacyTypePacket    = (dataByte & 0x08) != 0 ? false : true;
            CrcType             = dataByte & 0x07;
            StatisticsAvailable = (dataByte & 0x80) != 0 ? true : false;

            if (LegacyTypePacket)
            {
                BufferSize = response.ReadUInt16();
                response.ReadUInt16(); // reserved bytes
                NameLength        = response.ReadByte();
                VersionInfoLength = response.ReadByte();
            }
            else
            {
                ExtendedDeviceInfoLength = response.ReadUInt16();
                Uuid = response.ReadUInt32();
            }

            UptimeFrequency = response.ReadUInt16();
        }
        private async Task <BusTransceiveResult> TransceiveAsyncInternal(int address, BusRequest request, int responseSize, int attempts, bool sync)
        {
            BusResponse response = new BusResponse(responseSize);

            Types.ErrorCode transceiveStatus = Types.ErrorCode.TransportTransmissionError;

            while (attempts > 0)
            {
                (ErrorCode, byte[])result = sync ?
                                            BusAbstraction.Transceive(address, request.GetByteArray(), responseSize) :
                                            await BusAbstraction.TransceiveAsync(address, request.GetByteArray(), responseSize);

                transceiveStatus = result.Item1;
                byte[] receiveBuffer = result.Item2;

                response = new BusResponse(responseSize);
                response.Fill(receiveBuffer);

                switch (transceiveStatus)
                {
                case Types.ErrorCode.Success:
                    ++successfulTransmissions;
                    return(new BusTransceiveResult(Types.ErrorCode.Success, response));

                case Types.ErrorCode.TransportChecksumError:
                    ++checksumErrors;
                    break;

                case Types.ErrorCode.TransportReceptionNoAnswerError:
                    ++noAnswer;
                    break;

                case Types.ErrorCode.TransportReceptionMissingDataError:
                    ++missingData;
                    break;

                case Types.ErrorCode.TransportTransmissionError:
                    ++transmitErrors;
                    break;
                }

                attempts--;
            }

            return(new BusTransceiveResult(transceiveStatus, response));
        }
 public static bool HasNoErrorsAndSolutionIsNotEmpty <TSolution>(this BusResponse <TSolution> response)
 {
     return(string.IsNullOrEmpty(response.Errors) && response.Solution != null && response.Solution.Any());
 }
Esempio n. 4
0
 /// <summary>
 /// Creates a new instance, initializing the fields.
 /// </summary>
 /// <param name="transportError">The error code associated with the transceive operation.</param>
 /// <param name="response">The response of the associated transceive operation.</param>
 public BusTransceiveResult(ErrorCode transportError, BusResponse response)
 {
     this.TransportError = transportError;
     this.Response       = response;
 }