예제 #1
0
        public void FromXML(string xml)
        {
            XmlDocument dom = new XmlDocument();

            dom.LoadXml(xml);
            XmlNode xNode = dom.DocumentElement;

            if ((xNode.Name == RECEIVERS_ELEMENT) && (xNode.HasChildNodes))
            {
                foreach (XmlNode jNode in xNode.ChildNodes)
                {
                    if (jNode.Name == Receiver.RECEIVER_ELEMENT)
                    {
                        ReceiverTypes receiverType = ReceiverTypes.Unknown;
                        foreach (XmlAttribute jAttribute in jNode.Attributes)
                        {
                            if (jAttribute.Name == TYPE_ATTRIBUTE)
                            {
                                receiverType = (ReceiverTypes)Enum.Parse(typeof(ReceiverTypes), jAttribute.Value, true);
                            }
                        }
                        Receiver receiver = null;
#if (PocketPC)
                        if (receiverType == ReceiverTypes.HTCDiamond)
                        {
                            receiver = new HTCDiamondReceiver();
                        }
                        else
#endif
                        if (receiverType == ReceiverTypes.RFCOMM)
                        {
                            receiver = new RFCOMMReceiver();
                        }
                        else if (receiverType == ReceiverTypes.StandardCOM)
                        {
                            receiver = new StandardCOMReceiver();
                        }
                        else if (receiverType == ReceiverTypes.HTCDiamond)
                        {
                            receiver = new HTCDiamondReceiver();
                        }
                        receiver.FromXML(jNode.OuterXml);
                        this.Insert(receiver._ID, receiver);
                    }
                }
            }
        }
예제 #2
0
파일: Core.cs 프로젝트: katadam/wockets
        /// <summary>
        /// Listens to kernel events, updates wockets objects with new information and fires events to any subscribers
        /// </summary>
        private static void EventListener()
        {
            int myid = System.Threading.Thread.CurrentThread.ManagedThreadId;
            KernelResponse myevent = (KernelResponse)events[myid];
            string eventName = Core._IcomingChannel +"-"+ myevent.ToString();
            NamedEvents namedEvent = new NamedEvents();
            RegistryKey rk = null;
            while (true)
            {
                namedEvent.Receive(eventName);
                switch (myevent)
                {
                    case (KernelResponse)KernelResponse.STARTED:
                        Core._KernalStarted = true;
                        break;
                    case (KernelResponse)KernelResponse.PING_RESPONSE:
                        Core._KernalStarted = true;
                        break;
                    case (KernelResponse)KernelResponse.REGISTERED:
                        _Registered = true;
                        break;
                    case (KernelResponse)KernelResponse.UNREGISTERED:
                        _Registered = false;
                        break;
                    case (KernelResponse)KernelResponse.STOPPED:
                        Core._KernalStarted = false;
                        break;
                    case (KernelResponse)KernelResponse.DISCOVERED:
                        rk = Registry.LocalMachine.OpenSubKey(Core.REGISTRY_DISCOVERED_SENSORS_PATH);
                        if (rk != null)
                        {
                            string[] sensors = rk.GetSubKeyNames();
                            rk.Close();
                            _DiscoveredSensors.Clear();
                            if (sensors.Length > 0)
                            {
                                for (int i = 0; (i < sensors.Length); i++)
                                {

                                    rk = Registry.LocalMachine.OpenSubKey(Core.REGISTRY_DISCOVERED_SENSORS_PATH + "\\" + sensors[i]); ;
                                    _DiscoveredSensors.Add((string)rk.GetValue("Name"), (string)rk.GetValue("MacAddress"));
                                    rk.Close();
                                }
                            }
                        }
                        break;
                    case (KernelResponse)KernelResponse.SENSORS_UPDATED:
                        CurrentWockets._Controller = new WocketsController("", "", "");
                        CurrentWockets._Controller._Mode = Wockets.MemoryMode.SharedToLocal;
                        CurrentWockets._Controller._Receivers = new Wockets.Receivers.ReceiverList();
                        rk = null;
                        kernelLock.WaitOne();
                        for (int i = 0; (i < 5); i++)
                        {
                            try
                            {
                                rk = Registry.LocalMachine.OpenSubKey(Core.REGISTRY_SENSORS_PATH + "\\" + i.ToString("0"));
                                int status = (int)rk.GetValue("Status");
                                if (status == 1)
                                {
                                    string mac = (string)rk.GetValue("MacAddress");
                                    RFCOMMReceiver receiver = new RFCOMMReceiver();
                                    receiver._ID = 0;
                                    receiver._Address = mac;
                                    CurrentWockets._Controller._Receivers.Add(receiver);
                                    WocketsDecoder decoder = new WocketsDecoder();
                                    decoder._ID = 0;
                                    CurrentWockets._Controller._Decoders.Add(decoder);
                                    Wocket wocket = new Wocket();
                                    wocket._ID = 0;
                                    wocket._Loaded = true;
                                    wocket._Decoder = decoder;
                                    wocket._Receiver = receiver;
                                    CurrentWockets._Controller._Sensors.Add(wocket);

                                }
                                rk.Close();
                            }
                            catch
                            {
                            }
                        }
                        kernelLock.Release();
                        break;
                    case (KernelResponse)KernelResponse.CONNECTED:
                        CurrentWockets._Controller.Initialize();
                        Core._Connected = true;
                        break;
                    case (KernelResponse)KernelResponse.DISCONNECTED:
                        Core._Connected = false;
                        break;
                    case (KernelResponse)KernelResponse.BATTERY_LEVEL_UPDATED:
                        Core.READ_BATTERY_LEVEL();
                        break;
                    case (KernelResponse)KernelResponse.BATTERY_PERCENT_UPDATED:
                        Core.READ_BATTERY_PERCENT();
                        break;
                    case (KernelResponse)KernelResponse.PC_COUNT_UPDATED:
                        Core.READ_PDU_COUNT();
                        break;
                    case (KernelResponse)KernelResponse.SENSITIVITY_UPDATED:
                        Core.READ_SENSITIVITY();
                        break;
                    case (KernelResponse)KernelResponse.CALIBRATION_UPDATED:
                        Core.READ_CALIBRATION();
                        break;

                    case (KernelResponse)KernelResponse.SAMPLING_RATE_UPDATED:
                        Core.READ_SAMPLING_RATE();
                        break;
                    case (KernelResponse)KernelResponse.TRANSMISSION_MODE_UPDATED:
                        Core.READ_TRANSMISSION_MODE();
                        break;
                    case (KernelResponse)KernelResponse.ACTIVITY_COUNT_UPDATED:
                        Core.READ_ACTIVITY_COUNT();
                        break;
                    case (KernelResponse)KernelResponse.TCT_UPDATED:
                        Core.READ_TCT();
                        break;
                    default:
                        break;
                }
                namedEvent.Reset();
                FireEvent(myevent);
            }
        }