hrev51378 adds 2 changesets to branch 'master'
old head: cf3524e07fb9680c9071fe15c4b236151ae28340
new head: 8bff17cfd8936c94ce414f390323e3c8aa639e13
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=8bff17cfd893+%5Ecf3524e07fb9
----------------------------------------------------------------------------
7b6e6c1587a4: FT232x driver: support hardware flow control.
We had everything in place, except we never actually sent the command to
the device.
Note that the other drivers (prolific, etc) as well as pc_serial need to
be updated as well (might do it when I get access to hardware where I
can test the changes).
8bff17cfd893: SerialConnect: support sending raw files
Add a generic FileSender interface, which XModemSender implements. Add a
new RawSender which implements the same interface.
The RawSender currently blocks the application thread while sending,
which is not a good idea. Will rework this when I allow cancelling
transfers before they complete.
[ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ]
----------------------------------------------------------------------------
11 files changed, 199 insertions(+), 33 deletions(-)
.../kernel/drivers/ports/usb_serial/FTDI.cpp | 40 ++++++++++--
.../kernel/drivers/ports/usb_serial/FTDI.h | 1 +
.../drivers/ports/usb_serial/SerialDevice.cpp | 14 ++++-
.../drivers/ports/usb_serial/SerialDevice.h | 1 +
src/apps/serialconnect/FileSender.cpp | 64 ++++++++++++++++++++
src/apps/serialconnect/FileSender.h | 39 ++++++++++++
src/apps/serialconnect/Jamfile | 1 +
src/apps/serialconnect/SerialApp.cpp | 9 ++-
src/apps/serialconnect/SerialApp.h | 5 +-
src/apps/serialconnect/SerialWindow.cpp | 22 +++++--
src/apps/serialconnect/XModem.h | 36 +++++------
############################################################################
Commit: 7b6e6c1587a45b4e07952c93209569245cadf81d
URL: http://cgit.haiku-os.org/haiku/commit/?id=7b6e6c1587a4
Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date: Sat Aug 26 13:29:37 2017 UTC
FT232x driver: support hardware flow control.
We had everything in place, except we never actually sent the command to
the device.
Note that the other drivers (prolific, etc) as well as pc_serial need to
be updated as well (might do it when I get access to hardware where I
can test the changes).
----------------------------------------------------------------------------
diff --git a/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.cpp
b/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.cpp
index 60f2a79..4aa11e8 100644
--- a/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.cpp
+++ b/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.cpp
@@ -185,7 +185,8 @@ FTDIDevice::SetLineCoding(usb_cdc_line_coding *lineCoding)
status_t
FTDIDevice::SetControlLineState(uint16 state)
{
- TRACE_FUNCALLS("> FTDIDevice::SetControlLineState(0x%08x, 0x%04x)\n",
this, state);
+ TRACE_FUNCALLS("> FTDIDevice::SetControlLineState(0x%08x, 0x%04x)\n",
+ this, state);
int32 control;
control = (state & USB_CDC_CONTROL_SIGNAL_STATE_RTS) ?
FTDI_SIO_SET_RTS_HIGH
@@ -197,8 +198,10 @@ FTDIDevice::SetControlLineState(uint16 state)
FTDI_SIO_MODEM_CTRL, control,
FTDI_PIT_DEFAULT, 0, NULL, &length);
- if (status != B_OK)
- TRACE_ALWAYS("= FTDIDevice::SetControlLineState(): control set
request failed: 0x%08x\n", status);
+ if (status != B_OK) {
+ TRACE_ALWAYS("= FTDIDevice::SetControlLineState(): "
+ "control set request failed: 0x%08x\n", status);
+ }
control = (state & USB_CDC_CONTROL_SIGNAL_STATE_DTR) ?
FTDI_SIO_SET_DTR_HIGH
: FTDI_SIO_SET_DTR_LOW;
@@ -208,10 +211,37 @@ FTDIDevice::SetControlLineState(uint16 state)
FTDI_SIO_MODEM_CTRL, control,
FTDI_PIT_DEFAULT, 0, NULL, &length);
+ if (status != B_OK) {
+ TRACE_ALWAYS("= FTDIDevice::SetControlLineState(): "
+ "control set request failed: 0x%08x\n", status);
+ }
+
+ TRACE_FUNCRET("< FTDIDevice::SetControlLineState() returns: 0x%08x\n",
+ status);
+ return status;
+}
+
+
+status_t
+FTDIDevice::SetHardwareFlowControl(bool enable)
+{
+ TRACE_FUNCALLS("> FTDIDevice::SetHardwareFlowControl(0x%08x, %d)\n",
+ this, enable);
+
+ uint32 control = enable ? FTDI_SIO_RTS_CTS_HS :
FTDI_SIO_DISABLE_FLOW_CTRL;
+
+ size_t length = 0;
+ status_t status = gUSBModule->send_request(Device(),
+ USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT,
+ FTDI_SIO_SET_FLOW_CTRL, 0,
+ FTDI_PIT_DEFAULT | (control << 8), 0, NULL, &length);
+
if (status != B_OK)
- TRACE_ALWAYS("= FTDIDevice::SetControlLineState(): control set
request failed: 0x%08x\n", status);
+ TRACE_ALWAYS("= FTDIDevice::SetHardwareFlowControl(): "
+ "request failed: 0x%08x\n", status);
- TRACE_FUNCRET("< FTDIDevice::SetControlLineState() returns: 0x%08x\n",
status);
+ TRACE_FUNCRET("< FTDIDevice::SetHardwareFlowControl() returns:
0x%08x\n",
+ status);
return status;
}
diff --git a/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.h
b/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.h
index 1496b33..2dd6631 100644
--- a/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.h
+++ b/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.h
@@ -38,6 +38,7 @@ virtual status_t
ResetDevice();
virtual status_t
SetLineCoding(usb_cdc_line_coding *coding);
virtual status_t
SetControlLineState(uint16 state);
+virtual status_t
SetHardwareFlowControl(bool enable);
virtual void OnRead(char **buffer,
size_t *numBytes);
virtual void OnWrite(const char
*buffer, size_t *numBytes,
diff --git a/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.cpp
b/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.cpp
index eca908f..f5b18cf 100644
--- a/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.cpp
+++ b/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.cpp
@@ -180,6 +180,8 @@ SerialDevice::SetModes(struct termios *tios)
// update the termios of the device side
gTTYModule->tty_control(fDeviceTTYCookie, TCSETA, &config,
sizeof(termios));
+ SetHardwareFlowControl((tios->c_cflag & CRTSCTS) != 0);
+
usb_cdc_line_coding lineCoding;
lineCoding.speed = speed;
lineCoding.stopbits = (tios->c_cflag & CSTOPB)
@@ -521,7 +523,7 @@ status_t
SerialDevice::SetLineCoding(usb_cdc_line_coding *coding)
{
// default implementation - does nothing
- return B_OK;
+ return B_NOT_SUPPORTED;
}
@@ -529,7 +531,15 @@ status_t
SerialDevice::SetControlLineState(uint16 state)
{
// default implementation - does nothing
- return B_OK;
+ return B_NOT_SUPPORTED;
+}
+
+
+status_t
+SerialDevice::SetHardwareFlowControl(bool enable)
+{
+ // default implementation - does nothing
+ return B_NOT_SUPPORTED;
}
diff --git a/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.h
b/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.h
index 213e255..f834e61 100644
--- a/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.h
+++ b/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.h
@@ -78,6 +78,7 @@ virtual status_t
ResetDevice();
virtual status_t
SetLineCoding(usb_cdc_line_coding *coding);
virtual status_t
SetControlLineState(uint16 state);
+virtual status_t
SetHardwareFlowControl(bool enable);
virtual void OnRead(char **buffer,
size_t *numBytes);
virtual void OnWrite(const char
*buffer, size_t *numBytes,
############################################################################
Revision: hrev51378
Commit: 8bff17cfd8936c94ce414f390323e3c8aa639e13
URL: http://cgit.haiku-os.org/haiku/commit/?id=8bff17cfd893
Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date: Sat Aug 26 13:32:44 2017 UTC
SerialConnect: support sending raw files
Add a generic FileSender interface, which XModemSender implements. Add a
new RawSender which implements the same interface.
The RawSender currently blocks the application thread while sending,
which is not a good idea. Will rework this when I allow cancelling
transfers before they complete.
----------------------------------------------------------------------------
diff --git a/src/apps/serialconnect/FileSender.cpp
b/src/apps/serialconnect/FileSender.cpp
new file mode 100644
index 0000000..67100ef
--- /dev/null
+++ b/src/apps/serialconnect/FileSender.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017, Adrien Destugues, pulkomandy@xxxxxxxxxxxxx
+ * Distributed under terms of the MIT license.
+ */
+
+
+#include "FileSender.h"
+
+#include "SerialApp.h"
+
+#include <DataIO.h>
+#include <Message.h>
+#include <SerialPort.h>
+
+
+RawSender::RawSender(BDataIO* source, BSerialPort* sink, BHandler* listener)
+{
+ // FIXME doing this all here in the constructor is not good. We need to
+ // do things asynchronously instead so as not to lock the application
+ // thread.
+ off_t sourceSize;
+ off_t position;
+
+ BPositionIO* pos = dynamic_cast<BPositionIO*>(source);
+ if (pos)
+ pos->GetSize(&sourceSize);
+ else
+ sourceSize = 0;
+ position = 0;
+
+ BMessenger messenger(listener);
+
+ uint8_t buffer[256];
+ for (;;) {
+ ssize_t s = source->Read(&buffer, sizeof(buffer));
+ if (s <= 0)
+ return;
+
+ sink->Write(buffer, s);
+ position += s;
+
+ BMessage msg(kMsgProgress);
+ msg.AddInt32("pos", position);
+ msg.AddInt32("size", sourceSize);
+ msg.AddString("info", "Sending" B_UTF8_ELLIPSIS);
+ messenger.SendMessage(&msg);
+
+ //usleep(20000);
+ }
+}
+
+
+RawSender::~RawSender()
+{
+}
+
+
+bool
+RawSender::BytesReceived(const uint8_t* data, size_t length)
+{
+ // Nothing to do with received bytes, this protocol has no kind of
+ // acknowledgement from remote side.
+ return true;
+}
diff --git a/src/apps/serialconnect/FileSender.h
b/src/apps/serialconnect/FileSender.h
new file mode 100644
index 0000000..f3a4bbd
--- /dev/null
+++ b/src/apps/serialconnect/FileSender.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2017, Adrien Destugues, pulkomandy@xxxxxxxxxxxxx
+ * Distributed under terms of the MIT license.
+ */
+
+
+#ifndef FILESENDER_H
+#define FILESENDER_H
+
+
+#include <stdint.h>
+#include <string.h>
+
+
+class BDataIO;
+class BHandler;
+class BSerialPort;
+
+
+class FileSender {
+ public:
+ virtual bool BytesReceived(const uint8_t* data,
+ size_t length)
= 0;
+};
+
+
+class RawSender: public FileSender {
+ public:
+
RawSender(BDataIO* source, BSerialPort* sink,
+
BHandler* listener);
+ virtual ~RawSender();
+
+ virtual bool BytesReceived(const uint8_t*
data,
+ size_t
length);
+
+};
+
+
+#endif /* !FILESENDER_H */
diff --git a/src/apps/serialconnect/Jamfile b/src/apps/serialconnect/Jamfile
index c2c1fc4..620a5c9 100644
--- a/src/apps/serialconnect/Jamfile
+++ b/src/apps/serialconnect/Jamfile
@@ -7,6 +7,7 @@ SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src apps serialconnect
libvterm src ] ;
Application SerialConnect :
CustomRateWindow.cpp
+ FileSender.cpp
SerialApp.cpp
SerialWindow.cpp
TermView.cpp
diff --git a/src/apps/serialconnect/SerialApp.cpp
b/src/apps/serialconnect/SerialApp.cpp
index f78ae7f..6082cab 100644
--- a/src/apps/serialconnect/SerialApp.cpp
+++ b/src/apps/serialconnect/SerialApp.cpp
@@ -164,10 +164,12 @@ void SerialApp::MessageReceived(BMessage* message)
debugger("Invalid BMessage received");
return;
}
- case kMsgSendXmodem:
+ case kMsgSendFile:
{
entry_ref ref;
+ BString protocol = message->FindString("protocol");
+
if (message->FindRef("refs", &ref) == B_OK) {
BFile* file = new BFile(&ref, B_READ_ONLY);
status_t error = file->InitCheck();
@@ -175,7 +177,10 @@ void SerialApp::MessageReceived(BMessage* message)
puts(strerror(error));
else {
delete fFileSender;
- fFileSender = new XModemSender(file,
&fSerialPort, fWindow);
+ if (protocol == "xmodem")
+ fFileSender = new
XModemSender(file, &fSerialPort, fWindow);
+ else
+ fFileSender = new
RawSender(file, &fSerialPort, fWindow);
}
} else {
message->PrintToStream();
diff --git a/src/apps/serialconnect/SerialApp.h
b/src/apps/serialconnect/SerialApp.h
index 8f9e470..31da080 100644
--- a/src/apps/serialconnect/SerialApp.h
+++ b/src/apps/serialconnect/SerialApp.h
@@ -13,6 +13,7 @@
#include <SerialPort.h>
#include <String.h>
+#include "FileSender.h"
#include "XModem.h"
@@ -46,7 +47,7 @@ class SerialApp: public BApplication
BFile*
fLogFile;
BString
fPortPath;
- XModemSender* fFileSender;
+ FileSender*
fFileSender;
static status_t
PollSerial(void*);
@@ -63,7 +64,7 @@ enum messageConstants {
kMsgOpenPort = 'open',
kMsgProgress = 'prog',
kMsgSettings = 'stty',
- kMsgSendXmodem = 'xmtx',
+ kMsgSendFile = 'sndf',
};
#endif
diff --git a/src/apps/serialconnect/SerialWindow.cpp
b/src/apps/serialconnect/SerialWindow.cpp
index ac08922..4524fa1 100644
--- a/src/apps/serialconnect/SerialWindow.cpp
+++ b/src/apps/serialconnect/SerialWindow.cpp
@@ -87,19 +87,31 @@ SerialWindow::SerialWindow()
menuBar->AddItem(fFileMenu);
menuBar->AddItem(settingsMenu);
- // TODO edit menu - what's in it ?
+ // TODO edit menu - what's in it ? Usual copy/paste would be nice but we
+ // need a way to select text in the window.
//BMenu* editMenu = new BMenu("Edit");
//menuBar->AddItem(editMenu);
BMenuItem* logFile = new BMenuItem("Log to file" B_UTF8_ELLIPSIS,
new BMessage(kMsgLogfile));
fFileMenu->AddItem(logFile);
- // TODO implement these
+
+ // The "send" items are disabled initially. They are enabled only once
we
+ // are connected to a serial port.
+ BMessage* sendMsg = new BMessage(kMsgSendFile);
+ sendMsg->AddString("protocol", "xmodem");
BMenuItem* xmodemSend = new BMenuItem("XModem send" B_UTF8_ELLIPSIS,
- new BMessage(kMsgSendXmodem));
+ sendMsg);
fFileMenu->AddItem(xmodemSend);
xmodemSend->SetEnabled(false);
+
+ BMenuItem* rawSend = new BMenuItem("Raw send" B_UTF8_ELLIPSIS,
+ new BMessage(kMsgSendFile));
+ fFileMenu->AddItem(rawSend);
+ rawSend->SetEnabled(false);
+
#if 0
+ // TODO implement this
BMenuItem* xmodemReceive = new BMenuItem(
"X/Y/Zmodem receive" B_UTF8_ELLIPSIS, NULL);
fFileMenu->AddItem(xmodemReceive);
@@ -313,12 +325,12 @@ void SerialWindow::MessageReceived(BMessage* message)
return;
}
case kMsgLogfile:
- case kMsgSendXmodem:
+ case kMsgSendFile:
{
// Let's lazy init the file panel
if (fLogFilePanel == NULL) {
fLogFilePanel = new BFilePanel(
- message->what == kMsgSendXmodem ?
B_OPEN_PANEL : B_SAVE_PANEL,
+ message->what == kMsgSendFile ?
B_OPEN_PANEL : B_SAVE_PANEL,
&be_app_messenger, NULL, B_FILE_NODE,
false);
fLogFilePanel->SetMessage(message);
}
diff --git a/src/apps/serialconnect/XModem.h b/src/apps/serialconnect/XModem.h
index caa5731..c576a52 100644
--- a/src/apps/serialconnect/XModem.h
+++ b/src/apps/serialconnect/XModem.h
@@ -7,6 +7,7 @@
#ifndef XMODEM_H
#define XMODEM_H
+#include "FileSender.h"
#include <Messenger.h>
#include <String.h>
@@ -17,30 +18,31 @@ class BHandler;
class BSerialPort;
-class XModemSender {
+class XModemSender: public FileSender {
public:
- XModemSender(BDataIO* source,
BSerialPort* sink,
- BHandler* listener);
- ~XModemSender();
+
XModemSender(BDataIO* source, BSerialPort* sink,
+
BHandler* listener);
+ virtual ~XModemSender();
- bool BytesReceived(const uint8_t* data,
size_t length);
+ virtual bool BytesReceived(const uint8_t*
data,
+ size_t
length);
private:
- void SendBlock();
- status_t NextBlock();
+ void SendBlock();
+ status_t NextBlock();
- uint16_t CRC(const uint8_t* buffer, size_t size);
+ uint16_t CRC(const uint8_t*
buffer, size_t size);
private:
- BDataIO* fSource;
- BSerialPort* fSink;
- BMessenger fListener;
- off_t fBlockNumber;
- off_t fSourceSize;
- uint8_t fBuffer[128];
- bool fEotSent;
- bool fUseCRC;
- BString fStatus;
+ BDataIO* fSource;
+ BSerialPort* fSink;
+ BMessenger fListener;
+ off_t fBlockNumber;
+ off_t fSourceSize;
+ uint8_t fBuffer[128];
+ bool fEotSent;
+ bool fUseCRC;
+ BString fStatus;
};