Răsfoiți Sursa

Removed unused functions

jungervin 7 ani în urmă
părinte
comite
6965fd3a09

+ 0 - 17
EsPy/Lib/apa102.py

@@ -1,17 +0,0 @@
-# APA102 driver for MicroPython on ESP8266
-# MIT license; Copyright (c) 2016 Robert Foss, Daniel Busch
-
-from esp import apa102_write
-from neopixel import NeoPixel
-
-
-class APA102(NeoPixel):
-    ORDER = (0, 1, 2, 3)
-
-    def __init__(self, clock_pin, data_pin, n, bpp=4):
-        super().__init__(data_pin, n, bpp)
-        self.clock_pin = clock_pin
-        self.clock_pin.init(clock_pin.OUT)
-
-    def write(self):
-        apa102_write(self.clock_pin, self.pin, self.buf)

+ 0 - 25
EsPy/Lib/dht.py

@@ -1,25 +0,0 @@
-# DHT11/DHT22 driver for MicroPython on ESP8266
-# MIT license; Copyright (c) 2016 Damien P. George
-
-import esp
-
-class DHTBase:
-    def __init__(self, pin):
-        pass
-
-    def measure(self):
-        pass
-
-class DHT11(DHTBase):
-    def humidity(self):
-        pass
-
-    def temperature(self):
-        pass
-
-class DHT22(DHTBase):
-    def humidity(self):
-        pass
-
-    def temperature(self):
-        pass

+ 0 - 27
EsPy/Lib/ds18x20.py

@@ -1,27 +0,0 @@
-# DS18x20 temperature sensor driver for MicroPython.
-# MIT license; Copyright (c) 2016 Damien P. George
-
-from micropython import const
-
-_CONVERT = const(0x44)
-_RD_SCRATCH = const(0xbe)
-_WR_SCRATCH = const(0x4e)
-
-class DS18X20:
-    def __init__(self, onewire):
-        pass
-    
-    def scan(self):
-        pass
-
-    def convert_temp(self):
-        pass
-
-    def read_scratch(self, rom):
-        pass
-
-    def write_scratch(self, rom, buf):
-        pass
-
-    def read_temp(self, rom):
-        pass

+ 0 - 44
EsPy/Lib/flashbdev.py

@@ -1,44 +0,0 @@
-import esp
-
-class FlashBdev:
-
-    SEC_SIZE = 4096
-    START_SEC = esp.flash_user_start() // SEC_SIZE
-    NUM_BLK = 0x6b
-
-    def __init__(self, blocks=NUM_BLK):
-        pass
-
-    def readblocks(self, n, buf):
-        pass
-
-    def writeblocks(self, n, buf):
-        pass
-
-    def ioctl(self, op, arg):
-        pass
-
-def set_bl_flash_size(real_size):
-    pass
-
-# If bootloader size ID doesn't correspond to real Flash size,
-# fix bootloader value and reboot.
-size = esp.flash_id() >> 16
-# Check that it looks like realistic power of 2 for flash sizes
-# commonly used with esp8266
-if 22 >= size >= 18:
-    size = 1 << size
-    if size != esp.flash_size():
-        import machine
-        import time
-        print("Bootloader Flash size appear to have been set incorrectly, trying to fix")
-        set_bl_flash_size(size)
-        machine.reset()
-        while 1: time.sleep(1)
-
-size = esp.flash_size()
-if size < 1024*1024:
-    bdev = None
-else:
-    # 20K at the flash end is reserved for SDK params storage
-    bdev = FlashBdev((size - 20480) // FlashBdev.SEC_SIZE - FlashBdev.START_SEC)

+ 0 - 50
EsPy/Lib/inisetup.py

@@ -1,50 +0,0 @@
-import uos
-import network
-from flashbdev import bdev
-
-def wifi():
-    import ubinascii
-    ap_if = network.WLAN(network.AP_IF)
-    essid = b"MicroPython-%s" % ubinascii.hexlify(ap_if.config("mac")[-3:])
-    ap_if.config(essid=essid, authmode=network.AUTH_WPA_WPA2_PSK, password=b"micropythoN")
-
-def check_bootsec():
-    buf = bytearray(bdev.SEC_SIZE)
-    bdev.readblocks(0, buf)
-    empty = True
-    for b in buf:
-        if b != 0xff:
-            empty = False
-            break
-    if empty:
-        return True
-    fs_corrupted()
-
-def fs_corrupted():
-    import time
-    while 1:
-        print("""\
-FAT filesystem appears to be corrupted. If you had important data there, you
-may want to make a flash snapshot to try to recover it. Otherwise, perform
-factory reprogramming of MicroPython firmware (completely erase flash, followed
-by firmware programming).
-""")
-        time.sleep(3)
-
-def setup():
-    check_bootsec()
-    print("Performing initial setup")
-    wifi()
-    uos.VfsFat.mkfs(bdev)
-    vfs = uos.VfsFat(bdev, "")
-    with open("/boot.py", "w") as f:
-        f.write("""\
-# This file is executed on every boot (including wake-boot from deepsleep)
-#import esp
-#esp.osdebug(None)
-import gc
-#import webrepl
-#webrepl.start()
-gc.collect()
-""")
-    return vfs

+ 0 - 17
EsPy/Lib/machine.py

@@ -1,17 +0,0 @@
-class Pin():
-    #init', 'value', 'low', 'high', 'irq', 'IN', 'OUT', 'OPEN_DRAIN', 'PULL_UP', 'IRQ_RISING', 'IRQ_FALLING'
-
-    def __init__(self, pin_id):
-        pass
-
-    def value(self, value):
-        pass
-
-    def low(self):
-        pass
-
-    def high(self):
-        pass
-
-    def irq(self):
-        pass

+ 0 - 23
EsPy/Lib/neopixel.py

@@ -1,23 +0,0 @@
-# NeoPixel driver for MicroPython on ESP8266
-# MIT license; Copyright (c) 2016 Damien P. George
-
-from esp import neopixel_write
-
-
-class NeoPixel:
-    ORDER = (1, 0, 2, 3)
-
-    def __init__(self, pin, n, bpp=3):
-        pass
-
-    def __setitem__(self, index, val):
-        pass
-
-    def __getitem__(self, index):
-        pass
-
-    def fill(self, color):
-        pass
-
-    def write(self):
-        pass

+ 0 - 21
EsPy/Lib/ntptime.py

@@ -1,21 +0,0 @@
-try:
-    import usocket as socket
-except:
-    import socket
-try:
-    import ustruct as struct
-except:
-    import struct
-
-# (date(2000, 1, 1) - date(1900, 1, 1)).days * 24*60*60
-NTP_DELTA = 3155673600
-
-host = "pool.ntp.org"
-
-def time():
-    pass
-
-# There's currently no timezone support in MicroPython, so
-# utime.localtime() will return UTC time (as if it was .gmtime())
-def settime():
-    pass

+ 0 - 46
EsPy/Lib/onewire.py

@@ -1,46 +0,0 @@
-from micropython import const
-import _onewire as _ow
-
-class OneWireError(Exception):
-    pass
-
-class OneWire:
-    SEARCH_ROM = const(0xf0)
-    MATCH_ROM = const(0x55)
-    SKIP_ROM = const(0xcc)
-
-    def __init__(self, pin):
-        pass
-    
-    def reset(self, required=False):
-        pass
-
-    def readbit(self):
-        pass
-
-    def readbyte(self):
-        pass
-
-    def readinto(self, buf):
-        pass
-
-    def writebit(self, value):
-        pass
-
-    def writebyte(self, value):
-        pass
-
-    def write(self, buf):
-        pass
-
-    def select_rom(self, rom):
-        pass
-
-    def scan(self):
-        pass
-
-    def _search_rom(self, l_rom, diff):
-        pass
-
-    def crc8(self, data):
-        pass

+ 0 - 33
EsPy/Lib/port_diag.py

@@ -1,33 +0,0 @@
-import esp
-import uctypes
-import network
-import lwip
-
-
-def main():
-
-    ROM = uctypes.bytearray_at(0x40200000, 16)
-    fid = esp.flash_id()
-
-    print("FlashROM:")
-    print("Flash ID: %x (Vendor: %x Device: %x)" % (fid, fid & 0xff, fid & 0xff00 | fid >> 16))
-
-    print("Flash bootloader data:")
-    SZ_MAP = {0: "512KB", 1: "256KB", 2: "1MB", 3: "2MB", 4: "4MB"}
-    FREQ_MAP = {0: "40MHZ", 1: "26MHZ", 2: "20MHz", 0xf: "80MHz"}
-    print("Byte @2: %02x" % ROM[2])
-    print("Byte @3: %02x (Flash size: %s Flash freq: %s)" % (ROM[3], SZ_MAP.get(ROM[3] >> 4, "?"), FREQ_MAP.get(ROM[3] & 0xf)))
-    print("Firmware checksum:")
-    print(esp.check_fw())
-
-    print("\nNetworking:")
-    print("STA ifconfig:", network.WLAN(network.STA_IF).ifconfig())
-    print("AP ifconfig:", network.WLAN(network.AP_IF).ifconfig())
-    print("Free WiFi driver buffers of type:")
-    for i, comm in enumerate(("1,2 TX", "4 Mngmt TX(len: 0x41-0x100)", "5 Mngmt TX (len: 0-0x40)", "7", "8 RX")):
-        print("%d: %d (%s)" % (i, esp.esf_free_bufs(i), comm))
-    print("lwIP PCBs:")
-    lwip.print_pcbs()
-
-
-main()

+ 0 - 85
EsPy/Lib/ssd1306.py

@@ -1,85 +0,0 @@
-# MicroPython SSD1306 OLED driver, I2C and SPI interfaces
-
-from micropython import const
-import time
-import framebuf
-
-
-# register definitions
-SET_CONTRAST        = const(0x81)
-SET_ENTIRE_ON       = const(0xa4)
-SET_NORM_INV        = const(0xa6)
-SET_DISP            = const(0xae)
-SET_MEM_ADDR        = const(0x20)
-SET_COL_ADDR        = const(0x21)
-SET_PAGE_ADDR       = const(0x22)
-SET_DISP_START_LINE = const(0x40)
-SET_SEG_REMAP       = const(0xa0)
-SET_MUX_RATIO       = const(0xa8)
-SET_COM_OUT_DIR     = const(0xc0)
-SET_DISP_OFFSET     = const(0xd3)
-SET_COM_PIN_CFG     = const(0xda)
-SET_DISP_CLK_DIV    = const(0xd5)
-SET_PRECHARGE       = const(0xd9)
-SET_VCOM_DESEL      = const(0xdb)
-SET_CHARGE_PUMP     = const(0x8d)
-
-
-class SSD1306:
-    def __init__(self, width, height, external_vcc):
-        pass
-
-    def init_display(self):
-        pass
-
-    def poweroff(self):
-        pass
-
-    def contrast(self, contrast):
-        pass
-
-    def invert(self, invert):
-        pass
-
-    def show(self):
-        pass
-
-    def fill(self, col):
-        pass
-
-    def pixel(self, x, y, col):
-        pass
-
-    def scroll(self, dx, dy):
-        pass
-
-    def text(self, string, x, y, col=1):
-        pass
-
-
-class SSD1306_I2C(SSD1306):
-    def __init__(self, width, height, i2c, addr=0x3c, external_vcc=False):
-        pass
-
-    def write_cmd(self, cmd):
-        pass
-
-    def write_data(self, buf):
-        pass
-
-    def poweron(self):
-        pass
-
-
-class SSD1306_SPI(SSD1306):
-    def __init__(self, width, height, spi, dc, res, cs, external_vcc=False):
-        pass
-
-    def write_cmd(self, cmd):
-        pass
-
-    def write_data(self, buf):
-        pass
-
-    def poweron(self):
-        pass

+ 0 - 204
EsPy/Lib/umqtt/simple.py

@@ -1,204 +0,0 @@
-import usocket as socket
-import ustruct as struct
-from ubinascii import hexlify
-
-class MQTTException(Exception):
-    pass
-
-class MQTTClient:
-
-    def __init__(self, client_id, server, port=0, user=None, password=None, keepalive=0,
-                 ssl=False, ssl_params={}):
-        if port == 0:
-            port = 8883 if ssl else 1883
-        self.client_id = client_id
-        self.sock = None
-        self.server = server
-        self.port = port
-        self.ssl = ssl
-        self.ssl_params = ssl_params
-        self.pid = 0
-        self.cb = None
-        self.user = user
-        self.pswd = password
-        self.keepalive = keepalive
-        self.lw_topic = None
-        self.lw_msg = None
-        self.lw_qos = 0
-        self.lw_retain = False
-
-    def _send_str(self, s):
-        self.sock.write(struct.pack("!H", len(s)))
-        self.sock.write(s)
-
-    def _recv_len(self):
-        n = 0
-        sh = 0
-        while 1:
-            b = self.sock.read(1)[0]
-            n |= (b & 0x7f) << sh
-            if not b & 0x80:
-                return n
-            sh += 7
-
-    def set_callback(self, f):
-        self.cb = f
-
-    def set_last_will(self, topic, msg, retain=False, qos=0):
-        assert 0 <= qos <= 2
-        assert topic
-        self.lw_topic = topic
-        self.lw_msg = msg
-        self.lw_qos = qos
-        self.lw_retain = retain
-
-    def connect(self, clean_session=True):
-        self.sock = socket.socket()
-        addr = socket.getaddrinfo(self.server, self.port)[0][-1]
-        self.sock.connect(addr)
-        if self.ssl:
-            import ussl
-            self.sock = ussl.wrap_socket(self.sock, **self.ssl_params)
-        premsg = bytearray(b"\x10\0\0\0\0\0")
-        msg = bytearray(b"\x04MQTT\x04\x02\0\0")
-
-        sz = 10 + 2 + len(self.client_id)
-        msg[6] = clean_session << 1
-        if self.user is not None:
-            sz += 2 + len(self.user) + 2 + len(self.pswd)
-            msg[6] |= 0xC0
-        if self.keepalive:
-            assert self.keepalive < 65536
-            msg[7] |= self.keepalive >> 8
-            msg[8] |= self.keepalive & 0x00FF
-        if self.lw_topic:
-            sz += 2 + len(self.lw_topic) + 2 + len(self.lw_msg)
-            msg[6] |= 0x4 | (self.lw_qos & 0x1) << 3 | (self.lw_qos & 0x2) << 3
-            msg[6] |= self.lw_retain << 5
-
-        i = 1
-        while sz > 0x7f:
-            premsg[i] = (sz & 0x7f) | 0x80
-            sz >>= 7
-            i += 1
-        premsg[i] = sz
-
-        self.sock.write(premsg, i + 2)
-        self.sock.write(msg)
-        #print(hex(len(msg)), hexlify(msg, ":"))
-        self._send_str(self.client_id)
-        if self.lw_topic:
-            self._send_str(self.lw_topic)
-            self._send_str(self.lw_msg)
-        if self.user is not None:
-            self._send_str(self.user)
-            self._send_str(self.pswd)
-        resp = self.sock.read(4)
-        assert resp[0] == 0x20 and resp[1] == 0x02
-        if resp[3] != 0:
-            raise MQTTException(resp[3])
-        return resp[2] & 1
-
-    def disconnect(self):
-        self.sock.write(b"\xe0\0")
-        self.sock.close()
-
-    def ping(self):
-        self.sock.write(b"\xc0\0")
-
-    def publish(self, topic, msg, retain=False, qos=0):
-        pkt = bytearray(b"\x30\0\0\0")
-        pkt[0] |= qos << 1 | retain
-        sz = 2 + len(topic) + len(msg)
-        if qos > 0:
-            sz += 2
-        assert sz < 2097152
-        i = 1
-        while sz > 0x7f:
-            pkt[i] = (sz & 0x7f) | 0x80
-            sz >>= 7
-            i += 1
-        pkt[i] = sz
-        #print(hex(len(pkt)), hexlify(pkt, ":"))
-        self.sock.write(pkt, i + 1)
-        self._send_str(topic)
-        if qos > 0:
-            self.pid += 1
-            pid = self.pid
-            struct.pack_into("!H", pkt, 0, pid)
-            self.sock.write(pkt, 2)
-        self.sock.write(msg)
-        if qos == 1:
-            while 1:
-                op = self.wait_msg()
-                if op == 0x40:
-                    sz = self.sock.read(1)
-                    assert sz == b"\x02"
-                    rcv_pid = self.sock.read(2)
-                    rcv_pid = rcv_pid[0] << 8 | rcv_pid[1]
-                    if pid == rcv_pid:
-                        return
-        elif qos == 2:
-            assert 0
-
-    def subscribe(self, topic, qos=0):
-        assert self.cb is not None, "Subscribe callback is not set"
-        pkt = bytearray(b"\x82\0\0\0")
-        self.pid += 1
-        struct.pack_into("!BH", pkt, 1, 2 + 2 + len(topic) + 1, self.pid)
-        #print(hex(len(pkt)), hexlify(pkt, ":"))
-        self.sock.write(pkt)
-        self._send_str(topic)
-        self.sock.write(qos.to_bytes(1, "little"))
-        while 1:
-            op = self.wait_msg()
-            if op == 0x90:
-                resp = self.sock.read(4)
-                #print(resp)
-                assert resp[1] == pkt[2] and resp[2] == pkt[3]
-                if resp[3] == 0x80:
-                    raise MQTTException(resp[3])
-                return
-
-    # Wait for a single incoming MQTT message and process it.
-    # Subscribed messages are delivered to a callback previously
-    # set by .set_callback() method. Other (internal) MQTT
-    # messages processed internally.
-    def wait_msg(self):
-        res = self.sock.read(1)
-        self.sock.setblocking(True)
-        if res is None:
-            return None
-        if res == b"":
-            raise OSError(-1)
-        if res == b"\xd0":  # PINGRESP
-            sz = self.sock.read(1)[0]
-            assert sz == 0
-            return None
-        op = res[0]
-        if op & 0xf0 != 0x30:
-            return op
-        sz = self._recv_len()
-        topic_len = self.sock.read(2)
-        topic_len = (topic_len[0] << 8) | topic_len[1]
-        topic = self.sock.read(topic_len)
-        sz -= topic_len + 2
-        if op & 6:
-            pid = self.sock.read(2)
-            pid = pid[0] << 8 | pid[1]
-            sz -= 2
-        msg = self.sock.read(sz)
-        self.cb(topic, msg)
-        if op & 6 == 2:
-            pkt = bytearray(b"\x40\x02\0\0")
-            struct.pack_into("!H", pkt, 2, pid)
-            self.sock.write(pkt)
-        elif op & 6 == 4:
-            assert 0
-
-    # Checks whether a pending message from server is available.
-    # If not, returns immediately with None. Otherwise, does
-    # the same processing as wait_msg.
-    def check_msg(self):
-        self.sock.setblocking(False)
-        return self.wait_msg()

+ 0 - 1
EsPy/Lib/upip.py

@@ -1 +0,0 @@
-../../tools/upip.py

+ 0 - 1
EsPy/Lib/upip_utarfile.py

@@ -1 +0,0 @@
-../../tools/upip_utarfile.py

+ 0 - 77
EsPy/Lib/webrepl.py

@@ -1,77 +0,0 @@
-# This module should be imported from REPL, not run from command line.
-import socket
-import uos
-import network
-import websocket
-import websocket_helper
-import _webrepl
-
-listen_s = None
-client_s = None
-
-def setup_conn(port, accept_handler):
-    global listen_s
-    listen_s = socket.socket()
-    listen_s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-
-    ai = socket.getaddrinfo("0.0.0.0", port)
-    addr = ai[0][4]
-
-    listen_s.bind(addr)
-    listen_s.listen(1)
-    if accept_handler:
-        listen_s.setsockopt(socket.SOL_SOCKET, 20, accept_handler)
-    for i in (network.AP_IF, network.STA_IF):
-        iface = network.WLAN(i)
-        if iface.active():
-            print("WebREPL daemon started on ws://%s:%d" % (iface.ifconfig()[0], port))
-    return listen_s
-
-
-def accept_conn(listen_sock):
-    global client_s
-    cl, remote_addr = listen_sock.accept()
-    if uos.dupterm():
-        print("\nConcurrent WebREPL connection from", remote_addr, "rejected")
-        cl.close()
-        return
-    print("\nWebREPL connection from:", remote_addr)
-    client_s = cl
-    websocket_helper.server_handshake(cl)
-    ws = websocket.websocket(cl, True)
-    ws = _webrepl._webrepl(ws)
-    cl.setblocking(False)
-    # notify REPL on socket incoming data
-    cl.setsockopt(socket.SOL_SOCKET, 20, uos.dupterm_notify)
-    uos.dupterm(ws)
-
-
-def stop():
-    global listen_s, client_s
-    uos.dupterm(None)
-    if client_s:
-        client_s.close()
-    if listen_s:
-        listen_s.close()
-
-
-def start(port=8266, password=None):
-    stop()
-    if password is None:
-        try:
-            import webrepl_cfg
-            _webrepl.password(webrepl_cfg.PASS)
-            setup_conn(port, accept_conn)
-            print("Started webrepl in normal mode")
-        except:
-            print("WebREPL is not configured, run 'import webrepl_setup'")
-    else:
-        _webrepl.password(password)
-        setup_conn(port, accept_conn)
-        print("Started webrepl in manual override mode")
-
-
-def start_foreground(port=8266):
-    stop()
-    s = setup_conn(port, None)
-    accept_conn(s)

+ 0 - 111
EsPy/Lib/webrepl_setup.py

@@ -1,111 +0,0 @@
-import sys
-#import uos as os
-import os
-import machine
-
-RC = "./boot.py"
-CONFIG = "./webrepl_cfg.py"
-
-def input_choice(prompt, choices):
-    while 1:
-        resp = input(prompt)
-        if resp in choices:
-            return resp
-
-def getpass(prompt):
-    return input(prompt)
-
-def input_pass():
-    while 1:
-        passwd1 = getpass("New password: ")
-        if len(passwd1) < 4:
-            print("Password too short")
-            continue
-        elif len(passwd1) > 9:
-            print("Password too long")
-            continue
-        passwd2 = getpass("Confirm password: ")
-        if passwd1 == passwd2:
-            return passwd1
-        print("Passwords do not match")
-
-
-def exists(fname):
-    try:
-        with open(fname):
-            pass
-        return True
-    except OSError:
-        return False
-
-def copy_stream(s_in, s_out):
-    buf = bytearray(64)
-    while 1:
-        sz = s_in.readinto(buf)
-        s_out.write(buf, sz)
-
-
-def get_daemon_status():
-    with open(RC) as f:
-        for l in f:
-            if "webrepl" in l:
-                if l.startswith("#"):
-                    return False
-                return True
-        return None
-
-def add_daemon():
-    with open(RC) as old_f, open(RC + ".tmp", "w") as new_f:
-        new_f.write("import webrepl\nwebrepl.start()\n")
-        copy_stream(old_f, new_f)
-
-def change_daemon(action):
-    LINES = ("import webrepl", "webrepl.start()")
-    with open(RC) as old_f, open(RC + ".tmp", "w") as new_f:
-        for l in old_f:
-            for patt in LINES:
-                if patt in l:
-                    if action and l.startswith("#"):
-                        l = l[1:]
-                    elif not action and not l.startswith("#"):
-                        l = "#" + l
-            new_f.write(l)
-    # FatFs rename() is not POSIX compliant, will raise OSError if
-    # dest file exists.
-    os.remove(RC)
-    os.rename(RC + ".tmp", RC)
-
-
-def main():
-    status = get_daemon_status()
-
-    print("WebREPL daemon auto-start status:", "enabled" if status else "disabled")
-    print("\nWould you like to (E)nable or (D)isable it running on boot?")
-    print("(Empty line to quit)")
-    resp = input("> ").upper()
-
-    if resp == "E":
-        if exists(CONFIG):
-            resp2 = input_choice("Would you like to change WebREPL password? (y/n) ", ("y", "n", ""))
-        else:
-            print("To enable WebREPL, you must set password for it")
-            resp2 = "y"
-
-        if resp2 == "y":
-            passwd = input_pass()
-            with open(CONFIG, "w") as f:
-                f.write("PASS = %r\n" % passwd)
-
-
-    if resp not in ("D", "E") or (resp == "D" and not status) or (resp == "E" and status):
-        print("No further action required")
-        sys.exit()
-
-    change_daemon(resp == "E")
-
-    print("Changes will be activated after reboot")
-    resp = input_choice("Would you like to reboot now? (y/n) ", ("y", "n", ""))
-    if resp == "y":
-        machine.reset()
-
-main()

+ 0 - 74
EsPy/Lib/websocket_helper.py

@@ -1,74 +0,0 @@
-import sys
-try:
-    import ubinascii as binascii
-except:
-    import binascii
-try:
-    import uhashlib as hashlib
-except:
-    import hashlib
-
-DEBUG = 0
-
-def server_handshake(sock):
-    clr = sock.makefile("rwb", 0)
-    l = clr.readline()
-    #sys.stdout.write(repr(l))
-
-    webkey = None
-
-    while 1:
-        l = clr.readline()
-        if not l:
-            raise OSError("EOF in headers")
-        if l == b"\r\n":
-            break
-    #    sys.stdout.write(l)
-        h, v = [x.strip() for x in l.split(b":", 1)]
-        if DEBUG:
-            print((h, v))
-        if h == b'Sec-WebSocket-Key':
-            webkey = v
-
-    if not webkey:
-        raise OSError("Not a websocket request")
-
-    if DEBUG:
-        print("Sec-WebSocket-Key:", webkey, len(webkey))
-
-    d = hashlib.sha1(webkey)
-    d.update(b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11")
-    respkey = d.digest()
-    respkey = binascii.b2a_base64(respkey)[:-1]
-    if DEBUG:
-        print("respkey:", respkey)
-
-    sock.send(b"""\
-HTTP/1.1 101 Switching Protocols\r
-Upgrade: websocket\r
-Connection: Upgrade\r
-Sec-WebSocket-Accept: """)
-    sock.send(respkey)
-    sock.send("\r\n\r\n")
-
-
-# Very simplified client handshake, works for MicroPython's
-# websocket server implementation, but probably not for other
-# servers.
-def client_handshake(sock):
-    cl = sock.makefile("rwb", 0)
-    cl.write(b"""\
-GET / HTTP/1.1\r
-Host: echo.websocket.org\r
-Connection: Upgrade\r
-Upgrade: websocket\r
-Sec-WebSocket-Key: foo\r
-\r
-""")
-    l = cl.readline()
-#    print(l)
-    while 1:
-        l = cl.readline()
-        if l == b"\r\n":
-            break
-#        sys.stdout.write(l)

+ 0 - 14
EsPy/Python/IText.cs

@@ -1,14 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EsPy.Python
-{
-    public interface IText
-    {
-        string Text
-        { get; }
-    }
-}

+ 0 - 39
EsPy/Python/Jedi/BaseDefinition.cs

@@ -1,39 +0,0 @@
-using EsPy.Components;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EsPy.Python.Jedi
-{
-    public class BaseDefinition : ExListBox.ExListBoxItem
-    {
-        public int ImageIndex = 1;
-        public string module_path = null;
-        public string name = null;
-        public string type = null;
-        public string module_name = null;
-        public string in_builtin_module = null;
-        public string line = null;
-        public string column = null;
-        public string doc = null;
-        public string docstring = null;
-        public string description = null;
-        public string full_name = null;
-        public string[] parameters = null;
-
-        public virtual string Text
-        {
-            get
-            {
-                return name;
-            }
-        }
-
-        public override string ToString()
-        {
-            return this.name ?? "no suggestion";
-        }
-    }
-}

+ 0 - 15
EsPy/Python/Jedi/CallSignature.cs

@@ -1,15 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EsPy.Python.Jedi
-{
-    public class CallSignature : BaseDefinition
-    {
-        public string index = null;
-        public string bracket_start = null;
-
-    }
-}

+ 0 - 14
EsPy/Python/Jedi/Completion.cs

@@ -1,14 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EsPy.Python.Jedi
-{ 
-    public class Completion : BaseDefinition
-    {
-        public string complete = "";
-        public string name_with_symbols = "";    
-    }
-}

+ 0 - 15
EsPy/Python/Jedi/CompletionRequest.cs

@@ -1,15 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EsPy.Python.Jedi
-{
-    public class CompletionRequest : Request
-    {
-        
-        public CompletionRequest(Script script) : base("completion", script)
-        { }
-    }
-}

+ 0 - 13
EsPy/Python/Jedi/DefinedNames.cs

@@ -1,13 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EsPy.Python.Jedi
-{
-    public class DefinedNames
-    {
-        public List<Definition> Definitions = null;
-    }
-}

+ 0 - 23
EsPy/Python/Jedi/Definition.cs

@@ -1,23 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EsPy.Python.Jedi
-{
-    public class Definition : BaseDefinition
-    {
-        public string desc_with_module = null;
-        public DefinedNames defined_names = null;
-        public bool? is_definition = null;
-
-        public string Text
-        {
-            get
-            {
-                return name;
-            }
-        }
-    }
-}

+ 0 - 17
EsPy/Python/Jedi/Request.cs

@@ -1,17 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EsPy.Python.Jedi
-{
-    public class Request : PyRequest
-    {
-        public Script Script = null;
-        public Request(string method, Script script) : base("jedi", method)
-        {
-            this.Script = script;
-        }
-    }
-}

+ 0 - 22
EsPy/Python/Jedi/Script.cs

@@ -1,22 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EsPy.Python.Jedi
-{
-    public class Script
-    {
-        public int Line = 0;
-        public int Column = 0;
-        public string Source = "";
-
-        public Script(string source, int line, int column) 
-        {
-            this.Source = source;
-            this.Line = line;
-            this.Column = column;
-        }
-    }
-}

+ 0 - 16
EsPy/Python/Jedi/SignaturesRequest.cs

@@ -1,16 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EsPy.Python.Jedi
-{
-    public class SignaturesRequest : Request
-    {
-        public SignaturesRequest(Script script) : base("signature", script)
-        {
-
-        }
-    }
-}

+ 0 - 209
EsPy/Python/PyClient.cs

@@ -1,209 +0,0 @@
-using EsPy.Utility;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Linq;
-using System.Net;
-using System.Net.Sockets;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace EsPy.Python
-{
-    public class PyClient
-    {
-        private TcpClient Client = null;
-        private Process Process = null;
-        public PyClient(IPAddress address, int port)
-        {
-            this.Address = address;
-            this.Port = port;
-        }
-
-        private IPAddress Address
-        { get; set; }
-
-        private int Port
-        { get; set; }
-
-
-        private string ScriptPath
-        { get { return Path.Combine(Application.StartupPath, "Scripts", "PyHost.py"); } }
-
-        public bool Start()
-        {
-            if (File.Exists(this.ScriptPath))
-            {
-                System.Diagnostics.ProcessStartInfo inf = new System.Diagnostics.ProcessStartInfo(
-                 "python", this.ScriptPath);
-
-                inf.UseShellExecute = false;
-#if DEBUG
-                inf.CreateNoWindow = false;
-#else
-                inf.CreateNoWindow = true;
-#endif
-                this.Process = new System.Diagnostics.Process();
-                this.Process.StartInfo = inf;
-                try
-                {
-                    this.Process.Start();
-                    Thread.Sleep(1000);
-                    
-                    int p = 10;
-                    while (p-- > 0)
-                    {
-                        Thread.Sleep(1000);
-                        try
-                        {
-                            JToken res = Globals.PyClient.DoRequest<JToken>("jedi", "hello");
-                            if (res != null)
-                            {
-                                return true;
-                            }
-                        }
-                        catch
-                        { }
-                    }
-                    return p > 0;
-                }
-                catch (Exception ex)
-                {
-                    Console.WriteLine(ex.Message);
-                }
-            }
-            return false;
-        }
-
-        public void Stop()
-        {
-            try
-            {
-                try
-                {
-                    if (this.Client != null)
-                    {
-                        JToken res = this.DoRequest<JToken>("jedi", "bye");
-                        //if (res != null)
-                        this.Client.Close();
-                        this.Client.Dispose();
-                    }
-                }
-                catch (Exception e)
-                {
-                    Helpers.ErrorBox(e);
-                }
-
-                if (this.Process != null)
-                {
-                    this.Process.Close();
-                    this.Process.Dispose();
-                }
-            }
-            catch (Exception ee)
-            {
-                Helpers.ErrorBox(ee);
-            }
-
-        }
-
-        private void Connect()
-        {
-            try
-            {
-                if (this.Client == null)
-                {
-                    this.Client = new TcpClient();
-                    // Todo: test size
-                    //this.Client.ReceiveBufferSize = 1024;
-                    this.Client.ReceiveTimeout = 3000;
-                    this.Client.SendTimeout = 3000;
-                    this.Client.Connect(this.Address, this.Port);
-                }
-            }
-            catch (Exception ex)
-            {
-                this.Client = null;
-                Globals.PyClient = null;
-                Helpers.ErrorBox(ex);
-            }
-        }
-
-
-        byte[] InpBuffer = new byte[8192];
-        const int MAX_WAIT = 10;
-
-        private string DoRequest(string text)
-        {
-            this.Connect();
-
-            if (this.Client != null && this.Client.Connected)
-            {
-
-                NetworkStream ns = this.Client.GetStream();
-                byte[] buff = Encoding.UTF8.GetBytes(text);
-                ns.Write(BitConverter.GetBytes(buff.Length), 0, sizeof(Int32));
-                ns.Write(buff, 0, buff.Length);
-
-                byte[] rec = new byte[4];
-                ns.Read(rec, 0, sizeof(Int32));
-                int len = BitConverter.ToInt32(rec, 0);
-
-                if (len > this.InpBuffer.Length)
-                {
-                    Array.Resize(ref this.InpBuffer, len);
-                }
-                //byte[] inb = new byte[len];
-
-                //while (this.Client.Available < len)
-                //{
-                //    Thread.Sleep(10);
-                //}
-
-                int count = 0;
-                int p = MAX_WAIT;
-                while (count < len)
-                {
-
-                    if (this.Client.Available == 0)
-                    {
-                        Thread.Sleep(10);
-                        if (p-- <= 0)
-                        {
-                            throw new TimeoutException("MAX_WAIT Timeout!");
-                        }
-                    }
-                    else
-                    {
-                        count += ns.Read(this.InpBuffer, count, this.Client.Available);
-                        p = MAX_WAIT;
-                    }
-                }
-
-                //Console.WriteLine($"SOCKET: {count}/{len}");          
-
-                return System.Text.Encoding.UTF8.GetString(this.InpBuffer, 0, len);
-            }
-
-            return "";
-        }
-
-        public T DoRequest<T>(PyRequest req)
-        {
-            string json = JsonConvert.SerializeObject(req);
-            string res = Globals.PyClient.DoRequest(json);
-            return JsonConvert.DeserializeObject<T>(res);
-        }
-
-        public T DoRequest<T>(string module, string method)
-        {
-            PyRequest req = new PyRequest(module, method);
-            return DoRequest<T>(req);
-        }
-    }
-}

+ 0 - 19
EsPy/Python/PyRequest.cs

@@ -1,19 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EsPy.Python
-{
-    public class PyRequest
-    {
-        public string Module = "";
-        public string Method = "";
-        public PyRequest(string module, string method)
-        {
-            this.Module = module;
-            this.Method = method;
-        }
-    }
-}

+ 0 - 18
EsPy/Python/Pylint/PylintRequest.cs

@@ -1,18 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace EsPy.Python.Pylint
-{
-    public class PylintRequest 
-    {
-        public string Module = "pylint";
-        public string File = ""
-        public PylintRequest(string file)
-        {
-            this.File = file;
-        }
-    }
-}

+ 0 - 119
EsPy/Scripts/PyHost.py

@@ -1,119 +0,0 @@
-import socket
-
-TCP_IP = '127.0.0.1'
-TCP_PORT = 5005
-
-s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-s.bind((TCP_IP, TCP_PORT))
-s.listen(1)
-conn, addr = s.accept()
-print 'Connection address:', addr
-
-from struct import *
-import json
-import jedi
-import sys
-import os
-
-jedi.settings.no_completion_duplicates = True
-jedi.settings.use_filesystem_cache = True
-
-print(os.path.dirname(os.path.realpath(__file__)))
-lib = os.path.dirname(os.path.realpath(__file__)) + '\..\Lib'
-sys.path = []
-sys.path.append(lib)
-modules = []
-modules.append(lib + "\machine.py")
-modules.append(lib + "\onewire.py")
-modules.append(lib + "\umqtt\simple.py")
-#jedi.preload_module(modules)
-print(sys.path)
-print(modules)
-
-class Proc(object):
-    def __init__(self, j):
-        self.__dict__ = json.loads(j)
-         
-def serialize_completions(completions):
-    items = []
-    params ={}
-    try:
-        for completion in completions:
-            #print(dir(item))
-            if completion.module_name == '__builtin__':
-                continue
-            #print(completion.module_path)
-
-            params = []
-            if hasattr(completion, 'params'):
-                for p in completion.params:
-                    params.append(p.name)
-
-            item = {
-                #'column': completion.column,
-                'name': completion.name, 
-                'complete': completion.complete, 
-                #'description': completion.description,
-                #'doc': completion.doc,
-                #'docstring': completion.docstring(False), 
-                ## #'follow_definition': item.follow_definition(), 
-                #'full_name': completion.full_name, 
-                ## #'goto_assignments': item.goto_assignments(), 
-                ## 'in_builtin_module': completion.in_builtin_module, 
-                'is_keyword': completion.is_keyword, 
-                ##'line': completion.line, 
-                #'module_name': completion.module_name, 
-                #'module_path': completion.module_path, 
-                #'name_with_symbols': completion.name_with_symbols, 
-                ##'parameters': params, #completion.params, 
-                ##'parent': completion.parent, 
-                ##'raw_doc': completion.raw_doc, 
-                ##'start_pos': completion.start_pos,
-                #'type': completion.type
-            }
-            items.append(item)
-        return json.dumps({'completions': items})
-    except Exception as e:
-        print("EXCEPTION: ", e)
-        return "ERR"
-
-
-while 1:
-    data = conn.recv(4)
-    dlen = unpack('i', data)
-    data = ""
-
-    while len(data) < dlen[0]:
-        data += conn.recv(dlen[0])
-
-    obj = Proc(data)           
-    result = 'No suggestion';
-    print "MODULE: " + obj.Module
-    print "METHOD: " + obj.Method
-  
-    if obj.Module == 'jedi':
-        if obj.Method == 'completion':
-                script = jedi.Script(obj.Script['Source'], obj.Script['Line'], obj.Script['Column']) 
-                comp = script.completions()
-                print(comp)
-                result = serialize_completions(comp)
-        elif obj.Method == "hello":
-            result = json.dumps({"respose": "hello"})
-        elif obj.Method == "bye":
-            print("bye")
-            conn.close()
-            #input("Press Enter to continue...")
-            sys.exit()
-            #result = json.dumps({"respose": "bye"})
-            break
-
-    # response
-    dlen = len(result)
-    conn.send(pack('i', dlen))
-    n = conn.send(result)
-    result = ""
-    print("LEN: ", dlen, "SENT: ", n)
-
-conn.close()
-#input("Press Enter to continue...")
-sys.exit()