Skip to content

Commit

Permalink
Add the TCP/IP port in the curl calls
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanscherzinger committed Jul 10, 2024
1 parent 70409aa commit 9116e12
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion schunk_egu_egk_gripper_dummy/src/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def process_get(self, path: str, query: dict[str, list[str]]) -> dict | list | N
print(f"query: {query}")

if path == "info.json":
return {}
return {"dataformat": 0} # 0: Little endian, 1: Big endian
if path == "enum.json":
return []
if path == "data.json":
Expand Down
2 changes: 1 addition & 1 deletion schunk_egu_egk_gripper_dummy/tests/test_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_dummy_responds_correctly_to_info_requests():
dummy = Dummy()
path = "info.json"
query = ""
expected = {}
expected = {"dataformat": 0}
assert dummy.process_get(path, query) == expected


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class AnybusCom
void initAddresses();

std::string ip; //IP to the connected gripper
int port = 80; //TCP/IP Port of the gripper

uint8_t endian_format; //Flag for big/little Endian
bool not_double_word; //Flag if double word is requested (double words are always big Endian)
Expand Down Expand Up @@ -266,6 +267,7 @@ inline void AnybusCom::getWithInstance(const char inst[7], paramtype *param, con
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1L);
curl_easy_setopt(curl, CURLOPT_PORT, port);
res = curl_easy_perform(curl);

if (res != CURLE_OK)
Expand Down Expand Up @@ -302,6 +304,7 @@ inline void AnybusCom::getWithOffset(const std::string &offset, const size_t & c
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION, writeCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1);
curl_easy_setopt(curl, CURLOPT_PORT, port);

res = curl_easy_perform(curl);

Expand Down
21 changes: 7 additions & 14 deletions schunk_egu_egk_gripper_library/src/communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ size_t writeCallback(void* contents, size_t size, size_t nmemb, void* userp)
}

//Initialize the plcs and Addresses
AnybusCom::AnybusCom(const std::string &ip, int port) : ip(ip)
AnybusCom::AnybusCom(const std::string &ip, int port) : ip(ip), port(port)
{
initAddresses(); // for post and get
curl = curl_easy_init();
Expand Down Expand Up @@ -172,20 +172,12 @@ void AnybusCom::postParameter(std::string inst, std::string value)
//Inits used Addresses with the ip
void AnybusCom::initAddresses()
{
data_address = "http:///adi/data.json?";
update_address = "http:///adi/update.json";
enum_address = "http:///adi/enum.json?";
info_address = "http:///adi/info.json";
metadata_address = "http:///adi/metadata.json?";

if(ip.size() >= 100) ip = "0.0.0.0";

data_address.insert(7, ip);
update_address.insert(7, ip);
enum_address.insert(7,ip);
info_address.insert(7,ip);
metadata_address.insert(7,ip);

data_address = "http://" + ip + ":" + std::to_string(port) + "/adi/data.json?";
update_address = "http://" + ip + ":" + std::to_string(port) + "/adi/update.json";
enum_address = "http://" + ip + ":" + std::to_string(port) + "/adi/enum.json?";
info_address = "http://" + ip + ":" + std::to_string(port) + "/adi/info.json";
metadata_address = "http://" + ip + ":" + std::to_string(port) + "/adi/metadata.json?";
}

//Translates the received string of double_word to an integer[4] an saves it in plc_sync_input
Expand Down Expand Up @@ -271,6 +263,7 @@ void AnybusCom::getEnums(const char inst[7], const uint16_t &enumNum)
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1L);
curl_easy_setopt(curl, CURLOPT_PORT, port);

res = curl_easy_perform(curl);

Expand Down

0 comments on commit 9116e12

Please sign in to comment.