echo befehl funktioniert
This commit is contained in:
parent
a68bb3aecc
commit
c108303ba3
9 changed files with 98 additions and 3 deletions
41
drv/b15f.cpp
41
drv/b15f.cpp
|
@ -8,9 +8,48 @@ B15F::B15F()
|
|||
|
||||
void B15F::init(void)
|
||||
{
|
||||
std::cout << "moint: " << std::endl;
|
||||
int code = system(std::string("stty 38400 -F " + SERIAL_DEVICE).c_str());
|
||||
if(code)
|
||||
{
|
||||
throw DriverException("Konnte serielle Verbindung nicht initialisieren. Ist der Adapter angeschlossen?");
|
||||
}
|
||||
|
||||
usart.open(SERIAL_DEVICE.c_str());
|
||||
|
||||
if(!testConnection())
|
||||
{
|
||||
throw DriverException("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
|
||||
}
|
||||
}
|
||||
|
||||
bool B15F::testConnection(void)
|
||||
{
|
||||
srand (time(NULL));
|
||||
uint8_t dummy = rand() % 256;
|
||||
writeByte(0); // echo / dummy command for testing
|
||||
writeByte(dummy);
|
||||
|
||||
uint8_t aw = readByte();
|
||||
uint8_t mirror = readByte();
|
||||
|
||||
return aw == MSG_OK && mirror == dummy;
|
||||
}
|
||||
|
||||
void B15F::writeByte(uint8_t b)
|
||||
{
|
||||
usart.put(b);
|
||||
}
|
||||
|
||||
uint8_t B15F::readByte()
|
||||
{
|
||||
char b;
|
||||
while(1)
|
||||
{
|
||||
if (usart.get(b))
|
||||
return static_cast<uint8_t>(b);
|
||||
}
|
||||
}
|
||||
|
||||
B15F& B15F::getInstance(void)
|
||||
{
|
||||
if(!instance)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue