Skip to content

Commit

Permalink
Baudrate to 57600, might not fix anything for stability, maybe change…
Browse files Browse the repository at this point in the history
… back later. Made logging less memory consuming on arduino side. Added support for directory listing in native file system. Important change in arduino interface.cpp for better stability on serial protocol. If missing bytes, it gets back into sync.
  • Loading branch information
Larswad committed Jul 16, 2013
1 parent 704a81a commit 0e0bc8f
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 70 deletions.
17 changes: 0 additions & 17 deletions interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,20 +456,3 @@ byte dummy_no_newfile(char *s)
}
*/

/*
// The previous cmd is copied to this string:
char oldCmdStr[IEC::ATN_CMD_MAX_LENGTH];
const char errorStr0[] = "00,OK";
const char errorStr1[] = "21,READ ERROR";
const char errorStr2[] = "26,WRITE PROTECT ON";
const char errorStr3[] = "33,SYNTAX ERROR";
const char errorStr4[] = "62,FILE NOT FOUND";
const char errorStr5[] = "63,FILE EXISTS";
const char errorStr6[] = "73,MMC2IEC DOS V0.8";
const char errorStr7[] = "74,DRIVE NOT READY";
const char errorStr8[] = "75,RPI SERIAL ERR.";
const char *error_table[ErrCount] = { errorStr0, errorStr1, errorStr2, errorStr3, errorStr4, errorStr5, errorStr6, errorStr7, errorStr8 };
const char errorEnding[] = ",00,00";
*/
2 changes: 2 additions & 0 deletions interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#define CMD_CHANNEL 15

/*
enum {
IS_FAIL = 0xFF, // IFail: SD card or fat not ok
IS_NATIVE = 0, // Regular file system file state
Expand All @@ -22,6 +23,7 @@ enum {
IS_PRG = 4,
NumInterfaceStates
};
*/

enum OpenState {
O_NOTHING, // Nothing to send / File not found error
Expand Down
2 changes: 1 addition & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ MainWindow::MainWindow(QWidget *parent) :
#else
if(m_ports.count())
m_port.setPortName(m_ports.at(0).portName);
m_port.setBaudRate(BAUD115200);
m_port.setBaudRate(BAUD57600);
#endif

int ix = 0;
Expand Down
53 changes: 49 additions & 4 deletions nativefs.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "nativefs.hpp"
#include "logger.hpp"
#include <QDir>
#include <math.h>

using namespace Logging;

Expand Down Expand Up @@ -99,10 +100,54 @@ bool NativeFS::close()

bool NativeFS::sendListing(ISendLine& cb)
{
Log("NATIVEFS", "sendListing: NOT YET IMPLEMENTED", warning);
cb.send(0, "LISTING NOT YET IMPLEMENTED.");
Q_UNUSED(cb);
QDir dir(".");
QDir dir(QDir::current());
QString dirName(dir.dirName().toUpper());
dirName.truncate(23);
dirName = dirName.leftJustified(23);

QStringList filters;
filters.append("*.D64");
filters.append("*.T64");
filters.append("*.M2I");
filters.append("*.PRG");
filters.append("*.P00");

QString line("\x12\x22"); // Invert face, "
QString diskLabel("NATIVE FS");
uchar i;
for(i = 2; i < 25; i++) {
uchar c = dirName.at(0).toLatin1();
dirName.remove(0, 1);

if(0xA0 == c) // Convert padding A0 to spaces
c = ' ';

if(18 == i) // Ending "
c = '"';

line += c;
}
// Ending name with dbl quotes
line[i] = QChar('"').toLatin1();

cb.send(0, line);

QFileInfoList list(dir.entryInfoList(filters, QDir::NoDot bitor QDir::AllEntries, QDir::Name));
Log("NATIVEFS", QString("Listing %1 entrie(s) to CBM.").arg(QString::number(list.count())), info);
while(!list.isEmpty()) {
QFileInfo entry = list.first();
list.removeFirst();
line = " \"";
line.append(entry.fileName().toUpper());
if(entry.isDir())
line.append(strDir + '"');
else
line.append('"');

ushort fileSize = entry.size() / 1024;
// Send initial spaces (offset) according to file size
cb.send(fileSize, line.mid((int)log10(fileSize)));
}

return true;
} // sendListing
Expand Down
117 changes: 74 additions & 43 deletions uno2iec/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,25 @@
namespace {
// atn command buffer struct
IEC::ATNCmd cmd;
char serCmdIOBuf[80];
char serCmdIOBuf[120];
byte scrollBuffer[30];

// The previous cmd is copied to this string:
char oldCmdStr[IEC::ATN_CMD_MAX_LENGTH];

const char errorStr0[] = "00,OK";
const char errorStr1[] = "21,READ ERROR";
const char errorStr2[] = "26,WRITE PROTECT ON";
const char errorStr3[] = "33,SYNTAX ERROR";
const char errorStr4[] = "62,FILE NOT FOUND";
const char errorStr5[] = "63,FILE EXISTS";
const char errorStr6[] = "73,MMC2IEC DOS V0.8";
const char errorStr7[] = "74,DRIVE NOT READY";
const char errorStr8[] = "75,RPI SERIAL ERR.";
const char *error_table[ErrCount] = { errorStr0, errorStr1, errorStr2, errorStr3, errorStr4, errorStr5, errorStr6, errorStr7, errorStr8 };

const char errorEnding[] = ",00,00";

} // unnamed namespace


Expand All @@ -56,7 +73,7 @@ void Interface::reset(void)
{
m_openState = O_NOTHING;
m_queuedError = ErrIntro;
m_interfaceState = IS_NATIVE;
//m_interfaceState = IS_NATIVE;
} // reset


Expand Down Expand Up @@ -124,6 +141,8 @@ void Interface::sendListing()
if('L' == resp) { // PI will give us something else if we're at last line to send.
// get the length as one byte: This is kind of specific: For listings we allow 256 bytes length. Period.
byte len = serCmdIOBuf[1];
// TODO: Here we might need to read out the data in portions. The serCmdIOBuf might just be too small
// for long lines.
byte actual = Serial.readBytes(serCmdIOBuf, len);
if(len == actual) {
// send the bytes directly to CBM!
Expand Down Expand Up @@ -298,53 +317,65 @@ void Interface::handleATNCmdCodeDataTalk(byte chan)
{
byte lengthOrResult;
boolean wasSuccess = false;
if(lengthOrResult = Serial.readBytes(serCmdIOBuf, 3)) {
// process response into m_queuedError.
// Response: ><code in binary><CR>
if('>' == serCmdIOBuf[0] and 3 == lengthOrResult) {
lengthOrResult = serCmdIOBuf[1];
wasSuccess = true;
}
else
Log(Error, FAC_IFACE, serCmdIOBuf);
}
if(CMD_CHANNEL == chan) {
m_queuedError = wasSuccess ? lengthOrResult : ErrSerialComm;
// Send status message
sendStatus();
// go back to OK state, we have dispatched the error to IEC host now.
m_queuedError = ErrOK;

// process response into m_queuedError.
// Response: ><code in binary><CR>
serCmdIOBuf[0] = 0;
do {
lengthOrResult = Serial.readBytes(serCmdIOBuf, 1);
} while(lengthOrResult not_eq 1 or serCmdIOBuf[0] not_eq '>');

if(!lengthOrResult or '>' not_eq serCmdIOBuf[0]) {
m_iec.sendFNF();
Log(Information, FAC_IFACE, "Could not sync to response char.");
}
else {
m_openState = wasSuccess ? lengthOrResult : O_NOTHING;

switch(m_openState) {
case O_INFO:
// Reset and send SD card info
reset();
// TODO: interface with PI (file system media info).
sendListing();
break;
if(lengthOrResult = Serial.readBytes(serCmdIOBuf, 2)) {
if(2 == lengthOrResult) {
lengthOrResult = serCmdIOBuf[0];
wasSuccess = true;
}
else
Log(Error, FAC_IFACE, serCmdIOBuf);
}
if(CMD_CHANNEL == chan) {
m_queuedError = wasSuccess ? lengthOrResult : ErrSerialComm;
// Send status message
sendStatus();
// go back to OK state, we have dispatched the error to IEC host now.
m_queuedError = ErrOK;
}
else {
m_openState = wasSuccess ? lengthOrResult : O_NOTHING;

switch(m_openState) {
case O_INFO:
// Reset and send SD card info
reset();
// TODO: interface with PI (file system media info).
sendListing();
break;

case O_FILE_ERR:
// TODO: interface with pi for error info.
sendListing(/*&send_file_err*/);
break;
case O_FILE_ERR:
// TODO: interface with pi for error info.
sendListing(/*&send_file_err*/);
break;

case O_NOTHING: /*or (0 == pff)*/
// Say file not found
m_iec.sendFNF();
break;
case O_NOTHING: /*or (0 == pff)*/
// Say file not found
m_iec.sendFNF();
break;

case O_FILE:
// Send program file
sendFile();
break;
case O_FILE:
// Send program file
sendFile();
break;

case O_DIR:
// Send listing
sendListing(/*(PFUNC_SEND_LISTING)(pff->send_listing)*/);
break;
case O_DIR:
// Send listing
sendListing(/*(PFUNC_SEND_LISTING)(pff->send_listing)*/);
break;
}
}
}
// Log(Information, FAC_IFACE, serCmdIOBuf);
Expand Down
3 changes: 2 additions & 1 deletion uno2iec/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ typedef enum {
ErrCount
} IOErrorMessage;


/*
enum {
IS_FAIL = 0xFF, // IFail: SD card or fat not ok
IS_NATIVE = 0, // Regular file system file state
Expand All @@ -28,6 +28,7 @@ enum {
IS_PRG = 4,
NumInterfaceStates
};
*/

enum OpenState {
O_NOTHING, // Nothing to send / File not found error
Expand Down
6 changes: 3 additions & 3 deletions uno2iec/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ void registerFacilities(void)

void Log(byte severity , char facility, char* msg)
{
char strBuf[80];
sprintf(strBuf, "D%c%c%s\r", siwe[severity], facility, msg);
char strBuf[4];
sprintf(strBuf, "D%c%c", siwe[severity], facility);
// TODO: Queueing possible, polling of queue could be handled (called) from 'loop()'.
Serial.print(strBuf);
Serial.println(msg);
} // Log

2 changes: 1 addition & 1 deletion uno2iec/uno2iec.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <max7219.h>
#include "global_defines.h"

#define DEFAULT_BAUD_RATE 115200
#define DEFAULT_BAUD_RATE 57600

// Pin 13 has a LED connected on most Arduino boards.
const byte ledPort = 13;
Expand Down

0 comments on commit 0e0bc8f

Please sign in to comment.