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
0269b299
Commit
0269b299
authored
Feb 25, 2020
by
Zhukov, Alexander P
Browse files
WIP
parent
52bf241e
Changes
1
Hide whitespace changes
Inline
Side-by-side
c-code/test_code.c
View file @
0269b299
...
...
@@ -2,7 +2,7 @@
#include <string.h>
#include <stdlib.h>
#include <byteswap.h>
#include <sys/time.h>
unsigned
long
encodeDbl
(
double
a
){
unsigned
long
b
;
...
...
@@ -41,18 +41,21 @@ BinaryStorage bs_open(char* filename){
return
storage
;
}
int
write_record
(
BinaryStorage
*
bs
,
char
*
name
,
double
value
){
int
write_record
(
BinaryStorage
*
bs
,
char
*
name
,
double
timestamp
,
double
value
){
unsigned
char
name_len
=
strlen
(
name
);
unsigned
int
total_length
=
bswap_32
(
1
+
1
+
name_len
+
1
+
8
+
1
);
unsigned
int
total_length
=
bswap_32
(
1
+
1
+
name_len
+
1
+
8
+
1
+
8
+
1
);
fwrite
(
&
total_length
,
4
,
1
,
bs
->
file
);
fputc
(
1
,
bs
->
file
);
fwrite
(
&
name_len
,
1
,
1
,
bs
->
file
);
fwrite
(
name
,
1
,
name_len
,
bs
->
file
);
fputc
(
17
,
bs
->
file
);
unsigned
long
rawdata
=
encodeDbl
(
value
);
fputc
(
2
,
bs
->
file
);
unsigned
long
rawdata
=
encodeDbl
(
timestamp
);
fwrite
(
&
rawdata
,
8
,
1
,
bs
->
file
);
fputc
(
17
,
bs
->
file
);
rawdata
=
encodeDbl
(
value
);
fwrite
(
&
rawdata
,
8
,
1
,
bs
->
file
);
fputc
(
254
,
bs
->
file
);
...
...
@@ -85,6 +88,12 @@ void bs_close(BinaryStorage *bs){
int
main
(){
printf
(
"Hello World!
\n
"
);
BinaryStorage
storage
=
bs_open
(
"test_c.bin"
);
write_record
(
&
storage
,
"Hello World!"
,
314
);
struct
timeval
tp
;
gettimeofday
(
&
tp
,
NULL
);
long
int
ms
=
tp
.
tv_sec
*
1000
+
tp
.
tv_usec
/
1000
;
double
timestamp
=
tp
.
tv_sec
;
printf
(
"%d
\n
"
,
tp
.
tv_sec
);
write_record
(
&
storage
,
"Hello World!"
,
timestamp
,
314
);
bs_close
(
&
storage
);
}
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