コード例 #1
0
ファイル: SensorDB.cs プロジェクト: dhakalsamip/LoT
        /// <summary>
        ///  Called when a new port is registered with the platform
        /// </summary>
        public override void PortRegistered(VPort port)
        {
            logger.Log("Sensor:{0} got registeration notification for {1}", ToString(), port.ToString());

            lock (this)
            {
                if (!accessibleSensorPorts.Contains(port) &&
                    GetCapabilityFromPlatform(port) != null &&
                    (Role.ContainsRole(port, RoleSensor.RoleName) || Role.ContainsRole(port, RoleSensorMultiLevel.RoleName)))
                {
                    accessibleSensorPorts.Add(port);

                    logger.Log("Sensor:{0} added port {1}", this.ToString(), port.ToString());

                    if (Role.ContainsRole(port, RoleSensor.RoleName))
                    {
                        if (Subscribe(port, RoleSensor.Instance, RoleSensor.OpGetName))
                        {
                            logger.Log("Sensor:{0} subscribed to sensor port {1}", this.ToString(), port.ToString());
                        }
                        else
                        {
                            logger.Log("Sensor:{0} failed to subscribe to sensor  port {1}", this.ToString(), port.ToString());
                        }
                    }

                    if (Role.ContainsRole(port, RoleSensorMultiLevel.RoleName))
                    {
                        if (Subscribe(port, RoleSensorMultiLevel.Instance, RoleSensorMultiLevel.OpGetName))
                        {
                            logger.Log("Sensor:{0} subscribed to multi-level sensor port {1}", this.ToString(), port.ToString());
                        }
                        else
                        {
                            logger.Log("Sensor: {0} failed to subscribe to multi-level port {1}", this.ToString(), port.ToString());
                        }
                    }
                }
            }
        }
コード例 #2
0
        public override void OnNotification(string roleName, string opName, IList <VParamType> retVals, VPort senderPort)
        {
            string message;

            lock (this)
            {
                switch (opName.ToLower())
                {
                case RoleDummy.OpEchoSubName:
                    int rcvdNum = (int)retVals[0].Value();

                    message = String.Format("async echo response from {0}. rcvd = {1}", senderPort.ToString(), rcvdNum.ToString());
                    this.receivedMessageList.Add(message);
                    break;

                default:
                    message = String.Format("Invalid async operation return {0} from {1}", opName.ToLower(), senderPort.ToString());
                    break;
                }
            }
            logger.Log("{0} {1}", this.ToString(), message);
        }
コード例 #3
0
 public override void OnNotification(string roleName, string opName, IList <VParamType> retVals, VPort senderPort)
 {
     logger.Log("Notitification from {0} for {0}", roleName, opName);
     if (retVals.Count >= 1)
     {
         this.Temperature = (int)retVals[0].Value();
     }
     else
     {
         logger.Log("{0}: got unexpected retvals [{1}] from {2}", ToString(), retVals.Count.ToString(), senderPort.ToString());
     }
 }
コード例 #4
0
        public void SendEchoRequest(VPort port, int counter)
        {
            try
            {
                DateTime requestTime = DateTime.Now;

                var retVals = Invoke(port, RoleDummy.Instance, RoleDummy.OpEchoName, new ParamType(counter));

                double diffMs = (DateTime.Now - requestTime).TotalMilliseconds;

                if (retVals[0].Maintype() != (int)ParamType.SimpleType.error)
                {
                    int rcvdNum = (int)retVals[0].Value();

                    logger.Log("echo success to {0} after {1} ms. sent = {2} rcvd = {3}", port.ToString(), diffMs.ToString(), counter.ToString(), rcvdNum.ToString());
                }
                else
                {
                    logger.Log("echo failure to {0} after {1} ms. sent = {2} error = {3}", port.ToString(), diffMs.ToString(), counter.ToString(), retVals[0].Value().ToString());
                }
            }
            catch (Exception e)
            {
                logger.Log("Error while calling echo request: {0}", e.ToString());
            }
        }
コード例 #5
0
        void InitSwitch(VPort switchPort, SwitchType switchType, bool isColored)
        {
            logger.Log("{0} adding switch {1} {2}", this.ToString(), switchType.ToString(), switchPort.ToString());

            SwitchInfo switchInfo = new SwitchInfo();

            switchInfo.Capability = GetCapability(switchPort, Constants.UserSystem);
            switchInfo.Level      = 0;
            switchInfo.Type       = switchType;

            switchInfo.IsColored = isColored;
            switchInfo.Color     = Color.Black;

            registeredSwitches.Add(switchPort, switchInfo);

            string switchFriendlyName = switchPort.GetInfo().GetFriendlyName();

            switchFriendlyNames.Add(switchFriendlyName, switchPort);

            if (switchInfo.Capability != null)
            {
                IList <VParamType> retVals;

                if (switchType == SwitchType.Multi)
                {
                    retVals = switchPort.Invoke(RoleSwitchMultiLevel.RoleName, RoleSwitchMultiLevel.OpGetName, null,
                                                ControlPort, switchInfo.Capability, ControlPortCapability);

                    switchPort.Subscribe(RoleSwitchMultiLevel.RoleName, RoleSwitchMultiLevel.OpGetName, ControlPort, switchInfo.Capability, ControlPortCapability);

                    if (retVals[0].Maintype() < 0)
                    {
                        logger.Log("SwitchController could not get current level for {0}", switchFriendlyName);
                    }
                    else
                    {
                        switchInfo.Level = (double)retVals[0].Value();
                    }
                }
                else
                {
                    retVals = switchPort.Invoke(RoleSwitchBinary.RoleName, RoleSwitchBinary.OpGetName, null,
                                                ControlPort, switchInfo.Capability, ControlPortCapability);

                    switchPort.Subscribe(RoleSwitchBinary.RoleName, RoleSwitchBinary.OpGetName, ControlPort, switchInfo.Capability, ControlPortCapability);

                    if (retVals[0].Maintype() < 0)
                    {
                        logger.Log("SwitchController could not get current level for {0}", switchFriendlyName);
                    }
                    else
                    {
                        bool boolLevel = (bool)retVals[0].Value();
                        switchInfo.Level = (boolLevel) ? 1 : 0;
                    }
                }
            }
        }
コード例 #6
0
        public override void OnNotification(string roleName, string opName, IList <VParamType> retVals, VPort senderPort)
        {
            //...

            if (opName == RoleSwitchBinary.OpGetName)
            {
                if (retVals.Count >= 1 && retVals[0].Value() != null)
                {
                    bool level = (bool)retVals[0].Value();

                    registeredSwitches[senderPort].Level = (level)? 1 : 0;
                }
                else
                {
                    logger.Log("{0} got bad result for getlevel subscription from {1}", this.ToString(), senderPort.ToString());
                }
            }
        }
コード例 #7
0
ファイル: AppAlerts.cs プロジェクト: RBSystems/LoT
        public override void OnNotification(string roleName, string opName, IList <VParamType> retVals, VPort senderPort)
        {
            if (retVals.Count >= 1)
            {
                byte val = (byte)(int)retVals[0].Value();

                //hack for techfest since we are using a multi-level switch as a doorbell
                //if (RoleSwitchMultiLevel.RoleName.Equals(roleName, StringComparison.CurrentCultureIgnoreCase))
                //    val = 0;

                Alert newAlert = new Alert()
                {
                    TimeTriggered      = DateTime.Now,
                    SensorFriendlyName = senderPort.GetInfo().GetFriendlyName(),
                    SensorLocation     = senderPort.GetInfo().GetLocation().Name(),
                    Value        = val,
                    Acknowledged = false,
                };

                bool notify = //settings.Mode != AlertMode.none &&
                              IsAlertTime() &&
                              !SuppressAlert(newAlert) &&
                              ((RoleSwitchMultiLevel.RoleName.Equals(roleName, StringComparison.CurrentCultureIgnoreCase) && (val == 99 || val == 0)) ||
                               (RoleSensor.RoleName.Equals(roleName, StringComparison.CurrentCultureIgnoreCase) && val == 255));

                logger.Log("{0}: got notified by {1} [{2}] val = {3} notify = {4}\n",
                           this.ToString(), newAlert.SensorFriendlyName, roleName, val.ToString(), notify.ToString());

                if (notify)
                {
                    InsertAlert(newAlert);
                    GenerateMessage(newAlert);
                }
            }
            else
            {
                logger.Log("{0}: got unexpected retvals [{1}] from {2}", ToString(), retVals.Count.ToString(), senderPort.ToString());
            }
        }
コード例 #8
0
ファイル: AppAlerts.cs プロジェクト: RBSystems/LoT
        public override void PortRegistered(VPort port)
        {
            lock (this)
            {
                if (Role.ContainsRole(port, RoleCamera.RoleName))
                {
                    VCapability capability = GetCapability(port, Constants.UserSystem);

                    if (cameraPorts.ContainsKey(port))
                    {
                        cameraPorts[port] = capability;
                    }
                    else
                    {
                        cameraPorts.Add(port, capability);
                    }

                    logger.Log("{0} added camera port {1}", this.ToString(), port.ToString());
                }

                //lets not monitor switches
                //if (Role.ContainsRole(port, RoleSwitchMultiLevel.RoleName))
                //{
                //    if (port.GetInfo().GetFriendlyName().Equals(switchFriendlyName, StringComparison.CurrentCultureIgnoreCase))
                //    {
                //        switchPort = port;
                //        switchPortCapability = GetCapability(port, Constants.UserSystem);

                //        if (switchPortCapability != null)
                //        {
                //            switchPort.Subscribe(RoleSwitchMultiLevel.RoleName, RoleSwitchMultiLevel.OpGetName,
                //                this.ControlPort, switchPortCapability, this.ControlPortCapability);
                //        }
                //    }
                //}

                if (Role.ContainsRole(port, RoleSensor.RoleName))
                {
                    //if (port.GetInfo().GetFriendlyName().Equals(sensorFriendlyName, StringComparison.CurrentCultureIgnoreCase))
                    //{
                    //    sensorPort = port;
                    VCapability capability = GetCapability(port, Constants.UserSystem);

                    if (registeredSensors.ContainsKey(port))
                    {
                        registeredSensors[port] = capability;
                    }
                    else
                    {
                        registeredSensors.Add(port, capability);
                    }

                    if (capability != null)
                    {
                        port.Subscribe(RoleSensor.RoleName, RoleSensor.OpGetName,
                                       this.ControlPort, capability, this.ControlPortCapability);
                    }
                    //}
                }
            }
        }
コード例 #9
0
ファイル: SwitchController.cs プロジェクト: RBSystems/LoT
        public override void OnNotification(string roleName, string opName, IList <VParamType> retVals, VPort senderPort)
        {
            lock (this)
            {
                //check if notification is speech event
                if (roleName.Contains(RoleSpeechReco.RoleName) && opName.Equals(RoleSpeechReco.OpPhraseRecognizedSubName))
                {
                    string rcvdCmd = (string)retVals[0].Value();

                    switch (rcvdCmd)
                    {
                    case "ALLON":
                        SetAllSwitches(1.0);
                        break;

                    case "ALLOFF":
                        SetAllSwitches(0.0);
                        break;

                    case "PLAYMOVIE":
                        SetAllSwitches(0.1);
                        break;

                    case "DISCO":
                        DiscoSwitches();
                        break;
                    }
                    return;
                }

                if (!registeredSwitches.ContainsKey(senderPort))
                {
                    throw new Exception("Got notification from an unknown port " + senderPort.ToString());
                }

                switch (opName)
                {
                case RoleSwitchBinary.OpGetName:
                {
                    if (retVals.Count >= 1 && retVals[0].Value() != null)
                    {
                        bool level = (bool)retVals[0].Value();

                        registeredSwitches[senderPort].Level = (level)? 1 : 0;
                    }
                    else
                    {
                        logger.Log("{0} got bad result for getlevel subscription from {1}", this.ToString(), senderPort.ToString());
                    }
                }
                break;

                case RoleSwitchMultiLevel.OpGetName:
                {
                    if (retVals.Count >= 1 && retVals[0].Value() != null)
                    {
                        double level = (double)retVals[0].Value();

                        registeredSwitches[senderPort].Level = level;
                    }
                    else
                    {
                        logger.Log("{0} got bad result for getlevel subscription from {1}", this.ToString(), senderPort.ToString());
                    }
                }
                break;

                case RoleLightColor.OpGetName:
                {
                    if (!registeredSwitches[senderPort].IsColored)
                    {
                        logger.Log("Got {0} for non-colored switch {1}", opName, senderPort.ToString());

                        return;
                    }

                    if (retVals.Count >= 3)
                    {
                        byte red, green, blue;

                        red   = Math.Min(Math.Max((byte)(int)retVals[0].Value(), (byte)0), (byte)255);
                        green = Math.Min(Math.Max((byte)(int)retVals[1].Value(), (byte)0), (byte)255);
                        blue  = Math.Min(Math.Max((byte)(int)retVals[2].Value(), (byte)0), (byte)255);

                        registeredSwitches[senderPort].Color = Color.FromArgb(red, green, blue);
                    }
                    else
                    {
                        logger.Log("{0} got bad result for getlevel subscription from {1}", this.ToString(), senderPort.ToString());
                    }
                }
                break;

                default:
                    logger.Log("Got notification from incomprehensible operation: " + opName);
                    break;
                }
            }
        }
コード例 #10
0
ファイル: SwitchController.cs プロジェクト: RBSystems/LoT
        /// <summary>
        ///  Called when a new port is registered with the platform
        /// </summary>
        /// <param name="port"></param>
        public override void PortRegistered(VPort port)
        {
            lock (this)
            {
                if (Role.ContainsRole(port, RoleSwitchMultiLevel.RoleName) ||
                    Role.ContainsRole(port, RoleSwitchBinary.RoleName) ||
                    Role.ContainsRole(port, RoleLightColor.RoleName))
                {
                    if (!registeredSwitches.ContainsKey(port) &&
                        GetCapabilityFromPlatform(port) != null)
                    {
                        var switchType = (Role.ContainsRole(port, RoleSwitchMultiLevel.RoleName)) ? SwitchType.Multi : SwitchType.Binary;

                        bool colored = Role.ContainsRole(port, RoleLightColor.RoleName);

                        InitSwitch(port, switchType, colored);
                    }
                }

                else if (Role.ContainsRole(port, RoleSpeechReco.RoleName))
                {
                    if (!speechPorts.Contains(port) &&
                        GetCapabilityFromPlatform(port) != null)
                    {
                        speechPorts.Add(port);

                        logger.Log("SwitchController:{0} added speech port {1}", this.ToString(), port.ToString());


                        //TODO Call it with phrases we care about - FOR NOW HARD CODED in Kinect driver
                        //  var retVal = Invoke(port, RoleSpeechReco.Instance, RoleSpeechReco.OpSetSpeechPhraseName, new ParamType(ParamType.SimpleType.text, "on"));

                        //subscribe to speech reco
                        if (Subscribe(port, RoleSpeechReco.Instance, RoleSpeechReco.OpPhraseRecognizedSubName))
                        {
                            logger.Log("{0} subscribed to port {1}", this.ToString(), port.ToString());
                        }
                    }
                }
            }
        }
コード例 #11
0
        public override void OnNotification(string roleName, string opName, IList <VParamType> retVals, VPort senderPort)
        {
            string message;

            lock (this)
            {
                switch (opName.ToLower())
                {
                case "echosub":
                    string rcvdData = (string)retVals[0].Value();
                    irDataList.Add(rcvdData);
                    //ProcessData(rcvdData);
                    message = String.Format("async echo response from {0}. rcvd = {1}", senderPort.ToString(), rcvdData.ToString());
                    this.receivedMessageList.Add(message);
                    break;

                default:
                    message = String.Format("Invalid async operation return {0} from {1}", opName.ToLower(), senderPort.ToString());
                    break;
                }
            }
            //logger.Log("{0} {1}", this.ToString(), message);
        }
コード例 #12
0
ファイル: DigitalMedia.cs プロジェクト: RBSystems/LoT
        public override void OnNotification(string roleName, string opName, IList <VParamType> retVals, VPort senderPort)
        {
            string message = string.Empty;

            lock (this)
            {
                bool isSignalR = (this.Connection != null && this.Connection.State == ConnectionState.Connected);

                switch (opName.ToLower())
                {
                case RoleSignalDigital.OnDigitalEvent:

                    int  slot  = (int)retVals[0].Value();
                    int  join  = (int)retVals[1].Value();
                    bool value = (bool)retVals[2].Value();

                    if (isSignalR && this.HubProxy != null)
                    {
                        this.HubProxy.Invoke("OnDigitalEvent", slot, join, value);
                    }

                    if (this.azureEventHub != null)
                    {
                        this.azureEventHub.SendEvents(RoleSignalDigital.OnDigitalEvent, slot, join, value, string.Empty);
                    }


                    message = String.Format("async OnDigitalEvent from {0}. slot = {1} join={2} value = {3}", senderPort.ToString(), slot, join, value);
                    // this.receivedMessageList.Add(message);
                    break;

                case RoleSignalDigital.OnConnectEvent:

                    if (isSignalR)
                    {
                        this.HubProxy.Invoke("OnConnectEvent", retVals);
                    }

                    message = String.Format("async OnConnectEvent from {0}.", senderPort.ToString());
                    // this.receivedMessageList.Add(message);
                    if (this.azureEventHub != null)
                    {
                        this.azureEventHub.SendEvents(RoleSignalDigital.OnConnectEvent, -1, -1, false, senderPort.ToString());
                    }

                    break;

                case RoleSignalDigital.OnDisconnectEvent:

                    if (isSignalR)
                    {
                        this.HubProxy.Invoke("OnDisconnectEvent", retVals);
                    }

                    message = String.Format("async OnDisconnectEvent from {0}. DisconnectReasonMessage = {1}", retVals[0].Value());

                    if (this.azureEventHub != null)
                    {
                        this.azureEventHub.SendEvents(RoleSignalDigital.OnDisconnectEvent, -1, -1, false, retVals[0].Value().ToString());
                    }
                    // this.receivedMessageList.Add(message);
                    break;

                case RoleSignalDigital.OnErrorEvent:

                    if (isSignalR)
                    {
                        this.HubProxy.Invoke("OnErrorEvent", retVals);
                    }


                    message = string.Empty;
                    if (retVals != null && retVals.Count > 0)
                    {
                        message = String.Format("async OnErrorEvent from {0}. ErrorMessage = {1}", retVals[0].Value());
                    }

                    if (this.azureEventHub != null)
                    {
                        this.azureEventHub.SendEvents(RoleSignalDigital.OnErrorEvent, -1, -1, false, retVals[0].Value().ToString());
                    }

                    break;

                default:
                    message = String.Format("Invalid async operation return {0} from {1}", opName.ToLower(), senderPort.ToString());

                    if (this.azureEventHub != null)
                    {
                        this.azureEventHub.SendEvents(RoleSignalDigital.OnErrorEvent, -1, -1, false, message);
                    }

                    break;
                }
            }
            logger.Log("{0} {1}", this.ToString(), message);
        }
コード例 #13
0
ファイル: ModuleBase.cs プロジェクト: dhakalsamip/LoT
        /// <summary>
        /// Called from the platform to install a new capability for a port that is owned by this module
        /// </summary>
        /// <param name="capability">The capability to install</param>
        /// <param name="targetPort">The port on which to install the capability</param>
        /// <returns></returns>
        public sealed override int InstallCapability(VCapability capability, VPort targetPort)
        {
            ResultCode resultCode;

            if (!IsMyPort(targetPort))
            {
                logger.Log("{0} got InstallCapability request for somemeone else's port {1}", targetPort.ToString());

                resultCode = ResultCode.PortNotFound;
            }
            else
            {
                Port port = (Port)targetPort;
                port.AddCapability(capability);

                resultCode = ResultCode.Success;
            }

            return((int)resultCode);
        }