Skip to content
Extraits de code Groupes Projets
Valider 36c022ec rédigé par Diego de Bernard de Fauconval's avatar Diego de Bernard de Fauconval
Parcourir les fichiers

on progresse dans en can

parent c6a16706
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -32,7 +32,7 @@ compile_UART :
g++ -o uart uart.cpp -lwiringPi
compile_spi :
g++ -o spi spi.cpp -l wiringPi
g++ -o spi spi.cpp
compile_encoder :
g++ -o encoder encoder.cpp -l wiringPi
......
Fichier supprimé
#include <stdio.h>
#include <stdlib.h>
......
Fichier supprimé
#include <stdlib.h>
#include <stdio.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include <string.h>
#include <unistd.h>
#include <iostream>
#include <net/if.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/can.h>
#include <linux/can/raw.h>
using namespace std;
const int CHANNEL_CAN = 1;
int main(int argc, char const *argv[])
{
int result, fd;
unsigned char buff[30];
int fd;
struct sockaddr_can addr;
struct ifreq ifr;
struct can_frame frame;
printf("CAN TRY\n");
fd = wiringPiSPISetup(CHANNEL_CAN, 500000);
if (fd == -1) {
printf("Error setup\n");
fd = socket(PF_CAN, SOCK_RAW, CAN_RAW);
if (fd < 0) {
perror("error socket");
exit(EXIT_FAILURE);
}
int reg = 0x40;
int GPIO[] = {0b00000001, 0b00000010, 0b00001000, 0b00010000};
buff[0] = reg;
for (int i = 0; i < 4; i++) {
buff[1] = GPIO[i];
printf("buff %i : %x %x\n",i, buff[0], buff[1]);
result = wiringPiSPIDataRW(CHANNEL_CAN, buff, 2);
printf("buff %i : %x %x\n",i, buff[0], buff[1]);
buff[0] = reg;
delay(1500);
strcpy(ifr.ifr_name, "can0");
ioctl(fd, SIOCGIFINDEX, &ifr);
memset(&addr, 0, sizeof(addr));
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
perror("error bind");
exit(EXIT_FAILURE);
}
frame.can_id = 0x02;
frame.can_dlc = 1;
frame.data[0] = 0b011111111;
if (write(fd, &frame, sizeof(struct can_frame)) != sizeof(struct can_frame)) {
perror("error write");
exit(EXIT_FAILURE);
}
// int nbytes;
// struct can_frame readframe;
// nbytes = read(fd, &readframe, sizeof(struct can_frame));
// if (nbytes < 0) {
// perror("reading");
// exit(EXIT_FAILURE);
// }
// printf("0x%x [%d]\n", readframe.can_id, readframe.can_dlc);
// for (int i = 0; i < frame.can_dlc; i++)
// {
// printf("0x\n", readframe.data[i]);
// }
// printf("\r");
return 0;
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter