def file_truncate(radio, path_list, offset): def _truncate_msg(tname, offset): msg = TagPut(tname, pl=TagTlvList([(tlv_types.INTEGER, offset)])) return msg tname = TagName(path2tlvs(path_list)) req_msg = _truncate_msg(tname, offset) if get_cmd_args().verbosity > 2: mylog.debug(method=inspect.stack()[0][3], lineno=sys._getframe().f_lineno, name=req_msg.name, offset=offset) err, payload, msg_meta = msg_exchange(radio, req_msg) if (err == tlv_errors.SUCCESS): amtLeft = payload2values(payload, [tlv_types.SIZE, ])[0] if get_cmd_args().verbosity > 2: mylog.debug(method=inspect.stack()[0][3], lineno=sys._getframe().f_lineno, offset=amtLeft) return amtLeft mylog.error(method=inspect.stack()[0][3], lineno=sys._getframe().f_lineno, error=err) return -2
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 _put_msg(path_list, buf, offset=None): tlv_list = path2tlvs(path_list) if (offset): tlv_list.append(TagTlv(tlv_types.OFFSET, offset)) tname = TagName(tlv_list) msg = TagPut(tname) msg.payload = bytearray(buf[0:msg.payload_avail()]) return (msg, len(msg.payload))
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 _delete_msg(path_list): im_name = TagName(path2tlvs(path_list)) msg = TagDelete(im_name) return msg
def _close_msg(path_list): im_name = TagName(path2tlvs(path_list)) msg = TagPut(im_name, pl=[TagTlv(tlv_types.EOF)]) return msg
def _get_dir_msg(path_list): im_name = TagName(path2tlvs(path_list)) msg = TagGet(im_name) return msg
def dblk_put_note(radio, path_list, note): tname = TagName(path2tlvs(path_list)) return _put_bytes(radio, tname, note, 0)
def file_put_bytes(radio, path_list, buf, offset): tname = TagName(path2tlvs(path_list)) return _put_bytes(radio, tname, buf, offset)
def _file_attr_msg(path_list): tname = TagName(path2tlvs(path_list)) # zzz print('file update attrs', path_list, tname) return TagHead(tname)
def _file_attr_msg(path_list): tname = TagName(path2tlvs(path_list)) return TagHead(tname)
def _set_version_msg(path_list): tlv_list = path2tlvs(path_list[:-1]) tlv_list.append(TagTlv(tlv_types.VERSION, path_list[-1].split('.'))) req_obj = TagPut(TagName(tlv_list)) return req_obj
def _close_msg(path_list): im_name = TagName(path2tlvs(path_list)) im_name.append(TagTlv(tlv_types.OFFSET, offset)) msg = TagPut(im_name, pl=TagTlvList([TagTlv(tlv_types.EOF)])) return msg