Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ML
lib
Binary Storage
Commits
6e56f708
Commit
6e56f708
authored
Feb 28, 2020
by
Zhukov, Alexander P
Browse files
Cahnged names of custom typedefs to avoid name clashing
parent
f0e558a4
Changes
4
Hide whitespace changes
Inline
Side-by-side
c-code/binary_storage.c
View file @
6e56f708
...
...
@@ -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
,
bs
TSTMP
timestamp
,
bs
TAGS
*
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
,
bs
TSTMP
timestamp
,
bs
TAGS
*
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
,
bs
TSTMP
timestamp
,
bs
DBL
value
,
bs
TAGS
*
tags
,
char
*
description
){
uint32_t
count
=
value
.
count
;
if
(
count
==
0
){
return
-
1
;
...
...
c-code/binary_storage.h
View file @
6e56f708
...
...
@@ -49,17 +49,17 @@ typedef struct tagset {
size_t
count
;
char
**
data
;
}
TAGS
;
}
bs
TAGS
;
typedef
struct
timestamp
{
uint32_t
seconds
;
uint32_t
nanos
;
}
TSTMP
;
}
bs
TSTMP
;
typedef
struct
doublevalue
{
double
*
data
;
uint32_t
count
;
}
DBL
;
}
bs
DBL
;
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
,
bs
TSTMP
timestamp
,
bs
TAGS
*
tags
,
char
*
description
);
int
bsWriteDBL
(
BinaryStorage
*
bs
,
char
*
name
,
bs
TSTMP
timestamp
,
bs
DBL
value
,
bs
TAGS
*
tags
,
char
*
description
);
void
bsClose
(
BinaryStorage
*
bs
);
c-code/test_DBL.c
View file @
6e56f708
...
...
@@ -5,7 +5,7 @@
int
main
(){
BinaryStorage
storage
=
bsOpen
(
"test_DBL.bin"
);
TAGS
tags
=
{.
data
=
NULL
,
.
count
=
0
};
//empty
bs
TAGS
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
};
bs
TSTMP
timestamp
=
{.
seconds
=
tp
.
tv_sec
,
.
nanos
=
tp
.
tv_usec
*
1000
};
double
wf
[
10000
];
wf
[
0
]
=
1
.
0
;
wf
[
1
]
=
2
.
0
;
DBL
value
;
bs
DBL
value
;
double
x
;
char
*
description
;
char
*
tt
[
10
];
if
(
i
%
2
==
0
){
x
=
3
.
1415
*
i
;
value
=
(
DBL
){.
count
=
1
,
.
data
=&
x
};
value
=
(
bs
DBL
){.
count
=
1
,
.
data
=&
x
};
description
=
"double scalar"
;
tt
[
0
]
=
"SCALAR"
;
tt
[
1
]
=
"DOUBLE"
;
tags
=
(
TAGS
){.
data
=
tt
,
.
count
=
2
};
tags
=
(
bs
TAGS
){.
data
=
tt
,
.
count
=
2
};
}
else
{
value
=
(
DBL
){.
count
=
sizeof
(
wf
)
/
8
,
.
data
=
wf
};
value
=
(
bs
DBL
){.
count
=
sizeof
(
wf
)
/
8
,
.
data
=
wf
};
description
=
"double[]"
;
tt
[
0
]
=
"ARRAY"
;
tt
[
1
]
=
"DOUBLE"
;
tags
=
(
TAGS
){.
data
=
tt
,
.
count
=
2
};
tags
=
(
bs
TAGS
){.
data
=
tt
,
.
count
=
2
};
}
bsWriteDBL
(
&
storage
,
"Test_Record"
,
timestamp
,
value
,
&
tags
,
description
);
...
...
c-code/test_MPS.c
View file @
6e56f708
...
...
@@ -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
};
bs
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
]
=
t
ag
;
//all records in the file will have this tag
bs
TAGS
tags
=
{.
data
=
tag_str
,
.
count
=
0
};
tag_str
[
0
]
=
t
rip_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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment