Exemplo n.º 1
0
        private SensorData ConvertSensorData(SensorData oldData, SensorDataType? newDataType)
        {
            SensorData newData=new SensorData(newDataType,oldData.state);
            SensorDataType oldDataType = oldData.dataType.Value;

            //convert binary to percentage
            if ((oldDataType == SensorDataType.V_STATUS ||
                 oldDataType == SensorDataType.V_LIGHT ||
                 oldDataType == SensorDataType.V_ARMED ||
                 oldDataType == SensorDataType.V_TRIPPED ||
                 oldDataType == SensorDataType.V_LOCK_STATUS)
                &&
                (newDataType == SensorDataType.V_PERCENTAGE ||
                 newDataType == SensorDataType.V_DIMMER ||
                 newDataType == SensorDataType.V_LIGHT_LEVEL))
            {
                if (oldData.state == "0")
                    newData.state = "0";
                else
                    newData.state = "100";
            }

            //convert  percentage to binary
            if ((newDataType == SensorDataType.V_STATUS ||
                 newDataType == SensorDataType.V_LIGHT ||
                 newDataType == SensorDataType.V_ARMED ||
                 newDataType == SensorDataType.V_TRIPPED ||
                 newDataType == SensorDataType.V_LOCK_STATUS)
                &&
                (oldDataType == SensorDataType.V_PERCENTAGE ||
                 oldDataType == SensorDataType.V_DIMMER ||
                 oldDataType == SensorDataType.V_LIGHT_LEVEL))
            {
                if (oldData.state == "0")
                    newData.state = "0";
                else
                    newData.state = "1";
            }

            return newData;
        }
Exemplo n.º 2
0
        public void SendSensorData(int sensorId, SensorData data)
        {
            if (!IsConnected() || !IsPresentationCompleted()) return;

            Message message = new Message
            {
                nodeId = node.nodeId,
                sensorId = sensorId,
                messageType = MessageType.C_SET,
                ack = false,
                subType = (int)data.dataType,
                payload = data.state
            };

            if (OnDebugTxRxMessage != null)
                OnDebugTxRxMessage(message.ToString());

            client.SendMessage(message);
        }
Exemplo n.º 3
0
        public void AddOrUpdateData(SensorDataType dataType, string state)
        {
            List<SensorData> dataList = GetAllData();
            if (dataList == null)
                dataList = new List<SensorData>();

            SensorData data = dataList.FirstOrDefault(x => x.dataType == dataType);

            if (data == null)
            {
                data = new SensorData(dataType, state);
                dataList.Add(data);
            }
            else data.state = state;

            sensorDataJson = JsonConvert.SerializeObject(dataList);
        }
Exemplo n.º 4
0
 public void AddOrUpdateData(SensorData newData)
 {
     AddOrUpdateData(newData.dataType.Value, newData.state);
 }
Exemplo n.º 5
0
 public static void SendColor( Color color)
 {
     SensorData data = new SensorData(nodeId, sensorId,SensorDataType.V_RGB, ColorToHex(color));
     if (softNode.IsPresentationCompleted())
     {
         softNode.SendSensorData(sensorId, data);
         CalculateMessagesPerSec();
     }
 }
Exemplo n.º 6
0
        public void SendSensorState(int nodeId, int sensorId, SensorData data)
        {
            data.dateTime = DateTime.Now;

            Sensor sensor = GetNode(nodeId).GetSensor(sensorId);
            sensor.AddOrUpdateData(data);

            Message message = new Message();
            message.ack = false;
            message.messageType = MessageType.C_SET;
            message.nodeId = nodeId;
            message.payload = data.state;
            message.sensorId = sensorId;
            message.subType = (int)data.dataType;
            message.isValid = true;
            SendMessage(message);

            if (OnSensorUpdatedEvent != null)
                OnSensorUpdatedEvent(sensor);
        }