nova proba

Committer:
bosko001
Date:
Fri May 01 23:15:28 2020 +0000
Revision:
12:cbfc10c15437
Parent:
9:893843262a1f
popravljeno

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bosko001 4:7abcf4543282 1 #include "mbed.h"
bosko001 3:1196befeace0 2 #include "clubbing.h"
bosko001 2:45b351b4fc2a 3 #include "string.h"
bosko001 2:45b351b4fc2a 4 #include "dxml.h"
bosko001 2:45b351b4fc2a 5
bosko001 2:45b351b4fc2a 6 #include "doHTML.h"
bosko001 3:1196befeace0 7 #include "dataFlash.h"
bosko001 2:45b351b4fc2a 8 #include "HTMLpage.h"
bosko001 2:45b351b4fc2a 9
bosko001 2:45b351b4fc2a 10
bosko001 2:45b351b4fc2a 11
bosko001 5:c9a908749d4c 12 /************************** Pocetak *********************/
bosko001 4:7abcf4543282 13
bosko001 4:7abcf4543282 14 void test_HTML(void)
bosko001 4:7abcf4543282 15 {
bosko001 5:c9a908749d4c 16 extern C_HTMLparse *gpc_html;
bosko001 3:1196befeace0 17
bosko001 5:c9a908749d4c 18 P_str( "selected bit rate" , (char*)gpc_html->get_selected_option( "baud_rate" ) );
bosko001 5:c9a908749d4c 19 P_str( "selected parity" , (char*)gpc_html->get_selected_option( "parity" ) );
bosko001 5:c9a908749d4c 20 P_str( "selected stop bits" , (char*)gpc_html->get_selected_option( "stop_bits" ) );
bosko001 5:c9a908749d4c 21 P_str( "selected data bits" , (char*)gpc_html->get_selected_option( "data_bits" ) );
bosko001 3:1196befeace0 22
bosko001 4:7abcf4543282 23 {
bosko001 4:7abcf4543282 24 extern UARTSerial *gp_scom;
bosko001 4:7abcf4543282 25 extern void sendScom( struct UARTSerial *p_scom, char *buffer, int val);
bosko001 4:7abcf4543282 26
bosko001 5:c9a908749d4c 27 auto c = gpc_html->getHTML_free( );
bosko001 5:c9a908749d4c 28 // n = p_soc->send(c, strlen(c));
bosko001 5:c9a908749d4c 29 sendScom( gp_scom, c, strlen(c));
bosko001 5:c9a908749d4c 30 free(c);
bosko001 5:c9a908749d4c 31 }
bosko001 5:c9a908749d4c 32
bosko001 5:c9a908749d4c 33
bosko001 5:c9a908749d4c 34 P_str( "select bit rate 38400", gpc_html->set_selected_option( "baud_rate", "38400" ) );
bosko001 5:c9a908749d4c 35 P_str( "select bit parity ODD", gpc_html->set_selected_option( "parity", "odd" ) );
bosko001 5:c9a908749d4c 36 P_str( "select stop bits 1.5", gpc_html->set_selected_option( "stop_bits", "1.5" ) );
bosko001 5:c9a908749d4c 37 P_str( "select data bits 7", gpc_html->set_selected_option( "data_bits", "7" ) );
bosko001 5:c9a908749d4c 38
bosko001 5:c9a908749d4c 39 {
bosko001 5:c9a908749d4c 40 extern UARTSerial *gp_scom;
bosko001 5:c9a908749d4c 41 extern void sendScom( struct UARTSerial *p_scom, char *buffer, int val);
bosko001 5:c9a908749d4c 42
bosko001 5:c9a908749d4c 43 auto c = gpc_html->getHTML_free( );
bosko001 4:7abcf4543282 44 // n = p_soc->send(c, strlen(c));
bosko001 4:7abcf4543282 45 sendScom( gp_scom, c, strlen(c));
bosko001 4:7abcf4543282 46 free(c);
bosko001 4:7abcf4543282 47 }
bosko001 4:7abcf4543282 48
bosko001 4:7abcf4543282 49
bosko001 5:c9a908749d4c 50 P_str( "selected bit rate" , (char*)gpc_html->get_selected_option( "baud_rate" ) );
bosko001 5:c9a908749d4c 51 P_str( "selected parity" , (char*)gpc_html->get_selected_option( "parity" ) );
bosko001 5:c9a908749d4c 52 P_str( "selected stop bits" , (char*)gpc_html->get_selected_option( "stop_bits" ) );
bosko001 5:c9a908749d4c 53 P_str( "selected data bits" , (char*)gpc_html->get_selected_option( "data_bits" ) );
bosko001 5:c9a908749d4c 54
bosko001 5:c9a908749d4c 55 }
bosko001 5:c9a908749d4c 56
bosko001 5:c9a908749d4c 57
bosko001 5:c9a908749d4c 58
bosko001 5:c9a908749d4c 59
bosko001 5:c9a908749d4c 60
bosko001 5:c9a908749d4c 61 /************************ definicija klase C_HTMLparse ********************/
bosko001 3:1196befeace0 62
bosko001 5:c9a908749d4c 63 void C_HTMLparse::load_front_row(void )
bosko001 5:c9a908749d4c 64 {
bosko001 5:c9a908749d4c 65 int i = 0;
bosko001 5:c9a908749d4c 66 for (auto td = dxml_child(tr, "td")/*, i = 0*/; td; td = td->next)
bosko001 5:c9a908749d4c 67 {
bosko001 5:c9a908749d4c 68 auto input = dxml_child(td, "input");
bosko001 5:c9a908749d4c 69 front_row[i] = input;
bosko001 5:c9a908749d4c 70 ++i;
bosko001 5:c9a908749d4c 71 }
bosko001 5:c9a908749d4c 72
bosko001 5:c9a908749d4c 73 tr = tr->next;
bosko001 5:c9a908749d4c 74 }
bosko001 5:c9a908749d4c 75
bosko001 5:c9a908749d4c 76 void C_HTMLparse::load_second_row()
bosko001 5:c9a908749d4c 77 {
bosko001 5:c9a908749d4c 78 int i = 0;
bosko001 5:c9a908749d4c 79 for (auto td = dxml_child(tr, "td")/*, i = 0*/; td; td = td->next)
bosko001 5:c9a908749d4c 80 {
bosko001 5:c9a908749d4c 81 auto input = dxml_child(td, "input");
bosko001 5:c9a908749d4c 82 if (i == 0)
bosko001 5:c9a908749d4c 83 UDPs[0] = input;
bosko001 5:c9a908749d4c 84 else if(i == 1)
bosko001 5:c9a908749d4c 85 TCPs[0] = input;
bosko001 5:c9a908749d4c 86 ++i;
bosko001 5:c9a908749d4c 87 }
bosko001 5:c9a908749d4c 88
bosko001 5:c9a908749d4c 89 tr = tr->next;
bosko001 5:c9a908749d4c 90 }
bosko001 5:c9a908749d4c 91
bosko001 5:c9a908749d4c 92 void C_HTMLparse::load_udp_and_tcp(dxml_t& td)
bosko001 4:7abcf4543282 93 {
bosko001 5:c9a908749d4c 94 for (int i = 0; i < 4; td = td->next)
bosko001 5:c9a908749d4c 95 {
bosko001 5:c9a908749d4c 96 dxml_t inputs[5];
bosko001 5:c9a908749d4c 97 int input_count = 0;
bosko001 5:c9a908749d4c 98 for (auto input = dxml_child(td, "input"); input; input = input->next)
bosko001 5:c9a908749d4c 99 inputs[input_count++] = input;
bosko001 5:c9a908749d4c 100
bosko001 5:c9a908749d4c 101 if (i < 2) // Load inputs into UDPs
bosko001 5:c9a908749d4c 102 {
bosko001 5:c9a908749d4c 103 for (int k = 0; k < input_count; ++k)
bosko001 5:c9a908749d4c 104 UDPs[i == 0 ? k + 1 : k + 6] = inputs[k];
bosko001 5:c9a908749d4c 105 }
bosko001 5:c9a908749d4c 106 else
bosko001 5:c9a908749d4c 107 {
bosko001 5:c9a908749d4c 108 for (int k = 0; k < input_count; ++k)
bosko001 5:c9a908749d4c 109 TCPs[i == 2 ? k + 1 : k + 6] = inputs[k];
bosko001 5:c9a908749d4c 110 }
bosko001 5:c9a908749d4c 111
bosko001 5:c9a908749d4c 112 ++i;
bosko001 5:c9a908749d4c 113 }
bosko001 5:c9a908749d4c 114 }
bosko001 5:c9a908749d4c 115
bosko001 5:c9a908749d4c 116 void C_HTMLparse::load_serial(dxml_t& td)
bosko001 5:c9a908749d4c 117 {
bosko001 5:c9a908749d4c 118 auto select = dxml_child(td, "select");
bosko001 5:c9a908749d4c 119 for (int i = 0; select; select = select->next)
bosko001 5:c9a908749d4c 120 serial[i++] = select;
bosko001 5:c9a908749d4c 121 }
bosko001 5:c9a908749d4c 122
bosko001 5:c9a908749d4c 123
bosko001 5:c9a908749d4c 124 dxml_t C_HTMLparse::get_serial_option(dxml_t s, int option_idx)
bosko001 5:c9a908749d4c 125 {
bosko001 5:c9a908749d4c 126 auto rv = dxml_child(s, "option");
bosko001 5:c9a908749d4c 127 for (int i = 0; i < option_idx; ++i)
bosko001 5:c9a908749d4c 128 {
bosko001 5:c9a908749d4c 129 if( rv->next == NULL ) return NULL;
bosko001 5:c9a908749d4c 130 else rv = rv->next;
bosko001 5:c9a908749d4c 131 }
bosko001 5:c9a908749d4c 132 return rv;
bosko001 5:c9a908749d4c 133 }
bosko001 4:7abcf4543282 134
bosko001 5:c9a908749d4c 135 C_HTMLparse::C_HTMLparse( void )
bosko001 5:c9a908749d4c 136 {
bosko001 5:c9a908749d4c 137
bosko001 5:c9a908749d4c 138 p_HTMLpage = (char*)malloc(strlen(HTMLpage)+1);
bosko001 5:c9a908749d4c 139 strcpy( p_HTMLpage, HTMLpage);
bosko001 5:c9a908749d4c 140 P_int("ucitavam html", strlen(HTMLpage));
bosko001 5:c9a908749d4c 141 p_rootHTML = dxml_parse_str(p_HTMLpage, strlen(p_HTMLpage));
bosko001 5:c9a908749d4c 142 intern_init( );
bosko001 5:c9a908749d4c 143 }
bosko001 7:7ea932eb31f6 144
bosko001 5:c9a908749d4c 145 C_HTMLparse::C_HTMLparse( const char *str )
bosko001 5:c9a908749d4c 146 {
bosko001 5:c9a908749d4c 147 p_HTMLpage = (char*)malloc(strlen(str)+1);
bosko001 5:c9a908749d4c 148 strcpy( p_HTMLpage, str);
bosko001 5:c9a908749d4c 149 P_int("ucitavam html", strlen(str));
bosko001 5:c9a908749d4c 150 p_rootHTML = dxml_parse_str(p_HTMLpage, strlen(p_HTMLpage));
bosko001 5:c9a908749d4c 151 intern_init( );
bosko001 5:c9a908749d4c 152
bosko001 5:c9a908749d4c 153 }
bosko001 5:c9a908749d4c 154
bosko001 5:c9a908749d4c 155
bosko001 5:c9a908749d4c 156 void C_HTMLparse::intern_init( void )
bosko001 5:c9a908749d4c 157 {
bosko001 5:c9a908749d4c 158 html_body = dxml_child(p_rootHTML, "body");
bosko001 5:c9a908749d4c 159 html_form = dxml_child(html_body, "form");
bosko001 5:c9a908749d4c 160 html_table = dxml_child(html_form, "table");
bosko001 5:c9a908749d4c 161 tr = dxml_child(html_table, "tr");
bosko001 5:c9a908749d4c 162
bosko001 5:c9a908749d4c 163 load_front_row();
bosko001 5:c9a908749d4c 164
bosko001 5:c9a908749d4c 165 load_second_row();
bosko001 5:c9a908749d4c 166
bosko001 5:c9a908749d4c 167 auto td = dxml_child(tr, "td");
bosko001 5:c9a908749d4c 168 load_udp_and_tcp(td);
bosko001 5:c9a908749d4c 169 load_serial(td);
bosko001 7:7ea932eb31f6 170 for(int i = 0; i < sizeof( s_hpv)/sizeof( s_hpv[0]); i++) { s_hpv[i].name= NULL; s_hpv[i].value = NULL; }
bosko001 4:7abcf4543282 171 }
bosko001 4:7abcf4543282 172
bosko001 4:7abcf4543282 173
bosko001 5:c9a908749d4c 174 char *C_HTMLparse::getHTML_free( void )
bosko001 5:c9a908749d4c 175 {
bosko001 5:c9a908749d4c 176 return dxml_toxml(p_rootHTML);
bosko001 5:c9a908749d4c 177 }
bosko001 3:1196befeace0 178
bosko001 3:1196befeace0 179
bosko001 5:c9a908749d4c 180 /****************** geteri - seteri *************************/
bosko001 3:1196befeace0 181
bosko001 3:1196befeace0 182
bosko001 3:1196befeace0 183
bosko001 3:1196befeace0 184
bosko001 5:c9a908749d4c 185 const char * C_HTMLparse::get_selected_option( const char *name_option )
bosko001 5:c9a908749d4c 186 {
bosko001 5:c9a908749d4c 187 for( int i=0; dxml_attr(serial[i], "name") != NULL; i++ )
bosko001 5:c9a908749d4c 188 {
bosko001 5:c9a908749d4c 189 char *ret;
bosko001 5:c9a908749d4c 190 if( !strcmp( (char*)dxml_attr(serial[i], "name"), name_option) )
bosko001 5:c9a908749d4c 191 {
bosko001 5:c9a908749d4c 192 for(int j=0; dxml_attr(get_serial_option(serial[i], j), "value") != NULL; j++)
bosko001 5:c9a908749d4c 193 {
bosko001 5:c9a908749d4c 194 if( dxml_attr( get_serial_option(serial[i],j), "selected" ) )
bosko001 5:c9a908749d4c 195 return dxml_attr(get_serial_option(serial[i], j), "value");
bosko001 5:c9a908749d4c 196 }
bosko001 5:c9a908749d4c 197 return dxml_attr(get_serial_option(serial[i], 0), "value");
bosko001 5:c9a908749d4c 198 }
bosko001 5:c9a908749d4c 199 }
bosko001 5:c9a908749d4c 200 return NULL;
bosko001 5:c9a908749d4c 201 }
bosko001 5:c9a908749d4c 202
bosko001 5:c9a908749d4c 203 const char * C_HTMLparse::set_selected_option( const char* name_option, const char* value_option )
bosko001 5:c9a908749d4c 204 {
bosko001 5:c9a908749d4c 205 for( int i=0; dxml_attr(serial[i], "name") != NULL; i++ )
bosko001 5:c9a908749d4c 206 {
bosko001 5:c9a908749d4c 207 // printf(" i = %d \n\r", i );
bosko001 5:c9a908749d4c 208 char *ret;
bosko001 5:c9a908749d4c 209 if( !strcmp( (char*)dxml_attr(serial[i], "name"), name_option) )
bosko001 5:c9a908749d4c 210 {
bosko001 5:c9a908749d4c 211 for(int j=0; dxml_attr(get_serial_option(serial[i], j), "value") != NULL; j++)
bosko001 5:c9a908749d4c 212 {
bosko001 5:c9a908749d4c 213 // printf(" j=%d \n\r", j);
bosko001 5:c9a908749d4c 214 if( !strcmp( dxml_attr( get_serial_option(serial[i],j), "value"), value_option) )
bosko001 5:c9a908749d4c 215 {
bosko001 5:c9a908749d4c 216 if( !dxml_attr( get_serial_option(serial[i],j), "selected") )
bosko001 5:c9a908749d4c 217 {
bosko001 5:c9a908749d4c 218 for(int k=0; dxml_attr(get_serial_option(serial[i], k), "value") != NULL; k++)
bosko001 5:c9a908749d4c 219 {
bosko001 5:c9a908749d4c 220 // printf(" k=%d\n\r",k);
bosko001 5:c9a908749d4c 221 if( !strcmp( dxml_attr( get_serial_option(serial[i],k), "value"), value_option) )
bosko001 5:c9a908749d4c 222 {
bosko001 5:c9a908749d4c 223 printf(" kk=%d\n\r",k);
bosko001 5:c9a908749d4c 224 dxml_set_attr( get_serial_option(serial[i],k), "selected", "ON" );
bosko001 5:c9a908749d4c 225 }
bosko001 5:c9a908749d4c 226 else
bosko001 5:c9a908749d4c 227 {
bosko001 7:7ea932eb31f6 228 // printf(" k=%d\n\r",k);
bosko001 5:c9a908749d4c 229 dxml_set_attr( get_serial_option(serial[i],k), "selected", NULL );
bosko001 5:c9a908749d4c 230 }
bosko001 5:c9a908749d4c 231 }
bosko001 5:c9a908749d4c 232 }
bosko001 5:c9a908749d4c 233 return value_option;
bosko001 5:c9a908749d4c 234 }
bosko001 5:c9a908749d4c 235 }
bosko001 5:c9a908749d4c 236 }
bosko001 5:c9a908749d4c 237 }
bosko001 5:c9a908749d4c 238
bosko001 5:c9a908749d4c 239 return NULL;
bosko001 5:c9a908749d4c 240
bosko001 5:c9a908749d4c 241 }
bosko001 9:893843262a1f 242
bosko001 9:893843262a1f 243 const char * C_HTMLparse::get_BaudRate( void )
bosko001 9:893843262a1f 244 {
bosko001 9:893843262a1f 245 return get_selected_option( "baud_rate" );
bosko001 9:893843262a1f 246 }
bosko001 9:893843262a1f 247 const char * C_HTMLparse::get_Parity( void )
bosko001 9:893843262a1f 248 {
bosko001 9:893843262a1f 249 return get_selected_option( "parity" );
bosko001 9:893843262a1f 250 }
bosko001 9:893843262a1f 251 const char * C_HTMLparse::get_StopBits( void )
bosko001 9:893843262a1f 252 {
bosko001 9:893843262a1f 253 return get_selected_option( "stop_bits" );
bosko001 9:893843262a1f 254 }
bosko001 9:893843262a1f 255 const char * C_HTMLparse::get_DataBits( void )
bosko001 9:893843262a1f 256 {
bosko001 9:893843262a1f 257 return get_selected_option( "data_bits" );
bosko001 9:893843262a1f 258 }
bosko001 9:893843262a1f 259
bosko001 9:893843262a1f 260
bosko001 5:c9a908749d4c 261
bosko001 7:7ea932eb31f6 262 #define COPY_IP_ATTR_VALUE( DXML_T, STR ) { char *s = (char *)dxml_attr( DXML_T, "value"); if( s ) {strcpy( s, STR ); dxml_set_attr( DXML_T, "value", s); } }
bosko001 9:893843262a1f 263 //#define COPY_IP_ATTR_VALUE( DXML_T, STR ) { char *s = (char *)dxml_attr( DXML_T, "value"); free( s ); char *d = (char *)malloc( strlen(STR)+1); strcpy( s, STR ); dxml_set_attr( DXML_T, "value", d); }
bosko001 9:893843262a1f 264
bosko001 7:7ea932eb31f6 265 #define COPY_PORT_ATTR_VALUE( DXML_T, STR ) { char *s = (char *)dxml_attr( DXML_T, "value"); if( s ) {strcpy( s, STR ); dxml_set_attr( DXML_T, "value", s); } }
bosko001 5:c9a908749d4c 266
bosko001 7:7ea932eb31f6 267 void C_HTMLparse::set_myIP( const char* str ) { if( test_ip( str )) COPY_IP_ATTR_VALUE( front_row[0], str ); }
bosko001 7:7ea932eb31f6 268
bosko001 7:7ea932eb31f6 269 void C_HTMLparse::set_myMASK( const char* str ) { if( test_ip( str )) COPY_IP_ATTR_VALUE( front_row[1], str ); }
bosko001 5:c9a908749d4c 270
bosko001 7:7ea932eb31f6 271 void C_HTMLparse::set_myGATE( const char* str ) { if( test_ip( str )) COPY_IP_ATTR_VALUE( front_row[2], str ); }
bosko001 7:7ea932eb31f6 272
bosko001 7:7ea932eb31f6 273 void C_HTMLparse::set_myUdpPort( const char* str ) { if( test_num( str ) ) COPY_PORT_ATTR_VALUE( UDPs[0], str ); } //dxml_set_attr( UDPs[0], "value", str ); }
bosko001 7:7ea932eb31f6 274
bosko001 7:7ea932eb31f6 275 void C_HTMLparse::set_myTcpPort( const char* str ) { if( test_num( str ) ) COPY_PORT_ATTR_VALUE( TCPs[0], str ); } // if( test_num( str) ) dxml_set_attr( TCPs[0], "value", str); }
bosko001 5:c9a908749d4c 276
bosko001 5:c9a908749d4c 277 void C_HTMLparse::set_UdpIP( int i, const char* str )
bosko001 5:c9a908749d4c 278 {
bosko001 8:c0f54b381346 279 if( (i > 0) && (i <= 5 ) )
bosko001 8:c0f54b381346 280 {
bosko001 8:c0f54b381346 281 if( test_ip( str ) ) COPY_IP_ATTR_VALUE( UDPs[i], str )
bosko001 9:893843262a1f 282 else COPY_IP_ATTR_VALUE( UDPs[i], "xxx.xxx.xxx.xxx" )
bosko001 8:c0f54b381346 283 }
bosko001 5:c9a908749d4c 284 }
bosko001 5:c9a908749d4c 285 void C_HTMLparse::set_UdpPort( int i, const char* str )
bosko001 5:c9a908749d4c 286 {
bosko001 8:c0f54b381346 287 if( (i>0) && (i<= 4) )
bosko001 8:c0f54b381346 288 {
bosko001 8:c0f54b381346 289 if (test_num( str ) ) COPY_PORT_ATTR_VALUE( UDPs[i+5], str )
bosko001 9:893843262a1f 290 // else COPY_PORT_ATTR_VALUE( UDPs[i+5], " " )
bosko001 8:c0f54b381346 291 }
bosko001 5:c9a908749d4c 292 }
bosko001 5:c9a908749d4c 293
bosko001 5:c9a908749d4c 294 void C_HTMLparse::set_TcpIP( int i, const char* str )
bosko001 5:c9a908749d4c 295 {
bosko001 8:c0f54b381346 296 if( (i > 0) && (i <= 5 ) )
bosko001 8:c0f54b381346 297 {
bosko001 8:c0f54b381346 298 if( test_ip( str ) ) COPY_IP_ATTR_VALUE( TCPs[i], str ) /////// dxml_set_attr( TCPs[i], "value", str);
bosko001 9:893843262a1f 299 else COPY_IP_ATTR_VALUE( TCPs[i], "xxx.xxx.xxx.xxx" ) /////// dxml_set_attr( TCPs[i], "value", str);
bosko001 8:c0f54b381346 300 }
bosko001 5:c9a908749d4c 301 }
bosko001 5:c9a908749d4c 302 void C_HTMLparse::set_TcpPort( int i, const char* str )
bosko001 5:c9a908749d4c 303 {
bosko001 8:c0f54b381346 304 if( (i>0) && (i<= 4) )
bosko001 8:c0f54b381346 305 {
bosko001 8:c0f54b381346 306 if( test_num( str ) ) COPY_PORT_ATTR_VALUE( TCPs[i+5], str ) ////dxml_set_attr( TCPs[i+6], "value", str) ;
bosko001 9:893843262a1f 307 // else COPY_PORT_ATTR_VALUE( TCPs[i+5], " " )
bosko001 8:c0f54b381346 308 }
bosko001 5:c9a908749d4c 309 }
bosko001 5:c9a908749d4c 310
bosko001 5:c9a908749d4c 311 const char *C_HTMLparse::get_myIP( void )
bosko001 5:c9a908749d4c 312 {
bosko001 5:c9a908749d4c 313 return dxml_attr( front_row[0], "value");
bosko001 5:c9a908749d4c 314 }
bosko001 5:c9a908749d4c 315 const char *C_HTMLparse::get_myMASK(void)
bosko001 5:c9a908749d4c 316 {
bosko001 5:c9a908749d4c 317 return dxml_attr( front_row[1], "value");
bosko001 5:c9a908749d4c 318 }
bosko001 5:c9a908749d4c 319 const char *C_HTMLparse::get_myGATE( void )
bosko001 5:c9a908749d4c 320 {
bosko001 5:c9a908749d4c 321 return dxml_attr( front_row[2], "value");
bosko001 5:c9a908749d4c 322 }
bosko001 5:c9a908749d4c 323
bosko001 5:c9a908749d4c 324 const char *C_HTMLparse::get_myUdpPort( void )
bosko001 5:c9a908749d4c 325 {
bosko001 5:c9a908749d4c 326 return dxml_attr( UDPs[0], "value" );
bosko001 5:c9a908749d4c 327 }
bosko001 5:c9a908749d4c 328 const char *C_HTMLparse::get_myTcpPort( void )
bosko001 5:c9a908749d4c 329 {
bosko001 5:c9a908749d4c 330 return dxml_attr( TCPs[0], "value");
bosko001 5:c9a908749d4c 331 }
bosko001 5:c9a908749d4c 332
bosko001 5:c9a908749d4c 333 const char *C_HTMLparse::get_UdpIP( int i )
bosko001 5:c9a908749d4c 334 {
bosko001 5:c9a908749d4c 335 if( (i > 0) && (i <= 5 ) ) return dxml_attr( UDPs[i], "value");
bosko001 5:c9a908749d4c 336 return NULL;
bosko001 5:c9a908749d4c 337 }
bosko001 5:c9a908749d4c 338
bosko001 5:c9a908749d4c 339 const char *C_HTMLparse::get_UdpPort( int i )
bosko001 5:c9a908749d4c 340 {
bosko001 7:7ea932eb31f6 341 if( (i>0) && (i<= 4) ) return dxml_attr( UDPs[i+5], "value") ;
bosko001 5:c9a908749d4c 342 return NULL;
bosko001 5:c9a908749d4c 343 }
bosko001 5:c9a908749d4c 344
bosko001 5:c9a908749d4c 345 const char *C_HTMLparse::get_TcpIP( int i )
bosko001 5:c9a908749d4c 346 {
bosko001 5:c9a908749d4c 347 if( (i > 0) && (i <= 5 ) ) return dxml_attr( TCPs[i], "value");
bosko001 5:c9a908749d4c 348 return NULL;
bosko001 5:c9a908749d4c 349 }
bosko001 5:c9a908749d4c 350
bosko001 5:c9a908749d4c 351 const char *C_HTMLparse::get_TcpPort( int i )
bosko001 5:c9a908749d4c 352 {
bosko001 7:7ea932eb31f6 353 if( (i>0) && (i<= 4) ) return dxml_attr( TCPs[i+5], "value") ;
bosko001 5:c9a908749d4c 354 return NULL;
bosko001 5:c9a908749d4c 355 }
bosko001 5:c9a908749d4c 356
bosko001 5:c9a908749d4c 357
bosko001 7:7ea932eb31f6 358 /****************************************************************************/
bosko001 5:c9a908749d4c 359
bosko001 7:7ea932eb31f6 360 /*************** HTTP obrada *********************************************/
bosko001 7:7ea932eb31f6 361
bosko001 7:7ea932eb31f6 362
bosko001 7:7ea932eb31f6 363 int C_HTMLparse::httpSplitInLines( char *lines[], char * httpresp)
bosko001 7:7ea932eb31f6 364 {
bosko001 7:7ea932eb31f6 365
bosko001 7:7ea932eb31f6 366 char * pch;
bosko001 7:7ea932eb31f6 367 int i=0;
bosko001 7:7ea932eb31f6 368 pch = lines[i++]= strtok (httpresp,"\n\r");
bosko001 7:7ea932eb31f6 369 while (pch != NULL)
bosko001 7:7ea932eb31f6 370 {
bosko001 7:7ea932eb31f6 371 pch=lines[i++] = strtok (NULL, "\n\r");
bosko001 7:7ea932eb31f6 372 }
bosko001 7:7ea932eb31f6 373 return i;
bosko001 7:7ea932eb31f6 374 }
bosko001 7:7ea932eb31f6 375 char * C_HTMLparse::httpFirstLine( char **descr, char *line)
bosko001 7:7ea932eb31f6 376 {
bosko001 7:7ea932eb31f6 377 char * pch;
bosko001 7:7ea932eb31f6 378
bosko001 7:7ea932eb31f6 379 pch = strtok (line,"/ ");
bosko001 7:7ea932eb31f6 380 *descr = strtok (NULL, "/ ");
bosko001 7:7ea932eb31f6 381 return pch;
bosko001 7:7ea932eb31f6 382 }
bosko001 7:7ea932eb31f6 383 //
bosko001 7:7ea932eb31f6 384 //struct S_httpPostValues
bosko001 7:7ea932eb31f6 385 //{
bosko001 7:7ea932eb31f6 386 // char *name;
bosko001 7:7ea932eb31f6 387 // char *value;
bosko001 7:7ea932eb31f6 388 //} s_hpv[100];
bosko001 7:7ea932eb31f6 389
bosko001 7:7ea932eb31f6 390 //struct S_httpPostValues *ps_hpv = s_hpv;
bosko001 7:7ea932eb31f6 391
bosko001 7:7ea932eb31f6 392 int C_HTMLparse::extractPostPairs( struct S_httpPostValues ** ps_hpv, char *line)
bosko001 7:7ea932eb31f6 393 {
bosko001 7:7ea932eb31f6 394 char *lines[100];
bosko001 7:7ea932eb31f6 395 char * pch;
bosko001 7:7ea932eb31f6 396
bosko001 7:7ea932eb31f6 397 int i=0;
bosko001 7:7ea932eb31f6 398 pch = lines[i++]= strtok (line,"&");
bosko001 7:7ea932eb31f6 399 while (pch != NULL)
bosko001 7:7ea932eb31f6 400 {
bosko001 7:7ea932eb31f6 401 pch=lines[i++] = strtok (NULL, "&\n\r");
bosko001 7:7ea932eb31f6 402 }
bosko001 7:7ea932eb31f6 403
bosko001 12:cbfc10c15437 404 //printf("linija 26 %s\n\r", lines[26]);
bosko001 12:cbfc10c15437 405 //for(int i=0; i<15; i++) printf("%x ", *(lines[26]+i) ); printf("\n\r\n\r");
bosko001 7:7ea932eb31f6 406
bosko001 7:7ea932eb31f6 407 for( int j=0; j<i; j++)
bosko001 7:7ea932eb31f6 408 {
bosko001 7:7ea932eb31f6 409 char *s = strtok(lines[j], "=");
bosko001 7:7ea932eb31f6 410 (*ps_hpv)[j].name = s;
bosko001 7:7ea932eb31f6 411 (*ps_hpv)[j].value = strtok(NULL, "=");
bosko001 7:7ea932eb31f6 412 }
bosko001 7:7ea932eb31f6 413 return i;
bosko001 7:7ea932eb31f6 414 }
bosko001 7:7ea932eb31f6 415
bosko001 7:7ea932eb31f6 416
bosko001 7:7ea932eb31f6 417 char * C_HTMLparse::doHTTP( char * httpcontents)
bosko001 7:7ea932eb31f6 418 {
bosko001 7:7ea932eb31f6 419 char *lines[50];
bosko001 7:7ea932eb31f6 420
bosko001 7:7ea932eb31f6 421 int http_i = httpSplitInLines( lines, httpcontents);
bosko001 7:7ea932eb31f6 422
bosko001 7:7ea932eb31f6 423 char *descr;
bosko001 7:7ea932eb31f6 424 char *type = httpFirstLine( &descr, lines[0]);
bosko001 7:7ea932eb31f6 425
bosko001 7:7ea932eb31f6 426 printf("type = %s descr = %s\n\r", type, descr );
bosko001 7:7ea932eb31f6 427
bosko001 7:7ea932eb31f6 428 int html_j=0;
bosko001 7:7ea932eb31f6 429 if ( !strcmp( type, "POST") )
bosko001 7:7ea932eb31f6 430 {
bosko001 7:7ea932eb31f6 431 if( http_i >=14)
bosko001 7:7ea932eb31f6 432 {
bosko001 7:7ea932eb31f6 433 html_j = extractPostPairs( &ps_hpv, lines[14]);
bosko001 7:7ea932eb31f6 434 return "POST" ;
bosko001 7:7ea932eb31f6 435 }
bosko001 7:7ea932eb31f6 436 }
bosko001 7:7ea932eb31f6 437 else if( !strcmp(type, "GET"))
bosko001 7:7ea932eb31f6 438 {
bosko001 7:7ea932eb31f6 439 if( !strcmp(descr, "HTTP") ) return "GET_HTML";
bosko001 7:7ea932eb31f6 440 else return 0;
bosko001 7:7ea932eb31f6 441 }
bosko001 7:7ea932eb31f6 442 return 0;
bosko001 7:7ea932eb31f6 443 }
bosko001 7:7ea932eb31f6 444
bosko001 7:7ea932eb31f6 445 /* TEST
bosko001 7:7ea932eb31f6 446
bosko001 7:7ea932eb31f6 447 if( !strcmp(doHTTP( hG3), "POST") )
bosko001 7:7ea932eb31f6 448
bosko001 7:7ea932eb31f6 449 for( int k=0; k<10; k++ )
bosko001 7:7ea932eb31f6 450 printf("name= %s value= %s\n\r", (ps_hpv+k)->name, ps_hpv[k].value);
bosko001 7:7ea932eb31f6 451
bosko001 7:7ea932eb31f6 452 return 0;
bosko001 7:7ea932eb31f6 453 */
bosko001 7:7ea932eb31f6 454
bosko001 7:7ea932eb31f6 455 // struct S_httpPostValues
bosko001 7:7ea932eb31f6 456 // {
bosko001 7:7ea932eb31f6 457 // char *name;
bosko001 7:7ea932eb31f6 458 // char *value;
bosko001 7:7ea932eb31f6 459 // } s_hpv[100];
bosko001 7:7ea932eb31f6 460
bosko001 7:7ea932eb31f6 461
bosko001 7:7ea932eb31f6 462 void C_HTMLparse::htmlPOST_fun( void )
bosko001 7:7ea932eb31f6 463 {
bosko001 7:7ea932eb31f6 464 for(int i = 0; i<27; i++ )
bosko001 7:7ea932eb31f6 465 {
bosko001 9:893843262a1f 466 // printf(" rb = %d name:%s = value:%s \n\r", i, s_hpv[i].name, s_hpv[i].value );
bosko001 7:7ea932eb31f6 467
bosko001 7:7ea932eb31f6 468 if( !strcmp( s_hpv[i].name, "ip_adresa") ) set_myIP( s_hpv[i].value );
bosko001 7:7ea932eb31f6 469 else if( !strcmp( s_hpv[i].name, "netmask") ) set_myMASK( s_hpv[i].value );
bosko001 7:7ea932eb31f6 470 else if( !strcmp( s_hpv[i].name, "gateway") ) set_myGATE( s_hpv[i].value );
bosko001 7:7ea932eb31f6 471
bosko001 7:7ea932eb31f6 472 else if( !strcmp( s_hpv[i].name, "udp_server_port") ) set_myUdpPort( s_hpv[i].value );
bosko001 7:7ea932eb31f6 473 else if( !strcmp( s_hpv[i].name, "tcp_server_port") ) set_myTcpPort( s_hpv[i].value );
bosko001 7:7ea932eb31f6 474
bosko001 7:7ea932eb31f6 475 else if( !strcmp( s_hpv[i].name, "udp_ip_1") ) set_UdpIP( 1, s_hpv[i].value );
bosko001 7:7ea932eb31f6 476 else if( !strcmp( s_hpv[i].name, "udp_ip_2") ) set_UdpIP( 2, s_hpv[i].value );
bosko001 7:7ea932eb31f6 477 else if( !strcmp( s_hpv[i].name, "udp_ip_3") ) set_UdpIP( 3, s_hpv[i].value );
bosko001 7:7ea932eb31f6 478 else if( !strcmp( s_hpv[i].name, "udp_opseg_od") ) set_UdpIP( 4, s_hpv[i].value );
bosko001 7:7ea932eb31f6 479 else if( !strcmp( s_hpv[i].name, "udp_opseg_do") ) set_UdpIP( 5, s_hpv[i].value );
bosko001 7:7ea932eb31f6 480
bosko001 7:7ea932eb31f6 481 else if( !strcmp( s_hpv[i].name, "udp_port_1") ) set_UdpPort( 1, s_hpv[i].value );
bosko001 7:7ea932eb31f6 482 else if( !strcmp( s_hpv[i].name, "udp_port_2") ) set_UdpPort( 2, s_hpv[i].value );
bosko001 7:7ea932eb31f6 483 else if( !strcmp( s_hpv[i].name, "udp_port_3") ) set_UdpPort( 3, s_hpv[i].value );
bosko001 7:7ea932eb31f6 484 else if( !strcmp( s_hpv[i].name, "udp_port_opseg") ) set_UdpPort( 4, s_hpv[i].value );
bosko001 7:7ea932eb31f6 485
bosko001 7:7ea932eb31f6 486 else if( !strcmp( s_hpv[i].name, "tcp_ip_1") ) set_TcpIP( 1, s_hpv[i].value );
bosko001 7:7ea932eb31f6 487 else if( !strcmp( s_hpv[i].name, "tcp_ip_2") ) set_TcpIP( 2, s_hpv[i].value );
bosko001 7:7ea932eb31f6 488 else if( !strcmp( s_hpv[i].name, "tcp_ip_3") ) set_TcpIP( 3, s_hpv[i].value );
bosko001 7:7ea932eb31f6 489 else if( !strcmp( s_hpv[i].name, "tcp_opseg_od") ) set_TcpIP( 4, s_hpv[i].value );
bosko001 7:7ea932eb31f6 490 else if( !strcmp( s_hpv[i].name, "tcp_opseg_do") ) set_TcpIP( 5, s_hpv[i].value );
bosko001 7:7ea932eb31f6 491
bosko001 7:7ea932eb31f6 492 else if( !strcmp( s_hpv[i].name, "tcp_port_1") ) set_TcpPort( 1, s_hpv[i].value );
bosko001 7:7ea932eb31f6 493 else if( !strcmp( s_hpv[i].name, "tcp_port_2") ) set_TcpPort( 2, s_hpv[i].value );
bosko001 7:7ea932eb31f6 494 else if( !strcmp( s_hpv[i].name, "tcp_port_3") ) set_TcpPort( 3, s_hpv[i].value );
bosko001 7:7ea932eb31f6 495 else if( !strcmp( s_hpv[i].name, "tcp_port_opseg") ) set_TcpPort( 4, s_hpv[i].value );
bosko001 7:7ea932eb31f6 496
bosko001 7:7ea932eb31f6 497
bosko001 7:7ea932eb31f6 498 else if( !strcmp( s_hpv[i].name, "baud_rate") ) set_selected_option( "baud_rate" , s_hpv[i].value );
bosko001 7:7ea932eb31f6 499 else if( !strcmp( s_hpv[i].name, "parity") ) set_selected_option( "parity" , s_hpv[i].value );
bosko001 7:7ea932eb31f6 500 else if( !strcmp( s_hpv[i].name, "data_bits") ) { set_selected_option( "data_bits" , s_hpv[i].value ); }
bosko001 7:7ea932eb31f6 501 else if( !strcmp( s_hpv[i].name, "stop_bits") ) { set_selected_option( "stop_bits" , s_hpv[i].value ); }
bosko001 7:7ea932eb31f6 502 }
bosko001 7:7ea932eb31f6 503
bosko001 7:7ea932eb31f6 504 }
bosko001 7:7ea932eb31f6 505
bosko001 7:7ea932eb31f6 506
bosko001 7:7ea932eb31f6 507
bosko001 7:7ea932eb31f6 508 //ip_adresa=192.168.1.20&
bosko001 7:7ea932eb31f6 509 //netmask=255.255.255.0&
bosko001 7:7ea932eb31f6 510 //gateway=192.168.1.1&
bosko001 7:7ea932eb31f6 511 //udp_server_port=11000&
bosko001 7:7ea932eb31f6 512 //tcp_server_port=12000&
bosko001 7:7ea932eb31f6 513 //udp_ip_1=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 514 //udp_ip_2=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 515 //udp_ip_3=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 516 //udp_opseg_od=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 517 //udp_opseg_do=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 518 //udp_port_1=65535&
bosko001 7:7ea932eb31f6 519 //udp_port_2=&
bosko001 7:7ea932eb31f6 520 //udp_port_3=65535&
bosko001 7:7ea932eb31f6 521 //udp_port_opseg=65535&
bosko001 7:7ea932eb31f6 522 //tcp_ip_1=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 523 //tcp_ip_2=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 524 //tcp_ip_3=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 525 //tcp_opseg_od=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 526 //tcp_opseg_do=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 527 //tcp_port_1=65535&
bosko001 7:7ea932eb31f6 528 //tcp_port_2=&tcp_port_3=65535&
bosko001 7:7ea932eb31f6 529 //tcp_port_opseg=65535&
bosko001 7:7ea932eb31f6 530 //baud_rate=9600&
bosko001 7:7ea932eb31f6 531 //parity=none&data_bits=8&
bosko001 7:7ea932eb31f6 532 //stop_bits=1
bosko001 7:7ea932eb31f6 533
bosko001 7:7ea932eb31f6 534
bosko001 7:7ea932eb31f6 535
bosko001 7:7ea932eb31f6 536
bosko001 7:7ea932eb31f6 537 /*****************************************************************************/