Пример #1
0
        public static BlockityCommand <BlockityPin> SetDateTime(DateTime now)
        {
            var dateBytes = new[] {
                (Byte)Int32.Parse(now.ToString("yy")),
                (Byte)now.Month,
                (Byte)now.Day,
                (Byte)now.Hour,
                (Byte)now.Minute,
                (Byte)now.Second,
                now.DayOfWeek == 0 ? (Byte)7 : (Byte)now.DayOfWeek
            };

            var requestBytes = new Byte[dateBytes.Length + 3];

            requestBytes[0] = (Byte)CommandByte.SetDateRequest;
            requestBytes[1] = 7;
            requestBytes[9] = BlockityHelpers.GetCrc(dateBytes);

            dateBytes.CopyTo(requestBytes, 2);

            return(new BlockityCommand <BlockityPin> {
                RequestBytes = requestBytes,
                ResponseCommand = ResponseCommands.SetDateTimeResponse
            });
        }
Пример #2
0
        public static BlockityCommand <Boolean> SetName(String newName)
        {
            if (String.IsNullOrEmpty(newName))
            {
                throw new ArgumentException("Name is either null or empty.", "newName");
            }

            byte[] newNameBytes = Encoding.ASCII.GetBytes(newName.PadRight(15, '#'));
            if (newNameBytes.Length != 15)
            {
                throw new ArgumentException("Name is greater than 15 bytes in length.", "newName");
            }

            var command = new Byte[18];

            command[0] = (Byte)CommandByte.SetBluetoothNameRequest;
            command[1] = 0x0F;

            newNameBytes.CopyTo(command, 2);
            command[17] = BlockityHelpers.GetCrc(newNameBytes);

            return(new BlockityCommand <Boolean> {
                RequestBytes = command,
                ResponseCommand = input => ResponseCommands.SimpleResponse(CommandByte.SetBluetoothNameResponse, input)
            });
        }
Пример #3
0
        private static Boolean ValidateResponse(CommandByte expectedCommand, Byte[] input)
        {
            if (input.Length < 3 || input.Length != input[1] + 3)
            {
                return(false);
            }

            byte[] crcBytes = input.Skip(2).Take(input[1]).ToArray();
            return(BlockityHelpers.GetCrc(crcBytes) == input.Last());
        }
Пример #4
0
 public static BlockityCommand <Boolean> SetPassword(BlockityPin pin)
 {
     return(new BlockityCommand <Boolean> {
         RequestBytes = new Byte[] {
             (Byte)CommandByte.SetBluetoothPinRequest,
             4,
             pin.A,
             pin.B,
             pin.C,
             pin.D,
             BlockityHelpers.GetCrc(
                 new[] {
                 pin.A,
                 pin.B,
                 pin.C,
                 pin.D
             })
         },
         ResponseCommand = input => ResponseCommands.SimpleResponse(CommandByte.SetBluetoothPinResponse, input)
     });
 }
Пример #5
0
        public static BlockityCommand <IEnumerable <Data> > GetData(DateTime date, Byte hoursToRead)
        {
            // TODO: Éstas validaciones DEBEN tomar en cuenta la fecha y hora del aparato... hay que averguar cómo
            //if ( date > DateTime.UtcNow )
            //    throw new ArgumentException("Date to start Data Read cannot be in the future.", "date");

            //if ( date < DateTime.UtcNow.AddDays(-6) )
            //    throw new ArgumentException("Date to start Data Read cannot be greater than 7 days in the past.", "date");

            if (hoursToRead > 3)
            {
                throw new ArgumentException("Hours to Read cannot be greater than 3.", "hoursToRead");
            }

            if (hoursToRead < 1)
            {
                throw new ArgumentException("Hours to Read cannot be less than 1.", "hoursToRead");
            }

            var dayOfWeek = (Byte)(date.DayOfWeek == 0 ? 7 : (Int32)date.DayOfWeek);

            return(new BlockityCommand <IEnumerable <Data> > {
                RequestBytes = new Byte[] {
                    (Byte)CommandByte.ReadDataRequest,
                    3,
                    dayOfWeek,
                    (Byte)date.Hour,
                    hoursToRead,
                    BlockityHelpers.GetCrc(
                        new[] {
                        dayOfWeek,
                        (Byte)date.Hour,
                        hoursToRead
                    })
                },
                ResponseCommand = input => ResponseCommands.GetDataResponse(date, input)
            });
        }