#include <V24.h>
Definiert in Zeile 40 der Datei V24.h.
Öffentliche Methoden | |
void | closeDevice () |
bool | openDevice () |
void | parseFloatData (unsigned char *c, float *_data) |
void | parseIntegerData (unsigned char *d, unsigned int *_data) |
bool | receiveCommand (V24COMMAND *c) |
bool | receiveTransmitOKCommand () |
bool | setInterface (QString _interface) |
bool | transmitCommand (V24COMMAND *c) |
V24Control (QMutex *_guiMutex, QMainWindow *_vater) | |
Private Methoden | |
bool | receive (unsigned char *data) |
void | showErrorCode (unsigned long errorCode) |
bool | transmit (unsigned char data) |
bool | transmitAndReceive (unsigned char tData, unsigned char rData) |
Private Attribute | |
QMutex * | conMutex |
char | filename [50] |
QMutex * | guiMutex |
QMainWindow * | parent |
Posix_QextSerialPort * | port |
bool | receiving |
bool | rxtx |
QString | sDeviceInterface |
bool | transmitting |
V24Control::V24Control | ( | QMutex * | _guiMutex, | |
QMainWindow * | _parent | |||
) |
_guiMutex | ||
_parent |
Definiert in Zeile 35 der Datei V24.cpp.
Benutzt conMutex, guiMutex, parent, port, receiving, rxtx, sDeviceInterface und transmitting.
00035 { 00036 00037 sDeviceInterface = "/dev/ttyUSB0"; 00038 00039 port = new Posix_QextSerialPort(sDeviceInterface); 00040 this->guiMutex = _guiMutex; 00041 this->conMutex = new QMutex(); 00042 this->receiving = this->transmitting = false; 00043 this->parent = _parent; 00044 00045 rxtx = true; 00046 }
void V24Control::closeDevice | ( | ) |
Diese Funktion schließt die Verbindung zum V24 Gerät
Definiert in Zeile 223 der Datei V24.cpp.
Benutzt port.
Wird benutzt von setInterface(), Simulation::v24_copy_states_and_gamma_to_robot_button_clicked(), Simulation::v24_debug_button_clicked(), Simulation::v24_distance_button_clicked(), Simulation::v24_exploration_accept_clicked(), Simulation::v24_explore_feedback_button_clicked(), Simulation::v24_get_exploration_clicked(), Simulation::v24_get_states_and_gamma_from_robot_button_clicked(), Simulation::v24_getPositionAndMode_button_clicked(), Simulation::v24_ramtest_button_clicked(), Simulation::v24_reset_distance_button_clicked(), Simulation::v24_start_learning_button_clicked(), Simulation::v24_start_walking_button_clicked() und Simulation::v24_stop_walking_button_clicked().
00223 { 00224 port->close(); 00225 }
bool V24Control::openDevice | ( | ) |
Diese Funktion öffnet die Verbindung zum V24 Gerät
Definiert in Zeile 230 der Datei V24.cpp.
Benutzt DBG, parent, port, sDeviceInterface und SERIAL_BAUDRATE.
Wird benutzt von receiveCommand(), setInterface(), transmitCommand(), Simulation::v24_explore_feedback_button_clicked() und Simulation::v24_getPositionAndMode_button_clicked().
00230 { 00231 00232 // Wenn Port noch nicht geöffnet, dann öffnen 00233 if (!port->isOpen()) { 00234 00235 // 8N1, 9600 Baud 00236 if (!port->open()) { 00237 DBG(); 00238 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "Could not open Interface: " + sDeviceInterface); 00239 00240 return false; 00241 } else { 00242 00243 port->setFlowControl(FLOW_OFF); 00244 port->setParity(PAR_NONE); 00245 port->setDataBits(DATA_8); 00246 port->setStopBits(STOP_1); 00247 port->setBaudRate(SERIAL_BAUDRATE); 00248 port->setTimeout(1,0); // Timeout auf 10 Sekunden setzen 00249 } 00250 } 00251 00252 return true; 00253 }
void V24Control::parseFloatData | ( | unsigned char * | c, | |
float * | _data | |||
) |
Diese Funktionen, parst und interpretiert das Data-Array als Float-Zahl und liefert diese dann zurück
c | ||
_data |
Definiert in Zeile 262 der Datei V24.cpp.
Wird benutzt von Simulation::v24_debug_button_clicked(), Simulation::v24_get_exploration_clicked() und Simulation::v24_get_states_and_gamma_from_robot_button_clicked().
00262 { 00263 00264 unsigned char* _cpfValue = (unsigned char*)_data; 00265 00266 for (int i=0; i<(int)sizeof(float); i++) { 00267 _cpfValue[i] = c[i]; 00268 } 00269 }
void V24Control::parseIntegerData | ( | unsigned char * | c, | |
unsigned int * | _data | |||
) |
Diese Funktionen, parst und interpretiert das Data-Array als Integer-Zahl und liefert diese dann zurück
c | ||
_data |
Definiert in Zeile 278 der Datei V24.cpp.
Wird benutzt von Simulation::v24_distance_button_clicked() und Simulation::v24_getPositionAndMode_button_clicked().
00278 { 00279 00280 unsigned char* _cpiValue = (unsigned char*)_data; 00281 00282 for (int i=0; i<(int)sizeof(unsigned int); i++) { 00283 *(_cpiValue+i) = c[i]; 00284 } 00285 }
bool V24Control::receive | ( | unsigned char * | data | ) | [private] |
Diese Funktion empfängt ein Byte von der Seriellen Schnittstelle (low-level).
data |
Definiert in Zeile 116 der Datei V24.cpp.
Benutzt port und showErrorCode().
Wird benutzt von receiveCommand().
00116 { 00117 00118 int errorLoop = 0; 00119 int back; 00120 00121 do { 00122 back = port->readBlock((char*)data, 1); 00123 printf ("."); 00124 00125 if (back >= 1) { 00126 printf ("#RX=%d#", *data); 00127 errorLoop = 501; 00128 } else { 00129 usleep(10000); 00130 errorLoop++; 00131 fflush(stdout); 00132 } 00133 } while (errorLoop <500); 00134 00135 if (errorLoop == 500) { 00136 this->showErrorCode(E_READ_FAILED); 00137 return false; 00138 } 00139 00140 return true; 00141 }
bool V24Control::receiveCommand | ( | V24COMMAND * | c | ) |
Diese Funktion empfängt ein Kommando von der Seriellen Schnittstelle (high-level).
c |
Definiert in Zeile 183 der Datei V24.cpp.
Benutzt V24Command::command, V24Command::data, V24Command::dataLength, openDevice(), receive() und rxtx.
Wird benutzt von Simulation::v24_debug_button_clicked(), Simulation::v24_distance_button_clicked(), Simulation::v24_get_exploration_clicked(), Simulation::v24_get_states_and_gamma_from_robot_button_clicked(), Simulation::v24_getPositionAndMode_button_clicked() und Simulation::v24_ramtest_button_clicked().
00183 { 00184 // Port muss sicher geöffnet sein 00185 this->openDevice(); 00186 00187 printf("\nBegin receiveCommand():\n"); 00188 00189 // Komamndo empfangen 00190 if (!receive(&c->command)) { 00191 return false; 00192 } 00193 if (rxtx) { 00194 } 00195 printf ("\n"); 00196 00197 // Data-Length empfangen 00198 if (!receive(&c->dataLength)) { 00199 return false; 00200 } 00201 if (rxtx) { 00202 } 00203 printf ("\n"); 00204 00205 for (int i=0; i< c->dataLength; i++) { 00206 00207 if (!receive(&c->data[i])) { 00208 return false; 00209 } 00210 if (rxtx) { 00211 } 00212 printf ("\n"); 00213 } 00214 printf("End receiveCommand():\n"); 00215 00216 00217 return true; 00218 }
bool V24Control::receiveTransmitOKCommand | ( | ) |
Diese Funktion, nimmt eine Empfangsbestätigung vom Controller zurück. Wenn das Kommando in Ordnung war, dann liefert sie "true" zurück, ansonsten "false".
Definiert in Zeile 293 der Datei V24.cpp.
Wird benutzt von Simulation::v24_copy_states_and_gamma_to_robot_button_clicked(), Simulation::v24_distance_button_clicked(), Simulation::v24_exploration_accept_clicked(), Simulation::v24_explore_feedback_button_clicked(), Simulation::v24_get_exploration_clicked(), Simulation::v24_get_states_and_gamma_from_robot_button_clicked(), Simulation::v24_getPositionAndMode_button_clicked(), Simulation::v24_ramtest_button_clicked(), Simulation::v24_reset_distance_button_clicked(), Simulation::v24_start_learning_button_clicked(), Simulation::v24_start_walking_button_clicked() und Simulation::v24_stop_walking_button_clicked().
bool V24Control::setInterface | ( | QString | _interface | ) |
_interface |
Definiert in Zeile 20 der Datei V24.cpp.
Benutzt closeDevice(), openDevice(), port und sDeviceInterface.
Wird benutzt von Simulation::v24_accept_button_clicked().
00020 { 00021 this->sDeviceInterface = _interface; 00022 printf ("Serial Interface set to: %s\n", _interface.ascii()); 00023 if (port->isOpen()) this->closeDevice(); 00024 00025 port = new Posix_QextSerialPort(this->sDeviceInterface.ascii()); 00026 00027 return this->openDevice(); 00028 }
void V24Control::showErrorCode | ( | unsigned long | _errorCode | ) | [private] |
_errorCode |
Definiert in Zeile 302 der Datei V24.cpp.
Benutzt parent.
Wird benutzt von receive().
00302 { 00303 00304 // Bei keinem Fehler, abbrechen 00305 if (_errorCode == E_NO_ERROR) { 00306 return; 00307 } 00308 00309 // Ansonsten den Fehlercode ausgeben 00310 if (_errorCode == E_INVALID_FD) { 00311 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "Invalid file descriptor (port was not opened correctly)"); 00312 printf ("Invalid file descriptor (port was not opened correctly)\n"); 00313 } else if (_errorCode == E_NO_MEMORY) { 00314 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "Unable to allocate memory tables"); 00315 printf ("Unable to allocate memory tables\n"); 00316 } else if (_errorCode == E_CAUGHT_NON_BLOCKED_SIGNAL) { 00317 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "Caught a non-blocked signal"); 00318 printf ("Caught a non-blocked signal\n"); 00319 } else if (_errorCode == E_PORT_TIMEOUT) { 00320 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "Operation timed out"); 00321 printf ("Operation timed out\n"); 00322 } else if (_errorCode == E_INVALID_DEVICE) { 00323 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "The file opened by the port is not a character device"); 00324 printf ("The file opened by the port is not a character device\n"); 00325 } else if (_errorCode == E_BREAK_CONDITION) { 00326 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "The port detected a break condition"); 00327 printf ("The port detected a break condition\n"); 00328 } else if (_errorCode == E_FRAMING_ERROR) { 00329 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "The port detected a framing error"); 00330 printf ("The port detected a framing error\n"); 00331 } else if (_errorCode == E_IO_ERROR) { 00332 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "There was an I/O error while communicating with the port"); 00333 printf ("There was an I/O error while communicating with the port\n"); 00334 } else if (_errorCode == E_BUFFER_OVERRUN) { 00335 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "Character buffer overrun"); 00336 printf ("Character buffer overrun\n"); 00337 } else if (_errorCode == E_RECEIVE_OVERFLOW) { 00338 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "Receive buffer overflow"); 00339 printf ("Receive buffer overflow\n"); 00340 } else if (_errorCode == E_RECEIVE_PARITY_ERROR) { 00341 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "The port detected a parity error in the received data"); 00342 printf ("The port detected a parity error in the received data\n"); 00343 } else if (_errorCode == E_TRANSMIT_OVERFLOW) { 00344 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "Transmit buffer overflow"); 00345 printf ("Transmit buffer overflow\n"); 00346 } else if (_errorCode == E_READ_FAILED) { 00347 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "General read operation failure. Please check robot connection."); 00348 printf ("General read operation failure. Please check robot connection.\n"); 00349 } else if (_errorCode == E_WRITE_FAILED) { 00350 QMessageBox::critical(this->parent, "Serial Communcation ERROR:", "General write operation failure"); 00351 printf ("General write operation failure\n"); 00352 } 00353 }
bool V24Control::transmit | ( | unsigned char | data | ) | [private] |
Diese Funktion sendet ein Byte über die Serielle Schnittstelle (low-level). Liefert true zurück, wenn Daten korrekt gesendet wurden, "false" wenn nicht.
data |
Definiert in Zeile 101 der Datei V24.cpp.
Benutzt port.
Wird benutzt von transmitAndReceive().
00101 { 00102 00103 // Datenbyte senden 00104 printf(" TX=%u", data); 00105 port->writeBlock((char*)&data, 1); 00106 00107 return true; 00108 }
bool V24Control::transmitAndReceive | ( | unsigned char | tData, | |
unsigned char | rData | |||
) | [private] |
tData | ||
rData |
Definiert in Zeile 53 der Datei V24.cpp.
Benutzt port und transmit().
Wird benutzt von transmitCommand().
00053 { 00054 00055 int retransmitLoop=0, rxLoop=0, back; 00056 unsigned char _data; 00057 00058 retransmitLoop=0; 00059 rxLoop=0; 00060 do { 00061 transmit(tData); 00062 00063 rxLoop = 0; 00064 do { 00065 back = port->readBlock((char*)&_data, 1); 00066 printf ("."); 00067 00068 if (back >= 1) { 00069 printf ("###RX=%d###", _data); 00070 if (rData != _data) { 00071 rxLoop++; 00072 } else { 00073 usleep(10000); 00074 rxLoop = 501; 00075 retransmitLoop = 11; 00076 } 00077 } else { 00078 fflush(stdout); 00079 usleep(10000); 00080 rxLoop++; 00081 } 00082 00083 } while (rxLoop < 500); 00084 00085 printf ("\n"); 00086 retransmitLoop++; 00087 } while (retransmitLoop < 10 && rData != _data); 00088 if (retransmitLoop== 10) return false; 00089 00090 return true; 00091 00092 }
bool V24Control::transmitCommand | ( | V24COMMAND * | c | ) |
Diese Funktion sendet ein Kommando über die Seriellen Schnittstelle (high-level) Funktion liefert "true" zurück, wenn alles korrekt übertragen wurde. Im Fehlerfall => "false"
c |
Definiert in Zeile 151 der Datei V24.cpp.
Benutzt V24Command::command, V24Command::data, V24Command::dataLength, openDevice(), transmitAndReceive(), V24_COMMAND_SYNC_COMMAND und V24_COMMAND_SYNC_OK_COMMAND.
Wird benutzt von Simulation::v24_copy_states_and_gamma_to_robot_button_clicked(), Simulation::v24_debug_button_clicked(), Simulation::v24_distance_button_clicked(), Simulation::v24_exploration_accept_clicked(), Simulation::v24_explore_feedback_button_clicked(), Simulation::v24_get_exploration_clicked(), Simulation::v24_get_states_and_gamma_from_robot_button_clicked(), Simulation::v24_getPositionAndMode_button_clicked(), Simulation::v24_ramtest_button_clicked(), Simulation::v24_reset_distance_button_clicked(), Simulation::v24_start_learning_button_clicked(), Simulation::v24_start_walking_button_clicked() und Simulation::v24_stop_walking_button_clicked().
00151 { 00152 00153 // Port muss sicher geöffnet sein 00154 this->openDevice(); 00155 00156 00157 printf("\nBegin transmitCommand():\n"); 00158 00159 /************************** 00160 Synchronisierung 00161 ***************************/ 00162 if (!this->transmitAndReceive(V24_COMMAND_SYNC_COMMAND, V24_COMMAND_SYNC_OK_COMMAND)) return false; 00163 if (!this->transmitAndReceive(c->command, c->command)); 00164 if (!this->transmitAndReceive(c->dataLength, c->dataLength)); 00165 00166 for (int i=0; i < c->dataLength; i++) { 00167 00168 if (!this->transmitAndReceive(c->data[i], c->data[i])) return false; 00169 printf ("\n"); 00170 } 00171 00172 printf("End transmitCommand():\n"); 00173 00174 return true; 00175 }
QMutex* V24Control::conMutex [private] |
char V24Control::filename[50] [private] |
QMutex* V24Control::guiMutex [private] |
QMainWindow* V24Control::parent [private] |
Definiert in Zeile 62 der Datei V24.h.
Wird benutzt von openDevice(), showErrorCode() und V24Control().
Posix_QextSerialPort* V24Control::port [private] |
Definiert in Zeile 65 der Datei V24.h.
Wird benutzt von closeDevice(), openDevice(), receive(), setInterface(), transmit(), transmitAndReceive() und V24Control().
bool V24Control::receiving [private] |
bool V24Control::rxtx [private] |
QString V24Control::sDeviceInterface [private] |
Definiert in Zeile 69 der Datei V24.h.
Wird benutzt von openDevice(), setInterface() und V24Control().
bool V24Control::transmitting [private] |