0 | module Bindings.RtlSdr.Buffer
2 | import public Bindings.RtlSdr.Raw.Buffer
3 | import Bindings.RtlSdr.Device
4 | import Bindings.RtlSdr.Error
5 | import Bindings.RtlSdr.Raw.Support
23 | a == b = (iVal a, qVal a) == (iVal b, qVal b)
24 | a /= b = not (a == b)
28 | MkIQ a b + MkIQ a' b' = MkIQ (a+a') (b+b')
29 | MkIQ a b * MkIQ a' b' = MkIQ (a*a' + b*b') (a*b' + b*a')
30 | fromInteger x = MkIQ (cast x) 0
33 | scaleIQ : Bits8 -> Int16
34 | scaleIQ v = (cast {to = Int16} v) - 128
36 | toIQ : Bits8 -> Bits8 -> IQ
37 | toIQ i q = MkIQ (scaleIQ i) (scaleIQ q)
39 | toIQList : List Bits8 -> List IQ
42 | toIQList (xs::ys::rest) = (toIQ xs ys) :: toIQList rest
49 | readSync : Ptr RtlSdrHandle -> Buffer -> IO (Either RTLSDR_ERROR Int)
52 | v <- prim__castPtr <$> malloc 4
53 | r <- fromPrim $
read_sync h b l v
55 | free $
prim__forgetPtr v
56 | io_pure $
if r == 0 then Right nr else Left RtlSdrError
61 | ReadAsyncFn = AnyPtr -> List IQ -> IO ()
75 | readAsync : Ptr RtlSdrHandle -> ReadAsyncFn -> AnyPtr -> Int -> Int -> IO (Either RTLSDR_ERROR ())
76 | readAsync h cbIO ctx bn bl = do
77 | let cbPrim = \bufPtr, bufLen, ctxPtr => toPrim $
78 | cbIO ctxPtr =<< ((io_pure . toIQList) =<< readBufPtr' bufPtr bufLen)
79 | r <- fromPrim $
read_async h cbPrim ctx bn bl
80 | io_pure $
if r == 0 then Right () else Left RtlSdrError
86 | cancelAsync : Ptr RtlSdrHandle -> IO (Either RTLSDR_ERROR ())
88 | r <- fromPrim $
cancel_async h
89 | io_pure $
if r == 0 then Right () else Left RtlSdrError
97 | resetBuffer : Ptr RtlSdrHandle -> IO (Either RTLSDR_ERROR ())
99 | r <- fromPrim $
reset_buffer h
100 | io_pure $
if r == 0 then Right () else Left RtlSdrError