""" PTP/IP class for MicroPython @author Markus Birth """ # PTP/IP abstract: http://www.cipa.jp/ptp-ip/index_e.html # PTP packet structure: http://www.gphoto.org/doc/ptpip.php # and https://github.com/gphoto/libgphoto2/blob/master/camlibs/ptp2/PTPIP.TXT # PTP example implementation in JavaScript: https://github.com/feklee/ptp.js # PTP response codes: http://www.javased.com/?source_dir=cameraptp/src/main/java/ste/ptp/Response.java import binascii import socket import struct class PTPIP: def __init__(self, ipadr): self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.connect((ipadr, 15740)) self.socket.setblocking(1) # wait for answer def createPkg(self, pktype, payload): pklen = len(payload) + 8 pkg = struct.pack(' 0xdfff: u8text += chr(char16) else: # 2-word-char print("Encoded UTF-16. Please improve this method.") print("UTF- 8: %s" % u8text) return u8text # see http://www.ietf.org/rfc/rfc2781.txt def utf8to16(self, u8text): u16text = b'' for i in range(0, len(u8text)): char8 = u8text[i] if ord(char8)<0x10000: u16text += struct.pack(' 0: args.append(struct.unpack('