#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include "parser.h"
#include "global.h"
#include "connections.h"
#include "recreate.h"
#include "new_pmu_or_pdc.h"
Go to the source code of this file.
Functions | |
void | recreate_cfg_objects () |
void | init_cfgparser (unsigned char st[]) |
void | recreate_Connection_Table () |
void | recreate_udp_connections (struct Lower_Layer_Details *t11) |
void | recreate_tcp_connections (struct Lower_Layer_Details *t12) |
void init_cfgparser | ( | unsigned char | st[] | ) |
WHILE EACH PMU IS HANDLED
PHASOR FACTORS
Definition at line 172 of file recreate.c.
References format::analog, channel_names::angnames, for_each_pmu::annmr, for_each_pmu::anunit, for_each_pmu::cfg_cnt, cfgfirst, cfg_frame::cfgnext, for_each_pmu::cnext, copy_cbyc(), for_each_pmu::data_format, cfg_frame::data_rate, dgnames::dg_next, dgnames::dgn, for_each_pmu::dgnmr, for_each_pmu::dgunit, channel_names::first, for_each_pmu::fmt, for_each_pmu::fnom, fp_log, cfg_frame::fracsec, cfg_frame::framesize, format::freq, i, for_each_pmu::idcode, cfg_frame::idcode, cfg_frame::num_pmu, format::phasor, channel_names::phnames, for_each_pmu::phnmr, for_each_pmu::phunit, cfg_frame::pmu, format::polar, cfg_frame::soc, for_each_pmu::stn, cfg_frame::time_base, and to_intconvertor().
Referenced by recreate_cfg_objects().
00172 { 00173 00174 unsigned char *s; 00175 unsigned int phn,ann,dgn,num_pmu; 00176 int i,j,dgchannels; 00177 struct cfg_frame *cfg; 00178 struct channel_names *cn; 00179 00180 /******************** PARSING BEGINGS *******************/ 00181 00182 cfg = malloc(sizeof(struct cfg_frame)); 00183 if(!cfg) { 00184 fprintf(fp_log,"Not enough memory for cfg\n"); 00185 } 00186 00187 s = st; 00188 00189 // Memory Allocation Begins 00190 00191 // Allocate memory to framesize 00192 cfg->framesize = malloc(3*sizeof(unsigned char)); 00193 if(!cfg->framesize) { 00194 printf("Not enough memory for cfg->framesize\n"); 00195 } 00196 00197 // Allocate memory to idcode 00198 cfg->idcode = malloc(3*sizeof(unsigned char)); 00199 if(!cfg->idcode) { 00200 printf("Not enough memory for cfg->framesize\n"); 00201 } 00202 00203 // Allocate memory to soc 00204 cfg->soc = malloc(5*sizeof(unsigned char)); 00205 if(!cfg->soc) { 00206 printf("Not enough memory for cfg->soc\n"); 00207 } 00208 00209 // Allocate memory to fracsec 00210 cfg->fracsec = malloc(5*sizeof(unsigned char)); 00211 if(!cfg->fracsec) { 00212 printf("Not enough memory for cfg->fracsec\n"); 00213 } 00214 00215 // Allocate memory to time_base 00216 cfg->time_base = malloc(5*sizeof(unsigned char)); 00217 if(!cfg->time_base) { 00218 printf("Not enough memory for cfg->time_base\n"); 00219 } 00220 00221 // Allocate memory to num_pmu 00222 cfg->num_pmu = malloc(3*sizeof(unsigned char)); 00223 if(!cfg->num_pmu) { 00224 printf("Not enough memory for cfg->num_pmu\n"); 00225 } 00226 00227 // Allocate memory to data_rate 00228 cfg->data_rate = malloc(3*sizeof(unsigned char)); 00229 if(!cfg->data_rate) { 00230 printf("Not enough memory for cfg->data_rate\n"); 00231 } 00232 00233 // Skip the sync word 00234 s = s + 2; 00235 00236 // Separate the FRAME SIZE 00237 copy_cbyc (cfg->framesize,(unsigned char *)s,2); 00238 cfg->framesize[2]='\0'; 00239 s = s + 2; 00240 00241 //SEPARATE IDCODE 00242 copy_cbyc (cfg->idcode,(unsigned char *)s,2); 00243 cfg->idcode[2]='\0'; 00244 int id = to_intconvertor(cfg->idcode); 00245 printf("ID Code %d\n",id); 00246 s = s + 2; 00247 00248 //SEPARATE SOC 00249 copy_cbyc (cfg->soc,(unsigned char *)s,4); 00250 cfg->soc[4]='\0'; 00251 s = s + 4; 00252 00253 //SEPARATE FRACSEC 00254 copy_cbyc (cfg->fracsec,(unsigned char *)s,4); 00255 cfg->fracsec[4]='\0'; 00256 s = s + 4; 00257 00258 //SEPARATE TIMEBASE 00259 copy_cbyc (cfg->time_base,(unsigned char *)s,4); 00260 cfg->time_base[4]='\0'; 00261 s = s + 4; 00262 00263 //SEPARATE PMU NUM 00264 copy_cbyc (cfg->num_pmu,(unsigned char *)s,2); 00265 cfg->num_pmu[2]='\0'; 00266 s = s + 2; 00267 00268 num_pmu = to_intconvertor(cfg->num_pmu); 00269 printf("No of PMU %d\n",num_pmu); 00270 fprintf(fp_log,"INT No of PMU %d\n",num_pmu); 00271 00272 // Allocate Memeory For Each PMU 00273 cfg->pmu = malloc(num_pmu* sizeof(struct for_each_pmu *)); 00274 if(!cfg->pmu) { 00275 printf("Not enough memory pmu[][]\n"); 00276 exit(1); 00277 } 00278 00279 for (i = 0; i < num_pmu; i++) { 00280 cfg->pmu[i] = malloc(sizeof(struct for_each_pmu)); 00281 } 00282 00283 j = 0; 00284 00286 while(j<num_pmu) { 00287 00288 // Memory Allocation for stn 00289 cfg->pmu[j]->stn = malloc(17*sizeof(unsigned char)); 00290 if(!cfg->pmu[j]->stn) { 00291 printf("Not enough memory cfg->pmu[j]->stn\n"); 00292 exit(1); 00293 } 00294 00295 // Memory Allocation for idcode 00296 cfg->pmu[j]->idcode = malloc(3*sizeof(unsigned char)); 00297 if(!cfg->pmu[j]->idcode) { 00298 printf("Not enough memory cfg->pmu[j]->idcode\n"); 00299 exit(1); 00300 } 00301 00302 // Memory Allocation for format 00303 cfg->pmu[j]->data_format = malloc(3*sizeof(unsigned char)); 00304 if(!cfg->pmu[j]->data_format) { 00305 printf("Not enough memory cfg->pmu[j]->data_format\n"); 00306 exit(1); 00307 } 00308 00309 // Memory Allocation for phnmr 00310 cfg->pmu[j]->phnmr = malloc(3*sizeof(unsigned char)); 00311 if(!cfg->pmu[j]->phnmr) { 00312 printf("Not enough memory cfg->pmu[j]->phnmr\n"); 00313 exit(1); 00314 } 00315 00316 // Memory Allocation for annmr 00317 cfg->pmu[j]->annmr = malloc(3*sizeof(unsigned char)); 00318 if(!cfg->pmu[j]->annmr) { 00319 printf("Not enough memory cfg->pmu[j]->annmr\n"); 00320 exit(1); 00321 } 00322 00323 // Memory Allocation for dgnmr 00324 cfg->pmu[j]->dgnmr = malloc(3*sizeof(unsigned char)); 00325 if(!cfg->pmu[j]->dgnmr) { 00326 printf("Not enough memory cfg->pmu[j]->dgnmr\n"); 00327 exit(1); 00328 } 00329 00330 // Memory Allocation for fnom 00331 cfg->pmu[j]->fnom = malloc(3*sizeof(unsigned char)); 00332 if(!cfg->pmu[j]->fnom) { 00333 printf("Not enough memory cfg->pmu[j]->fnom\n"); 00334 exit(1); 00335 } 00336 00337 // Memory Allocation for cfg_cnt 00338 cfg->pmu[j]->cfg_cnt = malloc(3*sizeof(unsigned char)); 00339 if(!cfg->pmu[j]->cfg_cnt) { 00340 printf("Not enough memory cfg->pmu[j]->cfg_cnt\n"); 00341 exit(1); 00342 } 00343 00344 00345 //SEPARATE STATION NAME 00346 copy_cbyc (cfg->pmu[j]->stn,(unsigned char *)s,16); 00347 cfg->pmu[j]->stn[16]='\0'; 00348 s = s + 16; 00349 00350 //SEPARATE IDCODE 00351 copy_cbyc (cfg->pmu[j]->idcode,(unsigned char *)s,2); 00352 cfg->pmu[j]->idcode[2]='\0'; 00353 s = s + 2; 00354 00355 //SEPARATE DATA FORMAT 00356 copy_cbyc (cfg->pmu[j]->data_format,(unsigned char *)s,2); 00357 cfg->pmu[j]->data_format[2]='\0'; 00358 s = s + 2; 00359 00360 // USE fmt 00361 unsigned char hex = cfg->pmu[j]->data_format[1]; 00362 hex <<= 4; 00363 00364 // Extra field has been added to identify polar,rectangular,floating/fixed point 00365 cfg->pmu[j]->fmt = malloc(sizeof(struct format)); 00366 if((hex & 0x80) == 0x80) cfg->pmu[j]->fmt->freq = '1'; else cfg->pmu[j]->fmt->freq = '0'; 00367 if((hex & 0x40) == 0x40 ) cfg->pmu[j]->fmt->analog = '1'; else cfg->pmu[j]->fmt->analog = '0'; 00368 if((hex & 0x20) == 0x20) cfg->pmu[j]->fmt->phasor = '1'; else cfg->pmu[j]->fmt->phasor = '0'; 00369 if((hex & 0x10) == 0x10) cfg->pmu[j]->fmt->polar = '1'; else cfg->pmu[j]->fmt->polar = '0'; 00370 00371 //SEPARATE PHASORS 00372 copy_cbyc (cfg->pmu[j]->phnmr,(unsigned char *)s,2); 00373 cfg->pmu[j]->phnmr[2]='\0'; 00374 s = s + 2; 00375 phn = to_intconvertor(cfg->pmu[j]->phnmr); 00376 00377 //SEPARATE ANALOGS 00378 copy_cbyc (cfg->pmu[j]->annmr,(unsigned char *)s,2); 00379 cfg->pmu[j]->annmr[2]='\0'; 00380 s = s + 2; 00381 ann = to_intconvertor(cfg->pmu[j]->annmr); 00382 00383 //SEPARATE DIGITALS 00384 copy_cbyc (cfg->pmu[j]->dgnmr,(unsigned char *)s,2); 00385 cfg->pmu[j]->dgnmr[2] = '\0'; 00386 s = s + 2; 00387 dgn = to_intconvertor(cfg->pmu[j]->dgnmr); 00388 printf("Phasor %d Analogs %d Digitals %d\n",phn,ann,dgn); 00389 00390 cn = malloc(sizeof(struct channel_names)); 00391 if(!cn) { 00392 printf("Not enough memory cn\n"); 00393 exit(1); 00394 } 00395 cn->first = NULL; 00396 00398 if(phn != 0){ 00399 cn->phnames = malloc(phn*sizeof(unsigned char*)); 00400 if(!cn->phnames) { 00401 printf("Not enough memory cfg->pmu[j]->cn->phnames[][]\n"); 00402 exit(1); 00403 } 00404 00405 for (i = 0; i < phn; i++) { 00406 00407 cn->phnames[i] = malloc(17*sizeof(unsigned char)); 00408 00409 } 00410 00411 i = 0;//Index for PHNAMES 00412 while(i<phn){ 00413 copy_cbyc (cn->phnames[i],(unsigned char *)s,16); 00414 cn->phnames[i][16] = '\0'; 00415 printf("Phnames %s\n",cn->phnames[i]); 00416 s = s + 16; 00417 i++; 00418 00419 } 00420 } 00421 00422 //SEPARATE ANALOG NAMES 00423 if(ann!=0){ 00424 cn->angnames = malloc(ann*sizeof(unsigned char*)); 00425 if(!cn->angnames) { 00426 printf("Not enough memory cfg->pmu[j]->cn->phnames[][]\n"); 00427 exit(1); 00428 } 00429 00430 for (i = 0; i < ann; i++) { 00431 00432 cn->angnames[i] = malloc(17*sizeof(unsigned char)); 00433 00434 } 00435 00436 00437 i=0;//Index for ANGNAMES 00438 while(i<ann){ 00439 copy_cbyc (cn->angnames[i],(unsigned char *)s,16); 00440 cn->angnames[i][16]='\0'; 00441 printf("ANGNAMES %s\n",cn->angnames[i]); 00442 s =s + 16; 00443 i++; 00444 } 00445 } 00446 00447 struct dgnames *q; 00448 i = 0; //Index for number of dgwords 00449 while(i<dgn) { 00450 00451 struct dgnames *temp1 = malloc(sizeof(struct dgnames)); 00452 00453 temp1->dgn = malloc(16*sizeof(unsigned char *)); 00454 00455 if(!temp1->dgn) { 00456 printf("Not enough memory temp1->dgn\n"); 00457 exit(1); 00458 } 00459 00460 for (i = 0; i < 16; i++) { 00461 temp1->dgn[i] = malloc(17*sizeof(unsigned char)); 00462 00463 } 00464 00465 temp1->dg_next = NULL; 00466 00467 for(dgchannels=0;dgchannels<16;dgchannels++){ 00468 00469 copy_cbyc (temp1->dgn[dgchannels],(unsigned char *)s,16); 00470 temp1->dgn[dgchannels][16]='\0'; 00471 s += 16; 00472 printf("%s\n",temp1->dgn[dgchannels]); 00473 00474 } 00475 00476 if(cn->first == NULL){ 00477 cn->first = q = temp1; 00478 } else { 00479 while(q->dg_next!=NULL){ 00480 q = q->dg_next; 00481 } 00482 q->dg_next = temp1; 00483 } 00484 i++; 00485 } //DGWORD WHILE ENDS 00486 00487 cfg->pmu[j]->cnext = cn;//Assign to pointers 00488 00489 00491 if(phn != 0){ 00492 00493 cfg->pmu[j]->phunit = malloc(phn*sizeof(unsigned char*)); 00494 if(!cfg->pmu[j]->phunit) { 00495 printf("Not enough memory cfg->pmu[j]->phunit[][]\n"); 00496 exit(1); 00497 } 00498 00499 for (i = 0; i < phn; i++) { 00500 cfg->pmu[j]->phunit[i] = malloc(5*sizeof(unsigned char)); 00501 } 00502 00503 i = 0; 00504 while(i<phn){ //Separate the Phasor conversion factors 00505 copy_cbyc (cfg->pmu[j]->phunit[i],(unsigned char *)s,4); 00506 cfg->pmu[j]->phunit[i][4] = '\0'; 00507 s = s + 4; 00508 i++; 00509 } 00510 }//if for PHASOR Factors ends 00511 00512 //ANALOG FACTORS 00513 if(ann != 0){ 00514 00515 cfg->pmu[j]->anunit = malloc(ann*sizeof(unsigned char*)); 00516 if(!cfg->pmu[j]->anunit) { 00517 printf("Not enough memory cfg->pmu[j]->anunit[][]\n"); 00518 exit(1); 00519 } 00520 00521 for (i = 0; i < ann; i++) { 00522 cfg->pmu[j]->anunit[i] = malloc(5*sizeof(unsigned char)); 00523 00524 } 00525 00526 i = 0; 00527 while(i<ann){ //Separate the Phasor conversion factors 00528 copy_cbyc (cfg->pmu[j]->anunit[i],(unsigned char *)s,4); 00529 cfg->pmu[j]->anunit[i][4] = '\0'; 00530 s = s + 4; 00531 i++; 00532 } 00533 00534 } // if for ANALOG Factors ends 00535 00536 if(dgn != 0){ 00537 00538 cfg->pmu[j]->dgunit = malloc(dgn*sizeof(unsigned char*)); 00539 if(!cfg->pmu[j]->dgunit) { 00540 printf("Not enough memory cfg->pmu[j]->dgunit[][]\n"); 00541 exit(1); 00542 } 00543 00544 for (i = 0; i < dgn; i++) { 00545 cfg->pmu[j]->dgunit[i] = malloc(5*sizeof(unsigned char)); 00546 00547 } 00548 00549 i = 0; 00550 while(i<dgn){ //Separate the Phasor conversion factors 00551 00552 copy_cbyc (cfg->pmu[j]->dgunit[i],(unsigned char *)s,4); 00553 cfg->pmu[j]->dgunit[i][4] = '\0'; 00554 s = s + 4; 00555 i++; 00556 } 00557 } //if for Digital Words Factors ends 00558 00559 00560 copy_cbyc (cfg->pmu[j]->fnom,(unsigned char *)s,2); 00561 cfg->pmu[j]->fnom[2]='\0'; 00562 s = s + 2; 00563 00564 copy_cbyc (cfg->pmu[j]->cfg_cnt,(unsigned char *)s,2); 00565 cfg->pmu[j]->cfg_cnt[2] = '\0'; 00566 s = s + 2; 00567 j++; 00568 }//While for PMU number ends 00569 00570 00571 copy_cbyc (cfg->data_rate,(unsigned char *)s,2); 00572 cfg->data_rate[2] = '\0'; 00573 cfg->cfgnext = NULL; 00574 00575 00576 if (cfgfirst == NULL) { 00577 cfgfirst = cfg; 00578 } else { 00579 00580 struct cfg_frame *t=cfgfirst; 00581 while(t->cfgnext != NULL){ 00582 t = t->cfgnext; 00583 } 00584 t->cfgnext = cfg; 00585 } 00586 00587 }
void recreate_cfg_objects | ( | ) |
Definition at line 63 of file recreate.c.
References CFGSYNC, CMDCFGSEND, CMDDATAOFF, CMDDATASEND, CMDSYNC, DATASYNC, DB_Server_addr, DB_sockfd, DBPORT, dbserver_ip, init_cfgparser(), mutex_cfg, mutex_file, mutex_Lower_Layer_Details, mutex_status_change, mutex_Upper_Layer_Details, to_intconvertor(), and yes.
Referenced by fill_pdc_details(), and validation_pdc_detail().
00063 { 00064 00065 /* ---------------------------------------------------------------- */ 00066 /* Initialize Global Mutex Variable from global.h */ 00067 /* ---------------------------------------------------------------- */ 00068 pthread_mutex_init(&mutex_file, NULL); 00069 pthread_mutex_init(&mutex_cfg, NULL); 00070 pthread_mutex_init(&mutex_status_change, NULL); 00071 pthread_mutex_init(&mutex_Lower_Layer_Details, NULL); 00072 pthread_mutex_init(&mutex_Upper_Layer_Details, NULL); 00073 00074 CMDSYNC[0] = 0xaa; 00075 CMDSYNC[1] = 0x41; 00076 CMDSYNC[2] = '\0'; 00077 00078 CMDCFGSEND[0] = 0x00; 00079 CMDCFGSEND[1] = 0x05; 00080 CMDCFGSEND[2] = '\0'; 00081 00082 CMDDATASEND[0] = 0x00; 00083 CMDDATASEND[1] = 0x02; 00084 CMDDATASEND[2] = '\0'; 00085 00086 CMDDATAOFF[0] = 0x00; 00087 CMDDATAOFF[1] = 0x01; 00088 CMDDATAOFF[2] = '\0'; 00089 00090 DATASYNC[0] = 0xaa; 00091 DATASYNC[1] = 0x01; 00092 DATASYNC[2] = '\0'; 00093 00094 CFGSYNC[0] = 0xaa; 00095 CFGSYNC[1] = 0x31; 00096 CFGSYNC[2] = '\0'; 00097 00098 int yes =1; 00099 00100 /* Create UDP socket for DB Server and bind to DBPORT */ 00101 00102 if ((DB_sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { 00103 00104 perror("socket"); 00105 exit(1); 00106 00107 } else { 00108 00109 printf("DB Socket:Sucessfully created\n"); 00110 00111 } 00112 if (setsockopt(DB_sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1) { 00113 perror("setsockopt"); 00114 exit(1); 00115 } 00116 00117 bzero(&DB_Server_addr,sizeof(DB_Server_addr)); 00118 DB_Server_addr.sin_family = AF_INET; // host byte order 00119 DB_Server_addr.sin_port = htons(DBPORT); // short, network byte order 00120 DB_Server_addr.sin_addr.s_addr = inet_addr(dbserver_ip); // automatically fill with my IP 00121 memset(&(DB_Server_addr.sin_zero),'\0', 8); // zero the rest of the struct 00122 00123 00124 /* Create CFG Objects from cfg.bin*/ 00125 00126 static const char filename[] = "cfg.bin"; 00127 FILE *file = fopen (filename,"rb"); 00128 00129 unsigned char *line,frame_len[2]; 00130 unsigned int framesize; 00131 unsigned long fileLen; 00132 00133 if (file != NULL) { 00134 00135 //Get file length 00136 fseek(file, 0, SEEK_END); 00137 fileLen = ftell(file); 00138 fseek(file, 0, SEEK_SET); 00139 printf("FILE LEN LEFT %ld\n",fileLen); 00140 printf("Creating objects for entries in cfg.bin\n"); 00141 00142 while (fileLen != 0) /* Till the EOF */{ 00143 00144 fseek (file,2 ,SEEK_CUR); 00145 fread(frame_len, sizeof(unsigned char),2, file); 00146 fseek (file,-4 ,SEEK_CUR); 00147 00148 framesize = to_intconvertor(frame_len); 00149 line = malloc(framesize*sizeof(unsigned char)); 00150 memset(line,'\0',sizeof(line)); 00151 00152 fread(line, sizeof(unsigned char),framesize,file); 00153 init_cfgparser(line); 00154 free(line); 00155 fileLen -= framesize; 00156 } 00157 fclose (file); 00158 00159 } else { 00160 perror (filename); /* why didn't the file open? */ 00161 } 00162 00163 }
void recreate_Connection_Table | ( | ) |
Definition at line 594 of file recreate.c.
References Upper_Layer_Details::address_set, Upper_Layer_Details::config_change, Lower_Layer_Details::data_transmission_off, Upper_Layer_Details::ip, Lower_Layer_Details::ip, Upper_Layer_Details::next, Lower_Layer_Details::next, Upper_Layer_Details::pdc_addr, Lower_Layer_Details::pmu_remove, Lower_Layer_Details::pmuid, Upper_Layer_Details::port, Lower_Layer_Details::port, Upper_Layer_Details::prev, Lower_Layer_Details::prev, Upper_Layer_Details::protocol, Lower_Layer_Details::protocol, recreate_tcp_connections(), recreate_udp_connections(), Lower_Layer_Details::request_cfg_frame, Upper_Layer_Details::tcpup, Upper_Layer_Details::UL_data_transmission_off, Upper_Layer_Details::UL_upper_pdc_cfgsent, ULfirst, and ULlast.
Referenced by fill_pdc_details().
00594 { 00595 00596 FILE *f; 00597 char line[40],*ip,*port,*protocol,*id; 00598 int err; 00599 00600 // A new thread is created for each TCP connection in 'detached' mode. Thus allowing any number of threads to be created. 00601 pthread_attr_t attr; 00602 pthread_attr_init(&attr); 00603 if((err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))) { 00604 00605 perror(strerror(err)); 00606 exit(1); 00607 00608 } 00609 if((err = pthread_attr_setschedpolicy(&attr,SCHED_FIFO))) { 00610 00611 perror(strerror(err)); 00612 exit(1); 00613 } 00614 00615 f = fopen("ipaddress.txt","r"); 00616 if (f != NULL) { //1 if 00617 00618 printf("#### CONNECTION TABLE OF SOURCE DEVICES ####\n"); 00619 printf("-----------------------------------------------------------------\n"); 00620 printf("| PMU ID | Lower IP | Port | Protocol |\n"); 00621 printf("-----------------------------------------------------------------\n"); 00622 while (fgets (line, 40,f) != NULL) /* read a line */ { //2 while 00623 00624 /* Extract the ip and protocol */ 00625 id = strtok (line," "); 00626 ip = strtok (NULL," "); 00627 port = strtok (NULL," "); 00628 protocol = strtok (NULL," "); 00629 *(protocol+3) = '\0'; 00630 printf("|\t%d\t|%s\t|\t%d\t|\t%s\t|\n",atoi(id),ip,atoi(port),protocol); 00631 00632 struct Lower_Layer_Details *temp_pmu; 00633 temp_pmu = malloc(sizeof(struct Lower_Layer_Details)); 00634 if(!temp_pmu) { 00635 00636 printf("Not enough memory temp_pmu\n"); 00637 exit(1); 00638 00639 } 00640 00641 temp_pmu->pmuid = atoi(id); 00642 strcpy(temp_pmu->ip,ip); 00643 temp_pmu->port = atoi(port); 00644 strcpy(temp_pmu->protocol,protocol); 00645 temp_pmu->data_transmission_off = 0; 00646 temp_pmu->pmu_remove = 0; 00647 temp_pmu->request_cfg_frame = 0; 00648 temp_pmu->next = NULL; 00649 temp_pmu->prev = NULL; 00650 00651 if(!strncasecmp(temp_pmu->protocol,"UDP",3)) { 00652 00653 recreate_udp_connections(temp_pmu); 00654 } 00655 00656 if(!strncasecmp(temp_pmu->protocol,"TCP",3)) { 00657 00658 recreate_tcp_connections(temp_pmu); 00659 } 00660 00661 memset(line,'\0',40); 00662 } 00663 printf("-----------------------------------------------------------------\n"); 00664 fclose(f); 00665 00666 } else { 00667 00668 perror("ipaddress.txt"); 00669 } 00670 00671 f = fopen("upperpdc_ip.txt","r"); 00672 if (f != NULL) { //1 if 00673 00674 printf("#### CONNECTION TABLE OF DESTINATION DEVICES ####\n"); 00675 printf("-------------------------------------------------\n"); 00676 printf("| Upper IP | Port | Protocol |\n"); 00677 printf("-------------------------------------------------\n"); 00678 while(fgets (line, 40,f) != NULL) /* read a line */ { //2 while 00679 00680 /* Extract the ip and protocol */ 00681 ip = strtok (line," "); 00682 port = strtok (NULL," "); 00683 protocol = strtok (NULL," "); 00684 *(protocol+3) = '\0'; 00685 printf("|%s\t|\t%d\t|\t%s\t|\n",ip,atoi(port),protocol); 00686 00687 struct Upper_Layer_Details *temp_pdc; 00688 temp_pdc = malloc(sizeof(struct Upper_Layer_Details)); 00689 if(!temp_pdc) { 00690 00691 printf("Not enough memory temp_pmu\n"); 00692 exit(1); 00693 00694 } 00695 00696 strcpy(temp_pdc->ip,ip); 00697 temp_pdc->port = atoi(port); 00698 strcpy(temp_pdc->protocol,protocol); 00699 00700 bzero(&temp_pdc->pdc_addr,sizeof(temp_pdc->pdc_addr)); 00701 temp_pdc->pdc_addr.sin_family = AF_INET; 00702 temp_pdc->pdc_addr.sin_addr.s_addr = inet_addr(temp_pdc->ip); 00703 temp_pdc->pdc_addr.sin_port = htons(temp_pdc->port); 00704 00705 memset(&(temp_pdc->pdc_addr.sin_zero), '\0', 8); // zero the rest of the struct 00706 temp_pdc->config_change = 0; 00707 temp_pdc->UL_upper_pdc_cfgsent = 0; 00708 temp_pdc->UL_data_transmission_off = 1; 00709 temp_pdc->address_set = 0; 00710 temp_pdc->tcpup = 1; 00711 00712 if(ULfirst == NULL) { 00713 00714 ULfirst = temp_pdc; 00715 temp_pdc->prev = NULL; 00716 00717 } else { 00718 00719 ULlast->next = temp_pdc; 00720 temp_pdc->prev = ULlast; 00721 00722 } 00723 00724 ULlast = temp_pdc; 00725 temp_pdc->next = NULL; 00726 memset(line,'\0',40); 00727 } 00728 printf("-------------------------------------------------\n"); 00729 fclose(f); 00730 00731 } else { 00732 00733 perror("upperpdc_ip.txt"); 00734 } 00735 }
void recreate_tcp_connections | ( | struct Lower_Layer_Details * | t12 | ) |
Definition at line 771 of file recreate.c.
References connect_pmu_tcp().
Referenced by recreate_Connection_Table().
00771 { 00772 00773 int err; 00774 pthread_attr_t attr; 00775 pthread_attr_init(&attr); 00776 if((err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))) { 00777 00778 perror(strerror(err)); 00779 exit(1); 00780 00781 } 00782 if((err = pthread_attr_setschedpolicy(&attr,SCHED_FIFO))) { 00783 00784 perror(strerror(err)); 00785 exit(1); 00786 } 00787 00788 pthread_t t; 00789 00790 if(pthread_create(&t,&attr,connect_pmu_tcp,(void *)t12)) { 00791 perror(strerror(err)); 00792 exit(1); 00793 } 00794 }
void recreate_udp_connections | ( | struct Lower_Layer_Details * | t11 | ) |
Definition at line 741 of file recreate.c.
References connect_pmu_udp().
Referenced by recreate_Connection_Table().
00741 { 00742 00743 int err; 00744 pthread_attr_t attr; 00745 pthread_attr_init(&attr); 00746 if((err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))) { 00747 00748 perror(strerror(err)); 00749 exit(1); 00750 00751 } 00752 if((err = pthread_attr_setschedpolicy(&attr,SCHED_FIFO))) { 00753 00754 perror(strerror(err)); 00755 exit(1); 00756 } 00757 00758 pthread_t t; 00759 00760 if(pthread_create(&t,&attr,connect_pmu_udp,(void *)t11)) { 00761 00762 perror(strerror(err)); 00763 exit(1); 00764 } 00765 }