diff --git a/bfs/implementations/breadcrumbs/include/AHRSInputIOProcessor.hpp b/bfs/implementations/breadcrumbs/include/AHRSInputIOProcessor.hpp index a7a298f..728b646 100644 --- a/bfs/implementations/breadcrumbs/include/AHRSInputIOProcessor.hpp +++ b/bfs/implementations/breadcrumbs/include/AHRSInputIOProcessor.hpp @@ -35,4 +35,4 @@ class AHRSInputIOProcessor : public IOProcessor HANDLE hSerial; }; -#endif \ No newline at end of file +#endif diff --git a/bfs/implementations/breadcrumbs/io_procs/AHRSInputIOProcessor.cpp b/bfs/implementations/breadcrumbs/io_procs/AHRSInputIOProcessor.cpp index 3363a98..5f52fdc 100644 --- a/bfs/implementations/breadcrumbs/io_procs/AHRSInputIOProcessor.cpp +++ b/bfs/implementations/breadcrumbs/io_procs/AHRSInputIOProcessor.cpp @@ -1,11 +1,21 @@ #include "AHRSInputIOProcessor.hpp" +/* + * Return Values: + * 0 : No Errors. + * 1 : Serial port does not exist. + * 2 : Some other error occurred. + * 3 : Error getting state. + * 4 : Error setting serial port state + * 5 : Error occured while setting timoemouts. + * 6 : Error occured while trying to send GoToConfig message. + * 7 : Error occured while trying to send SetOutputConfiguration message. + * 8 : Error occured while trying to send GoToMeasurment message. +*/ + int AHRSInputIOProcessor::configAHRS() { - DCB dcb = {0}; - //HANDLE hSerial; - hSerial = CreateFile("COM8", // The COM port to connect to, may have to be changed GENERIC_READ | GENERIC_WRITE, // depending on what COM port gets selected. 0, @@ -18,19 +28,20 @@ int AHRSInputIOProcessor::configAHRS() { if(GetLastError() == ERROR_FILE_NOT_FOUND) { - std::cout << "Serial port does not exist." << std::endl; - return 1; // serial port does not exist. + std::cerr << "Serial port does not exist." << std::endl; + return 1; } - std::cout << "Some other error occurred." << std::endl; - return 2; // some other error occurred. + std::cerr << "Some other error occurred." << std::endl; + return 2; } - + + DCB dcb = { 0 }; dcb.DCBlength = sizeof(dcb); if (!GetCommState(hSerial, &dcb)) { - std::cout << "Error getting state." << std::endl; - return 3; // error getting state. + std::cerr << "Error getting state." << std::endl; + return 3; } dcb.BaudRate = CBR_115200; // defualt baud rate of MT @@ -40,8 +51,8 @@ int AHRSInputIOProcessor::configAHRS() if (!SetCommState(hSerial, &dcb)) { - std::cout << "Error setting serial port state." << std::endl; - return 4; // error setting serial port state + std::cerr << "Error setting serial port state." << std::endl; + return 4; } COMMTIMEOUTS timeouts = {0}; @@ -54,7 +65,7 @@ int AHRSInputIOProcessor::configAHRS() if (!SetCommTimeouts(hSerial, &timeouts)) { - std::cout << "Error occured while setting timoemouts." << std::endl; + std::cerr << "Error occured while setting timoemouts." << std::endl; return 5; } @@ -66,7 +77,7 @@ int AHRSInputIOProcessor::configAHRS() if (!WriteFile(hSerial, wBuff1, 6, &dwBytesWritten, NULL)) { - std::cout << "Error occured while trying to send GoToConfig message." << std::endl; + std::cerr << "Error occured while trying to send GoToConfig message." << std::endl; return 6; } @@ -75,7 +86,7 @@ int AHRSInputIOProcessor::configAHRS() if (!WriteFile(hSerial, wBuff2, 10, &dwBytesWritten, NULL)) { - std::cout << "Error occured while trying to send SetOutputConfiguration message." << std::endl; + std::cerr << "Error occured while trying to send SetOutputConfiguration message." << std::endl; return 7; } @@ -84,7 +95,7 @@ int AHRSInputIOProcessor::configAHRS() if (!WriteFile(hSerial, wBuff3, 6, &dwBytesWritten, NULL)) { - std::cout << "Error occured while trying to send GoToMeasurment message." << std::endl; + std::cerr << "Error occured while trying to send GoToMeasurment message." << std::endl; return 8; } @@ -94,7 +105,7 @@ int AHRSInputIOProcessor::configAHRS() bool AHRSInputIOProcessor::loopCondition() { - return iterations > 0; + return true; } void AHRSInputIOProcessor::loop() @@ -107,8 +118,7 @@ void AHRSInputIOProcessor::loop() if (!ReadFile(hSerial, szBuff, 64, &dwBytesRead, NULL)) { - std::cout << "Error occured while trying to read bytes." << std::endl; - //return 9; + std::cerr << "Error occured while trying to read bytes." << std::endl; } int index = -1; @@ -131,8 +141,7 @@ void AHRSInputIOProcessor::loop() double doubleYaw = *reinterpret_cast(yawArray); Attribute attrib("yawAngle", 8, &doubleYaw); getComms()->sendAttribute(attrib); - iterations--; - if (iterations == 0) - CloseHandle(hSerial); + // I am not sure if it will close autimatically when the process ends, at the moment I guess we just won't close it... + //CloseHandle(hSerial); } \ No newline at end of file