public CommandInfoModel(List <string> commandType, List <string> commandText, BaseActuator humidifier, BaseActuator waterPump, BaseActuator airCooler)
        {
            CommandText = commandText;
            CommandType = commandType;

            Humidifier = humidifier;
            WaterPump  = waterPump;
            AirCooler  = airCooler;
        }
示例#2
0
        private JsonResult PutRequest(BaseActuator actuator, string parameter, SetCommandParameterModel data)
        {
            Console.WriteLine("Received PUT request with payload:");
            Console.WriteLine(JsonConvert.SerializeObject(data));

            ModifyData(actuator, parameter, data.Value);

            return(new JsonResult(
                       new
            {
                message = "Parameter set!"
            }
                       ));
        }
示例#3
0
        private void ModifyData(BaseActuator actuator, string parameter, float value)
        {
            switch (parameter)
            {
            case "OFFSET":
                actuator.Offset = value;
                break;

            case "MIN":
                actuator.MinValue = value;
                break;

            case "MAX":
                actuator.MaxValue = value;
                break;

            default:
                break;
            }
        }
示例#4
0
 private string GetActuatorCommandParameters(BaseActuator actuator)
 {
     return(JsonConvert.SerializeObject(actuator));
 }
示例#5
0
        private Response getResponseValues(int sensorId, string commandText, string commandType, float value)
        {
            string json = null;

            BaseActuator actuator = null;

            if (!goodCommandFormat(commandText, commandType))
            {
                return(new Response("Bad command format!", "Command not recognized", false, ""));
            }

            string requestUri = determineRequestUri(commandText, commandType);

            float offset = 0;

            switch (commandType)
            {
            case "HUMIDIFIER":
                actuator = humidifier;
                break;

            case "AIRCOOLER":
                actuator = airCooler;
                break;

            case "WATERPUMP":
                actuator = waterPump;
                break;

            default:
                break;
            }

            offset = actuator.Offset;

            switch (commandText)
            {
            case "ON":
            case "OFF":
                bool actuatorOn = false;
                if (commandText.Equals("ON"))
                {
                    actuatorOn = true;
                }
                else if (commandText.Equals("OFF"))
                {
                    actuatorOn = false;
                }

                json = JsonConvert.SerializeObject(new TurnOnOrOffCommandModel(sensorId, actuatorOn));
                break;

            case "DECREASE":
            case "INCREASE":
                if (commandText == "DECREASE")
                {
                    offset *= -1;
                }
                if (!actuator.valueInBounds(value))
                {
                    return(new Response("New value not in [MIN, MAX] bounds", "Command not sent (new value out of bounds)", false, ""));
                }
                json = JsonConvert.SerializeObject(new AddOffsetCommandModel(sensorId, offset));
                break;

            case "SET":
                json = JsonConvert.SerializeObject(new SetValueCommandModel(sensorId, value));
                break;

            default:
                break;
            }
            return(new Response("Command OK!", json, true, requestUri));
        }