Ejemplo n.º 1
0
        SalachovRequest(RUSDeviceId deviceId, Command address, bool isWriteRequest, ResponseLength responseLength, IEnumerable <IDataEntity> dataEntities, DeviceOperationScope scope)
        {
            DeviceId       = deviceId;
            Address        = address;
            IsWriteRequest = isWriteRequest;
            var addressInfo = Address.GetInfo();

            _responseFullLength = responseLength;
            _hasLengthField     = _responseFullLength.IsUnknown;

            _commandWords = new ushort[]
            {
                (ushort)(((byte)DeviceId << 9) | ((~0x80) & Address.GetInfo().Address) | (IsWriteRequest ? 1 << 7 : 0)),
                0x0000
            };
            _header = wordsToBytes(_commandWords).ToArray();

            Serialized = serialize(dataEntities);

            IEnumerable <byte> serialize(IEnumerable <IDataEntity> entities)
            {
                var dataBytes = entities
                                .Select(e => e.RawValue)
                                .Flatten()
                                .ToArray();
                var zeroTrailShouldBeAdded = dataBytes.Length % 2 == 1;
                var actualLength           = zeroTrailShouldBeAdded
                    ? dataBytes.Length + 1
                    : dataBytes.Length;
                var requestBytes = new Enumerable <byte>()
                {
                    _header,
                    IsWriteRequest     // If there is data - we need to add length of the data
                            ? wordsToBytes(((ushort)actualLength).ToSequence())
                            : new byte[0],
                    dataBytes,
                    zeroTrailShouldBeAdded
                            ? new byte[1]
                            : new byte[0]
                };

                requestBytes.Add(wordsToBytes(_checksum.ComputeChecksum(requestBytes).ToSequence()));

                return(requestBytes);
            }
        }
Ejemplo n.º 2
0
 SalachovRequest(RUSDeviceId deviceId, Command address, bool isWriteRequest, ResponseLength responseLength, DeviceOperationScope scope)
     : this(deviceId, address, isWriteRequest, responseLength, new IDataEntity[0], scope)
 {
 }
Ejemplo n.º 3
0
 public ResponseInfo(ResponseReadMode readMode, ResponseLength responseFullLength, IEnumerable <byte> expectedAnswer)
 {
     ReadMode           = readMode;
     ResponseFullLength = responseFullLength ?? throw new ArgumentNullException(nameof(responseFullLength));
     ExpectedAnswer     = expectedAnswer;
 }