Remove all debugging printouts to stdout

pull/4/head
Paul Hollinsky 2018-10-30 15:02:01 -04:00
parent ccd26a3637
commit 92d98f8bd5
16 changed files with 79 additions and 46 deletions

View File

@ -58,6 +58,14 @@ static constexpr const char* ERROR_SETTINGS_LENGTH = "The settings length is inc
static constexpr const char* ERROR_SETTINGS_CHECKSUM = "The settings checksum is incorrect, attempting to set defaults may remedy this issue."; static constexpr const char* ERROR_SETTINGS_CHECKSUM = "The settings checksum is incorrect, attempting to set defaults may remedy this issue.";
static constexpr const char* ERROR_SETTINGS_NOT_AVAILABLE = "Settings are not available for this device."; static constexpr const char* ERROR_SETTINGS_NOT_AVAILABLE = "Settings are not available for this device.";
// Transport Errors
static constexpr const char* ERROR_FAILED_TO_READ = "A read operation failed.";
static constexpr const char* ERROR_FAILED_TO_WRITE = "A write operation failed.";
static constexpr const char* ERROR_DRIVER_FAILED_TO_OPEN = "The device driver encountered a low-level error while opening the device.";
static constexpr const char* ERROR_PACKET_CHECKSUM_ERROR = "There was a checksum error while decoding a packet. The packet was dropped.";
static constexpr const char* ERROR_PCAP_COULD_NOT_START = "The PCAP driver could not be started. Ethernet devices will not be found.";
static constexpr const char* ERROR_PCAP_COULD_NOT_FIND_DEVICES = "The PCAP driver failed to find devices. Ethernet devices will not be found.";
static constexpr const char* ERROR_TOO_MANY_ERRORS = "Too many errors have occurred. The list has been truncated."; static constexpr const char* ERROR_TOO_MANY_ERRORS = "Too many errors have occurred. The list has been truncated.";
static constexpr const char* ERROR_UNKNOWN = "An unknown internal error occurred."; static constexpr const char* ERROR_UNKNOWN = "An unknown internal error occurred.";
static constexpr const char* ERROR_INVALID = "An invalid internal error occurred."; static constexpr const char* ERROR_INVALID = "An invalid internal error occurred.";
@ -92,6 +100,20 @@ const char* APIError::DescriptionForType(ErrorType type) {
return ERROR_SETTINGS_CHECKSUM; return ERROR_SETTINGS_CHECKSUM;
case SettingsNotAvailable: case SettingsNotAvailable:
return ERROR_SETTINGS_NOT_AVAILABLE; return ERROR_SETTINGS_NOT_AVAILABLE;
// Transport Errors
case FailedToRead:
return ERROR_FAILED_TO_READ;
case FailedToWrite:
return ERROR_FAILED_TO_WRITE;
case DriverFailedToOpen:
return ERROR_DRIVER_FAILED_TO_OPEN;
case PacketChecksumError:
return ERROR_PACKET_CHECKSUM_ERROR;
case PCAPCouldNotStart:
return ERROR_PCAP_COULD_NOT_START;
case PCAPCouldNotFindDevices:
return ERROR_PCAP_COULD_NOT_FIND_DEVICES;
// Other Errors // Other Errors
case TooManyErrors: case TooManyErrors:
@ -109,6 +131,9 @@ APIError::Severity APIError::SeverityForType(ErrorType type) {
case OutputTruncated: case OutputTruncated:
// Device Warnings // Device Warnings
case PollingMessageOverflow: case PollingMessageOverflow:
// Transport Warnings
case PCAPCouldNotStart:
case PCAPCouldNotFindDevices:
return Severity::Warning; return Severity::Warning;
// API Errors // API Errors
@ -124,6 +149,11 @@ APIError::Severity APIError::SeverityForType(ErrorType type) {
case SettingsLengthError: case SettingsLengthError:
case SettingsChecksumError: case SettingsChecksumError:
case SettingsNotAvailable: case SettingsNotAvailable:
// Transport Errors
case FailedToRead:
case FailedToWrite:
case DriverFailedToOpen:
case PacketChecksumError:
// Other Errors // Other Errors
case TooManyErrors: case TooManyErrors:
case Unknown: case Unknown:

View File

@ -45,7 +45,8 @@ void MultiChannelCommunication::readTask() {
currentCommandType = (CommandType)usbReadFifo[0]; currentCommandType = (CommandType)usbReadFifo[0];
if(!CommandTypeIsValid(currentCommandType)) { if(!CommandTypeIsValid(currentCommandType)) {
std::cout << "cnv" << std::hex << (int)currentCommandType << ' ' << std::dec; // TODO Flag error? Device to host bytes discarded
//std::cout << "cnv" << std::hex << (int)currentCommandType << ' ' << std::dec;
usbReadFifo.pop_front(); usbReadFifo.pop_front();
continue; continue;
} }

View File

@ -111,7 +111,7 @@ bool Packetizer::input(const std::vector<uint8_t>& inputBytes) {
bytes.pop_front(); bytes.pop_front();
} else { } else {
if(gotGoodPackets) // Don't complain unless we've already gotten a good packet, in case we started in the middle of a stream if(gotGoodPackets) // Don't complain unless we've already gotten a good packet, in case we started in the middle of a stream
std::cout << "Dropping packet due to bad checksum" << std::endl; err(APIError::PacketChecksumError);
bytes.pop_front(); // Drop the first byte so it doesn't get picked up again bytes.pop_front(); // Drop the first byte so it doesn't get picked up again
} }

View File

@ -50,6 +50,14 @@ public:
SettingsChecksumError = 0x2006, SettingsChecksumError = 0x2006,
SettingsNotAvailable = 0x2007, SettingsNotAvailable = 0x2007,
// Transport Errors
FailedToRead = 0x3000,
FailedToWrite = 0x3001,
DriverFailedToOpen = 0x3002,
PacketChecksumError = 0x3003,
PCAPCouldNotStart = 0x3102,
PCAPCouldNotFindDevices = 0x3103,
TooManyErrors = 0xFFFFFFFE, TooManyErrors = 0xFFFFFFFE,
Unknown = 0xFFFFFFFF Unknown = 0xFFFFFFFF
}; };

View File

@ -21,14 +21,7 @@ public:
return false; return false;
} }
const auto main51Message = std::dynamic_pointer_cast<Main51Message>(message); const auto main51Message = std::dynamic_pointer_cast<Main51Message>(message);
if(!main51Message) return main51Message && matchCommand(main51Message->command);
std::cout << "could not upcast " << message->network << std::endl;
if(main51Message == nullptr || !matchCommand(main51Message->command)) {
if(main51Message)
std::cout << "Could not match command " << (int)(command) << " to " << (int)(main51Message->command) << std::endl;
return false;
}
return true;
} }
private: private:

View File

@ -102,7 +102,7 @@ protected:
} }
template<typename Transport> template<typename Transport>
std::unique_ptr<ICommunication> makeTransport() { return std::unique_ptr<ICommunication>(new Transport(getWritableNeoDevice())); } std::unique_ptr<ICommunication> makeTransport() { return std::unique_ptr<ICommunication>(new Transport(err, getWritableNeoDevice())); }
virtual void setupTransport(ICommunication* transport) {} virtual void setupTransport(ICommunication* transport) {}
virtual std::shared_ptr<Packetizer> makePacketizer() { return std::make_shared<Packetizer>(err); } virtual std::shared_ptr<Packetizer> makePacketizer() { return std::make_shared<Packetizer>(err); }

View File

@ -9,6 +9,7 @@
#include "icsneo/device/neodevice.h" #include "icsneo/device/neodevice.h"
#include "icsneo/communication/icommunication.h" #include "icsneo/communication/icommunication.h"
#include "icsneo/third-party/concurrentqueue/blockingconcurrentqueue.h" #include "icsneo/third-party/concurrentqueue/blockingconcurrentqueue.h"
#include "icsneo/api/errormanager.h"
namespace icsneo { namespace icsneo {
@ -18,7 +19,7 @@ public:
static std::vector<neodevice_t> FindByProduct(int product); static std::vector<neodevice_t> FindByProduct(int product);
static bool IsHandleValid(neodevice_handle_t handle); static bool IsHandleValid(neodevice_handle_t handle);
FTDI(neodevice_t& forDevice); FTDI(device_errorhandler_t err, neodevice_t& forDevice);
~FTDI() { close(); } ~FTDI() { close(); }
bool open(); bool open();
bool close(); bool close();
@ -43,6 +44,7 @@ private:
bool openable; // Set to false in the constructor if the object has not been found in searchResultDevices bool openable; // Set to false in the constructor if the object has not been found in searchResultDevices
neodevice_t& device; neodevice_t& device;
device_errorhandler_t err;
FTDIDevice ftdiDevice; FTDIDevice ftdiDevice;
}; };

View File

@ -3,6 +3,7 @@
#include "icsneo/communication/icommunication.h" #include "icsneo/communication/icommunication.h"
#include "icsneo/device/neodevice.h" #include "icsneo/device/neodevice.h"
#include "icsneo/api/errormanager.h"
#include <chrono> #include <chrono>
#include <stdint.h> #include <stdint.h>
@ -10,7 +11,7 @@ namespace icsneo {
class STM32 : public ICommunication { class STM32 : public ICommunication {
public: public:
STM32(neodevice_t& forDevice) : device(forDevice) {} STM32(device_errorhandler_t err, neodevice_t& forDevice) : device(forDevice), err(err) {}
static std::vector<neodevice_t> FindByProduct(int product); static std::vector<neodevice_t> FindByProduct(int product);
bool open(); bool open();
@ -19,6 +20,7 @@ public:
private: private:
neodevice_t& device; neodevice_t& device;
device_errorhandler_t err;
int fd = -1; int fd = -1;
static constexpr neodevice_handle_t HANDLE_OFFSET = 10; static constexpr neodevice_handle_t HANDLE_OFFSET = 10;

View File

@ -7,7 +7,7 @@ namespace icsneo {
class FTDI : public VCP { class FTDI : public VCP {
public: public:
FTDI(neodevice_t& forDevice) : VCP(forDevice) {} FTDI(device_errorhandler_t err, neodevice_t& forDevice) : VCP(err, forDevice) {}
static std::vector<neodevice_t> FindByProduct(int product) { return VCP::FindByProduct(product, L"serenum"); } static std::vector<neodevice_t> FindByProduct(int product) { return VCP::FindByProduct(product, L"serenum"); }
}; };

View File

@ -4,6 +4,7 @@
#include "icsneo/platform/windows/internal/pcapdll.h" #include "icsneo/platform/windows/internal/pcapdll.h"
#include "icsneo/device/neodevice.h" #include "icsneo/device/neodevice.h"
#include "icsneo/communication/icommunication.h" #include "icsneo/communication/icommunication.h"
#include "icsneo/api/errormanager.h"
#include <string> #include <string>
namespace icsneo { namespace icsneo {
@ -20,7 +21,7 @@ public:
static std::string GetEthDevSerialFromMacAddress(uint8_t product, uint16_t macSerial); static std::string GetEthDevSerialFromMacAddress(uint8_t product, uint16_t macSerial);
static bool IsHandleValid(neodevice_handle_t handle); static bool IsHandleValid(neodevice_handle_t handle);
PCAP(neodevice_t& forDevice); PCAP(device_errorhandler_t err, neodevice_t& forDevice);
bool open(); bool open();
bool isOpen(); bool isOpen();
bool close(); bool close();

View File

@ -7,7 +7,7 @@ namespace icsneo {
class STM32 : public VCP { class STM32 : public VCP {
public: public:
STM32(neodevice_t& forDevice) : VCP(forDevice) {} STM32(device_errorhandler_t err, neodevice_t& forDevice) : VCP(err, forDevice) {}
static std::vector<neodevice_t> FindByProduct(int product) { return VCP::FindByProduct(product, L"usbser"); } static std::vector<neodevice_t> FindByProduct(int product) { return VCP::FindByProduct(product, L"usbser"); }
}; };

View File

@ -9,6 +9,7 @@
#include <Windows.h> #include <Windows.h>
#include "icsneo/device/neodevice.h" #include "icsneo/device/neodevice.h"
#include "icsneo/communication/icommunication.h" #include "icsneo/communication/icommunication.h"
#include "icsneo/api/errormanager.h"
namespace icsneo { namespace icsneo {
@ -19,7 +20,7 @@ public:
static bool IsHandleValid(neodevice_handle_t handle); static bool IsHandleValid(neodevice_handle_t handle);
typedef void(*fn_boolCallback)(bool success); typedef void(*fn_boolCallback)(bool success);
VCP(neodevice_t& forDevice) : device(forDevice) { VCP(device_errorhandler_t err, neodevice_t& forDevice) : device(forDevice), err(err) {
overlappedRead.hEvent = INVALID_HANDLE_VALUE; overlappedRead.hEvent = INVALID_HANDLE_VALUE;
overlappedWrite.hEvent = INVALID_HANDLE_VALUE; overlappedWrite.hEvent = INVALID_HANDLE_VALUE;
overlappedWait.hEvent = INVALID_HANDLE_VALUE; overlappedWait.hEvent = INVALID_HANDLE_VALUE;
@ -34,6 +35,7 @@ private:
bool open(bool fromAsync); bool open(bool fromAsync);
bool opening = false; bool opening = false;
neodevice_t& device; neodevice_t& device;
device_errorhandler_t err;
HANDLE handle = INVALID_HANDLE_VALUE; HANDLE handle = INVALID_HANDLE_VALUE;
OVERLAPPED overlappedRead = {}; OVERLAPPED overlappedRead = {};
OVERLAPPED overlappedWrite = {}; OVERLAPPED overlappedWrite = {};

View File

@ -58,7 +58,7 @@ bool FTDI::GetDeviceForHandle(neodevice_handle_t handle, FTDIDevice& device) {
return false; return false;
} }
FTDI::FTDI(neodevice_t& forDevice) : device(forDevice) { FTDI::FTDI(device_errorhandler_t err, neodevice_t& forDevice) : device(forDevice), err(err) {
openable = GetDeviceForHandle(forDevice.handle, ftdiDevice); openable = GetDeviceForHandle(forDevice.handle, ftdiDevice);
} }

View File

@ -195,7 +195,8 @@ bool STM32::open() {
ss << "/dev/ttyACM" << (int)(device.handle - HANDLE_OFFSET); ss << "/dev/ttyACM" << (int)(device.handle - HANDLE_OFFSET);
fd = ::open(ss.str().c_str(), O_RDWR | O_NOCTTY | O_SYNC); fd = ::open(ss.str().c_str(), O_RDWR | O_NOCTTY | O_SYNC);
if(!isOpen()) { if(!isOpen()) {
std::cout << "Open of " << ss.str().c_str() << " failed with " << strerror(errno) << ' '; //std::cout << "Open of " << ss.str().c_str() << " failed with " << strerror(errno) << ' ';
err(APIError::DriverFailedToOpen);
return false; return false;
} }
@ -276,6 +277,6 @@ void STM32::writeTask() {
const ssize_t writeSize = (ssize_t)writeOp.bytes.size(); const ssize_t writeSize = (ssize_t)writeOp.bytes.size();
ssize_t actualWritten = ::write(fd, writeOp.bytes.data(), writeSize); ssize_t actualWritten = ::write(fd, writeOp.bytes.data(), writeSize);
if(actualWritten != writeSize) if(actualWritten != writeSize)
std::cout << "Failure to write " << writeSize << " bytes, wrote " << actualWritten << std::endl; err(APIError::FailedToWrite);
} }
} }

View File

@ -20,7 +20,7 @@ std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
std::vector<PCAPFoundDevice> foundDevices; std::vector<PCAPFoundDevice> foundDevices;
PCAPDLL pcap; PCAPDLL pcap;
if(!pcap.ok()) { if(!pcap.ok()) {
std::cout << "PCAP not okay" << std::endl; ErrorManager::GetInstance().add(APIError::PCAPCouldNotStart);
return std::vector<PCAPFoundDevice>(); return std::vector<PCAPFoundDevice>();
} }
@ -38,7 +38,7 @@ std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
} }
if(!success) { if(!success) {
std::cout << "PCAP FindAllDevs_Ex not okay " << errbuf << std::endl; ErrorManager::GetInstance().add(APIError::PCAPCouldNotFindDevices);
return std::vector<PCAPFoundDevice>(); return std::vector<PCAPFoundDevice>();
} }
@ -55,13 +55,13 @@ std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
// Now we're going to ask Win32 for the information as well // Now we're going to ask Win32 for the information as well
ULONG size = 0; ULONG size = 0;
if(GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, nullptr, nullptr, &size) != ERROR_BUFFER_OVERFLOW) { if(GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, nullptr, nullptr, &size) != ERROR_BUFFER_OVERFLOW) {
std::cout << "GetAdaptersAddresses size query not okay" << std::endl; ErrorManager::GetInstance().add(APIError::PCAPCouldNotFindDevices);
return std::vector<PCAPFoundDevice>(); return std::vector<PCAPFoundDevice>();
} }
std::vector<uint8_t> adapterAddressBuffer; std::vector<uint8_t> adapterAddressBuffer;
adapterAddressBuffer.resize(size); adapterAddressBuffer.resize(size);
if(GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, nullptr, (IP_ADAPTER_ADDRESSES*)adapterAddressBuffer.data(), &size) != ERROR_SUCCESS) { if(GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, nullptr, (IP_ADAPTER_ADDRESSES*)adapterAddressBuffer.data(), &size) != ERROR_SUCCESS) {
std::cout << "GetAdaptersAddresses not okay" << std::endl; ErrorManager::GetInstance().add(APIError::PCAPCouldNotFindDevices);
return std::vector<PCAPFoundDevice>(); return std::vector<PCAPFoundDevice>();
} }
@ -124,7 +124,7 @@ std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
const uint8_t* data; const uint8_t* data;
auto res = pcap.next_ex(interface.fp, &header, &data); auto res = pcap.next_ex(interface.fp, &header, &data);
if(res < 0) { if(res < 0) {
std::cout << "pcapnextex failed with " << res << std::endl; //std::cout << "pcapnextex failed with " << res << std::endl;
break; break;
} }
if(res == 0) if(res == 0)
@ -177,7 +177,7 @@ bool PCAP::IsHandleValid(neodevice_handle_t handle) {
return (netifIndex < knownInterfaces.size()); return (netifIndex < knownInterfaces.size());
} }
PCAP::PCAP(neodevice_t& forDevice) : device(forDevice) { PCAP::PCAP(device_errorhandler_t err, neodevice_t& forDevice) : device(forDevice), err(err) {
if(IsHandleValid(device.handle)) { if(IsHandleValid(device.handle)) {
interface = knownInterfaces[(device.handle >> 24) & 0xFF]; interface = knownInterfaces[(device.handle >> 24) & 0xFF];
interface.fp = nullptr; // We're going to open our own connection to the interface. This should already be nullptr but just in case. interface.fp = nullptr; // We're going to open our own connection to the interface. This should already be nullptr but just in case.
@ -206,7 +206,7 @@ bool PCAP::open() {
// Open the interface // Open the interface
interface.fp = pcap.open(interface.nameFromWinPCAP.c_str(), 100, PCAP_OPENFLAG_PROMISCUOUS | PCAP_OPENFLAG_MAX_RESPONSIVENESS, 1, nullptr, errbuf); interface.fp = pcap.open(interface.nameFromWinPCAP.c_str(), 100, PCAP_OPENFLAG_PROMISCUOUS | PCAP_OPENFLAG_MAX_RESPONSIVENESS, 1, nullptr, errbuf);
if(interface.fp == nullptr) { if(interface.fp == nullptr) {
std::cout << "Open device " << device.serial << " failed with " << errbuf << std::endl; err(APIError::DriverFailedToOpen);
return false; return false;
} }
@ -241,7 +241,7 @@ void PCAP::readTask() {
while(!closing) { while(!closing) {
auto readBytes = pcap.next_ex(interface.fp, &header, &data); auto readBytes = pcap.next_ex(interface.fp, &header, &data);
if(readBytes < 0) { if(readBytes < 0) {
std::cout << "pcapnextex failed in read task with " << readBytes << std::endl; err(APIError::FailedToRead);
break; break;
} }
if(readBytes == 0) if(readBytes == 0)

View File

@ -249,28 +249,22 @@ void VCP::readTask() {
case LAUNCH: { case LAUNCH: {
COMSTAT comStatus; COMSTAT comStatus;
unsigned long errorCodes; unsigned long errorCodes;
if(!ClearCommError(handle, &errorCodes, &comStatus)) ClearCommError(handle, &errorCodes, &comStatus);
std::cout << "Error clearing com err" << std::endl;
bytesRead = 0; bytesRead = 0;
if(ReadFile(handle, readbuf, READ_BUFFER_SIZE, nullptr, &overlappedRead)) { if(ReadFile(handle, readbuf, READ_BUFFER_SIZE, nullptr, &overlappedRead)) {
if(GetOverlappedResult(handle, &overlappedRead, &bytesRead, FALSE)) { if(GetOverlappedResult(handle, &overlappedRead, &bytesRead, FALSE)) {
if(bytesRead) if(bytesRead)
readQueue.enqueue_bulk(readbuf, bytesRead); readQueue.enqueue_bulk(readbuf, bytesRead);
} else {
std::cout <<"Readfile succeeded but not enqueued " << GetLastError() << std::endl;
} }
continue; continue;
} }
auto err = GetLastError(); auto lastError = GetLastError();
if(err == ERROR_SUCCESS) if(lastError == ERROR_IO_PENDING)
std::cout << "Error was success?" << std::endl;
if(err == ERROR_IO_PENDING)
state = WAIT; state = WAIT;
else else if(lastError != ERROR_SUCCESS)
std::cout << "ReadFile failed " << err << std::endl; err(APIError::FailedToRead);
} }
break; break;
case WAIT: { case WAIT: {
@ -281,11 +275,11 @@ void VCP::readTask() {
readQueue.enqueue_bulk(readbuf, bytesRead); readQueue.enqueue_bulk(readbuf, bytesRead);
state = LAUNCH; state = LAUNCH;
} else } else
std::cout << "ReadFile deferred failed " << err << std::endl; err(APIError::FailedToRead);
} }
if(ret == WAIT_ABANDONED) { if(ret == WAIT_ABANDONED) {
state = LAUNCH; state = LAUNCH;
std::cout << "Readfile abandoned" << std::endl; err(APIError::FailedToRead);
} }
} }
} }
@ -311,20 +305,19 @@ void VCP::writeTask() {
state = WAIT; state = WAIT;
} }
else else
std::cout << "Writefile failed " << err << std::endl; err(APIError::FailedToWrite);
} }
break; break;
case WAIT: { case WAIT: {
auto ret = WaitForSingleObject(overlappedWrite.hEvent, 50); auto ret = WaitForSingleObject(overlappedWrite.hEvent, 50);
if(ret == WAIT_OBJECT_0) { if(ret == WAIT_OBJECT_0) {
if(!GetOverlappedResult(handle, &overlappedWrite, &bytesWritten, FALSE)) { if(!GetOverlappedResult(handle, &overlappedWrite, &bytesWritten, FALSE))
std::cout << "Writefile deferred failed " << GetLastError() << std::endl; err(APIError::FailedToWrite);
}
state = LAUNCH; state = LAUNCH;
} }
if(ret == WAIT_ABANDONED) { if(ret == WAIT_ABANDONED) {
std::cout << "Writefile deferred abandoned" << std::endl; err(APIError::FailedToWrite);
state = LAUNCH; state = LAUNCH;
} }
} }