mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Reset the Greaseweazle data stream when connecting.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
#include "globals.h"
|
||||
#include "usb.h"
|
||||
#include "lib/globals.h"
|
||||
#include "protocol.h"
|
||||
#include "fluxmap.h"
|
||||
#include "bytes.h"
|
||||
#include "lib/fluxmap.h"
|
||||
#include "lib/bytes.h"
|
||||
#include "lib/usb/usb.pb.h"
|
||||
#include "greaseweazle.h"
|
||||
#include "serial.h"
|
||||
#include "usb.h"
|
||||
#include <unistd.h>
|
||||
|
||||
static const char* gw_error(int e)
|
||||
{
|
||||
@@ -96,6 +97,13 @@ public:
|
||||
version);
|
||||
}
|
||||
|
||||
/* Twiddle the baud rate, which indicates to the Greaseweazle that the
|
||||
* data stream has been reset. */
|
||||
|
||||
_serial->setBaudRate(10000);
|
||||
usleep(100000);
|
||||
_serial->setBaudRate(9600);
|
||||
|
||||
/* Configure the hardware. */
|
||||
|
||||
do_command({CMD_SET_BUS_TYPE, 3, (uint8_t)config.bus_type()});
|
||||
|
||||
@@ -88,6 +88,17 @@ public:
|
||||
return wlen;
|
||||
}
|
||||
|
||||
void setBaudRate(int baudRate) override
|
||||
{
|
||||
DCB dcb = {.DCBlength = sizeof(DCB),
|
||||
.BaudRate = baudRate,
|
||||
.fBinary = true,
|
||||
.ByteSize = 8,
|
||||
.Parity = NOPARITY,
|
||||
.StopBits = ONESTOPBIT};
|
||||
SetCommState(_handle, &dcb);
|
||||
}
|
||||
|
||||
private:
|
||||
static std::string get_last_error_string()
|
||||
{
|
||||
@@ -181,6 +192,14 @@ public:
|
||||
return wlen;
|
||||
}
|
||||
|
||||
void setBaudRate(int baudRate) override
|
||||
{
|
||||
struct termios t;
|
||||
tcgetattr(_fd, &t);
|
||||
cfsetspeed(&t, baudRate);
|
||||
tcsetattr(_fd, TCSANOW, &t);
|
||||
}
|
||||
|
||||
private:
|
||||
int _fd;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ public:
|
||||
virtual ~SerialPort();
|
||||
virtual ssize_t readImpl(uint8_t* buffer, size_t len) = 0;
|
||||
virtual ssize_t write(const uint8_t* buffer, size_t len) = 0;
|
||||
virtual void setBaudRate(int baudRate) = 0;
|
||||
|
||||
void read(uint8_t* buffer, size_t len);
|
||||
void read(Bytes& bytes);
|
||||
|
||||
Reference in New Issue
Block a user