internal static int BATT_INDX = 8; //Num Bytes for Battery Level is 1



            //////////////////////////////////////////////////////////////////////////

            /// <summary>
            /// Generate UUIDsSensorsTable from SensorsUUIDsTable
            /// Swap keys with values
            /// -----
            /// Generate the Characteristics lookup table
            /// Rather than "Linqing" to find info on a service characteristic create a lookup table of all
            ///   valid Characteristic UUIds wit their types.
            ///   Table has UUID string as key and (sensor,characteristic type) as values
            /// </summary>
            public SensorServicesCls()
            {
                Sensors = new Dictionary <SensorIndexes, SensorChars>();

                UUIDsSensorsTable = new Dictionary <string, SensorIndexes>();
                foreach (var x in SensorsUUIDsTable)
                {
                    if (!UUIDsSensorsTable.Keys.Contains(x.Value.ToUpper()))
                    {
                        UUIDsSensorsTable.Add(x.Value.ToUpper(), x.Key);
                    }
                    else
                    {
                    }
                }

                Characters = new Dictionary <string, Tuple <SensorIndexes, CharacteristicTypes> >();
                Dictionary <CharacteristicTypes, string> Masks;

                for (SensorIndexes sensor = SensorIndexes.IR_SENSOR; sensor < SensorIndexes.NOTFOUND; sensor++)
                {
                    switch (sensor)
                    {
                    case SensorIndexes.IO_SENSOR:
                        Masks = MasksIO;
                        break;

                    case SensorIndexes.REGISTERS:
                        Masks = MasksRegisters;
                        break;

                    case SensorIndexes.BAROMETRIC_PRESSURE:
                        Masks = MasksBaro;
                        break;

                    default:
                        Masks = MasksSensors;
                        break;
                    }

                    foreach (var mask in Masks)
                    {
                        //Add the 7th digit in the mask to the 7th digit in the UUID
                        string uuid      = SensorsUUIDsTable[sensor];
                        char[] uuidArray = uuid.ToCharArray();
                        char[] maskArray = mask.Value.ToCharArray();
                        char[] baseArray = Masks[0].ToCharArray();
                        uuidArray[7] = (char)((int)uuidArray[7] + ((int)maskArray[7] - (int)baseArray[7]));
                        uuid         = new string(uuidArray);

                        Tuple <SensorIndexes, CharacteristicTypes> tpl = new Tuple <SensorIndexes, CharacteristicTypes>(sensor, mask.Key);
                        Characters.Add(uuid.ToUpper(), tpl);
                        //System.Diagnostics.Debug.WriteLine("{0} {1} {2}",uuid, sensor, mask.Key);
                    }
                }
            }
            internal static SensorIndexes GetSensor(string uuid)
            {
                SensorIndexes sensor = SensorIndexes.NOTFOUND;

                if (UUIDsSensorsTable.Keys.Contains(uuid.ToUpper()))
                {
                    sensor = UUIDsSensorsTable[uuid.ToUpper()];
                }
                return(sensor);
            }
Example #3
0
        public static SensorIndexes GetSensorIndex(int Index)
        {
            SensorIndexes senIndx = SensorIndexes.NOTFOUND;

            for (int i = 0; i < UUIDBase.Count(); i++)
            {
                if (UUIDBase[i] != "")
                {
                    char ch   = UUIDBase[i][6];
                    int  indx = ch - '0';
                    if (indx == Index)
                    {
                        senIndx = (SensorIndexes)i;
                        break;
                    }
                }
            }
            return(senIndx);
        }
Example #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="gattService">Gatt Service found for this sensor</param>
        /// <param name="sensorIndex">SensorIndex</param>
        public CC2650SensorTag(GattDeviceService gattService, SensorIndexes sensorIndex)
        {
            Debug.WriteLine("Begin sensor constructor: " + sensorIndex.ToString());

            GattService     = gattService;
            HasSetCallBacks = false;
            SensorIndex     = sensorIndex;
            Guid guidNull         = Guid.Empty;
            Guid guidData         = guidNull;
            Guid guidNotification = guidNull;
            Guid guidConfiguraton = guidNull;
            Guid guidPeriod       = guidNull;
            Guid guidAddress      = guidNull;
            Guid guidDevId        = guidNull;


            switch (SensorIndex)
            {
            case SensorIndexes.KEYS:
                guidNotification = BUTTONS_NOTIFICATION_GUID;
                break;

            case SensorIndexes.IO_SENSOR:
                guidData         = IO_SENSOR_DATA_GUID;
                guidConfiguraton = IO_SENSOR_CONFIGURATION_GUID;
                break;

            case SensorIndexes.REGISTERS:
                guidData    = REGISTERS_DATA_GUID;
                guidAddress = REGISTERS_ADDRESS_GUID;
                guidDevId   = REGISTERS_DEVICE_ID_GUID;
                break;

            default:
                guidData         = new Guid(UUIDBase[(int)SensorIndex] + SENSOR_GUID_SUFFFIX);
                guidNotification = new Guid(UUIDBase[(int)SensorIndex] + SENSOR_NOTIFICATION_GUID_SUFFFIX);
                guidConfiguraton = new Guid(UUIDBase[(int)SensorIndex] + SENSOR_ENABLE_GUID_SUFFFIX);
                guidPeriod       = new Guid(UUIDBase[(int)SensorIndex] + SENSOR_PERIOD_GUID_SUFFFIX);
                break;
            }

            IReadOnlyList <GattCharacteristic> characteristicList_Data          = null;
            IReadOnlyList <GattCharacteristic> characteristicList_Notification  = null;
            IReadOnlyList <GattCharacteristic> characteristicList_Configuration = null;
            IReadOnlyList <GattCharacteristic> characteristicList_Period        = null;

            IReadOnlyList <GattCharacteristic> characteristicList_Address   = null;
            IReadOnlyList <GattCharacteristic> characteristicList_Device_Id = null;

            if (guidData != guidNull)
            {
                characteristicList_Data = gattService.GetCharacteristics(guidData);
            }
            if (guidNotification != guidNull)
            {
                characteristicList_Notification = gattService.GetCharacteristics(guidNotification);
            }
            if (guidConfiguraton != guidNull)
            {
                characteristicList_Configuration = gattService.GetCharacteristics(guidConfiguraton);
            }
            if (guidPeriod != guidNull)
            {
                characteristicList_Period = gattService.GetCharacteristics(guidPeriod);
            }

            if (guidAddress != guidNull)
            {
                characteristicList_Address = gattService.GetCharacteristics(guidAddress);
            }
            if (guidDevId != guidNull)
            {
                characteristicList_Device_Id = gattService.GetCharacteristics(guidDevId);
            }

            if (characteristicList_Data != null)
            {
                if (characteristicList_Data.Count > 0)
                {
                    Data = characteristicList_Data[0];
                }
            }
            if (characteristicList_Notification != null)
            {
                if (characteristicList_Notification.Count > 0)
                {
                    Notification = characteristicList_Notification[0];
                }
            }
            if (characteristicList_Configuration != null)
            {
                if (characteristicList_Configuration.Count > 0)
                {
                    Configuration = characteristicList_Configuration[0];
                }
            }
            if (characteristicList_Period != null)
            {
                if (characteristicList_Period.Count > 0)
                {
                    Data = characteristicList_Period[0];
                }
            }

            if (characteristicList_Address != null)
            {
                if (characteristicList_Address.Count > 0)
                {
                    Address = characteristicList_Address[0];
                }
            }
            if (characteristicList_Device_Id != null)
            {
                if (characteristicList_Device_Id.Count > 0)
                {
                    Device_Id = characteristicList_Device_Id[0];
                }
            }

            SensorsCharacteristicsList[(int)sensorIndex] = this;

            if (SensorIndex >= 0 && SensorIndex != SensorIndexes.IO_SENSOR && SensorIndex != SensorIndexes.REGISTERS)
            {
                ActiveCharacteristicNotifications[(int)SensorIndex] = Notification;
                Task.Run(() => this.EnableNotify()).Wait(); //Could leave out Wait but potentially could action this instance too soon
                Task.Run(() => this.TurnOnSensor()).Wait(); //This launches a new thread for this action but stalls the constructor thread.
            }

            Debug.WriteLine("End sensor constructor: " + SensorIndex.ToString());
        }