Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Fixed small naming Issue with generated JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
iml-dlux committed Dec 10, 2018
1 parent 51d5bfe commit 36e1e7e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
3 changes: 1 addition & 2 deletions scripts/include/pubsub/contextbroker/cbPublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _publish(context_id, datatype, attributes, connection, sendCommand=True):
# \param entity attributes
# \param context broker to send to

## Explicitly ignore the rosmsg which is posted!firef
## Explicitly ignore the rosmsg which is posted!
if context_id is "rosmsg":
return

Expand Down Expand Up @@ -120,7 +120,6 @@ def _publish(context_id, datatype, attributes, connection, sendCommand=True):
url = "http://{}:{}/v1/updateContext".format(connection["ADDRESS"], connection["PORT"])
data_json = json.dumps(data)


try:
# TODO TODO DL change to v2/ID/attrs or other NGSIv2 APIs, so native JSON TYpes can be supported.
# Currently NGSIv1 is used and 'stringifies' every native json-Type into a String. Errors can occur by Back-Conversion
Expand Down
23 changes: 19 additions & 4 deletions scripts/include/ros/topicHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def loadMsgHandlers(robot_data):
Log("INFO", "\n")
CloudSubscriber.subscribe(robotName, DEFAULT_CONTEXT_TYPE, ROBOT_TOPICS[robotName])
Log("INFO", "Subscribed to " + robotName + "'s topics\n")
CloudPublisher.publishMsg(msg_types.values())
# CloudPublisher.publishMsg(msg_types.values()) ### --> This sends the rosmsg TODO DL method only used here!
MapHandler.mapPublisher()


Expand Down Expand Up @@ -191,13 +191,14 @@ def _callback(data, args):
datatype = ROBOT_TOPICS[robot]["subscriber"][topic]["msg"]
contextType = DEFAULT_CONTEXT_TYPE

# dataType of topic
# Setting firostimestamp
tempData = ros2Obj(data)
tempData['firosstamp'] = time.time()
# tempData.__class__.__name__ = datatype # We just assume it is an object of dataType
dtc = DataTypeClass(datatype, tempData)
# Creating Python-Specific JSON of the data (TODO add metadata exact types!)
tempData = ObjectFiwareConverter.obj2Fiware(tempData, ind=0, dataTypeDict=topic_DataTypeDefinition[datatype], ignorePythonMetaData=True)
# Back Conversion to JSON-conform-Object (no data-loss), because this Project still treats it like an Object
tempData = ObjectFiwareConverter.obj2Fiware(dtc, ind=0, dataTypeDict=topic_DataTypeDefinition[datatype], ignorePythonMetaData=True)

tempData = json.loads(tempData)

content = [{
Expand All @@ -208,6 +209,20 @@ def _callback(data, args):
CloudPublisher.publish(robot, contextType, content)




class DataTypeClass(object):
## Explicitly set __name__ to the DataType!
# Also set all keys in dict as your own variables
def __init__(self, datatype_str, in_dict):
self.__class__.__name__ = datatype_str
self.__name__ = datatype_str
for k,v in in_dict.iteritems():
setattr(self, k, v)




def robotDisconnection(data):
## \brief Handle robot diconnection
# \param robot data dict (name)
Expand Down

0 comments on commit 36e1e7e

Please sign in to comment.