From: Wouter V. <m97...@us...> - 2003-07-31 17:59:50
|
Update of /cvsroot/openmsx/openMSX/src/serial In directory sc8-pr-cvs1:/tmp/cvs-serv30974/src/serial Modified Files: Makefile.am RS232Connector.cc RS232Connector.hh Added Files: RS232Tester.cc RS232Tester.hh Log Message: Implemeted a RS232 tester pluggable --- NEW FILE: RS232Tester.cc --- // $Id: RS232Tester.cc,v 1.1 2003/07/31 17:22:28 m9710797 Exp $ #include "RS232Tester.hh" #include "PluggingController.hh" #include "RS232Connector.hh" #include "Scheduler.hh" RS232Tester::RS232Tester() : thread(this), connector(NULL), lock(1) { PluggingController::instance()->registerPluggable(this); } RS232Tester::~RS232Tester() { Scheduler::instance()->removeSyncPoint(this); PluggingController::instance()->unregisterPluggable(this); } // Pluggable void RS232Tester::plug(Connector* connector_, const EmuTime& time) { // output outFile.open("rs232-output"); // input inFile = fopen("rs232-input", "rb"); if (!inFile) { return; } connector = (RS232Connector*)connector_; connector->setDataBits(SerialDataInterface::DATA_8); // 8 data bits connector->setStopBits(SerialDataInterface::STOP_1); // 1 stop bit connector->setParityBit(false, SerialDataInterface::EVEN); // no parity thread.start(); } void RS232Tester::unplug(const EmuTime& time) { // output outFile.close(); // input lock.down(); thread.stop(); lock.up(); connector = NULL; fclose(inFile); } const string& RS232Tester::getName() const { static const string name("rs232-tester"); return name; } // Runnable void RS232Tester::run() { byte buf; while (true) { int num = fread(&buf, 1, 1, inFile); if (num != 1) { continue; } assert(connector); lock.down(); queue.push_back(buf); Scheduler::instance()->setSyncPoint(Scheduler::ASAP, this); lock.up(); } } // input void RS232Tester::signal(const EmuTime& time) { if (!connector->acceptsData()) { queue.clear(); return; } if (!connector->ready()) { return; } lock.down(); if (queue.empty()) { lock.up(); return; } byte data = queue.front(); queue.pop_front(); lock.up(); connector->recvByte(data, time); } // Schedulable void RS232Tester::executeUntilEmuTime(const EmuTime& time, int userData) { if (connector) { signal(time); } else { lock.down(); queue.empty(); lock.up(); } } const string& RS232Tester::schedName() const { return getName(); } // output void RS232Tester::recvByte(byte value, const EmuTime& time) { outFile.put(value); outFile.flush(); } --- NEW FILE: RS232Tester.hh --- // $Id: RS232Tester.hh,v 1.1 2003/07/31 17:22:28 m9710797 Exp $ #ifndef __RS232TESTER_HH__ #define __RS232TESTER_HH__ #include <fstream> #include <stdio.h> #include <list> #include "openmsx.hh" #include "RS232Device.hh" #include "Thread.hh" #include "Schedulable.hh" #include "Semaphore.hh" class RS232Connector; class RS232Tester : public RS232Device, private Runnable, private Schedulable { public: RS232Tester(); virtual ~RS232Tester(); // Pluggable virtual void plug(Connector* connector, const EmuTime& time); virtual void unplug(const EmuTime& time); virtual const string &getName() const; // input virtual void signal(const EmuTime& time); // output virtual void recvByte(byte value, const EmuTime& time); private: // Runnable virtual void run(); // Schedulable virtual void executeUntilEmuTime(const EmuTime& time, int userData); virtual const string& schedName() const; Thread thread; FILE* inFile; RS232Connector* connector; list<byte> queue; Semaphore lock; // to protect queue ofstream outFile; }; #endif Index: Makefile.am =================================================================== RCS file: /cvsroot/openmsx/openMSX/src/serial/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Makefile.am 29 Jul 2003 20:24:27 -0000 1.7 +++ Makefile.am 31 Jul 2003 17:22:28 -0000 1.8 @@ -37,7 +37,8 @@ RS232Connector.cc RS232Connector.hh \ RS232Device.cc RS232Device.hh \ MSXRS232.cc MSXRS232.hh \ - DummyRS232Device.cc DummyRS232Device.hh + DummyRS232Device.cc DummyRS232Device.hh \ + RS232Tester.cc RS232Tester.hh nodebug: resetdebug all debug: setdebug all Index: RS232Connector.cc =================================================================== RCS file: /cvsroot/openmsx/openMSX/src/serial/RS232Connector.cc,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- RS232Connector.cc 29 Jul 2003 20:24:27 -0000 1.1 +++ RS232Connector.cc 31 Jul 2003 17:22:28 -0000 1.2 @@ -3,6 +3,7 @@ #include "RS232Connector.hh" #include "RS232Device.hh" #include "DummyRS232Device.hh" +#include "RS232Tester.hh" #include "PluggingController.hh" @@ -10,6 +11,7 @@ : name(name_) { dummy = new DummyRS232Device(); + tester = new RS232Tester(); PluggingController::instance()->registerConnector(this); unplug(time); @@ -18,6 +20,7 @@ RS232Connector::~RS232Connector() { PluggingController::instance()->unregisterConnector(this); + delete tester; delete dummy; } Index: RS232Connector.hh =================================================================== RCS file: /cvsroot/openmsx/openMSX/src/serial/RS232Connector.hh,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- RS232Connector.hh 29 Jul 2003 20:24:27 -0000 1.1 +++ RS232Connector.hh 31 Jul 2003 17:22:28 -0000 1.2 @@ -7,6 +7,7 @@ #include "SerialDataInterface.hh" class DummyRS232Device; +class RS232Tester; class RS232Connector : public Connector, public SerialDataInterface { @@ -31,6 +32,7 @@ private: string name; DummyRS232Device* dummy; + RS232Tester* tester; }; #endif |