mirror of
https://github.com/RobotechLille/cdf2018-principal
synced 2024-11-13 03:46:12 +01:00
Communication A↔C : Base côté Chef
This commit is contained in:
parent
078b4ad2d9
commit
fc6b9e3317
|
@ -37,7 +37,7 @@ endif
|
|||
default: bin/testpin bin/premier
|
||||
|
||||
# Binaires (dont il faut spécifier les objets explicitement)
|
||||
bin/premier: obj/common.o
|
||||
bin/premier: obj/common.o obj/serial.o
|
||||
bin/testPin: obj/testPin.o
|
||||
$(CC) $(LDFLAGS) $^ -lwiringPi -o $@
|
||||
|
||||
|
|
1
chef/src/ACsignals.h
Symbolic link
1
chef/src/ACsignals.h
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../arduino/ACsignals.h
|
|
@ -1,7 +1,15 @@
|
|||
#include "premier.h"
|
||||
|
||||
int main() {
|
||||
printf("Hello world!\n");
|
||||
// avancer(10);
|
||||
#include "serial.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned char g;
|
||||
configureCA();
|
||||
sendByteCA('c');
|
||||
while ((g = readByteCA())) {
|
||||
printf("%c\n", g);
|
||||
}
|
||||
deconfigureCA();
|
||||
return 0;
|
||||
}
|
||||
|
|
58
chef/src/serial.c
Normal file
58
chef/src/serial.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
#include "serial.h"
|
||||
#include <stdio.h> // printf...
|
||||
#include <stdlib.h> // stuff
|
||||
#include <unistd.h> // read(), write()...
|
||||
#include <fcntl.h> // O_*
|
||||
#include <strings.h> // bzero
|
||||
|
||||
#include "common.h"
|
||||
|
||||
void configureCA()
|
||||
{
|
||||
// Connection au port série
|
||||
printf("Connexion à %s... ", ARDUINO_PORTNAME);
|
||||
arduino = open(ARDUINO_PORTNAME, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
if (arduino < 0) {
|
||||
printf("Échec !\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Configuration du port série
|
||||
struct termios cfg;
|
||||
bzero(&cfg, sizeof(cfg));
|
||||
cfg.c_cflag = CLOCAL | CREAD | CA_BAUDRATE | CS8;
|
||||
cfg.c_iflag = 0;
|
||||
cfg.c_oflag = 0;
|
||||
cfg.c_lflag = 0; /* set input mode (non-canonical, no echo,...) */
|
||||
cfg.c_cc[VTIME] = 0; /* inter-character timer unused */
|
||||
cfg.c_cc[VMIN] = 1; /* blocking read until 1 char received */
|
||||
if (tcsetattr(arduino, TCSANOW, &cfg) < 0) {
|
||||
perror("serialConfig.tcsetattr");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
printf("OK!\n");
|
||||
}
|
||||
|
||||
void deconfigureCA() {
|
||||
close(arduino);
|
||||
}
|
||||
|
||||
void sendByteCA(unsigned char data) {
|
||||
write(arduino, &data, sizeof(data));
|
||||
}
|
||||
|
||||
void sendCA(unsigned char code, void* data, size_t size)
|
||||
{
|
||||
sendByteCA(code);
|
||||
write(arduino, data, size);
|
||||
}
|
||||
|
||||
unsigned char readByteCA() {
|
||||
unsigned char c;
|
||||
while (read(arduino, &c, sizeof(c)) < 1) {
|
||||
}
|
||||
return c;
|
||||
}
|
19
chef/src/serial.h
Normal file
19
chef/src/serial.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef __SERIAL_H_
|
||||
#define __SERIAL_H_
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h> // baudrates
|
||||
|
||||
#include "ACsignals.h"
|
||||
|
||||
#define ARDUINO_PORTNAME "/dev/ttyACM0"
|
||||
#define CA_BAUDRATE B9600
|
||||
|
||||
int arduino;
|
||||
|
||||
void configureCA();
|
||||
void deconfigureCA();
|
||||
void sendByteCA(unsigned char data);
|
||||
unsigned char readByteCA();
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue