Make obreader setup the tty itself
This commit is contained in:
parent
1237f1a2ca
commit
133fc642b7
|
@ -18,6 +18,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <termios.h>
|
||||||
|
|
||||||
#define INTERVAL 1
|
#define INTERVAL 1
|
||||||
|
|
||||||
|
@ -72,6 +73,74 @@ void setnonblocking(int fd) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setupserial(int fd){
|
||||||
|
struct termios config;
|
||||||
|
|
||||||
|
if(!isatty(fd)) {
|
||||||
|
fprintf(stderr,"fd %d is not a tty?",fd);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
};
|
||||||
|
if(tcgetattr(fd, &config) < 0) {
|
||||||
|
perror("tcgetattr");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
};
|
||||||
|
//
|
||||||
|
// Input flags - Turn off input processing
|
||||||
|
// convert break to null byte, no CR to NL translation,
|
||||||
|
// no NL to CR translation, don't mark parity errors or breaks
|
||||||
|
// no input parity check, don't strip high bit off,
|
||||||
|
// no XON/XOFF software flow control
|
||||||
|
//
|
||||||
|
config.c_iflag &= ~(IGNBRK | BRKINT | ICRNL |
|
||||||
|
INLCR | PARMRK | INPCK | ISTRIP | IXON);
|
||||||
|
//
|
||||||
|
// Output flags - Turn off output processing
|
||||||
|
// no CR to NL translation, no NL to CR-NL translation,
|
||||||
|
// no NL to CR translation, no column 0 CR suppression,
|
||||||
|
// no Ctrl-D suppression, no fill characters, no case mapping,
|
||||||
|
// no local output processing
|
||||||
|
//
|
||||||
|
// config.c_oflag &= ~(OCRNL | ONLCR | ONLRET |
|
||||||
|
// ONOCR | ONOEOT| OFILL | OLCUC | OPOST);
|
||||||
|
config.c_oflag = 0;
|
||||||
|
//
|
||||||
|
// No line processing:
|
||||||
|
// echo off, echo newline off, canonical mode off,
|
||||||
|
// extended input processing off, signal chars off
|
||||||
|
//
|
||||||
|
config.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
|
||||||
|
//
|
||||||
|
// Turn off character processing
|
||||||
|
// clear current char size mask, no parity checking,
|
||||||
|
// no output processing, force 8 bit input
|
||||||
|
//
|
||||||
|
config.c_cflag &= ~(CSIZE | PARENB);
|
||||||
|
config.c_cflag |= CS8;
|
||||||
|
//
|
||||||
|
// One input byte is enough to return from read()
|
||||||
|
// Inter-character timer off
|
||||||
|
//
|
||||||
|
config.c_cc[VMIN] = 1;
|
||||||
|
config.c_cc[VTIME] = 0;
|
||||||
|
//
|
||||||
|
// Communication speed (simple version, using the predefined
|
||||||
|
// constants)
|
||||||
|
//
|
||||||
|
/*
|
||||||
|
if(cfsetispeed(&config, B9600) < 0 || cfsetospeed(&config, B9600) < 0) {
|
||||||
|
perror("cfset[io]speed");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Finally, apply the configuration
|
||||||
|
//
|
||||||
|
if(tcsetattr(fd, TCSAFLUSH, &config) < 0) {
|
||||||
|
perror("tcsetattr");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/* Reference is https://r0ket.badge.events.ccc.de/tracking:reader */
|
/* Reference is https://r0ket.badge.events.ccc.de/tracking:reader */
|
||||||
void pkt_cleanup(int idx){
|
void pkt_cleanup(int idx){
|
||||||
static u_int32_t ctr;
|
static u_int32_t ctr;
|
||||||
|
@ -285,6 +354,7 @@ and sends them off via TCP/UDP to a central host\n\n\
|
||||||
perror("open(device)");
|
perror("open(device)");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
};
|
};
|
||||||
|
setupserial(devfd);
|
||||||
setnonblocking(devfd);
|
setnonblocking(devfd);
|
||||||
setup_r0ket(devfd);
|
setup_r0ket(devfd);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue