Esempio n. 1
0
        protected void addProxySensor(SensorCore sensor, bool replace)
        {
            if ((replace) && (dictSensors.ContainsKey(sensor.Id)))
            {
                dictSensors.Remove(sensor.Id);
            }

            //_logger.LogDebug("Adding Proxy sensor Id='{0}', NodeId='{1}', Activated='{2}'", sensor.Id, sensor.NodeId, sensor.Activated);
            dictSensors.Add(sensor.Id, sensor);
        }
Esempio n. 2
0
        void callbackStateMessageHandler(object sender, BasicDeliverEventArgs eventArgs)
        {
            var body    = eventArgs.Body;
            var message = Encoding.UTF8.GetString(body);

            Console.WriteLine(" State Message Arrived: {0}", message);
            SensorStateMessage ssm    = MessageCore.fromJSON <SensorStateMessage>(message);
            SensorCore         sensor = getSensorByName(ssm.Id);

            ((SensorProxy)sensor).setTriggeredState(ssm.Triggered);
        }
Esempio n. 3
0
        void callbackControlMessageHandler(object sender, BasicDeliverEventArgs eventArgs)
        {
            var body    = eventArgs.Body;
            var message = Encoding.UTF8.GetString(body);

            Console.WriteLine(" Control Message Request Arrived: {0}", message);
            MessageControl mc = MessageCore.fromJSON <MessageControl>(message);

            if (mc.Request == ControlRequest.REQUEST_CONFIG)
            {
                foreach (KeyValuePair <String, SensorCore> kvp in dictSensors)
                {
                    SensorCore sc = kvp.Value;
                    if (sc.NodeId == mc.Id)
                    {
                        //Publish sensor config to Client
                        PublishClientConfig(sc.getConfig <ConfigSensor>());
                    }
                }
            }
        }
Esempio n. 4
0
    // METHODS ------------------------------------------------------------------------------------

    #region Monobehaviour

    private void Awake()
    {
        if (Main != null)
        {
            Destroy(gameObject);
            return;
        }

        Main = this;
        Debug.Log("<color='blue'>SensorCore</color>: Set <i>" + this.name +
                  "</i> as Main sensor. Set to <b>" +
                  ((destroyAfterScene) ? "destroy" : "persist") +
                  "</b> on scene end.");

        if (!destroyAfterScene)
        {
            DontDestroyOnLoad(this);
        }

        if (autoConnectOnAwake)
        {
            Debug.Log("<color='blue'>SensorCore</color>: Attempting autoConnect...");
            if (portName == null || portName.Length == 0)
            {
                portName = GuessPortName();
            }

            try
            {
                Connect();
            }
            catch (System.Exception e)
            {
                Debug.Log("<color='blue'>SensorCore</color>: <color='red'>FAIL</color> " +
                          "Unable to open serial port " + portName + ".\n" + e);
            }
        }
    }
Esempio n. 5
0
 public SensorLink(SensorCore source, AlarmZone target, IManager manager) : base(manager)
 {
     source.addLink(OnSensorTriggeredEvent);
     this.sensor    = source;
     this.alarmZone = target;
 }