Skip to content

Instantly share code, notes, and snippets.

View nbuchwitz's full-sized avatar
🐧
hi there

Nicolai nbuchwitz

🐧
hi there
View GitHub Profile
@nbuchwitz
nbuchwitz / burst.py
Created October 21, 2026 20:37
macb missed TX completion reproducer (raspberrypi/linux#7661)
#!/usr/bin/env python3
# send one burst of N bytes, then sample BQL inflight until it drains, report drain time
import socket, sys, time
host, size, reps, gap = sys.argv[1], int(sys.argv[2]), int(sys.argv[3]), float(sys.argv[4])
INF = "/sys/class/net/eth0/queues/tx-0/byte_queue_limits/inflight"
def inflight():
with open(INF) as f: return int(f.read())
s = socket.create_connection((host, 9000))
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
time.sleep(0.5)
#!/usr/bin/env python3
import argparse
import random
import subprocess
import sys
import can
verbose = False
#!/bin/bash
rpi_revision_code() {
# see https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#new-style-revision-codes
code=$(grep Revision /proc/cpuinfo | cut -f 2 -d \: | xargs)
echo $((16#${code}))
}
rpi_type() {
#!/bin/bash
set -e
nm_files="dhcp-eth0.nmconnection dhcp-eth1.nmconnection fallback-link-local-eth0.nmconnection fallback-link-local-eth1.nmconnection 99-revpi.conf"
download_dir=$(mktemp -d)
echo -n "This script will change the network configuration from dhcpcd to NetworkManager. Do you want to proceed? [yN] "
read choice
#!/bin/bash
if [[ $(id -u) != 0 ]]; then
echo "usage: sudo $(basename $0)"
exit 1
fi
pibridge_static_mac() {
interface=$1
#!/bin/bash
VENDOR_ID=2109
PRODUCT_ID=2817
# find all devices which match our product id
for f in $(grep --include='idProduct' -rlw "$PRODUCT_ID" /sys/bus/usb/devices/usb* 2>/dev/null); do
device=$(dirname $f)
# ensure that vendor id also matches
@nbuchwitz
nbuchwitz / copy_modbus_to_gateway.py
Created March 11, 2022 12:59
RevPi: Copy data from virtual modbus registers to gateway component
#!/usr/bin/env python3
import revpimodio2
def loop_function(ct):
# copy 5 input register from modbus to gateway
rpi.io.Gateway_Output_Word_1.value = rpi.io.Input_Word_1.value
rpi.io.Gateway_Output_Word_2.value = rpi.io.Input_Word_2.value
rpi.io.Gateway_Output_Word_3.value = rpi.io.Input_Word_3.value
rpi.io.Gateway_Output_Word_4.value = rpi.io.Input_Word_4.value
import os
import revpimodio2
class Application():
def __init__(self):
self.rpi = revpimodio2.RevPiModIO(autorefresh=True)
self.rpi.handlesignalend(self.cleanup_revpi)
self.rpi.core.x2in.reg_event(self.event_shutdown, edge=revpimodio2.RISING)
#!/usr/bin/env python3
import sys
import json
import argparse
import os.path
DEFAULT_CONFIG_NEW = "/var/www/revpi/pictory/projects/_config.rsc"
DEFAULT_CONFIG_OLD = "/var/www/pictory/projects/_config.rsc"
import revpimodio2
def ev(name, value):
# payload is bytes, so we need to know the enconding (eg. ascii, utf-8, etc...)
print(name, value.decode('ascii'))
rpi = revpimodio2.RevPiModIO(autorefresh=True, monitoring=True)
rpi.handlesignalend()
# define IO: change length of string in the frm argument