-
Notifications
You must be signed in to change notification settings - Fork 7
Hacked node-speaker exports and other imports here to get examples working #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cjheath
wants to merge
6
commits into
mildsunrise:main
Choose a base branch
from
cjheath:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
74538a7
Hacked node-speaker exports and other imports here to get examples wo…
cjheath 2e32033
Updated package and Typescript versions
cjheath 1370e8a
Added Speaker close event message
cjheath d66d9eb
Working toward a production acceptance test for the HackRF, using a s…
cjheath 9ce27fe
Split off reception_test
cjheath acfbea2
Added board_rev reporting to list_devices.ts
cjheath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Configure a HackRF as test rig, another as test subject (DUT) and run tests interactively | ||
*/ | ||
|
||
import { DeviceInfo, listDevices, UsbBoardId, visible_hackrfs, scan_hackrfs } from '../lib' | ||
import { run_test_sequence } from './test_sequence' | ||
|
||
function timeout(ms: number) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
async function await_hackrf(device: string) { | ||
process.stdout.write(`Please connect ${device}: `); | ||
for (;;) { | ||
for await (const device_change of scan_hackrfs()) { | ||
if (device_change.added) { | ||
console.log(`\nPlugged in: ${device_change.added.serialNumber}`) | ||
process.stdout.write("\n"); | ||
return device_change.added; | ||
} | ||
/* Ignore removals for now | ||
else if (device_change.removed) { | ||
console.log(`Unplugged: ${device_change.removed.serialNumber}`) | ||
return undefined; | ||
} | ||
*/ | ||
} | ||
|
||
await timeout(1000); // Sleep for a second before trying again | ||
} | ||
} | ||
|
||
async function await_rig() | ||
{ | ||
// Do the initial scan to see what's connected | ||
for await (const device_change of scan_hackrfs()) { scan_hackrfs(); } | ||
|
||
while (visible_hackrfs.length > 1) { | ||
process.stdout.write(`${visible_hackrfs.length} HackRFs connected, unplug all but the test controller please\r`) | ||
await timeout(1000); // Sleep for a second before trying again | ||
for await (const device_change of scan_hackrfs()) { scan_hackrfs(); } | ||
} | ||
|
||
if (visible_hackrfs.length == 1) | ||
{ | ||
console.log(`Detected ${visible_hackrfs[0].serialNumber} as test controller`) | ||
return visible_hackrfs[0]; | ||
} | ||
return await_hackrf("test controller HackRF"); | ||
} | ||
|
||
async function await_dut() | ||
{ | ||
return await_hackrf("HackRF to be tested"); | ||
} | ||
|
||
async function main() { | ||
|
||
var rig = await await_rig(); | ||
for (;;) { | ||
var dut = await await_dut(); | ||
if (!dut) continue; | ||
|
||
console.log(`Detected ${dut.serialNumber} as DUT`) | ||
|
||
await run_test_sequence(rig, dut) | ||
break; // REVISIT: Just one run for now :) | ||
} | ||
process.exit(0) | ||
} | ||
main() |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
import { listDevices, UsbBoardId } from '../lib' | ||
|
||
async function main() { | ||
let ld = listDevices(); | ||
for await (const info of ld) { | ||
console.log(info.device) // Show USB detail | ||
console.log(`Found ${UsbBoardId[info.usbBoardId]} (PID 0x${info.usbBoardId.toString(16).padStart(4, '0')})`) | ||
if (info.serialNumber) { | ||
console.log(`Serial: ${info.serialNumber.replace(/^1+/,'')}`) | ||
} | ||
if (info.boardRev !== undefined) { | ||
console.log(`Board Rev ${info.boardRev}`) | ||
} | ||
} | ||
|
||
process.exit(0) | ||
} | ||
main() |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { HackrfDevice } from '../lib' | ||
|
||
export async function reception_test(rig: HackrfDevice, dut: HackrfDevice, frequency: number): Promise<number> { | ||
console.log(`Testing reception at ${frequency}`) | ||
|
||
// REVISIT: Implement receiver test | ||
return 0; | ||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Continuously scan for HackRF devices, announcing when each appears or disappears | ||
*/ | ||
|
||
import { DeviceInfo, listDevices, UsbBoardId, visible_hackrfs, scan_hackrfs } from '../lib' | ||
|
||
function timeout(ms: number) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
async function main() { | ||
for (;;) { | ||
for await (const device_change of scan_hackrfs()) { | ||
if (device_change.added) { | ||
console.log(`Plugged in: ${device_change.added.serialNumber}`) | ||
} else if (device_change.removed) { | ||
console.log(`Unplugged: ${device_change.removed.serialNumber}`) | ||
} | ||
} | ||
|
||
await timeout(1000); // Sleep for a second before trying again | ||
} | ||
process.exit(0) | ||
} | ||
main() |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Testing sequence for the HackRF. | ||
* | ||
* Initially just test the noise floor at a range of frequencies. | ||
* Noise floor is simplified to just the variance in the magnitude of the I/Q vectors. | ||
*/ | ||
import { open, HackrfDevice, DeviceInfo, UsbBoardId } from '../lib' | ||
|
||
import { reception_test } from "./reception_test" | ||
|
||
type Complex = [number, number] | ||
|
||
function timeout(ms: number) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
/* | ||
* Not really an FFT, not yet. But aspiring to be | ||
*/ | ||
class FFT { | ||
protected num_samples: number = 0; | ||
protected sum_mag: number = 0; | ||
protected sum_mag_squared: number = 0; | ||
|
||
constructor(_logSize: number) { | ||
// Allocate array of size 2^_logSize | ||
} | ||
|
||
accumulate(x: Complex): void { | ||
const mag_squared = x[0]*x[0] + x[1]*x[1] | ||
this.sum_mag_squared += mag_squared; | ||
this.num_samples++; | ||
} | ||
|
||
noise_floor(): number | ||
{ | ||
return Math.sqrt(this.sum_mag_squared/this.num_samples); | ||
} | ||
} | ||
|
||
async function noise_floor_test(dut: HackrfDevice, frequency: number, sample_rate: number): Promise<number> { | ||
console.log(`Measuring noise floor at ${frequency}`) | ||
|
||
const num_seconds = 1; | ||
|
||
await dut.setFrequency(frequency) | ||
await dut.setSampleRate(sample_rate) | ||
await dut.setAmpEnable(false) | ||
await dut.setLnaGain(32) | ||
await dut.setVgaGain(48) | ||
|
||
var fft = new FFT(12); | ||
var num_samples = 0; | ||
await dut.receive((array): undefined | void | false => { | ||
if (num_samples >= num_seconds*sample_rate) | ||
return; // Discard overrun | ||
const samples = array.length / 2 | ||
for (let n = 0; n < samples; n++) | ||
{ | ||
if (++num_samples == num_seconds*sample_rate) { // Collect 1 second of data | ||
dut.requestStop(); | ||
break; | ||
} | ||
const i = array[n * 2 + 0] / 127 | ||
const q = array[n * 2 + 1] / 127 | ||
fft.accumulate([i, q]) | ||
} | ||
}) | ||
return fft.noise_floor(); | ||
} | ||
|
||
export async function run_test_sequence(rig_info: DeviceInfo, dut_info: DeviceInfo) | ||
{ | ||
const rig: HackrfDevice = await open(rig_info.serialNumber) | ||
if (!rig) | ||
return `rig ${rig_info.serialNumber} not available`; | ||
|
||
const dut: HackrfDevice = await open(dut_info.serialNumber) | ||
if (!dut) | ||
return `HackRF ${dut_info.serialNumber} not available`; | ||
|
||
console.log(`Testing ${dut_info.serialNumber} using ${rig_info.serialNumber}:\n`); | ||
|
||
const frequencies = [80e6, 600e6, 2.4e9, 3.6e9] | ||
for (let i = 0; i < frequencies.length; i++) { | ||
const frequency = frequencies[i]; | ||
var noise_floor = await noise_floor_test(dut, frequency, 1.2e6); | ||
console.log(`Noise floor at ${frequency/1e6} is ${Math.round(noise_floor*1280)/10}`) | ||
} | ||
|
||
var frequency = frequencies[0]; | ||
var receive_result = await reception_test(rig, dut, frequency); | ||
console.log(`Reception at ${frequency/1e6} returned ${receive_result}`) | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing
..
to../lib
shouldn't be necessary to run the examples, as long as you've rannpm run build
first and you have compiled files indist
🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw! these examples are meant to be run with
ts-node
or similarThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. New to the ecosystem and didn't have any build instructions :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also; opening in vscode is disappointing; that guesses that the build instructions are just to run tsc, so "Start Debugging" doesn't work