Example #1
0
        protected virtual void OnMessageReceivedInternal(MessageReceivedEventArgs e)
        {
            Match  match         = JablotronDeviceAddressRegex.Match(e.Message);
            string addressString = match.Groups["address"].Value;

            if (_jablotronDevices.ContainsKey(addressString))
            {
                _jablotronDevices[addressString].OnMessageReceiverAsync(e.Message);
            }

            int deviceAddress             = Convert.ToInt32(addressString);
            JablotronDevicType deviceType = JablotronDevice.GetDeviceType((byte)(deviceAddress / 65536));

            bool lowBatteryNotification = e.Message.Contains(LowBatteryMessagePatern);
            bool tamperNotification     = e.Message.Contains(TamperMessagePatern);

            if (lowBatteryNotification)
            {
                LowDeviceBatteryNotificationReceived?.Invoke(this,
                                                             new LowDeviceBatteryNotificationEventArgs(deviceAddress, deviceType));
            }
            if (tamperNotification)
            {
                DeviceTamperNotificationReceived?.Invoke(this,
                                                         new DeviceTamperNotificationEventArgs(e.Message.Contains(ActActivePatern), deviceAddress, deviceType));
            }
        }
Example #2
0
        public static BitArray GetSignature(this JablotronDevice device)
        {
            byte     index    = device.GetIndex();
            BitArray bitArray = new BitArray(BitConverter.GetBytes(index).ToArray());

            bitArray.Length = 5;
            return(bitArray);
        }
Example #3
0
        public async Task InitializeAsync(Action <Exception> initFailedAction, Action <TurrisDongle> initFinishedAction, bool initializeDeviceList = true)
        {
            try
            {
                if (IsInitialized)
                {
                    return;
                }
                await InitializeTurrisDongle();

                if (initializeDeviceList)
                {
                    for (int i = 0; i < 32; i++)
                    {
                        string command = string.Format("GET SLOT:{0:00}", i);
                        _dataWriter.WriteString(ComposeCommand(command));
                        await _dataWriter.StoreAsync();

                        string message = await GetDataFromDataReader(_dataReader, _readCancellationTokenSource.Token);

                        if (message.Contains(NoDeviceAddressPatern))
                        {
                            _jablotronDeviceMap[i] = null;
                            continue;
                        }
                        Match           match           = JablotronDeviceSlotAddressRegex.Match(message);
                        string          addressString   = match.Groups["address"].Value;
                        int             address         = Convert.ToInt32(addressString);
                        JablotronDevice jablotronDevice = JablotronDevice.Create(this, (byte)(address / 65536),
                                                                                 (ushort)(address % 65536));
                        _jablotronDevices.Add(addressString, jablotronDevice);
                        _jablotronDeviceMap[i] = addressString;
                    }
                }
                IsInitialized = true;
                foreach (KeyValuePair <string, JablotronDevice> device in _jablotronDevices)
                {
                    await device.Value.InitializeAsync();
                }
                initFinishedAction?.Invoke(this);
                _messageProcessingTask = MessageProcessing();
            }
            catch (Exception ex)
            {
                initFailedAction?.Invoke(ex);
            }
        }