/** * @brief Parse reply, D-Bus array type */ static gboolean set_reply_to_qmi_data(DBusMessageIter *main_iter, struct qmi_data *qmi) { DBusMessageIter dict; DBG(); if(dbus_message_iter_get_arg_type(main_iter) != DBUS_TYPE_ARRAY) { connman_error("Message is not a D-Bus array type"); return FALSE; } dbus_message_iter_recurse(main_iter, &dict); /* Parse each D-Bus dictionary entry */ while(dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter entry; dbus_message_iter_recurse(&dict, &entry); /* Set new key/ value properties */ update_network(qmi, &entry); dbus_message_iter_next(&dict); } return TRUE; }
float train_network_datum(network net) { #ifdef GPU if(gpu_index >= 0) return train_network_datum_gpu(net); #endif *net.seen += net.batch; net.train = 1; forward_network(net); backward_network(net); float error = *net.cost; if(((*net.seen)/net.batch)%net.subdivisions == 0) update_network(net); return error; }
static void update_current_network(struct _adapter *adapter, struct ndis_wlan_bssid_ex *pnetwork) { struct mlme_priv *pmlmepriv = &adapter->mlmepriv; if (is_same_network(&(pmlmepriv->cur_network.network), pnetwork)) { update_network(&(pmlmepriv->cur_network.network), pnetwork, adapter); r8712_update_protection(adapter, (pmlmepriv->cur_network.network.IEs) + sizeof(struct NDIS_802_11_FIXED_IEs), pmlmepriv->cur_network.network.IELength); } }
float train_network_datum(network net, float *x, float *y) { #ifdef GPU if(gpu_index >= 0) return train_network_datum_gpu(net, x, y); #endif network_state state; state.input = x; state.truth = y; state.train = 1; forward_network(net, state); backward_network(net, state); float error = get_network_cost(net); if((net.seen/net.batch)%net.subdivisions == 0) update_network(net); return error; }
float train_network_batch(network net, data d, int n) { int i,j; network_state state; state.train = 1; float sum = 0; int batch = 2; for(i = 0; i < n; ++i){ for(j = 0; j < batch; ++j){ int index = rand()%d.X.rows; state.input = d.X.vals[index]; state.truth = d.y.vals[index]; forward_network(net, state); backward_network(net, state); sum += get_network_cost(net); } update_network(net); } return (float)sum/(n*batch); }
void nn_connectometry::on_run_clicked() { if(ui->foi->currentIndex() < 0) return; on_stop_clicked(); nna.t.learning_rate = ui->learning_rate->value()*0.01f; nna.t.momentum = ui->momentum->value(); nna.t.batch_size = 64; nna.t.epoch = ui->epoch->value(); nna.foi_index = ui->foi->currentIndex(); nna.is_regression = ui->nn_regression->isChecked(); nna.seed_search = 0; nna.otsu = ui->otsu->value(); nna.cv_fold = ui->cv->value(); nna.normalize_value = ui->norm_output->isEnabled() && ui->norm_output->isChecked(); //nna.t.error_table.resize(nna.nn.get_output_size()*nna.nn.get_output_size()); if(!nna.run(ui->network_text->text().toStdString())) { QMessageBox::information(this,"Error",nna.error_msg.c_str(),0); return; } ui->test_subjects->setRowCount(0); cur_fold = 0; s2 = s3 = s4 = 0; chart1->removeAllSeries(); chart2->removeAllSeries(); chart3->removeAllSeries(); chart4->removeAllSeries(); if(timer) delete timer; timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(update_network())); timer->setInterval(1000); timer->start(); }
int main(int argc,char *argv[]) { node_t node_inser_info; sensor_t sensor_inser_info; network_t network_inser_info; memset(&node_inser_info,0,sizeof(node_t)); memset(&sensor_inser_info,0,sizeof(sensor_t)); memset(&network_inser_info,0,sizeof(network_t)); node_t node_info[10000]; sensor_t sensor_info[10000]; network_t network_info[10000]; memset(&node_info,0,sizeof(node_info)); memset(&sensor_info,0,sizeof(sensor_info)); memset(&network_info,0,sizeof(network_info)); MYSQL mysql; get_db_handler(&mysql); int num = 0; node_inser_info.node_id = num; node_inser_info.power = num; node_inser_info.position.x = 50 + num % 10; node_inser_info.position.y = 40 + num % 10; strcpy(node_inser_info.network_name,"10.16.17.0"); strcpy(node_inser_info.work_state,"work"); strcpy(node_inser_info.node_status,"normal"); update_node_info(mysql,node_inser_info); network_inser_info.node_id = num; network_inser_info.parent_id = num; network_inser_info.quality = 100; strcpy(network_inser_info.network_name,"10.16.17.0"); update_network(mysql,network_inser_info); for(num = 1;num <= 10;num++){ node_inser_info.node_id = num; node_inser_info.power = 90 + num % 10; node_inser_info.position.x = 50 + num % 10; node_inser_info.position.y = 40 + num % 10; strcpy(node_inser_info.network_name,"10.16.17.0"); strcpy(node_inser_info.work_state,"work"); strcpy(node_inser_info.node_status,"normal"); update_node_info(mysql,node_inser_info); network_inser_info.node_id = num; network_inser_info.parent_id = num - 1; network_inser_info.quality = 100; strcpy(network_inser_info.network_name,"10.16.17.0"); update_network(mysql,network_inser_info); strcpy(sensor_inser_info.network_name,"10.16.17.0"); sensor_inser_info.node_id = num % 300; sensor_inser_info.temp = 26 + num % 10; sensor_inser_info.photo = 98 + num % 10; sensor_inser_info.sound = 21 + num % 10; sensor_inser_info.x_acc = 34 + num % 10; sensor_inser_info.y_acc = 0 + num % 10; sensor_inser_info.x_mag = 22 + num % 10; sensor_inser_info.y_mag = 33 + num % 10; insert_sense_record(mysql,sensor_inser_info); } printf("===================insert end=================\n"); long i,j,k,l; for(l = 0; l< 10;l++){ //j = get_all_record(mysql,sensor_info); //j = get_absolute_record(mysql,sensor_info,"10.16.17.0",99,"temp","2012-09-23 11:21:41","2012-09-23 11:21:42"); k = get_latest_record(mysql,sensor_info,"10.16.17.0",1,"sound"); //j = get_relative_record(mysql,sensor_info,"10.16.17.0",99,"temp","20120927220609",30); j = get_all_node_info(mysql,node_info); //j = get_network_info(mysql,network_info); printf("j = %ld\n",j); if(j==-1) return -1; else{ for(i = 0;i < j;i++){ printf("network_id:%d \t" ,node_info[i].network_id); printf("network_name:%s \t" ,node_info[i].network_name); printf("node_id:%d\t" ,node_info[i].node_id); printf("parent_id:%d\t" ,node_info[i].parent_id); printf("power:%d\t" ,node_info[i].power); printf("position_x:%6.2lf\t" ,node_info[i].position.x); printf("position_y:%6.2lf\t" ,node_info[i].position.y); printf("\n"); //printf("network_id:%d \t" ,network_info[i].network_id); //printf("network_name:%s \t" ,network_info[i].network_name); //printf("node_id:%d \t" ,network_info[i].node_id); //printf("parent_id:%d \t" ,network_info[i].parent_id); //printf("quality:%d \t" ,network_info[i].quality); //printf("\n"); } for(i = 0;i< k;i++){ printf("network_id:%d\t" ,sensor_info[i].network_id); printf("network_name:%s\t" ,sensor_info[i].network_name); printf("node_id:%d\t" ,sensor_info[i].node_id); printf("temp:%6.2lf\t" ,sensor_info[i].temp); printf("photo:%6.2lf\t" ,sensor_info[i].photo); printf("sound:%6.2lf\t" ,sensor_info[i].sound); //printf("x_acc:%6.2lf\t" ,sensor_info[i].x_acc); //printf("y_acc:%6.2lf\t" ,sensor_info[i].y_acc); //printf("x_mag:%6.2lf\t" ,sensor_info[i].x_mag); //printf("y_mag:%6.2lf\t" ,sensor_info[i].y_mag); printf("insert_time:%s\t" ,sensor_info[i].time); printf("\n"); } } sleep(1); } mysql_close(&mysql); return 0; }
int gen_rand_network_metrop(Network **RN_p,int real_vec13[14]) { int rc=RC_OK; int sin_num_of_switchs,dbl_num_of_switchs,num_at_t; //int s2,t1,t2; int i,j,l; int k; // number of succesful switches int w; // total number of switches //int tries; //number of tries to find proper pair of edges to exchange //int twin_i,twin_j; Network *RN; int rand_network_checked=FALSE; Res_tbl met_res_tbl; //int real_vec13[14]; int rand_vec13[14]; //int sub13[14]; //int add13[14]; //double E1,E2,dE; double E1,E2; int snover,dnover; // maximum # of graph changes at any temperature //int nlimit,snlimit,dnlimit; // maximum # of succesful graph changes at any temperature int snlimit,dnlimit; // maximum # of succesful graph changes at any temperature //int make_change; //int numsucc; // how many successful switches already made double t; // the temperature int success; int dispair=0; double dummy; int switches_range; double *switch_ratio_arr; switch_ratio_arr=(double*)calloc(GNRL_ST.rnd_net_num+1,sizeof(double)); sin_num_of_switchs=0; if(G_N->e_sin_num<=1) sin_num_of_switchs=0; else { // num of switches is round(10*(1+rand)*#edges) //num of edges in undirfecetd is actually *2 therefore divided by 2 switches_range=(int)(2*GNRL_ST.r_switch_factor*G_N->e_sin_num); sin_num_of_switchs=(int)switches_range+get_rand((int)switches_range); } if(G_N->e_dbl_num<=1) dbl_num_of_switchs=0; else { // num of switches is round(10*(1+rand)*#edges) //num of edges in undirfecetd is actually *2 therefore divided by 2 switches_range=(int)(2*GNRL_ST.r_switch_factor*G_N->e_dbl_num/2); dbl_num_of_switchs=(int)switches_range+get_rand((int)switches_range); } t=GNRL_ST.t_init; if (GNRL_ST.use_stubs_method==TRUE) { success=0; dispair=0; while ((success==FALSE)&&(dispair<GEN_NETWORK_DISPAIR)) { //printf("trying ron\n"); rc=gen_rand_network_stubs_method(&RN); if(rc==RC_OK) success=TRUE; else success=FALSE; if (success==FALSE) { //printf("dispair - discard\n"); dispair++; } } if (dispair==GEN_NETWORK_DISPAIR) // give up try switch method gen_rand_network_switches_method_conserve_double_edges(&RN,&dummy); else { success=update_network(RN,G_N); if (!success) { printf("Error - degrees don't match\n"); at_exit(-1); } //shuffle_double_edges(RN); if (DEBUG_LEVEL>20 && GNRL_ST.out_log_flag) { fprintf(GNRL_ST.log_fp,"The network :\n\n"); for (l=1;l<=(*RN).edges_num;l++) fprintf(GNRL_ST.log_fp,"%d %d %d\n",(*RN).e_arr[l].t,(*RN).e_arr[l].s,1); } } } else gen_rand_network_switches_method_conserve_double_edges(&RN, &dummy); /**************************************************************/ /**************************************************************/ /**************************************************************/ /* Part II - metropolis algorithm. Perform switches with probability*/ /**************************************************************/ /**************************************************************/ /**************************************************************/ /**************************************************************/ /* metropolis parameters depend on num_of _switches*/ /* otuput real network to _METROP file */ init_res_tbl(&met_res_tbl); list64_init(&met_res_tbl.real); met_motifs_search_real(RN,&met_res_tbl,rand_vec13); list64_free_mem(met_res_tbl.real); E1=energy(real_vec13,rand_vec13); w=0; if(GNRL_ST.out_metrop_mat_flag) { fprintf(GNRL_ST.mat_metrop_fp,"\nreal network\n"); fprintf(GNRL_ST.mat_metrop_fp,"E=%lf T=%lf\n",E1,t); fprintf(GNRL_ST.mat_metrop_fp,"Real triadic census :\n "); output13(real_vec13,GNRL_ST.mat_metrop_fp); fprintf(GNRL_ST.mat_metrop_fp,"random network\n"); fprintf(GNRL_ST.mat_metrop_fp,"%lf,%lf \n",E1,t); fprintf(GNRL_ST.mat_metrop_fp,"Initial random triadic census :\n "); output13(rand_vec13,GNRL_ST.mat_metrop_fp); } /* nover=sin_num_of_switchs*GNRL_ST.iteration_factor; nlimit=nover/10; k=0; num_at_t=0; sin_metrop_switches(&RN,nover,nlimit,GNRL_ST.t_init,real_vec13,rand_vec13); */ if (dbl_num_of_switchs==0) { snover=sin_num_of_switchs*(int)GNRL_ST.iteration_factor; snlimit=snover/10; t=sin_metrop_switches(&RN,snover,snlimit,GNRL_ST.t_init,real_vec13,rand_vec13); } else { dnover=dbl_num_of_switchs*(int)GNRL_ST.iteration_factor/10; dnlimit=dnover/10; if (dnover<10) { dnover=dbl_num_of_switchs; dnlimit=dnover; } t=dbl_metrop_switches(&RN,dnover,dnlimit,GNRL_ST.t_init,real_vec13,rand_vec13); snover=sin_num_of_switchs*(int)GNRL_ST.iteration_factor/10; snlimit=snover/10; k=0; num_at_t=0; t=sin_metrop_switches(&RN,snover,snlimit,t,real_vec13,rand_vec13); if(GNRL_ST.out_metrop_mat_flag) { fprintf(GNRL_ST.mat_metrop_fp,"End E\n"); printf("End E\n"); } for (i=1;i<10;i++) { E2=energy(real_vec13,rand_vec13); if (E2>0) { t=dbl_metrop_switches(&RN,dnover,dnlimit,t,real_vec13,rand_vec13); t=sin_metrop_switches(&RN,snover,snlimit,t,real_vec13,rand_vec13); } } } //check that there are no self edges. If there are any then start again rand_network_checked = TRUE; if(GNRL_ST.calc_self_edges == FALSE){ for(i=1;i<=RN->vertices_num;i++) { if( MatGet(RN->mat,i,i)==1 ) { printf("Self edges still exist building random graph again\n"); rand_network_checked=FALSE; free_network_mem(RN); break; } } } //merge lists to RN->e_arr // j=0; for(i=1;i<=RN->e_dbl_num;i++) { RN->e_arr[++j].s=RN->e_arr_dbl[i].s; RN->e_arr[j].t=RN->e_arr_dbl[i].t; } for(i=1;i<=RN->e_sin_num;i++) { RN->e_arr[++j].s=RN->e_arr_sin[i].s; RN->e_arr[j].t=RN->e_arr_sin[i].t; } if(DEBUG_LEVEL>1 && GNRL_ST.out_metrop_mat_flag) { fprintf(GNRL_ST.mat_metrop_fp,"The network :\n"); for (i=1;i<=RN->edges_num;i++) fprintf(GNRL_ST.mat_metrop_fp,"%d %d %d\n",RN->e_arr[i].t,RN->e_arr[i].s,1); fprintf(GNRL_ST.mat_metrop_fp,"End of network\n"); fprintf(GNRL_ST.mat_metrop_fp,"\n\n"); } if(GNRL_ST.out_metrop_mat_flag) { fprintf(GNRL_ST.mat_metrop_fp,"Real triadic census :\n "); output13(real_vec13,GNRL_ST.mat_metrop_fp); fprintf(GNRL_ST.mat_metrop_fp,"Final random triadic census :\n "); output13(rand_vec13,GNRL_ST.mat_metrop_fp); } *RN_p=RN; return RC_OK; }
/** * @brief Signal handler for technology changed signal from qmi-dbus */ static gboolean on_handle_technology_changed(DBusConnection *conn, DBusMessage *message, gpointer unused) { DBusMessageIter message_iter; GHashTableIter hash_iter; gpointer key, value; struct qmi_data *qmi = NULL; /* Get object path of this message */ const gchar *object_path = dbus_message_get_path(message);; DBG("Object path %s", object_path); if(dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) { const char *dbus_error = dbus_message_get_error_name(message); connman_error("%s", dbus_error); return FALSE; } if(dbus_message_iter_init(message, &message_iter) == FALSE) { connman_error("Failure init ITER"); return FALSE; } if(dbus_message_iter_get_arg_type(&message_iter) == DBUS_TYPE_INVALID) { connman_error("Invalid D-Bus type"); return FALSE; } if(object_path) { /* Find qmi device data to object path */ g_hash_table_iter_init (&hash_iter, qmi_hash); while (g_hash_table_iter_next (&hash_iter, &key, &value)) { qmi = (struct qmi_data *)value; if(g_strcmp0(object_path, qmi->object_path) == 0) { break; } else { qmi = NULL; } } } if(qmi == NULL) { connman_error("No qmi device to object path %s", object_path); return FALSE; } /* Update new property value */ update_network(qmi, &message_iter); return TRUE; }
/* Caller must hold pmlmepriv->lock first. */ static void update_scanned_network(struct _adapter *adapter, struct ndis_wlan_bssid_ex *target) { struct list_head *plist, *phead; u32 bssid_ex_sz; struct mlme_priv *pmlmepriv = &adapter->mlmepriv; struct __queue *queue = &pmlmepriv->scanned_queue; struct wlan_network *pnetwork = NULL; struct wlan_network *oldest = NULL; phead = get_list_head(queue); plist = get_next(phead); while (1) { if (end_of_queue_search(phead, plist) == true) break; pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list); if (is_same_network(&pnetwork->network, target)) break; if ((oldest == ((struct wlan_network *)0)) || time_after((unsigned long)oldest->last_scanned, (unsigned long)pnetwork->last_scanned)) oldest = pnetwork; plist = get_next(plist); } /* If we didn't find a match, then get a new network slot to initialize * with this beacon's information */ if (end_of_queue_search(phead, plist) == true) { if (_queue_empty(&pmlmepriv->free_bss_pool) == true) { /* If there are no more slots, expire the oldest */ pnetwork = oldest; target->Rssi = (pnetwork->network.Rssi + target->Rssi) / 2; memcpy(&pnetwork->network, target, r8712_get_ndis_wlan_bssid_ex_sz(target)); pnetwork->last_scanned = jiffies; } else { /* Otherwise just pull from the free list */ /* update scan_time */ pnetwork = alloc_network(pmlmepriv); if (pnetwork == NULL) return; bssid_ex_sz = r8712_get_ndis_wlan_bssid_ex_sz(target); target->Length = bssid_ex_sz; memcpy(&pnetwork->network, target, bssid_ex_sz); list_insert_tail(&pnetwork->list, &queue->queue); } } else { /* we have an entry and we are going to update it. But * this entry may be already expired. In this case we * do the same as we found a new net and call the new_net * handler */ update_network(&pnetwork->network, target, adapter); pnetwork->last_scanned = jiffies; } }
// 8. LOAD_CONFIG_FILE // test: HTTP://192.168.1.155/cgi-bin/Flash2AppREMOTEM_load_config_file.cgi?path=/upload/input.xml static void proc_cmd_load_config_file(struct mg_connection* conn, const struct mg_request_info* request_info) { char configXmlPath[200]; char inputXmlPath[200]; char str_file_path[200]; char *address = 0, *netmask = 0, *gateway = 0; int dhcp = 0; char* broadcast_xml_field; char*rec_pre_xml_field; int found = 0; int isNetUpdate = 0; get_qsvar(request_info, "path", str_file_path, sizeof(str_file_path)); if (strlen(str_file_path) == 0) { mg_printf(conn, "HTTP/1.0 200 OK\r\n\r\nerrno=%d\r\n", INPUT_PARAM_NOT_SPECIFIED); return; } sprintf(inputXmlPath, "%s%s", ODI_HOME, str_file_path); sprintf(configXmlPath, "%s", ODI_CONFIG_XML); logger_remotem("load_config_file: merge XML Config File: from %s to %s", inputXmlPath, ODI_CONFIG_XML); struct my_file xmlfile = MY_STRUCT_FILE_INITIALIZER; if (!my_file_stat(inputXmlPath, &xmlfile)) { logger_remotem("No Input Config file to Load %s", inputXmlPath); send_http_error(conn, 404, "No Input Config file to Load ", "%s not found", inputXmlPath); goto leave; } if (!my_file_stat(ODI_CONFIG_XML, &xmlfile)) { logger_remotem("No destination Config file to Merge %s", ODI_CONFIG_XML); send_http_error(conn, 404, "No original config file to compare for merge ", "%s not found", ODI_CONFIG_XML); goto leave; } // read network file logger_remotem("Start merge XML Config File: %s", inputXmlPath); xmlDocPtr inputXmlDocumentPointer = xmlParseFile(inputXmlPath); if (inputXmlDocumentPointer == 0) { logger_remotem("LOAD_CONFIG_FILE: input XML not well formed %s", inputXmlPath); mg_printf(conn, "HTTP/1.0 200 OK\r\n\r\nInputXML file is not well-formed.\r\n"); return; } xmlDocPtr configXmlDocumentPointer = xmlParseFile(ODI_CONFIG_XML); if (configXmlDocumentPointer == 0) { logger_remotem("LOAD_CONFIG_FILE: config XML not well formed %s", ODI_CONFIG_XML); mg_printf(conn, "HTTP/1.0 200 OK\r\n\r\nConfiguration XML file is not well-formed.\r\n"); return; } // doc check xmlNodePtr cur = xmlDocGetRootElement(inputXmlDocumentPointer); if (cur == NULL) { logger_remotem("LOAD_CONFIG_FILE: input XML is empty"); xmlFreeDoc(configXmlDocumentPointer); xmlFreeDoc(inputXmlDocumentPointer); goto leave; } // config-meta check if (xmlStrcmp(cur->name, (const xmlChar*)"config-metadata")) { logger_remotem("LOAD_CONFIG_FILE: config-metadata tag not found"); xmlFreeDoc(configXmlDocumentPointer); xmlFreeDoc(inputXmlDocumentPointer); goto leave; } xmlNodePtr destParent = xmlDocGetRootElement(configXmlDocumentPointer); //node not found if (destParent == NULL) { logger_remotem("LOAD_CONFIG_FILE: empty doc"); xmlFreeDoc(configXmlDocumentPointer); xmlFreeDoc(inputXmlDocumentPointer); goto leave; } if (xmlStrcmp(destParent->name, (const xmlChar*)"config-metadata")) { logger_remotem("LOAD_CONFIG_FILE: root node != config-metadata"); xmlFreeDoc(configXmlDocumentPointer); xmlFreeDoc(inputXmlDocumentPointer); goto leave; } destParent = destParent->xmlChildrenNode; while (destParent) { if ((!xmlStrcmp(destParent->name, (const xmlChar*)"config"))) { found = 1; //Parse child content for field that need reboot xmlNodePtr info = destParent->xmlChildrenNode; while (info != NULL) { if (!xmlStrcmp(info->name, (const xmlChar*)"remotem_broadcast_ip")) { // logger_info("Tag 1: %s", info->name); // logger_info("Content: %s", (char *)xmlNodeGetContent(info)); broadcast_xml_field = (char*)xmlNodeGetContent(info); } else if (!xmlStrcmp(info->name, (const xmlChar *) "rec_pre")) { // logger_info("Tag 2: %s", info->name); // logger_info("Content: %s", (char *)xmlNodeGetContent(info)); rec_pre_xml_field = (char*)xmlNodeGetContent(info); } info = info->next; } break; } destParent = destParent->next; } if (!found) { logger_remotem("LOAD_CONFIG_FILE: config tag not found in %s", configXmlPath); xmlFreeDoc(configXmlDocumentPointer); xmlFreeDoc(inputXmlDocumentPointer); goto leave; } cur = cur->xmlChildrenNode; xmlNodePtr child = NULL; char *new_date = 0, *new_time = 0, *new_tz = 0; char str_comm[200]; unsigned int config_change_reboot = 0; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar*)"config"))) { child = cur->xmlChildrenNode; while (child != NULL) { if (!(xmlStrcmp(child->name, (const xmlChar*)"text"))) { ; } else if (!(xmlStrcmp(child->name, (const xmlChar*)"dvr_id"))) { // cannot change DVR ID ; } else if (!(xmlStrcmp(child->name, (const xmlChar*)"dts_date"))) { new_date = (char*)xmlNodeGetContent(child); if (strlen(new_date) == 10) // Check for valid date { logger_remotem("LOAD_CONFIG_FILE: setting date %s", new_date); modifytree(&destParent, child); } } else if (!(xmlStrcmp(child->name, (const xmlChar*)"dts_time"))) { new_time = (char*)xmlNodeGetContent(child); if (strlen(new_time) == 8) // Check for valid time { logger_remotem("LOAD_CONFIG_FILE: setting time %s", new_time); modifytree(&destParent, child); } } else if (!(xmlStrcmp(child->name, (const xmlChar*)"dvr_name"))) { char* str = (char*)xmlNodeGetContent(child); if (strlen(str) > 1) { logger_remotem("LOAD_CONFIG_FILE: setting dvr_name %s", str); modifytree(&destParent, child); set_dvr_name(str); } } else if (!(xmlStrcmp(child->name, (const xmlChar*)"ops_carnum"))) { char* str = (char*)xmlNodeGetContent(child); if (strlen(str) > 1) // Check for valid time { logger_remotem("LOAD_CONFIG_FILE: setting ops_carnum %s", str); modifytree(&destParent, child); set_dvr_name(str); } } else if (!(xmlStrcmp(child->name, (const xmlChar*)"usb_login"))) { char* str = (char*)xmlNodeGetContent(child); if (strlen(str) > 1) // Check for valid time { logger_remotem("LOAD_CONFIG_FILE: setting usb_login %s", str); modifytree(&destParent, child); set_assignable(str); } } else if (!(xmlStrcmp(child->name, (const xmlChar*)"dts_tz"))) { new_tz = (char*)xmlNodeGetContent(child); modifytree(&destParent, child); char ptr[strlen(new_tz) + 1]; int i, j = 0; for (i = 0; new_tz[i] != ' '; i++) { // skip till space } i++; // move up from the space for (i; new_tz[i] != '\0'; i++) { ptr[j++] = new_tz[i]; } ptr[j] = '\0'; memset(str_comm, 0, 200); sprintf(str_comm, "export TZ=%s", ptr); system(str_comm); } else if (!(xmlStrcmp(child->name, (const xmlChar*)"eth_dhcp"))) { isNetUpdate = 1; if (!(xmlStrcmp((const xmlChar*)xmlNodeGetContent(child), (const xmlChar*)"true"))) { dhcp = 1; logger_remotem("LOAD_CONFIG_FILE: change to DHCP"); } else { dhcp = 0; logger_remotem("LOAD_CONFIG_FILE: DHCP is static"); } modifytree(&destParent, child); } else if (!(xmlStrcmp(child->name, (const xmlChar*)"eth_addr"))) { address = (char *)xmlNodeGetContent(child); if (address != NULL && strlen(address) > 7) { isNetUpdate = 1; modifytree(&destParent, child); } } else if (!(xmlStrcmp(child->name, (const xmlChar*)"eth_mask"))) { netmask = (char*)xmlNodeGetContent(child); if (netmask != NULL && strlen(netmask) > 7) { isNetUpdate = 1; modifytree(&destParent, child); } } else if (!(xmlStrcmp(child->name, (const xmlChar*)"eth_gate"))) { gateway = (char*)xmlNodeGetContent(child); if (gateway != NULL && strlen(gateway) > 7) { isNetUpdate = 1; modifytree(&destParent, child); } // Set flag for config update item need to reboot to apply change } else if (!(xmlStrcmp(child->name, (const xmlChar*)"remotem_broadcast_ip"))) { logger_info("New: %s Old: %s", xmlNodeGetContent(child), broadcast_xml_field); if (strcmp((char*)xmlNodeGetContent(child), broadcast_xml_field)) { config_change_reboot = 1; } modifytree(&destParent, child); } else if (!(xmlStrcmp(child->name, (const xmlChar*)"rec_pre"))) { if (rec_pre_xml_field == NULL) { config_change_reboot = 1; } else if (strcmp((char*)xmlNodeGetContent(child), rec_pre_xml_field)) { if (strncmp(get_hw_version(), "3", 1)) // Only update when >= v4.0 { config_change_reboot = 1; } } modifytree(&destParent, child); } else { if (modifytree(&destParent, child) == -1) { logger_remotem("LOAD_CONFIG_FILE: %s doesn't contain %s tag", configXmlPath, (char*)child->name); } } child = child->next; } } cur = cur->next; } // end while loop until NULL all elements processed if (new_date == NULL && new_time == NULL) { logger_remotem("%s: date and time are null", __FUNCTION__); } else { set_sys_clock(new_date, new_time); } mg_printf(conn, "HTTP/1.0 200 OK\r\n\r\nerrno=0\r\n"); if (isNetUpdate) { update_network(dhcp, address, netmask, gateway); } logger_remotem("LOAD_CONFIG_FILE: saving new config, size=%d", xmlSaveFileEnc(configXmlPath, configXmlDocumentPointer, "UTF-8")); leave: if (inputXmlDocumentPointer) { xmlFreeDoc(inputXmlDocumentPointer); } if (configXmlDocumentPointer) { xmlFreeDoc(configXmlDocumentPointer); } if (config_change_reboot == 1) { logger_info("Config item change need system reboot"); // write_command_to_serial_port("RST\r\n"); // sleep(1); system("reboot"); } }
// Update network settings from /odi/conf/config.xml file void configure_network() { struct my_file xmlfile = MY_STRUCT_FILE_INITIALIZER; if (!my_file_stat(ODI_CONFIG_XML, &xmlfile)) { logger_remotem("Config file not found: %s", ODI_CONFIG_XML); return; } xmlDocPtr configXmlDocumentPointer = xmlParseFile(ODI_CONFIG_XML); if (configXmlDocumentPointer == 0) { logger_error("Configure network: config XML not well formed %s", ODI_CONFIG_XML); return; } // doc check xmlNodePtr cur = xmlDocGetRootElement(configXmlDocumentPointer); if (cur == NULL) { logger_error("Configure network: input XML is empty"); xmlFreeDoc(configXmlDocumentPointer); return; } // config-meta check if (xmlStrcmp(cur->name, (const xmlChar*)"config-metadata")) { logger_remotem("Configure network: config-metadata tag not found"); xmlFreeDoc(configXmlDocumentPointer); return; } cur = cur->xmlChildrenNode; xmlNodePtr child = NULL; char *address = 0, *netmask = 0, *gateway = 0; int dhcp = 0; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar*)"config"))) { child = cur->xmlChildrenNode; while (child != NULL) { if (!(xmlStrcmp(child->name, (const xmlChar*)"text"))) { ; } else if (!(xmlStrcmp(child->name, (const xmlChar*)"eth_dhcp"))) { if (!(xmlStrcmp((const xmlChar*)xmlNodeGetContent(child), (const xmlChar*)"true"))) { dhcp = 1; } } else if (!(xmlStrcmp(child->name, (const xmlChar*)"eth_addr"))) { address = (char*)xmlNodeGetContent(child); } else if (!(xmlStrcmp(child->name, (const xmlChar*)"eth_mask"))) { netmask = (char*)xmlNodeGetContent(child); } else if (!(xmlStrcmp(child->name, (const xmlChar*)"eth_gate"))) { gateway = (char*)xmlNodeGetContent(child); } child = child->next; } } cur = cur->next; } // end while loop until NULL all elements processed if (dhcp == 0 && (address == NULL || strlen(address) == 0 || netmask == NULL || strlen(netmask) == 0 || gateway == NULL || strlen(gateway) == 0)) { logger_remotem("Configure network error: address=%s, netmask=%s, gateway=%s", address, netmask, gateway); logger_remotem("Configure network: static requires address, net mask & gateway"); return; } update_network(dhcp, address, netmask, gateway); }