def _get_dir_msg(path_list, version): tlv_list = path2tlvs(path_list) if (version): tlv_list.append(TagTlv(tlv_types.VERSION, version)) im_name = TagName(tlv_list) msg = TagGet(im_name) return msg
def _file_record_msg(path_list): # / <node_id> / "tag" / "info" / "sens" / "gps" / "xyz" tlv_list = path2tlvs(path_list) tname = TagName(tlv_list) if get_cmd_args().verbosity > 3: mylog.debug(method=inspect.stack()[0][3], lineno=sys._getframe().f_lineno, name=tname) return TagGet(tname)
def _file_bytes_msg(path_list, amount_to_get, file_offset): # / <node_id> / "tag" / "sd" / 0 / devname / byte [/ fileno] tlv_list = path2tlvs(path_list) tlv_list.extend([ TagTlv(tlv_types.OFFSET, file_offset), TagTlv(tlv_types.SIZE, amount_to_get) ]) tname = TagName(tlv_list) # zzz print(tname) return TagGet(tname)
def _file_bytes_msg(path_list, amount_to_get, file_offset): # / <node_id> / "tag" / "sd" / 0 / blockname / byte [/ fileno] tlv_list = path2tlvs(path_list) tlv_list.extend([TagTlv(tlv_types.OFFSET, file_offset), TagTlv(tlv_types.SIZE, amount_to_get)]) tname = TagName(tlv_list) if get_cmd_args().verbosity > 2: mylog.debug(method=inspect.stack()[0][3], lineno=sys._getframe().f_lineno, name=tname) return TagGet(tname)
def radio_get_position(radio, node=None, name=None, power=None, wait=MAX_WAIT): gps_geo = None if not node: node = TagTlv(tlv_types.NODE_ID, -1) if not name: name = TagName([ node, TagTlv('tag'), TagTlv('info'), TagTlv('sens'), TagTlv('gps'), TagTlv('xyz') ]) xyz_struct = pystruct.Struct('<iii') get_gps_xyz = TagGet(name) if get_cmd_args().verbosity > 2: mylog.debug(method=inspect.stack()[0][3], lineno=sys._getframe().f_lineno, name=get_gps_xyz.name) req_msg = get_gps_xyz.build() error, payload, msg_meta = msg_exchange(radio, req_obj) rssi, sstatus, rstatus = msg_meta if (error is tlv_errors.SUCCESS): if payload: gps_xyz = payload2values(payload, [ tlv_types.GPS, ])[0] if get_cmd_args().verbosity > 2: mylog.debug(method=inspect.stack()[0][3], lineno=sys._getframe().f_lineno, data={ 'x': gps_xyz[0], 'y': gps_xyz[0], 'z': gps_xyz[0], }) lon, lat, elv = transform(ecef, wgs84, *gps_xyz) gps_geo = float(lat), float(lon), float(elv) if get_cmd_args().verbosity > 2: mylog.debug('home geolocation', method=inspect.stack()[0][3], lineno=sys._getframe().f_lineno, data={ 'latitude': gps_geo[0], 'longitude': gps_geo[1], 'elevation': gps_geo[0], }) return gps_xyz, gps_geo else: mylog.error('response error', method=inspect.stack()[0][3], error=error) else: mylog.error('timeout', method=inspect.stack()[0][3]) return None, None
def radio_get_rtctime(radio, node=None, name=None, power=None, wait=MAX_WAIT): if not node: node = TagTlv(tlv_types.NODE_ID, -1) if not name: name = TagName([node, TagTlv('tag'), TagTlv('sys'), TagTlv('rtc')]) req_obj = TagGet(name) if get_cmd_args().verbosity > 3: mylog.debug('*** radio_get_rtctime', method=inspect.stack()[0][3], lineno=sys._getframe().f_lineno, name=name) error, payload, msg_meta = msg_exchange(radio, req_obj) rssi, sstatus, rstatus = msg_meta if (error is tlv_errors.SUCCESS): if payload: tagtime = payload2values(payload, [ tlv_types.UTC_TIME, ])[0] return tagtime, rssi, sstatus, rstatus return None, None, sstatus, rstatus
def radio_get_power(radio, node=None, name=None, power=None, wait=MAX_WAIT): if not node: node = TagTlv(tlv_types.NODE_ID, -1) if not name: name = TagName( [node, TagTlv('tag'), TagTlv('.test'), TagTlv('tx_pwr')]) # zzz print('*** radio_get_power',name) req_obj = TagGet(name) req_msg = req_obj.build() error, payload, msg_meta = msg_exchange(radio, req_obj) rssi, sstatus, rstatus = msg_meta if (error is tlv_errors.SUCCESS): if payload: # zzz print('*** radio_get_power',payload) tag_power = payload2values(payload, [ tlv_types.INTEGER, ])[0] return tag_power, rssi, sstatus, rstatus return None, None, sstatus, rstatus
def radio_get_rssi(radio, node=None, name=None, power=None, wait=MAX_WAIT): if not node: node = TagTlv(tlv_types.NODE_ID, -1) if not name: name = TagName([node, TagTlv('tag'), TagTlv('.test'), TagTlv('rssi')]) req_obj = TagGet(name) req_msg = req_obj.build() error, payload, msg_meta = msg_exchange(radio, req_obj) rssi, sstatus, rstatus = msg_meta if (error is tlv_errors.SUCCESS): if payload: if get_cmd_args().verbosity > 3: mylog.debug('*** radio_get_rssi', method=inspect.stack()[0][3], lineno=sys._getframe().f_lineno, payload=payload) tag_rssi = payload2values(payload, [ tlv_types.INTEGER, ])[0] return tag_rssi, rssi, sstatus, rstatus return None, rssi, sstatus, rstatus return None, None, sstatus, rstatus
def _get_dir_msg(path_list): im_name = TagName(path2tlvs(path_list)) msg = TagGet(im_name) return msg
def radio_read_test(radio, test_name, pos, num, node=None, name=None, power=None, wait=MAX_WAIT): if not node: node = TagTlv(tlv_types.NODE_ID, -1) if not name: name = TagName([ node, TagTlv('tag'), TagTlv('.test'), TagTlv(test_name), TagTlv('byte'), TagTlv(tlv_types.OFFSET, pos), TagTlv(tlv_types.SIZE, num), ]) req_obj = TagGet(name) if get_cmd_args().verbosity > 2: mylog.debug(method=inspect.stack()[0][3], lineno=sys._getframe().f_lineno, name=req_obj.name) req_msg = req_obj.build() radio_send_msg(radio, req_msg, power) rsp_msg, rssi, status = radio_receive_msg(radio, MAX_RECV, wait) if rsp_msg: rsp_obj = TagMessage(rsp_msg) if get_cmd_args().verbosity > 2: mylog.debug(method=inspect.stack()[0][3], lineno=sys._getframe().f_lineno, error=rsp_obj.header.options.param.error_code, data=rsp_obj.payload.__repr__()) if rsp_obj.payload: error, offset, amt, block = payload2values(rsp_obj.payload, [ tlv_types.ERROR, tlv_types.OFFSET, tlv_types.SIZE, tlv_types.BLOCK, ]) seta = set(block) if (len(seta) > 1): mylog.error( 'check error', method=inspect.stack()[0][3], diff=seta, size=amt, ) amt = 0 return error, offset, amt, block else: mylog.error('timeout', method=inspect.stack()[0][3], error=rsp_obj.header.options.param.error_code) else: mylog.error( 'timeout', method=inspect.stack()[0][3], ) return None