nova proba

Committer:
bosko001
Date:
Wed Apr 08 08:41:16 2020 +0000
Revision:
3:1196befeace0
Parent:
2:45b351b4fc2a
Child:
4:7abcf4543282
ver 04 od 8.4.20

Who changed what in which revision?

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