nova proba

Committer:
bosko001
Date:
Sat Apr 11 17:11:38 2020 +0000
Revision:
4:7abcf4543282
Parent:
3:1196befeace0
Child:
5:c9a908749d4c
dxml bug removed

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 char* p_HTMLpage;
bosko001 2:45b351b4fc2a 12 dxml_t p_rootHTML;
bosko001 2:45b351b4fc2a 13
bosko001 3:1196befeace0 14 static dxml_t html_body, html_form, html_table, /*html_*/tr;
bosko001 3:1196befeace0 15
bosko001 3:1196befeace0 16 static dxml_t front_row[3];
bosko001 3:1196befeace0 17 static dxml_t UDPs[10];
bosko001 3:1196befeace0 18 static dxml_t TCPs[10];
bosko001 3:1196befeace0 19 static dxml_t serial[4];
bosko001 2:45b351b4fc2a 20
bosko001 2:45b351b4fc2a 21
bosko001 2:45b351b4fc2a 22 char *getHTML_free( void )
bosko001 2:45b351b4fc2a 23 {
bosko001 2:45b351b4fc2a 24 return dxml_toxml(p_rootHTML);
bosko001 2:45b351b4fc2a 25 }
bosko001 2:45b351b4fc2a 26
bosko001 2:45b351b4fc2a 27
bosko001 2:45b351b4fc2a 28
bosko001 3:1196befeace0 29 static void load_front_row()
bosko001 3:1196befeace0 30 {
bosko001 3:1196befeace0 31 int i = 0;
bosko001 3:1196befeace0 32 for (auto td = dxml_child(tr, "td")/*, i = 0*/; td; td = td->next)
bosko001 3:1196befeace0 33 {
bosko001 3:1196befeace0 34 auto input = dxml_child(td, "input");
bosko001 3:1196befeace0 35 front_row[i] = input;
bosko001 3:1196befeace0 36 ++i;
bosko001 3:1196befeace0 37 }
bosko001 3:1196befeace0 38
bosko001 3:1196befeace0 39 tr = tr->next;
bosko001 3:1196befeace0 40 }
bosko001 3:1196befeace0 41
bosko001 3:1196befeace0 42 static void load_second_row()
bosko001 3:1196befeace0 43 {
bosko001 3:1196befeace0 44 int i = 0;
bosko001 3:1196befeace0 45 for (auto td = dxml_child(tr, "td")/*, i = 0*/; td; td = td->next)
bosko001 3:1196befeace0 46 {
bosko001 3:1196befeace0 47 auto input = dxml_child(td, "input");
bosko001 3:1196befeace0 48 if (i == 0)
bosko001 3:1196befeace0 49 UDPs[0] = input;
bosko001 3:1196befeace0 50 else if(i == 1)
bosko001 3:1196befeace0 51 TCPs[0] = input;
bosko001 3:1196befeace0 52 ++i;
bosko001 3:1196befeace0 53 }
bosko001 3:1196befeace0 54
bosko001 3:1196befeace0 55 tr = tr->next;
bosko001 3:1196befeace0 56 }
bosko001 3:1196befeace0 57
bosko001 3:1196befeace0 58 static void load_udp_and_tcp(dxml_t& td)
bosko001 3:1196befeace0 59 {
bosko001 3:1196befeace0 60 for (int i = 0; i < 4; td = td->next)
bosko001 3:1196befeace0 61 {
bosko001 3:1196befeace0 62 dxml_t inputs[5];
bosko001 3:1196befeace0 63 int input_count = 0;
bosko001 3:1196befeace0 64 for (auto input = dxml_child(td, "input"); input; input = input->next)
bosko001 3:1196befeace0 65 inputs[input_count++] = input;
bosko001 3:1196befeace0 66
bosko001 3:1196befeace0 67 if (i < 2) // Load inputs into UDPs
bosko001 3:1196befeace0 68 {
bosko001 3:1196befeace0 69 for (int k = 0; k < input_count; ++k)
bosko001 3:1196befeace0 70 UDPs[i == 0 ? k + 1 : k + 6] = inputs[k];
bosko001 3:1196befeace0 71 }
bosko001 3:1196befeace0 72 else
bosko001 3:1196befeace0 73 {
bosko001 3:1196befeace0 74 for (int k = 0; k < input_count; ++k)
bosko001 3:1196befeace0 75 TCPs[i == 2 ? k + 1 : k + 6] = inputs[k];
bosko001 3:1196befeace0 76 }
bosko001 3:1196befeace0 77
bosko001 3:1196befeace0 78 ++i;
bosko001 3:1196befeace0 79 }
bosko001 3:1196befeace0 80 }
bosko001 3:1196befeace0 81
bosko001 3:1196befeace0 82 void load_serial(dxml_t& td)
bosko001 3:1196befeace0 83 {
bosko001 3:1196befeace0 84 auto select = dxml_child(td, "select");
bosko001 3:1196befeace0 85 for (int i = 0; select; select = select->next)
bosko001 3:1196befeace0 86 serial[i++] = select;
bosko001 3:1196befeace0 87 }
bosko001 3:1196befeace0 88
bosko001 3:1196befeace0 89
bosko001 3:1196befeace0 90 dxml_t get_serial_option(dxml_t s, int option_idx);
bosko001 3:1196befeace0 91 void init_html( void )
bosko001 3:1196befeace0 92 {
bosko001 3:1196befeace0 93
bosko001 3:1196befeace0 94 p_HTMLpage = (char*)malloc(sizeof(HTMLpage));
bosko001 3:1196befeace0 95 strcpy( p_HTMLpage, HTMLpage);
bosko001 3:1196befeace0 96 P_int("ucitavam html", sizeof(HTMLpage));
bosko001 3:1196befeace0 97
bosko001 3:1196befeace0 98
bosko001 3:1196befeace0 99 p_rootHTML = dxml_parse_str(p_HTMLpage, strlen(p_HTMLpage));
bosko001 3:1196befeace0 100 html_body = dxml_child(p_rootHTML, "body");
bosko001 3:1196befeace0 101 html_form = dxml_child(html_body, "form");
bosko001 3:1196befeace0 102 html_table = dxml_child(html_form, "table");
bosko001 3:1196befeace0 103 tr = dxml_child(html_table, "tr");
bosko001 3:1196befeace0 104
bosko001 3:1196befeace0 105 // //load_first_row();
bosko001 3:1196befeace0 106 load_front_row();
bosko001 3:1196befeace0 107 // P_str("front 1", (char*)dxml_attr(front_row[0], "value"));
bosko001 3:1196befeace0 108 // P_str("front 2", (char*)dxml_attr(front_row[1], "value"));
bosko001 3:1196befeace0 109 // P_str("front 3", (char*)dxml_attr(front_row[2], "value"));
bosko001 3:1196befeace0 110
bosko001 3:1196befeace0 111 load_second_row();
bosko001 3:1196befeace0 112 // P_str("UDP[0]", (char*)dxml_attr(UDPs[0], "value"));
bosko001 3:1196befeace0 113 // P_str("TCP[0]", (char*)dxml_attr(TCPs[0], "value"));
bosko001 3:1196befeace0 114 printf("\n\r");
bosko001 3:1196befeace0 115
bosko001 3:1196befeace0 116 auto td = dxml_child(tr, "td");
bosko001 3:1196befeace0 117 load_udp_and_tcp(td);
bosko001 3:1196befeace0 118 load_serial(td);
bosko001 3:1196befeace0 119
bosko001 3:1196befeace0 120 // for( int i=0; i<10; i++ ) P_str("UDP", (char*)dxml_attr(UDPs[i], "value"));
bosko001 3:1196befeace0 121 // for( int i=0; i<10; i++ ) P_str("TCP", (char*)dxml_attr(TCPs[i], "value"));
bosko001 3:1196befeace0 122
bosko001 3:1196befeace0 123
bosko001 3:1196befeace0 124 // for( int i=0; i<4; i++ )
bosko001 3:1196befeace0 125 // {
bosko001 3:1196befeace0 126 // {
bosko001 3:1196befeace0 127 // P_str("Serial", (char*)dxml_attr(serial[i], "name"));
bosko001 3:1196befeace0 128 // for(int j=0; dxml_attr(get_serial_option(serial[i], j), "value") != NULL; j++)
bosko001 3:1196befeace0 129 // P_str( (char*)dxml_attr(serial[i], "name"), (char *)dxml_attr(get_serial_option(serial[i], j), "value"));
bosko001 3:1196befeace0 130 // }
bosko001 3:1196befeace0 131 // }
bosko001 3:1196befeace0 132
bosko001 4:7abcf4543282 133 }
bosko001 4:7abcf4543282 134
bosko001 4:7abcf4543282 135 void test_HTML(void)
bosko001 4:7abcf4543282 136 {
bosko001 3:1196befeace0 137 extern const char *get_selected_option( const char *name_option );
bosko001 3:1196befeace0 138 extern const char * set_selected_option( const char* name_option, const char* value_option );
bosko001 3:1196befeace0 139
bosko001 3:1196befeace0 140 P_str( "selected bit rate" , (char*)get_selected_option( "baud_rate" ) );
bosko001 3:1196befeace0 141 P_str( "selected parity" , (char*)get_selected_option( "parity" ) );
bosko001 3:1196befeace0 142 P_str( "selected stop bits" , (char*)get_selected_option( "stop_bits" ) );
bosko001 3:1196befeace0 143 P_str( "selected data bits" , (char*)get_selected_option( "data_bits" ) );
bosko001 3:1196befeace0 144
bosko001 4:7abcf4543282 145 {
bosko001 4:7abcf4543282 146 extern UARTSerial *gp_scom;
bosko001 4:7abcf4543282 147 extern void sendScom( struct UARTSerial *p_scom, char *buffer, int val);
bosko001 4:7abcf4543282 148
bosko001 4:7abcf4543282 149 auto c = getHTML_free( );
bosko001 4:7abcf4543282 150 // n = p_soc->send(c, strlen(c));
bosko001 4:7abcf4543282 151 sendScom( gp_scom, c, strlen(c));
bosko001 4:7abcf4543282 152 free(c);
bosko001 4:7abcf4543282 153 }
bosko001 4:7abcf4543282 154
bosko001 4:7abcf4543282 155
bosko001 3:1196befeace0 156 P_str( "select bit rate 38400", set_selected_option( "baud_rate", "38400" ) );
bosko001 3:1196befeace0 157 P_str( "select bit parity ODD", set_selected_option( "parity", "odd" ) );
bosko001 3:1196befeace0 158 P_str( "select stop bits 1.5", set_selected_option( "stop_bits", "1.5" ) );
bosko001 3:1196befeace0 159 P_str( "select data bits 7", set_selected_option( "data_bits", "7" ) );
bosko001 3:1196befeace0 160
bosko001 4:7abcf4543282 161 {
bosko001 4:7abcf4543282 162 extern UARTSerial *gp_scom;
bosko001 4:7abcf4543282 163 extern void sendScom( struct UARTSerial *p_scom, char *buffer, int val);
bosko001 4:7abcf4543282 164
bosko001 4:7abcf4543282 165 auto c = getHTML_free( );
bosko001 4:7abcf4543282 166 // n = p_soc->send(c, strlen(c));
bosko001 4:7abcf4543282 167 sendScom( gp_scom, c, strlen(c));
bosko001 4:7abcf4543282 168 free(c);
bosko001 4:7abcf4543282 169 }
bosko001 4:7abcf4543282 170
bosko001 4:7abcf4543282 171
bosko001 3:1196befeace0 172 P_str( "selected bit rate" , (char*)get_selected_option( "baud_rate" ) );
bosko001 3:1196befeace0 173 P_str( "selected parity" , (char*)get_selected_option( "parity" ) );
bosko001 3:1196befeace0 174 P_str( "selected stop bits" , (char*)get_selected_option( "stop_bits" ) );
bosko001 3:1196befeace0 175 P_str( "selected data bits" , (char*)get_selected_option( "data_bits" ) );
bosko001 3:1196befeace0 176
bosko001 3:1196befeace0 177
bosko001 3:1196befeace0 178 }
bosko001 3:1196befeace0 179
bosko001 3:1196befeace0 180 const char *get_selected_option( const char *name_option )
bosko001 3:1196befeace0 181 {
bosko001 3:1196befeace0 182 for( int i=0; dxml_attr(serial[i], "name") != NULL; i++ )
bosko001 3:1196befeace0 183 {
bosko001 3:1196befeace0 184 char *ret;
bosko001 3:1196befeace0 185 if( !strcmp( (char*)dxml_attr(serial[i], "name"), name_option) )
bosko001 3:1196befeace0 186 {
bosko001 3:1196befeace0 187 for(int j=0; dxml_attr(get_serial_option(serial[i], j), "value") != NULL; j++)
bosko001 3:1196befeace0 188 {
bosko001 3:1196befeace0 189 if( dxml_attr( get_serial_option(serial[i],j), "selected" ) )
bosko001 3:1196befeace0 190 return dxml_attr(get_serial_option(serial[i], j), "value");
bosko001 3:1196befeace0 191 }
bosko001 3:1196befeace0 192 return dxml_attr(get_serial_option(serial[i], 0), "value");
bosko001 3:1196befeace0 193 }
bosko001 3:1196befeace0 194 }
bosko001 3:1196befeace0 195 return NULL;
bosko001 3:1196befeace0 196 }
bosko001 3:1196befeace0 197
bosko001 3:1196befeace0 198 const char * set_selected_option( const char* name_option, const char* value_option )
bosko001 3:1196befeace0 199 {
bosko001 3:1196befeace0 200 for( int i=0; dxml_attr(serial[i], "name") != NULL; i++ )
bosko001 3:1196befeace0 201 {
bosko001 3:1196befeace0 202 // printf(" i = %d \n\r", i );
bosko001 3:1196befeace0 203 char *ret;
bosko001 3:1196befeace0 204 if( !strcmp( (char*)dxml_attr(serial[i], "name"), name_option) )
bosko001 3:1196befeace0 205 {
bosko001 3:1196befeace0 206 for(int j=0; dxml_attr(get_serial_option(serial[i], j), "value") != NULL; j++)
bosko001 3:1196befeace0 207 {
bosko001 3:1196befeace0 208 // printf(" j=%d \n\r", j);
bosko001 3:1196befeace0 209 if( !strcmp( dxml_attr( get_serial_option(serial[i],j), "value"), value_option) )
bosko001 3:1196befeace0 210 {
bosko001 3:1196befeace0 211 if( !dxml_attr( get_serial_option(serial[i],j), "selected") )
bosko001 3:1196befeace0 212 {
bosko001 3:1196befeace0 213 for(int k=0; dxml_attr(get_serial_option(serial[i], k), "value") != NULL; k++)
bosko001 3:1196befeace0 214 {
bosko001 3:1196befeace0 215 // printf(" k=%d\n\r",k);
bosko001 3:1196befeace0 216 if( !strcmp( dxml_attr( get_serial_option(serial[i],k), "value"), value_option) )
bosko001 4:7abcf4543282 217 {
bosko001 4:7abcf4543282 218 printf(" kk=%d\n\r",k);
bosko001 4:7abcf4543282 219 dxml_set_attr( get_serial_option(serial[i],k), "selected", "ON" );
bosko001 4:7abcf4543282 220 }
bosko001 4:7abcf4543282 221 else
bosko001 4:7abcf4543282 222 {
bosko001 4:7abcf4543282 223 printf(" k=%d\n\r",k);
bosko001 4:7abcf4543282 224 dxml_set_attr( get_serial_option(serial[i],k), "selected", NULL );
bosko001 4:7abcf4543282 225 }
bosko001 3:1196befeace0 226 }
bosko001 3:1196befeace0 227 }
bosko001 3:1196befeace0 228 return value_option;
bosko001 3:1196befeace0 229 }
bosko001 3:1196befeace0 230 }
bosko001 3:1196befeace0 231 }
bosko001 3:1196befeace0 232 }
bosko001 3:1196befeace0 233
bosko001 3:1196befeace0 234 return NULL;
bosko001 3:1196befeace0 235
bosko001 3:1196befeace0 236 }
bosko001 3:1196befeace0 237
bosko001 3:1196befeace0 238
bosko001 3:1196befeace0 239 //dxml_t[3] get_front_row()
bosko001 3:1196befeace0 240 dxml_t* get_front_row()
bosko001 3:1196befeace0 241 {
bosko001 3:1196befeace0 242 return front_row;
bosko001 3:1196befeace0 243 }
bosko001 3:1196befeace0 244
bosko001 3:1196befeace0 245 //dxml_t[10] get_udp()
bosko001 3:1196befeace0 246 dxml_t* get_udp()
bosko001 3:1196befeace0 247 {
bosko001 3:1196befeace0 248 return UDPs;
bosko001 3:1196befeace0 249 }
bosko001 3:1196befeace0 250
bosko001 3:1196befeace0 251 //dxml_t[10] get_tcp()
bosko001 3:1196befeace0 252 dxml_t* get_tcp()
bosko001 3:1196befeace0 253 {
bosko001 3:1196befeace0 254 return TCPs;
bosko001 3:1196befeace0 255 }
bosko001 3:1196befeace0 256
bosko001 3:1196befeace0 257 //dxml_t[4] get_serial()
bosko001 3:1196befeace0 258 dxml_t* get_serial()
bosko001 3:1196befeace0 259 {
bosko001 3:1196befeace0 260 return serial;
bosko001 3:1196befeace0 261 }
bosko001 3:1196befeace0 262
bosko001 3:1196befeace0 263 dxml_t get_serial_option(dxml_t s, int option_idx)
bosko001 3:1196befeace0 264 {
bosko001 3:1196befeace0 265 auto rv = dxml_child(s, "option");
bosko001 3:1196befeace0 266 for (int i = 0; i < option_idx; ++i)
bosko001 3:1196befeace0 267 {
bosko001 3:1196befeace0 268 if( rv->next == NULL ) return NULL;
bosko001 3:1196befeace0 269 else rv = rv->next;
bosko001 3:1196befeace0 270 }
bosko001 3:1196befeace0 271 return rv;
bosko001 3:1196befeace0 272 }
bosko001 3:1196befeace0 273
bosko001 3:1196befeace0 274
bosko001 3:1196befeace0 275
bosko001 3:1196befeace0 276 extern struct S_FlashData *gps_fd;
bosko001 3:1196befeace0 277 // P_str( "FLASH IP ", gps_fd->s_EthAdd.ip );
bosko001 3:1196befeace0 278 // P_str( "FLASH MASK ", gps_fd->s_EthAdd.mask );
bosko001 3:1196befeace0 279 // P_str( "FLASH GATE ", gps_fd->s_EthAdd.gate );
bosko001 3:1196befeace0 280 //
bosko001 3:1196befeace0 281 // P_str( "FLASH UDP PORT ", gps_fd->serverPortUdp );
bosko001 3:1196befeace0 282 // P_str( "FLASH TCP PORT ", gps_fd->serverPortTcp );
bosko001 3:1196befeace0 283 //
bosko001 3:1196befeace0 284 // P_str( "FLASH UDP IP[0] ", gps_fd->s_EthAddRemUdp[0].ip );
bosko001 3:1196befeace0 285 // P_int( "FLASH UDP PORT[0] ", gps_fd->s_EthAddRemUdp[0].port );
bosko001 3:1196befeace0 286 // P_str( "FLASH TCP IP[0] ", gps_fd->s_EthAddRemTcp[0].ip );
bosko001 3:1196befeace0 287 // P_int( "FLASH TCP PORT[0] ", gps_fd->s_EthAddRemTcp[0].port );
bosko001 3:1196befeace0 288 //
bosko001 3:1196befeace0 289 // P_int( "FLASH SERIAL BAUD ", gps_fd->baudRate );
bosko001 3:1196befeace0 290 // P_int( "FLASH SERIAL BAUD ", gps_fd->parity );
bosko001 3:1196befeace0 291 // P_int( "FLASH SERIAL BAUD ", gps_fd->dataBits );
bosko001 3:1196befeace0 292 // P_int( "FLASH SERIAL BAUD ", gps_fd->stopBits );
bosko001 3:1196befeace0 293
bosko001 3:1196befeace0 294 void putHTMLintoFlash( void )
bosko001 3:1196befeace0 295 {
bosko001 3:1196befeace0 296 strncpy( gps_fd->s_EthAdd.ip, dxml_attr(front_row[0], "value"), 16 );
bosko001 3:1196befeace0 297 strncpy( gps_fd->s_EthAdd.mask, dxml_attr(front_row[1], "value"), 16 );
bosko001 3:1196befeace0 298 strncpy( gps_fd->s_EthAdd.gate, dxml_attr(front_row[2], "value"), 16 );
bosko001 3:1196befeace0 299
bosko001 3:1196befeace0 300 strncpy( gps_fd->serverPortUdp, dxml_attr(UDPs[0], "value"), 6 );
bosko001 3:1196befeace0 301 strncpy( gps_fd->serverPortTcp, dxml_attr(TCPs[0], "value"), 6 );
bosko001 3:1196befeace0 302
bosko001 3:1196befeace0 303 strncpy( gps_fd->s_EthAddRemUdp[0].ip, dxml_attr(UDPs[1], "value"), 16 );
bosko001 3:1196befeace0 304 gps_fd->s_EthAddRemUdp[0].port = atoi( dxml_attr(UDPs[6], "value") );
bosko001 3:1196befeace0 305
bosko001 3:1196befeace0 306 strncpy( gps_fd->s_EthAddRemTcp[0].ip, dxml_attr(TCPs[1], "value"), 16 );
bosko001 3:1196befeace0 307 gps_fd->s_EthAddRemTcp[0].port = atoi( dxml_attr(TCPs[6], "value") );
bosko001 3:1196befeace0 308
bosko001 3:1196befeace0 309 fillDataIntoFlash( );
bosko001 3:1196befeace0 310 }
bosko001 3:1196befeace0 311
bosko001 3:1196befeace0 312
bosko001 3:1196befeace0 313
bosko001 3:1196befeace0 314