Log serial input to a file.
This commit is contained in:
@@ -16,6 +16,6 @@ Application SerialConnect :
|
||||
state.c
|
||||
unicode.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 <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <File.h>
|
||||
|
||||
#include "SerialWindow.h"
|
||||
|
||||
|
||||
SerialApp::SerialApp()
|
||||
:
|
||||
BApplication(SerialApp::kApplicationSignature)
|
||||
: BApplication(SerialApp::kApplicationSignature)
|
||||
, fLogFile(NULL)
|
||||
{
|
||||
fWindow = new SerialWindow();
|
||||
|
||||
@@ -24,6 +29,12 @@ SerialApp::SerialApp()
|
||||
}
|
||||
|
||||
|
||||
SerialApp::~SerialApp()
|
||||
{
|
||||
delete fLogFile;
|
||||
}
|
||||
|
||||
|
||||
void SerialApp::ReadyToRun()
|
||||
{
|
||||
fWindow->Show();
|
||||
@@ -51,6 +62,19 @@ void SerialApp::MessageReceived(BMessage* message)
|
||||
// forward the message to the window, which will display the
|
||||
// incoming data
|
||||
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;
|
||||
}
|
||||
case kMsgDataWrite:
|
||||
@@ -62,6 +86,27 @@ void SerialApp::MessageReceived(BMessage* message)
|
||||
fSerialPort.Write(bytes, size);
|
||||
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:
|
||||
{
|
||||
int32 baudrate;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <SerialPort.h>
|
||||
|
||||
|
||||
class BFile;
|
||||
class SerialWindow;
|
||||
|
||||
|
||||
@@ -19,6 +20,7 @@ class SerialApp: public BApplication
|
||||
{
|
||||
public:
|
||||
SerialApp();
|
||||
~SerialApp();
|
||||
void ReadyToRun();
|
||||
void MessageReceived(BMessage* message);
|
||||
|
||||
@@ -26,6 +28,7 @@ class SerialApp: public BApplication
|
||||
BSerialPort fSerialPort;
|
||||
sem_id fSerialLock;
|
||||
SerialWindow* fWindow;
|
||||
BFile* fLogFile;
|
||||
|
||||
static status_t PollSerial(void*);
|
||||
|
||||
@@ -34,9 +37,10 @@ class SerialApp: public BApplication
|
||||
|
||||
|
||||
enum messageConstants {
|
||||
kMsgOpenPort = 'open',
|
||||
kMsgDataRead = 'dare',
|
||||
kMsgDataWrite = 'dawr',
|
||||
kMsgLogfile = 'logf',
|
||||
kMsgOpenPort = 'open',
|
||||
kMsgSettings = 'stty',
|
||||
};
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <FilePanel.h>
|
||||
#include <GroupLayout.h>
|
||||
#include <Menu.h>
|
||||
#include <MenuBar.h>
|
||||
@@ -19,9 +20,9 @@
|
||||
|
||||
|
||||
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)
|
||||
, fLogFilePanel(NULL)
|
||||
{
|
||||
SetLayout(new BGroupLayout(B_VERTICAL, 0.0f));
|
||||
|
||||
@@ -32,17 +33,29 @@ SerialWindow::SerialWindow()
|
||||
AddChild(fTermView);
|
||||
|
||||
fConnectionMenu = new BMenu("Connection");
|
||||
fConnectionMenu->SetRadioMode(true);
|
||||
|
||||
BMenu* editMenu = new BMenu("Edit");
|
||||
BMenu* fileMenu = new BMenu("File");
|
||||
BMenu* settingsMenu = new BMenu("Settings");
|
||||
|
||||
fConnectionMenu->SetRadioMode(true);
|
||||
|
||||
menuBar->AddItem(fConnectionMenu);
|
||||
menuBar->AddItem(editMenu);
|
||||
menuBar->AddItem(fileMenu);
|
||||
menuBar->AddItem(settingsMenu);
|
||||
|
||||
// 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
|
||||
// window instead ?
|
||||
BMenu* baudRate = new BMenu("Baud rate");
|
||||
@@ -159,7 +172,13 @@ SerialWindow::SerialWindow()
|
||||
CenterOnScreen();
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
SerialWindow::~SerialWindow()
|
||||
{
|
||||
delete fLogFilePanel;
|
||||
}
|
||||
|
||||
|
||||
void SerialWindow::MenusBeginning()
|
||||
{
|
||||
@@ -216,6 +235,17 @@ void SerialWindow::MessageReceived(BMessage* message)
|
||||
fTermView->PushBytes(bytes, length);
|
||||
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:
|
||||
BWindow::MessageReceived(message);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ class SerialWindow: public BWindow
|
||||
{
|
||||
public:
|
||||
SerialWindow();
|
||||
~SerialWindow();
|
||||
|
||||
void MenusBeginning();
|
||||
void MessageReceived(BMessage* message);
|
||||
@@ -22,6 +23,7 @@ class SerialWindow: public BWindow
|
||||
private:
|
||||
TermView* fTermView;
|
||||
BMenu* fConnectionMenu;
|
||||
BFilePanel* fLogFilePanel;
|
||||
|
||||
static const char* kWindowTitle;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user