示例#1
0
        //===============================================
        // Initialize
        // TODO SSI I had to add a "void" to get this to compile
        public void BtSerial(string address,string type_name)
        {
            // check that it doesn't affect the other connections
                TurnON_BT_Radio();

                Thread.Sleep(50);

                bt_type_name = type_name;

                if (type_name.CompareTo("wocket") == 0)
                {
                    BT_TYPE = WOCKET;
                    MAX_BYTES = 4096;

                    wocket_dc = new WocketsDecoder();
                    Wockets.Utils.WocketsTimer.InitializeTime();
                    cbuffer = new CircularBuffer(MAX_BYTES);
                }
                else if (type_name.CompareTo("lilypad") == 0)
                {
                    BT_TYPE = SERIAL_LILYPAD;
                    MAX_BYTES = 4096;
                }

                //Initialize buffer
                buffer = new byte[MAX_BYTES];

                address_set = SetAddress(address);
        }
示例#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);
            }
        }