00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <stdio.h>
00031 #include <string.h>
00032 #include <stdlib.h>
00033 #include <pthread.h>
00034 #include "parser.h"
00035 #include "global.h"
00036 #include "align_sort.h"
00037 #include "connections.h"
00038 #include "dallocate.h"
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 int i;
00056
00057 int front = -1;
00058 int rear = -1;
00059 pthread_mutex_t mutex_on_TSB = PTHREAD_MUTEX_INITIALIZER;
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 void time_align(struct data_frame *df) {
00070
00071 int flag = 0;
00072 fprintf(fp_log,"Inside time_align()\n");
00073 pthread_mutex_lock(&mutex_on_TSB);
00074 if(front == -1) {
00075
00076 front = rear = 0;
00077 assign_df_to_TSB(df,front);
00078 pthread_mutex_unlock(&mutex_on_TSB);
00079 return;
00080
00081 } else {
00082
00083 unsigned long int df_soc,df_fracsec,tsb_soc,tsb_fracsec;
00084
00085 df_soc = to_long_int_convertor(df->soc);
00086 df_fracsec = to_long_int_convertor(df->fracsec);
00087 tsb_soc = to_long_int_convertor((unsigned char *)TSB[front].soc);
00088 tsb_fracsec = to_long_int_convertor((unsigned char *)TSB[front].fracsec);
00089
00090 if((df_soc < tsb_soc) || ((df_soc == tsb_soc) && (df_fracsec < tsb_fracsec))) {
00091
00092 fprintf(fp_log,"df_soc %ld tsb_soc %ld df_fracsec %ld tsb_fracsec %ld\n",df_soc,tsb_soc,df_fracsec,tsb_fracsec);
00093 fprintf(fp_log,"The Data frame is too old\n");
00094 pthread_mutex_unlock(&mutex_on_TSB);
00095 return;
00096 }
00097
00098 if(rear >= front) {
00099 for(i = rear; i>= front; i--) {
00100
00101 if(!ncmp_cbyc ((unsigned char *)TSB[i].soc,df->soc,4)) {
00102
00103 if(!ncmp_cbyc ((unsigned char *)TSB[i].fracsec,df->fracsec,3)) {
00104
00105 flag = 1;
00106 break;
00107
00108 }
00109
00110 } else {
00111
00112 continue;
00113
00114 }
00115 }
00116 } else {
00117
00118 for(i = rear; i< front; i++) {
00119
00120 if(!ncmp_cbyc ((unsigned char *)TSB[i].soc,df->soc,4)) {
00121
00122 if(!ncmp_cbyc ((unsigned char *)TSB[i].fracsec,df->fracsec,3)) {
00123
00124 flag = 1;
00125 break;
00126 }
00127
00128 } else {
00129
00130 continue;
00131
00132 }
00133 }
00134 }
00135
00136 }
00137
00138 if(flag) {
00139
00140 fprintf(fp_log,"Matched with TSB[%d]\n",i);
00141
00142 assign_df_to_TSB(df,i);
00143
00144 } else {
00145
00146 rear = (rear + 1) % MAXTSB;
00147
00148 if(front == rear) {
00149
00150 dispatch(rear);
00151 front = (front + 1) % MAXTSB;
00152 assign_df_to_TSB(df,rear);
00153
00154 } else {
00155
00156 assign_df_to_TSB(df,rear);
00157
00158 }
00159 }
00160 pthread_mutex_unlock(&mutex_on_TSB);
00161 }
00162
00163
00164
00165
00166
00167
00168 void assign_df_to_TSB(struct data_frame *df,int index) {
00169
00170 fprintf(fp_log,"Inside assign_df_to_TSB()\n");
00171
00172
00173 if(TSB[index].soc == NULL) {
00174
00175 struct cfg_frame *temp_cfg = cfgfirst;
00176
00177 TSB[index].soc = malloc(5);
00178 TSB[index].fracsec = malloc(5);
00179
00180 memset(TSB[index].soc,'\0',5);
00181 memset(TSB[index].fracsec,'\0',5);
00182
00183 copy_cbyc((unsigned char *)TSB[index].soc,df->soc,4);
00184 copy_cbyc((unsigned char *)TSB[index].fracsec,df->fracsec,4);
00185
00186 TSB[index].first_data_frame = df;
00187
00188
00189 struct pmupdc_id_list *temp_pmuid;
00190 while(temp_cfg != NULL) {
00191
00192
00193 struct pmupdc_id_list *pmuid = malloc(sizeof(struct pmupdc_id_list));
00194 pmuid->idcode = malloc(3);
00195 memset(pmuid->idcode,'\0',3);
00196 copy_cbyc((unsigned char *)pmuid->idcode,temp_cfg->idcode,2);
00197 pmuid->num_pmu = to_intconvertor(temp_cfg->num_pmu);
00198 pmuid->nextid = NULL;
00199
00200 if(TSB[index].idlist == NULL) {
00201
00202 TSB[index].idlist = temp_pmuid = pmuid;
00203
00204 } else {
00205
00206 temp_pmuid->nextid = pmuid;
00207 temp_pmuid = pmuid;
00208
00209 }
00210
00211 temp_cfg = temp_cfg->cfgnext;
00212 }
00213
00214 } else {
00215
00216 struct cfg_frame *temp_cfg = cfgfirst;
00217 if(TSB[index].first_data_frame == NULL) {
00218
00219
00220
00221
00222
00223
00224 copy_cbyc((unsigned char *)TSB[index].soc,df->soc,4);
00225 copy_cbyc((unsigned char *)TSB[index].fracsec,df->fracsec,4);
00226
00227 TSB[index].first_data_frame = df;
00228
00229
00230
00231
00232 struct pmupdc_id_list *temp_pmuid;
00233 while(temp_cfg != NULL) {
00234
00235
00236
00237
00238 struct pmupdc_id_list *pmuid = malloc(sizeof(struct pmupdc_id_list));
00239 pmuid->idcode = malloc(3);
00240 memset(pmuid->idcode,'\0',3);
00241 copy_cbyc((unsigned char *)pmuid->idcode,temp_cfg->idcode,2);
00242 pmuid->num_pmu = to_intconvertor(temp_cfg->num_pmu);
00243 pmuid->nextid = NULL;
00244
00245 if(TSB[index].idlist == NULL) {
00246
00247 TSB[index].idlist = temp_pmuid = pmuid;
00248
00249 } else {
00250
00251 temp_pmuid->nextid = pmuid;
00252 temp_pmuid = pmuid;
00253
00254 }
00255
00256 temp_cfg = temp_cfg->cfgnext;
00257 }
00258
00259 } else {
00260
00261
00262
00263 struct data_frame *temp_df,*check_df;
00264
00265
00266
00267 check_df = TSB[index].first_data_frame;
00268 while(check_df != NULL) {
00269
00270 if(!ncmp_cbyc(check_df->idcode,df->idcode,2)) {
00271
00272 fprintf(fp_log,"Data frame already inside TSB[%d]\n",index);
00273 free_dataframe_object(df);
00274 return;
00275
00276 } else {
00277
00278 check_df = check_df->dnext;
00279
00280 }
00281 }
00282
00283 temp_df = TSB[index].first_data_frame;
00284 while(temp_df->dnext != NULL) {
00285
00286 temp_df = temp_df->dnext;
00287
00288 }
00289
00290 temp_df->dnext = df;
00291 }
00292
00293 }
00294 }
00295
00296
00297
00298
00299
00300
00301 void dispatch(int index) {
00302
00303 int size,flag = 0;
00304 fprintf(fp_log,"Inside dispatch()\n");
00305 sort_data_inside_TSB(index);
00306 dataframe = NULL;
00307 pthread_mutex_lock(&mutex_Upper_Layer_Details);
00308 struct Upper_Layer_Details *temp_pdc = ULfirst;
00309
00310 while(temp_pdc != NULL ) {
00311
00312 if((temp_pdc->UL_upper_pdc_cfgsent == 1) && (temp_pdc->UL_data_transmission_off == 0)) {
00313
00314 if(flag == 0) {
00315
00316 size = create_dataframe(index);
00317 flag = 1;
00318 }
00319
00320 if(temp_pdc->config_change == 1) {
00321
00322 dataframe[14] = 0x04;
00323 dataframe[15] = 0x00;
00324
00325 } else {
00326
00327 dataframe[14] = 0x00;
00328 dataframe[15] = 0x00;
00329
00330 }
00331
00332 if(temp_pdc->port == UDPPORT) {
00333
00334 if (sendto(temp_pdc->sockfd,dataframe, size, 0,
00335 (struct sockaddr *)&temp_pdc->pdc_addr,sizeof(temp_pdc->pdc_addr)) == -1)
00336 perror("sendto");
00337 else fprintf(fp_log,"\nDispatched toUPDC ");
00338
00339
00340 } else if((temp_pdc->port == TCPPORT) && (temp_pdc->tcpup == 1)) {
00341
00342 if(send(temp_pdc->sockfd,dataframe,size, 0)== -1) {
00343 perror("send");
00344 printf("TCP connection closed\n");
00345 temp_pdc->tcpup = 0;
00346 pthread_cancel(temp_pdc->thread_id);
00347 }
00348 }
00349 }
00350 temp_pdc = temp_pdc->next;
00351 }
00352 pthread_mutex_unlock(&mutex_Upper_Layer_Details);
00353 if(dataframe != NULL) free(dataframe);
00354
00355 clear_TSB(index);
00356 }
00357
00358
00359
00360
00361
00362
00363
00364 void sort_data_inside_TSB(int index) {
00365
00366 fprintf(fp_log,"sort_data_inside_TSB()\n");
00367 struct pmupdc_id_list *temp_list;
00368 struct data_frame *prev_df,*curr_df,*sorted_df,*r_df,*s_df,*last_df,*p_df;
00369 int match = 0;
00370 unsigned int id_check;
00371
00372
00373
00374
00375 temp_list = TSB[index].idlist;
00376 last_df = TSB[index].first_data_frame;
00377 p_df = TSB[index].first_data_frame;
00378
00379 curr_df = last_df;
00380 sorted_df = prev_df = NULL;
00381
00382 while(temp_list != NULL) {
00383
00384 match = 0;
00385 while(curr_df != NULL) {
00386
00387 if(!ncmp_cbyc(curr_df->idcode,(unsigned char *)temp_list->idcode,2)){
00388
00389 match = 1;
00390 break;
00391
00392 } else {
00393
00394 prev_df = curr_df;
00395 curr_df = curr_df->dnext;
00396
00397 }
00398
00399 }
00400
00401 if (match == 1) {
00402
00403 if(prev_df == NULL) {
00404
00405 r_df = curr_df;
00406 s_df = curr_df->dnext;
00407 if(sorted_df == NULL) {
00408
00409 sorted_df = r_df;
00410 TSB[index].first_data_frame = sorted_df;
00411 } else {
00412
00413 sorted_df->dnext = r_df;
00414 sorted_df = r_df;
00415 }
00416 sorted_df->dnext = s_df ;
00417 curr_df = last_df = s_df;
00418
00419 } else {
00420
00421 if(sorted_df == NULL) {
00422
00423 r_df = curr_df;
00424 s_df = r_df->dnext;
00425 prev_df->dnext = s_df;
00426 sorted_df = r_df;
00427 TSB[index].first_data_frame = sorted_df;
00428 sorted_df->dnext = last_df ;
00429 curr_df = last_df;
00430 prev_df = NULL;
00431
00432 } else {
00433
00434 r_df = curr_df;
00435 s_df = r_df->dnext;
00436 prev_df->dnext = s_df;
00437 sorted_df->dnext = r_df;
00438 sorted_df = r_df;
00439 sorted_df->dnext = last_df ;
00440 curr_df = last_df;
00441 prev_df = NULL;
00442 }
00443 }
00444
00445 } else {
00446
00447 char *idcode;
00448 idcode = malloc(3);
00449
00450 struct data_frame *df = malloc(sizeof(struct data_frame));
00451 if(!df) {
00452
00453 fprintf(fp_log,"Not enough memory df\n");
00454 }
00455 df->dnext = NULL;
00456
00457
00458
00459 df->framesize = malloc(3);
00460 if(!df->framesize) {
00461
00462 fprintf(fp_log,"Not enough memory df->idcode\n");
00463 exit(1);
00464 }
00465
00466
00467 df->idcode = malloc(3);
00468 if(!df->idcode) {
00469
00470 fprintf(fp_log,"Not enough memory df->idcode\n");
00471 exit(1);
00472 }
00473
00474
00475 df->soc = malloc(5);
00476 if(!df->soc) {
00477
00478 fprintf(fp_log,"Not enough memory df->soc\n");
00479 exit(1);
00480 }
00481
00482
00483 df->fracsec = malloc(5);
00484 if(!df->fracsec) {
00485 fprintf(fp_log,"Not enough memory df->fracsec\n");
00486 exit(1);
00487 }
00488
00489 unsigned int size = (16 + (temp_list->num_pmu)*2)*sizeof(unsigned char);
00490
00491 df->num_pmu = temp_list->num_pmu ;
00492
00493 int_to_ascii_convertor(size,df->framesize);
00494 df->framesize[2] = '\0';
00495
00496
00497 copy_cbyc (df->idcode,(unsigned char *)temp_list->idcode,2);
00498 df->idcode[2] = '\0';
00499
00500
00501 copy_cbyc (df->soc,(unsigned char *)TSB[index].soc,4);
00502 df->soc[4] = '\0';
00503
00504
00505 copy_cbyc (df->fracsec,(unsigned char *)TSB[index].fracsec,4);
00506 df->fracsec[4] = '\0';
00507
00508 df->dpmu = malloc(temp_list->num_pmu * sizeof(struct data_for_each_pmu *));
00509 if(!df->dpmu) {
00510 fprintf(fp_log,"Not enough memory df->dpmu[][]\n");
00511 exit(1);
00512 }
00513
00514 for (i = 0; i < temp_list->num_pmu; i++) {
00515 df->dpmu[i] = malloc(sizeof(struct data_for_each_pmu));
00516 }
00517
00518 int j = 0;
00519
00520 while(j < temp_list->num_pmu) {
00521
00522 df->dpmu[j]->stat = malloc(3);
00523 if(!df->dpmu[j]->stat) {
00524 fprintf(fp_log,"Not enough memory for df->dpmu[j]->stat\n");
00525 }
00526
00527 df->dpmu[j]->stat[0] = 0x00;
00528 df->dpmu[j]->stat[1] = 0x0F;
00529 df->dpmu[j]->stat[2] = '\0';
00530 j++;
00531 }
00532
00533 if(sorted_df == NULL) {
00534
00535 r_df = df;
00536 sorted_df = r_df;
00537 TSB[index].first_data_frame = sorted_df;
00538 sorted_df->dnext = last_df ;
00539 curr_df = last_df;
00540 prev_df = NULL;
00541 } else {
00542 r_df = df;
00543 sorted_df->dnext = r_df;
00544 sorted_df = r_df;
00545 sorted_df->dnext = last_df ;
00546 curr_df = last_df;
00547 prev_df = NULL;
00548 }
00549 }
00550
00551 temp_list = temp_list->nextid;
00552
00553 }
00554
00555 p_df = TSB[index].first_data_frame;
00556 while(p_df != NULL){
00557
00558 id_check = to_intconvertor(p_df->idcode);
00559 p_df = p_df->dnext;
00560 }
00561 }
00562
00563
00564
00565
00566
00567
00568
00569 void clear_TSB(int index) {
00570
00571 fprintf(fp_log,"Inside clear_TSB()\n");
00572 unsigned long int tsb_soc,tsb_fracsec;
00573 tsb_soc = to_long_int_convertor((unsigned char *)TSB[front].soc);
00574 tsb_fracsec = to_long_int_convertor((unsigned char *)TSB[front].fracsec);
00575
00576 memset(TSB[index].soc,'\0',5);
00577 memset(TSB[index].fracsec,'\0',5);
00578
00579 struct pmupdc_id_list *t_list,*r_list;
00580 t_list = TSB[index].idlist;
00581
00582 while(t_list != NULL) {
00583
00584 r_list = t_list->nextid;
00585 free(t_list->idcode);
00586 free(t_list);
00587 t_list = r_list;
00588 }
00589
00590 struct data_frame *t,*r;
00591 t = TSB[index].first_data_frame;
00592
00593 while(t != NULL) {
00594
00595 r = t->dnext;
00596 free_dataframe_object(t);
00597 t = r;
00598 }
00599
00600 TSB[index].first_data_frame = NULL;
00601 TSB[index].idlist = NULL;
00602 }
00603
00604
00605
00606
00607
00608
00609
00610
00611 int create_dataframe(int index) {
00612
00613 fprintf(fp_log,"Inside create_dataframe()\n");
00614 int total_frame_size = 0;
00615 unsigned char temp[3];
00616 struct data_frame *temp_df;
00617 unsigned int fsize;
00618 uint16_t chk;
00619
00620 temp_df = TSB[index].first_data_frame;
00621
00622 while(temp_df != NULL) {
00623
00624 fsize = to_intconvertor(temp_df->idcode);
00625 fsize = to_intconvertor(temp_df->framesize);
00626 total_frame_size = total_frame_size + fsize;
00627 total_frame_size -= 16;
00628 temp_df = temp_df->dnext;
00629 }
00630
00631 total_frame_size = total_frame_size + 18;
00632
00633 dataframe = malloc((total_frame_size + 1)*sizeof(char));
00634 if(!dataframe) {
00635
00636 fprintf(fp_log,"No enough memory for dataframe\n");
00637 }
00638 dataframe[total_frame_size] = '\0';
00639
00640
00641 int z = 0;
00642 byte_by_byte_copy(dataframe,DATASYNC,z,2);
00643 z += 2;
00644
00645 memset(temp,'\0',3);
00646 int_to_ascii_convertor(total_frame_size,temp);
00647 byte_by_byte_copy(dataframe,temp,z,2);
00648 z += 2;
00649
00650 memset(temp,'\0',3);
00651 int_to_ascii_convertor(PDC_IDCODE,temp);
00652 byte_by_byte_copy(dataframe,temp,z,2);
00653 z += 2;
00654
00655 byte_by_byte_copy(dataframe,(unsigned char *)TSB[index].soc,z,4);
00656 z += 4;
00657 byte_by_byte_copy(dataframe,(unsigned char *)TSB[index].fracsec,z,4);
00658 z += 4;
00659
00660 unsigned char stat[2];
00661 stat[0] = 0x00;
00662 stat[1] = 0x00;
00663 byte_by_byte_copy(dataframe,stat,z,2);
00664 z += 2;
00665
00666 temp_df = TSB[index].first_data_frame;
00667 while(temp_df != NULL) {
00668
00669 int j = 0;
00670 while(j < temp_df->num_pmu) {
00671
00672 if(temp_df->dpmu[j]->stat[1] == 0x0f) {
00673
00674
00675 byte_by_byte_copy(dataframe,temp_df->dpmu[j]->stat,z,2);
00676 z += 2;
00677 j++;
00678 continue;
00679 }
00680
00681
00682 byte_by_byte_copy(dataframe,temp_df->dpmu[j]->stat,z,2);
00683
00684 z += 2;
00685
00686 int i = 0;
00687
00688 if(temp_df->dpmu[j]->phnmr != 0) {
00689 if(temp_df->dpmu[j]->fmt->phasor == '1') {
00690 while(i < temp_df->dpmu[j]->phnmr) {
00691
00692 byte_by_byte_copy(dataframe,temp_df->dpmu[j]->phasors[i],z,8);
00693 z += 8;
00694 i++;
00695 }
00696 } else {
00697 while(i < temp_df->dpmu[j]->phnmr) {
00698
00699 byte_by_byte_copy(dataframe,temp_df->dpmu[j]->phasors[i],z,4);
00700 z += 4;
00701 i++;
00702 }
00703 }
00704
00705 }
00706
00707 if(temp_df->dpmu[j]->fmt->freq == '1') {
00708
00709 byte_by_byte_copy(dataframe,temp_df->dpmu[j]->freq,z,4);
00710 z += 4;
00711 byte_by_byte_copy(dataframe,temp_df->dpmu[j]->dfreq,z,4);
00712 z += 4;
00713
00714 } else {
00715 byte_by_byte_copy(dataframe,temp_df->dpmu[j]->freq,z,2);
00716 z += 2;
00717 byte_by_byte_copy(dataframe,temp_df->dpmu[j]->dfreq,z,2);
00718 z += 2;
00719
00720 }
00721
00722
00723 if(temp_df->dpmu[j]->annmr != 0) {
00724 if(temp_df->dpmu[j]->fmt->analog == '1') {
00725
00726 for(i = 0; i<temp_df->dpmu[j]->annmr; i++){
00727
00728 byte_by_byte_copy(dataframe,temp_df->dpmu[j]->analog[i],z,4);
00729 z += 4;
00730 }
00731 } else {
00732
00733 for(i = 0; i<temp_df->dpmu[j]->annmr; i++){
00734
00735 byte_by_byte_copy(dataframe,temp_df->dpmu[j]->analog[i],z,2);
00736 z += 2;
00737 }
00738 }
00739 }
00740
00741 i = 0;
00742 if(temp_df->dpmu[j]->dgnmr != 0) {
00743 while(i < temp_df->dpmu[j]->dgnmr) {
00744
00745 byte_by_byte_copy(dataframe,temp_df->dpmu[j]->digital[i],z,2);
00746 z += 2;
00747 i++;
00748 }
00749 }
00750 j++;
00751 }
00752
00753 temp_df = temp_df->dnext;
00754 }
00755
00756
00757 chk = compute_CRC(dataframe,z);
00758 dataframe[z++] = (chk >> 8) & ~(~0<<8);
00759 dataframe[z++] = (chk ) & ~(~0<<8);
00760
00761 return z;
00762 }
00763
00764
00765
00766
00767
00768
00769
00770
00771 int create_cfgframe() {
00772
00773 fprintf(fp_log,"Inside create_cfgframe()()\n");
00774 struct cfg_frame *temp_cfg;
00775 int total_frame_size = 0,count = 0;
00776 unsigned char datarate[2],soc[4],fracsec[4];
00777 int total_num_pmu = 0;
00778 unsigned char time_base[4];
00779 unsigned int fsize,num_pmu,phnmr,dgnmr,annmr;
00780 unsigned int data_rate,temp_data_rate;
00781 unsigned long int sec,frac = 0,temp_tb,tb;
00782 uint16_t chk;
00783
00784 sec = (long int)time (NULL);
00785 long_int_to_ascii_convertor(sec,soc);
00786 long_int_to_ascii_convertor(frac,fracsec);
00787
00788 temp_cfg = cfgfirst;
00789
00790 while(temp_cfg != NULL) {
00791
00792 if(count == 0) {
00793
00794
00795 tb = to_long_int_convertor(temp_cfg->time_base);
00796 copy_cbyc (time_base,temp_cfg->time_base,4);
00797
00798 data_rate = to_intconvertor(temp_cfg->data_rate);
00799 copy_cbyc (datarate,temp_cfg->data_rate,2);
00800
00801 fsize = to_intconvertor(temp_cfg->framesize);
00802 total_frame_size += fsize;
00803 count++;
00804
00805 num_pmu = to_intconvertor(temp_cfg->num_pmu);
00806 total_num_pmu += num_pmu;
00807 temp_cfg = temp_cfg->cfgnext;
00808
00809 } else {
00810
00811 fsize = to_intconvertor(temp_cfg->framesize);
00812 total_frame_size += fsize;
00813 total_frame_size -= 24;
00814
00815
00816 temp_tb = to_long_int_convertor(temp_cfg->time_base);
00817 if(temp_tb < tb) {
00818
00819 copy_cbyc (time_base,temp_cfg->time_base,4);
00820 tb = temp_tb;
00821
00822 }
00823
00824
00825 temp_data_rate = to_intconvertor(temp_cfg->data_rate);
00826 if(temp_data_rate > data_rate) {
00827
00828 copy_cbyc (datarate,temp_cfg->data_rate,2);
00829 data_rate = temp_data_rate;
00830 }
00831 count++;
00832
00833 num_pmu = to_intconvertor(temp_cfg->num_pmu);
00834 total_num_pmu += num_pmu;
00835 temp_cfg = temp_cfg->cfgnext;
00836 }
00837
00838 }
00839
00840 cfgframe = malloc((total_frame_size + 1)*sizeof(unsigned char));
00841 cfgframe[total_frame_size] = '\0';
00842
00843
00844 int z = 0;
00845 byte_by_byte_copy(cfgframe,CFGSYNC,z,2);
00846 z += 2;
00847
00848 unsigned char temp[3];
00849 memset(temp,'\0',3);
00850 int_to_ascii_convertor(total_frame_size,temp);
00851 byte_by_byte_copy(cfgframe,temp,z,2);
00852 z += 2;
00853
00854 unsigned char tmp[2];
00855 tmp[0]= cfgframe[2];
00856 tmp[1]= cfgframe[3];
00857 int newl;
00858 newl = to_intconvertor(tmp);
00859 printf("CFG Frame Len %d\n",newl);
00860
00861 memset(temp,'\0',3);
00862 int_to_ascii_convertor(PDC_IDCODE,temp);
00863 byte_by_byte_copy(cfgframe,temp,z,2);
00864 z += 2;
00865
00866 byte_by_byte_copy(cfgframe,soc,z,4);
00867 z += 4;
00868 byte_by_byte_copy(cfgframe,fracsec,z,4);
00869 z += 4;
00870 byte_by_byte_copy(cfgframe,time_base,z,4);
00871 z += 4;
00872
00873 memset(temp,'\0',3);
00874 int_to_ascii_convertor(total_num_pmu,temp);
00875 byte_by_byte_copy(cfgframe,temp,z,2);
00876 z += 2;
00877
00878 int i,j;
00879 temp_cfg = cfgfirst;
00880 while(temp_cfg != NULL) {
00881
00882 num_pmu = to_intconvertor(temp_cfg->num_pmu);
00883 j = 0;
00884
00885 while (j < num_pmu) {
00886
00887 byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->stn,z,16);
00888 z += 16;
00889
00890 byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->idcode,z,2);
00891 z += 2;
00892
00893 byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->data_format,z,2);
00894 z += 2;
00895
00896 byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->phnmr,z,2);
00897 z += 2;
00898
00899 byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->annmr,z,2);
00900 z += 2;
00901
00902 byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->dgnmr,z,2);
00903 z += 2;
00904
00905 phnmr = to_intconvertor(temp_cfg->pmu[j]->phnmr);
00906 annmr = to_intconvertor(temp_cfg->pmu[j]->annmr);
00907 dgnmr = to_intconvertor(temp_cfg->pmu[j]->dgnmr);
00908
00909
00910 if(phnmr != 0){
00911
00912 for(i = 0; i<phnmr;i++) {
00913
00914 byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->cnext->phnames[i],z,16);
00915 z += 16;
00916 }
00917 }
00918
00919
00920 if(annmr != 0){
00921
00922 for(i = 0; i<annmr;i++) {
00923
00924 byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->cnext->angnames[i],z,16);
00925 z += 16;
00926 }
00927 }
00928
00929
00930 if(dgnmr != 0) {
00931
00932 struct dgnames *temp_dgname = temp_cfg->pmu[j]->cnext->first;
00933 while (temp_dgname != NULL) {
00934
00935 for(i = 0;i<16;i++) {
00936
00937 byte_by_byte_copy(cfgframe,temp_dgname->dgn[i],z,16);
00938 z += 16;
00939
00940 }
00941
00942 temp_dgname = temp_dgname->dg_next;
00943 }
00944
00945 }
00946
00947
00948 if(phnmr != 0){
00949
00950 for (i = 0; i<phnmr;i++) {
00951
00952 byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->phunit[i],z,4);
00953 z += 4;
00954 }
00955 }
00956
00957
00958 if(annmr != 0){
00959
00960 for (i = 0; i<annmr;i++) {
00961
00962 byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->anunit[i],z,4);
00963 z += 4;
00964
00965 }
00966 }
00967
00968
00969 if(dgnmr != 0){
00970
00971 for (i = 0; i<dgnmr;i++) {
00972
00973 byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->dgunit[i],z,4);
00974 z += 4;
00975 }
00976
00977 }
00978
00979 byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->fnom,z,2);
00980 z += 2;
00981
00982 byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->cfg_cnt,z,2);
00983 z += 2;
00984
00985 j++;
00986
00987 }
00988
00989 temp_cfg = temp_cfg->cfgnext;
00990
00991 }
00992
00993
00994 byte_by_byte_copy(cfgframe,datarate,z,2);
00995 z += 2;
00996
00997 chk = compute_CRC(cfgframe,z);
00998 cfgframe[z++] = (chk >> 8) & ~(~0<<8);
00999 cfgframe[z++] = (chk ) & ~(~0<<8);
01000 return z;
01001 }