Beispiel #1
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)
            });
        }
Beispiel #2
0
 public static BlockityCommand <Byte> GetBatteryLevel()
 {
     return(new BlockityCommand <Byte> {
         RequestBytes = new Byte[] {
             (Byte)CommandByte.ReadDeviceDataRequest,
             1
         },
         ResponseCommand = input => ResponseCommands.RawResponse(input)[0]
     });
 }
Beispiel #3
0
 public static BlockityCommand <Boolean> FactoryReset()
 {
     return(new BlockityCommand <Boolean> {
         RequestBytes = new Byte[] {
             (Byte)CommandByte.FactoryResetRequest,
             0,
             0
         },
         ResponseCommand = input => ResponseCommands.SimpleResponse(CommandByte.FactoryResetResponse, input)
     });
 }
Beispiel #4
0
 public static BlockityCommand <Boolean> ClearData()
 {
     return(new BlockityCommand <Boolean> {
         RequestBytes = new Byte[] {
             (Byte)CommandByte.ClearDataRequest,
             0,
             0
         },
         ResponseCommand = input => ResponseCommands.SimpleResponse(CommandByte.ClearDataRequest, input)
     });
 }
Beispiel #5
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)
     });
 }
Beispiel #6
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)
            });
        }