Is there a reason why I cant change the time value from a cgi function?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Is there a reason why I cant change the time value from a cgi function?

Jump to solution
4,187 Views
MQXuser
Contributor III

I am using the following code to change the time value in a cgi function but the webserver stops working after i call the function. Any clues about why is this happening?

 

 

    TIME_STRUCT  MQX_time;
    DATE_STRUCT  DateStruct;
   
    DateStruct.YEAR = year;
    DateStruct.MONTH = month;
    DateStruct.DAY = day;
    DateStruct.HOUR = hour;
    DateStruct.MINUTE = minute;
    DateStruct.SECOND = second;
    DateStruct.MILLISEC = millisec;

 _time_from_date(&DateStruct, &MQX_time);//Convierte la fecha a tiempo MQX
 _time_set (&MQX_time); //Actualiza el tiempo MQX con la fecha actual
 _rtc_sync_with_mqx ( FALSE ); //Sincroniza RTC con MQX (MQX es la Fuente)

 

 

 

0 Kudos
Reply
1 Solution
2,505 Views
MQXuser
Contributor III

I stopped messing with MQX_time and used another time structure. Things are going fine for now.

View solution in original post

0 Kudos
Reply
10 Replies
2,505 Views
PetrL
NXP Employee
NXP Employee

I can see any issue in your code. In this type of problem I would check task stack usage (in TAD) and eather increase it or try to save space on stack.. 

 

 

PetrL

 

0 Kudos
Reply
2,505 Views
MQXuser
Contributor III

I which task would you increase the stack?

If it is a task created into an MQX library, could you mention the file where I can define the stack?

0 Kudos
Reply
2,505 Views
JuroV
NXP Employee
NXP Employee
This can be set with ___DEFAULT_INTERRUPT_STACK_SIZE in lcf (linker) file.
0 Kudos
Reply
2,505 Views
JuroV
NXP Employee
NXP Employee

For task stack, to increase the stack size, you can do that in task template list.

Use TAD, break the running code in the CGI handler and look in which task's context the handler is running. Increase the stack size for that task (or for interrupts).

0 Kudos
Reply
2,505 Views
MQXuser
Contributor III

Thank you for your answer, I have increased the stack size for http_server task (because it had the higher usage percentage)as well as for interrupt stack.

Problem is still present.

I dont think problem comes from stack overflow,  I have tested my functions in other tasks and everything works fine.

Is there a restriction for changing the mqx time from a cgi function?

0 Kudos
Reply
2,505 Views
PetrM
Senior Contributor I

Yes, it looks like httpd sessions rely on actual MQX time. I guess this is good point of further improvement. As a workaround, please try to redefine macro in httpd_mqx.h like this:

 

#define HTTPD_GET_TIME(time)   _time_get_elapsed(time)

 

0 Kudos
Reply
2,505 Views
MQXuser
Contributor III
Changing the macro is not working for me (I've changed the macro and recompiled the libraries).
All the application hangs as soon as the MQX time changes(I have plenty of other tasks and all of them stop working).
I noticed that if I change MQX_time for a time not very far from the original time, everything works okay.
Does anybody see a solution to this problem? How to change MQX_time using ethernet?
0 Kudos
Reply
2,506 Views
MQXuser
Contributor III

I stopped messing with MQX_time and used another time structure. Things are going fine for now.

0 Kudos
Reply
2,505 Views
JuroV
NXP Employee
NXP Employee
Nothing obvious, please post the whole CGI handler.
0 Kudos
Reply
2,505 Views
MQXuser
Contributor III

Thank you for your answer.

 

Everything works when the  setTimeFromDate function is not called.

setTimeFromDate(ianio, imes, idia, ihora, iminuto, 0, 0);

void setTimeFromDate(uint_16 year, uint_16 month, uint_16 day, uint_16 hour,
                       uint_16 minute, uint_16 second, uint_16 millisec){
    TIME_STRUCT  MQX_time;
    DATE_STRUCT  DateStruct;
   
    DateStruct.YEAR = year;
    DateStruct.MONTH = month;
    DateStruct.DAY = day;
    DateStruct.HOUR = hour;
    DateStruct.MINUTE = minute;
    DateStruct.SECOND = second;
    DateStruct.MILLISEC = millisec;

 _time_from_date(&DateStruct, &MQX_time);//Convierte la fecha a tiempo MQX
 _time_set (&MQX_time); //Actualiza el tiempo MQX con la fecha actual
 _rtc_sync_with_mqx ( FALSE ); //Sincroniza RTC con MQX (MQX es la Fuente)
}



 

 

int cgi_modificar_tiempo(HTTPD_SESSION_STRUCT *session) {
 uint_32  len = 0,index=0;
 char     hora[5], minuto[5], dia[5], mes[5], anio[5];
 uint_32   ihora, iminuto, idia, imes, ianio;
 boolean  bParams = FALSE;
 char buffer[100];

 html_head(session->sock,"HVAC Settings response");

 httpd_sendstr(session->sock, "<BODY>\n");

 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, "hora", hora, sizeof(hora)) &&
    httpd_get_varval(session, buffer, "minuto", minuto, sizeof(minuto)) &&
    httpd_get_varval(session, buffer, "dia", dia, sizeof(dia)) &&   
    httpd_get_varval(session, buffer, "mes", mes, sizeof(mes)) &&
    httpd_get_varval(session, buffer, "anio", anio, sizeof(anio))
    ){
  
   bParams =  TRUE;
            if( !PasswordOK() ){
          rclave_ing = "Es necesario ingresar la palabra clave para utilizar esta funcion";
       httpd_sendstr(session->sock,
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"
    "<html><head><title>MQX</title>"
    "<meta http-equiv=\"REFRESH\" content=\"0;url=resultado.html\"></HEAD>"
    "<BODY></BODY></HTML>");
            }
            else{
             if (  (sscanf(hora, "%d", &ihora) == 1  ) && (sscanf(minuto, "%d", &iminuto) == 1  )                      && (sscanf(dia, "%d", &idia) == 1  ) &&
                   (sscanf(mes, "%d", &imes) == 1  ) && (sscanf(anio, "%d", &ianio) == 1  )  ) {
                  setTimeFromDate(ianio, imes, idia, ihora, iminuto, 0, 0);
                rclave_ing = "Se ha modificado la fecha correctamente";
       httpd_sendstr(session->sock,
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"
    "<html><head><title>MQX</title>"
    "<meta http-equiv=\"REFRESH\" content=\"0;url=resultado.html\"></HEAD>"
    "<BODY></BODY></HTML>");
          }
          else{
           bParams = FALSE;
          }
            }
     }
    }

 if (!bParams) {
  httpd_sendstr(session->sock, "No se recibieron los parametros<br>\n");
 }

 return session->request.content_len;
}

 

 

 

I have called the function  setTimeFromDate(2009, 11, 23, 10, 30, 0, 0);  with constant numbers

and the webserver stops working too.

 

 

Thank you.

 

 

0 Kudos
Reply