hlibBladeRF 0.1.0.4 → 0.1.0.5
raw patch · 9 files changed
+56/−38 lines, 9 files
Files
- ChangeLog +10/−0
- hlibBladeRF.cabal +2/−2
- src/LibBladeRF/Flash.hs +2/−2
- src/LibBladeRF/Frequency.hs +3/−3
- src/LibBladeRF/Gain.hs +6/−6
- src/LibBladeRF/Gpio.hs +1/−1
- src/LibBladeRF/LibBladeRF.hs +7/−3
- src/LibBladeRF/Sync.hs +22/−18
- src/LibBladeRF/Utils.hs +3/−3
ChangeLog view
@@ -1,3 +1,13 @@+Changes in 0.1.0.5++* Provide 'BladeRFReturnType' type-alias and replace 'Either BladeRFError a'+ with 'BladeRFReturnType a'. For brevity and clarity, use a type-alias to+ wrap the Either error or result context in the return type of the+ bindings various IO actions.+* Sync.hs: Handle bladerf_sync_{t,r}x return err codes. Deal with possible+ return error codes from the C functions, wrapping them in the+ Either context mapped to the 'BladeRFError' type.+ Changes in 0.1.0.4 * No need to explicitly pass #. of samples to bladeRFSyncTx
hlibBladeRF.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: hlibBladeRF-version: 0.1.0.4+version: 0.1.0.5 synopsis: Haskell binding to libBladeRF SDR library description: IO Monadic binding for libbladeRF software defined radio. homepage: https://victoredwardocallaghan.github.io/hlibBladeRF@@ -77,4 +77,4 @@ type: git location: git://github.com/victoredwardocallaghan/hlibBladeRF branch: master- tag: v0.1.0.4+ tag: v0.1.0.5
src/LibBladeRF/Flash.hs view
@@ -31,7 +31,7 @@ bladeRFEraseFlash :: DeviceHandle -- ^ Device handle -> Word32 -- ^ Erase block to start erasing at -> Word32 -- ^ Number of blocks to erase.- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFEraseFlash dev b n = do ret <- c'bladerf_erase_flash (unDeviceHandle dev) b n return $ bladeRFErrorTy ret@@ -53,7 +53,7 @@ -> BS.ByteString -- ^ Data to write to flash -> Word32 -- ^ page Page to begin writing at -> Word32 -- ^ count- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFWriteFlash dev b p c = allocaBytes (fromIntegral $ p * c'BLADERF_FLASH_PAGE_SIZE) $ \bptr -> do -- XXX - Buffer allocation size must be `page` * BLADERF_FLASH_PAGE_SIZE bytes or larger. pokeArray bptr (BS.unpack b) -- XXX can we overflow here??
src/LibBladeRF/Frequency.hs view
@@ -28,7 +28,7 @@ -- | Write value to VCTCXO DAC. bladeRFDACWrite :: DeviceHandle -- ^ Device handle -> Word16 -- ^ Data to write to DAC register- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFDACWrite dev v = do ret <- c'bladerf_dac_write (unDeviceHandle dev) v return $ bladeRFErrorTy ret@@ -47,7 +47,7 @@ bladeRFSetFrequency :: DeviceHandle -- ^ Device handle -> BladeRFModule -- ^ Module to configure -> Int -- ^ Desired frequency- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFSetFrequency dev m f = do ret <- c'bladerf_set_frequency (unDeviceHandle dev) ((fromIntegral . fromEnum) m) (fromIntegral f) return $ bladeRFErrorTy ret@@ -66,7 +66,7 @@ -> BladeRFModule -- ^ Module to apply correction to -> BladeRFCorrection -- ^ Correction type -> Word16 -- ^ Value to apply- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFSetCorrection dev m c v = do ret <- c'bladerf_set_correction (unDeviceHandle dev) ((fromIntegral . fromEnum) m) ((fromIntegral . fromEnum) c) v return $ bladeRFErrorTy ret
src/LibBladeRF/Gain.hs view
@@ -40,7 +40,7 @@ -- | Set the PA gain in dB. bladeRFSetTXVGA2 :: DeviceHandle -- ^ Device handle -> Int -- ^ Desired gain- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFSetTXVGA2 dev g = do ret <- c'bladerf_set_txvga2 (unDeviceHandle dev) (fromIntegral g) return $ bladeRFErrorTy ret@@ -57,7 +57,7 @@ -- | Set the post-LPF gain in dB. bladeRFSetTXVGA1 :: DeviceHandle -- ^ Device handle -> BladeRFVGAGainBounds -- ^ Desired gain- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFSetTXVGA1 dev g = do ret <- c'bladerf_set_txvga1 (unDeviceHandle dev) ((fromIntegral . fromEnum) g) return $ bladeRFErrorTy ret@@ -74,7 +74,7 @@ -- | Set the post-LPF VGA gain. bladeRFSetRXVGA2 :: DeviceHandle -- ^ Device handle -> BladeRFVGAGainBounds -- ^ Desired gain- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFSetRXVGA2 dev g = do ret <- c'bladerf_set_rxvga2 (unDeviceHandle dev) ((fromIntegral . fromEnum) g) return $ bladeRFErrorTy ret@@ -91,7 +91,7 @@ -- | Set the pre-LPF VGA gain. bladeRFSetRXVGA1 :: DeviceHandle -- ^ Device handle -> BladeRFVGAGainBounds -- ^ Desired gain- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFSetRXVGA1 dev g = do ret <- c'bladerf_set_rxvga1 (unDeviceHandle dev) ((fromIntegral . fromEnum) g) return $ bladeRFErrorTy ret@@ -108,7 +108,7 @@ -- | Set LNA Gain. bladeRFSetLNAGain :: DeviceHandle -- ^ Device handle -> BladeRFLNAGain -- ^ Desired gain level- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFSetLNAGain dev g = do ret <- c'bladerf_set_lna_gain (unDeviceHandle dev) ((fromIntegral . fromEnum) g) return $ bladeRFErrorTy ret@@ -130,7 +130,7 @@ bladeRFSetGain :: DeviceHandle -- ^ Device handle -> BladeRFModule -- ^ Module -> Int -- ^ Desired gain- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFSetGain dev m g = do ret <- c'bladerf_set_gain (unDeviceHandle dev) ((fromIntegral . fromEnum) m) (fromIntegral g) return $ bladeRFErrorTy ret
src/LibBladeRF/Gpio.hs view
@@ -35,7 +35,7 @@ -- accidentally clearing other GPIO bits that may be set by the library internally. bladeRFConfigGPIOWrite :: DeviceHandle -- ^ Device handle -> Word32 -- ^ Data to write to GPIO register- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFConfigGPIOWrite dev v = do ret <- c'bladerf_config_gpio_write (unDeviceHandle dev) v return $ bladeRFErrorTy ret
src/LibBladeRF/LibBladeRF.hs view
@@ -18,6 +18,7 @@ module LibBladeRF.LibBladeRF ( withBladeRF , DeviceHandle(..) , BladeRFError(..)+ , BladeRFReturnType(..) , bladeRFErrorValue , bladeRFErrorTy ) where@@ -95,15 +96,18 @@ ] -- | (For internal use) Obtain a 'BladeRFError' type of a C value from the Error codes list.-bladeRFErrorValue :: CInt -> Either BladeRFError Int+bladeRFErrorValue :: CInt -> BladeRFReturnType Int bladeRFErrorValue c | c >= 0 = (Right . fromIntegral) c -- Success (on ret == 0) | c < 0 = (Left . toEnum . fromIntegral) c -- C ret code to typed error -- | (For internal use) Obtain a 'BladeRFError' type of a C value from the Error codes list.-bladeRFErrorTy :: CInt -> Either BladeRFError ()+bladeRFErrorTy :: CInt -> BladeRFReturnType () bladeRFErrorTy c | c >= 0 = return () -- Success (on ret == 0) | c < 0 = (Left . toEnum . fromIntegral) c -- C ret code to typed error +-- | Short-hand type for brevity and clarity.+type BladeRFReturnType a = Either BladeRFError a+ -- | DeviceHandle wrapper around C device descriptor pointer newtype DeviceHandle = DeviceHandle { unDeviceHandle :: Ptr C'bladerf } @@ -122,7 +126,7 @@ -- Open specified device using a device identifier string. -- See bladerf_open_with_devinfo() if a device identifier string -- is not readily available.-openBladeRF' :: IO (Either BladeRFError DeviceHandle)+openBladeRF' :: IO (BladeRFReturnType DeviceHandle) openBladeRF' = alloca $ \ptr -> do ret <- c'bladerf_open ptr nullPtr if ret /= 0 then
src/LibBladeRF/Sync.hs view
@@ -44,8 +44,7 @@ -> Int -- ^ The size of the underlying stream buffers, in samples. This value must be a multiple of 1024. -> Int -- ^ The number of active USB transfers that may be in-flight at any given time. -> Int -- ^ Timeout (milliseconds) for transfers in the underlying data stream.- -> IO (Either BladeRFError ())-+ -> IO (BladeRFReturnType ()) bladeRFSyncConfig dev m f nb sz tr to = do ret <- c'bladerf_sync_config (unDeviceHandle dev) ((fromIntegral . fromEnum) m) ((fromIntegral . fromEnum) f) (fromIntegral nb) (fromIntegral sz) (fromIntegral tr) (fromIntegral to) return $ bladeRFErrorTy ret@@ -75,10 +74,10 @@ -- be 'Nothing' when the interface is configured for -- the 'FORMAT_SC16_Q11' format. -> Int -- ^ Timeout (milliseconds) for this call to complete. Zero implies infinite.- -> IO ()+ -> IO (BladeRFReturnType ()) bladeRFSyncTx dev s md t = do -- The number of samples to write is the length of the bytestring `div` by (|IQ|=2 * |int16_t|=2)=4- alloca $ \pmd ->+ ret <- alloca $ \pmd -> case md of Nothing -> BS.useAsCStringLen s $ \(p, len) -> c'bladerf_sync_tx (unDeviceHandle dev) p (fromIntegral $ len `div` 4) nullPtr (fromIntegral t)@@ -94,7 +93,7 @@ poke pmd meta BS.useAsCStringLen s $ \(p, len) -> c'bladerf_sync_tx (unDeviceHandle dev) p (fromIntegral $ len `div` 4) pmd (fromIntegral t)- return () -- XXX ignores ret+ return $ bladeRFErrorTy ret -- | Receive IQ samples. --@@ -113,18 +112,23 @@ bladeRFSyncRx :: DeviceHandle -- ^ Device handle -> Int -- ^ Number of samples to read -> Int -- ^ Timeout (milliseconds) for this call to complete. Zero implies infinite.- -> IO (BS.ByteString, BladeRFMetadata)+ -> IO (BladeRFReturnType (BS.ByteString, BladeRFMetadata)) bladeRFSyncRx dev n t = alloca $ \pmd -> do par <- allocaBytes (4 * n) $ \ptr -> do- c'bladerf_sync_rx (unDeviceHandle dev) ptr (fromIntegral n) pmd (fromIntegral t)- peekArray (4 * n) ptr- let bs = BS.pack par- cmd <- peek pmd- -- Use the following instead when switching to ghc7.8 later..- -- bladeRFMetadataFromCBladeRFMetadata :: C'bladerf_metadata -> BladeRFMetadata- let meta = BladeRFMetadata { timestamp = c'bladerf_metadata'timestamp cmd- , flags = c'bladerf_metadata'flags cmd- , status = c'bladerf_metadata'status cmd- , count = fromIntegral $ c'bladerf_metadata'actual_count cmd- }- return (bs, meta)+ ret <- c'bladerf_sync_rx (unDeviceHandle dev) ptr (fromIntegral n) pmd (fromIntegral t)+ if ret < 0 then (return . Left . toEnum . fromIntegral) ret -- C ret code to typed error+ else (return . Right) $ peekArray (4 * n) ptr+ case par of+ Left ret -> (return . Left) ret+ Right par' -> do+ par'' <- par'+ let bs = BS.pack par''+ cmd <- peek pmd+ -- Use the following instead when switching to ghc7.8 later..+ -- bladeRFMetadataFromCBladeRFMetadata :: C'bladerf_metadata -> BladeRFMetadata+ let meta = BladeRFMetadata { timestamp = c'bladerf_metadata'timestamp cmd+ , flags = c'bladerf_metadata'flags cmd+ , status = c'bladerf_metadata'status cmd+ , count = fromIntegral $ c'bladerf_metadata'actual_count cmd+ }+ return $ Right (bs, meta)
src/LibBladeRF/Utils.hs view
@@ -91,7 +91,7 @@ -- power cycle. Pass Full path to FPGA bitstream. bladeRFLoadFPGA :: DeviceHandle -- ^ Device handle -> String -- ^ Full path to FPGA bitstream- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFLoadFPGA dev s = do p <- newCString s ret <- c'bladerf_load_fpga (unDeviceHandle dev) p@@ -146,7 +146,7 @@ bladeRFEnableModule :: DeviceHandle -- ^ Device handle -> BladeRFModule -- ^ Device module -> Bool -- ^ 'True' to enable, 'False' to disable- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFEnableModule dev m t = do ret <- c'bladerf_enable_module (unDeviceHandle dev) ((fromIntegral . fromEnum) m) t return $ bladeRFErrorTy ret@@ -159,7 +159,7 @@ bladeRFSetLoopback :: DeviceHandle -- ^ Device handle -> BladeRFLoopback -- ^ Loopback mode. Note that 'LB_NONE' -- disables the use of loopback functionality.- -> IO (Either BladeRFError ())+ -> IO (BladeRFReturnType ()) bladeRFSetLoopback dev l = do ret <- c'bladerf_set_loopback (unDeviceHandle dev) ((fromIntegral . fromEnum) l) return $ bladeRFErrorTy ret