int_32  Shell_hvac(int_32 argc, char_ptr argv[] )
{
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc > 2) {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else {
         if (argc == 2) {
            if (strcmp(argv[1],"off")==0) {
               HVAC_SetHVACMode(HVAC_Off);
            } else if (strcmp(argv[1],"cool")==0) {
               HVAC_SetHVACMode(HVAC_Cool);
            } else if (strcmp(argv[1],"heat")==0) {
               HVAC_SetHVACMode(HVAC_Heat);
            } else if (strcmp(argv[1],"auto")==0) {
               HVAC_SetHVACMode(HVAC_Auto);
            } else {
               printf("Invalid hvac mode specified\n");
            } 
         }

         printf("HVAC mode is %s\n", HVAC_HVACModeName(HVAC_GetHVACMode()));
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s [<mode>]\n", argv[0]);
      } else  {
         printf("Usage: %s [<mode>]\n", argv[0]);
         printf("   <mode> = off, cool, heat or auto\n");
      }
   }
   return return_code;
} 
Beispiel #2
0
void Switch_Poll(void) 
{
   HVAC_Input_t   input;

   // Save previous input states
   for (input=(HVAC_Input_t)0;input<HVAC_MAX_INPUTS;input++) {
      LastInputState[input]=InputState[input];
      InputState[input]=HVAC_GetInput(input);
   }

   // Check each input for a low-high transition (button press)
   if (InputState[HVAC_TEMP_UP_INPUT]) {
      if (!LastInputState[HVAC_TEMP_UP_INPUT] && !InputState[HVAC_TEMP_DOWN_INPUT]) {
         if (HVAC_GetDesiredTemperature() < HVAC_ConvertCelsiusToDisplayTemp(HVAC_TEMP_MAXIMUM - HVAC_TEMP_SW_DELTA)) 
         {
            HVAC_SetDesiredTemperature(HVAC_GetDesiredTemperature()+HVAC_TEMP_SW_DELTA);
         }
      }
   } else if (InputState[HVAC_TEMP_DOWN_INPUT] && !LastInputState[HVAC_TEMP_DOWN_INPUT] ) {
      if (HVAC_GetDesiredTemperature() > HVAC_ConvertCelsiusToDisplayTemp(HVAC_TEMP_MINIMUM + HVAC_TEMP_SW_DELTA)) 
      {
         HVAC_SetDesiredTemperature(HVAC_GetDesiredTemperature()-HVAC_TEMP_SW_DELTA);
      }
   }

   if (InputState[HVAC_FAN_ON_INPUT] & !LastInputState[HVAC_FAN_ON_INPUT] ) {
      HVAC_SetFanMode(HVAC_GetFanMode()==Fan_On?Fan_Automatic:Fan_On);
   }

   if (InputState[HVAC_HEAT_ON_INPUT] & !LastInputState[HVAC_HEAT_ON_INPUT] ) {
      HVAC_SetHVACMode(HVAC_Heat);
   } else if (InputState[HVAC_AC_ON_INPUT] & !LastInputState[HVAC_AC_ON_INPUT] ) {
      HVAC_SetHVACMode(HVAC_Cool);
   } else if (LastInputState[HVAC_HEAT_ON_INPUT] | LastInputState[HVAC_AC_ON_INPUT]) {
      HVAC_SetHVACMode(HVAC_Off);
   }

   HVAC_ReadAmbientTemperature();
}
Beispiel #3
0
_mqx_int cgi_hvac_output(HTTPD_SESSION_STRUCT *session) {
    uint_32  len = 0;
    char     hvac[10], unit[10], fan[10], t[40];
    uint_32  temp,temp_fract=0;
    boolean  bParams = FALSE; 
    char buffer[100];

    session->response.contenttype = CONTENT_TYPE_HTML;
    httpd_sendhdr(session, 0, 0);

    httpd_sendstr(session->sock, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"
        "<html><head><title>HVAC Settings response</title>"
        "<meta http-equiv=\"REFRESH\" content=\"0;url=hvac.html\"></head>\n<body>\n");

//  html_link(session->sock,"Home","index.cgi");
//  html_link(session->sock,"HVAC Status","hvac.cgi");
//  html_link(session->sock,"HVAC Settings","hvac_input.cgi");
    //html_link(session->sock,"HVAC Log","hvac_log.txt");
    
    httpd_sendstr(session->sock, "<br><br>\n");
    
    if (session->request.content_len) {
        len = session->request.content_len;
        len = httpd_read(session, buffer, (int)((len > sizeof(buffer)) ? sizeof(buffer) : len));
        buffer[len] = 0;
        session->request.content_len -= len;
        len = 0;
        
        if (httpd_get_varval(session, buffer, "hvac", hvac, sizeof(hvac)) &&
            httpd_get_varval(session, buffer, "unit", unit, sizeof(unit)) &&
            httpd_get_varval(session, buffer, "temp", t, sizeof(t)) &&
            httpd_get_varval(session, buffer, "fan", fan, sizeof(fan))) {
            
            bParams =  TRUE;
         
            if (strcmp(hvac,"heat") == 0) {
                HVAC_SetHVACMode(HVAC_Heat);
            }
            else if (strcmp(hvac,"cool") == 0) {
                HVAC_SetHVACMode(HVAC_Cool);
            }
            else {
                HVAC_SetHVACMode(HVAC_Off);
            }
            
            if (strcmp(unit,"f") == 0)
                HVAC_SetTemperatureScale(Fahrenheit);
            else
                HVAC_SetTemperatureScale(Celsius);
         

            if (strcmp(fan,"auto") == 0) {
                HVAC_SetFanMode(Fan_Automatic);
            }
            else {
                HVAC_SetFanMode(Fan_On);
            }
        

        
            if (sscanf(t, "%d.%d", &temp, &temp_fract) >= 1) {
                if (temp_fract<10) {
                    HVAC_SetDesiredTemperature(temp * 10 + temp_fract);
                }
            }
        }
    }
  
   
    if (!bParams) {
        httpd_sendstr(session->sock, "No parameters received.<br>\n");
    }
    
    httpd_sendstr(session->sock, "</body></html>");
    return session->request.content_len;
}
Beispiel #4
0
_mqx_int cgi_hvac_output(HTTPSRV_CGI_REQ_STRUCT* param)
{
    
    uint_32  len = 0;
    char     hvac[10];
    char     unit[10];
    char     fan[10];
    char     t[40];
    uint_32  temp = 0;
    uint_32  temp_fract = 0;
    boolean  bParams = FALSE; 
    char     buffer[100];
    HTTPSRV_CGI_RES_STRUCT response;
    
    if (param->request_method != HTTPSRV_REQ_POST)
    {
        return(0);
    }
    
    len = param->content_length;
    len = HTTPSRV_cgi_read(param->ses_handle, buffer, (len > sizeof(buffer)) ? sizeof(buffer) : len);
    
    if (param->content_length)
    {
        buffer[len] = 0;
        param->content_length -= len;
        len = 0;
        
        if (hvac_get_varval(buffer, "hvac", hvac, sizeof(hvac)) &&
            hvac_get_varval(buffer, "unit", unit, sizeof(unit)) &&
            hvac_get_varval(buffer, "temp", t, sizeof(t)) &&
            hvac_get_varval(buffer, "fan", fan, sizeof(fan))) {
            
            bParams =  TRUE;
         
            if (strcmp(hvac,"heat") == 0)
            {
                HVAC_SetHVACMode(HVAC_Heat);
            }
            else if (strcmp(hvac,"cool") == 0)
            {
                HVAC_SetHVACMode(HVAC_Cool);
            }
            else
            {
                HVAC_SetHVACMode(HVAC_Off);
            }
            
            if (strcmp(unit,"f") == 0)
            {
                HVAC_SetTemperatureScale(Fahrenheit);
            }
            else
            {
                HVAC_SetTemperatureScale(Celsius);
            }
            if (strcmp(fan,"auto") == 0)
            {
                HVAC_SetFanMode(Fan_Automatic);
            }
            else
            {
                HVAC_SetFanMode(Fan_On);
            }
        
            if (sscanf(t, "%d.%d", &temp, &temp_fract) >= 1)
            {
                if (temp_fract<10)
                {
                    HVAC_SetDesiredTemperature(temp * 10 + temp_fract);
                }
            }
        }
    }
    response.ses_handle = param->ses_handle;
    response.content_type = HTTPSRV_CONTENT_TYPE_HTML;
    response.status_code = 200;
    response.data = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"
        "<html><head><title>HVAC Settings response</title>"
        "<meta http-equiv=\"REFRESH\" content=\"0;url=hvac.shtml\"></head>\n<body>\n";
    response.data_length = strlen(response.data);
    response.content_length = 0;
    HTTPSRV_cgi_write(&response);
    
    if (!bParams)
    {
        response.data = "No parameters received.<br>\n";
        response.data_length = strlen(response.data);
        HTTPSRV_cgi_write(&response);
    }
    response.data = "<br><br>\n</body></html>";
    response.data_length = strlen(response.data);
    HTTPSRV_cgi_write(&response);    
    return (response.content_length);
}