-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·70 lines (47 loc) · 1.49 KB
/
main.cpp
File metadata and controls
executable file
·70 lines (47 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <cmath>
#include "jy901.h"
#include <iostream>
#include <fstream>
#include <time.h> /* time */
struct Range{
int accel = 4;
int gyro = 1000;
const double g = 9.8;
const int k = 32768;
}imu_range;
void publish(CJY901::Data &data)
{
float x = (float)data.stcAcc.a[0]/32768*imu_range.accel*imu_range.g;
float y = (float)data.stcAcc.a[1]/32768*imu_range.accel*imu_range.g;
float z = (float)data.stcAcc.a[2]/32768*imu_range.accel*imu_range.g;
printf("%f %f %f \n", x, y, z);
// data.stcAcc, data.stcGyro, data.stcQuater
// data.stcMag
}
void print_hex(unsigned char* buffer, int size)
{
for (int i = 0; i < size; i++)
std::cout << std::hex << (unsigned int)buffer[i] << " ";
std::cout << std::endl;
}
int main (void){
srand (time(NULL));
std::ifstream hexdump;
hexdump.open("../raw_imu_data.hex", std::ios::binary);
CJY901 jy901;
unsigned char buffer[1024];
while(hexdump){
static int last_seq = 0;
// read random number of bytes, simulating hardware
int size = std::rand() % 16 + 8;
hexdump.read(reinterpret_cast<char *>(buffer), size);
// print_hex(buffer,size);
jy901.CopeSerialData(buffer,size);
if (last_seq != jy901.data.seq){
last_seq = jy901.data.seq;
publish(jy901.data);
}
}
std::cout << "All Parsed!" << std::endl;
return 0;
}