00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #include "uip.h"
00049 #include "psock.h"
00050 #include "httpd.h"
00051 #include "httpd-cgi.h"
00052 #include "httpd-fs.h"
00053 #inclide "http_func.h"
00054
00055 #include "../mprintf/mprintf.h"
00056 #include <string.h>
00057 #include <stdio.h>
00058
00059 HTTPD_CGI_CALL(temp, "tag-temp", cgitemperature );
00060 HTTPD_CGI_CALL(setp, "tag-setpoint", cgisetpoint );
00061 HTTPD_CGI_CALL(estad, "tag-estado", cgiestado );
00062
00063
00064 static const struct httpd_cgi_call *calls[] = { &temp, &setp, &estad, NULL };
00065
00066
00067 static
00068 PT_THREAD(nullfunction(struct httpd_state *s, char *ptr))
00069 {
00070 PSOCK_BEGIN(&s->sout);
00071 PSOCK_END(&s->sout);
00072 }
00073
00074 httpd_cgifunction
00075 httpd_cgi(char *name)
00076 {
00077 const struct httpd_cgi_call **f;
00078
00079
00080 for(f = calls; *f != NULL; ++f) {
00081 if(strncmp((*f)->name, name, strlen((*f)->name)) == 0) {
00082 return (*f)->function;
00083 }
00084 }
00085 return nullfunction;
00086 }
00087 extern unsigned char temp0, temp1, setpoint, ac_auto_on, ac_modo;
00088
00089 static unsigned short cgi_gettemp( void *arg )
00090 {
00091 sprintf( uip_appdata, "%3d,%02d", (int)temp1, (int)temp0);
00092
00093 return strlen( uip_appdata );
00094 }
00095
00096 static PT_THREAD(cgitemperature(struct httpd_state *s, char *ptr))
00097 {
00098 PSOCK_BEGIN(&s->sout);
00099 PSOCK_GENERATOR_SEND(&s->sout, cgi_gettemp, NULL);
00100 PSOCK_END(&s->sout);
00101 }
00102
00103 static unsigned short cgi_getsetp( void *arg )
00104 {
00105 sprintf( uip_appdata, "%d", (int)setpoint);
00106
00107 return strlen( uip_appdata );
00108 }
00109
00110 static PT_THREAD(cgisetpoint(struct httpd_state *s, char *ptr))
00111 {
00112 PSOCK_BEGIN(&s->sout);
00113 PSOCK_GENERATOR_SEND(&s->sout, cgi_getsetp, NULL);
00114 PSOCK_END(&s->sout);
00115 }
00116
00117 static unsigned short cgi_getestado( void *arg )
00118 {
00119 switch(ac_modo)
00120 {
00121 case 0:
00122 strcpy( uip_appdata, "<option>ON</option> <option>AUTO</option> <option selected>OFF</option>");
00123 break;
00124 case 1:
00125 strcpy( uip_appdata, "<option>ON</option> <option selected>AUTO</option> <option>OFF</option>");
00126 break;
00127 case 2:
00128 strcpy( uip_appdata, "<option selected>ON</option> <option>AUTO</option> <option>OFF</option>");
00129 break;
00130 default:
00131 strcpy( uip_appdata, "<option>ON</option> <option>AUTO</option> <option selected>OFF</option>");
00132 break;
00133 }
00134 return strlen( uip_appdata );
00135 }
00136
00137 static PT_THREAD(cgiestado(struct httpd_state *s, char *ptr))
00138 {
00139 PSOCK_BEGIN(&s->sout);
00140 PSOCK_GENERATOR_SEND(&s->sout, cgi_getestado, NULL);
00141 PSOCK_END(&s->sout);
00142 }
00143
00144 #define PASSWORD "sisca"
00145
00146 void cgiProcessFormInput( char *pcInputString, int xInputLength )
00147 {
00148 char *c, *d, *e, *pcText;
00149 char tac_modo, tsetpoint;
00150
00151 c = strstr( pcInputString, "?" );
00152 if( c )
00153 {
00154 printf("\n\n");
00155 *c = 0x00;
00156 c++;
00157 e = strstr( c, " " );
00158 if( e != NULL )
00159 {
00160 *e = 0x00;
00161 }
00162 d = strstr( c, "stpt=");
00163 if (d) {
00164 c=d;
00165 c += strlen("stpt=");
00166 d = strchr( c, '&');
00167 *d = '\0';
00168 tsetpoint = atoi(c);
00169 printf("--[%s]--",c);
00170 c=d+1;
00171 }
00172
00173 d = strstr( c, "estd=");
00174 if(d) {
00175 c=d;
00176 c += strlen("estd=");
00177 d = strchr( c, '&');
00178 *d = '\0';
00179 if(strstr(c, "ON")) tac_modo=2;
00180 if(strstr(c, "OFF")) tac_modo=0;
00181 if(strstr(c, "AUTO")) tac_modo=1;
00182 printf("--[%s]--",c);
00183 c=d+1; }
00184 d = strstr( c, "psswd=");
00185 if (d)
00186 {
00187 c=d;
00188 c += strlen("psswd=");
00189 printf("--[%s]--",c);
00190 if(strstr(c,PASSWORD))
00191 {
00192 setpoint = tsetpoint;
00193 ac_modo = tac_modo;
00194 printf("\n Password ok");
00195 }
00196 else
00197 {
00198 tsetpoint = setpoint;
00199 tac_modo = ac_modo;
00200 printf("\n Wrong Password");
00201 }
00202 }
00203
00204 printf("\n Setpoint: %d",setpoint);
00205 printf("\n Modo de op: %d\n",ac_modo);
00206 }
00207 }
00208
00209
00210
00211
00212