Exemplo n.º 1
0
        public async void ProcessCommands()
        {
            Debug.WriteLine("SyncHandler: ProcessCommands");

            if (this.ProcessQeueue.Count > 0)
            {
                Command = this.ProcessQeueue.Dequeue();
            }
            else
            {
                Debug.WriteLine("No more commands to be processed!");
                return;
            }

            ICharacteristic chr = null;

            switch (Command)
            {
            case Constants.SyncHandlerSequence.EnableFF07:
                Debug.WriteLine("SyncDeviceHandler939: Enabling FF07 characteristic");
                Ff07Char = GetServicesCharacteristic(Constants.CharacteristicsUUID._FF07);
                if (Ff07Char == null)
                {
                    Debug.WriteLine("FF07 is NULL. Disconnecting device.");
                    this.Adapter.DisconnectDevice(Device);
                }
                else
                {
                    Ff07Char.StartUpdates();
                }
                break;

            case Constants.SyncHandlerSequence.EnableFF08:
                Debug.WriteLine("SyncDeviceHandler939: Enabling FF08 characteristic");
                Ff08Char = GetServicesCharacteristic(Constants.CharacteristicsUUID._FF08);
                if (Ff08Char == null)
                {
                    Debug.WriteLine("FF08 is NULL. Disconnecting device.");
                    this.Adapter.DisconnectDevice(Device);
                }
                else
                {
                    Ff08Char.StartUpdates();
                }
                break;

            case Constants.SyncHandlerSequence.ReadModel:
                Debug.WriteLine("SyncDeviceHandler939: Reading model from characteristic.");
                ReadChar = GetServicesCharacteristic(Constants.CharacteristicsUUID._2A24);
                chr      = await ReadChar.ReadAsync();

                Debug.WriteLine("Model: " + System.Text.Encoding.UTF8.GetString(chr.Value, 0, chr.Value.Length));
                ProcessCommands();
                break;

            case Constants.SyncHandlerSequence.ReadSerial:
                Debug.WriteLine("SyncDeviceHandler939: Reading serial from characterisitic.");
                ReadChar = GetServicesCharacteristic(Constants.CharacteristicsUUID._2A25);
                chr      = await ReadChar.ReadAsync();

                Debug.WriteLine("Serial: " + System.Text.Encoding.UTF8.GetString(chr.Value, 0, chr.Value.Length));
                ProcessCommands();
                break;

            case Constants.SyncHandlerSequence.ReadFwVersion:
                Debug.WriteLine("SyncDeviceHandler939: Reading fw version from characteristic.");
                ReadChar = GetServicesCharacteristic(Constants.CharacteristicsUUID._2A26);
                chr      = await ReadChar.ReadAsync();

                Debug.WriteLine("Firmware Version: " + System.Text.Encoding.UTF8.GetString(chr.Value, 0, chr.Value.Length));
                ProcessCommands();
                break;

            case Constants.SyncHandlerSequence.ReadManufacturer:
                Debug.WriteLine("SyncDeviceHandler939: Reading manufacturer from characteristic.");
                this.StartIncrementProgress = true;
                ReadChar = GetServicesCharacteristic(Constants.CharacteristicsUUID._2A29);
                chr      = await ReadChar.ReadAsync();

                Debug.WriteLine("Manufacturer: " + System.Text.Encoding.UTF8.GetString(chr.Value, 0, chr.Value.Length));
                ProcessCommands();
                break;

            case Constants.SyncHandlerSequence.ReadBatteryLevel:
                Debug.WriteLine("SyncDeviceHandler939: Reading battery level from characteristic.");
                ReadChar = GetServicesCharacteristic(Constants.CharacteristicsUUID._2A19);
                chr      = await ReadChar.ReadAsync();

                Debug.WriteLine("Battery Level: " + (int)chr.Value[0]);
                ProcessCommands();
                break;

            case Constants.SyncHandlerSequence.ReadDeviceStatus:
                Debug.WriteLine("SyncDeviceHandler939: Read Device Status");
                CommandRequest = new byte[] { 0x1B, 0x13 };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadDeviceSettings:
                Debug.WriteLine("SyncDeviceHandler939: Read Device Settings");
                CommandRequest = new byte[] { 0x1B, 0x17 };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadUserSettings:
                Debug.WriteLine("SyncDeviceHandler939: Read User Settings");
                CommandRequest = new byte[] { 0x1B, 0x19 };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadStepsHeader:
                Debug.WriteLine("SyncDeviceHandler939: Read Steps Header");
                CommandRequest = new byte[] { 0x1B, 0x22 };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadSeizureTable:
                Debug.WriteLine("SyncDeviceHandler939: Read Seizure Table");
                break;

            case Constants.SyncHandlerSequence.ReadHourlySteps:
                Debug.WriteLine("SyncDeviceHandler939: Read Steps Header");
                //CommandRequest = new byte[] { 0x1B, 0x24, 0x };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadCurrentHour:
                Debug.WriteLine("SyncDeviceHandler939: Read Current Hour");
                CommandRequest = new byte[] { 0x1B, 0x27 };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadSignature:
                Debug.WriteLine("SyncDeviceHandler939: Read Signature Data");
                //CommandRequest = new byte[] { 0x1B, 0x27 };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadSeizure:
                Debug.WriteLine("SyncDeviceHandler939: Read seizure Data");
                break;

            case Constants.SyncHandlerSequence.WriteStepsHeader:
                Debug.WriteLine("SyncDeviceHandler939: Writing steps header");
                break;

            case Constants.SyncHandlerSequence.WriteDeviceSettings:
                Debug.WriteLine("SyncDeviceHandler939: Writing device settings");
                break;

            case Constants.SyncHandlerSequence.WriteUserSettings:
                Debug.WriteLine("SyncDeviceHandler939: Writing user settings");
                break;

            case Constants.SyncHandlerSequence.WriteExerciseSettings:
                Debug.WriteLine("SyncDeviceHandler939: Writing exercise settings");
                break;

            case Constants.SyncHandlerSequence.WriteCompanySettings:
                Debug.WriteLine("SyncDeviceHandler939: Writing company settings");
                break;

            case Constants.SyncHandlerSequence.WriteSignatureSettings:
                Debug.WriteLine("SyncDeviceHandler939: Writing signature settings");
                break;

            case Constants.SyncHandlerSequence.WriteSeizureSettings:
                Debug.WriteLine("SyncDeviceHandler939: Writing seizure settings");
                break;

            case Constants.SyncHandlerSequence.WriteScreenFlow:
                Debug.WriteLine("SyncDeviceHandler939: Writing screenflow settings");
                break;

            case Constants.SyncHandlerSequence.WriteDeviceSensitivity:
                Debug.WriteLine("SyncDeviceHandler936: Writing device sensitivity settings");
                break;

            case Constants.SyncHandlerSequence.WriteDeviceStatus:
                Debug.WriteLine("SyncDeviceHandler939: Writing device status settings");
                break;

            case Constants.SyncHandlerSequence.WriteScreenDisplay:
                Debug.WriteLine("SyncDeviceHandler939: Writing screen display");
                break;

            case Constants.SyncHandlerSequence.ClearEEProm:
                Debug.WriteLine("SyncDeviceHandler939: Clear eeprom");
                break;

            case Constants.SyncHandlerSequence.WsGetDeviceInfo:
                Debug.WriteLine("SyncDeviceHandler939: WS Request GetDeviceInfo");
                Dictionary <String, object> parameter = new Dictionary <String, object>();
                parameter.Add("serno", "9999999894");
                parameter.Add("fwver", "4.3");
                parameter.Add("mdl", "961");
                parameter.Add("aid", 16781);
                parameter.Add("ddtm", "16-08-12 14:15");
                await WebService.PostData("https://test.savvysherpa.com/DeviceServices/api/Pedometer/GetDeviceInfo", parameter);

                break;

            default:
                Debug.WriteLine("SyncDeviceHandler939: Unable to identify command.");
                break;
            }

            if (this.ProcessQeueue.Count == 0)
            {
                Debug.WriteLine("Queue is already empty. Device will be disconnected.");
                this.Adapter.DisconnectDevice(this.Device);
                this.SyncDone(this, new SyncDoneEventArgs {
                    Status = true
                });
            }
        }
Exemplo n.º 2
0
        public async void ProcessCommands()
        {
            Debug.WriteLine("SyncHandler: ProcessCommands");

            if (this.ProcessQeueue.Count > 0)
            {
                Command = this.ProcessQeueue.Dequeue();
            }
            else
            {
                Debug.WriteLine("No more commands to be processed! Disconnecting device.");
                this.Adapter.DisconnectDevice(this.Device);
                return;
            }

            ICharacteristic chr = null;

            switch (Command)
            {
            case Constants.SyncHandlerSequence.EnableFF07:
                Debug.WriteLine("SyncDeviceHandler961: Enabling FF07 characteristic");
                Ff07Char = GetServicesCharacteristic(Constants.CharacteristicsUUID._FF07);
                if (Ff07Char == null)
                {
                    Debug.WriteLine("FF07 is NULL. Disconnecting device.");
                    this.Adapter.DisconnectDevice(Device);
                }
                else
                {
                    Ff07Char.StartUpdates();
                }
                break;

            case Constants.SyncHandlerSequence.EnableFF08:
                Debug.WriteLine("SyncDeviceHandler961: Enabling FF08 characteristic");
                Ff08Char = GetServicesCharacteristic(Constants.CharacteristicsUUID._FF08);
                if (Ff08Char == null)
                {
                    Debug.WriteLine("FF08 is NULL. Disconnecting device.");
                    this.Adapter.DisconnectDevice(Device);
                }
                else
                {
                    Ff08Char.StartUpdates();
                }
                break;

            case Constants.SyncHandlerSequence.ReadModel:
                Debug.WriteLine("SyncDeviceHandler961: Reading model from characteristic.");
                ReadChar = GetServicesCharacteristic(Constants.CharacteristicsUUID._2A24);
                chr      = await ReadChar.ReadAsync();

                int num = 0;
                Debug.WriteLine("Model: " + num);
                int.TryParse(System.Text.Encoding.UTF8.GetString(chr.Value, 0, chr.Value.Length).Replace("PE", "").Replace("FT", ""), out num);
                this.TrioDeviceInformationInstance.ModelNumber = num;
                ProcessCommands();
                break;

            case Constants.SyncHandlerSequence.ReadSerial:
                Debug.WriteLine("SyncDeviceHandler961: Reading serial from characterisitic.");
                ReadChar = GetServicesCharacteristic(Constants.CharacteristicsUUID._2A25);
                chr      = await ReadChar.ReadAsync();

                long serial = 0;
                long.TryParse(System.Text.Encoding.UTF8.GetString(chr.Value, 0, chr.Value.Length), out serial);
                Debug.WriteLine("Serial: " + serial);
                this.TrioDeviceInformationInstance.SerialNumber = serial;
                ProcessCommands();
                break;

            case Constants.SyncHandlerSequence.ReadFwVersion:
                Debug.WriteLine("SyncDeviceHandler961: Reading fw version from characteristic.");
                ReadChar = GetServicesCharacteristic(Constants.CharacteristicsUUID._2A26);
                chr      = await ReadChar.ReadAsync();

                float fwVer = 0;
                float.TryParse(System.Text.Encoding.UTF8.GetString(chr.Value, 0, chr.Value.Length), out fwVer);
                Debug.WriteLine("Firmware Version: " + fwVer);
                this.TrioDeviceInformationInstance.FirmwareVersion = fwVer;
                ProcessCommands();
                break;

            case Constants.SyncHandlerSequence.ReadManufacturer:
                Debug.WriteLine("SyncDeviceHandler961: Reading manufacturer from characteristic.");
                this.StartIncrementProgress = true;
                ReadChar = GetServicesCharacteristic(Constants.CharacteristicsUUID._2A29);
                chr      = await ReadChar.ReadAsync();

                Debug.WriteLine("Manufacturer: " + System.Text.Encoding.UTF8.GetString(chr.Value, 0, chr.Value.Length));
                ProcessCommands();
                break;

            case Constants.SyncHandlerSequence.ReadBatteryLevel:
                Debug.WriteLine("SyncDeviceHandler961: Reading battery level from characteristic.");
                ReadChar = GetServicesCharacteristic(Constants.CharacteristicsUUID._2A19);
                chr      = await ReadChar.ReadAsync();

                int battery = (int)chr.Value[0];
                Debug.WriteLine("Battery Level: " + battery);
                this.TrioDeviceInformationInstance.BatteryLevel = battery;
                ProcessCommands();
                break;

            case Constants.SyncHandlerSequence.ReadTallies:
                Debug.WriteLine("SyncDeviceHandler961: Read Device Tallies");
                CommandRequest = new byte[] { 0x1B, 0x5D };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadDeviceInformation:
                Debug.WriteLine("SyncDeviceHandler961: Read Device Information");
                CommandRequest = new byte[] { 0x1B, 0x40 };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadDeviceStatus:
                Debug.WriteLine("SyncDeviceHandler961: Read Device Status");
                CommandRequest = new byte[] { 0x1B, 0x13 };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadDeviceSettings:
                Debug.WriteLine("SyncDeviceHandler961: Read Device Settings");
                CommandRequest = new byte[] { 0x1B, 0x17 };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadUserSettings:
                Debug.WriteLine("SyncDeviceHandler961: Read User Settings");
                //CommandRequest = new byte[] { 0x1B, 0x19 };
                CommandRequest = await UserSettingsInstance.GetReadCommand();

                Debug.WriteLine("Read User Settings: " + Motion.Mobile.Utilities.Utils.ByteArrayToHexString(CommandRequest));
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadStepsHeader:
                Debug.WriteLine("SyncDeviceHandler961: Read Steps Header");
                CommandRequest = new byte[] { 0x1B, 0x22 };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadSeizureTable:
                Debug.WriteLine("SyncDeviceHandler961: Read Seizure Table");
                break;

            case Constants.SyncHandlerSequence.ReadHourlySteps:
                Debug.WriteLine("SyncDeviceHandler961: Read Steps Header");
                //CommandRequest = new byte[] { 0x1B, 0x24, 0x };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadCurrentHour:
                Debug.WriteLine("SyncDeviceHandler961: Read Current Hour");
                CommandRequest = new byte[] { 0x1B, 0x27 };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadSignature:
                Debug.WriteLine("SyncDeviceHandler961: Read Signature Data");
                //CommandRequest = new byte[] { 0x1B, 0x27 };
                this.Adapter.SendCommand(Ff07Char, CommandRequest);
                break;

            case Constants.SyncHandlerSequence.ReadSeizure:
                Debug.WriteLine("SyncDeviceHandler961: Read seizure Data");
                break;

            case Constants.SyncHandlerSequence.WriteStepsHeader:
                Debug.WriteLine("SyncDeviceHandler961: Writing steps header");
                break;

            case Constants.SyncHandlerSequence.WriteDeviceSettings:
                Debug.WriteLine("SyncDeviceHandler961: Writing device settings");
                break;

            case Constants.SyncHandlerSequence.WriteUserSettings:
                Debug.WriteLine("SyncDeviceHandler961: Writing user settings");
                break;

            case Constants.SyncHandlerSequence.WriteExerciseSettings:
                Debug.WriteLine("SyncDeviceHandler961: Writing exercise settings");
                break;

            case Constants.SyncHandlerSequence.WriteCompanySettings:
                Debug.WriteLine("SyncDeviceHandler961: Writing company settings");
                break;

            case Constants.SyncHandlerSequence.WriteSignatureSettings:
                Debug.WriteLine("SyncDeviceHandler961: Writing signature settings");
                break;

            case Constants.SyncHandlerSequence.WriteSeizureSettings:
                Debug.WriteLine("SyncDeviceHandler961: Writing seizure settings");
                break;

            case Constants.SyncHandlerSequence.WriteScreenFlow:
                Debug.WriteLine("SyncDeviceHandler961: Writing screenflow settings");
                break;

            case Constants.SyncHandlerSequence.WriteDeviceSensitivity:
                Debug.WriteLine("SyncDeviceHandler961: Writing device sensitivity settings");
                break;

            case Constants.SyncHandlerSequence.WriteDeviceStatus:
                Debug.WriteLine("SyncDeviceHandler961: Writing device status settings");
                break;

            case Constants.SyncHandlerSequence.WriteScreenDisplay:
                Debug.WriteLine("SyncDeviceHandler961: Writing screen display");
                break;

            case Constants.SyncHandlerSequence.ClearEEProm:
                Debug.WriteLine("SyncDeviceHandler961: Clear eeprom");
                break;

            case Constants.SyncHandlerSequence.WsGetDeviceInfo:
                Debug.WriteLine("SyncDeviceHandler961: WS Request GetDeviceInfo");
                //to be replaced - start
                Dictionary <String, object> parameter = new Dictionary <String, object>();
                parameter.Add("serno", "9999999894");
                parameter.Add("fwver", "4.3");
                parameter.Add("mdl", "961");
                parameter.Add("aid", 16781);
                parameter.Add("ddtm", "16-08-12 14:15");
                Dictionary <string, object> dictionary = await WebService.PostData("https://test.savvysherpa.com/DeviceServices/api/Pedometer/GetDeviceInfo", parameter);

                //to be replaced - end
                string status = null;
                if (dictionary.ContainsKey("status"))
                {
                    status = dictionary["status"].ToString();
                }

                if (status != null && status.ToUpper().CompareTo("OK") == 0)
                {
                    Debug.WriteLine("Device is paired");
                    this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.ReadTallies);
                    this.ProcessCommands();
                }
                else
                {
                    Debug.WriteLine("Device is not paired");
                    this.Adapter.DisconnectDevice(this.Device);
                }

                break;

            case Constants.SyncHandlerSequence.WsUploadTallies:
                break;

            case Constants.SyncHandlerSequence.WsUploadSteps:
                break;

            case Constants.SyncHandlerSequence.WsUploadSignature:
                break;

            case Constants.SyncHandlerSequence.WsUploadProfile:
                break;

            case Constants.SyncHandlerSequence.WsUnpairDevice:
                break;

            case Constants.SyncHandlerSequence.WsUploadSeizure:
                break;

            case Constants.SyncHandlerSequence.WsSendNotifySettingsUpdate:
                break;

            default:
                Debug.WriteLine("SyncDeviceHandler961: Unable to identify command.");
                break;
            }
        }