00001 #include "SIGEL_Robot/SIG_LanguageParameters.h"
00002 #include "SIGEL_Robot/SIG_CommandParameters.h"
00003 #include "SIGEL_Robot/SIG_RobotExceptions.h"
00004
00005 namespace SIGEL_Robot {
00006 SIG_LanguageParameters::SIG_LanguageParameters (void)
00007 : bitsPerRegister (32),
00008 memSize (8),
00009 maximalDelayTime(5000),
00010 allowedCommands ()
00011 {
00012 SIG_CommandParameters *commandParameters = new SIG_CommandParameters();
00013 commandParameters->setDuration( 0.001 );
00014 this->addCommand( "ADD", commandParameters );
00015
00016 commandParameters = new SIG_CommandParameters();
00017 commandParameters->setDuration( 0.001 );
00018 this->addCommand( "CMP", commandParameters );
00019
00020 commandParameters = new SIG_CommandParameters();
00021 commandParameters->setDuration( 0.001 );
00022 this->addCommand( "COPY", commandParameters );
00023
00024 commandParameters = new SIG_CommandParameters();
00025 commandParameters->setDuration( 0.001 );
00026 this->addCommand( "DELAY", commandParameters );
00027
00028 commandParameters = new SIG_CommandParameters();
00029 commandParameters->setDuration( 0.001 );
00030 this->addCommand( "DIV", commandParameters );
00031
00032 commandParameters = new SIG_CommandParameters();
00033 commandParameters->setDuration( 0.001 );
00034 this->addCommand( "JMP", commandParameters );
00035
00036 commandParameters = new SIG_CommandParameters();
00037 commandParameters->setDuration( 0.001 );
00038 this->addCommand( "LOAD", commandParameters );
00039
00040 commandParameters = new SIG_CommandParameters();
00041 commandParameters->setDuration( 0.001 );
00042 this->addCommand( "MAX", commandParameters );
00043
00044 commandParameters = new SIG_CommandParameters();
00045 commandParameters->setDuration( 0.001 );
00046 this->addCommand( "MIN", commandParameters );
00047
00048 commandParameters = new SIG_CommandParameters();
00049 commandParameters->setDuration( 0.001 );
00050 this->addCommand( "MOD", commandParameters );
00051
00052 commandParameters = new SIG_CommandParameters();
00053 commandParameters->setDuration( 0.001 );
00054 this->addCommand( "MOVE", commandParameters );
00055
00056 commandParameters = new SIG_CommandParameters();
00057 commandParameters->setDuration( 0.001 );
00058 this->addCommand( "MUL", commandParameters );
00059
00060 commandParameters = new SIG_CommandParameters();
00061 commandParameters->setDuration( 0.001 );
00062 this->addCommand( "NOP", commandParameters );
00063
00064 commandParameters = new SIG_CommandParameters();
00065 commandParameters->setDuration( 0.001 );
00066 this->addCommand( "SENSE", commandParameters );
00067
00068 commandParameters = new SIG_CommandParameters();
00069 commandParameters->setDuration( 0.001 );
00070 this->addCommand( "SUB", commandParameters );
00071
00072 allowedCommands.setAutoDelete( true );
00073 }
00074
00075 SIG_LanguageParameters::SIG_LanguageParameters (QTextStream & tx,
00076 bool nir = false)
00077 {
00078 QString tmpstr;
00079 int zahl;
00080
00081 if (nir) {
00082 tx >> tmpstr;
00083 if (tmpstr != "LanguageParameters")
00084 throw SIG_UnstreamingError (__FILE__, __LINE__, "LanguageParameters expected");
00085 }
00086
00087
00088
00089 tx >> bitsPerRegister;
00090 tx >> memSize;
00091 tx >> maximalDelayTime;
00092
00093 tx >> zahl;
00094 for (int i = 0; i < zahl; i++) {
00095 tx >> tmpstr;
00096 allowedCommands.insert (tmpstr, new SIG_CommandParameters (tx));
00097 }
00098 allowedCommands.setAutoDelete( true );
00099 }
00100
00101 SIG_LanguageParameters::~SIG_LanguageParameters (void)
00102 {
00103
00104 }
00105
00106 void SIG_LanguageParameters::addCommand (QString name, SIG_CommandParameters *cmdP)
00107 {
00108 allowedCommands.insert (name, cmdP);
00109 }
00110
00111 void SIG_LanguageParameters::removeCommand( QString name )
00112 {
00113 allowedCommands.remove( name );
00114 }
00115
00116 bool SIG_LanguageParameters::hasCommand (QString name) const
00117 {
00118 return (allowedCommands.find (name) != 0);
00119 }
00120
00121 SIG_CommandParameters *SIG_LanguageParameters::getCommand (QString name) const
00122 {
00123 return allowedCommands.find (name);
00124 }
00125
00126 void SIG_LanguageParameters::setRegisterWidth (int width)
00127 {
00128 bitsPerRegister = width;
00129 }
00130
00131 int SIG_LanguageParameters::getRegisterWidth (void) const
00132 {
00133 return bitsPerRegister;
00134 }
00135
00136 void SIG_LanguageParameters::setMemorySize (int amount)
00137 {
00138 memSize = amount;
00139 }
00140
00141 int SIG_LanguageParameters::getMemorySize (void) const
00142 {
00143 return memSize;
00144 }
00145
00146 void SIG_LanguageParameters::setMaximalDelayTime( int amount )
00147 {
00148 maximalDelayTime = amount;
00149 }
00150
00151 int SIG_LanguageParameters::getMaximalDelayTime( void ) const
00152 {
00153 return maximalDelayTime;
00154 }
00155
00156 void SIG_LanguageParameters::writeToFileTransfer (QTextStream & tx) const
00157 {
00158 QDictIterator<SIG_CommandParameters> cmditer (allowedCommands);
00159
00160 tx << "LanguageParameters " << bitsPerRegister << ' ' << memSize << ' ' << maximalDelayTime << ' ';
00161 tx << allowedCommands.count () << '\n';
00162 while (cmditer.current ()) {
00163 tx << cmditer.currentKey () << ' ';
00164 cmditer.current ()->writeToFileTransfer (tx);
00165 ++cmditer;
00166 }
00167 }
00168 }