Last active
April 9, 2016 01:09
-
-
Save summivox/324473f01de0b14dd2273ca7da7d795b to your computer and use it in GitHub Desktop.
AMTI MSR-6 interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env lsc | |
require! { | |
'serialport': {SerialPort} | |
} | |
say = console.~log | |
timeout = (t, f) -> setTimeout(f, t) | |
PORT = 'COM3' | |
s = new SerialPort PORT, baudrate: 57600 | |
err <- s.on 'open' | |
if err then throw err | |
say 'opened at 57600' | |
err <- s.write Buffer [0x52 0x53] | |
if err then throw err | |
say 'wrote 0x52 0x53 (stop, autozero)' | |
say 'idle wait for autozero' | |
<- timeout 1250 | |
say 'done' | |
err <- s.write Buffer [0x76] | |
if err then throw err | |
say 'wrote 0x76 (very high speed output)' | |
err <- s.close | |
if err then throw err | |
say 'closed 57600' | |
s = new SerialPort PORT, baudrate: 115200 | |
err <- s.on 'open' | |
if err then throw err | |
say 'opened at 115200' | |
err <- s.write Buffer [0x51] | |
if err then throw err | |
say 'wrote 0x51 (start streaming)' | |
err <- s.close | |
if err then throw err | |
say 'closed 115200' | |
say 'success' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ... */ | |
/* | |
* const int N = 6; // total number of channels | |
* const int K = 3; // lookahead window size (in readings) | |
* const int KK = 2*K; // ditto (in bytes) | |
* uint16_t* rptr; // points to read index of circular buffer | |
* uint16_t* wptr; // points to write index of circular buffer | |
* uint16_t fifosize; // size of circular buffer | |
* uint16_t fifocount = (*wptr - *rptr) % fifosize; // number of items currently in circular buffer | |
* int* data; // content of circular buffer | |
* uint16_t DPtr[N]; // output vector (decoded data) | |
*/ | |
found = 0; | |
for (i = 0 ; i + KK <= fifocount ; ++i, ++*rptr) { | |
found = 1; | |
for (j = 1 ; j < KK ; j += 2) { | |
uint8_T ch = ((uint8_T)data[(*rptr + j)%fifosize] & 0xF0) >> 4; | |
if (!(0 <= ch && ch < N)) { | |
found = 0; | |
break; | |
} | |
} | |
if (found) break; | |
} | |
if (!found) return; | |
for (j = 0 ; j < KK ; j += 2) { | |
uint8_T b0 = data[(*rptr + j) %fifosize]; | |
uint8_T b1 = data[(*rptr + j + 1)%fifosize]; | |
unsigned short val = b0 | ((b1 & 0x0F) << 8); | |
unsigned short ch = (b1 & 0xF0) >> 4; | |
DPtr[ch] = val; | |
} | |
*rptr = (*rptr + KK)%fifosize; | |
/* ... */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment