forked from teamrudra/r25-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
52 lines (37 loc) · 1.2 KB
/
main.c
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
#include <stdint.h>
#include <stdio.h>
#include <parsing.h>
int main(int argc, char** argv) {
if (argc != 3) {
printf("Usage: %s <SBUS_port> <Sabertooth_port>\n", argv[0]);
return 1;
}
char *port_name_1 = argv[1]; // SBUS
char *port_name_2 = argv[2]; // Sabertooth1
FILE *sbus;
FILE *sabertooth;
// to store sbus packets
uint8_t sbus_packet[25]; // Adjust the size if necessary
// to store value of individual RC channel
uint16_t *channel;
// pwm value after interpolation
int pwm;
// opening serial port for serial communication with Sabertooth and SBUS
sbus = open_file(port_name_1, "rb");
sabertooth = open_file(port_name_2, "w+");
if (sbus == NULL || sabertooth == NULL) {
return 1;
}
// read data from RC transmitter using sbus
read_SBUS(sbus_packet, sizeof(uint8_t), 25, sbus);
// parsing sbus packet
channel = parse_buffer(sbus_packet);
// get pwm range for Sabertooth 1
pwm = interpolation(channel[0]);
// write data to Sabertooth 1
write_to_SB(sabertooth, "%d\n", pwm);
// closing all serial port
close_file(sbus);
close_file(sabertooth);
return 0;
}