Skip to content
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

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

cjheath
Copy link

@cjheath cjheath commented Sep 8, 2020

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.

@mildsunrise
Copy link
Owner

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

@@ -6,7 +6,7 @@
* (SDR - audio card) but it should be functional.
*/

import { open } from '..'
import { open } from '../lib'
Copy link
Owner

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 ran npm run build first and you have compiled files in dist 🤔

Copy link
Owner

@mildsunrise mildsunrise Sep 8, 2020

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 similar

Copy link
Author

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 :)

Copy link
Author

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

package.json Outdated Show resolved Hide resolved
package.json Outdated
"usb": "^1.6.3"
},
"devDependencies": {
"@types/jest": "^23.3.14",
"coveralls": "^3.1.0",
"jest": "^26.4.2",
"speaker": "^0.5.2",
"speaker": "https://github.com/cjheath/node-speaker.git",
Copy link
Owner

Choose a reason for hiding this comment

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

could you explain a bit more what changes you need / made in your fork?

Copy link
Author

@cjheath cjheath Sep 8, 2020

Choose a reason for hiding this comment

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

@@ -17,6 +17,7 @@
"emitDecoratorMetadata": true
},
"include": [
"lib"
"lib",
"examples"
Copy link
Owner

Choose a reason for hiding this comment

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

AFAIK that would cause examples to be compiled and distributed with the NPM package... I think examples don't need to be published, just the actual library code

Copy link
Author

Choose a reason for hiding this comment

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

Right, probably not sensible for a library module. But some instructions on building the examples would be good, also the ability to build them without installing. Guess I don't understand why they import from ".." if there's no code there?

Copy link
Owner

Choose a reason for hiding this comment

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

they import from '..' because that's the module itself :) so according to package.json, that resolves to dist/index.js

as per running / building examples, you're just supposed to run them with ts-node rather than building. I'll put a README in the examples folder

Copy link
Author

Choose a reason for hiding this comment

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

Excellent idea :) thanks!

@cjheath
Copy link
Author

cjheath commented Sep 8, 2020

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
Copy link
Author

cjheath commented Sep 8, 2020

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;

@mildsunrise
Copy link
Owner

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)

@cjheath
Copy link
Author

cjheath commented Sep 8, 2020

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)

@mildsunrise
Copy link
Owner

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

@mildsunrise
Copy link
Owner

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

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

@mildsunrise
Copy link
Owner

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

@cjheath
Copy link
Author

cjheath commented Sep 8, 2020

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:


> hackrf.js@1.0.0-rc1 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.

@mildsunrise
Copy link
Owner

mildsunrise commented Sep 9, 2020

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

@cjheath
Copy link
Author

cjheath commented Sep 9, 2020

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

@mildsunrise
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants