Log serial input to a file.
This commit is contained in:
@@ -16,6 +16,6 @@ Application SerialConnect :
|
|||||||
state.c
|
state.c
|
||||||
unicode.c
|
unicode.c
|
||||||
vterm.c
|
vterm.c
|
||||||
: be device $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSUPC++)
|
: be device tracker $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSUPC++)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -4,16 +4,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "SerialApp.h"
|
#include "SerialApp.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <Directory.h>
|
||||||
|
#include <Entry.h>
|
||||||
|
#include <File.h>
|
||||||
|
|
||||||
#include "SerialWindow.h"
|
#include "SerialWindow.h"
|
||||||
|
|
||||||
|
|
||||||
SerialApp::SerialApp()
|
SerialApp::SerialApp()
|
||||||
:
|
: BApplication(SerialApp::kApplicationSignature)
|
||||||
BApplication(SerialApp::kApplicationSignature)
|
, fLogFile(NULL)
|
||||||
{
|
{
|
||||||
fWindow = new SerialWindow();
|
fWindow = new SerialWindow();
|
||||||
|
|
||||||
@@ -24,6 +29,12 @@ SerialApp::SerialApp()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SerialApp::~SerialApp()
|
||||||
|
{
|
||||||
|
delete fLogFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SerialApp::ReadyToRun()
|
void SerialApp::ReadyToRun()
|
||||||
{
|
{
|
||||||
fWindow->Show();
|
fWindow->Show();
|
||||||
@@ -51,6 +62,19 @@ void SerialApp::MessageReceived(BMessage* message)
|
|||||||
// forward the message to the window, which will display the
|
// forward the message to the window, which will display the
|
||||||
// incoming data
|
// incoming data
|
||||||
fWindow->PostMessage(message);
|
fWindow->PostMessage(message);
|
||||||
|
|
||||||
|
if (fLogFile)
|
||||||
|
{
|
||||||
|
const char* bytes;
|
||||||
|
ssize_t length;
|
||||||
|
message->FindData("data", B_RAW_TYPE, (const void**)&bytes,
|
||||||
|
&length);
|
||||||
|
if(fLogFile->Write(bytes, length) != length)
|
||||||
|
{
|
||||||
|
puts("### WRITE ERROR");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case kMsgDataWrite:
|
case kMsgDataWrite:
|
||||||
@@ -62,6 +86,27 @@ void SerialApp::MessageReceived(BMessage* message)
|
|||||||
fSerialPort.Write(bytes, size);
|
fSerialPort.Write(bytes, size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case kMsgLogfile:
|
||||||
|
{
|
||||||
|
entry_ref parent;
|
||||||
|
const char* filename;
|
||||||
|
|
||||||
|
if (message->FindRef("directory", &parent) == B_OK
|
||||||
|
&& message->FindString("name", &filename) == B_OK)
|
||||||
|
{
|
||||||
|
delete fLogFile;
|
||||||
|
BDirectory directory(&parent);
|
||||||
|
fLogFile = new BFile(&directory, filename,
|
||||||
|
B_WRITE_ONLY | B_CREATE_FILE | B_OPEN_AT_END);
|
||||||
|
status_t error = fLogFile->InitCheck();
|
||||||
|
if(error != B_OK)
|
||||||
|
{
|
||||||
|
puts(strerror(error));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
debugger("Invalid BMessage received");
|
||||||
|
}
|
||||||
|
}
|
||||||
case kMsgSettings:
|
case kMsgSettings:
|
||||||
{
|
{
|
||||||
int32 baudrate;
|
int32 baudrate;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <SerialPort.h>
|
#include <SerialPort.h>
|
||||||
|
|
||||||
|
|
||||||
|
class BFile;
|
||||||
class SerialWindow;
|
class SerialWindow;
|
||||||
|
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ class SerialApp: public BApplication
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SerialApp();
|
SerialApp();
|
||||||
|
~SerialApp();
|
||||||
void ReadyToRun();
|
void ReadyToRun();
|
||||||
void MessageReceived(BMessage* message);
|
void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
@@ -26,6 +28,7 @@ class SerialApp: public BApplication
|
|||||||
BSerialPort fSerialPort;
|
BSerialPort fSerialPort;
|
||||||
sem_id fSerialLock;
|
sem_id fSerialLock;
|
||||||
SerialWindow* fWindow;
|
SerialWindow* fWindow;
|
||||||
|
BFile* fLogFile;
|
||||||
|
|
||||||
static status_t PollSerial(void*);
|
static status_t PollSerial(void*);
|
||||||
|
|
||||||
@@ -34,9 +37,10 @@ class SerialApp: public BApplication
|
|||||||
|
|
||||||
|
|
||||||
enum messageConstants {
|
enum messageConstants {
|
||||||
kMsgOpenPort = 'open',
|
|
||||||
kMsgDataRead = 'dare',
|
kMsgDataRead = 'dare',
|
||||||
kMsgDataWrite = 'dawr',
|
kMsgDataWrite = 'dawr',
|
||||||
|
kMsgLogfile = 'logf',
|
||||||
|
kMsgOpenPort = 'open',
|
||||||
kMsgSettings = 'stty',
|
kMsgSettings = 'stty',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <FilePanel.h>
|
||||||
#include <GroupLayout.h>
|
#include <GroupLayout.h>
|
||||||
#include <Menu.h>
|
#include <Menu.h>
|
||||||
#include <MenuBar.h>
|
#include <MenuBar.h>
|
||||||
@@ -19,9 +20,9 @@
|
|||||||
|
|
||||||
|
|
||||||
SerialWindow::SerialWindow()
|
SerialWindow::SerialWindow()
|
||||||
:
|
: BWindow(BRect(100, 100, 400, 400), SerialWindow::kWindowTitle,
|
||||||
BWindow(BRect(100, 100, 400, 400), SerialWindow::kWindowTitle,
|
|
||||||
B_DOCUMENT_WINDOW, B_QUIT_ON_WINDOW_CLOSE | B_AUTO_UPDATE_SIZE_LIMITS)
|
B_DOCUMENT_WINDOW, B_QUIT_ON_WINDOW_CLOSE | B_AUTO_UPDATE_SIZE_LIMITS)
|
||||||
|
, fLogFilePanel(NULL)
|
||||||
{
|
{
|
||||||
SetLayout(new BGroupLayout(B_VERTICAL, 0.0f));
|
SetLayout(new BGroupLayout(B_VERTICAL, 0.0f));
|
||||||
|
|
||||||
@@ -32,17 +33,29 @@ SerialWindow::SerialWindow()
|
|||||||
AddChild(fTermView);
|
AddChild(fTermView);
|
||||||
|
|
||||||
fConnectionMenu = new BMenu("Connection");
|
fConnectionMenu = new BMenu("Connection");
|
||||||
fConnectionMenu->SetRadioMode(true);
|
BMenu* fileMenu = new BMenu("File");
|
||||||
|
|
||||||
BMenu* editMenu = new BMenu("Edit");
|
|
||||||
BMenu* settingsMenu = new BMenu("Settings");
|
BMenu* settingsMenu = new BMenu("Settings");
|
||||||
|
|
||||||
|
fConnectionMenu->SetRadioMode(true);
|
||||||
|
|
||||||
menuBar->AddItem(fConnectionMenu);
|
menuBar->AddItem(fConnectionMenu);
|
||||||
menuBar->AddItem(editMenu);
|
menuBar->AddItem(fileMenu);
|
||||||
menuBar->AddItem(settingsMenu);
|
menuBar->AddItem(settingsMenu);
|
||||||
|
|
||||||
// TODO edit menu - what's in it ?
|
// TODO edit menu - what's in it ?
|
||||||
|
//BMenu* editMenu = new BMenu("Edit");
|
||||||
|
//menuBar->AddItem(editMenu);
|
||||||
|
|
||||||
|
BMenuItem* logFile = new BMenuItem("Log to file" B_UTF8_ELLIPSIS,
|
||||||
|
new BMessage(kMsgLogfile));
|
||||||
|
fileMenu->AddItem(logFile);
|
||||||
|
BMenuItem* xmodemSend = new BMenuItem("X/Y/ZModem send" B_UTF8_ELLIPSIS,
|
||||||
|
NULL);
|
||||||
|
fileMenu->AddItem(xmodemSend);
|
||||||
|
BMenuItem* xmodemReceive = new BMenuItem(
|
||||||
|
"X/Y/Zmodem receive" B_UTF8_ELLIPSIS, NULL);
|
||||||
|
fileMenu->AddItem(xmodemReceive);
|
||||||
|
|
||||||
// Configuring all this by menus may be a bit unhandy. Make a setting
|
// Configuring all this by menus may be a bit unhandy. Make a setting
|
||||||
// window instead ?
|
// window instead ?
|
||||||
BMenu* baudRate = new BMenu("Baud rate");
|
BMenu* baudRate = new BMenu("Baud rate");
|
||||||
@@ -159,7 +172,13 @@ SerialWindow::SerialWindow()
|
|||||||
CenterOnScreen();
|
CenterOnScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
|
SerialWindow::~SerialWindow()
|
||||||
|
{
|
||||||
|
delete fLogFilePanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SerialWindow::MenusBeginning()
|
void SerialWindow::MenusBeginning()
|
||||||
{
|
{
|
||||||
@@ -216,6 +235,17 @@ void SerialWindow::MessageReceived(BMessage* message)
|
|||||||
fTermView->PushBytes(bytes, length);
|
fTermView->PushBytes(bytes, length);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case kMsgLogfile:
|
||||||
|
{
|
||||||
|
// Let's lazy init the file panel
|
||||||
|
if(fLogFilePanel == NULL) {
|
||||||
|
fLogFilePanel = new BFilePanel(B_SAVE_PANEL, &be_app_messenger,
|
||||||
|
NULL, B_FILE_NODE, false);
|
||||||
|
fLogFilePanel->SetMessage(message);
|
||||||
|
}
|
||||||
|
fLogFilePanel->Show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class SerialWindow: public BWindow
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SerialWindow();
|
SerialWindow();
|
||||||
|
~SerialWindow();
|
||||||
|
|
||||||
void MenusBeginning();
|
void MenusBeginning();
|
||||||
void MessageReceived(BMessage* message);
|
void MessageReceived(BMessage* message);
|
||||||
@@ -22,6 +23,7 @@ class SerialWindow: public BWindow
|
|||||||
private:
|
private:
|
||||||
TermView* fTermView;
|
TermView* fTermView;
|
||||||
BMenu* fConnectionMenu;
|
BMenu* fConnectionMenu;
|
||||||
|
BFilePanel* fLogFilePanel;
|
||||||
|
|
||||||
static const char* kWindowTitle;
|
static const char* kWindowTitle;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user