internal AquaCleanBaseClient(IBluetoothLeConnector bluetoothLeConnector)
        {
            this.bluetoothLeConnector = bluetoothLeConnector;
            frameService   = new FrameService();
            frameFactory   = new FrameFactory();
            messageService = new MessageService();

            // Build lookup
            var type  = typeof(IApiCall);
            var types = AppDomain.CurrentDomain.GetAssemblies()
                        .SelectMany(s => s.GetTypes())
                        .Where(p => type.IsAssignableFrom(p));

            contextLookup = types
                            .Select(t => new
            {
                Type = t,
                Api  = (ApiCallAttribute)t.GetCustomAttributes(typeof(ApiCallAttribute), false).FirstOrDefault()
            }
                                    )
                            .Where(t => t.Api != null)
                            .ToDictionary(t => t.Api, t => t.Type);

            // Process received data from Bluetooth
            bluetoothLeConnector.DataReceived += (sender, data) =>
            {
                frameService.ProcessData(data);
            };

            // Connection status has changed
            bluetoothLeConnector.ConnectionStatusChanged += (sender, args) => {
                this.ConnectionStatusChanged?.Invoke(this, new ConnectionStatusChangedEventArgs(args));
            };

            // Send Frame over Bluetooth
            frameService.SendData += async(sender, data) =>
            {
                await bluetoothLeConnector.SendMessageAsync(data);
            };

            // Process complete transaction
            frameService.TransactionComplete += (sender, data) =>
            {
                this.messageContext = messageService.ParseMessage(data);
                var context = new ApiCallAttribute()
                {
                    Context   = messageContext.Context,
                    Procedure = messageContext.Procedure
                };
                if (contextLookup.ContainsKey(context))
                {
                    var cc = contextLookup[context];
                    Debug.WriteLine("Result for " + cc.Name);
                }

                eventWaitHandle.Set();
            };
        }
Ejemplo n.º 2
0
        internal AquaCleanClient(IBluetoothLeConnector bluetoothConnector)
        {
            this.baseClient = new AquaCleanBaseClient(bluetoothConnector);
            this.baseClient.ConnectionStatusChanged += (sender, args) =>
            {
                this.ConnectionStatusChanged?.Invoke(this, args);
            };
            this.stateChangedTimer = new Timer(STATE_CHANGED_TIMER_INTERVAL);

            this.stateChangedTimer.Elapsed += StateChangedTimer_Elapsed;
        }
Ejemplo n.º 3
0
 public AquaCleanClientFactory(IBluetoothLeConnector bluetoothLeConnector)
 {
     this.BluetoothLeConnector = bluetoothLeConnector;
 }