Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Commit

Permalink
Fix termios related stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Zotov committed Jun 5, 2010
1 parent 252d999 commit 68c263a
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions software/vuxprog.cpp
Expand Up @@ -120,35 +120,29 @@ class protocol_error: public error {

class vuxboot {
public:
vuxboot(string filename, unsigned baud = 115200) : _debug(false) {
vuxboot(string filename, unsigned baud = B115200) : _debug(false) {
_fd = open(filename.c_str(), O_RDWR | O_NONBLOCK | O_NOCTTY);
if(!_fd) throw new io_error("cannot open port");

// Serial initialization was written with FTDI USB-to-serial converters
// in mind. Anyway, who wants to use non-8n1 protocol?

tcgetattr(_fd, &_termios);

termios tio = {0};
tio.c_iflag = IGNPAR;
tio.c_oflag = 0;
tio.c_cflag = B38400 | CLOCAL | CREAD | CS8;
tio.c_cflag = baud | CLOCAL | CREAD | CS8;
tio.c_lflag = 0;

tcflush(_fd, TCIFLUSH);
tcsetattr(_fd, TCSANOW, &tio);

// Following piece of code is copied from some orphaned Wine patch:
// so there are weird variable names. Try googling them!
serial_struct nuts;
ioctl(_fd, TIOCGSERIAL, &nuts);
nuts.custom_divisor = nuts.baud_base / baud;
if (!(nuts.custom_divisor)) nuts.custom_divisor = 1;
int arby = nuts.baud_base / nuts.custom_divisor;
nuts.flags &= ~ASYNC_SPD_MASK;
nuts.flags |= ASYNC_SPD_CUST;
ioctl(_fd, TIOCSSERIAL, &nuts);
}

~vuxboot() {
// do you ever want to kitten(1) your ttyUSB?
tcsetattr(_fd, TCSANOW, &_termios);

close(_fd);
}

Expand Down Expand Up @@ -373,6 +367,7 @@ class vuxboot {
bool _debug;

int _fd;
termios _termios;

bool _has_eeprom;
unsigned _eeprom_bytes;
Expand Down

0 comments on commit 68c263a

Please sign in to comment.