nova verzija tcp+udp->serial com

Committer:
bosko001
Date:
Sat Apr 18 22:32:13 2020 +0000
Revision:
7:7ea932eb31f6
Parent:
5:c9a908749d4c
Child:
8:c0f54b381346
potpuno ispravan html - flash rad

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