-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathTelemetry.h
71 lines (50 loc) · 1.51 KB
/
Telemetry.h
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
71
#pragma once
#include "common/base_classes/FOCMotor.h"
#include "../SimpleFOCRegisters.h"
#include "../RegisterIO.h"
#ifndef TELEMETRY_MAX_TELEMETRIES
#define TELEMETRY_MAX_TELEMETRIES 4
#endif
#ifndef TELEMETRY_MAX_REGISTERS
#define TELEMETRY_MAX_REGISTERS 8
#endif
#ifndef TELEMETRY_MAX_MOTORS
#define TELEMETRY_MAX_MOTORS 4
#endif
#define DEF_TELEMETRY_DOWNSAMPLE 100
typedef enum : uint8_t {
TELEMETRY_PACKETTYPE_DATA = 'T',
TELEMETRY_PACKETTYPE_HEADER = 'H'
} TelemetryFrameType;
class Telemetry {
friend class SimpleFOCRegisters;
public:
Telemetry();
virtual ~Telemetry();
virtual void init(PacketIO& _comms);
void addMotor(FOCMotor* motor);
void setTelemetryRegisters(uint8_t numRegisters, uint8_t* registers, uint8_t* motors = NULL);
void run();
uint16_t downsample = DEF_TELEMETRY_DOWNSAMPLE;
uint32_t min_elapsed_time = 0;
uint32_t last_iterations = 0;
static uint8_t num_telemetry;
static uint8_t telemetry_ctrl;
static Telemetry* telemetries[];
protected:
virtual void sendTelemetry();
virtual void sendHeader();
uint8_t id;
FOCMotor* motors[TELEMETRY_MAX_MOTORS];
uint8_t numMotors = 0;
uint8_t numRegisters;
uint8_t registers[TELEMETRY_MAX_REGISTERS];
uint8_t registers_motor[TELEMETRY_MAX_REGISTERS];
uint8_t packetSize;
bool headerSent;
unsigned long last_run_time = 0;
unsigned long last_iter_time = 0;
uint16_t downsampleCnt = 0;
uint32_t iterations = 0;
PacketIO* comms;
};