reworked and optimized device handling and check network device address, log failed device open, avoid blocking threads with sleep(), optimized shutdown

This commit is contained in:
john30
2015-02-08 10:06:03 +01:00
parent 4404202609
commit aa306d9131
17 changed files with 664 additions and 735 deletions
+62
View File
@@ -0,0 +1,62 @@
/*
* Copyright (C) John Baier 2015 <ebusd@johnm.de>
*
* This file is part of ebusd.
*
* ebusd is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ebusd is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ebusd. If not, see http://www.gnu.org/licenses/.
*/
#include "device.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
Device* device = Device::create("/dev/ttyUSB20", true, NULL);
if (device == NULL) {
cout << "unable to create device" << endl;
return -1;
}
result_t result = device->open();
if (result != RESULT_OK) {
cout << "open failed: " << getResultCode(result) << endl;
} else {
if (device->isValid() == false)
cout << "device not available." << endl;
int count = 0;
while (1) {
unsigned char byte = 0;
result = device->recv(0, byte);
if (result == RESULT_OK)
cout << hex << setw(2) << setfill('0')
<< static_cast<unsigned>(byte) << endl;
count++;
}
device->close();
if(device->isValid() == false)
cout << "close successful." << endl;
}
delete device;
return 0;
}