commit d7d286556e3291aa90154d8cf1747e02c9817f65 Author: Nis Wechselberg Date: Mon Nov 20 21:06:56 2017 +0100 Initial dump diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5dd4928 --- /dev/null +++ b/.gitignore @@ -0,0 +1,74 @@ +###SublimeText### + +# cache files for sublime text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# workspace files are user-specific +*.sublime-workspace + +# project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using SublimeText +# *.sublime-project + +# sftp configuration file +sftp-config.json + + +###Python### + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ diff --git a/pyNetworkWS2812.py b/pyNetworkWS2812.py new file mode 100644 index 0000000..1eff19f --- /dev/null +++ b/pyNetworkWS2812.py @@ -0,0 +1,56 @@ +import os.path +import serial +import time +import random +import logging + + +port_addr = '/dev/ttyACM0' + +logging.warning("Staring up") + +if os.path.exists(port_addr): + port = serial.Serial( + port=port_addr, + baudrate=115200, + bytesize=serial.EIGHTBITS, + parity=serial.PARITY_NONE, + stopbits=serial.STOPBITS_ONE, + timeout=1, + xonxoff=False, + rtscts=False, + dsrdtr=False, + write_timeout=None, + inter_byte_timeout=None) + + logging.warning("Opening port") + + time.sleep(2) + + logging.warning("Opened port") + + val1 = random.randint(0,100) + val2 = random.randint(0,100) + + logging.warning("Staring with values %d and %d", val1, val2) + + while True: + val1 += random.randint(-10,10) + val2 += random.randint(-10,10) + if val1 < 0: + val1 = 0 + if val1 > 100: + val1 = 100 + if val2 < 0: + val2 = 0 + if val2 > 100: + val2 = 100 + + message = bytearray(3) + message[0] = 0xFF + message[1] = val1 + message[2] = val2 + + port.write(message) + + time.sleep(0.01) diff --git a/pyNetworkWS2812.sublime-project b/pyNetworkWS2812.sublime-project new file mode 100644 index 0000000..24db303 --- /dev/null +++ b/pyNetworkWS2812.sublime-project @@ -0,0 +1,8 @@ +{ + "folders": + [ + { + "path": "." + } + ] +} diff --git a/test.py b/test.py new file mode 100644 index 0000000..5a00bf8 --- /dev/null +++ b/test.py @@ -0,0 +1,50 @@ +import re +import time + + +# A regular expression which separates the interesting fields and saves them in named groups +regexp = r""" + \s* # a interface line starts with none, one or more whitespaces + (?P\w+):\s+ # the name of the interface followed by a colon and spaces + (?P\d+)\s+ # the number of received bytes and one or more whitespaces + (?P\d+)\s+ # the number of received packets and one or more whitespaces + (?P\d+)\s+ # the number of receive errors and one or more whitespaces + (?P\d+)\s+ # the number of dropped rx packets and ... + (?P\d+)\s+ # rx fifo + (?P\d+)\s+ # rx frame + (?P\d+)\s+ # rx compressed + (?P\d+)\s+ # rx multicast + (?P\d+)\s+ # the number of transmitted bytes and one or more whitespaces + (?P\d+)\s+ # the number of transmitted packets and one or more whitespaces + (?P\d+)\s+ # the number of transmit errors and one or more whitespaces + (?P\d+)\s+ # the number of dropped tx packets and ... + (?P\d+)\s+ # tx fifo + (?P\d+)\s+ # tx frame + (?P\d+)\s+ # tx compressed + (?P\d+)\s* # tx multicast +""" + + +pattern = re.compile(regexp, re.VERBOSE) + + +def get_bytes(interface_name): + '''returns tuple of (rx_bytes, tx_bytes) ''' + with open('/proc/net/dev', 'r') as f: + a = f.readline() + while(a): + m = pattern.search(a) + # the regexp matched + # look for the needed interface and return the rx_bytes and tx_bytes + if m: + if m.group('interface') == interface_name: + return (m.group('rx_bytes'),m.group('tx_bytes')) + a = f.readline() + + +while True: + last_time = time.time() + last_bytes = get_bytes('wlxa4db303b745e') + time.sleep(1) + now_bytes = get_bytes('wlxa4db303b745e') + print("rx: {} B/s, tx {} B/s".format(int(now_bytes[0]) - int(last_bytes[0]), int(now_bytes[1]) - int(last_bytes[1])))