hackrf.js icon indicating copy to clipboard operation
hackrf.js copied to clipboard

Hacked node-speaker exports and other imports here to get examples working

Open cjheath opened this issue 5 years ago • 12 comments

Please note I changed package.json to refer to my fork of node-speaker also.

As a newb to the TypeScript ecosystem I don't know if my export/import changes are correct/modern/acceptable, but I got the examples working.

There is still a bug (in usb?) where fm_tone doesn't exit on a ^C interrupt. Have to ^Z and kill it.

cjheath avatar Sep 08 '20 05:09 cjheath

welcome! I don't quite understand some of the changes you're proposing, I'll add comments

mildsunrise avatar Sep 08 '20 08:09 mildsunrise

Mainly just things to get it compiling. I tried under VSCode, then command line, just saying "tsc" at the top level.

  • tsconfig.json compiles things in examples
  • examples import from ../lib, where the code is
  • usb updated to a version that works
  • speaker updates to a version that exports itself in a way that works (I understand there are two kinds of export):

https://github.com/cjheath/node-speaker/commit/09377c3544742a32afaa4e8aeff8a6ada33f0205

cjheath avatar Sep 08 '20 08:09 cjheath

Also I've just done this:

-       const carrierFrequency = 98.8e6
+       let carrierFrequency : number = 104.9e6
        const carrierDeviation = 75e3
 
+       if (process.argv.length >= 3)
+               carrierFrequency = (+process.argv[2])*1.0e6;

cjheath avatar Sep 08 '20 08:09 cjheath

There is still a bug (in usb?) where fm_tone doesn't exit on a ^C interrupt. Have to ^Z and kill it.

I'm just speculating, but that happened to me too, and it seems to be a loop starvation issue somewhere in my code or usb, which prevents the ^C event from being dispatched. if it happens on fm_tone, your cpu is probably not fast enough to run the code (keep in mind examples aren't optimized in any way)

mildsunrise avatar Sep 08 '20 08:09 mildsunrise

I'd be very surprised if my CPU isn't fast enough. 2yo i7 MacBook Pro...

BTW, I've developed a new version of HackRF, updating to still-available components. and adding robust protection to the antenna port. It's about to go to batch manufacturing and will be available for purchase on aliexpress (no cash to me, just development sample units)

cjheath avatar Sep 08 '20 09:09 cjheath

that looks nice :blue_heart: let me know when it's available :)

mildsunrise avatar Sep 08 '20 09:09 mildsunrise

by the way, I don't know enough TypeScript to understand why speaker works for me, but not for you :thinking:

in any case, according to the documentation, import Speaker = require('speaker') syntax should be used, so I'll do that

mildsunrise avatar Sep 08 '20 09:09 mildsunrise

I've added npm run build-examples, instructions, and proposed proper fixes to speaker

mildsunrise avatar Sep 08 '20 10:09 mildsunrise

I've fetched your latest. npm run build-examples fails for me. The Speaker one is not a concern, but failing to import from .. is:


> [email protected] build-examples /Users/cjh/work/electronics/SDR/node/hackrf.js-upstream
> cd examples && tsc

fm_receiver.ts:9:22 - error TS2307: Cannot find module '..' or its corresponding type declarations.

9 import { open } from '..'
                       ~~~~

fm_receiver.ts:26:22 - error TS2351: This expression is not constructable.
  Type 'typeof import("/Users/cjh/work/electronics/SDR/node/hackrf.js-upstream/node_modules/speaker/index")' has no construct signatures.

26  const speaker = new Speaker({ sampleRate: 48000, channels: 1, bitDepth: 16 })
                        ~~~~~~~

fm_receiver.ts:53:23 - error TS7006: Parameter 'array' implicitly has an 'any' type.

53  await device.receive(array => {
                         ~~~~~

fm_tone.ts:5:22 - error TS2307: Cannot find module '..' or its corresponding type declarations.

5 import { open } from '..'
                       ~~~~

fm_tone.ts:27:24 - error TS7006: Parameter 'array' implicitly has an 'any' type.

27  await device.transmit(array => {
                          ~~~~~


Found 5 errors.

cjheath avatar Sep 08 '20 23:09 cjheath

have you run npm install again? do you have compiled files in dist? (also, does dist/index.js exist?)

mildsunrise avatar Sep 09 '20 07:09 mildsunrise

Ahh, apologies, that fixed it, or would have, if `speaker`` had been fixed already

cjheath avatar Sep 09 '20 10:09 cjheath

perfect! now I just have to fix the loop starvation bug

mildsunrise avatar Sep 09 '20 10:09 mildsunrise