Skip to content

Commit

Permalink
enforce unique ids
Browse files Browse the repository at this point in the history
  • Loading branch information
ClemensElflein committed Jul 25, 2024
1 parent ff88b92 commit c8d2368
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion codegen/templates/ServiceInterfaceTemplate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ServiceTemplateInterfaceBase : public xbot::serviceif::ServiceInterfaceBas


private:
void OnData(const std::string &uid, uint64_t timestamp, uint16_t target_id, const void *payload, size_t buflen);
void OnData(const std::string &uid, uint64_t timestamp, uint16_t target_id, const void *payload, size_t buflen) final;
void OnServiceConnected(const std::string &uid) override;
void OnTransactionStart(uint64_t timestamp) override;
void OnTransactionEnd() override;
Expand Down
11 changes: 11 additions & 0 deletions codegen/xbot_codegen/xbot_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def binary2c_array(data):
def toCamelCase(name):
return ''.join(x for x in name if not x.isspace())

def check_unique_ids(l):
id_set = set()
for dict in l:
id = dict['id']
if id in id_set:
raise Exception("Duplicate ID found: {}".format(id))
else:
id_set.add(id)

def loadService(path: str) -> dict:
# Fetch the service definition
Expand All @@ -54,6 +62,9 @@ def loadService(path: str) -> dict:
# Transform the input definitions
additional_includes = []
inputs = []
check_unique_ids(json_service["inputs"])
check_unique_ids(json_service["outputs"])
check_unique_ids(json_service["registers"])
for json_input in json_service["inputs"]:
# Convert to valid C++ function name
input_name = toCamelCase(json_input['name'])
Expand Down

0 comments on commit c8d2368

Please sign in to comment.