Editing
DreamTeam/pastebin
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
<code> [[File:fftsim.txt]] [[File:Foo.txt]] [[File:Mindwave reader alpha.txt]] asynchronous serial stream of bytes 3 parts header payload checksum transport medium UART serial comm USB bluetooth and any mechanism which can stream bytes packet begins with header then payload ends with payloads's checksum byte payload section may be up to 169 bytes long each of sync, plength, and checksum are 1 byte each header consists of 2 syncs and 1 plength bytes so, possible packet sync sync plength (1+1+1) payload (169) checksum (1) so minumum 4 (? empty payload) maximum 173 header 2 sync bytes signal beginning of new packet 0xaa issue of 2 sync "special 0xaa" appear in data therefore plength and checksum are necessary to avoid in-band signal/data ambiguity mis-parsing plength == payload length not packet length so if larger than 169 then error can be 0 payload don't parse until verify checksum checksum sum bytes take lowest 8 bits perform bit inverse payload is series of data rows data row format: value type there can be 0 or more data rows each data row begins with 0 or more Extended Code Flag Byte (0x55) Extended Code Level (not yet implemented) given by ECFB count 1 Code bytes (which will never by 0x55/ECFB or 0xaa/sync) 0 or 1 VLength bytes (signalled by Code <= 0x7f) 1 or more Value bytes <= 0x7f "single-byte code" 0x02 POOR_SIGNAL 0x04 ATTENTION 0x05 MEDITATION 0x16 BLINK EVENT unsigned 2s-complement >= 0x80 "multi-byte code" 0x80 RAW Wave Value single 16-bit [https://en.wikipedia.org/wiki/Two%27s_complement 2s-complement] signed [https://en.wikipedia.org/wiki/Endianness big-endian] (-32768 to 32767) 0x83 ASIC_EEG_POWER 8 24-bit 2s-complement unsigned big-endian (0 to 16,777,216) " ............... sync_flag_count = 0 valid_plength = False valid_payload = False plength = -1 have_checksum = False payload_byte_count = 0 buffer_size = 256 payload_buffer = byte_array(buffer_size) while (stream) get abyte if sync_flag_count < 2 if abyte not sync (trace out-of-sync value, sync_flag_count) sync_flag_count = 0 continue increment sync_flag_count if sync_flag_count < 2 continue (trace successful sync) if not valid_plength plength = abyte valid_plength = test_plength(plength) (value from 0 to 170) if not valid_plength (trace not valid_plength) plength = -1 continue (trace valid_plength) if not have_checksum checksum = abyte have_checksum = True (trace checksum) continue if payload_byte_count < plength payload_buffer.append(abyte) increment payload_byte_count trace(payload_buffer, payload_byte_count) continue if payload_byte_count > plength valid_payload = False (trace serious logic error) break valid_payload = test_payload(payload, plength, checksum) if valid_payload (trace valid_payload) parse_payload(payload_buffer) else (trace not valid_payload) reset_flags(plength, checksum, etc) </code> <code> state progression: need_socket receiving_signal - loop need_first_sync need_second_sync need_plength need_checksum need_payload need_paysum - loop payload_remaining need_datarow need_codelevel need_codetype need_vlength need_val valid_data - valid_packet - </code>
Summary:
Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Noisebridge:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Request account
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Dig in!
Noisebridge
- Status: MOVED
- Donate
- ABOUT
- Accessibility
- Vision
- Blog
Manual
MANUAL
Visitors
Participation
Community Standards
Channels
Operations
Events
EVENTS
Guilds
GUILDS
- Meta
- Electronics
- Fabrication
- Games
- Music
- Library
- Neuro
- Philosophy
- Funding
- Art
- Crypto
- Documentation/Wiki
Wiki
Recent Changes
Random Page
Help
Categories
(Edit)
Tools
What links here
Related changes
Special pages
Page information