hamlib 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +5 -5
- package/package.json +7 -8
- package/prebuilds/darwin-arm64/node.napi.node +0 -0
- package/prebuilds/linux-arm64/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.node +0 -0
- package/src/hamlib.cpp +185 -5
- package/src/hamlib.h +1 -0
- package/lib/binary-loader.js +0 -95
- package/prebuilds/darwin-arm64/hamlib.node +0 -0
- package/prebuilds/linux-arm64/hamlib.node +0 -0
- package/prebuilds/linux-x64/hamlib.node +0 -0
- package/scripts/install.js +0 -262
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
const nativeModule =
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const nodeGypBuild = require('node-gyp-build');
|
|
3
|
+
// Ensure loader resolves from package root (contains prebuilds/ and build/)
|
|
4
|
+
const nativeModule = nodeGypBuild(path.join(__dirname, '..'));
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* HamLib class for controlling amateur radio devices
|
|
@@ -1076,4 +1076,4 @@ class HamLib {
|
|
|
1076
1076
|
// Export for CommonJS
|
|
1077
1077
|
module.exports = { HamLib };
|
|
1078
1078
|
module.exports.HamLib = HamLib;
|
|
1079
|
-
module.exports.default = { HamLib };
|
|
1079
|
+
module.exports.default = { HamLib };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hamlib",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "Node.js wrapper for hamlib radio control library",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
"lib/",
|
|
31
31
|
"prebuilds/",
|
|
32
32
|
"src/",
|
|
33
|
-
"scripts/",
|
|
34
33
|
"index.js",
|
|
35
34
|
"index.d.ts",
|
|
36
35
|
"binding.gyp",
|
|
@@ -43,16 +42,16 @@
|
|
|
43
42
|
"clean": "node-gyp clean",
|
|
44
43
|
"test": "node test/test_loader.js",
|
|
45
44
|
"test:network": "node test/test_network.js",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"prepare": "npm run build",
|
|
49
|
-
"prepack": "npm run build"
|
|
45
|
+
"prebuild": "prebuildify --napi --strip",
|
|
46
|
+
"prepare": ""
|
|
50
47
|
},
|
|
51
48
|
"dependencies": {
|
|
52
|
-
"node-addon-api": "^4.3.0"
|
|
49
|
+
"node-addon-api": "^4.3.0",
|
|
50
|
+
"node-gyp-build": "^4.8.0"
|
|
53
51
|
},
|
|
54
52
|
"devDependencies": {
|
|
55
|
-
"node-gyp": "^9.4.0"
|
|
53
|
+
"node-gyp": "^9.4.0",
|
|
54
|
+
"prebuildify": "^5.0.0"
|
|
56
55
|
},
|
|
57
56
|
"engines": {
|
|
58
57
|
"node": ">=12.0.0"
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/hamlib.cpp
CHANGED
|
@@ -15,6 +15,16 @@
|
|
|
15
15
|
#endif
|
|
16
16
|
#endif
|
|
17
17
|
|
|
18
|
+
// 安全宏 - 检查RIG指针有效性,防止空指针解引用和已销毁对象访问
|
|
19
|
+
#define CHECK_RIG_VALID() \
|
|
20
|
+
do { \
|
|
21
|
+
if (!hamlib_instance_ || !hamlib_instance_->my_rig) { \
|
|
22
|
+
result_code_ = -RIG_EINVAL; \
|
|
23
|
+
error_message_ = "RIG is not initialized or has been destroyed"; \
|
|
24
|
+
return; \
|
|
25
|
+
} \
|
|
26
|
+
} while(0)
|
|
27
|
+
|
|
18
28
|
// Structure to hold rig information for the callback
|
|
19
29
|
struct RigListData {
|
|
20
30
|
std::vector<Napi::Object> rigList;
|
|
@@ -37,6 +47,8 @@ public:
|
|
|
37
47
|
: HamLibAsyncWorker(env, hamlib_instance) {}
|
|
38
48
|
|
|
39
49
|
void Execute() override {
|
|
50
|
+
CHECK_RIG_VALID();
|
|
51
|
+
|
|
40
52
|
result_code_ = rig_open(hamlib_instance_->my_rig);
|
|
41
53
|
if (result_code_ != RIG_OK) {
|
|
42
54
|
error_message_ = rigerror(result_code_);
|
|
@@ -73,6 +85,8 @@ public:
|
|
|
73
85
|
: HamLibAsyncWorker(env, hamlib_instance), freq_(freq), vfo_(vfo) {}
|
|
74
86
|
|
|
75
87
|
void Execute() override {
|
|
88
|
+
CHECK_RIG_VALID();
|
|
89
|
+
|
|
76
90
|
result_code_ = rig_set_freq(hamlib_instance_->my_rig, vfo_, freq_);
|
|
77
91
|
if (result_code_ != RIG_OK) {
|
|
78
92
|
error_message_ = rigerror(result_code_);
|
|
@@ -104,6 +118,8 @@ public:
|
|
|
104
118
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), freq_(0) {}
|
|
105
119
|
|
|
106
120
|
void Execute() override {
|
|
121
|
+
CHECK_RIG_VALID();
|
|
122
|
+
|
|
107
123
|
result_code_ = rig_get_freq(hamlib_instance_->my_rig, vfo_, &freq_);
|
|
108
124
|
if (result_code_ != RIG_OK) {
|
|
109
125
|
error_message_ = rigerror(result_code_);
|
|
@@ -135,6 +151,8 @@ public:
|
|
|
135
151
|
: HamLibAsyncWorker(env, hamlib_instance), mode_(mode), width_(width), vfo_(vfo) {}
|
|
136
152
|
|
|
137
153
|
void Execute() override {
|
|
154
|
+
CHECK_RIG_VALID();
|
|
155
|
+
|
|
138
156
|
result_code_ = rig_set_mode(hamlib_instance_->my_rig, vfo_, mode_, width_);
|
|
139
157
|
if (result_code_ != RIG_OK) {
|
|
140
158
|
error_message_ = rigerror(result_code_);
|
|
@@ -167,6 +185,8 @@ public:
|
|
|
167
185
|
: HamLibAsyncWorker(env, hamlib_instance), mode_(0), width_(0) {}
|
|
168
186
|
|
|
169
187
|
void Execute() override {
|
|
188
|
+
CHECK_RIG_VALID();
|
|
189
|
+
|
|
170
190
|
result_code_ = rig_get_mode(hamlib_instance_->my_rig, RIG_VFO_CURR, &mode_, &width_);
|
|
171
191
|
if (result_code_ != RIG_OK) {
|
|
172
192
|
error_message_ = rigerror(result_code_);
|
|
@@ -203,6 +223,8 @@ public:
|
|
|
203
223
|
: HamLibAsyncWorker(env, hamlib_instance), ptt_(ptt) {}
|
|
204
224
|
|
|
205
225
|
void Execute() override {
|
|
226
|
+
CHECK_RIG_VALID();
|
|
227
|
+
|
|
206
228
|
result_code_ = rig_set_ptt(hamlib_instance_->my_rig, RIG_VFO_CURR, ptt_);
|
|
207
229
|
if (result_code_ != RIG_OK) {
|
|
208
230
|
error_message_ = rigerror(result_code_);
|
|
@@ -233,6 +255,8 @@ public:
|
|
|
233
255
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), strength_(0) {}
|
|
234
256
|
|
|
235
257
|
void Execute() override {
|
|
258
|
+
CHECK_RIG_VALID();
|
|
259
|
+
|
|
236
260
|
result_code_ = rig_get_strength(hamlib_instance_->my_rig, vfo_, &strength_);
|
|
237
261
|
if (result_code_ != RIG_OK) {
|
|
238
262
|
error_message_ = rigerror(result_code_);
|
|
@@ -264,6 +288,8 @@ public:
|
|
|
264
288
|
: HamLibAsyncWorker(env, hamlib_instance), level_type_(level_type), value_(value) {}
|
|
265
289
|
|
|
266
290
|
void Execute() override {
|
|
291
|
+
CHECK_RIG_VALID();
|
|
292
|
+
|
|
267
293
|
result_code_ = rig_set_level(hamlib_instance_->my_rig, RIG_VFO_CURR, level_type_, value_);
|
|
268
294
|
if (result_code_ != RIG_OK) {
|
|
269
295
|
error_message_ = rigerror(result_code_);
|
|
@@ -297,6 +323,8 @@ public:
|
|
|
297
323
|
}
|
|
298
324
|
|
|
299
325
|
void Execute() override {
|
|
326
|
+
CHECK_RIG_VALID();
|
|
327
|
+
|
|
300
328
|
result_code_ = rig_get_level(hamlib_instance_->my_rig, RIG_VFO_CURR, level_type_, &value_);
|
|
301
329
|
if (result_code_ != RIG_OK) {
|
|
302
330
|
error_message_ = rigerror(result_code_);
|
|
@@ -328,6 +356,8 @@ public:
|
|
|
328
356
|
: HamLibAsyncWorker(env, hamlib_instance), func_type_(func_type), enable_(enable) {}
|
|
329
357
|
|
|
330
358
|
void Execute() override {
|
|
359
|
+
CHECK_RIG_VALID();
|
|
360
|
+
|
|
331
361
|
result_code_ = rig_set_func(hamlib_instance_->my_rig, RIG_VFO_CURR, func_type_, enable_);
|
|
332
362
|
if (result_code_ != RIG_OK) {
|
|
333
363
|
error_message_ = rigerror(result_code_);
|
|
@@ -359,6 +389,8 @@ public:
|
|
|
359
389
|
: HamLibAsyncWorker(env, hamlib_instance), func_type_(func_type), state_(0) {}
|
|
360
390
|
|
|
361
391
|
void Execute() override {
|
|
392
|
+
CHECK_RIG_VALID();
|
|
393
|
+
|
|
362
394
|
result_code_ = rig_get_func(hamlib_instance_->my_rig, RIG_VFO_CURR, func_type_, &state_);
|
|
363
395
|
if (result_code_ != RIG_OK) {
|
|
364
396
|
error_message_ = rigerror(result_code_);
|
|
@@ -390,6 +422,8 @@ public:
|
|
|
390
422
|
: HamLibAsyncWorker(env, hamlib_instance), chan_(chan) {}
|
|
391
423
|
|
|
392
424
|
void Execute() override {
|
|
425
|
+
CHECK_RIG_VALID();
|
|
426
|
+
|
|
393
427
|
result_code_ = rig_set_channel(hamlib_instance_->my_rig, RIG_VFO_MEM, &chan_);
|
|
394
428
|
if (result_code_ != RIG_OK) {
|
|
395
429
|
error_message_ = rigerror(result_code_);
|
|
@@ -422,6 +456,8 @@ public:
|
|
|
422
456
|
}
|
|
423
457
|
|
|
424
458
|
void Execute() override {
|
|
459
|
+
CHECK_RIG_VALID();
|
|
460
|
+
|
|
425
461
|
chan_.channel_num = channel_num_;
|
|
426
462
|
chan_.vfo = RIG_VFO_MEM;
|
|
427
463
|
result_code_ = rig_get_channel(hamlib_instance_->my_rig, RIG_VFO_MEM, &chan_, read_only_);
|
|
@@ -476,6 +512,8 @@ public:
|
|
|
476
512
|
: HamLibAsyncWorker(env, hamlib_instance), channel_num_(channel_num) {}
|
|
477
513
|
|
|
478
514
|
void Execute() override {
|
|
515
|
+
CHECK_RIG_VALID();
|
|
516
|
+
|
|
479
517
|
result_code_ = rig_set_mem(hamlib_instance_->my_rig, RIG_VFO_CURR, channel_num_);
|
|
480
518
|
if (result_code_ != RIG_OK) {
|
|
481
519
|
error_message_ = rigerror(result_code_);
|
|
@@ -506,6 +544,8 @@ public:
|
|
|
506
544
|
: HamLibAsyncWorker(env, hamlib_instance), rit_offset_(rit_offset) {}
|
|
507
545
|
|
|
508
546
|
void Execute() override {
|
|
547
|
+
CHECK_RIG_VALID();
|
|
548
|
+
|
|
509
549
|
result_code_ = rig_set_rit(hamlib_instance_->my_rig, RIG_VFO_CURR, rit_offset_);
|
|
510
550
|
if (result_code_ != RIG_OK) {
|
|
511
551
|
error_message_ = rigerror(result_code_);
|
|
@@ -536,6 +576,8 @@ public:
|
|
|
536
576
|
: HamLibAsyncWorker(env, hamlib_instance), rit_offset_(0) {}
|
|
537
577
|
|
|
538
578
|
void Execute() override {
|
|
579
|
+
CHECK_RIG_VALID();
|
|
580
|
+
|
|
539
581
|
result_code_ = rig_get_rit(hamlib_instance_->my_rig, RIG_VFO_CURR, &rit_offset_);
|
|
540
582
|
if (result_code_ != RIG_OK) {
|
|
541
583
|
error_message_ = rigerror(result_code_);
|
|
@@ -566,6 +608,8 @@ public:
|
|
|
566
608
|
: HamLibAsyncWorker(env, hamlib_instance), xit_offset_(xit_offset) {}
|
|
567
609
|
|
|
568
610
|
void Execute() override {
|
|
611
|
+
CHECK_RIG_VALID();
|
|
612
|
+
|
|
569
613
|
result_code_ = rig_set_xit(hamlib_instance_->my_rig, RIG_VFO_CURR, xit_offset_);
|
|
570
614
|
if (result_code_ != RIG_OK) {
|
|
571
615
|
error_message_ = rigerror(result_code_);
|
|
@@ -596,6 +640,8 @@ public:
|
|
|
596
640
|
: HamLibAsyncWorker(env, hamlib_instance), xit_offset_(0) {}
|
|
597
641
|
|
|
598
642
|
void Execute() override {
|
|
643
|
+
CHECK_RIG_VALID();
|
|
644
|
+
|
|
599
645
|
result_code_ = rig_get_xit(hamlib_instance_->my_rig, RIG_VFO_CURR, &xit_offset_);
|
|
600
646
|
if (result_code_ != RIG_OK) {
|
|
601
647
|
error_message_ = rigerror(result_code_);
|
|
@@ -626,6 +672,8 @@ public:
|
|
|
626
672
|
: HamLibAsyncWorker(env, hamlib_instance) {}
|
|
627
673
|
|
|
628
674
|
void Execute() override {
|
|
675
|
+
CHECK_RIG_VALID();
|
|
676
|
+
|
|
629
677
|
int ritCode = rig_set_rit(hamlib_instance_->my_rig, RIG_VFO_CURR, 0);
|
|
630
678
|
int xitCode = rig_set_xit(hamlib_instance_->my_rig, RIG_VFO_CURR, 0);
|
|
631
679
|
|
|
@@ -661,6 +709,8 @@ public:
|
|
|
661
709
|
: HamLibAsyncWorker(env, hamlib_instance), tx_freq_(tx_freq), vfo_(vfo) {}
|
|
662
710
|
|
|
663
711
|
void Execute() override {
|
|
712
|
+
CHECK_RIG_VALID();
|
|
713
|
+
|
|
664
714
|
result_code_ = rig_set_split_freq(hamlib_instance_->my_rig, vfo_, tx_freq_);
|
|
665
715
|
if (result_code_ != RIG_OK) {
|
|
666
716
|
error_message_ = rigerror(result_code_);
|
|
@@ -692,6 +742,8 @@ public:
|
|
|
692
742
|
: HamLibAsyncWorker(env, hamlib_instance), tx_freq_(0), vfo_(vfo) {}
|
|
693
743
|
|
|
694
744
|
void Execute() override {
|
|
745
|
+
CHECK_RIG_VALID();
|
|
746
|
+
|
|
695
747
|
result_code_ = rig_get_split_freq(hamlib_instance_->my_rig, vfo_, &tx_freq_);
|
|
696
748
|
if (result_code_ != RIG_OK) {
|
|
697
749
|
error_message_ = rigerror(result_code_);
|
|
@@ -723,6 +775,8 @@ public:
|
|
|
723
775
|
: HamLibAsyncWorker(env, hamlib_instance), rx_vfo_(rx_vfo), split_(split), tx_vfo_(tx_vfo) {}
|
|
724
776
|
|
|
725
777
|
void Execute() override {
|
|
778
|
+
CHECK_RIG_VALID();
|
|
779
|
+
|
|
726
780
|
result_code_ = rig_set_split_vfo(hamlib_instance_->my_rig, rx_vfo_, split_, tx_vfo_);
|
|
727
781
|
if (result_code_ != RIG_OK) {
|
|
728
782
|
error_message_ = rigerror(result_code_);
|
|
@@ -755,6 +809,8 @@ public:
|
|
|
755
809
|
: HamLibAsyncWorker(env, hamlib_instance), split_(RIG_SPLIT_OFF), tx_vfo_(RIG_VFO_B), vfo_(vfo) {}
|
|
756
810
|
|
|
757
811
|
void Execute() override {
|
|
812
|
+
CHECK_RIG_VALID();
|
|
813
|
+
|
|
758
814
|
result_code_ = rig_get_split_vfo(hamlib_instance_->my_rig, vfo_, &split_, &tx_vfo_);
|
|
759
815
|
if (result_code_ != RIG_OK) {
|
|
760
816
|
error_message_ = rigerror(result_code_);
|
|
@@ -796,6 +852,8 @@ public:
|
|
|
796
852
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo) {}
|
|
797
853
|
|
|
798
854
|
void Execute() override {
|
|
855
|
+
CHECK_RIG_VALID();
|
|
856
|
+
|
|
799
857
|
result_code_ = rig_set_vfo(hamlib_instance_->my_rig, vfo_);
|
|
800
858
|
if (result_code_ != RIG_OK) {
|
|
801
859
|
error_message_ = rigerror(result_code_);
|
|
@@ -826,6 +884,8 @@ public:
|
|
|
826
884
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(0) {}
|
|
827
885
|
|
|
828
886
|
void Execute() override {
|
|
887
|
+
CHECK_RIG_VALID();
|
|
888
|
+
|
|
829
889
|
result_code_ = rig_get_vfo(hamlib_instance_->my_rig, &vfo_);
|
|
830
890
|
if (result_code_ != RIG_OK) {
|
|
831
891
|
// 提供更清晰的错误信息
|
|
@@ -887,6 +947,14 @@ public:
|
|
|
887
947
|
: HamLibAsyncWorker(env, hamlib_instance) {}
|
|
888
948
|
|
|
889
949
|
void Execute() override {
|
|
950
|
+
CHECK_RIG_VALID();
|
|
951
|
+
|
|
952
|
+
// 检查rig是否已经关闭
|
|
953
|
+
if (!hamlib_instance_->rig_is_open) {
|
|
954
|
+
result_code_ = RIG_OK; // 已经关闭,返回成功
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
|
|
890
958
|
result_code_ = rig_close(hamlib_instance_->my_rig);
|
|
891
959
|
if (result_code_ != RIG_OK) {
|
|
892
960
|
error_message_ = rigerror(result_code_);
|
|
@@ -916,14 +984,15 @@ public:
|
|
|
916
984
|
: HamLibAsyncWorker(env, hamlib_instance) {}
|
|
917
985
|
|
|
918
986
|
void Execute() override {
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
987
|
+
CHECK_RIG_VALID();
|
|
988
|
+
|
|
989
|
+
// rig_cleanup会自动调用rig_close,所以我们不需要重复调用
|
|
922
990
|
result_code_ = rig_cleanup(hamlib_instance_->my_rig);
|
|
923
991
|
if (result_code_ != RIG_OK) {
|
|
924
992
|
error_message_ = rigerror(result_code_);
|
|
925
993
|
} else {
|
|
926
994
|
hamlib_instance_->rig_is_open = false;
|
|
995
|
+
hamlib_instance_->my_rig = nullptr; // 重要:清空指针防止重复释放
|
|
927
996
|
}
|
|
928
997
|
}
|
|
929
998
|
|
|
@@ -949,6 +1018,8 @@ public:
|
|
|
949
1018
|
: HamLibAsyncWorker(env, hamlib_instance), scan_type_(scan_type), channel_(channel) {}
|
|
950
1019
|
|
|
951
1020
|
void Execute() override {
|
|
1021
|
+
CHECK_RIG_VALID();
|
|
1022
|
+
|
|
952
1023
|
result_code_ = rig_scan(hamlib_instance_->my_rig, RIG_VFO_CURR, scan_type_, channel_);
|
|
953
1024
|
if (result_code_ != RIG_OK) {
|
|
954
1025
|
error_message_ = rigerror(result_code_);
|
|
@@ -981,6 +1052,8 @@ public:
|
|
|
981
1052
|
: HamLibAsyncWorker(env, hamlib_instance) {}
|
|
982
1053
|
|
|
983
1054
|
void Execute() override {
|
|
1055
|
+
CHECK_RIG_VALID();
|
|
1056
|
+
|
|
984
1057
|
result_code_ = rig_scan(hamlib_instance_->my_rig, RIG_VFO_CURR, RIG_SCAN_STOP, 0);
|
|
985
1058
|
if (result_code_ != RIG_OK) {
|
|
986
1059
|
error_message_ = rigerror(result_code_);
|
|
@@ -1009,6 +1082,8 @@ public:
|
|
|
1009
1082
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_op_(vfo_op) {}
|
|
1010
1083
|
|
|
1011
1084
|
void Execute() override {
|
|
1085
|
+
CHECK_RIG_VALID();
|
|
1086
|
+
|
|
1012
1087
|
result_code_ = rig_vfo_op(hamlib_instance_->my_rig, RIG_VFO_CURR, vfo_op_);
|
|
1013
1088
|
if (result_code_ != RIG_OK) {
|
|
1014
1089
|
error_message_ = rigerror(result_code_);
|
|
@@ -1040,6 +1115,8 @@ public:
|
|
|
1040
1115
|
: HamLibAsyncWorker(env, hamlib_instance), antenna_(antenna), vfo_(vfo), option_(option) {}
|
|
1041
1116
|
|
|
1042
1117
|
void Execute() override {
|
|
1118
|
+
CHECK_RIG_VALID();
|
|
1119
|
+
|
|
1043
1120
|
result_code_ = rig_set_ant(hamlib_instance_->my_rig, vfo_, antenna_, option_);
|
|
1044
1121
|
if (result_code_ != RIG_OK) {
|
|
1045
1122
|
error_message_ = rigerror(result_code_);
|
|
@@ -1073,6 +1150,8 @@ public:
|
|
|
1073
1150
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), antenna_(antenna), antenna_curr_(0), antenna_tx_(0), antenna_rx_(0) {}
|
|
1074
1151
|
|
|
1075
1152
|
void Execute() override {
|
|
1153
|
+
CHECK_RIG_VALID();
|
|
1154
|
+
|
|
1076
1155
|
option_ = {0};
|
|
1077
1156
|
|
|
1078
1157
|
result_code_ = rig_get_ant(hamlib_instance_->my_rig, vfo_, antenna_, &option_, &antenna_curr_, &antenna_tx_, &antenna_rx_);
|
|
@@ -1118,6 +1197,8 @@ public:
|
|
|
1118
1197
|
: HamLibAsyncWorker(env, hamlib_instance), power_(power), freq_(freq), mode_(mode), mwpower_(0) {}
|
|
1119
1198
|
|
|
1120
1199
|
void Execute() override {
|
|
1200
|
+
CHECK_RIG_VALID();
|
|
1201
|
+
|
|
1121
1202
|
result_code_ = rig_power2mW(hamlib_instance_->my_rig, &mwpower_, power_, freq_, mode_);
|
|
1122
1203
|
if (result_code_ != RIG_OK) {
|
|
1123
1204
|
error_message_ = rigerror(result_code_);
|
|
@@ -1152,6 +1233,8 @@ public:
|
|
|
1152
1233
|
: HamLibAsyncWorker(env, hamlib_instance), mwpower_(mwpower), freq_(freq), mode_(mode), power_(0.0) {}
|
|
1153
1234
|
|
|
1154
1235
|
void Execute() override {
|
|
1236
|
+
CHECK_RIG_VALID();
|
|
1237
|
+
|
|
1155
1238
|
result_code_ = rig_mW2power(hamlib_instance_->my_rig, &power_, mwpower_, freq_, mode_);
|
|
1156
1239
|
if (result_code_ != RIG_OK) {
|
|
1157
1240
|
error_message_ = rigerror(result_code_);
|
|
@@ -1186,6 +1269,8 @@ public:
|
|
|
1186
1269
|
: HamLibAsyncWorker(env, hamlib_instance), tx_mode_(tx_mode), tx_width_(tx_width), vfo_(vfo) {}
|
|
1187
1270
|
|
|
1188
1271
|
void Execute() override {
|
|
1272
|
+
CHECK_RIG_VALID();
|
|
1273
|
+
|
|
1189
1274
|
result_code_ = rig_set_split_mode(hamlib_instance_->my_rig, vfo_, tx_mode_, tx_width_);
|
|
1190
1275
|
if (result_code_ != RIG_OK) {
|
|
1191
1276
|
error_message_ = rigerror(result_code_);
|
|
@@ -1219,6 +1304,8 @@ public:
|
|
|
1219
1304
|
: HamLibAsyncWorker(env, hamlib_instance), tx_mode_(0), tx_width_(0), vfo_(vfo) {}
|
|
1220
1305
|
|
|
1221
1306
|
void Execute() override {
|
|
1307
|
+
CHECK_RIG_VALID();
|
|
1308
|
+
|
|
1222
1309
|
result_code_ = rig_get_split_mode(hamlib_instance_->my_rig, vfo_, &tx_mode_, &tx_width_);
|
|
1223
1310
|
if (result_code_ != RIG_OK) {
|
|
1224
1311
|
error_message_ = rigerror(result_code_);
|
|
@@ -1257,6 +1344,8 @@ public:
|
|
|
1257
1344
|
: HamLibAsyncWorker(env, hamlib_instance), param_name_(param_name), param_value_(param_value) {}
|
|
1258
1345
|
|
|
1259
1346
|
void Execute() override {
|
|
1347
|
+
CHECK_RIG_VALID();
|
|
1348
|
+
|
|
1260
1349
|
// Apply serial configuration parameter
|
|
1261
1350
|
if (param_name_ == "data_bits") {
|
|
1262
1351
|
int data_bits = std::stoi(param_value_);
|
|
@@ -1414,6 +1503,8 @@ public:
|
|
|
1414
1503
|
: HamLibAsyncWorker(env, hamlib_instance), param_name_(param_name) {}
|
|
1415
1504
|
|
|
1416
1505
|
void Execute() override {
|
|
1506
|
+
CHECK_RIG_VALID();
|
|
1507
|
+
|
|
1417
1508
|
// Get serial configuration parameter
|
|
1418
1509
|
if (param_name_ == "data_bits") {
|
|
1419
1510
|
param_value_ = std::to_string(hamlib_instance_->my_rig->state.rigport.parm.serial.data_bits);
|
|
@@ -1529,6 +1620,8 @@ public:
|
|
|
1529
1620
|
: HamLibAsyncWorker(env, hamlib_instance), ptt_type_(ptt_type) {}
|
|
1530
1621
|
|
|
1531
1622
|
void Execute() override {
|
|
1623
|
+
CHECK_RIG_VALID();
|
|
1624
|
+
|
|
1532
1625
|
ptt_type_t ptt_type;
|
|
1533
1626
|
if (ptt_type_ == "RIG") {
|
|
1534
1627
|
ptt_type = RIG_PTT_RIG;
|
|
@@ -1581,6 +1674,8 @@ public:
|
|
|
1581
1674
|
: HamLibAsyncWorker(env, hamlib_instance) {}
|
|
1582
1675
|
|
|
1583
1676
|
void Execute() override {
|
|
1677
|
+
CHECK_RIG_VALID();
|
|
1678
|
+
|
|
1584
1679
|
ptt_type_t ptt_type = hamlib_instance_->my_rig->state.pttport.type.ptt;
|
|
1585
1680
|
|
|
1586
1681
|
switch (ptt_type) {
|
|
@@ -1640,6 +1735,8 @@ public:
|
|
|
1640
1735
|
: HamLibAsyncWorker(env, hamlib_instance), dcd_type_(dcd_type) {}
|
|
1641
1736
|
|
|
1642
1737
|
void Execute() override {
|
|
1738
|
+
CHECK_RIG_VALID();
|
|
1739
|
+
|
|
1643
1740
|
dcd_type_t dcd_type;
|
|
1644
1741
|
if (dcd_type_ == "RIG") {
|
|
1645
1742
|
dcd_type = RIG_DCD_RIG;
|
|
@@ -1694,6 +1791,8 @@ public:
|
|
|
1694
1791
|
: HamLibAsyncWorker(env, hamlib_instance) {}
|
|
1695
1792
|
|
|
1696
1793
|
void Execute() override {
|
|
1794
|
+
CHECK_RIG_VALID();
|
|
1795
|
+
|
|
1697
1796
|
dcd_type_t dcd_type = hamlib_instance_->my_rig->state.dcdport.type.dcd;
|
|
1698
1797
|
|
|
1699
1798
|
switch (dcd_type) {
|
|
@@ -1756,6 +1855,8 @@ public:
|
|
|
1756
1855
|
: HamLibAsyncWorker(env, hamlib_instance), status_(status) {}
|
|
1757
1856
|
|
|
1758
1857
|
void Execute() override {
|
|
1858
|
+
CHECK_RIG_VALID();
|
|
1859
|
+
|
|
1759
1860
|
result_code_ = rig_set_powerstat(hamlib_instance_->my_rig, status_);
|
|
1760
1861
|
if (result_code_ != RIG_OK) {
|
|
1761
1862
|
error_message_ = rigerror(result_code_);
|
|
@@ -1786,6 +1887,8 @@ public:
|
|
|
1786
1887
|
: HamLibAsyncWorker(env, hamlib_instance), status_(RIG_POWER_UNKNOWN) {}
|
|
1787
1888
|
|
|
1788
1889
|
void Execute() override {
|
|
1890
|
+
CHECK_RIG_VALID();
|
|
1891
|
+
|
|
1789
1892
|
result_code_ = rig_get_powerstat(hamlib_instance_->my_rig, &status_);
|
|
1790
1893
|
if (result_code_ != RIG_OK) {
|
|
1791
1894
|
error_message_ = rigerror(result_code_);
|
|
@@ -1817,6 +1920,8 @@ public:
|
|
|
1817
1920
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), ptt_(RIG_PTT_OFF) {}
|
|
1818
1921
|
|
|
1819
1922
|
void Execute() override {
|
|
1923
|
+
CHECK_RIG_VALID();
|
|
1924
|
+
|
|
1820
1925
|
result_code_ = rig_get_ptt(hamlib_instance_->my_rig, vfo_, &ptt_);
|
|
1821
1926
|
if (result_code_ != RIG_OK) {
|
|
1822
1927
|
error_message_ = rigerror(result_code_);
|
|
@@ -1849,6 +1954,8 @@ public:
|
|
|
1849
1954
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), dcd_(RIG_DCD_OFF) {}
|
|
1850
1955
|
|
|
1851
1956
|
void Execute() override {
|
|
1957
|
+
CHECK_RIG_VALID();
|
|
1958
|
+
|
|
1852
1959
|
result_code_ = rig_get_dcd(hamlib_instance_->my_rig, vfo_, &dcd_);
|
|
1853
1960
|
if (result_code_ != RIG_OK) {
|
|
1854
1961
|
error_message_ = rigerror(result_code_);
|
|
@@ -1881,6 +1988,8 @@ public:
|
|
|
1881
1988
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), ts_(ts) {}
|
|
1882
1989
|
|
|
1883
1990
|
void Execute() override {
|
|
1991
|
+
CHECK_RIG_VALID();
|
|
1992
|
+
|
|
1884
1993
|
result_code_ = rig_set_ts(hamlib_instance_->my_rig, vfo_, ts_);
|
|
1885
1994
|
if (result_code_ != RIG_OK) {
|
|
1886
1995
|
error_message_ = rigerror(result_code_);
|
|
@@ -1912,6 +2021,8 @@ public:
|
|
|
1912
2021
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), ts_(0) {}
|
|
1913
2022
|
|
|
1914
2023
|
void Execute() override {
|
|
2024
|
+
CHECK_RIG_VALID();
|
|
2025
|
+
|
|
1915
2026
|
result_code_ = rig_get_ts(hamlib_instance_->my_rig, vfo_, &ts_);
|
|
1916
2027
|
if (result_code_ != RIG_OK) {
|
|
1917
2028
|
error_message_ = rigerror(result_code_);
|
|
@@ -1944,6 +2055,8 @@ public:
|
|
|
1944
2055
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), shift_(shift) {}
|
|
1945
2056
|
|
|
1946
2057
|
void Execute() override {
|
|
2058
|
+
CHECK_RIG_VALID();
|
|
2059
|
+
|
|
1947
2060
|
result_code_ = rig_set_rptr_shift(hamlib_instance_->my_rig, vfo_, shift_);
|
|
1948
2061
|
if (result_code_ != RIG_OK) {
|
|
1949
2062
|
error_message_ = rigerror(result_code_);
|
|
@@ -1975,6 +2088,8 @@ public:
|
|
|
1975
2088
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), shift_(RIG_RPT_SHIFT_NONE) {}
|
|
1976
2089
|
|
|
1977
2090
|
void Execute() override {
|
|
2091
|
+
CHECK_RIG_VALID();
|
|
2092
|
+
|
|
1978
2093
|
result_code_ = rig_get_rptr_shift(hamlib_instance_->my_rig, vfo_, &shift_);
|
|
1979
2094
|
if (result_code_ != RIG_OK) {
|
|
1980
2095
|
error_message_ = rigerror(result_code_);
|
|
@@ -2003,6 +2118,8 @@ public:
|
|
|
2003
2118
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), offset_(offset) {}
|
|
2004
2119
|
|
|
2005
2120
|
void Execute() override {
|
|
2121
|
+
CHECK_RIG_VALID();
|
|
2122
|
+
|
|
2006
2123
|
result_code_ = rig_set_rptr_offs(hamlib_instance_->my_rig, vfo_, offset_);
|
|
2007
2124
|
if (result_code_ != RIG_OK) {
|
|
2008
2125
|
error_message_ = rigerror(result_code_);
|
|
@@ -2034,6 +2151,8 @@ public:
|
|
|
2034
2151
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), offset_(0) {}
|
|
2035
2152
|
|
|
2036
2153
|
void Execute() override {
|
|
2154
|
+
CHECK_RIG_VALID();
|
|
2155
|
+
|
|
2037
2156
|
result_code_ = rig_get_rptr_offs(hamlib_instance_->my_rig, vfo_, &offset_);
|
|
2038
2157
|
if (result_code_ != RIG_OK) {
|
|
2039
2158
|
error_message_ = rigerror(result_code_);
|
|
@@ -2157,6 +2276,21 @@ NodeHamLib::NodeHamLib(const Napi::CallbackInfo & info): ObjectWrap(info) {
|
|
|
2157
2276
|
rig_is_open = false;
|
|
2158
2277
|
}
|
|
2159
2278
|
|
|
2279
|
+
// 析构函数 - 确保资源正确清理
|
|
2280
|
+
NodeHamLib::~NodeHamLib() {
|
|
2281
|
+
// 如果rig指针存在,执行清理
|
|
2282
|
+
if (my_rig) {
|
|
2283
|
+
// 如果rig是打开状态,先关闭
|
|
2284
|
+
if (rig_is_open) {
|
|
2285
|
+
rig_close(my_rig);
|
|
2286
|
+
rig_is_open = false;
|
|
2287
|
+
}
|
|
2288
|
+
// 清理rig资源
|
|
2289
|
+
rig_cleanup(my_rig);
|
|
2290
|
+
my_rig = nullptr;
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2160
2294
|
int NodeHamLib::freq_change_cb(RIG *rig, vfo_t vfo, freq_t freq, void* arg) {
|
|
2161
2295
|
auto instance = static_cast<NodeHamLib*>(arg);
|
|
2162
2296
|
printf("Rig changed freq to %0.7f Hz\n", freq);
|
|
@@ -3976,6 +4110,8 @@ public:
|
|
|
3976
4110
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), tone_(tone) {}
|
|
3977
4111
|
|
|
3978
4112
|
void Execute() override {
|
|
4113
|
+
CHECK_RIG_VALID();
|
|
4114
|
+
|
|
3979
4115
|
result_code_ = rig_set_ctcss_tone(hamlib_instance_->my_rig, vfo_, tone_);
|
|
3980
4116
|
if (result_code_ != RIG_OK) {
|
|
3981
4117
|
error_message_ = rigerror(result_code_);
|
|
@@ -4007,6 +4143,8 @@ public:
|
|
|
4007
4143
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), tone_(0) {}
|
|
4008
4144
|
|
|
4009
4145
|
void Execute() override {
|
|
4146
|
+
CHECK_RIG_VALID();
|
|
4147
|
+
|
|
4010
4148
|
result_code_ = rig_get_ctcss_tone(hamlib_instance_->my_rig, vfo_, &tone_);
|
|
4011
4149
|
if (result_code_ != RIG_OK) {
|
|
4012
4150
|
error_message_ = rigerror(result_code_);
|
|
@@ -4038,6 +4176,8 @@ public:
|
|
|
4038
4176
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), code_(code) {}
|
|
4039
4177
|
|
|
4040
4178
|
void Execute() override {
|
|
4179
|
+
CHECK_RIG_VALID();
|
|
4180
|
+
|
|
4041
4181
|
result_code_ = rig_set_dcs_code(hamlib_instance_->my_rig, vfo_, code_);
|
|
4042
4182
|
if (result_code_ != RIG_OK) {
|
|
4043
4183
|
error_message_ = rigerror(result_code_);
|
|
@@ -4069,6 +4209,8 @@ public:
|
|
|
4069
4209
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), code_(0) {}
|
|
4070
4210
|
|
|
4071
4211
|
void Execute() override {
|
|
4212
|
+
CHECK_RIG_VALID();
|
|
4213
|
+
|
|
4072
4214
|
result_code_ = rig_get_dcs_code(hamlib_instance_->my_rig, vfo_, &code_);
|
|
4073
4215
|
if (result_code_ != RIG_OK) {
|
|
4074
4216
|
error_message_ = rigerror(result_code_);
|
|
@@ -4100,6 +4242,8 @@ public:
|
|
|
4100
4242
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), tone_(tone) {}
|
|
4101
4243
|
|
|
4102
4244
|
void Execute() override {
|
|
4245
|
+
CHECK_RIG_VALID();
|
|
4246
|
+
|
|
4103
4247
|
result_code_ = rig_set_ctcss_sql(hamlib_instance_->my_rig, vfo_, tone_);
|
|
4104
4248
|
if (result_code_ != RIG_OK) {
|
|
4105
4249
|
error_message_ = rigerror(result_code_);
|
|
@@ -4131,6 +4275,8 @@ public:
|
|
|
4131
4275
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), tone_(0) {}
|
|
4132
4276
|
|
|
4133
4277
|
void Execute() override {
|
|
4278
|
+
CHECK_RIG_VALID();
|
|
4279
|
+
|
|
4134
4280
|
result_code_ = rig_get_ctcss_sql(hamlib_instance_->my_rig, vfo_, &tone_);
|
|
4135
4281
|
if (result_code_ != RIG_OK) {
|
|
4136
4282
|
error_message_ = rigerror(result_code_);
|
|
@@ -4162,6 +4308,8 @@ public:
|
|
|
4162
4308
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), code_(code) {}
|
|
4163
4309
|
|
|
4164
4310
|
void Execute() override {
|
|
4311
|
+
CHECK_RIG_VALID();
|
|
4312
|
+
|
|
4165
4313
|
result_code_ = rig_set_dcs_sql(hamlib_instance_->my_rig, vfo_, code_);
|
|
4166
4314
|
if (result_code_ != RIG_OK) {
|
|
4167
4315
|
error_message_ = rigerror(result_code_);
|
|
@@ -4193,6 +4341,8 @@ public:
|
|
|
4193
4341
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), code_(0) {}
|
|
4194
4342
|
|
|
4195
4343
|
void Execute() override {
|
|
4344
|
+
CHECK_RIG_VALID();
|
|
4345
|
+
|
|
4196
4346
|
result_code_ = rig_get_dcs_sql(hamlib_instance_->my_rig, vfo_, &code_);
|
|
4197
4347
|
if (result_code_ != RIG_OK) {
|
|
4198
4348
|
error_message_ = rigerror(result_code_);
|
|
@@ -4225,6 +4375,8 @@ public:
|
|
|
4225
4375
|
: HamLibAsyncWorker(env, hamlib_instance), parm_(parm), value_(value) {}
|
|
4226
4376
|
|
|
4227
4377
|
void Execute() override {
|
|
4378
|
+
CHECK_RIG_VALID();
|
|
4379
|
+
|
|
4228
4380
|
result_code_ = rig_set_parm(hamlib_instance_->my_rig, parm_, value_);
|
|
4229
4381
|
if (result_code_ != RIG_OK) {
|
|
4230
4382
|
error_message_ = rigerror(result_code_);
|
|
@@ -4258,6 +4410,8 @@ public:
|
|
|
4258
4410
|
}
|
|
4259
4411
|
|
|
4260
4412
|
void Execute() override {
|
|
4413
|
+
CHECK_RIG_VALID();
|
|
4414
|
+
|
|
4261
4415
|
result_code_ = rig_get_parm(hamlib_instance_->my_rig, parm_, &value_);
|
|
4262
4416
|
if (result_code_ != RIG_OK) {
|
|
4263
4417
|
error_message_ = rigerror(result_code_);
|
|
@@ -4290,6 +4444,8 @@ public:
|
|
|
4290
4444
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), digits_(digits) {}
|
|
4291
4445
|
|
|
4292
4446
|
void Execute() override {
|
|
4447
|
+
CHECK_RIG_VALID();
|
|
4448
|
+
|
|
4293
4449
|
result_code_ = rig_send_dtmf(hamlib_instance_->my_rig, vfo_, digits_.c_str());
|
|
4294
4450
|
if (result_code_ != RIG_OK) {
|
|
4295
4451
|
error_message_ = rigerror(result_code_);
|
|
@@ -4323,8 +4479,11 @@ public:
|
|
|
4323
4479
|
}
|
|
4324
4480
|
|
|
4325
4481
|
void Execute() override {
|
|
4482
|
+
CHECK_RIG_VALID();
|
|
4483
|
+
|
|
4326
4484
|
length_ = max_length_;
|
|
4327
|
-
|
|
4485
|
+
// rig_recv_dtmf expects a mutable buffer (char*). Ensure non-const pointer.
|
|
4486
|
+
result_code_ = rig_recv_dtmf(hamlib_instance_->my_rig, vfo_, &digits_[0], &length_);
|
|
4328
4487
|
if (result_code_ != RIG_OK) {
|
|
4329
4488
|
error_message_ = rigerror(result_code_);
|
|
4330
4489
|
}
|
|
@@ -4361,6 +4520,8 @@ public:
|
|
|
4361
4520
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), ch_(0) {}
|
|
4362
4521
|
|
|
4363
4522
|
void Execute() override {
|
|
4523
|
+
CHECK_RIG_VALID();
|
|
4524
|
+
|
|
4364
4525
|
result_code_ = rig_get_mem(hamlib_instance_->my_rig, vfo_, &ch_);
|
|
4365
4526
|
if (result_code_ != RIG_OK) {
|
|
4366
4527
|
error_message_ = rigerror(result_code_);
|
|
@@ -4392,6 +4553,8 @@ public:
|
|
|
4392
4553
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), bank_(bank) {}
|
|
4393
4554
|
|
|
4394
4555
|
void Execute() override {
|
|
4556
|
+
CHECK_RIG_VALID();
|
|
4557
|
+
|
|
4395
4558
|
result_code_ = rig_set_bank(hamlib_instance_->my_rig, vfo_, bank_);
|
|
4396
4559
|
if (result_code_ != RIG_OK) {
|
|
4397
4560
|
error_message_ = rigerror(result_code_);
|
|
@@ -4423,6 +4586,8 @@ public:
|
|
|
4423
4586
|
: HamLibAsyncWorker(env, hamlib_instance), count_(0) {}
|
|
4424
4587
|
|
|
4425
4588
|
void Execute() override {
|
|
4589
|
+
CHECK_RIG_VALID();
|
|
4590
|
+
|
|
4426
4591
|
count_ = rig_mem_count(hamlib_instance_->my_rig);
|
|
4427
4592
|
if (count_ < 0) {
|
|
4428
4593
|
result_code_ = count_;
|
|
@@ -4457,6 +4622,8 @@ public:
|
|
|
4457
4622
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), msg_(msg) {}
|
|
4458
4623
|
|
|
4459
4624
|
void Execute() override {
|
|
4625
|
+
CHECK_RIG_VALID();
|
|
4626
|
+
|
|
4460
4627
|
result_code_ = rig_send_morse(hamlib_instance_->my_rig, vfo_, msg_.c_str());
|
|
4461
4628
|
if (result_code_ != RIG_OK) {
|
|
4462
4629
|
error_message_ = rigerror(result_code_);
|
|
@@ -4488,6 +4655,8 @@ public:
|
|
|
4488
4655
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo) {}
|
|
4489
4656
|
|
|
4490
4657
|
void Execute() override {
|
|
4658
|
+
CHECK_RIG_VALID();
|
|
4659
|
+
|
|
4491
4660
|
result_code_ = rig_stop_morse(hamlib_instance_->my_rig, vfo_);
|
|
4492
4661
|
if (result_code_ != RIG_OK) {
|
|
4493
4662
|
error_message_ = rigerror(result_code_);
|
|
@@ -4518,6 +4687,8 @@ public:
|
|
|
4518
4687
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo) {}
|
|
4519
4688
|
|
|
4520
4689
|
void Execute() override {
|
|
4690
|
+
CHECK_RIG_VALID();
|
|
4691
|
+
|
|
4521
4692
|
result_code_ = rig_wait_morse(hamlib_instance_->my_rig, vfo_);
|
|
4522
4693
|
if (result_code_ != RIG_OK) {
|
|
4523
4694
|
error_message_ = rigerror(result_code_);
|
|
@@ -4549,6 +4720,8 @@ public:
|
|
|
4549
4720
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), ch_(ch) {}
|
|
4550
4721
|
|
|
4551
4722
|
void Execute() override {
|
|
4723
|
+
CHECK_RIG_VALID();
|
|
4724
|
+
|
|
4552
4725
|
result_code_ = rig_send_voice_mem(hamlib_instance_->my_rig, vfo_, ch_);
|
|
4553
4726
|
if (result_code_ != RIG_OK) {
|
|
4554
4727
|
error_message_ = rigerror(result_code_);
|
|
@@ -4580,6 +4753,8 @@ public:
|
|
|
4580
4753
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo) {}
|
|
4581
4754
|
|
|
4582
4755
|
void Execute() override {
|
|
4756
|
+
CHECK_RIG_VALID();
|
|
4757
|
+
|
|
4583
4758
|
#if HAVE_RIG_STOP_VOICE_MEM
|
|
4584
4759
|
result_code_ = rig_stop_voice_mem(hamlib_instance_->my_rig, vfo_);
|
|
4585
4760
|
if (result_code_ != RIG_OK) {
|
|
@@ -4620,6 +4795,8 @@ public:
|
|
|
4620
4795
|
tx_mode_(tx_mode), tx_width_(tx_width) {}
|
|
4621
4796
|
|
|
4622
4797
|
void Execute() override {
|
|
4798
|
+
CHECK_RIG_VALID();
|
|
4799
|
+
|
|
4623
4800
|
#if HAVE_RIG_SPLIT_FREQ_MODE
|
|
4624
4801
|
result_code_ = rig_set_split_freq_mode(hamlib_instance_->my_rig, vfo_, tx_freq_, tx_mode_, tx_width_);
|
|
4625
4802
|
if (result_code_ != RIG_OK) {
|
|
@@ -4660,6 +4837,8 @@ public:
|
|
|
4660
4837
|
: HamLibAsyncWorker(env, hamlib_instance), vfo_(vfo), tx_freq_(0), tx_mode_(RIG_MODE_NONE), tx_width_(0) {}
|
|
4661
4838
|
|
|
4662
4839
|
void Execute() override {
|
|
4840
|
+
CHECK_RIG_VALID();
|
|
4841
|
+
|
|
4663
4842
|
#if HAVE_RIG_SPLIT_FREQ_MODE
|
|
4664
4843
|
result_code_ = rig_get_split_freq_mode(hamlib_instance_->my_rig, vfo_, &tx_freq_, &tx_mode_, &tx_width_);
|
|
4665
4844
|
if (result_code_ != RIG_OK) {
|
|
@@ -4705,6 +4884,8 @@ public:
|
|
|
4705
4884
|
: HamLibAsyncWorker(env, hamlib_instance), reset_(reset) {}
|
|
4706
4885
|
|
|
4707
4886
|
void Execute() override {
|
|
4887
|
+
CHECK_RIG_VALID();
|
|
4888
|
+
|
|
4708
4889
|
result_code_ = rig_reset(hamlib_instance_->my_rig, reset_);
|
|
4709
4890
|
if (result_code_ != RIG_OK) {
|
|
4710
4891
|
error_message_ = rigerror(result_code_);
|
|
@@ -5166,4 +5347,3 @@ Napi::Value NodeHamLib::Reset(const Napi::CallbackInfo& info) {
|
|
|
5166
5347
|
asyncWorker->Queue();
|
|
5167
5348
|
return asyncWorker->GetPromise();
|
|
5168
5349
|
}
|
|
5169
|
-
|
package/src/hamlib.h
CHANGED
|
@@ -31,6 +31,7 @@ protected:
|
|
|
31
31
|
class NodeHamLib : public Napi::ObjectWrap<NodeHamLib> {
|
|
32
32
|
public:
|
|
33
33
|
NodeHamLib(const Napi::CallbackInfo&);
|
|
34
|
+
~NodeHamLib(); // Add destructor declaration
|
|
34
35
|
Napi::Value Open(const Napi::CallbackInfo&);
|
|
35
36
|
Napi::Value SetVFO(const Napi::CallbackInfo&);
|
|
36
37
|
Napi::Value SetFrequency(const Napi::CallbackInfo&);
|
package/lib/binary-loader.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const os = require('os');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Get the platform-specific binary file name
|
|
7
|
-
* @returns {string} Platform-specific binary file name
|
|
8
|
-
*/
|
|
9
|
-
function getPlatformBinaryPath() {
|
|
10
|
-
const platform = os.platform();
|
|
11
|
-
const arch = os.arch();
|
|
12
|
-
|
|
13
|
-
let platformTarget;
|
|
14
|
-
|
|
15
|
-
switch (platform) {
|
|
16
|
-
case 'win32':
|
|
17
|
-
platformTarget = `win32-${arch}`;
|
|
18
|
-
break;
|
|
19
|
-
case 'darwin':
|
|
20
|
-
platformTarget = `darwin-${arch}`;
|
|
21
|
-
break;
|
|
22
|
-
case 'linux':
|
|
23
|
-
platformTarget = `linux-${arch}`;
|
|
24
|
-
break;
|
|
25
|
-
default:
|
|
26
|
-
throw new Error(`Unsupported platform: ${platform}-${arch}`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return path.join(__dirname, '..', 'prebuilds', platformTarget, 'hamlib.node');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Find and load the native hamlib module
|
|
34
|
-
* @returns {Object} Native hamlib module
|
|
35
|
-
*/
|
|
36
|
-
function loadNativeModule() {
|
|
37
|
-
const possiblePaths = [
|
|
38
|
-
// First try locally compiled binary (prioritize latest features)
|
|
39
|
-
path.join(__dirname, '..', 'build', 'Release', 'hamlib.node'),
|
|
40
|
-
path.join(__dirname, '..', 'build', 'Debug', 'hamlib.node'),
|
|
41
|
-
// Fallback to prebuilt binary
|
|
42
|
-
getPlatformBinaryPath(),
|
|
43
|
-
// Try different possible locations
|
|
44
|
-
path.join(__dirname, '..', 'hamlib.node'),
|
|
45
|
-
path.join(process.cwd(), 'hamlib.node'),
|
|
46
|
-
path.join(process.cwd(), 'build', 'Release', 'hamlib.node'),
|
|
47
|
-
path.join(process.cwd(), 'build', 'Debug', 'hamlib.node')
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
let lastError;
|
|
51
|
-
|
|
52
|
-
for (const binaryPath of possiblePaths) {
|
|
53
|
-
try {
|
|
54
|
-
if (fs.existsSync(binaryPath)) {
|
|
55
|
-
console.log(`Loading hamlib native module from: ${binaryPath}`);
|
|
56
|
-
return require(binaryPath);
|
|
57
|
-
}
|
|
58
|
-
} catch (error) {
|
|
59
|
-
lastError = error;
|
|
60
|
-
console.warn(`Failed to load hamlib from ${binaryPath}: ${error.message}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// If we get here, we couldn't find any working binary
|
|
65
|
-
const errorMessage = [
|
|
66
|
-
'Failed to load hamlib native module.',
|
|
67
|
-
'Tried the following paths:',
|
|
68
|
-
...possiblePaths.map(p => ` - ${p}`),
|
|
69
|
-
'',
|
|
70
|
-
'This may be due to one of the following reasons:',
|
|
71
|
-
'1. The prebuilt binary is not available for your platform',
|
|
72
|
-
'2. The module needs to be compiled from source',
|
|
73
|
-
'3. Missing system dependencies (libhamlib)',
|
|
74
|
-
'',
|
|
75
|
-
'To compile from source, run:',
|
|
76
|
-
' npm run build',
|
|
77
|
-
'',
|
|
78
|
-
'To install system dependencies:',
|
|
79
|
-
' Linux: sudo apt-get install libhamlib-dev',
|
|
80
|
-
' macOS: brew install hamlib',
|
|
81
|
-
' Windows: Install hamlib via vcpkg or from source'
|
|
82
|
-
].join('\n');
|
|
83
|
-
|
|
84
|
-
const error = new Error(errorMessage);
|
|
85
|
-
if (lastError) {
|
|
86
|
-
error.originalError = lastError;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
throw error;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
module.exports = {
|
|
93
|
-
loadNativeModule,
|
|
94
|
-
getPlatformBinaryPath
|
|
95
|
-
};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/scripts/install.js
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const { execSync } = require('child_process');
|
|
4
|
-
const { getPlatformBinaryPath } = require('../lib/binary-loader');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Check if a prebuilt binary exists for the current platform
|
|
8
|
-
*/
|
|
9
|
-
function checkPrebuiltBinary() {
|
|
10
|
-
try {
|
|
11
|
-
const binaryPath = getPlatformBinaryPath();
|
|
12
|
-
return fs.existsSync(binaryPath);
|
|
13
|
-
} catch (error) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Check if we can build from source
|
|
20
|
-
*/
|
|
21
|
-
function canBuildFromSource() {
|
|
22
|
-
try {
|
|
23
|
-
// Check if binding.gyp exists
|
|
24
|
-
const bindingGypPath = path.join(__dirname, '..', 'binding.gyp');
|
|
25
|
-
if (!fs.existsSync(bindingGypPath)) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Check if source files exist
|
|
30
|
-
const srcPath = path.join(__dirname, '..', 'src');
|
|
31
|
-
if (!fs.existsSync(srcPath)) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Check if node-gyp is available
|
|
36
|
-
try {
|
|
37
|
-
execSync('node-gyp --version', { stdio: 'ignore' });
|
|
38
|
-
return true;
|
|
39
|
-
} catch (error) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
} catch (error) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Check if we're in a MinGW environment
|
|
49
|
-
*/
|
|
50
|
-
function isMinGWEnvironment() {
|
|
51
|
-
return process.env.HAMLIB_ROOT === '/mingw64' ||
|
|
52
|
-
process.env.HAMLIB_ROOT === 'C:\\msys64\\mingw64' ||
|
|
53
|
-
process.env.MSYSTEM === 'MINGW64' ||
|
|
54
|
-
process.env.MINGW_PREFIX === '/mingw64' ||
|
|
55
|
-
process.env.MINGW_PREFIX === 'C:\\msys64\\mingw64';
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Check if hamlib is available in the system
|
|
60
|
-
*/
|
|
61
|
-
function checkHamlibAvailable() {
|
|
62
|
-
try {
|
|
63
|
-
if (isMinGWEnvironment()) {
|
|
64
|
-
// In MinGW environment, try to use pkg-config to check hamlib
|
|
65
|
-
try {
|
|
66
|
-
execSync('pkg-config --exists hamlib', { stdio: 'ignore' });
|
|
67
|
-
console.log('✓ Hamlib found via pkg-config');
|
|
68
|
-
return true;
|
|
69
|
-
} catch (pkgConfigError) {
|
|
70
|
-
// If pkg-config fails, try to check for specific files
|
|
71
|
-
// Note: In MSYS2, /mingw64 might be mapped differently for Node.js
|
|
72
|
-
console.log('pkg-config check failed, trying direct file checks...');
|
|
73
|
-
|
|
74
|
-
// Try common MSYS2 paths
|
|
75
|
-
const possiblePaths = [
|
|
76
|
-
'/mingw64/include/hamlib',
|
|
77
|
-
'C:/msys64/mingw64/include/hamlib',
|
|
78
|
-
'C:\\msys64\\mingw64\\include\\hamlib',
|
|
79
|
-
process.env.MINGW_PREFIX + '/include/hamlib',
|
|
80
|
-
process.env.HAMLIB_ROOT + '/include/hamlib'
|
|
81
|
-
].filter(Boolean);
|
|
82
|
-
|
|
83
|
-
for (const includePath of possiblePaths) {
|
|
84
|
-
try {
|
|
85
|
-
if (fs.existsSync(includePath)) {
|
|
86
|
-
console.log(`✓ Hamlib headers found at: ${includePath}`);
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
} catch (e) {
|
|
90
|
-
// Continue to next path
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// If all file checks fail, assume hamlib is available since we're in MinGW
|
|
95
|
-
// and the build process showed it was installed
|
|
96
|
-
console.log('Direct file checks failed, but assuming hamlib is available in MinGW environment');
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
} else {
|
|
100
|
-
// Check if hamlib is available in standard locations
|
|
101
|
-
const locations = [
|
|
102
|
-
'/usr/include/hamlib',
|
|
103
|
-
'/usr/local/include/hamlib',
|
|
104
|
-
'/opt/homebrew/include/hamlib'
|
|
105
|
-
];
|
|
106
|
-
return locations.some(location => fs.existsSync(location));
|
|
107
|
-
}
|
|
108
|
-
} catch (error) {
|
|
109
|
-
console.log('Error checking hamlib availability:', error.message);
|
|
110
|
-
// In MinGW environment, be more lenient since paths might be mapped differently
|
|
111
|
-
return isMinGWEnvironment();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Setup Windows dependencies if needed
|
|
117
|
-
*/
|
|
118
|
-
async function setupWindowsDependencies() {
|
|
119
|
-
// Skip if we're in MinGW environment - dependencies should already be set up
|
|
120
|
-
if (isMinGWEnvironment()) {
|
|
121
|
-
console.log('✓ MinGW environment detected, skipping Windows dependency setup...');
|
|
122
|
-
return checkHamlibAvailable();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Check if dependencies are already set up
|
|
126
|
-
if (process.env.HAMLIB_ROOT && fs.existsSync(process.env.HAMLIB_ROOT)) {
|
|
127
|
-
console.log('✓ Windows dependencies already set up, skipping...');
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
console.log('Setting up Windows dependencies...');
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
// Call PowerShell script instead of Node.js script
|
|
135
|
-
const scriptPath = path.join(__dirname, 'setup-windows-deps.ps1');
|
|
136
|
-
const command = `powershell -ExecutionPolicy Bypass -File "${scriptPath}"`;
|
|
137
|
-
|
|
138
|
-
console.log(`Running: ${command}`);
|
|
139
|
-
execSync(command, { stdio: 'inherit' });
|
|
140
|
-
|
|
141
|
-
console.log('✓ Windows dependencies setup completed');
|
|
142
|
-
return true;
|
|
143
|
-
} catch (error) {
|
|
144
|
-
console.error('✗ Failed to setup Windows dependencies:', error.message);
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Try to build from source
|
|
151
|
-
*/
|
|
152
|
-
async function buildFromSource() {
|
|
153
|
-
console.log('Building hamlib from source...');
|
|
154
|
-
|
|
155
|
-
try {
|
|
156
|
-
// Setup Windows dependencies first if on Windows and not in MinGW environment
|
|
157
|
-
if (process.platform === 'win32' && !isMinGWEnvironment()) {
|
|
158
|
-
const success = await setupWindowsDependencies();
|
|
159
|
-
if (!success) {
|
|
160
|
-
throw new Error('Windows dependencies setup failed');
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// For MinGW environment, verify hamlib is available
|
|
165
|
-
if (isMinGWEnvironment()) {
|
|
166
|
-
if (!checkHamlibAvailable()) {
|
|
167
|
-
throw new Error('Hamlib not found in MinGW environment. Please install hamlib first.');
|
|
168
|
-
}
|
|
169
|
-
console.log('✓ Hamlib found in MinGW environment');
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Build with node-gyp
|
|
173
|
-
execSync('node-gyp configure', { stdio: 'inherit' });
|
|
174
|
-
execSync('node-gyp build', { stdio: 'inherit' });
|
|
175
|
-
|
|
176
|
-
console.log('✓ Built hamlib successfully');
|
|
177
|
-
return true;
|
|
178
|
-
} catch (error) {
|
|
179
|
-
console.error('✗ Failed to build hamlib from source:', error.message);
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Main installation logic
|
|
186
|
-
*/
|
|
187
|
-
async function main() {
|
|
188
|
-
console.log('Installing node-hamlib...');
|
|
189
|
-
|
|
190
|
-
try {
|
|
191
|
-
// Try to find prebuilt binary first
|
|
192
|
-
const prebuiltPath = path.join(__dirname, '..', 'prebuilds');
|
|
193
|
-
const platform = process.platform;
|
|
194
|
-
const arch = process.arch;
|
|
195
|
-
|
|
196
|
-
let targetDir = '';
|
|
197
|
-
if (platform === 'win32' && arch === 'x64') {
|
|
198
|
-
targetDir = 'win32-x64';
|
|
199
|
-
} else if (platform === 'linux' && arch === 'x64') {
|
|
200
|
-
targetDir = 'linux-x64';
|
|
201
|
-
} else if (platform === 'linux' && arch === 'arm64') {
|
|
202
|
-
targetDir = 'linux-arm64';
|
|
203
|
-
} else if (platform === 'darwin' && arch === 'arm64') {
|
|
204
|
-
targetDir = 'darwin-arm64';
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const prebuiltBinary = path.join(prebuiltPath, targetDir, 'hamlib.node');
|
|
208
|
-
|
|
209
|
-
if (fs.existsSync(prebuiltBinary)) {
|
|
210
|
-
console.log('✓ Found prebuilt binary');
|
|
211
|
-
|
|
212
|
-
// Copy to build directory
|
|
213
|
-
const buildDir = path.join(__dirname, '..', 'build', 'Release');
|
|
214
|
-
if (!fs.existsSync(buildDir)) {
|
|
215
|
-
fs.mkdirSync(buildDir, { recursive: true });
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const targetPath = path.join(buildDir, 'hamlib.node');
|
|
219
|
-
fs.copyFileSync(prebuiltBinary, targetPath);
|
|
220
|
-
|
|
221
|
-
console.log('✓ Installation completed successfully');
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
console.log('⚠ No prebuilt binary found for your platform');
|
|
226
|
-
|
|
227
|
-
// Build from source
|
|
228
|
-
const success = await buildFromSource();
|
|
229
|
-
if (!success) {
|
|
230
|
-
throw new Error('Failed to build from source');
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
console.log('✓ Installation completed successfully');
|
|
234
|
-
|
|
235
|
-
} catch (error) {
|
|
236
|
-
console.error('❌ Installation failed!');
|
|
237
|
-
console.error('This could be due to:');
|
|
238
|
-
console.error('1. No prebuilt binary available for your platform');
|
|
239
|
-
console.error('2. Missing system dependencies (libhamlib-dev)');
|
|
240
|
-
console.error('3. Missing build tools (node-gyp, compiler)');
|
|
241
|
-
console.error('');
|
|
242
|
-
console.error('To resolve this:');
|
|
243
|
-
console.error('System dependencies:');
|
|
244
|
-
console.error(' Linux: sudo apt-get install libhamlib-dev');
|
|
245
|
-
console.error(' macOS: brew install hamlib');
|
|
246
|
-
console.error(' Windows: Install hamlib via vcpkg or from source');
|
|
247
|
-
console.error('');
|
|
248
|
-
console.error('Build tools:');
|
|
249
|
-
console.error(' npm install -g node-gyp');
|
|
250
|
-
console.error(' # Follow node-gyp platform-specific setup instructions');
|
|
251
|
-
|
|
252
|
-
process.exit(1);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Run only if this script is called directly
|
|
257
|
-
if (require.main === module) {
|
|
258
|
-
main().catch(error => {
|
|
259
|
-
console.error('Installation failed:', error);
|
|
260
|
-
process.exit(1);
|
|
261
|
-
});
|
|
262
|
-
}
|