예제 #1
0
 public void CleanUp()
 {
     this.ProcessQeueue.Clear();
     this.Command        = Constants.SyncHandlerSequence.Default;
     this.CommandRequest = new byte[] { };
     this.PacketsReceived.Clear();
     this.Device = null;
     this.StartIncrementProgress = false;
 }
예제 #2
0
		public void CleanUp()
		{
			this.ProcessQeueue.Clear();
			this.Command = Constants.SyncHandlerSequence.Default;
			this.CommandRequest = new byte[] { };
			this.PacketsReceived.Clear();
			this.Device = null;
			this.StartIncrementProgress = false;
		}
예제 #3
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("SyncDeviceHandler936: 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("SyncDeviceHandler936: 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("SyncDeviceHandler936: 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("SyncDeviceHandler936: 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("SyncDeviceHandler936: 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("SyncDeviceHandler936: 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("SyncDeviceHandler936: 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(": Read Device Status");
					CommandRequest = new byte[] { 0x1B, 0x13 };
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.ReadDeviceSettings:
					Debug.WriteLine("SyncDeviceHandler936: Read Device Settings");
					CommandRequest = new byte[] { 0x1B, 0x17 };
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.ReadUserSettings:
					Debug.WriteLine("SyncDeviceHandler936: Read User Settings");
					CommandRequest = new byte[] { 0x1B, 0x19 };
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.ReadStepsHeader:
					Debug.WriteLine("SyncDeviceHandler936: Read Steps Header");
					CommandRequest = new byte[] { 0x1B, 0x22 };
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.ReadSeizureTable:
					Debug.WriteLine("SyncDeviceHandler936: Read Seizure Table");
					break;
				case Constants.SyncHandlerSequence.ReadHourlySteps:
					Debug.WriteLine("SyncDeviceHandler936: Read Steps Header");
					//CommandRequest = new byte[] { 0x1B, 0x24, 0x };
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.ReadCurrentHour:
					Debug.WriteLine("SyncDeviceHandler936: Read Current Hour");
					CommandRequest = new byte[] { 0x1B, 0x27 };
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.ReadSignature:
					Debug.WriteLine("SyncDeviceHandler936: Read Signature Data");
					//CommandRequest = new byte[] { 0x1B, 0x27 };
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.ReadSeizure:
					Debug.WriteLine("SyncDeviceHandler936: Read seizure Data");
					break;
				case Constants.SyncHandlerSequence.WriteStepsHeader:
					Debug.WriteLine("SyncDeviceHandler936: Writing steps header");
					break;
				case Constants.SyncHandlerSequence.WriteDeviceSettings:
					Debug.WriteLine("SyncDeviceHandler936: Writing device settings");
					break;
				case Constants.SyncHandlerSequence.WriteUserSettings:
					Debug.WriteLine("SyncDeviceHandler936: Writing user settings");
					break;
				case Constants.SyncHandlerSequence.WriteExerciseSettings:
					Debug.WriteLine("SyncDeviceHandler936: Writing exercise settings");
					break;
				case Constants.SyncHandlerSequence.WriteCompanySettings:
					Debug.WriteLine("SyncDeviceHandler936: Writing company settings");
					break;
				case Constants.SyncHandlerSequence.WriteSignatureSettings:
					Debug.WriteLine("SyncDeviceHandler936: Writing signature settings");
					break;
				case Constants.SyncHandlerSequence.WriteSeizureSettings:
					Debug.WriteLine("SyncDeviceHandler936: Writing seizure settings");
					break;
				case Constants.SyncHandlerSequence.WriteScreenFlow:
					Debug.WriteLine("SyncDeviceHandler936: Writing screenflow settings");
					break;
				case Constants.SyncHandlerSequence.WriteDeviceSensitivity:
					Debug.WriteLine("SyncDeviceHandler936: Writing device sensitivity settings");
					break;
				case Constants.SyncHandlerSequence.WriteDeviceStatus:
					Debug.WriteLine("SyncDeviceHandler936: Writing device status settings");
					break;
				case Constants.SyncHandlerSequence.WriteScreenDisplay:
					Debug.WriteLine("SyncDeviceHandler936: Writing screen display");
					break;
				case Constants.SyncHandlerSequence.ClearEEProm:
					Debug.WriteLine("SyncDeviceHandler936: Clear eeprom");
					break;
				case Constants.SyncHandlerSequence.WsGetDeviceInfo:
					Debug.WriteLine("SyncDeviceHandler936: 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("SyncDeviceHandler936: 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 });
			}
		}
예제 #4
0
        public 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;
            }

            switch (command)
            {
                case Constants.SyncHandlerSequence.EnableFF07:
                    Debug.WriteLine("SyncDeviceHandler961: Enabling FF07 characteristic");
                    ff07Char = GetServicesCharacterisitic(Constants.CharacteristicsUUID._FF07);
                    ff07Char.StartUpdates();
                    Task.Delay(500);
                    ProcessCommands();
                    break;
                case Constants.SyncHandlerSequence.EnableFF08:
                    Debug.WriteLine("SyncDeviceHandler961: Enabling FF08 characteristic");
                    ff08Char = GetServicesCharacterisitic(Constants.CharacteristicsUUID._FF08);
                    ff08Char.StartUpdates();
                    Task.Delay(500);
                    ProcessCommands();
                    break;
                case Constants.SyncHandlerSequence.ReadModel:
                    Debug.WriteLine("SyncDeviceHandler961: Reading model from characteristic.");
                    readChar = GetServicesCharacterisitic(Constants.CharacteristicsUUID._2A24);
                    readChar.ReadAsync();
                    break;
                case Constants.SyncHandlerSequence.ReadSerial:
                    Debug.WriteLine("SyncDeviceHandler961: Reading serial from characterisitic.");
                    readChar = GetServicesCharacterisitic(Constants.CharacteristicsUUID._2A25);
                    readChar.ReadAsync();
                    break;
                case Constants.SyncHandlerSequence.ReadFwVersion:
                    Debug.WriteLine("SyncDeviceHandler961: Reading fw version from characteristic.");
                    readChar = GetServicesCharacterisitic(Constants.CharacteristicsUUID._2A26);
                    readChar.ReadAsync();
                    break;
                case Constants.SyncHandlerSequence.ReadManufacturer:
                    Debug.WriteLine("SyncDeviceHandler961: Reading manufacturer from characteristic.");
                    readChar = GetServicesCharacterisitic(Constants.CharacteristicsUUID._2A29);
                    readChar.ReadAsync();
                    break;
                case Constants.SyncHandlerSequence.ReadBatteryLevel:
                    Debug.WriteLine("SyncDeviceHandler961: Reading battery level from characteristic.");
                    readChar = GetServicesCharacterisitic(Constants.CharacteristicsUUID._2A19);
                    readChar.ReadAsync();
                    break;
                default:
                    Debug.WriteLine("SyncDeviceHandler961: Unable to identify command.");
                    break;
            }
        }
예제 #5
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
                });
            }
        }
예제 #6
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;
            }
        }
예제 #7
0
        public 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;
            }

            switch (command)
            {
            case Constants.SyncHandlerSequence.EnableFF07:
                Debug.WriteLine("SyncDeviceHandler961: Enabling FF07 characteristic");
                ff07Char = GetServicesCharacterisitic(Constants.CharacteristicsUUID._FF07);
                ff07Char.StartUpdates();
                Task.Delay(500);
                ProcessCommands();
                break;

            case Constants.SyncHandlerSequence.EnableFF08:
                Debug.WriteLine("SyncDeviceHandler961: Enabling FF08 characteristic");
                ff08Char = GetServicesCharacterisitic(Constants.CharacteristicsUUID._FF08);
                ff08Char.StartUpdates();
                Task.Delay(500);
                ProcessCommands();
                break;

            case Constants.SyncHandlerSequence.ReadModel:
                Debug.WriteLine("SyncDeviceHandler961: Reading model from characteristic.");
                readChar = GetServicesCharacterisitic(Constants.CharacteristicsUUID._2A24);
                readChar.ReadAsync();
                break;

            case Constants.SyncHandlerSequence.ReadSerial:
                Debug.WriteLine("SyncDeviceHandler961: Reading serial from characterisitic.");
                readChar = GetServicesCharacterisitic(Constants.CharacteristicsUUID._2A25);
                readChar.ReadAsync();
                break;

            case Constants.SyncHandlerSequence.ReadFwVersion:
                Debug.WriteLine("SyncDeviceHandler961: Reading fw version from characteristic.");
                readChar = GetServicesCharacterisitic(Constants.CharacteristicsUUID._2A26);
                readChar.ReadAsync();
                break;

            case Constants.SyncHandlerSequence.ReadManufacturer:
                Debug.WriteLine("SyncDeviceHandler961: Reading manufacturer from characteristic.");
                readChar = GetServicesCharacterisitic(Constants.CharacteristicsUUID._2A29);
                readChar.ReadAsync();
                break;

            case Constants.SyncHandlerSequence.ReadBatteryLevel:
                Debug.WriteLine("SyncDeviceHandler961: Reading battery level from characteristic.");
                readChar = GetServicesCharacterisitic(Constants.CharacteristicsUUID._2A19);
                readChar.ReadAsync();
                break;

            default:
                Debug.WriteLine("SyncDeviceHandler961: Unable to identify command.");
                break;
            }
        }
예제 #8
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;
					int.TryParse(System.Text.Encoding.UTF8.GetString(chr.Value, 0, chr.Value.Length).Replace("PE", "").Replace("FT", ""), out num);
					Debug.WriteLine("Model: " + num);
					this.TrioDeviceInformationInstance.ModelNumber = num;
					string[] deviceNameComponents = this.Device.Name.Split(new Char[] {'-'});
					if ( deviceNameComponents.Count() == 3)
						this.TrioDeviceInformationInstance.BroadcastType = deviceNameComponents[1];
					else
						this.TrioDeviceInformationInstance.BroadcastType = "";

					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.");
					ReadChar = GetServicesCharacteristic(Constants.CharacteristicsUUID._2A29);
					chr = await ReadChar.ReadAsync();
					Debug.WriteLine("Manufacturer: " + System.Text.Encoding.UTF8.GetString(chr.Value, 0, chr.Value.Length));
					this.Adapter.CommandResponse += ReceiveResponse;
					//this.isGettingDeviceInformation = false;
					//if (this.ScanType == Constants.ScanType.SYNCING)
					//	this.isGettingDeviceInformation = true;
					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 = await DeviceStatusInstance.GetReadCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.ReadDeviceSettings:
					Debug.WriteLine("SyncDeviceHandler961: Read Device Settings");
					CommandRequest = await DeviceSettingsInstance.GetReadCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.ReadSeizureSettings:
					Debug.WriteLine("SyncDeviceHandler961: Read Seizure Settings");
					CommandRequest = await SeizureSettingsInstance.GetReadCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;	
				case Constants.SyncHandlerSequence.ReadUserSettings:
					Debug.WriteLine("SyncDeviceHandler961: Read User Settings");
					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 = await StepsTableDataInstance.GetReadStepTableDataCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.ReadSeizureBlocks:
					Debug.WriteLine("SyncDeviceHandler961: Read Seizure Table");
					CommandRequest = await SeizureBlocksDataInstance.GetReadSeizureBlocksDataCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.ReadHourlySteps:
					Debug.WriteLine("SyncDeviceHandler961: Read Hourly Steps");
					DateTime dt = this.currentDateForStepTable;
					CommandRequest = await StepsDataInstance.getReadHourRangeCommand(dt, this.currentStartTimeForStepTable, currentEndTimeForStepTable);
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					Debug.WriteLine("Read Hour Range Settings: " + Motion.Mobile.Utilities.Utils.ByteArrayToHexString(CommandRequest));
					break;
				case Constants.SyncHandlerSequence.ReadCurrentHour:
					Debug.WriteLine("SyncDeviceHandler961: Read Current Hour");
					CommandRequest = await StepsDataInstance.getReadCurrentHourCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.ReadSignature:
					Debug.WriteLine("SyncDeviceHandler961: Read Signature Data");
					StepsTableParameters sigData = this.SignatureToBeUploadedTableList.ElementAt(0);
					SignatureDataInstance.SDYear = sigData.dbYear;
					SignatureDataInstance.SDMonth = sigData.dbMonth;
					SignatureDataInstance.SDDay = sigData.dbDay;
					CommandRequest = await SignatureDataInstance.GetReadSignDataCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);

					// insert timer here
					break;
				case Constants.SyncHandlerSequence.ReadSeizure:
					Debug.WriteLine("SyncDeviceHandler961: Read seizure Data");
					SeizureBlockInfo seizureBlock = this.SeizureToBeUploadedList.ElementAt(0);
					SeizureDataInstance.SeizureRecToRead = seizureBlock.sbseizureRecordNo;
					SeizureDataInstance.BlockNumber = seizureBlock.sbSeizureBlock;
					CommandRequest = await SeizureDataInstance.GetReadCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);

					// insert timer here
					break;
				case Constants.SyncHandlerSequence.WriteStepsHeader:
					Debug.WriteLine("SyncDeviceHandler961: Writing steps header");
					CommandRequest = await StepsTableDataInstance.GetWriteStepTableDataCommand(StepTableParamInstance);
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.WriteDeviceSettings:
					Debug.WriteLine("SyncDeviceHandler961: Writing device settings");
					CommandRequest = await DeviceSettingsInstance.GetWriteCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.WriteUserSettings:
					Debug.WriteLine("SyncDeviceHandler961: Writing user settings");
					CommandRequest = await UserSettingsInstance.GetWriteCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.WriteExerciseSettings:
					Debug.WriteLine("SyncDeviceHandler961: Writing exercise settings");
					CommandRequest = await ExerciseSettingsInstance.GetWriteCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.WriteCompanySettings:
					Debug.WriteLine("SyncDeviceHandler961: Writing company settings");
					CommandRequest = await CompanySettingsInstance.GetWriteCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.WriteSignatureSettings:
					Debug.WriteLine("SyncDeviceHandler961: Writing signature settings");
					CommandRequest = await SignatureSettingsInstance.GetWriteCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.WriteSeizureSettings:
					Debug.WriteLine("SyncDeviceHandler961: Writing seizure settings");
					CommandRequest = await SeizureSettingsInstance.GetWriteCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
		          	break;
				case Constants.SyncHandlerSequence.WriteScreenFlow:
					Debug.WriteLine("SyncDeviceHandler961: Writing screenflow settings");
					CommandRequest = await FirmwareDisplaySequenceInstance.GetWriteCommand(this.ScreenFlowList);
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.WriteDeviceSensitivity:
					Debug.WriteLine("SyncDeviceHandler961: Writing device sensitivity settings");
					SensitivitySettingsInstance.SensitivityOld = DeviceDataInstance.TrackerSensitivity;
					CommandRequest = await SensitivitySettingsInstance.GetWriteCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.WriteDeviceStatus:
					Debug.WriteLine("SyncDeviceHandler961: Writing device status settings");
					CommandRequest = await DeviceStatusInstance.GetWriteCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.WriteDeviceMode:
					Debug.WriteLine("SyncDeviceHandler961: Writing device mode settings");
					DeviceModeInstance.EnableBroadcastAlways = DeviceDataInstance.AdvertiseMode;
					CommandRequest = await DeviceModeInstance.GetWriteCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;	
				case Constants.SyncHandlerSequence.WriteScreenDisplay:
					Debug.WriteLine("SyncDeviceHandler961: Writing screen display");
					this.ActivationCode = Utils.GetRandomDigits(4); //4 random digits to be generated
					// For testing purposes only
					this.ActivationCode[0] = 0x31;
					this.ActivationCode[1] = 0x32;
					this.ActivationCode[2] = 0x33;
					this.ActivationCode[3] = 0x34;
					// For testing purposes only
					Debug.WriteLine("Random digits: " + Motion.Mobile.Utilities.Utils.ByteArrayToHexString(this.ActivationCode));
					CommandRequest = await DisplayOnScreenInstance.GetWriteCommand(this.ActivationCode);
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.ClearEEProm:
					Debug.WriteLine("SyncDeviceHandler961: Clear eeprom");
					ClearEEPROMInstance.ExerciseData = this.clearMessagesOnly?false:true;
					ClearEEPROMInstance.SettingsData = false;
					ClearEEPROMInstance.SurveyQuestions = true;
					ClearEEPROMInstance.Tallies = true;
					ClearEEPROMInstance.MedicineAlarm = true;
					ClearEEPROMInstance.MotivationalQuotes = true;
					CommandRequest = await ClearEEPROMInstance.GetWriteCommand();
					this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;

				case Constants.SyncHandlerSequence.WsActivateDeviceWithMember:
					Debug.WriteLine("SyncDeviceHandler961: WS Activate Device With Member");
					WSActivateDeviceWithMemberInstance.request.TrackerModel = TrioDeviceInformationInstance.ModelNumber;
					WSActivateDeviceWithMemberInstance.request.TrackerSerialNumber = TrioDeviceInformationInstance.SerialNumber;
					WSActivateDeviceWithMemberInstance.request.TrackerBtAdd = "";
					WSActivateDeviceWithMemberInstance.request.ApplicationID = UserInformationInstance.ApplicationID;
					WSActivateDeviceWithMemberInstance.request.MemberDermID = UserInformationInstance.MemberID;
					WSActivateDeviceWithMemberInstance.request.TrackerFirmwareVersion = TrioDeviceInformationInstance.FirmwareVersion;
					this.status = await WSActivateDeviceWithMemberInstance.PostRequest();

					if (this.status == WebServiceRequestStatus.SUCCESS)
					{
						Debug.WriteLine("Success");
						if (WSActivateDeviceWithMemberInstance.response != null)
						{
							this.SetSettingsFromActivateDeviceWithMemberResponseWS(WSActivateDeviceWithMemberInstance.response);
							ProcessCommands();
						}


					}
					else
					{
						Debug.WriteLine("ActivateDeviceWithMemeber Response is " + WSActivateDeviceWithMemberInstance.response.ResponseMessage);
						this.Adapter.DisconnectDevice(this.Device);
					}
					//this.Adapter.SendCommand(Ff07Char, CommandRequest);
					break;
				case Constants.SyncHandlerSequence.WsGetDeviceInfo:
					Debug.WriteLine("SyncDeviceHandler961: WS Request GetDeviceInfo");
					WSGetDeviceInformationInstance.request.TrackerModel = TrioDeviceInformationInstance.ModelNumber;
					WSGetDeviceInformationInstance.request.TrackerSerialNumber = TrioDeviceInformationInstance.SerialNumber;
					WSGetDeviceInformationInstance.request.DeviceDateTime = Motion.Mobile.Utilities.Utils.GetDeviceDateTimeWithFormat(DateTime.Now);
					WSGetDeviceInformationInstance.request.ApplicationID = UserInformationInstance.ApplicationID;
					WSGetDeviceInformationInstance.request.DevicePairingStatus = 1;
					WSGetDeviceInformationInstance.request.TrackerFirmwareVersion = TrioDeviceInformationInstance.FirmwareVersion;
					this.status = await WSGetDeviceInformationInstance.PostRequest();

					this.ServerReadTimeDuration = 0;
					if (this.status == WebServiceRequestStatus.SUCCESS)
					{
						Debug.WriteLine("Success");
						if (WSGetDeviceInformationInstance.response != null)
						{
							this.isResettingTrio = false;
							timerForServer = new Timer(timerCallBack, new object(), 0, 1000);
							timerForServer.Increment += TimerForServer_Increment;
							this.SetSettingsFromGetDeviceInfoResponseWS(WSGetDeviceInformationInstance.response);
							ProcessCommands();
						}
						else
						{
							Debug.WriteLine("WS Request GetDeviceInfo Response is " + WSGetDeviceInformationInstance.response.ResponseMessage);
							this.Adapter.DisconnectDevice(this.Device);
						}

					}
					//else if  Tobe Added?
					else if (string.Equals(WSGetDeviceInformationInstance.response.ResponseStatus, "reset"))
					{
						this.isResettingTrio = true;
						DeviceStatusInstance.PairingStatus = 1;
						this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WriteDeviceStatus);
						this.ProcessCommands();
						Debug.WriteLine("Device Not Paired...");
					}
					else
					{ 
						Debug.WriteLine("Get Device Info Failed :(");
					}
						


					break;

				case Constants.SyncHandlerSequence.WsUploadTallies:
					Debug.WriteLine("SyncDeviceHandler961: WS Upload Tallies");

					WSUploadTalliesDataInstance.request.DeviceModel = TrioDeviceInformationInstance.ModelNumber;
					WSUploadTalliesDataInstance.request.DeviceSerial = TrioDeviceInformationInstance.SerialNumber;
					WSUploadTalliesDataInstance.request.MemberDeviceID = UserInformationInstance.MemberDeviceId;
					WSUploadTalliesDataInstance.request.ApplicationID = UserInformationInstance.ApplicationID;
					WSUploadTalliesDataInstance.request.PlatformID = UserInformationInstance.PlatformID;
					WSUploadTalliesDataInstance.request.DeviceDateTime = Motion.Mobile.Utilities.Utils.GetServerDateTimeFromString(MemberServerProfileInstance.ServerDateTime);
					WSUploadTalliesDataInstance.request.talliesData = TalliesDataInstance;

					this.status = await WSUploadTalliesDataInstance.PostRequest();

					if (this.status == WebServiceRequestStatus.SUCCESS)
					{
						Debug.WriteLine("Success");

						if (ApplicationInfoInstance.ApplicationID > 0 && ApplicationInfoInstance.PlatformID > 0)
						{
							if ((AppUpdateSettingsInstance.UpdateFlag && AppUpdateSettingsInstance.UpdateType != 2) || !AppUpdateSettingsInstance.UpdateFlag)
							{
								if (!this.clearTracker)
								{
									this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.ReadSeizureSettings);
									this.ProcessCommands();
								}

							}

						}

						else
						{
							this.isValidateAppInfo = true;
							this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsSendAppInfo);
							this.ProcessCommands();
						}


					}
					else
					{
						Debug.WriteLine("Upload Tallies Response is " + WSUploadTalliesDataInstance.response.ResponseStatus);
						this.Adapter.DisconnectDevice(this.Device);
					}
					break;
				case Constants.SyncHandlerSequence.WsUploadSteps:
					Debug.WriteLine("SyncDeviceHandler961: WS Upload Steps");
					this.CreateUploadStepsDataRequest(WSUploadStepsDataInstance.request);
					this.status = await WSUploadStepsDataInstance.PostRequest();
					if (this.status == WebServiceRequestStatus.SUCCESS)
					{
						Debug.WriteLine("Success");
						if (this.isReadingCurrentHour)
						{
							//READ_DEVICE_SETTING
							this.checkTimeDifferenceAndUpdateDeviceTime();
						}
						else
						{
							//UpdateStepDataTable
							StepTableParamInstance = this.UpdateStepDataTable();
							this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WriteStepsHeader);
							this.ProcessCommands();

						}

					}
					else
					{
						Debug.WriteLine("Upload Steps Response is " + WSUploadStepsDataInstance.response.ResponseMessage);
						this.Adapter.DisconnectDevice(this.Device);
					}
					break;
				case Constants.SyncHandlerSequence.WsUploadSignature:
					Debug.WriteLine("SyncDeviceHandler961: WS Upload Signature");
					this.CreateUploadSignatureRequestData(WSUploadSignatureDataInstance.request);
					this.status = await WSUploadSignatureDataInstance.PostRequest();
					if (this.status == WebServiceRequestStatus.SUCCESS)
					{
						Debug.WriteLine("Success");
						if (this.SignatureToBeUploadedTableList.Count() > 0)
						{
							this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.ReadSignature);
							this.ProcessCommands();
						}
						else
						{
							if (this.MemberServerProfileInstance.UpdateFlag > 0)
							{
								this.UpdateSettingsFlag(Utils.USER_SETTINGS_BIT_LOC);
							}
							else
							{
								//if(READ SURVEY)
								//else
								// update settings 
								//CLEAR_MESSAGES_SETTINGS_BIT_LOC
								this.UpdateSettingsFlag(Utils.CLEAR_MESSAGES_SETTINGS_BIT_LOC);
							}
						}
							

					}
					else
					{
						Debug.WriteLine("Upload Signature Response is " + WSUploadSignatureDataInstance.response.ResponseMessage);
						this.Adapter.DisconnectDevice(this.Device);
					}
					break;
				case Constants.SyncHandlerSequence.WsUploadProfile:
					break;
				case Constants.SyncHandlerSequence.WsUnpairDevice:
					Debug.WriteLine("SyncDeviceHandler961: WS Unpair Device");
					WSUnpairMemberDeviceInstance.request.DeviceID = WSActivateDeviceWithMemberInstance.response.DeviceID;
					WSUnpairMemberDeviceInstance.request.MemberID = UserInformationInstance.MemberID;
					WSUnpairMemberDeviceInstance.request.MemberDeviceID = UserInformationInstance.MemberDeviceId;
					this.status = await WSUploadSeiureDataInstance.PostRequest();
					if (this.status == WebServiceRequestStatus.SUCCESS)
					{
						Debug.WriteLine("Deactivating Device Successful");
					}
					break;
				case Constants.SyncHandlerSequence.WsUploadSeizure:
					Debug.WriteLine("SyncDeviceHandler961: WS Upload Seizure");
					this.CreateUploadSeizureRequestData(WSUploadSeiureDataInstance.request);
					this.status = await WSUploadSeiureDataInstance.PostRequest();
					if (this.status == WebServiceRequestStatus.SUCCESS)
					{
						Debug.WriteLine("Success");
						if (this.SeizureToBeUploadedList.Count() > 0)
						{
							this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.ReadSeizure);
							this.ProcessCommands();
						}
						else
						{
							if (this.SignatureToBeUploadedTableList.Count() > 0)
							{
								this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.ReadSignature);
								this.ProcessCommands();
							}
							else
							{
								if (this.MemberServerProfileInstance.UpdateFlag > 0)
								{
									this.UpdateSettingsFlag(Utils.USER_SETTINGS_BIT_LOC);
								}
								else
								{
									//if(READ SURVEY)
									//else
									// update settings 
									//CLEAR_MESSAGES_SETTINGS_BIT_LOC
									this.UpdateSettingsFlag(Utils.CLEAR_MESSAGES_SETTINGS_BIT_LOC);
								}
							}
						}


					}
					else
					{
						Debug.WriteLine("Upload Seizure Response is " + WSUploadSeiureDataInstance.response.ResponseMessage);
						this.Adapter.DisconnectDevice(this.Device);
					}
					break;
				case Constants.SyncHandlerSequence.WsSendNotifySettingsUpdate:
					Debug.WriteLine("SyncDeviceHandler961: WS Notify Settings Update");

					DateTime currentDateTime = DateTime.Now;

					long dateTimeInUnix = (long)Motion.Mobile.Utilities.Utils.DateTimeToUnixTimestamp(currentDateTime);

					DateTime dateTime = new DateTime(DeviceSettingsInstance.Year + 2000, DeviceSettingsInstance.Month, DeviceSettingsInstance.Day, DeviceSettingsInstance.Hour, DeviceSettingsInstance.Minute, DeviceSettingsInstance.Second);
					dateTime.AddSeconds(this.DeviceReadTimeDuration);

					WSNotifySettingsUpdateInstance.request.MemberID = UserInformationInstance.MemberID;
					WSNotifySettingsUpdateInstance.request.MemberDeviceID = UserInformationInstance.MemberDeviceId;
					WSNotifySettingsUpdateInstance.request.LastSyncSettingDateTime = dateTimeInUnix;
					WSNotifySettingsUpdateInstance.request.TrackerModel = TrioDeviceInformationInstance.ModelNumber;
					WSNotifySettingsUpdateInstance.request.UpdateFlag = MemberServerProfileInstance.UpdateFlag;
					WSNotifySettingsUpdateInstance.request.SettingType = MemberServerProfileInstance.UpdateFlagChanges;
					WSNotifySettingsUpdateInstance.request.DevicePairingStatus = DeviceStatusInstance.PairingStatus;
					WSNotifySettingsUpdateInstance.request.DeviceDateTime = Motion.Mobile.Utilities.Utils.GetDeviceDateTimeWithFormat(dateTime);
					WSNotifySettingsUpdateInstance.request.BatteryLevel = TrioDeviceInformationInstance.BatteryLevel;


					this.status = await WSNotifySettingsUpdateInstance.PostRequest();
					if (this.status == WebServiceRequestStatus.SUCCESS)
					{
						Debug.WriteLine("WS Notify Settings Update Successful");
					}
					else
					{
						Debug.WriteLine("WS Notify Settings Update Response is " + WSNotifySettingsUpdateInstance.response.ResponseMessage);
						this.Adapter.DisconnectDevice(this.Device);
					}
					break;
				case Constants.SyncHandlerSequence.WsUploadCommandResponse:
					Debug.WriteLine("SyncDeviceHandler961: WS Upload Command Response");
					WSUploadCommandResponseInstance.request.commandRespData.UploadCommand = 0x58;
					WSUploadCommandResponseInstance.request.DeviceModel = TrioDeviceInformationInstance.ModelNumber;
					WSUploadCommandResponseInstance.request.DeviceSerial = TrioDeviceInformationInstance.SerialNumber;
					WSUploadCommandResponseInstance.request.MemberDeviceID = UserInformationInstance.MemberDeviceId;
					WSUploadCommandResponseInstance.request.ApplicationID = UserInformationInstance.ApplicationID;
					WSUploadCommandResponseInstance.request.PlatformID = UserInformationInstance.PlatformID;
					WSUploadCommandResponseInstance.request.SynchronizationID = this.MemberServerProfileInstance.SynchronizationID;
					this.status = await WSUploadCommandResponseInstance.PostRequest();
					if (this.status == WebServiceRequestStatus.SUCCESS)
					{
						Debug.WriteLine("WS Upload Command Successful!");
					}
					else
					{
						Debug.WriteLine("WS Upload Command Response is " + WSUploadCommandResponseInstance.response.ResponseMessage);
						this.Adapter.DisconnectDevice(this.Device);
					}
					break;	
				case Constants.SyncHandlerSequence.WsSendAppInfo:
					Debug.WriteLine("SyncDeviceHandler961: WS Validate App Info");
					WSSendAppInfoInstance.request.ApplicationName = ApplicationInfoInstance.ApplicationName;
					WSSendAppInfoInstance.request.ApplicationVersion = ApplicationInfoInstance.ApplicationVersion;
					WSSendAppInfoInstance.request.OperatingSystem = ApplicationInfoInstance.OperatingSystem;
					WSSendAppInfoInstance.request.OperatingSystemVersion = ApplicationInfoInstance.OperatingSystemVersion;
					WSSendAppInfoInstance.request.PlatformType = ApplicationInfoInstance.PlatformType;
					WSSendAppInfoInstance.request.Brand = ApplicationInfoInstance.Brand;
					WSSendAppInfoInstance.request.Model = ApplicationInfoInstance.Model;
					WSSendAppInfoInstance.request.Manufacturer = ApplicationInfoInstance.Manufacturer;
					WSSendAppInfoInstance.request.CommunicationType = ApplicationInfoInstance.CommunicationType;
					this.status = await WSSendAppInfoInstance.PostRequest();
					if (this.status == WebServiceRequestStatus.SUCCESS)
					{
						Debug.WriteLine("WS Validate App Info Successful");

						this.UserInformationInstance.ApplicationID = WSSendAppInfoInstance.response.ApplicationID;
						this.UserInformationInstance.PlatformID = WSSendAppInfoInstance.response.PlatformID;
						if (this.isValidateAppInfo)
						{
							this.ApplicationInfoInstance.ApplicationID = WSSendAppInfoInstance.response.ApplicationID;
							this.ApplicationInfoInstance.PlatformID = WSSendAppInfoInstance.response.PlatformID;
							if ((AppUpdateSettingsInstance.UpdateFlag && AppUpdateSettingsInstance.UpdateType != 2) || !AppUpdateSettingsInstance.UpdateFlag)
							{
								if (!this.clearTracker)
									this.ProcessCommands();
								else
								{
									this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WriteDeviceSettings);
									this.ProcessCommands();
								}
							}

						}
						else
						{ 
							this.AppUpdateSettingsInstance.UpdateType = WSSendAppInfoInstance.response.appUpdateInfo.UpdateType;
						}

					}
					else
					{
						Debug.WriteLine("WS Validate App Info Response is " + WSUploadCommandResponseInstance.response.ResponseMessage);
						this.Adapter.DisconnectDevice(this.Device);
					}
					break;	
				default:
					Debug.WriteLine("SyncDeviceHandler961: Unable to identify command.");
					break;
			}

		}
예제 #9
0
		public void CleanUp()
		{
			this.ProcessQeueue.Clear();
			this.Command = Constants.SyncHandlerSequence.Default;
			this.CommandRequest = new byte[]{ };
			this.PacketsReceived.Clear();
			this.Device = null;
			this.StartIncrementProgress = false;


			if (this.timerForDevice != null)
			{
				this.timerForDevice.Cancel();
				this.timerForDevice = null;
			}

			if (this.timerForServer != null)
			{
				this.timerForServer.Cancel();
				this.timerForServer = null;
			}
		}