public async void ReceiveResponse(object sender, CommandResponseEventArgs e) { Debug.WriteLine("Receiving Response: " + Motion.Mobile.Utilities.Utils.ByteArrayToHexString(e.Data)); if (this.StartIncrementProgress) { this.IncrementProgressBar(this, new EventArgs() { }); } switch (this.Command) { case Constants.SyncHandlerSequence.ReadTallies: Debug.WriteLine("Receiving device tallies"); this.PacketsReceived.Add(e.Data); if (Utils.LastPacketReceived(2, e.Data)) { Debug.WriteLine("Last packet received..."); //Process Data Here... this.ProcessCommands(); } break; case Constants.SyncHandlerSequence.ReadDeviceInformation: Debug.WriteLine("Receving device information"); this.ProcessCommands(); break; case Constants.SyncHandlerSequence.ReadDeviceStatus: Debug.WriteLine("Receving device status"); this.ProcessCommands(); break; case Constants.SyncHandlerSequence.ReadDeviceSettings: Debug.WriteLine("Receving device settings"); this.ProcessCommands(); break; case Constants.SyncHandlerSequence.ReadUserSettings: Debug.WriteLine("Receiving user settings: "); BLEParsingStatus status = await UserSettingsInstance.ParseData(e.Data); if (status == BLEParsingStatus.SUCCESS) { Debug.WriteLine("User RMR: " + UserSettingsInstance.RestMetabolicRate); this.ProcessCommands(); } else { this.Adapter.DisconnectDevice(this.Device); } break; case Constants.SyncHandlerSequence.ReadStepsHeader: Debug.WriteLine("Receiving steps header data"); this.PacketsReceived.Add(e.Data); if (Utils.LastPacketReceived(2, e.Data)) { Debug.WriteLine("Last packet received..."); //Process Data Here... this.ProcessCommands(); } break; case Constants.SyncHandlerSequence.ReadSeizureTable: Debug.WriteLine("Receiving seizure table data"); this.PacketsReceived.Add(e.Data); if (Utils.LastPacketReceived(2, e.Data)) { Debug.WriteLine("Last packet received..."); //Process Data Here... this.ProcessCommands(); } break; case Constants.SyncHandlerSequence.ReadHourlySteps: Debug.WriteLine("Receiving hourly steps data"); this.PacketsReceived.Add(e.Data); if (Utils.TerminatorFound(0xFF, 4, e.Data)) { Debug.WriteLine("Terminator Found..."); this.ProcessCommands(); } break; case Constants.SyncHandlerSequence.ReadCurrentHour: Debug.WriteLine("Receiving current hour steps data"); this.PacketsReceived.Add(e.Data); if (Utils.TerminatorFound(0xFF, 4, e.Data)) { Debug.WriteLine("Terminator Found..."); this.ProcessCommands(); } break; case Constants.SyncHandlerSequence.ReadSignature: Debug.WriteLine("Receiving signature data"); this.PacketsReceived.Add(e.Data); if (Utils.TerminatorFound(0xFF, 4, e.Data)) { Debug.WriteLine("Terminator Found..."); this.ProcessCommands(); } break; case Constants.SyncHandlerSequence.ReadSeizure: break; case Constants.SyncHandlerSequence.WriteStepsHeader: break; case Constants.SyncHandlerSequence.WriteDeviceSettings: break; case Constants.SyncHandlerSequence.WriteUserSettings: break; case Constants.SyncHandlerSequence.WriteExerciseSettings: break; case Constants.SyncHandlerSequence.WriteCompanySettings: break; case Constants.SyncHandlerSequence.WriteSignatureSettings: break; case Constants.SyncHandlerSequence.WriteSeizureSettings: break; case Constants.SyncHandlerSequence.WriteScreenFlow: break; case Constants.SyncHandlerSequence.WriteDeviceSensitivity: break; case Constants.SyncHandlerSequence.WriteDeviceStatus: break; case Constants.SyncHandlerSequence.ClearEEProm: break; default: Debug.WriteLine("Invalid response received."); break; } }
public async void ReceiveResponse(object sender, CommandResponseEventArgs e) { Debug.WriteLine("Receiving Response: " + Motion.Mobile.Utilities.Utils.ByteArrayToHexString(e.Data)); if (this.StartIncrementProgress) { this.IncrementProgressBar(this, new EventArgs() { }); } switch (this.Command) { case Constants.SyncHandlerSequence.WriteScreenDisplay: this.ParsingStatus = await DisplayOnScreenInstance.ParseData(e.Data); // For testing purposes only if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.ValidationCodeDisplayed(this, new EventArgs()); } else { this.Adapter.DisconnectDevice(this.Device); } break; case Constants.SyncHandlerSequence.ReadTallies: Debug.WriteLine("Receiving device tallies"); this.PacketsReceived.Add(e.Data); if (Utils.LastPacketReceived(2, e.Data)) { Debug.WriteLine("Last packet received..."); //Process Data Here... this.ParsingStatus = await TalliesDataInstance.ParseData(this.PacketsReceived.SelectMany(a => a).ToArray()); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.PacketsReceived.Clear(); this.ProcessCommands(); } else { this.Adapter.DisconnectDevice(this.Device); } } break; case Constants.SyncHandlerSequence.ReadDeviceInformation: Debug.WriteLine("Receving device information"); this.ProcessCommands(); break; case Constants.SyncHandlerSequence.ReadDeviceStatus: Debug.WriteLine("Receving device status"); this.ParsingStatus = await DeviceStatusInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.ProcessCommands(); } else { this.Adapter.DisconnectDevice(this.Device); } break; case Constants.SyncHandlerSequence.ReadDeviceSettings: Debug.WriteLine("Receiving device settings"); this.ParsingStatus = await DeviceSettingsInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { if (this.ScanType == Constants.ScanType.ACTIVATION) { // To be added //this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsSendNotifyMessageSettingsUpdate); this.Adapter.DisconnectDevice(this.Device); } else { timerForDevice = new Timer(timerCallBack, new object(), 0, 1000); timerForDevice.Increment += TimerForDevice_Increment; this.ProcessCommands(); } } else { this.Adapter.DisconnectDevice(this.Device); } break; case Constants.SyncHandlerSequence.ReadSeizureSettings: Debug.WriteLine("Receiving seizure settings"); this.ParsingStatus = await SeizureSettingsInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.ProcessCommands(); } else { this.Adapter.DisconnectDevice(this.Device); } break; case Constants.SyncHandlerSequence.ReadUserSettings: Debug.WriteLine("Receiving user settings: "); this.ParsingStatus = await UserSettingsInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { Debug.WriteLine("User RMR: " + UserSettingsInstance.RestMetabolicRate); this.ReadStepsData(); } else { this.Adapter.DisconnectDevice(this.Device); } break; case Constants.SyncHandlerSequence.ReadStepsHeader: Debug.WriteLine("Receiving steps header data"); this.PacketsReceived.Add(e.Data); if (Utils.LastPacketReceived(2, e.Data)) { Debug.WriteLine("Last packet received..."); byte[] data = new byte[20 * this.PacketsReceived.Count]; int len = 0; int currentIndex = 0; for (int i = 0; i < this.PacketsReceived.Count; i++) { len = this.PacketsReceived.ElementAt(i).ToArray().Length; Array.Copy(this.PacketsReceived.ElementAt(i).ToArray(), Constants.INDEX_ZERO, data, currentIndex, len); Debug.WriteLine("Loop Response: " + Motion.Mobile.Utilities.Utils.ByteArrayToHexString(data)); currentIndex += len; } this.ParsingStatus = await StepsTableDataInstance.ParseData(data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { foreach (StepsTableParameters stepTable in StepsTableDataInstance.stepsDataTable) { Debug.WriteLine("Date: " + stepTable.tableDate); } this.PacketsReceived.Clear(); this.ProcessCommands(); } else { this.Adapter.DisconnectDevice(this.Device); } } break; case Constants.SyncHandlerSequence.ReadSeizureBlocks: Debug.WriteLine("Receiving seizure table data"); this.ParsingStatus = await SeizureBlocksDataInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.ProcessSeizureBlocksResponse(); } else { this.Adapter.DisconnectDevice(this.Device); }; break; case Constants.SyncHandlerSequence.ReadHourlySteps: Debug.WriteLine("Receiving hourly steps data"); this.PacketsReceived.Add(e.Data); if (Utils.TerminatorFound(0xFF, 4, e.Data)) { Debug.WriteLine("Last packet received..."); this.ParsingStatus = await StepsDataInstance.ParseData(this.PacketsReceived.SelectMany(a => a).ToArray()); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.PacketsReceived.Clear(); //this.isUploadingStepsData = true; //this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.ReadDeviceSettings); if (StepsDataInstance.dailyData != null && StepsDataInstance.dailyData.Count > 0 && StepsDataInstance.dailyData[0].stepsYear != 0) this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsUploadSteps); this.ProcessCommands(); } else { Debug.WriteLine("Error Parsing: " + this.ParsingStatus); this.Adapter.DisconnectDevice(this.Device); }; } break; case Constants.SyncHandlerSequence.ReadCurrentHour: Debug.WriteLine("Receiving current hour steps data"); this.PacketsReceived.Add(e.Data); if (Utils.TerminatorFound(0xFF, 4, e.Data)) { Debug.WriteLine("Last packet received..."); this.ParsingStatus = await StepsDataInstance.ParseData(this.PacketsReceived.SelectMany(a => a).ToArray()); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.PacketsReceived.Clear(); if (StepsDataInstance.dailyData != null && StepsDataInstance.dailyData.Count > 0 && StepsDataInstance.dailyData[0].stepsYear != 0) this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsUploadSteps); this.ProcessCommands(); } else { this.Adapter.DisconnectDevice(this.Device); }; } break; case Constants.SyncHandlerSequence.ReadSignature: Debug.WriteLine("Receiving signature data"); this.PacketsReceived.Add(e.Data); if (Utils.TerminatorFound(0xFF, 4, e.Data)) { Debug.WriteLine("Terminator Found..."); this.ParsingStatus = await SignatureDataInstance.ParseData(this.PacketsReceived.SelectMany(a => a).ToArray()); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.SignatureToBeUploadedTableList.RemoveAt(0); this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsUploadSignature); this.ProcessCommands(); } } break; case Constants.SyncHandlerSequence.ReadSeizure: this.PacketsReceived.Add(e.Data); if (Utils.TerminatorFound(0xFF, 4, e.Data)) { Debug.WriteLine("Terminator Found..."); Debug.WriteLine("Terminator Found..."); this.ParsingStatus = await SeizureDataInstance.ParseData(this.PacketsReceived.SelectMany(a => a).ToArray()); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.SeizureToBeUploadedList.RemoveAt(0); this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsUploadSeizure); this.ProcessCommands(); } } break; case Constants.SyncHandlerSequence.WriteStepsHeader: Debug.WriteLine("Receiving Write Steps Header response."); this.ParsingStatus = await StepsTableDataInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.ProcessWriteTableHeaderResponse(); } else { this.Adapter.DisconnectDevice(this.Device); }; break; case Constants.SyncHandlerSequence.WriteDeviceSettings: Debug.WriteLine("Receiving Write Device Settings response."); this.ParsingStatus = await DeviceSettingsInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.MemberServerProfileInstance.UpdateFlagChanges = this.MemberServerProfileInstance.UpdateFlagChanges | Utils.DEVICE_SETTINGS; } else { Debug.WriteLine("Write Device Settings Failed."); if (this.ScanType == Constants.ScanType.ACTIVATION) { //unpair this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsUnpairDevice); this.ProcessCommands(); } } if (this.ScanType == Constants.ScanType.ACTIVATION) { if (this.clearTracker) this.ProcessCommands(); else this.UpdateSettingsFlag(Utils.USER_SETTINGS_BIT_LOC); } else { if (this.clearTracker) { this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.ClearEEProm); this.ProcessCommands(); } if (this.isUnFlaggingTableHeaderDueToTimeChange && this.TimeChangeTableDataList.Count() > 1) { if (this.UpdateStepDataTable() == null) { this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WriteStepsHeader); this.ProcessCommands(); } } else { this.CheckSeizureOrSignatureForUpload(); } } break; case Constants.SyncHandlerSequence.WriteUserSettings: Debug.WriteLine("Receiving Write User Settings response."); this.ParsingStatus = await UserSettingsInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.MemberServerProfileInstance.UpdateFlagChanges = (this.MemberServerProfileInstance.UpdateFlagChanges | Utils.USER_SETTINGS); } else { //unpair if activating } this.UpdateSettingsFlag(Utils.EXERCISE_SETTINGS_BIT_LOC); break; case Constants.SyncHandlerSequence.WriteExerciseSettings: Debug.WriteLine("Receiving Write Exercise Settings response."); this.ParsingStatus = await ExerciseSettingsInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.MemberServerProfileInstance.UpdateFlagChanges = (this.MemberServerProfileInstance.UpdateFlagChanges | Utils.EXERCISE_SETTINGS); } else { if (this.ScanType == Constants.ScanType.ACTIVATION) { //unpair this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsUnpairDevice); this.ProcessCommands(); } } this.UpdateSettingsFlag(Utils.COMPANY_SETTINGS_BIT_LOC); break; case Constants.SyncHandlerSequence.WriteCompanySettings: Debug.WriteLine("Receiving Write Company Settings response."); this.ParsingStatus = await CompanySettingsInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.MemberServerProfileInstance.UpdateFlagChanges = (this.MemberServerProfileInstance.UpdateFlagChanges | Utils.COMPANY_SETTINGS); } else { if (this.ScanType == Constants.ScanType.ACTIVATION) { //unpair this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsUnpairDevice); this.ProcessCommands(); } } this.UpdateSettingsFlag(Utils.SIGNATURE_SETTINGS_BIT_LOC); break; case Constants.SyncHandlerSequence.WriteSignatureSettings: Debug.WriteLine("Receiving Write Signature Settings response."); this.ParsingStatus = await SignatureSettingsInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.MemberServerProfileInstance.UpdateFlagChanges = (this.MemberServerProfileInstance.UpdateFlagChanges | Utils.SIGNATURE_SETTINGS); } else { if (this.ScanType == Constants.ScanType.ACTIVATION) { //unpair this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsUnpairDevice); this.ProcessCommands(); } } this.UpdateSettingsFlag(Utils.SEIZURE_SETTINGS_BIT_LOC); break; case Constants.SyncHandlerSequence.WriteSeizureSettings: Debug.WriteLine("Receiving Write Seizure Settings response."); this.ParsingStatus = await SeizureSettingsInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.MemberServerProfileInstance.UpdateFlagChanges = (this.MemberServerProfileInstance.UpdateFlagChanges | Utils.SEIZURE_SETTINGS); } else { if (this.ScanType == Constants.ScanType.ACTIVATION) { //unpair this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsUnpairDevice); this.ProcessCommands(); } } this.UpdateSettingsFlag(Utils.SCREEN_SETTINGS_BIT_LOC); break; case Constants.SyncHandlerSequence.WriteScreenFlow: this.ParsingStatus = await FirmwareDisplaySequenceInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.MemberServerProfileInstance.UpdateFlagChanges = (this.MemberServerProfileInstance.UpdateFlagChanges | Utils.SCREEN_SETTINGS); } else { if (this.ScanType == Constants.ScanType.ACTIVATION) { //unpair this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsUnpairDevice); this.ProcessCommands(); } } this.UpdateSettingsFlag(Utils.SENSITIVITY_SETTINGS_BIT_LOC); break; case Constants.SyncHandlerSequence.WriteDeviceSensitivity: int flag = await SensitivitySettingsInstance.ParseData(e.Data); if (flag == 0) { this.MemberServerProfileInstance.UpdateFlagChanges = (this.MemberServerProfileInstance.UpdateFlagChanges | Utils.SENSITIVITY_SETTINGS); if (this.ScanType == Constants.ScanType.SYNCING) { this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsSendNotifySettingsUpdate); this.ProcessCommands(); } else { DeviceStatusInstance.PairingStatus = 1; this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WriteDeviceStatus); this.ProcessCommands(); } } else { if (this.ScanType == Constants.ScanType.ACTIVATION) { //unpair this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsUnpairDevice); this.ProcessCommands(); } else { WSUploadCommandResponseInstance.request.commandRespData.UploadResponse = flag; this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WsUploadCommandResponse); this.ProcessCommands(); } } break; case Constants.SyncHandlerSequence.WriteDeviceStatus: this.ParsingStatus = await DeviceStatusInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { DeviceStatusInstance.PairingStatus = 0; this.MemberServerProfileInstance.UpdateFlagChanges = (this.MemberServerProfileInstance.UpdateFlagChanges | Utils.PAIRING_SETTINGS); if (this.ScanType == Constants.ScanType.ACTIVATION) { this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.WriteDeviceMode); this.ProcessCommands(); } } else { Debug.WriteLine("Failed to Set Pairing.."); } if (this.ScanType == Constants.ScanType.SYNCING) { this.Adapter.DisconnectDevice(this.Device); } break; case Constants.SyncHandlerSequence.WriteDeviceMode: this.ParsingStatus = await DeviceStatusInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { this.ProcessQeueue.Enqueue(Constants.SyncHandlerSequence.ReadDeviceSettings); this.ProcessCommands(); } break; case Constants.SyncHandlerSequence.ClearEEProm: Debug.WriteLine("Receiving clear eeprom: "); this.ParsingStatus = await ClearEEPROMInstance.ParseData(e.Data); if (this.ParsingStatus == BLEParsingStatus.SUCCESS) { if (this.ScanType == Constants.ScanType.SYNCING) this.MemberServerProfileInstance.UpdateFlagChanges = (this.MemberServerProfileInstance.UpdateFlagChanges | Utils.CLEAR_EX); if (this.ScanType == Constants.ScanType.ACTIVATION || (!this.clearMessagesOnly) ) { this.UpdateSettingsFlag(Utils.USER_SETTINGS_BIT_LOC); } } else { this.Adapter.DisconnectDevice(this.Device); } break; default: Debug.WriteLine("Invalid response received: " + this.Command.ToString()); break; } }