Skip to content

Commit

Permalink
Merge pull request #2 from JuliaTelecom/uhd4
Browse files Browse the repository at this point in the history
Merge UHD4 support, artifact and test refactor
  • Loading branch information
RGerzaguet committed May 19, 2021
2 parents e456b80 + 6831a2f commit 079a8cf
Show file tree
Hide file tree
Showing 19 changed files with 604 additions and 629 deletions.
21 changes: 21 additions & 0 deletions Artifacts.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[[libUHD]]
arch = "x86_64"
git-tree-sha1 = "2947ee61a72e51f3bb7e7247d0460472fedf2eaa"
os = "macos"

[[libUHD.download]]
url = "https://github.com/JuliaTelecom/Artifact_libUHD/releases/download/v0.1/libUHD_MacOS.tar.gz"
sha256 = "12fb524edeb043c7abcc856a4b43045a58bc04bb45ccc0585adf7d2a28872f3e"


[[libUHD]]
arch = "x86_64"
git-tree-sha1 = "95ad926e1c215f57d98d15df1c28ddf72873a990"
os = "linux"

[[libUHD.download]]
url = "https://github.com/JuliaTelecom/Artifact_libUHD/releases/download/v0.1/libUHD_Linux.tar.gz"
sha256 = "c312a32adfe65e9383cacd19c192884f43d5f2d85a9191bfe937178559f29eb6"



103 changes: 103 additions & 0 deletions Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,114 @@
# This file is machine-generated - editing it directly is not advised

[[ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"

[[Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[Downloads]]
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"

[[LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"

[[LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"

[[MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"

[[NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"

[[Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[TOML]]
deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[[Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"

[[Test]]
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"

[[nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"

[[p7zip_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name = "UHDBindings"
uuid = "4d90b16f-829e-4b78-80d9-fb9bcf8c06e0"
authors = ["Robin Gerzaguet <robin.gerzaguet@irisa.fr>"]
version = "0.1.3"
version = "0.2.0"

[deps]
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
julia = "1"
2 changes: 2 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

This simple package proposes some bindings to the UHD, the C driver of the Universal Software Radio Peripheral [USRP](https://files.ettus.com/manual/)

The package is heavily dependent on libUHD the open source driver from Ettus research. The library is shipped in the package through Artifacts, and the current implementation uses libUHD.4.0.0

The purpose is to able to instantiate the radio peripheral inside a Julia session and to be able to send and receive complex samples directly within a Julia session.

The package introduces the `UHDBinding` structure which pilots and controls the radio. This structure has two important fields namely `tx` and `rx` that are respectively related to transmitter and receiver stages.
Expand Down
30 changes: 20 additions & 10 deletions tests_rx/Benchmark.jl → examples/Benchmark.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
module Benchmark
# ----------------------------------------------------
# --- Modules & Utils
# --- Benchmark module
# ----------------------------------------------------
# This module uses UHDBindings and can be used to benchmark output rate of the SDR
# Benchmark.main(5e6,args) returns a tuple (ideally (5e6,5e6)) where
# Input
# - First parmaeter is the desired radio rate
# - Second parameter is the radio parameter (USRP device)
# Output
# First parameter is the actual radio rate
# Second parameter is the calculated rate

# To benchmark a range one can do Benchmark.main.(1e6:1e6:16e6)

# --- External modules
using UHDBindings
# --- Functions
Expand All @@ -16,20 +27,19 @@ end
"""
Main call to monitor Rx rate
"""
function main(samplingRate)
function main(samplingRate,args)
# ----------------------------------------------------
# --- Physical layer and RF parameters
# ----------------------------------------------------
# --- Create the radio object in function
carrierFreq = 770e6;
gain = 50.0;
radio = openUHD(carrierFreq,samplingRate,gain);
radioRx = radio.rx;
radio = openUHD(carrierFreq,samplingRate,gain,args=args)
# --- Print the configuration
print(radioRx);
print(radio);
# --- Init parameters
# Get the radio size for buffer pre-allocation
nbSamples = radioRx.packetSize;
nbSamples = radio.rx.packetSize;
# We will get complex samples from recv! method
sig = zeros(Complex{Cfloat},nbSamples);
# --- Targeting 2 seconds acquisition
Expand All @@ -38,12 +48,12 @@ function main(samplingRate)
# Max counter definition
nbBuffer = 2*samplingRate;
# --- Timestamp init
p = recv!(sig,radioRx);
p = recv!(sig,radio);
nS += p;
timeInit = time();
while true
# --- Direct call to avoid allocation
p = recv!(sig,radioRx);
p = recv!(sig,radio);
# # --- Ensure packet is OK
# err = getError(radioRx);
# --- Update counter
Expand All @@ -56,10 +66,10 @@ function main(samplingRate)
# --- Last timeStamp and rate
timeFinal = time();
# --- Getting effective rate
radioRate = radioRx.samplingRate;
radioRate = radio.rx.samplingRate;
effectiveRate = getRate(timeInit,timeFinal,nS);
# --- Free all and return
close(radio);
return (radioRate,effectiveRate);
end
end
end
56 changes: 56 additions & 0 deletions examples/SimplePSD.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module SimplePSD

# A simple example code to calculate a PSD of a received signal
# This uses AbstractFFTs to compute the FFT here, even though FFTW would be faster

using UHDBindings
using FFTW


"""
Compute the PSD at the given carrier frequency, on the given bandwidth, withe SDR parameters args.
PSD is calculated a the periodogram (square root of the averaged FFT)
Input parameters
- carrierFreq = Carrier frequency (in Hz)
- samplingRate = Desired bandwidth (in Hz)
- gain = desired gain
- args = USRP device argument (ex: "addr=192.168.10.16")
- N : Desired FFT size [Default 1024]
- nbMean : Averaging factor. Number of buffers averaged before computed final result
Output parameters
xAx = Frequency values (Vector{Float})
psd = PSD values at the associated frequencies (Vector{Float})
The result then can be plotted by plot(xAx,10*log10.(psd))
"""
function computePSD(carrierFreq,samplingRate,gain;args="",N=1024,nbMean=32)
# ----------------------------------------------------
# --- Physical layer and RF parameters
# ----------------------------------------------------
# --- Create the radio object in function
sdr = openUHD(carrierFreq,samplingRate,gain,args=args)
# --- Print the configuration
print(sdr);
# We will get complex samples from recv! method
sig = zeros(Complex{Cfloat},N); # Buffer in time domain
psd = zeros(Cfloat,N); # Buffer in freq domain
# ----------------------------------------------------
# --- Acqusition and frequency domain calculation
# ----------------------------------------------------
for _ 1 : nbMean
# Populate buffer
recv!(sig,sdr)
# Compute FFT
psd += abs2.(fft(sig))
end
# --- Close SDR
close(sdr)
# --- Compute freq axis
freqAx = ((0:N-1)/(N-1) .- 0.5) * samplingRate
# --- Return tuple (freq,mag)
return (freqAx, fftshift(psd))
end


end
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

This package proposes some bindings to UHD, the C driver of the Universal Software Radio Peripheral [USRP](https://files.ettus.com/manual/)

The purpose is to able to instantiate the radio peripheral inside a Julia session and to be able to send and receive complex samples direclty within a Julia session.
The package is heavily dependent on libUHD the open source driver from Ettus research. The library is shipped in the package through Artifacts, and the current implementation uses libUHD.4.0.0

The purpose is to able to instantiate the radio peripheral inside a Julia session and to be able to send and receive complex samples directly within a Julia session.

For instance, in order to get 4096 samples at 868MHz with a instantaneous bandwidth of 16MHz, with a 30dB Rx Gain, the following Julia code will do the trick and returns a vector with type Complex{Cfloat} with 4096 samples.

Expand Down
Loading

2 comments on commit 079a8cf

@RGerzaguet
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/37035

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" 079a8cfe02d068b4ce48b77019cf43a2db902f48
git push origin v0.2.0

Please sign in to comment.