Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. (define (hackrf-start-rx ctx d stream-processor)
  2. (let ([ctlin (second ctx)]
  3. [ctlout (third ctx)]
  4. [r (fourth ctx)])
  5. (displayln
  6. (string-append "startrx " d) ctlin)
  7. (flush-output ctlin)
  8. (sleep 0.1)
  9. (let ([line (read-line ctlout)])
  10. (if (not (equal? line "creating stream"))
  11. (raise line)
  12. (let ([dataout (open-input-file
  13. (string-append "/tmp/hackrfkern-"
  14. r
  15. "/dataout-"
  16. d))])
  17. (thread
  18. (lambda ()
  19. (letrec ([loop (lambda ()
  20. (if (eof-object? (peek-byte dataout))
  21. (void)
  22. (let* ([line (read-line dataout)]
  23. [tokens (string-split line)])
  24. (if (or (not (= (length tokens) 3))
  25. (not (string=? (car tokens) "rx")))
  26. (raise (string-append "bad prefix in RX stream: " line))
  27. (stream-processor dataout (string->number (third tokens))))
  28. (loop))))])
  29. (loop)))))))))
  30.  
  31. (define (sp-to-file path)
  32. (let* ([out (open-output-file path)]
  33. [buffer-size 100000]
  34. [buffer (make-bytes buffer-size)])
  35. (lambda (in nbytes)
  36. (if (> nbytes buffer-size)
  37. (begin
  38. (set! buffer-size nbytes)
  39. (set! buffer (make-bytes buffer-size)))
  40. (void))
  41. (read-bytes! buffer in 0 nbytes)
  42. (write-bytes buffer out 0 nbytes))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement