untested but almost finished sketch of thalaic network and state machine code