Esempio n. 1
0
        /// <summary>
        /// Add a sensor with the remote self instance, agents may now subscribe to this
        /// sensor and OnStart() will be invoked automatically by this framework.
        /// </summary>
        /// <param name="a_Sensor">The sensor object to add.</param>
        /// <param name="a_bOverride">If true, then any remote sensor with the same name will be overridden.</param>
        public void AddSensor(ISensor a_Sensor, bool a_bOverride)
        {
            if (!m_Sensors.ContainsKey(a_Sensor.GetSensorId()))
            {
                Dictionary <string, object> register = new Dictionary <string, object>();
                register["event"]       = "add_sensor_proxy";
                register["sensorId"]    = a_Sensor.GetSensorId();
                register["name"]        = a_Sensor.GetSensorName();
                register["data_type"]   = a_Sensor.GetDataType();
                register["binary_type"] = a_Sensor.GetBinaryType();
                register["override"]    = a_bOverride;

                TopicClient.Publish("sensor-manager", Json.Serialize(register));
                m_Sensors[a_Sensor.GetSensorId()]   = a_Sensor;
                m_Overrides[a_Sensor.GetSensorId()] = a_bOverride;

                Log.Status("SensorManager", "Sensor {0} added.", a_Sensor.GetSensorId());
            }
        }
Esempio n. 2
0
        void OnConnected()
        {
            if (m_bDisconnected)
            {
                // re-register all our sensors on reconnect.
                foreach (var kv in m_Sensors)
                {
                    string  sensorId = kv.Key;
                    ISensor sensor   = kv.Value;

                    Dictionary <string, object> register = new Dictionary <string, object>();
                    register["event"]       = "add_sensor_proxy";
                    register["sensorId"]    = sensor.GetSensorId();
                    register["name"]        = sensor.GetSensorName();
                    register["data_type"]   = sensor.GetDataType();
                    register["binary_type"] = sensor.GetBinaryType();
                    register["override"]    = m_Overrides[sensorId];

                    TopicClient.Publish("sensor-manager", Json.Serialize(register));
                    Log.Status("SensorManager", "Sensor {0} restored.", sensor.GetSensorId());
                }
                m_bDisconnected = false;
            }
        }