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

test_MPS.c creates file with all trip records

parent f25a0ce6
......@@ -95,7 +95,10 @@ int write_meta(BinaryStorage *bs, char* name, TSTMP timestamp, TAGS *tags, char*
fwrite(description, 1,length,bs->file);
}
}
int bsWriteTagsOnly(BinaryStorage *bs, char* name, TSTMP timestamp, TAGS *tags, char* description){
write_meta(bs, name, timestamp, tags, description, 0);
close_record(bs);
}
int bsWriteDBL(BinaryStorage *bs, char* name, TSTMP timestamp, DBL value, TAGS *tags, char* description){
uint32_t count = value.count;
if(count==0){
......
......@@ -69,5 +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);
void bsClose(BinaryStorage *bs);
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <binary_storage.h>
int main(){
//mess with time formatting
struct timeval curTime;
gettimeofday(&curTime, NULL);
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);
//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};
//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
//open storage, real file name should be unique of course
BinaryStorage storage = bsOpen("test_MPS.bin");
//first 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
char *name="";
//BLM records
tag_str[1] = "BLM"; //tags all BLM records
tags.count =2; //BLMs will have only two tags: BLM and trip identifier
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;
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
timestamp.seconds = curTime.tv_sec;
timestamp.nanos=curTime.tv_usec*1000;
bsWriteTagsOnly(&storage,name, timestamp, &tags, NULL); // BLM record
}
//Misc records
tag_str[1] = "MISC"; //tags all MISC records
name = "LEBT_Chop_DBCM01_fault";
//we will put the same timestamp as the cause, but it can be different of course
timestamp.seconds = curTime.tv_sec;
timestamp.nanos=curTime.tv_usec*1000;
bsWriteTagsOnly(&storage,name, timestamp, &tags, NULL); //first misc record
bsClose(&storage);
}
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