Commit 5d8dde8b authored by nickolay.kovalev's avatar nickolay.kovalev
Browse files

error handling after testing

parent 5440e07d
......@@ -98,8 +98,8 @@ int main(void)
switch(input[0])
{
case CONNECT:
std::cerr << "CONNECTO clause "<< input+1 << std::endl;
std::cerr.flush();
//std::cerr << "CONNECTO clause "<< input+1 << std::endl;
//std::cerr.flush();
retval = UA_Client_connect(client, input+1); /* Connects to server */
*output = (retval != UA_STATUSCODE_GOOD) ? NOT_OK : OK;
......@@ -112,8 +112,8 @@ int main(void)
std::cout.flush();
break;
case DISCONNECT:
std::cerr << "DISCONNECT clause " << std::endl;
std::cerr.flush();
//std::cerr << "DISCONNECT clause " << std::endl;
//std::cerr.flush();
UA_Client_delete(client); /* Disconnects the client internally */
*output = OK;
writePacketLength(std::cout, 1);
......@@ -123,9 +123,9 @@ int main(void)
case READ_NODE:
parseIdentity(input+1, &nmSpace, &nodeid);
std::cerr << "input: " << input << std::endl;
std::cerr << "READ_NODE: " << nmSpace << ":" << nodeid << std::endl;
std::cerr.flush();
//std::cerr << "input: " << input << std::endl;
//std::cerr << "READ_NODE: " << nmSpace << ":" << nodeid << std::endl;
//std::cerr.flush();
if(nmSpace >= 0){
nodeId = UA_NODEID_NUMERIC(nmSpace, nodeid);
......@@ -155,17 +155,24 @@ int main(void)
len = error_resp.size();
}
std::cerr << "read_response: " << output << std::endl;
std::cerr << "read_response_len: " << len << std::endl;
std::cerr.flush();
//std::cerr << "read_response: " << output << std::endl;
//std::cerr << "read_response_len: " << len << std::endl;
//std::cerr.flush();
writePacketLength(std::cout, len);
std::cout.write(output, len);
std::cout.flush();
break;
default:
std::cerr << "Unknown clause";
std::cerr.flush();
//std::cerr << "Unknown clause";
//std::cerr.flush();
std::string error_resp = "error|Uknown request";
error_resp.copy(output, error_resp.size(), 0);
len = error_resp.size();
writePacketLength(std::cout, len);
std::cout.write(output, len);
std::cout.flush();
break;
}
......@@ -278,16 +285,13 @@ void parseType(UA_Variant *value, char *destination, uint32_t *len){
*len = float_resp.size();
}
/* String type */
/*
else if(UA_Variant_hasScalarType(value, &UA_TYPES[UA_TYPES_STRING])) {
UA_String string = *(UA_String *) value->data;
char *
std::string str(*(char *) string.data, string.data + string.length());
std::string string_resp = "string|" + str;
string_resp.copy(destination, string_resp.size(), 0);
*len = string_resp.size();
UA_String string_val = *(UA_String *) value->data;
std::string str_resp(reinterpret_cast<char*>(string_val.data));
std::string resp = "string|" + str_resp;
resp.copy(destination, resp.size(), 0);
*len = resp.size();
}
*/
//TODO more datatypes if needed
else {
std::string error_resp = "error|Unknown value type";
......@@ -302,7 +306,8 @@ void parseIdentity(const char *input, int32_t *nmSpace, uint32_t *nodeId){
std::size_t found = identity.find(delimiter);
if (found != std::string::npos)
{
std::string name_string(identity, 0, found-1);
//std::cerr << "parseIdentity.found: " << found << std::endl;
std::string name_string(identity, 0, found);
std::string node_string(identity, found+1, identity.size()-found-1);
//std::cerr << "parseIdentity.name_string: " << name_string.c_str() << std::endl;
//std::cerr << "parseIdentity.node_string: " << node_string.c_str() << std::endl;
......
......@@ -100,10 +100,13 @@ sync_read(Port, Data) when is_binary(Data) ->
{Port, {data, <<"int|", Value/binary>>}} ->
{integer, erlang:binary_to_integer(Value)};
{Port, {data, <<"float|", Value/binary>>}} ->
Float = string:to_float(erlang:binary_to_list(Value)),
{float, Float};
{float, convert_to_float(Value)};
{Port, {data, <<"string|", Value/binary>>}} ->
{string, Value};
{Port, {data, <<"bool|true">>}} ->
{boolean, true};
{Port, {data, <<"bool|false">>}} ->
{boolean, false};
{Port, {exit_status, Status}} ->
{exit, Status};
Anything ->
......@@ -111,3 +114,16 @@ sync_read(Port, Data) when is_binary(Data) ->
after ?PORT_SYNC_MS ->
{error, timeout}
end.
convert_to_float(Value) when is_binary(Value) ->
try erlang:binary_to_float(Value) of
Float ->
Float
catch _:_:_ ->
try erlang:binary_to_integer(Value) of
Int ->
erlang:float(Int)
catch _:_:_ ->
bad_value
end
end.
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment