Esempio n. 1
0
        private void OnPortActivatedCb(PortKey pkey)
        {
            var targetThing = Helper.Things.Find(i => i.ThingKey == pkey.ThingKey);

            if (targetThing == null)
            {
                return;
            }
            var targetPort = targetThing.GetPort(pkey);

            if (targetPort == null)
            {
                return;
            }

            DebugEx.TraceLog("ACTIVATED: " + pkey);
            if (targetPort.ioDirection == ioPortDirection.Output ||
                targetPort.ioDirection == ioPortDirection.InputOutput)
            {
                var groveBaseSensor = Helper.Lookup.TryGetOrDefault(targetThing);
                if (groveBaseSensor != null)
                {
                    groveBaseSensor.ReadContinuously();
                }
            }
        }
Esempio n. 2
0
        private void _SetupThings()
        {
            #region thing for pin20
            var thingPin20Id = CreateThingKey("Pin20");
            Console.WriteLine("Adding thing with ID: {0}", thingPin20Id);
            ThingIdToPin.Add(thingPin20Id, GpioPin.Pin20);
            ThingIdToThing.Add(thingPin20Id, new Yodiwo.API.Plegma.Thing()
            {
                ThingKey = ThingKey.BuildFromArbitraryString(NodeKey, thingPin20Id),
                Type     = ThingTypeLibrary.Lights.Type + PlegmaAPI.ThingModelTypeSeparator + ThingTypeLibrary.Gpio_Type,
                Name     = "GPIO pin 20",
                Config   = null,
                UIHints  = new ThingUIHints()
                {
                    IconURI = "/Content/img/icons/Generic/gpio.png",
                },
                Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        PortKey     = PortKey.BuildFromArbitraryString(ThingKey.BuildFromArbitraryString(NodeKey, thingPin20Id), "0"),
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "PinState",
                        State       = "0",
                        PortModelId = ModelTypeLibrary.GpioModel_Id,
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                    }
                }
            });
            #endregion

            #region thing for pin21
            var thingPin21Id = CreateThingKey("Pin21");
            Console.WriteLine("Adding thing with ID: {0}", thingPin21Id);
            ThingIdToPin.Add(thingPin21Id, GpioPin.Pin21);
            ThingIdToThing.Add(thingPin21Id, new Yodiwo.API.Plegma.Thing()
            {
                ThingKey = ThingKey.BuildFromArbitraryString(NodeKey, thingPin21Id),
                Type     = ThingTypeLibrary.Lights.Type + PlegmaAPI.ThingModelTypeSeparator + ThingTypeLibrary.Gpio_Type,
                Name     = "GPIO pin 21",
                Config   = null,
                UIHints  = new ThingUIHints()
                {
                    IconURI = "/Content/img/icons/Generic/gpio.png",
                },
                Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        PortKey     = PortKey.BuildFromArbitraryString(ThingKey.BuildFromArbitraryString(NodeKey, thingPin21Id), "0"),
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "PinState",
                        State       = "0",
                        PortModelId = ModelTypeLibrary.GpioModel_Id,
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                    }
                }
            });
            #endregion
        }
Esempio n. 3
0
        public static Thing CreateThing(NodeKey NodeKey)
        {
            //create key
            ThingKey     = new ThingKey(NodeKey, PluginMain.ThingKeyPrefix + "Test_Text_IO");
            PortKey_Text = new PortKey(ThingKey, "Text");

            //create thing
            var thing = new Thing()
            {
                ThingKey  = ThingKey,
                Name      = "Text IO",
                ConfFlags = eThingConf.Removable,
            };

            thing.Ports = new List <Port>()
            {
                new Yodiwo.API.Plegma.Port()
                {
                    PortKey     = PortKey_Text,
                    ioDirection = Yodiwo.API.Plegma.ioPortDirection.InputOutput,
                    Name        = "Text",
                    State       = "",
                    Type        = Yodiwo.API.Plegma.ePortType.String,
                    ConfFlags   = ePortConf.None,
                },
            };
            return(thing);
        }
Esempio n. 4
0
        public bool IsSameType(ThingDescriptor thing)
        {
            if (!String.IsNullOrWhiteSpace(Type) && Type != thing.Type)
            {
                return(false);
            }

            if (Ports.Count != thing.Ports.Count)
            {
                return(false);
            }

            foreach (var pkv in thing.Ports)
            {
                // build the right PortKey
                PortKey        thingPortKey = PortKey.BuildFromArbitraryString(thing.ThingKey, ((PortKey)pkv.PortKey).PortUID);
                PortDescriptor Port         = thing.GetPort(thingPortKey);
                if (Port == null)
                {
                    DebugEx.Assert("could not find Port for pkey: " + thingPortKey);
                }
                if (Port.PortType != pkv.PortType)
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 5
0
            public PortEventExt(PortEvent ev)
                : base(ev.PortKey, ev.State, ev.RevNum, ev.Timestamp)
            {
                PortKey p = new PortKey(ev.PortKey);

                this.ThingUID = p.ThingKey.ThingUID;
                this.PortUID  = p.PortUID;
            }
Esempio n. 6
0
 public Port(PortKey portKey, ePortType type, ioPortDirection ioDirection, string portmodelid = null)
 {
     this.PortKey     = portKey;
     this.Type        = type;
     this.ioDirection = ioDirection;
     this.State       = null;
     this.PortModelId = portmodelid;
 }
Esempio n. 7
0
        public Port(PortKey portKey, ePortType type, ioPortDirection ioDirection, string portmodelid = null)
        {
            this.PortKey     = portKey;
            this.Type        = type;
            this.State       = null;
            this.PortModelId = portmodelid;

            DebugEx.Assert(ioDirection != ioPortDirection.Undefined, $"Undefined IO direction for port {portKey}");
            this.ioDirection = ioDirection;
        }
Esempio n. 8
0
        //------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Functions
        //------------------------------------------------------------------------------------------------------------------------
        public override bool Initialize(mNodeConfig mNodeConfig, string PluginConfig, string UserConfig)
        {
            //init base
            if (base.Initialize(mNodeConfig, PluginConfig, UserConfig) == false)
            {
                return(false);
            }


            //initialize native system (threads etc)
            try
            {
                if (Native.Initialize(ThingKeyPrefix) != 0)
                {
                    DebugEx.TraceLog("Could not initialize native system");
                }
                else
                {
                    DebugEx.TraceLog("Initialized native system");

                    // Get things
                    var json   = Native.GetThings();
                    var things = json.FromJSON <List <Thing> >();
                    DebugEx.TraceLog($"Things:{things.Count} - {things[0].Name}");

                    // Fix keys
                    foreach (var t in things)
                    {
                        t.ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", t.ThingKey);
                        foreach (var p in t.Ports)
                        {
                            p.PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", p.PortKey);
                        }
                    }

                    // Add things
                    AddThing(things);


                    //start command retriver
                    isRunning = true;
                    CommandRetrieverThread = new Thread(commandRetrieverHeartbeatEntryPoint);
                    CommandRetrieverThread.IsBackground = true;
                    CommandRetrieverThread.Start();
                }
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "Failed to init plugin"); return(false); }


            //init plugin
            DebugEx.TraceLog("C++11 Plugin up and running !! ");

            //done
            return(true);
        }
Esempio n. 9
0
        public static List <Thing> GatherThings(Transport trans)
        {
            //setup Camera  thing
            #region Setup Camera thing
            {
                ConfigParameter conf = new ConfigParameter()
                {
                    Name  = "AccessUri",
                    Value = "RasPiCamera://10.30.254.223",
                };
                var thing = CameraThing = new Yodiwo.API.Plegma.Thing()
                {
                    Type    = "yodiwo.output.camera",
                    Name    = "RasPiCamera ",
                    Config  = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/VirtualGateway/img/icon-thing-genericwebcam.png",
                    },
                };
                VideoMediaDescriptor video = new VideoMediaDescriptor()
                {
                    uri         = "node://$NodeKey$/" + conf.Value,
                    protocol    = "http://",
                    videoDevice = VideoIn.Node,
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Camera Feed",
                        State       = video.ToJSON(HtmlEncode: false),
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "Camera Filter",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "1")
                    }
                };
            }
            #endregion

            Things.Add(CameraThing);

            return(Things);
        }
Esempio n. 10
0
        //------------------------------------------------------------------------------------------------------------------------
        /// <summary> Process commands received by the native library </summary>
        void processCommand(string jsonMsg)
        {
            try
            {
                var msg = jsonMsg.FromJSON <Msg>();

                if (msg.Type == MsgType.SendPortEvent)
                {
                    var sendPortEvent = msg.Message.FromJSON <SendPortEvent>();
                    var tKey          = ThingKey.BuildFromArbitraryString(this.NodeKey, sendPortEvent.ThingKey);
                    var pKey          = PortKey.BuildFromArbitraryString(tKey, sendPortEvent.PortKey);
                    SetPortState(pKey, sendPortEvent.State);
                }
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "processCommand failed"); }
        }
Esempio n. 11
0
        public static Thing CreateThing(string btnID, string flicBtnName)
        {
            var thing = new Thing()
            {
                ThingKey  = ThingKey.BuildFromArbitraryString("$NodeKey$", CreateThingKey(btnID)),
                Name      = "Flic-" + flicBtnName,
                ConfFlags = eThingConf.Removable,
                UIHints   = new ThingUIHints()
                {
                    Description = "FLIC Button " + flicBtnName + ".",
                    IconURI     = "/Content/img/icons/Generic/icon-thing-flic.png"
                },
            };

            thing.Ports = new List <Port>()
            {
                new Yodiwo.API.Plegma.Port()
                {
                    PortKey     = PortKey.BuildFromArbitraryString(thing.ThingKey, SingleClick),
                    ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                    Name        = "Single Click",
                    State       = "",
                    Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                    ConfFlags   = ePortConf.None,
                },
                new Yodiwo.API.Plegma.Port()
                {
                    PortKey     = PortKey.BuildFromArbitraryString(thing.ThingKey, DoubleClick),
                    ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                    Name        = "Double Click",
                    State       = "",
                    Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                    ConfFlags   = ePortConf.None,
                },
                new Yodiwo.API.Plegma.Port()
                {
                    PortKey     = PortKey.BuildFromArbitraryString(thing.ThingKey, LongClick),
                    ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                    Name        = "Long Click",
                    State       = "",
                    Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                    ConfFlags   = ePortConf.None,
                },
            };
            return(thing);
        }
Esempio n. 12
0
        //------------------------------------------------------------------------------------------------------------------------
        private Thing ReconstructThing(ThingDescriptor thdesc)
        {
            if (!LookupThingType.ContainsKey(thdesc.Type))
            {
                DebugEx.TraceError("Not Valid type in: " + thdesc.Name.ToLowerInvariant());
                return(null);
            }
            if (!LookupPortDirection.ContainsKey(thdesc.IO.ToLowerInvariant()))
            {
                DebugEx.TraceError("Not Valid IO in: " + thdesc.Name);
                return(null);
            }

            Thing thing = new Thing()
            {
                Name    = thdesc?.Name,
                Config  = null,
                UIHints = new ThingUIHints()
                {
                    IconURI = thdesc?.FriendlyIcon
                }
            };

            thing.Ports = new List <Port>()
            {
                new Port()
                {
                    ioDirection = LookupPortDirection[thdesc.IO],
                    Name        = thing.Name + "Value",
                    Type        = LookupThingType[thdesc.Type],
                    PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0"),
                    State       = LookupThingState[LookupThingType[thdesc.Type]],
                }
            };
            return(thing);
        }
Esempio n. 13
0
        public static void CreateThings(Transport trans, Node node)
        {
            //setup Position  thing
            //3 ports (x,y,z)
            #region Setup Position thing
            {
                var thing = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "PositionThing"),
                    Type     = ThingTypeLibrary.PositionSensor.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault,
                    Name     = "Position",
                    Config   = null,
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "/Content/img/icons/Generic/position.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Position x State",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortModelId = ModelTypeLibrary.PositionSensorModel_XId,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Position y State",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortModelId = ModelTypeLibrary.PositionSensorModel_YId,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "1")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Position z State",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortModelId = ModelTypeLibrary.PositionSensorModel_ZId,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "2")
                    },
                };
                PositionThing = thing = node.AddThing(thing);
            }
            #endregion

            //setup Gesture thing
            // 5 ports(i.e tap:'center','flick':north2south,'touch':west...)
            #region Setup Gesture thing
            {
                var thing = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "GestureThing"),
                    Type     = ThingTypeLibrary.GestureSensor.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault,
                    Name     = "Gesture",
                    Config   = null,
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "/Content/img/icons/Generic/motion.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Tap",
                        State       = "false",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortModelId = ModelTypeLibrary.GestureSensorModel_TapId,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Touch",
                        State       = "false",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortModelId = ModelTypeLibrary.GestureSensorModel_TouchId,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "1")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "DoubleTap",
                        State       = "false",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortModelId = ModelTypeLibrary.GestureSensorModel_DoubleTapId,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "2")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Airwheel",
                        State       = "false",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortModelId = ModelTypeLibrary.GestureSensorModel_AirwheelId,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "3")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Flick",
                        State       = "false",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortModelId = ModelTypeLibrary.GestureSensorModel_FlickId,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "4")
                    },
                };
                GestureThing = thing = node.AddThing(thing);
            }
            #endregion

            //add things
            Things.Add(PositionThing);
            Things.Add(GestureThing);

            //create skywriter sensors
            PositionSensor positionsensor = new PositionSensor(trans);
            GestureSensor  gesturesensor  = new GestureSensor(trans);
            //update dictinaries
            Lookup.Add(PositionThing, positionsensor);
            Lookup.Add(GestureThing, gesturesensor);
            SkyWriterSensors.Add(PositionThing.Name, positionsensor);
            SkyWriterSensors.Add(GestureThing.Name, gesturesensor);

            //register events
            positionsensor.OnGetContinuousDatacb += p => OnGetPositionDatacb(positionsensor, p);
            gesturesensor.OnGetContinuousDatacb  += p => OnGetGestureDatacb(gesturesensor, p);
        }
Esempio n. 14
0
 public virtual Port GetPort(PortKey key)
 {
     return(this.Ports.FirstOrDefault(c => key == c.PortKey));
 }
Esempio n. 15
0
        //------------------------------------------------------------------------------------------------------------------------
        private IEnumerable <Thing> SetupSerialPortThing()
        {
            // Clean old things
            things.Clear();

            // mNode transport conncted event
            {
                var isTransportConnected = new Port()
                {
                    ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                    Name        = "Connected",
                    State       = "",
                    ConfFlags   = ePortConf.IsTrigger,
                    Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                    PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                };
                Ports.Add("isTransportConnected", isTransportConnected);

                var connectionTimestamp = new Port()
                {
                    ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                    Name        = "Timestamp",
                    State       = "",
                    ConfFlags   = ePortConf.None,
                    Type        = Yodiwo.API.Plegma.ePortType.Timestamp,
                    PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "1")
                };
                Ports.Add("connectionTimestamp", connectionTimestamp);

                var t = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", CreateThingKey("0")),
                    Type     = "",
                    Name     = "Transport",
                    Config   = new List <ConfigParameter>(),
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "http://simpleicon.com/wp-content/uploads/cloud-connection-1.png",
                    },

                    Ports = new List <Port>()
                    {
                        isTransportConnected,
                        connectionTimestamp
                    }
                };

                t = AddThing(t);
                things.Add("Transport", t);
            }

            // mNode periodic send
            {
                var periodicTimestamp = new Port()
                {
                    ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                    Name        = "Timestamp",
                    State       = "",
                    ConfFlags   = ePortConf.None,
                    Type        = Yodiwo.API.Plegma.ePortType.Timestamp,
                    PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                };
                Ports.Add("periodicTimestamp", periodicTimestamp);

                var t = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", CreateThingKey("1")),
                    Type     = "",
                    Name     = "Periodic",
                    Config   = new List <ConfigParameter>()
                    {
                        // TODO: Use the actual value of the thing
                        new ConfigParameter()
                        {
                            Description = "Period Seconds",
                            Name        = "Period",
                            Value       = "10"
                        }
                    },
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "https://openreferral.org/wp-content/uploads/2015/02/icon_4034-300x300.png",
                    },

                    Ports = new List <Port>()
                    {
                        periodicTimestamp
                    }
                };

                t = AddThing(t);
                things.Add("Periodic", t);
            }

            // mNode Ping
            {
                var echoPortOut = new Port()
                {
                    ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                    Name        = "Echo",
                    State       = "",
                    ConfFlags   = ePortConf.None,
                    Type        = Yodiwo.API.Plegma.ePortType.String,
                    PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                };
                Ports.Add("echoPortOut", echoPortOut);

                var echoPortIn = new Port()
                {
                    ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                    Name        = "Echo",
                    State       = "",
                    ConfFlags   = ePortConf.None,
                    Type        = Yodiwo.API.Plegma.ePortType.String,
                    PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "1")
                };
                Ports.Add("echoPortIn", echoPortIn);

                var t = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", CreateThingKey("2")),
                    Type     = "",
                    Name     = "Ping",
                    Config   = new List <ConfigParameter>(),
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "https://apk-dl.com/detail/image/com.lipinic.ping-w250.png",
                    },

                    Ports = new List <Port>()
                    {
                        echoPortIn,
                        echoPortOut
                    }
                };

                t = AddThing(t);
                things.Add("Ping", t);
            }

            return(things.Values);
        }
Esempio n. 16
0
        public static List <Thing> GatherThings(Transport trans)
        {
            //setup Position  thing
            //3 ports (x,y,z)
            #region Setup Position thing
            {
                var thing = PositionThing = new Yodiwo.API.Plegma.Thing()
                {
                    Type    = "yodiwo.output.sensors.position",
                    Name    = "Position",
                    Config  = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/SkyWriter/img/position.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Position x State",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Position y State",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "1")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Position z State",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "2")
                    },
                };
            }
            #endregion

            //setup Gesture thing
            // 5 ports(i.e tap:'center','flick':north2south,'touch':west...)
            #region Setup Gesture thing
            {
                var thing = GestureThing = new Yodiwo.API.Plegma.Thing()
                {
                    Type    = "yodiwo.output.gesture",
                    Name    = "Gesture",
                    Config  = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/SkyWriter/img/motion.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Tap",
                        State       = "false",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Touch",
                        State       = "false",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "1")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "DoubleTap",
                        State       = "false",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "2")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Airwheel",
                        State       = "false",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "3")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Flick",
                        State       = "false",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "4")
                    },
                };
            }
            #endregion

            //add things
            Things.Add(PositionThing);
            Things.Add(GestureThing);

            //create skywriter sensors
            PositionSensor positionsensor = new PositionSensor(trans);
            GestureSensor  gesturesensor  = new GestureSensor(trans);
            //update dictinaries
            Lookup.Add(PositionThing, positionsensor);
            Lookup.Add(GestureThing, gesturesensor);
            SkyWriterSensors.Add(PositionThing.Name, positionsensor);
            SkyWriterSensors.Add(GestureThing.Name, gesturesensor);

            //register events
            positionsensor.OnGetContinuousDatacb += p => OnGetPositionDatacb(positionsensor, p);
            gesturesensor.OnGetContinuousDatacb  += p => OnGetGestureDatacb(gesturesensor, p);

            return(Things);
        }
Esempio n. 17
0
        private void GotButton(Bdaddr bdAddr)
        {
            DebugEx.TraceLog("Got Button");
            var thing = flicThings.TryGetOrDefault(bdAddr);

            if (thing == null)
            {
                thing = ThingTools.FlicThing.CreateThing(bdAddr.ToString().Replace(":", ""), bdAddr.ToString());
                thing = AddThing(thing);
                flicThings.Add(bdAddr, thing);
            }

            DebugEx.TraceLog("===========>Add Button Thing Completed");
            var channel = ButtonChannels.TryGetOrDefault(bdAddr);

            if (channel == null)
            {
                DebugEx.TraceLog("===========>New Channel is created");
                channel = new ButtonConnectionChannel(bdAddr);

                channel.CreateConnectionChannelResponse += (sender1, eventArgs) =>
                {
                    if (eventArgs.Error == CreateConnectionChannelError.NoError)
                    {
                        _channelConnected((ButtonConnectionChannel)sender1);
                    }
                    else
                    {
                        DebugEx.TraceError(((ButtonConnectionChannel)sender1).BdAddr.ToString() + " could not be connected");
                    }
                };
                channel.Removed += (sender1, eventArgs) =>
                {
                    _channelDisconnected((ButtonConnectionChannel)sender1);
                };
                channel.ConnectionStatusChanged += (sender1, eventArgs) =>
                {
                    var chan = (ButtonConnectionChannel)sender1;
                    if (eventArgs.ConnectionStatus == ConnectionStatus.Disconnected)
                    {
                        _channelDisconnected(chan);
                    }
                };
                channel.ButtonSingleOrDoubleClickOrHold += (sender1, eventArgs) =>
                {
                    var chan      = (ButtonConnectionChannel)sender1;
                    var thisThing = flicThings.TryGetOrDefault(chan.BdAddr);
                    if (thisThing == null)
                    {
                        return;
                    }

                    DebugEx.TraceLog(eventArgs.ClickType + " for " + thisThing.Name + " (key:" + thisThing.ThingKey + ")");
                    switch (eventArgs.ClickType)
                    {
                    case ClickType.ButtonSingleClick:
                        SetPortState(PortKey.BuildFromArbitraryString(thisThing.ThingKey, ThingTools.FlicThing.SingleClick), "True");
                        break;

                    case ClickType.ButtonDoubleClick:
                        SetPortState(PortKey.BuildFromArbitraryString(thisThing.ThingKey, ThingTools.FlicThing.DoubleClick), "True");
                        break;

                    case ClickType.ButtonHold:
                        SetPortState(PortKey.BuildFromArbitraryString(thisThing.ThingKey, ThingTools.FlicThing.LongClick), "True");
                        break;

                    default:
                        break;
                    }

                    if (!ButtonChannels.ContainsKey(chan.BdAddr))
                    {
                        _channelConnected(chan);
                    }
                };

                //try to add channel
                _flicClient.AddConnectionChannel(channel);
                DebugEx.TraceLog("===========>Add Connection Channel Completed");

                foreach (var navctx in NavigationContext.Values)
                {
                    DebugEx.TraceLog("===========>navctx.CurrentPage.Title: " + navctx.CurrentPage.Title);
                    if (navctx.CurrentPage.Title == "Flic Pairing")
                    {
                        DebugEx.TraceLog("=====>here I am <======");
                        navctx.GoBack();
                        navctx.UpdateCurrentPage(createDiscoverPage());
                    }
                }
            }
        }
Esempio n. 18
0
        //------------------------------------------------------------------------------------------------------------------------

        #region Functions
        //------------------------------------------------------------------------------------------------------------------------
        //initialize node's things
        public static List <Thing> GatherThings()
        {
            //setup CheckBox 1 thing
            #region Setup CheckBox 1 thing
            {
                var thing = CheckBox1Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type    = "yodiwo.output.checkboxes",
                    Name    = "Virtual CheckBox 1",
                    Config  = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/VirtualGateway/img/icon-thing-checkbox.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "CheckState",
                        State       = "false",
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing);
            }
            #endregion

            //setup Text 1 thing
            #region Setup CheckBox 1 thing
            {
                var thing = TextThing = new Yodiwo.API.Plegma.Thing()
                {
                    Type    = "yodiwo.output.labels",
                    Name    = "Text 1",
                    Config  = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/VirtualGateway/img/icon-thing-text.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "Text",
                        State       = "",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing);
            }
            #endregion

            //setup slider 1 thing
            #region Setup slider 1 thing
            {
                var thing = Slider1Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type    = "yodiwo.output.slider",
                    Name    = "Slider 1",
                    Config  = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/VirtualGateway/img/icon-thing-slider.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Value",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Decimal,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing);
            }
            #endregion

            //setup Light 1 thing
            #region Setup Light 1 thing
            {
                var thing = Light1Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type    = "yodiwo.input.lights.dimmable",
                    Name    = "Virtual Light 1",
                    Config  = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/VirtualGateway/img/icon-thing-genericlight.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "LightState",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Decimal,
                        ConfFlags   = ePortConf.PropagateAllEvents,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing);
            }
            #endregion

            //setup SpeechReg thing
            #region Setup SpeechReg thing
            {
                var thing = SpeechRegThing = new Yodiwo.API.Plegma.Thing()
                {
                    Type    = "yodiwo.output.speechrecognition",
                    Name    = "Virtual SpeechReg",
                    Config  = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/VirtualGateway/img/icon-thing-voicerecognition.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Text",
                        State       = "",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        ConfFlags   = ePortConf.PropagateAllEvents,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing);
            }
            #endregion

            //setup SpeechReg thing
            #region Setup Text2Speech thing
            {
                var thing = Text2SpeechThing = new Yodiwo.API.Plegma.Thing()
                {
                    Type    = "yodiwo.input.text2speech",
                    Name    = "Virtual Text2Speech",
                    Config  = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/VirtualGateway/img/icon-thing-text2speech.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "Text",
                        State       = "",
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        ConfFlags   = ePortConf.PropagateAllEvents,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing);
            }
            #endregion


            //setup thing
            #region accell 1 thing
            {
                var thing = AccelerometerThing = new Yodiwo.API.Plegma.Thing()
                {
                    Type    = "yodiwo.output.accelerometer",
                    Name    = "Accelerometer",
                    Config  = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/VirtualGateway/img/icon-thing-slider.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "X",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Decimal,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Y",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Decimal,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "1")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Z",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Decimal,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "2")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Length",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Decimal,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "3")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Shaken",
                        State       = "0",
                        ConfFlags   = ePortConf.PropagateAllEvents,
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "4")
                    }
                };
                Things.Add(thing);
            }
            #endregion



            //setup  thing
            #region Setup fall thing
            {
                var thing = FallThing = new Yodiwo.API.Plegma.Thing()
                {
                    Type    = "yodiwo.output.accelerometer",
                    Name    = "Fall Detector",
                    Config  = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/VirtualGateway/img/icon-thing-checkbox.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Fall Event",
                        State       = "false",
                        ConfFlags   = ePortConf.PropagateAllEvents,
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing);
            }
            #endregion



            return(Things);
        }
Esempio n. 19
0
 public Port(PortKey portKey, ePortType type, ioPortDirection ioDirection, string portmodelid = null)
 {
     this.PortKey = portKey;
     this.Type = type;
     this.ioDirection = ioDirection;
     this.State = null;
     this.PortModelId = portmodelid;
 }
Esempio n. 20
0
 public PortDescriptor GetPort(PortKey key)
 {
     return(this.Ports.Where(p => p.PortKey == key)?.First());
 }
Esempio n. 21
0
        //------------------------------------------------------------------------------------------------------------------------
        private List <Thing> SetupSerialPortThings()
        {
            List <Thing> things = new List <Thing>();

            // Serial Port Data
            {
                var tkey1 = new ThingKey(NodeKey, CreateThingId("1"));
                SendToCloudPort = new Port()
                {
                    ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                    Name        = "FromSerialPort",
                    State       = "",
                    ConfFlags   = ePortConf.None,
                    Type        = Yodiwo.API.Plegma.ePortType.String,
                    PortKey     = PortKey.BuildFromArbitraryString(tkey1, "0")
                };

                var t = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = tkey1,
                    Type     = "com.yodiwo.serialport",
                    Name     = "SerialOut",
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "http://www.aimtouch.com/images/RS232-icon.png",
                    },

                    Ports = new List <Port>()
                    {
                        SendToCloudPort
                    }
                };

                t = AddThing(t);
                things.Add(t);
            }

            // Serial Port success write
            {
                var tkey2 = new ThingKey(NodeKey, CreateThingId("2"));
                ReceiveFromCloudPort = new Port()
                {
                    ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                    Name        = "ToSerialPort",
                    State       = "",
                    ConfFlags   = ePortConf.None,
                    Type        = Yodiwo.API.Plegma.ePortType.String,
                    PortKey     = PortKey.BuildFromArbitraryString(tkey2, "0")
                };

                var t = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = tkey2,
                    Type     = "com.yodiwo.serialport",
                    Name     = "SerialIn",
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "http://www.aimtouch.com/images/RS232-icon.png",
                    },

                    Ports = new List <Port>()
                    {
                        ReceiveFromCloudPort
                    }
                };

                t = AddThing(t);
                things.Add(t);
            }

            return(things);
        }
Esempio n. 22
0
 //------------------------------------------------------------------------------------------------------------------------
 public bool IsPortActive(PortKey pk)
 {
     return(_ActivePortKeys?.Contains(pk) ?? false);
 }
Esempio n. 23
0
        public static void CreateThings(Transport trans, Node node)
        {
            #region READ CONFIGURATION

            var SavedThingsConfig = ReadConfig();
            if (SavedThingsConfig == null)
            {
                DebugEx.Assert("Could not retrieve or create config; startup failed");
                return;
            }

            //use pin configuration from saved conf file
            var buzzerPin      = SavedThingsConfig[typeof(Buzzer)].Pin;
            var rgbLedPin      = SavedThingsConfig[typeof(RgbLed)].Pin;
            var soundSensorPin = SavedThingsConfig[typeof(SoundSensor)].Pin;
            var lightSensorPin = SavedThingsConfig[typeof(LightSensor)].Pin;
            var buttonPin      = SavedThingsConfig[typeof(Button)].Pin;
            var rotaryAnglePin = SavedThingsConfig[typeof(RotaryAngleSensor)].Pin;
            var relayPin       = SavedThingsConfig[typeof(Relay)].Pin;
            var htSensorPin    = SavedThingsConfig[typeof(TempAndHumidity)].Pin;
            var ultrasonicPin  = SavedThingsConfig[typeof(UltraSonicRanger)].Pin;
            var lcdPin         = SavedThingsConfig[typeof(LCD)].Pin;

            //use sampling period configuration from saved conf file
            var gpio_Sampling       = SavedThingsConfig[typeof(GPIO)].Period;
            var soundSensorSampling = SavedThingsConfig[typeof(SoundSensor)].Period;
            var lightSensorSampling = SavedThingsConfig[typeof(LightSensor)].Period;
            var buttonSampling      = SavedThingsConfig[typeof(Button)].Period;
            var rotaryAngleSampling = SavedThingsConfig[typeof(RotaryAngleSensor)].Period;
            var relaySampling       = SavedThingsConfig[typeof(Relay)].Period;
            var htSensorSampling    = SavedThingsConfig[typeof(TempAndHumidity)].Period;
            var ultrasonicSampling  = SavedThingsConfig[typeof(UltraSonicRanger)].Period;

            #endregion


            #region CREATE SENSORS

            /* A2MCU */
            GPIO GPIO_2 = new GPIO(Pin.DigitalPin2, trans, gpio_Sampling);
            GPIO GPIO_3 = new GPIO(Pin.DigitalPin3, trans, gpio_Sampling);
            GPIO GPIO_4 = new GPIO(Pin.DigitalPin4, trans, gpio_Sampling);
            GPIO GPIO_5 = new GPIO(Pin.DigitalPin5, trans, gpio_Sampling);
            GPIO GPIO_6 = new GPIO(Pin.DigitalPin6, trans, gpio_Sampling);
            /* /A2MCU */

            Buzzer            buzzer            = new Buzzer(GrovePiSensor.PinNameToPin[buzzerPin], trans);
            RgbLed            rgbled            = new RgbLed(GrovePiSensor.PinNameToPin[rgbLedPin], trans);
            SoundSensor       soundSensor       = new SoundSensor(GrovePiSensor.PinNameToPin[soundSensorPin], trans, soundSensorSampling);
            LightSensor       lightSensor       = new LightSensor(GrovePiSensor.PinNameToPin[lightSensorPin], trans, lightSensorSampling);
            Button            button            = new Button(GrovePiSensor.PinNameToPin[buttonPin], trans, buttonSampling);
            RotaryAngleSensor rotaryAngleSensor = new RotaryAngleSensor(GrovePiSensor.PinNameToPin[rotaryAnglePin], trans, rotaryAngleSampling);
            Relay             relaySensor       = new Relay(GrovePiSensor.PinNameToPin[relayPin], trans, relaySampling);
            TempAndHumidity   htSensor          = new TempAndHumidity(GrovePiSensor.PinNameToPin[htSensorPin], trans, htSensorSampling);
            UltraSonicRanger  ultrasonicSensor  = new UltraSonicRanger(GrovePiSensor.PinNameToPin[ultrasonicPin], trans, ultrasonicSampling);
            LCD lcd = new LCD(GrovePiSensor.PinNameToPin[lcdPin], trans);

            #endregion


            #region SETUP THINGS

            #region Setup A2MCU GPIO things

            List <Thing> gpio_things = new List <Thing>();
            for (int i = 2; i <= 6; i++)
            {
                //var pinConfig = new ConfigParameter() { Name = "Pin", Value = buzzerPin };
                var samplePeriodConfig = new ConfigParameter()
                {
                    Name = "SamplePeriod", Value = gpio_Sampling.ToStringInvariant()
                };
                var thing = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "gpio_thing" + i),
                    Type     = ThingTypeLibrary.Gpio.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault,
                    Name     = "GPIO_" + i,
                    Config   = new List <ConfigParameter>()
                    {
                        samplePeriodConfig
                    },
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/img/icons/Generic/gpio.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "GPO",
                        PortModelId = ModelTypeLibrary.GpioModel_Id,
                        State       = "false",
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "GPO")
                    },
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "GPI",
                        State       = "false",
                        PortModelId = ModelTypeLibrary.GpioModel_Id,
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "GPI")
                    }
                };
                thing = node.AddThing(thing);
                gpio_things.Add(thing);
                Things.Add(thing);
            }

            //gpio thing --> gpio sensor class
            GPIOs.Add(gpio_things.ElementAt(0), GPIO_2);
            GPIOs.Add(gpio_things.ElementAt(1), GPIO_3);
            GPIOs.Add(gpio_things.ElementAt(2), GPIO_4);
            GPIOs.Add(gpio_things.ElementAt(3), GPIO_5);
            GPIOs.Add(gpio_things.ElementAt(4), GPIO_6);

            //gpio thing --> generic sensor class
            Lookup.Add(gpio_things.ElementAt(0), GPIO_2);
            Lookup.Add(gpio_things.ElementAt(1), GPIO_3);
            Lookup.Add(gpio_things.ElementAt(2), GPIO_4);
            Lookup.Add(gpio_things.ElementAt(3), GPIO_5);
            Lookup.Add(gpio_things.ElementAt(4), GPIO_6);

            gpio_things.Clear();

            #endregion

            //setup Buzzer  thing
            #region Setup Buzzer thing
            {
                var pinConfig = new ConfigParameter()
                {
                    Name = "Pin", Value = buzzerPin
                };
                var thing = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "buzzerthing"),
                    Type     = ThingTypeLibrary.Buzzer.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault,
                    Name     = "Buzzer",
                    Config   = new List <ConfigParameter>()
                    {
                        pinConfig
                    },
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/img/icons/buzzer.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "BuzzerState",
                        State       = "false",
                        PortModelId = ModelTypeLibrary.BuzzerModel_Id,
                        Type        = Yodiwo.API.Plegma.ePortType.Decimal,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                BuzzerThing = thing = node.AddThing(thing);
            }
            #endregion

            //setup RgbLed thing
            #region SetUp RgbLedThing
            {
                var pinConfig = new ConfigParameter()
                {
                    Name = "Pin", Value = rgbLedPin
                };
                var thing = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "RgbLedThing"),
                    Type     = ThingTypeLibrary.Lights.Type + PlegmaAPI.ThingModelTypeSeparator + ThingTypeLibrary.Lights_BooleanModelType,
                    Name     = "RgbLed",
                    Config   = new List <ConfigParameter>()
                    {
                        pinConfig
                    },
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/img/icons/Generic/thing-genericlight.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "RgbLedState",
                        State       = "false",
                        PortModelId = ModelTypeLibrary.OnOffLightModel_Id,
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                RgbLedThing = thing = node.AddThing(thing);
            }
            #endregion

            //setup SoundSensorThing
            #region SetUp SoundSensorThing
            {
                var pinConfig = new ConfigParameter()
                {
                    Name = "Pin", Value = soundSensorPin
                };
                var samplePeriodConfig = new ConfigParameter()
                {
                    Name = "SamplePeriod", Value = soundSensorSampling.ToStringInvariant()
                };
                var thing = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "SoundSensorThing"),
                    Type     = ThingTypeLibrary.SoundSensor.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault,
                    Name     = "SoundSensor",
                    Config   = new List <ConfigParameter>()
                    {
                        pinConfig, samplePeriodConfig
                    },
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/img/icons/sound.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Value",
                        State       = "0",
                        PortModelId = ModelTypeLibrary.SoundSensorModel_Id,
                        Type        = Yodiwo.API.Plegma.ePortType.Integer,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                SoundSensorThing = thing = node.AddThing(thing);
            }
            #endregion

            //setup Light Sensor thing
            #region SetUp LightSensorThing
            {
                var pinConfig = new ConfigParameter()
                {
                    Name = "Pin", Value = lightSensorPin
                };
                var samplePeriodConfig = new ConfigParameter()
                {
                    Name = "SamplePeriod", Value = lightSensorSampling.ToStringInvariant()
                };
                var thing = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "LightSensorThing"),
                    Type     = ThingTypeLibrary.LightSensor.Type + PlegmaAPI.ThingModelTypeSeparator + ThingTypeLibrary.LightSensor_NonNormalizedModelType,
                    Name     = "LightSensor",
                    Config   = new List <ConfigParameter>()
                    {
                        pinConfig, samplePeriodConfig
                    },
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/img/icons/light.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "Lumens",
                        State       = "0",
                        PortModelId = ModelTypeLibrary.Brightness_Id,
                        Type        = Yodiwo.API.Plegma.ePortType.Integer,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                LightSensorThing = thing = node.AddThing(thing);
            }
            #endregion

            //setup Button thing
            #region SetUp ButtonThing
            {
                var pinConfig = new ConfigParameter()
                {
                    Name = "Pin", Value = buttonPin
                };
                var samplePeriodConfig = new ConfigParameter()
                {
                    Name = "SamplePeriod", Value = buttonSampling.ToStringInvariant()
                };
                var thing = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "ButtonSensorThing"),
                    Type     = ThingTypeLibrary.Button.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault,
                    Name     = "Button",
                    Config   = new List <ConfigParameter>()
                    {
                        pinConfig, samplePeriodConfig
                    },
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/img/icons/Generic/thing-genericbutton.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "ButtonState",
                        State       = "0",
                        PortModelId = ModelTypeLibrary.ButtonModel_OnOffActuatorId,
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                ButtonSensorThing = thing = node.AddThing(thing);
            }
            #endregion

            //setup RotaryAngle Sensor thing
            #region SetUp RotaryAngleSensorThing
            {
                var pinConfig = new ConfigParameter()
                {
                    Name = "Pin", Value = rotaryAnglePin
                };
                var samplePeriodConfig = new ConfigParameter()
                {
                    Name = "SamplePeriod", Value = rotaryAngleSampling.ToStringInvariant()
                };
                var thing = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "RotaryAngleSensorThing"),
                    Type     = ThingTypeLibrary.Slider.Type + PlegmaAPI.ThingModelTypeSeparatorStr,
                    Name     = "Rotary Angle Sensor",
                    Config   = new List <ConfigParameter>()
                    {
                        pinConfig, samplePeriodConfig
                    },
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/img/icons/Generic/thing-slider.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "RotaryAngle",
                        State       = "0",
                        PortModelId = ModelTypeLibrary.SliderModel_Id,
                        Type        = Yodiwo.API.Plegma.ePortType.Decimal,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                RotaryAngleSensorThing = thing = node.AddThing(thing);
            }
            #endregion

#if false
            //setup Relay thing
            #region SetUp RelayThing
            {
                var pinConfig = new ConfigParameter()
                {
                    Name = "Pin", Value = relayPin
                };
                var samplePeriodConfig = new ConfigParameter()
                {
                    Name = "SamplePeriod", Value = relaySampling.ToStringInvariant()
                };
                var thing = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "RelaySensorThing"),
                    Type     = ThingTypeLibrary.SwitchActuator.Type + PlegmaAPI.ThingModelTypeSeparator + ThingTypeLibrary.SwitchActuator_RelayModelType,
                    Name     = "Relay",
                    Config   = new List <ConfigParameter>()
                    {
                        pinConfig, samplePeriodConfig
                    },
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/img/icons/relay.jpg",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "RelayState",
                        PortModelId = ModelTypeLibrary.RelayModel_RelayId,
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Integer,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                RelaySensorThing = thing = node.AddThing(thing);
            }
            #endregion
#endif
            //setup Temperature and Humidity Sensor thing
            #region SetUp HTSensorThing
            {
                var pinConfig = new ConfigParameter()
                {
                    Name = "Pin", Value = htSensorPin
                };
                var samplePeriodConfig = new ConfigParameter()
                {
                    Name = "SamplePeriod", Value = htSensorSampling.ToStringInvariant()
                };
                var thing = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "HTSensorThing"),
                    Type     = ThingTypeLibrary.HTSensor.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault,
                    Name     = "Temperature and Humidity Sensor",
                    Config   = new List <ConfigParameter>()
                    {
                        pinConfig, samplePeriodConfig
                    },
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/img/icons/ht.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        PortModelId = ModelTypeLibrary.HTSensorModel_TemperatureSensorId,
                        Name        = "HT",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Integer,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                HTSensorThing = thing = node.AddThing(thing);
            }
            #endregion

            //setup UltraSonic Sensor thing
            #region SetUp UltrasonicThing
            {
                var pinConfig = new ConfigParameter()
                {
                    Name = "Pin", Value = ultrasonicPin
                };
                var samplePeriodConfig = new ConfigParameter()
                {
                    Name = "SamplePeriod", Value = ultrasonicSampling.ToStringInvariant()
                };
                var thing = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "UltrasonicSensorThing"),
                    Type     = ThingTypeLibrary.ProximitySensor.Type + PlegmaAPI.ThingModelTypeSeparator + ThingTypeLibrary.ProximitySensor_UltrasonicModelType,
                    Name     = "Ultrasonic Sensor",
                    Config   = new List <ConfigParameter>()
                    {
                        pinConfig, samplePeriodConfig
                    },
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/img/icons/proximity.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output,
                        Name        = "cm",
                        State       = "0",
                        PortModelId = ModelTypeLibrary.UltrasonicSensorModel_Id,
                        Type        = Yodiwo.API.Plegma.ePortType.Integer,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                UltrasonicSensorThing = thing = node.AddThing(thing);
            }
            #endregion

            //setup LCD Sensor thing
            #region SetUp LCDThing
            {
                var pinConfig = new ConfigParameter()
                {
                    Name = "Pin", Value = lcdPin
                };
                var thing = new Yodiwo.API.Plegma.Thing()
                {
                    ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "LCDThing"),
                    Type     = ThingTypeLibrary.Lcd.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault,
                    Name     = "LCD",
                    Config   = new List <ConfigParameter>()
                    {
                        pinConfig
                    },
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/img/icons/lcd.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "Message",
                        State       = "0",
                        PortModelId = ModelTypeLibrary.LcdModel_Id,
                        Type        = Yodiwo.API.Plegma.ePortType.String,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                LCDThing = thing = node.AddThing(thing);
            }
            #endregion

            #endregion


            #region LUT CRETION

            Things.Add(BuzzerThing);
            Things.Add(RgbLedThing);
            Things.Add(SoundSensorThing);
            Things.Add(LightSensorThing);
            Things.Add(ButtonSensorThing);
            Things.Add(RotaryAngleSensorThing);
            //Things.Add(RelaySensorThing);
            Things.Add(HTSensorThing);
            Things.Add(UltrasonicSensorThing);
            Things.Add(LCDThing);


            Lookup.Add(BuzzerThing, buzzer);
            Lookup.Add(RgbLedThing, rgbled);
            Lookup.Add(SoundSensorThing, soundSensor);
            Lookup.Add(LightSensorThing, lightSensor);
            Lookup.Add(ButtonSensorThing, button);
            Lookup.Add(RotaryAngleSensorThing, rotaryAngleSensor);
            //Lookup.Add(RelaySensorThing, relaySensor);
            Lookup.Add(HTSensorThing, htSensor);
            Lookup.Add(UltrasonicSensorThing, ultrasonicSensor);
            Lookup.Add(LCDThing, lcd);


            /*
             * GroveSensors.Add(BuzzerThing.Name, buzzer);
             * GroveSensors.Add(RgbLedThing.Name, rgbled);
             * GroveSensors.Add(SoundSensorThing.Name, soundSensor);
             * GroveSensors.Add(LightSensorThing.Name, lightSensor);
             * GroveSensors.Add(ButtonSensorThing.Name, button);
             * GroveSensors.Add(RotaryAngleSensorThing.Name, rotaryAngleSensor);
             * GroveSensors.Add(RelaySensorThing.Name, relaySensor);
             * GroveSensors.Add(HTSensorThing.Name, htSensor);
             * GroveSensors.Add(UltrasonicSensorThing.Name, ultrasonicSensor);
             * GroveSensors.Add(LCDThing.Name, lcd);
             */

            #endregion


            #region REGISTER EVENTS

            foreach (var gpio in GPIOs.Values)
            {
                gpio.OnGetContinuousDatacb += data => OnGetContinuousDatacb(gpio, data);
            }

            soundSensor.OnGetContinuousDatacb       += data => OnGetContinuousDatacb(soundSensor, data);
            lightSensor.OnGetContinuousDatacb       += data => OnGetContinuousDatacb(lightSensor, data);
            button.OnGetContinuousDatacb            += data => OnGetContinuousDatacb(button, data);
            rotaryAngleSensor.OnGetContinuousDatacb += data => OnGetContinuousDatacb(rotaryAngleSensor, data);
            relaySensor.OnGetContinuousDatacb       += data => OnGetContinuousDatacb(relaySensor, data);
            htSensor.OnGetContinuousDatacb          += data => OnGetContinuousDatacb(htSensor, data);
            ultrasonicSensor.OnGetContinuousDatacb  += data => OnGetContinuousDatacb(ultrasonicSensor, data);

            #endregion
        }
Esempio n. 24
0
 //------------------------------------------------------------------------------------------------------------------------
 public bool IsPortActive(PortKey pk) { return _ActivePortKeys?.Contains(pk) ?? false; }
Esempio n. 25
0
        private void OnPortActivatedCb(PortKey pkey)
        {
            var targetThing = Helper.Things.Find(i => i.ThingKey == pkey.ThingKey);
            if (targetThing == null)
                return;
            var targetPort = targetThing.GetPort(pkey);
            if (targetPort == null)
                return;

            DebugEx.TraceLog("ACTIVATED: " + pkey);
            if (targetPort.ioDirection == ioPortDirection.Output ||
                targetPort.ioDirection == ioPortDirection.InputOutput)
            {
                var groveBaseSensor = Helper.Lookup.TryGetOrDefault(targetThing);
                if (groveBaseSensor != null)
                    groveBaseSensor.ReadContinuously();
            }
        }
Esempio n. 26
0
 public override int GetHashCode()
 {
     return(PortKey == null ? 0 : PortKey.GetHashCode());
 }
        static DeveelDbConnectionStringBuilder()
        {
            defaults = new Dictionary <string, object>();
            defaults.Add(HostKey, DefaultHost);
            defaults.Add(PortKey, DefaultPort);
            defaults.Add(DatabaseKey, DefaultDatabase);
            defaults.Add(UserNameKey, DefaultUserName);
            defaults.Add(PasswordKey, DefaultPassword);
            defaults.Add(SchemaKey, DefaultSchema);
            defaults.Add(PathKey, DefaultPath);
            defaults.Add(CreateKey, DefaultCreate);
            defaults.Add(BootOrCreateKey, DefaultBootOrCreate);
            defaults.Add(ParameterStyleKey, DefaultParameterStyle);
            defaults.Add(VerboseColumnNamesKey, DefaultVerboseColumnName);
            defaults.Add(PersistSecurityInfoKey, DefaultPersistSecurityInfo);
            defaults.Add(RowCacheSizeKey, DefaultRowCacheSize);
            defaults.Add(MaxCacheSizeKey, DefaultMaxCacheSize);
            defaults.Add(FetchSizeKey, DefaultFetchSize);
            defaults.Add(MaxFetchSizeKey, DefaultMaxFetchSize);
            defaults.Add(AutoCommitKey, DefaultAutoCommit);
            defaults.Add(QueryTimeoutKey, DefaultQueryTimeout);

            keymaps = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);
            keymaps[HostKey.ToUpper()]     = HostKey;
            keymaps["ADDRESS"]             = HostKey;
            keymaps["SERVER"]              = HostKey;
            keymaps[PortKey.ToUpper()]     = PortKey;
            keymaps[DatabaseKey.ToUpper()] = DatabaseKey;
            keymaps["CATALOG"]             = DatabaseKey;
            keymaps["INITIAL CATALOG"]     = DatabaseKey;
            keymaps["DB"] = DatabaseKey;
            keymaps[SchemaKey.ToUpper()]   = SchemaKey;
            keymaps["DEFAULT SCHEMA"]      = SchemaKey;
            keymaps[PathKey.ToUpper()]     = PathKey;
            keymaps["DATA PATH"]           = PathKey;
            keymaps["DATABASE PATH"]       = PathKey;
            keymaps["DATAPATH"]            = PathKey;
            keymaps["DATABASEPATH"]        = PathKey;
            keymaps[CreateKey.ToUpper()]   = CreateKey;
            keymaps[BootOrCreateKey]       = BootOrCreateKey;
            keymaps["BOOT OR CREATE"]      = BootOrCreateKey;
            keymaps["CREATE OR BOOT"]      = BootOrCreateKey;
            keymaps["CREATEORBOOT"]        = BootOrCreateKey;
            keymaps[CreateKey.ToUpper()]   = CreateKey;
            keymaps["CREATE DATABASE"]     = CreateKey;
            keymaps[UserNameKey.ToUpper()] = UserNameKey;
            keymaps["USER"]                             = UserNameKey;
            keymaps["USER NAME"]                        = UserNameKey;
            keymaps["USER ID"]                          = UserNameKey;
            keymaps["USERID"]                           = UserNameKey;
            keymaps["UID"]                              = UserNameKey;
            keymaps[PasswordKey.ToUpper()]              = PasswordKey;
            keymaps["PASS"]                             = PasswordKey;
            keymaps["PWD"]                              = PasswordKey;
            keymaps["SECRET"]                           = PasswordKey;
            keymaps[ParameterStyleKey.ToUpper()]        = ParameterStyleKey;
            keymaps["PARAMSTYLE"]                       = ParameterStyleKey;
            keymaps["PARAMETER STYLE"]                  = ParameterStyleKey;
            keymaps["USEPARMAMETER"]                    = ParameterStyleKey;
            keymaps["USE PARAMETER"]                    = ParameterStyleKey;
            keymaps[VerboseColumnNamesKey.ToUpper()]    = VerboseColumnNamesKey;
            keymaps["VERBOSE COLUMNS"]                  = VerboseColumnNamesKey;
            keymaps["VERBOSE COLUMN NAMES"]             = VerboseColumnNamesKey;
            keymaps["VERBOSECOLUMNS"]                   = VerboseColumnNamesKey;
            keymaps["COLUMNS VERBOSE"]                  = VerboseColumnNamesKey;
            keymaps[PersistSecurityInfoKey.ToUpper()]   = PersistSecurityInfoKey;
            keymaps["PERSIST SECURITY INFO"]            = PersistSecurityInfoKey;
            keymaps[RowCacheSizeKey.ToUpper()]          = RowCacheSizeKey;
            keymaps["ROW CACHE SIZE"]                   = RowCacheSizeKey;
            keymaps["CACHE SIZE"]                       = RowCacheSizeKey;
            keymaps[MaxCacheSizeKey.ToUpper()]          = MaxCacheSizeKey;
            keymaps["MAX CACHE SIZE"]                   = MaxCacheSizeKey;
            keymaps["MAX CACHE"]                        = MaxCacheSizeKey;
            keymaps[QueryTimeoutKey.ToUpper()]          = QueryTimeoutKey;
            keymaps["QUERY TIMEOUT"]                    = QueryTimeoutKey;
            keymaps[IgnoreIdentifiersCaseKey.ToUpper()] = IgnoreIdentifiersCaseKey;
            keymaps["IGNORE CASE"]                      = IgnoreIdentifiersCaseKey;
            keymaps["IGNORE ID CASE"]                   = IgnoreIdentifiersCaseKey;
            keymaps["ID CASE IGNORED"]                  = IgnoreIdentifiersCaseKey;
            keymaps[StrictGetValueKey.ToUpper()]        = StrictGetValueKey;
            keymaps["STRICT"]                           = StrictGetValueKey;
            keymaps["STRICT GETVALUE"]                  = StrictGetValueKey;
            keymaps["STRICT VALUE"]                     = StrictGetValueKey;
            keymaps["STRICTVALUE"]                      = StrictGetValueKey;
            keymaps[FetchSizeKey.ToUpper()]             = FetchSizeKey;
            keymaps["FETCH SIZE"]                       = FetchSizeKey;
            keymaps["ROW COUNT"]                        = FetchSizeKey;
            keymaps["ROWCOUNT"]                         = FetchSizeKey;
            keymaps[MaxFetchSizeKey.ToUpper()]          = MaxFetchSizeKey;
            keymaps["MAX FETCH SIZE"]                   = MaxFetchSizeKey;
            keymaps["MAXFETCHSIZE"]                     = MaxFetchSizeKey;
            keymaps["MAX ROW COUNT"]                    = MaxFetchSizeKey;
            keymaps["MAX ROWCOUNT"]                     = MaxFetchSizeKey;
            keymaps["MAXROWCOUNT"]                      = MaxFetchSizeKey;
            keymaps[AutoCommitKey.ToUpper()]            = AutoCommitKey;
            keymaps["AUTOCOMMIT"]                       = AutoCommitKey;
            keymaps["AUTO-COMMIT"]                      = AutoCommitKey;
            keymaps["AUTO_COMMIT"]                      = AutoCommitKey;
            keymaps["AUTO COMMIT"]                      = AutoCommitKey;
            keymaps["COMMIT AUTO"]                      = AutoCommitKey;
            keymaps["COMMIT_AUTO"]                      = AutoCommitKey;
            keymaps["COMMITAUTO"]                       = AutoCommitKey;
            keymaps["COMMIT-AUTO"]                      = AutoCommitKey;
            keymaps["COMMIT"]                           = AutoCommitKey;
            keymaps["ENLIST"]                           = EnlistKey;
        }
Esempio n. 28
0
        public void Start()
        {
            #region Configurations

            this.YConfig   = this.InitConfig();
            this.ActiveCfg = this.YConfig.GetActiveConf();
            NodeConfig conf = new NodeConfig()
            {
                uuid = ActiveCfg.Uuid,
                Name = "RaspberryNode",
                MqttBrokerHostname = ActiveCfg.MqttBrokerHostname,
                MqttUseSsl         = ActiveCfg.MqttUseSsl,
                YpServer           = ActiveCfg.ApiServer,
                YpchannelPort      = ActiveCfg.YpchannelPort,
                SecureYpc          = ActiveCfg.YpchannelSecure,
                FrontendServer     = ActiveCfg.FrontendServer
            };

            #endregion

            #region Things setup

            #region Setup Led1 thing
            {
                var thing = Led1Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type     = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name     = "Raspberry Led 1",
                    Config   = null,
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "LedState",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led1);
            }
            #endregion

            #region Setup Led2 thing
            {
                var thing = Led2Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type     = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name     = "Raspberry Led 2",
                    Config   = null,
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "LedState",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led2);
            }
            #endregion

            #region Setup Led3 thing
            {
                var thing = Led3Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type     = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name     = "Raspberry Led 3",
                    Config   = null,
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "LedState",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led3);
            }
            #endregion

            #region Setup Led4 thing
            {
                var thing = Led4Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type     = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name     = "Raspberry Led 4",
                    Config   = null,
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "LedState",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led4);
            }
            #endregion

            #region Setup Led5 thing
            {
                var thing = Led5Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type     = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name     = "Raspberry Led 5",
                    Config   = null,
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "LedState",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led5);
            }
            #endregion

            #endregion

            #region Node construction
            //prepare pairing module
            var pairmodule = new Yodiwo.Node.Pairing.NancyPairing.NancyPairing();
            //prepare node graph manager module
            var nodeGraphManager = new Yodiwo.NodeLibrary.Graphs.NodeGraphManager(
                new Type[]
            {
                typeof(Yodiwo.Logic.BlockLibrary.Basic.Librarian),
                typeof(Yodiwo.Logic.BlockLibrary.Extended.Librarian),
            });
            //create node
            Node = new Yodiwo.NodeLibrary.Node(conf,
                                               Things.Values.ToList(),
                                               pairmodule,
                                               null, null,
                                               NodeGraphManager: nodeGraphManager
                                               //MqttTransport: typeof(Yodiwo.NodeLibrary.Transports.MQTT)
                                               );

            #endregion

            #region Register port event handlers

            Node.PortEventHandlers[Led1Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led      = PkeyToLed.TryGetOrDefault(Led1Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            Node.PortEventHandlers[Led2Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led      = PkeyToLed.TryGetOrDefault(Led2Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            Node.PortEventHandlers[Led3Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led      = PkeyToLed.TryGetOrDefault(Led3Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            Node.PortEventHandlers[Led4Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led      = PkeyToLed.TryGetOrDefault(Led4Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            Node.PortEventHandlers[Led5Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led      = PkeyToLed.TryGetOrDefault(Led5Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            #endregion

            #region Register callbacks

            Node.OnChangedState          += OnChangedStateCb;
            Node.OnNodePaired            += OnPairedCb;
            Node.OnTransportConnected    += OnTransportConnectedCb;
            Node.OnTransportDisconnected += OnTransportDisconnectedCb;
            Node.OnTransportError        += OnTransportErrorCb;
            Node.OnUnexpectedMessage      = OnUnexpectedMessageCb;

            #endregion

            #region Pairing/Connect

            if (String.IsNullOrWhiteSpace(ActiveCfg.NodeKey))
            {
                DebugEx.TraceLog("Starting pairing procedure.");
                var task = Node.StartPairing(ActiveCfg.FrontendServer, null, ActiveCfg.LocalWebServer);
            }
            else
            {
                Node.SetupNodeKeys(ActiveCfg.NodeKey, ActiveCfg.NodeSecret);
                DebugEx.TraceLog("Node already paired: NodeKey = "
                                 + ActiveCfg.NodeKey + ", NodeSecret = ", ActiveCfg.NodeSecret);

                Node.Connect();
            }

            #endregion
        }