nova proba

Committer:
Bosko Lekovic
Date:
Mon Jan 18 14:46:46 2021 +0100
Revision:
28:49bafc8bb056
Parent:
27:0772451fb880
novije

Who changed what in which revision?

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