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

WIP

parent 52bf241e
......@@ -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);
}
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