Ejemplo n.º 1
0
        public async Task ParseThingPublish(string data)
        {
            data = data.Substring(data.IndexOf(" ") + 1);
            string topic = data.Substring(0, data.IndexOf(" "));
            string value = data.Substring(data.IndexOf(" ") + 1);

            List <string> tokenizeTopic = topic.Split('/').ToList();

            if (tokenizeTopic.Count > 2)
            {
                string driverName = tokenizeTopic[tokenizeTopic.Count - 2];
                string property   = tokenizeTopic[tokenizeTopic.Count - 1];

                //find driver
                OWLOSDriver driver = drivers.Find(d => d.name == driverName);

                if (driver != null)
                {
                    await driver.SetParsedProperty(property, value);
                }//can be ESP drivers
                else
                {
                    driver = drivers.Find(d => d.name == "wifi");
                    if (driver != null)
                    {
                        if (await driver.SetParsedProperty(property, value) != true)
                        {
                            driver = drivers.Find(d => d.name == "network");
                            if (driver != null)
                            {
                                if (await driver.SetParsedProperty(property, value) != true)
                                {
                                    driver = drivers.Find(d => d.name == "esp");
                                    if (driver != null)
                                    {
                                        await driver.SetParsedProperty(property, value);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public async Task ParseGetAllDriversProperties(string driverData)
        {
            List <string> driverRaw = driverData.Split('\n').ToList();
            OWLOSDriver   driver    = null;

            foreach (string driverProp in driverRaw)
            {
                //find driver
                if ((driverProp.IndexOf("properties for:") != -1) || (driverProp.IndexOf("PF:") != -1))
                {
                    string driverName = driverProp.Substring(driverProp.IndexOf(":") + 1);
                    driver = drivers.Find(n => n.name == driverName);
                    if (driver == null)
                    {
                        driver = new OWLOSDriver(this, driverName);

                        OWLOSDriverWrapperEventArgs _OWLOSDriverWrapperEventArgs = new OWLOSDriverWrapperEventArgs(driver);

                        NewDriver(_OWLOSDriverWrapperEventArgs);

                        drivers.Add(driver);
                    }
                    else
                    {
                    }
                }
                else
                if (driver != null)
                {
                    if (driverProp.IndexOf("=") != -1)
                    {
                        string key   = driverProp.Substring(0, driverProp.IndexOf("="));
                        string value = driverProp.Substring(driverProp.IndexOf("=") + 1);
                        await driver.SetParsedProperty(key, value);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public OWLOSDriverWrapperEventArgs(OWLOSDriver driver)
 {
     this.driver = driver;
 }