17 #define SOPASBASE_VERSION "1.0.0"
95 std::string ipAddress,
153 printError(
"SopasBase::connect: Failed to read scanner type and version.");
157 if (success ==
false)
159 printWarning(
"SopasBase::connect: Initialisation failed!");
224 if (success ==
false)
226 printError(
"SopasBase::openTcpConnection: ERROR: Failed to establish TCP connection, aborting!");
251 ((
SopasBase*)obj)->readCallbackFunction(buffer, numOfBytes);
261 bool beVerboseHere =
false;
262 printInfoMessage(
"SopasBase::readCallbackFunction(): Called with " +
toString(numOfBytes) +
" available bytes.", beVerboseHere);
266 UINT32 bytesToBeTransferred = numOfBytes;
267 if (remainingSpace < numOfBytes)
269 bytesToBeTransferred = remainingSpace;
270 printWarning(
"SopasBase::readCallbackFunction(): Input buffer space is to small, transferring only " +
271 ::
toString(bytesToBeTransferred) +
" of " + ::
toString(numOfBytes) +
" bytes.");
276 " bytes from TCP to input buffer.", beVerboseHere);
279 if (bytesToBeTransferred > 0)
297 printInfoMessage(
"SopasBase::readCallbackFunction(): No complete frame in input buffer, we are done.", beVerboseHere);
305 printInfoMessage(
"SopasBase::readCallbackFunction(): Processing a frame of length " + ::
toString(frame.
size()) +
" bytes.", beVerboseHere);
318 printInfoMessage(
"SopasBase::readCallbackFunction(): Leaving. Current input buffer fill level is " +
400 if (magicWord != 0x02020202)
407 if (magicWord == 0x02020202)
434 printInfoMessage(
"SopasBase::findFrameInReceiveBuffer: Frame cannot be decoded yet, only " +
441 payloadlength = colab::getIntegerFromBuffer<UINT32>(
m_receiveBuffer, pos);
448 printWarning(
"SopasBase::findFrameInReceiveBuffer: Frame too big for receive buffer. Frame discarded with length:"
456 printInfoMessage(
"SopasBase::findFrameInReceiveBuffer: Frame not complete yet. Waiting for the rest of it (" +
462 frameLen = payloadlength + 9;
476 for (
UINT16 i = 8; i < (frameLen - 1); i++)
480 temp_xor = temp_xor ^ temp;
484 if (temp_xor != checkSum)
486 printWarning(
"SopasBase::findFrameInReceiveBuffer: Wrong checksum, Frame discarded.");
507 UINT8 sendBuffer[1024];
550 printWarning(
"SopasBase::receiveAnswer: Wrong protocol (is either not CoLa-A or CoLa-B).");
577 printWarning(
"SopasBase::receiveAnswer: Wrong protocol (is either not CoLa-A or CoLa-B).");
606 printInfoMessage(
"SopasBase::receiveAnswer_CoLa_A: Response received (len= " +
614 if (rxData.length() > 0)
619 if (
cmd == receivedCommand)
623 if (receivedCommand ==
WA)
631 if (receivedIndex == index)
642 else if (receivedCommand ==
EA)
645 printInfoMessage(
"SopasBase::receiveAnswer_CoLa_A: Event (by index) successfully (un)registered: " +
659 else if (receivedCommand ==
FA)
704 printInfoMessage(
"SopasBase::receiveAnswer_CoLa_A: Response received (len= " +
711 if (rxData.length() > 0)
716 if (
cmd == receivedCommand)
720 if (receivedCommand ==
WA)
728 if (receivedName == name)
739 else if (receivedCommand ==
EA)
755 else if (receivedCommand ==
FA)
757 printInfoMessage(
"SopasBase:: Error answer received: FA " + rxData +
".",
true);
787 std::string receivedName;
816 if (receivedCommand ==
FA)
821 printWarning(
"SopasBase::receiveAnswer_CoLa_B: Error from sensor! Code=" +
toString(errorCode) +
827 if (
cmd != receivedCommand)
845 if (name != receivedName)
855 if (receivedCommand ==
WA)
863 else if (receivedCommand ==
EA)
870 else if (receivedCommand ==
AN )
877 else if (receivedCommand ==
RA)
887 printInfoMessage(
"SopasBase::receiveAnswer_CoLa_B: Unkown Sopas command.",
true);
923 return "Sopas_Error_METHODIN_ACCESSDENIED";
925 return "Sopas_Error_METHODIN_UNKNOWNINDEX";
927 return "Sopas_Error_VARIABLE_UNKNOWNINDEX";
929 return "Sopas_Error_LOCALCONDITIONFAILED";
931 return "Sopas_Error_INVALID_DATA";
933 return "Sopas_Error_UNKNOWN_ERROR";
935 return "Sopas_Error_BUFFER_OVERFLOW";
937 return "Sopas_Error_BUFFER_UNDERFLOW";
939 return "Sopas_Error_ERROR_UNKNOWN_TYPE";
941 return "Sopas_Error_VARIABLE_WRITE_ACCESSDENIED";
943 return "Sopas_Error_UNKNOWN_CMD_FOR_NAMESERVER";
945 return "Sopas_Error_UNKNOWN_COLA_COMMAND";
947 return "Sopas_Error_METHODIN_SERVER_BUSY";
949 return "Sopas_Error_FLEX_OUT_OF_BOUNDS";
951 return "Sopas_Error_EVENTREG_UNKNOWNINDEX";
953 return "Sopas_Error_COLA_A_VALUE_OVERFLOW";
955 return "Sopas_Error_COLA_A_INVALID_CHARACTER";
957 return "Sopas_Error_OSAI_NO_MESSAGE";
959 return "Sopas_Error_OSAI_NO_ANSWER_MESSAGE";
961 return "Sopas_Error_INTERNAL";
963 return "Sopas_Error_HubAddressCorrupted";
965 return "Sopas_Error_HubAddressDecoding";
967 return "Sopas_Error_HubAddressAddressExceeded";
969 return "Sopas_Error_HubAddressBlankExpected";
971 return "Sopas_Error_AsyncMethodsAreSuppressed";
973 return "Sopas_Error_ComplexArraysNotSupported";
975 return "(unknown_Sopas_error_code)";
978 return "(unknown_Sopas_error_code)";
989 printInfoMessage(
"SopasBase::receiveAnswer_CoLa_B_idx: Entering function.", beVerboseHere);
1004 printInfoMessage(
"SopasBase::receiveAnswer_CoLa_B_idx: There is something in receive buffer.", beVerboseHere);
1022 if (receivedCommand ==
FA)
1026 printWarning(
"SopasBase::receiveAnswer_CoLa_B_idx: Error from sensor! Code=" +
toString(receivedIndex) +
1032 else if (index != receivedIndex)
1037 printInfoMessage(
"SopasBase::receiveAnswer_CoLa_B_idx: This is not the index we are waiting for (expected="
1038 +
toString(index) +
", received=" +
toString(receivedIndex) +
")." , beVerboseHere);
1043 else if (
cmd != receivedCommand)
1053 else if (receivedCommand ==
WA)
1056 printInfoMessage(
"SopasBase::receiveAnswer_CoLa_B_idx: Variable successfully set.", beVerboseHere);
1061 else if (receivedCommand ==
EA)
1064 printInfoMessage(
"SopasBase::receiveAnswer_CoLa_B_idx: Event successfully (un)registered: " + ::
toString(receivedIndex) +
".", beVerboseHere);
1069 else if (receivedCommand ==
AI )
1072 printInfoMessage(
"SopasBase::receiveAnswer_CoLa_B_idx: Answer to method call with index " + ::
toString(receivedIndex) +
".", beVerboseHere);
1078 else if (receivedCommand ==
RA)
1081 printInfoMessage(
"SopasBase::receiveAnswer_CoLa_B_idx: Answer to read variable with index " + ::
toString(receivedIndex) +
".", beVerboseHere);
1090 printWarning(
"SopasBase::receiveAnswer_CoLa_B_idx: Unknown Sopas command.");
1097 printInfoMessage(
"SopasBase::receiveAnswer_CoLa_B_idx: Untreated Sopas command.", beVerboseHere);
1110 printInfoMessage(
"SopasBase::receiveAnswer_CoLa_B_idx: Leaving with timeout.", beVerboseHere);
1150 assert (
command.length() == 2);
1158 if (frame.
size() > 8)
1161 std::string eventName;
1178 printWarning(
"SopasBase::Received an unknown event! Event name is: " + eventName +
".");
1245 bool frameWasProcessed =
false;
1248 if (frame.
size() > 12)
1252 std::string eventName;
1260 eventIndex = colab::getIntegerFromBuffer<UINT16>(
m_receiveBuffer, pos);
1268 frameWasProcessed =
true;
1273 frameWasProcessed =
true;
1281 printWarning(
"SopasBase::processFrame_CoLa_B: Decoding of events by name is not implemented yet.");
1286 if (frameWasProcessed ==
false)
1289 printWarning(
"SopasBase::processFrame_CoLa_B: Don't know how to process the incoming event with the short name <" +
1290 eventName +
"> and the index " + ::
toString(eventIndex) +
", ignoring it!");
1296 printWarning(
"SopasBase::processFrame_CoLa_B: Received a very short (and unknown) event! Frame length is " + ::
toString(frame.
size()) +
" bytes.");
1329 printError(
"SopasBase::copyFrameToResposeBuffer: Failed to copy frame (Length=" + ::
toString(frameLength) +
1330 " bytes) to response buffer because the response buffer is too small (buffer size=" +
1349 " bytes from the input buffer. New length is " + ::
toString(newLen) +
" bytes.",
m_beVerbose);
1378 if (cmdString ==
"RN")
1384 else if (cmdString ==
"AN")
1389 else if (cmdString ==
"SN")
1395 if (cmdString ==
"RI")
1399 else if (cmdString ==
"WI")
1403 else if (cmdString ==
"MI")
1407 else if (cmdString ==
"AI")
1411 else if (cmdString ==
"EI")
1415 else if (cmdString ==
"SI")
1421 else if (cmdString ==
"RA")
1425 else if (cmdString ==
"WA")
1429 else if (cmdString ==
"MA")
1433 else if (cmdString ==
"AA")
1437 else if (cmdString ==
"EA")
1441 else if (cmdString ==
"SA")
1445 else if (cmdString ==
"FA")
1452 printError(
"SopasBase::stringToSopasCommand: Trying to resolve an unknown command: " + cmdString +
".");
1534 printError(
"SopasBase::sopasCommandToString: Trying to resolve an unknown command!");
1552 bool result =
false;
1561 if (result && answer != NULL && answer->
isValid())
1565 std::string colaaAnswer;
1569 colaaAnswer = std::string((
char*)answer->
getBuffer(), answer->
size());
1609 *rxData = rxData->substr(len + 1);
1633 fieldLength = colab::getIntegerFromBuffer<UINT16>(buffer, pos);
1637 fieldLength = colab::getIntegerFromBuffer<UINT16>(buffer, pos);
1651 BYTE cmdBuffer[128];
1658 cmdBuffer[cmdBufferLen++] =
' ';
1662 if (parametersLength > 0)
1664 cmdBuffer[cmdBufferLen++] =
' ';
1670 colab::addIntegerToBuffer<UINT16>(cmdBuffer, cmdBufferLen, methodeName.size());
1675 if (parametersLength > 0)
1678 memcpy(&cmdBuffer[cmdBufferLen], parameters, parametersLength);
1679 cmdBufferLen += parametersLength;
1695 printWarning(
"SopasBase::invokeMethod: Calling of " + methodeName +
" was NOT successful.");
1708 BYTE cmdBuffer[128];
1714 printError(
"SopasBase::invokeMethod: Invoke method cola-a by index not supported.");
1720 colab::addIntegerToBuffer<UINT16>(cmdBuffer, cmdBufferLen, index);
1724 if (parametersLength > 0)
1727 memcpy(&cmdBuffer[cmdBufferLen], parameters, parametersLength);
1728 cmdBufferLen += parametersLength;
1744 printWarning(
"SopasBase::invokeMethod: Calling of method with index=" + ::
toString(index) +
" was NOT successful.");
1757 BYTE cmdBuffer[128];
1763 cmdBuffer[cmdBufferLen++] =
' ';
1770 cmdBuffer[cmdBufferLen++] =
' ';
1786 printWarning(
"SopasBase::readVariable: Answer to " + variableName +
" not successful.");
1799 BYTE cmdBuffer[128];
1805 cmdBuffer[cmdBufferLen++] =
' ';
1811 colab::addIntegerToBuffer<UINT16>(cmdBuffer, cmdBufferLen, index);
1838 printInfoMessage(
"SopasBase::writeVariable: ReadOnly Modus - ignore writing to variable '" +
1844 BYTE cmdBuffer[128];
1850 cmdBuffer[cmdBufferLen++] =
' ';
1852 if (parametersLength > 0)
1854 cmdBuffer[cmdBufferLen++] =
' ';
1859 printError(
"SopasBase::writeVariable: Write variable cola-b by Name: NOT IMPLEMENTED");
1870 if (parametersLength > 0)
1873 memcpy(&cmdBuffer[cmdBufferLen], parameters, parametersLength);
1874 cmdBufferLen += parametersLength;
1912 printInfoMessage(
"SopasBase::writeVariable: ReadOnly Modus - ignore writing to variable index '" + ::
toString(variableIndex) +
1918 UINT32 cmdBufferLen = parametersLength + 4;
1919 BYTE* cmdBuffer =
new BYTE[cmdBufferLen];
1925 BYTE* buffer = &(cmdBuffer[2]);
1931 memcpy(&(cmdBuffer[4]), parameters, parametersLength);
1934 printInfoMessage(
"SopasBase::writeVariable: Sending command buffer now (payload len=" +
toString(parametersLength+4) +
" bytes).", beVerboseHere);
1937 printInfoMessage(
"SopasBase::writeVariable: Command sent, waiting for reply...", beVerboseHere);
1952 printWarning(
"SopasBase::writeVariable: Answer to " +
toString(variableIndex) +
" not successful!");
1955 printInfoMessage(
"SopasBase::writeVariable: All done, leaving.", beVerboseHere);
1963 BYTE cmdBuffer[128];
1969 cmdBuffer[cmdBufferLen++] =
' ';
1971 cmdBuffer[cmdBufferLen++] =
' ';
1972 cmdBuffer[cmdBufferLen++] =
'1';
1978 cmdBuffer[cmdBufferLen++] =
' ';
1980 cmdBuffer[cmdBufferLen++] =
' ';
1981 colab::addIntegerToBuffer<UINT8>(cmdBuffer, cmdBufferLen, 1);
2008 BYTE cmdBuffer[128];
2014 printError(
"SopasBase::register event cola-a by index not supported, aborting.");
2021 colab::addIntegerToBuffer<UINT16>(cmdBuffer, cmdBufferLen, index);
2022 colab::addIntegerToBuffer<UINT8>(cmdBuffer, cmdBufferLen, 1);
2046 printError(
"SopasBase::registerEvent: Calling of method with index=" + ::
toString(index) +
" was NOT successful.");
2056 BYTE cmdBuffer[128];
2062 printError(
"SopasBase::unregisterEvent: Unregister event cola-a by index not supported.");
2069 colab::addIntegerToBuffer<UINT16>(cmdBuffer, cmdBufferLen, index);
2070 colab::addIntegerToBuffer<UINT8>(cmdBuffer, cmdBufferLen, 0);
2104 BYTE cmdBuffer[128];
2110 cmdBuffer[cmdBufferLen++] =
' ';
2112 cmdBuffer[cmdBufferLen++] =
' ';
2113 cmdBuffer[cmdBufferLen++] =
'0';
2119 cmdBuffer[cmdBufferLen++] =
' ';
2121 cmdBuffer[cmdBufferLen++] =
' ';
2122 colab::addIntegerToBuffer<UINT8>(cmdBuffer, cmdBufferLen, 0);
2148 return ::normalizeRadians(
angle);
2164 m_buffer(buffer), m_protocol(protocol), m_frameLength(frameLength), m_encoding(
SopasBase::ByName)
2174 UINT32 payLoadLength = 0;
2185 return payLoadLength;
2192 std::string commandString;
2197 commandString = std::string((
char*) &
m_buffer[2], 2);
2200 commandString = std::string((
char*) &
m_buffer[9], 2);
2203 return commandString;
2214 BYTE* bufferPos = NULL;
2238 printWarning(
"SopasEventMessage::getVariableIndex: Encoding is not ByIndex, aborting!");
2252 printError(
"SopasEventMessage::getVariableIndex: Unknown protocol!");
2272 printError(
"SopasEventMessage::getVariableName: Protocol CoLa-A is not supported, aborting!");
2347 if (answerLength > 0)