def parse_hardware_data(topic, datatype, data, timestamp): """ Handles messages from the ROS network to do with hardware information in a threadsafe way. @param topic: The ROS topic name the message was received on @param datatype: The datatype of the message @param data: The data contained in the message @param timestamp: The timestamp of when the message was received """ global hwinfo, hwinfo_lock, hwinfo_json, hwinfo_json_lock if RosWeb._isCamera(topic): parse_camera(topic, datatype, data, timestamp) else: hwinfo_lock.acquire() if datatype_helpers.datatype_is_array(datatype): if topic.find("/hardware/vicon") != -1: name = data.data.split(" ")[0] if topic not in hwinfo.keys(): hwinfo[topic] = [] found = False for i in hwinfo[topic]: if i[-1] == name: hwinfoo[topic][i] = [topic, data.data, timestam, name] found = True if not found: hwinfo[topic].append([topic, data.data, timestam, name]) for i in range(0, len(data.data)): topic_itr = topic + "_%s" % i # Probably faster than checking key exists, right? try: if timestamp > hwinfo[topic_itr][2]: hwinfo[topic_itr] = [topic_itr, data.data[i], timestamp] except: hwinfo[topic_itr] = [topic_itr, data.data[i], timestamp] else: try: if timestamp > hwinfo[topic_itr][2]: hwinfo[topic] = [topic, data.data, timestamp] except: hwinfo[topic] = [topic, data.data, timestamp] hwinfo_lock.release() json_data = json.dumps(hwinfo.values()) hwinfo_json_lock.acquire() hwinfo_json = json_data hwinfo_json_lock.release()
def _parse_data(self, data, datatype): """ If data is a list, returns a string of CSV columns, otherwise encapsulates string in quotes. """ try: str(data.data) except: return if datatype_helpers.datatype_is_array(datatype): data_text = "" for i in data.data: data_text = data_text + '"%s",' % str(i).replace('"', '""') data_text = data_text[:-1] else: data_text = '"%s"' % str(data.data).replace('"', '""') return data_text