nova proba

Committer:
bosko001
Date:
Sun Apr 19 22:13:45 2020 +0000
Revision:
8:c0f54b381346
Parent:
7:7ea932eb31f6
Child:
9:893843262a1f
zavrseno sa dataFlashom i sa HTML-om

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 5:c9a908749d4c 242
bosko001 7:7ea932eb31f6 243 #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 7:7ea932eb31f6 244 #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 245
bosko001 7:7ea932eb31f6 246 void C_HTMLparse::set_myIP( const char* str ) { if( test_ip( str )) COPY_IP_ATTR_VALUE( front_row[0], str ); }
bosko001 7:7ea932eb31f6 247
bosko001 7:7ea932eb31f6 248 void C_HTMLparse::set_myMASK( const char* str ) { if( test_ip( str )) COPY_IP_ATTR_VALUE( front_row[1], str ); }
bosko001 5:c9a908749d4c 249
bosko001 7:7ea932eb31f6 250 void C_HTMLparse::set_myGATE( const char* str ) { if( test_ip( str )) COPY_IP_ATTR_VALUE( front_row[2], str ); }
bosko001 7:7ea932eb31f6 251
bosko001 7:7ea932eb31f6 252 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 253
bosko001 7:7ea932eb31f6 254 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 255
bosko001 5:c9a908749d4c 256 void C_HTMLparse::set_UdpIP( int i, const char* str )
bosko001 5:c9a908749d4c 257 {
bosko001 8:c0f54b381346 258 if( (i > 0) && (i <= 5 ) )
bosko001 8:c0f54b381346 259 {
bosko001 8:c0f54b381346 260 if( test_ip( str ) ) COPY_IP_ATTR_VALUE( UDPs[i], str )
bosko001 8:c0f54b381346 261 else COPY_IP_ATTR_VALUE( UDPs[i], " " )
bosko001 8:c0f54b381346 262 }
bosko001 5:c9a908749d4c 263 }
bosko001 5:c9a908749d4c 264 void C_HTMLparse::set_UdpPort( int i, const char* str )
bosko001 5:c9a908749d4c 265 {
bosko001 8:c0f54b381346 266 if( (i>0) && (i<= 4) )
bosko001 8:c0f54b381346 267 {
bosko001 8:c0f54b381346 268 if (test_num( str ) ) COPY_PORT_ATTR_VALUE( UDPs[i+5], str )
bosko001 8:c0f54b381346 269 else COPY_PORT_ATTR_VALUE( UDPs[i+5], " " )
bosko001 8:c0f54b381346 270 }
bosko001 5:c9a908749d4c 271 }
bosko001 5:c9a908749d4c 272
bosko001 5:c9a908749d4c 273 void C_HTMLparse::set_TcpIP( int i, const char* str )
bosko001 5:c9a908749d4c 274 {
bosko001 8:c0f54b381346 275 if( (i > 0) && (i <= 5 ) )
bosko001 8:c0f54b381346 276 {
bosko001 8:c0f54b381346 277 if( test_ip( str ) ) COPY_IP_ATTR_VALUE( TCPs[i], str ) /////// dxml_set_attr( TCPs[i], "value", str);
bosko001 8:c0f54b381346 278 else COPY_IP_ATTR_VALUE( TCPs[i], " " ) /////// dxml_set_attr( TCPs[i], "value", str);
bosko001 8:c0f54b381346 279 }
bosko001 5:c9a908749d4c 280 }
bosko001 5:c9a908749d4c 281 void C_HTMLparse::set_TcpPort( int i, const char* str )
bosko001 5:c9a908749d4c 282 {
bosko001 8:c0f54b381346 283 if( (i>0) && (i<= 4) )
bosko001 8:c0f54b381346 284 {
bosko001 8:c0f54b381346 285 if( test_num( str ) ) COPY_PORT_ATTR_VALUE( TCPs[i+5], str ) ////dxml_set_attr( TCPs[i+6], "value", str) ;
bosko001 8:c0f54b381346 286 else COPY_PORT_ATTR_VALUE( TCPs[i+5], " " )
bosko001 8:c0f54b381346 287 }
bosko001 5:c9a908749d4c 288 }
bosko001 5:c9a908749d4c 289
bosko001 5:c9a908749d4c 290 const char *C_HTMLparse::get_myIP( void )
bosko001 5:c9a908749d4c 291 {
bosko001 5:c9a908749d4c 292 return dxml_attr( front_row[0], "value");
bosko001 5:c9a908749d4c 293 }
bosko001 5:c9a908749d4c 294 const char *C_HTMLparse::get_myMASK(void)
bosko001 5:c9a908749d4c 295 {
bosko001 5:c9a908749d4c 296 return dxml_attr( front_row[1], "value");
bosko001 5:c9a908749d4c 297 }
bosko001 5:c9a908749d4c 298 const char *C_HTMLparse::get_myGATE( void )
bosko001 5:c9a908749d4c 299 {
bosko001 5:c9a908749d4c 300 return dxml_attr( front_row[2], "value");
bosko001 5:c9a908749d4c 301 }
bosko001 5:c9a908749d4c 302
bosko001 5:c9a908749d4c 303 const char *C_HTMLparse::get_myUdpPort( void )
bosko001 5:c9a908749d4c 304 {
bosko001 5:c9a908749d4c 305 return dxml_attr( UDPs[0], "value" );
bosko001 5:c9a908749d4c 306 }
bosko001 5:c9a908749d4c 307 const char *C_HTMLparse::get_myTcpPort( void )
bosko001 5:c9a908749d4c 308 {
bosko001 5:c9a908749d4c 309 return dxml_attr( TCPs[0], "value");
bosko001 5:c9a908749d4c 310 }
bosko001 5:c9a908749d4c 311
bosko001 5:c9a908749d4c 312 const char *C_HTMLparse::get_UdpIP( int i )
bosko001 5:c9a908749d4c 313 {
bosko001 5:c9a908749d4c 314 if( (i > 0) && (i <= 5 ) ) return dxml_attr( UDPs[i], "value");
bosko001 5:c9a908749d4c 315 return NULL;
bosko001 5:c9a908749d4c 316 }
bosko001 5:c9a908749d4c 317
bosko001 5:c9a908749d4c 318 const char *C_HTMLparse::get_UdpPort( int i )
bosko001 5:c9a908749d4c 319 {
bosko001 7:7ea932eb31f6 320 if( (i>0) && (i<= 4) ) return dxml_attr( UDPs[i+5], "value") ;
bosko001 5:c9a908749d4c 321 return NULL;
bosko001 5:c9a908749d4c 322 }
bosko001 5:c9a908749d4c 323
bosko001 5:c9a908749d4c 324 const char *C_HTMLparse::get_TcpIP( int i )
bosko001 5:c9a908749d4c 325 {
bosko001 5:c9a908749d4c 326 if( (i > 0) && (i <= 5 ) ) return dxml_attr( TCPs[i], "value");
bosko001 5:c9a908749d4c 327 return NULL;
bosko001 5:c9a908749d4c 328 }
bosko001 5:c9a908749d4c 329
bosko001 5:c9a908749d4c 330 const char *C_HTMLparse::get_TcpPort( int i )
bosko001 5:c9a908749d4c 331 {
bosko001 7:7ea932eb31f6 332 if( (i>0) && (i<= 4) ) return dxml_attr( TCPs[i+5], "value") ;
bosko001 5:c9a908749d4c 333 return NULL;
bosko001 5:c9a908749d4c 334 }
bosko001 5:c9a908749d4c 335
bosko001 5:c9a908749d4c 336
bosko001 7:7ea932eb31f6 337 /****************************************************************************/
bosko001 5:c9a908749d4c 338
bosko001 7:7ea932eb31f6 339 /*************** HTTP obrada *********************************************/
bosko001 7:7ea932eb31f6 340
bosko001 7:7ea932eb31f6 341
bosko001 7:7ea932eb31f6 342 int C_HTMLparse::httpSplitInLines( char *lines[], char * httpresp)
bosko001 7:7ea932eb31f6 343 {
bosko001 7:7ea932eb31f6 344
bosko001 7:7ea932eb31f6 345 char * pch;
bosko001 7:7ea932eb31f6 346 int i=0;
bosko001 7:7ea932eb31f6 347 pch = lines[i++]= strtok (httpresp,"\n\r");
bosko001 7:7ea932eb31f6 348 while (pch != NULL)
bosko001 7:7ea932eb31f6 349 {
bosko001 7:7ea932eb31f6 350 pch=lines[i++] = strtok (NULL, "\n\r");
bosko001 7:7ea932eb31f6 351 }
bosko001 7:7ea932eb31f6 352 return i;
bosko001 7:7ea932eb31f6 353 }
bosko001 7:7ea932eb31f6 354 char * C_HTMLparse::httpFirstLine( char **descr, char *line)
bosko001 7:7ea932eb31f6 355 {
bosko001 7:7ea932eb31f6 356 char * pch;
bosko001 7:7ea932eb31f6 357
bosko001 7:7ea932eb31f6 358 pch = strtok (line,"/ ");
bosko001 7:7ea932eb31f6 359 *descr = strtok (NULL, "/ ");
bosko001 7:7ea932eb31f6 360 return pch;
bosko001 7:7ea932eb31f6 361 }
bosko001 7:7ea932eb31f6 362 //
bosko001 7:7ea932eb31f6 363 //struct S_httpPostValues
bosko001 7:7ea932eb31f6 364 //{
bosko001 7:7ea932eb31f6 365 // char *name;
bosko001 7:7ea932eb31f6 366 // char *value;
bosko001 7:7ea932eb31f6 367 //} s_hpv[100];
bosko001 7:7ea932eb31f6 368
bosko001 7:7ea932eb31f6 369 //struct S_httpPostValues *ps_hpv = s_hpv;
bosko001 7:7ea932eb31f6 370
bosko001 7:7ea932eb31f6 371 int C_HTMLparse::extractPostPairs( struct S_httpPostValues ** ps_hpv, char *line)
bosko001 7:7ea932eb31f6 372 {
bosko001 7:7ea932eb31f6 373 char *lines[100];
bosko001 7:7ea932eb31f6 374 char * pch;
bosko001 7:7ea932eb31f6 375
bosko001 7:7ea932eb31f6 376 int i=0;
bosko001 7:7ea932eb31f6 377 pch = lines[i++]= strtok (line,"&");
bosko001 7:7ea932eb31f6 378 while (pch != NULL)
bosko001 7:7ea932eb31f6 379 {
bosko001 7:7ea932eb31f6 380 pch=lines[i++] = strtok (NULL, "&\n\r");
bosko001 7:7ea932eb31f6 381 }
bosko001 7:7ea932eb31f6 382
bosko001 7:7ea932eb31f6 383 printf("linija 26 %s\n\r", lines[26]);
bosko001 7:7ea932eb31f6 384 for(int i=0; i<15; i++) printf("%x ", *(lines[26]+i) ); printf("\n\r\n\r");
bosko001 7:7ea932eb31f6 385
bosko001 7:7ea932eb31f6 386 for( int j=0; j<i; j++)
bosko001 7:7ea932eb31f6 387 {
bosko001 7:7ea932eb31f6 388 char *s = strtok(lines[j], "=");
bosko001 7:7ea932eb31f6 389 (*ps_hpv)[j].name = s;
bosko001 7:7ea932eb31f6 390 (*ps_hpv)[j].value = strtok(NULL, "=");
bosko001 7:7ea932eb31f6 391 }
bosko001 7:7ea932eb31f6 392 return i;
bosko001 7:7ea932eb31f6 393 }
bosko001 7:7ea932eb31f6 394
bosko001 7:7ea932eb31f6 395
bosko001 7:7ea932eb31f6 396 char * C_HTMLparse::doHTTP( char * httpcontents)
bosko001 7:7ea932eb31f6 397 {
bosko001 7:7ea932eb31f6 398 char *lines[50];
bosko001 7:7ea932eb31f6 399
bosko001 7:7ea932eb31f6 400 int http_i = httpSplitInLines( lines, httpcontents);
bosko001 7:7ea932eb31f6 401
bosko001 7:7ea932eb31f6 402 char *descr;
bosko001 7:7ea932eb31f6 403 char *type = httpFirstLine( &descr, lines[0]);
bosko001 7:7ea932eb31f6 404
bosko001 7:7ea932eb31f6 405 printf("type = %s descr = %s\n\r", type, descr );
bosko001 7:7ea932eb31f6 406
bosko001 7:7ea932eb31f6 407 int html_j=0;
bosko001 7:7ea932eb31f6 408 if ( !strcmp( type, "POST") )
bosko001 7:7ea932eb31f6 409 {
bosko001 7:7ea932eb31f6 410 if( http_i >=14)
bosko001 7:7ea932eb31f6 411 {
bosko001 7:7ea932eb31f6 412 html_j = extractPostPairs( &ps_hpv, lines[14]);
bosko001 7:7ea932eb31f6 413 return "POST" ;
bosko001 7:7ea932eb31f6 414 }
bosko001 7:7ea932eb31f6 415 }
bosko001 7:7ea932eb31f6 416 else if( !strcmp(type, "GET"))
bosko001 7:7ea932eb31f6 417 {
bosko001 7:7ea932eb31f6 418 if( !strcmp(descr, "HTTP") ) return "GET_HTML";
bosko001 7:7ea932eb31f6 419 else return 0;
bosko001 7:7ea932eb31f6 420 }
bosko001 7:7ea932eb31f6 421 return 0;
bosko001 7:7ea932eb31f6 422 }
bosko001 7:7ea932eb31f6 423
bosko001 7:7ea932eb31f6 424 /* TEST
bosko001 7:7ea932eb31f6 425
bosko001 7:7ea932eb31f6 426 if( !strcmp(doHTTP( hG3), "POST") )
bosko001 7:7ea932eb31f6 427
bosko001 7:7ea932eb31f6 428 for( int k=0; k<10; k++ )
bosko001 7:7ea932eb31f6 429 printf("name= %s value= %s\n\r", (ps_hpv+k)->name, ps_hpv[k].value);
bosko001 7:7ea932eb31f6 430
bosko001 7:7ea932eb31f6 431 return 0;
bosko001 7:7ea932eb31f6 432 */
bosko001 7:7ea932eb31f6 433
bosko001 7:7ea932eb31f6 434 // struct S_httpPostValues
bosko001 7:7ea932eb31f6 435 // {
bosko001 7:7ea932eb31f6 436 // char *name;
bosko001 7:7ea932eb31f6 437 // char *value;
bosko001 7:7ea932eb31f6 438 // } s_hpv[100];
bosko001 7:7ea932eb31f6 439
bosko001 7:7ea932eb31f6 440
bosko001 7:7ea932eb31f6 441 void C_HTMLparse::htmlPOST_fun( void )
bosko001 7:7ea932eb31f6 442 {
bosko001 7:7ea932eb31f6 443 for(int i = 0; i<27; i++ )
bosko001 7:7ea932eb31f6 444 {
bosko001 7:7ea932eb31f6 445 // printf(" rb = %d name:%s = value:%s \n\r", i, s_hpv[i].name, s_hpv[i].value );
bosko001 7:7ea932eb31f6 446
bosko001 7:7ea932eb31f6 447 if( !strcmp( s_hpv[i].name, "ip_adresa") ) set_myIP( s_hpv[i].value );
bosko001 7:7ea932eb31f6 448 else if( !strcmp( s_hpv[i].name, "netmask") ) set_myMASK( s_hpv[i].value );
bosko001 7:7ea932eb31f6 449 else if( !strcmp( s_hpv[i].name, "gateway") ) set_myGATE( s_hpv[i].value );
bosko001 7:7ea932eb31f6 450
bosko001 7:7ea932eb31f6 451 else if( !strcmp( s_hpv[i].name, "udp_server_port") ) set_myUdpPort( s_hpv[i].value );
bosko001 7:7ea932eb31f6 452 else if( !strcmp( s_hpv[i].name, "tcp_server_port") ) set_myTcpPort( s_hpv[i].value );
bosko001 7:7ea932eb31f6 453
bosko001 7:7ea932eb31f6 454 else if( !strcmp( s_hpv[i].name, "udp_ip_1") ) set_UdpIP( 1, s_hpv[i].value );
bosko001 7:7ea932eb31f6 455 else if( !strcmp( s_hpv[i].name, "udp_ip_2") ) set_UdpIP( 2, s_hpv[i].value );
bosko001 7:7ea932eb31f6 456 else if( !strcmp( s_hpv[i].name, "udp_ip_3") ) set_UdpIP( 3, s_hpv[i].value );
bosko001 7:7ea932eb31f6 457 else if( !strcmp( s_hpv[i].name, "udp_opseg_od") ) set_UdpIP( 4, s_hpv[i].value );
bosko001 7:7ea932eb31f6 458 else if( !strcmp( s_hpv[i].name, "udp_opseg_do") ) set_UdpIP( 5, s_hpv[i].value );
bosko001 7:7ea932eb31f6 459
bosko001 7:7ea932eb31f6 460 else if( !strcmp( s_hpv[i].name, "udp_port_1") ) set_UdpPort( 1, s_hpv[i].value );
bosko001 7:7ea932eb31f6 461 else if( !strcmp( s_hpv[i].name, "udp_port_2") ) set_UdpPort( 2, s_hpv[i].value );
bosko001 7:7ea932eb31f6 462 else if( !strcmp( s_hpv[i].name, "udp_port_3") ) set_UdpPort( 3, s_hpv[i].value );
bosko001 7:7ea932eb31f6 463 else if( !strcmp( s_hpv[i].name, "udp_port_opseg") ) set_UdpPort( 4, s_hpv[i].value );
bosko001 7:7ea932eb31f6 464
bosko001 7:7ea932eb31f6 465 else if( !strcmp( s_hpv[i].name, "tcp_ip_1") ) set_TcpIP( 1, s_hpv[i].value );
bosko001 7:7ea932eb31f6 466 else if( !strcmp( s_hpv[i].name, "tcp_ip_2") ) set_TcpIP( 2, s_hpv[i].value );
bosko001 7:7ea932eb31f6 467 else if( !strcmp( s_hpv[i].name, "tcp_ip_3") ) set_TcpIP( 3, s_hpv[i].value );
bosko001 7:7ea932eb31f6 468 else if( !strcmp( s_hpv[i].name, "tcp_opseg_od") ) set_TcpIP( 4, s_hpv[i].value );
bosko001 7:7ea932eb31f6 469 else if( !strcmp( s_hpv[i].name, "tcp_opseg_do") ) set_TcpIP( 5, s_hpv[i].value );
bosko001 7:7ea932eb31f6 470
bosko001 7:7ea932eb31f6 471 else if( !strcmp( s_hpv[i].name, "tcp_port_1") ) set_TcpPort( 1, s_hpv[i].value );
bosko001 7:7ea932eb31f6 472 else if( !strcmp( s_hpv[i].name, "tcp_port_2") ) set_TcpPort( 2, s_hpv[i].value );
bosko001 7:7ea932eb31f6 473 else if( !strcmp( s_hpv[i].name, "tcp_port_3") ) set_TcpPort( 3, s_hpv[i].value );
bosko001 7:7ea932eb31f6 474 else if( !strcmp( s_hpv[i].name, "tcp_port_opseg") ) set_TcpPort( 4, s_hpv[i].value );
bosko001 7:7ea932eb31f6 475
bosko001 7:7ea932eb31f6 476
bosko001 7:7ea932eb31f6 477 else if( !strcmp( s_hpv[i].name, "baud_rate") ) set_selected_option( "baud_rate" , s_hpv[i].value );
bosko001 7:7ea932eb31f6 478 else if( !strcmp( s_hpv[i].name, "parity") ) set_selected_option( "parity" , s_hpv[i].value );
bosko001 7:7ea932eb31f6 479 else if( !strcmp( s_hpv[i].name, "data_bits") ) { set_selected_option( "data_bits" , s_hpv[i].value ); }
bosko001 7:7ea932eb31f6 480 else if( !strcmp( s_hpv[i].name, "stop_bits") ) { set_selected_option( "stop_bits" , s_hpv[i].value ); }
bosko001 7:7ea932eb31f6 481 }
bosko001 7:7ea932eb31f6 482
bosko001 7:7ea932eb31f6 483 }
bosko001 7:7ea932eb31f6 484
bosko001 7:7ea932eb31f6 485
bosko001 7:7ea932eb31f6 486
bosko001 7:7ea932eb31f6 487 //ip_adresa=192.168.1.20&
bosko001 7:7ea932eb31f6 488 //netmask=255.255.255.0&
bosko001 7:7ea932eb31f6 489 //gateway=192.168.1.1&
bosko001 7:7ea932eb31f6 490 //udp_server_port=11000&
bosko001 7:7ea932eb31f6 491 //tcp_server_port=12000&
bosko001 7:7ea932eb31f6 492 //udp_ip_1=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 493 //udp_ip_2=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 494 //udp_ip_3=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 495 //udp_opseg_od=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 496 //udp_opseg_do=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 497 //udp_port_1=65535&
bosko001 7:7ea932eb31f6 498 //udp_port_2=&
bosko001 7:7ea932eb31f6 499 //udp_port_3=65535&
bosko001 7:7ea932eb31f6 500 //udp_port_opseg=65535&
bosko001 7:7ea932eb31f6 501 //tcp_ip_1=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 502 //tcp_ip_2=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 503 //tcp_ip_3=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 504 //tcp_opseg_od=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 505 //tcp_opseg_do=xxx.xxx.xxx.xxx&
bosko001 7:7ea932eb31f6 506 //tcp_port_1=65535&
bosko001 7:7ea932eb31f6 507 //tcp_port_2=&tcp_port_3=65535&
bosko001 7:7ea932eb31f6 508 //tcp_port_opseg=65535&
bosko001 7:7ea932eb31f6 509 //baud_rate=9600&
bosko001 7:7ea932eb31f6 510 //parity=none&data_bits=8&
bosko001 7:7ea932eb31f6 511 //stop_bits=1
bosko001 7:7ea932eb31f6 512
bosko001 7:7ea932eb31f6 513
bosko001 7:7ea932eb31f6 514
bosko001 7:7ea932eb31f6 515
bosko001 7:7ea932eb31f6 516 /*****************************************************************************/