-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend.cc
More file actions
43 lines (34 loc) · 882 Bytes
/
Copy pathsend.cc
File metadata and controls
43 lines (34 loc) · 882 Bytes
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
#include <linux/can.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include "vcan.h"
void send(int socket, uint8_t number) {
static int message_count = 0;
message_count++;
struct can_frame frame;
frame.can_id = 0x123;
frame.can_dlc = 2;
frame.data[0] = message_count;
frame.data[1] = number;
int nbytes = write(socket, &frame, sizeof(struct can_frame));
std::printf("Sent %d bytes\n", nbytes);
}
int main(void) {
std::string iface = "vcan0";
int sock = vcan::create_can_socket(iface);
if (sock < 0) {
std::cout << "Failed to create a socket." << std::endl;
return 1;
}
int input;
while (true) {
std::cout << "Enter a number (0-255) to send: ";
std::cin >> input;
send(sock, input);
}
return 0;
}