Commit 6e56f708 authored by Zhukov, Alexander P's avatar Zhukov, Alexander P
Browse files

Cahnged names of custom typedefs to avoid name clashing

parent f0e558a4
......@@ -47,7 +47,7 @@ void close_record(BinaryStorage *bs){
}
int write_meta(BinaryStorage *bs, char* name, TSTMP timestamp, TAGS *tags, char* description, uint32_t extra_count){
int write_meta(BinaryStorage *bs, char* name, bsTSTMP timestamp, bsTAGS *tags, char* description, uint32_t extra_count){
unsigned char name_len = strlen(name);
uint32_t descr_len=0;
if(description!=NULL){
......@@ -96,12 +96,12 @@ int write_meta(BinaryStorage *bs, char* name, TSTMP timestamp, TAGS *tags, char*
}
return 0;
}
int bsWriteTagsOnly(BinaryStorage *bs, char* name, TSTMP timestamp, TAGS *tags, char* description){
int bsWriteTagsOnly(BinaryStorage *bs, char* name, bsTSTMP timestamp, bsTAGS *tags, char* description){
write_meta(bs, name, timestamp, tags, description, 0);
close_record(bs);
return 0;
}
int bsWriteDBL(BinaryStorage *bs, char* name, TSTMP timestamp, DBL value, TAGS *tags, char* description){
int bsWriteDBL(BinaryStorage *bs, char* name, bsTSTMP timestamp, bsDBL value, bsTAGS *tags, char* description){
uint32_t count = value.count;
if(count==0){
return -1;
......
......@@ -49,17 +49,17 @@ typedef struct tagset {
size_t count;
char **data;
} TAGS;
} bsTAGS;
typedef struct timestamp {
uint32_t seconds;
uint32_t nanos;
} TSTMP;
} bsTSTMP;
typedef struct doublevalue {
double *data;
uint32_t count;
} DBL;
} bsDBL;
typedef struct storage {
FILE* file;
......@@ -69,6 +69,6 @@ typedef struct storage {
} BinaryStorage;
BinaryStorage bsOpen(char* filename);
int bsWriteTagsOnly(BinaryStorage *bs, char* name, TSTMP timestamp, TAGS *tags, char* description);
int bsWriteDBL(BinaryStorage *bs, char* name, TSTMP timestamp, DBL value, TAGS *tags, char* description);
int bsWriteTagsOnly(BinaryStorage *bs, char* name, bsTSTMP timestamp, bsTAGS *tags, char* description);
int bsWriteDBL(BinaryStorage *bs, char* name, bsTSTMP timestamp, bsDBL value, bsTAGS *tags, char* description);
void bsClose(BinaryStorage *bs);
......@@ -5,7 +5,7 @@
int main(){
BinaryStorage storage = bsOpen("test_DBL.bin");
TAGS tags = {.data=NULL, .count = 0}; //empty
bsTAGS tags = {.data=NULL, .count = 0}; //empty
int i=0;
for(i=0;i<3000;i++){
......@@ -13,32 +13,32 @@ int main(){
long int ms;
gettimeofday(&tp, NULL);
ms = tp.tv_sec * 1000 + tp.tv_usec / 1000;
TSTMP timestamp = {.seconds = tp.tv_sec, .nanos=tp.tv_usec*1000};
bsTSTMP timestamp = {.seconds = tp.tv_sec, .nanos=tp.tv_usec*1000};
double wf[10000];
wf[0] = 1.0;
wf[1] = 2.0;
DBL value;
bsDBL value;
double x;
char *description;
char *tt[10];
if(i%2==0){
x = 3.1415*i;
value = (DBL){.count = 1, .data=&x};
value = (bsDBL){.count = 1, .data=&x};
description = "double scalar";
tt[0]="SCALAR";
tt[1]="DOUBLE";
tags = (TAGS){.data=tt, .count = 2};
tags = (bsTAGS){.data=tt, .count = 2};
}
else {
value = (DBL){.count = sizeof(wf)/8, .data=wf};
value = (bsDBL){.count = sizeof(wf)/8, .data=wf};
description = "double[]";
tt[0]="ARRAY";
tt[1]="DOUBLE";
tags = (TAGS){.data=tt, .count = 2};
tags = (bsTAGS){.data=tt, .count = 2};
}
bsWriteDBL(&storage,"Test_Record", timestamp, value, &tags, description);
......
......@@ -11,29 +11,30 @@ int main(){
char time_str[16];
strftime(time_str, 16, "%Y%m%d_%H%M%S", localtime(&curTime.tv_sec));
char cause[255]="DTL_LLRF_HPM6_fault";
char tag[300] = "";
//merge cause with timestamp, this will be used to tag all records in the current file
//effectively it's a trip identifier
sprintf(tag, "%s-%s", cause, time_str);
char trip_id[300] = "";
sprintf(trip_id, "%s-%s", cause, time_str);
//This structure is made of seconds since UNIX epoch and nanos
//Preferrably to be taken from timing system
TSTMP timestamp = {.seconds = curTime.tv_sec, .nanos=curTime.tv_usec*1000};
bsTSTMP timestamp = {.seconds = curTime.tv_sec, .nanos=curTime.tv_usec*1000};
//this will hold tag strings
char *tag_str[10];
TAGS tags = {.data = tag_str, .count = 0};
tag_str[0] = tag; //all records in the file will have this tag
bsTAGS tags = {.data = tag_str, .count = 0};
tag_str[0] = trip_id; //all records in the file will have this tag
//open storage, real file name should be unique of course
BinaryStorage storage = bsOpen("test_MPS.bin");
//first record
//Cause record
tag_str[1] = "TRIP_CAUSE"; //this tags one record that is actual cause of trip
tag_str[2] = "LLRF"; //since it's actually LLRF we add this tag as well
tags.count = 3; // it will have three tags
bsWriteTagsOnly(&storage,cause, timestamp, &tags, NULL); //first record is actual cause
bsWriteTagsOnly(&storage,cause, timestamp, &tags, NULL); //first record to store is actual cause
char *name="";
......@@ -43,8 +44,7 @@ int main(){
char *blms[] = {"SCL_Diag_BLM_Mov01_fault", "SCL_Diag_BLM_Mov02_fault",
"SCL_Diag_BLM01b_fault","SCL_Diag_BLM01c_fault", "SCL_Diag_BLM02b_fault"};
int num_of_blms = 5;
int i=0;
int i=0, num_of_blms = 5;
for(i=0;i<num_of_blms;i++){
name = blms[i];
//we will put the same timestamp as the cause, but it can be different of course
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment