Initial dump
This commit is contained in:
commit
d7d286556e
4 changed files with 188 additions and 0 deletions
74
.gitignore
vendored
Normal file
74
.gitignore
vendored
Normal file
|
@ -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/
|
56
pyNetworkWS2812.py
Normal file
56
pyNetworkWS2812.py
Normal file
|
@ -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)
|
8
pyNetworkWS2812.sublime-project
Normal file
8
pyNetworkWS2812.sublime-project
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"folders":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
50
test.py
Normal file
50
test.py
Normal file
|
@ -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<interface>\w+):\s+ # the name of the interface followed by a colon and spaces
|
||||||
|
(?P<rx_bytes>\d+)\s+ # the number of received bytes and one or more whitespaces
|
||||||
|
(?P<rx_packets>\d+)\s+ # the number of received packets and one or more whitespaces
|
||||||
|
(?P<rx_errors>\d+)\s+ # the number of receive errors and one or more whitespaces
|
||||||
|
(?P<rx_drop>\d+)\s+ # the number of dropped rx packets and ...
|
||||||
|
(?P<rx_fifo>\d+)\s+ # rx fifo
|
||||||
|
(?P<rx_frame>\d+)\s+ # rx frame
|
||||||
|
(?P<rx_compr>\d+)\s+ # rx compressed
|
||||||
|
(?P<rx_multicast>\d+)\s+ # rx multicast
|
||||||
|
(?P<tx_bytes>\d+)\s+ # the number of transmitted bytes and one or more whitespaces
|
||||||
|
(?P<tx_packets>\d+)\s+ # the number of transmitted packets and one or more whitespaces
|
||||||
|
(?P<tx_errors>\d+)\s+ # the number of transmit errors and one or more whitespaces
|
||||||
|
(?P<tx_drop>\d+)\s+ # the number of dropped tx packets and ...
|
||||||
|
(?P<tx_fifo>\d+)\s+ # tx fifo
|
||||||
|
(?P<tx_frame>\d+)\s+ # tx frame
|
||||||
|
(?P<tx_compr>\d+)\s+ # tx compressed
|
||||||
|
(?P<tx_multicast>\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])))
|
Loading…
Reference in a new issue