mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-25 20:07:51 +02:00
Fixed scripting + cleaner code + fixed RTLTCP
This commit is contained in:
@ -129,6 +129,21 @@ private:
|
||||
|
||||
duk_push_c_function(dukCtx, duk_setDemodulator, 1);
|
||||
duk_put_prop_string(dukCtx, objId, "setDemodulator");
|
||||
|
||||
duk_push_c_function(dukCtx, duk_getDemodulator, 0);
|
||||
duk_put_prop_string(dukCtx, objId, "getDemodulator");
|
||||
|
||||
duk_push_c_function(dukCtx, duk_setBandwidth, 1);
|
||||
duk_put_prop_string(dukCtx, objId, "setBandwidth");
|
||||
|
||||
duk_push_c_function(dukCtx, duk_getBandwidth, 0);
|
||||
duk_put_prop_string(dukCtx, objId, "getBandwidth");
|
||||
|
||||
duk_push_c_function(dukCtx, duk_getMaxBandwidth, 0);
|
||||
duk_put_prop_string(dukCtx, objId, "getMaxBandwidth");
|
||||
|
||||
duk_push_c_function(dukCtx, duk_getMinBandwidth, 0);
|
||||
duk_put_prop_string(dukCtx, objId, "getMinBandwidth");
|
||||
|
||||
duk_push_pointer(dukCtx, ctx);
|
||||
duk_put_prop_string(dukCtx, objId, DUK_HIDDEN_SYMBOL("radio_ctx"));
|
||||
@ -138,17 +153,159 @@ private:
|
||||
const char* str = duk_require_string(dukCtx, -1);
|
||||
std::string modName = str;
|
||||
|
||||
if (modName == "USB") {
|
||||
duk_push_this(dukCtx);
|
||||
if (!duk_get_prop_literal(dukCtx, -1, DUK_HIDDEN_SYMBOL("radio_ctx"))) {
|
||||
printf("COULD NOT RETRIEVE POINTER\n");
|
||||
}
|
||||
|
||||
RadioModule* _this = (RadioModule*)duk_require_pointer(dukCtx, -1);
|
||||
|
||||
duk_pop_n(dukCtx, 3); // Pop demod name, this and context
|
||||
|
||||
if (modName == "NFM") {
|
||||
_this->demod = 0;
|
||||
_this->bandWidth = 16000;
|
||||
_this->bandWidthMin = 8000;
|
||||
_this->bandWidthMax = 16000;
|
||||
_this->sigPath.setDemodulator(SigPath::DEMOD_NFM, _this->bandWidth);
|
||||
}
|
||||
else if (modName == "WFM") {
|
||||
_this->demod = 1;
|
||||
_this->bandWidth = 200000;
|
||||
_this->bandWidthMin = 100000;
|
||||
_this->bandWidthMax = 200000;
|
||||
_this->sigPath.setDemodulator(SigPath::DEMOD_FM, _this->bandWidth);
|
||||
}
|
||||
else if (modName == "AM") {
|
||||
_this->demod = 2;
|
||||
_this->bandWidth = 12500;
|
||||
_this->bandWidthMin = 6250;
|
||||
_this->bandWidthMax = 12500;
|
||||
_this->sigPath.setDemodulator(SigPath::DEMOD_AM, _this->bandWidth);
|
||||
}
|
||||
else if (modName == "DSB") {
|
||||
_this->demod = 3;
|
||||
_this->bandWidth = 6000;
|
||||
_this->bandWidthMin = 3000;
|
||||
_this->bandWidthMax = 6000;
|
||||
_this->sigPath.setDemodulator(SigPath::DEMOD_DSB, _this->bandWidth);
|
||||
}
|
||||
else if (modName == "USB") {
|
||||
_this->demod = 4;
|
||||
_this->bandWidth = 3000;
|
||||
_this->bandWidthMin = 1500;
|
||||
_this->bandWidthMax = 3000;
|
||||
_this->sigPath.setDemodulator(SigPath::DEMOD_USB, _this->bandWidth);
|
||||
}
|
||||
else if (modName == "CW") { _this->demod = 5; }
|
||||
else if (modName == "LSB") {
|
||||
_this->demod = 6;
|
||||
_this->bandWidth = 3000;
|
||||
_this->bandWidthMin = 1500;
|
||||
_this->bandWidthMax = 3000;
|
||||
_this->sigPath.setDemodulator(SigPath::DEMOD_LSB, _this->bandWidth);
|
||||
}
|
||||
else if (modName == "RAW") {
|
||||
_this->demod = 7;
|
||||
_this->bandWidth = 10000;
|
||||
_this->bandWidthMin = 3000;
|
||||
_this->bandWidthMax = 10000;
|
||||
_this->sigPath.setDemodulator(SigPath::DEMOD_RAW, _this->bandWidth);
|
||||
}
|
||||
else {
|
||||
duk_push_string(dukCtx, "Invalid demodulator name");
|
||||
duk_throw(dukCtx);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static duk_ret_t duk_getDemodulator(duk_context* dukCtx) {
|
||||
duk_push_this(dukCtx);
|
||||
if (!duk_get_prop_literal(dukCtx, -1, DUK_HIDDEN_SYMBOL("radio_ctx"))) {
|
||||
printf("COULD NOT RETRIEVE POINTER\n");
|
||||
}
|
||||
|
||||
RadioModule* _this = (RadioModule*)duk_require_pointer(dukCtx, -1);
|
||||
|
||||
duk_pop_n(dukCtx, 2); // Pop demod name, this and context
|
||||
|
||||
const char* demodNames[] = {"NFM", "WFM", "AM", "DSB", "USB", "CW", "LSB", "RAW"};
|
||||
|
||||
duk_push_string(dukCtx, demodNames[_this->demod]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static duk_ret_t duk_setBandwidth(duk_context* dukCtx) {
|
||||
double bandwidth = duk_require_number(dukCtx, -1);
|
||||
|
||||
duk_push_this(dukCtx);
|
||||
if (!duk_get_prop_literal(dukCtx, -1, DUK_HIDDEN_SYMBOL("radio_ctx"))) {
|
||||
printf("COULD NOT RETRIEVE POINTER\n");
|
||||
}
|
||||
|
||||
RadioModule* _this = (RadioModule*)duk_require_pointer(dukCtx, -1);
|
||||
|
||||
duk_pop_n(dukCtx, 3); // Pop demod name, this and context
|
||||
|
||||
if (bandwidth > _this->bandWidthMax || bandwidth < _this->bandWidthMin) {
|
||||
duk_push_string(dukCtx, "Bandwidth out of range");
|
||||
duk_throw(dukCtx);
|
||||
}
|
||||
|
||||
_this->bandWidth = bandwidth;
|
||||
_this->bandWidth = std::clamp<int>(_this->bandWidth, _this->bandWidthMin, _this->bandWidthMax);
|
||||
_this->sigPath.setBandwidth(_this->bandWidth);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static duk_ret_t duk_getBandwidth(duk_context* dukCtx) {
|
||||
duk_push_this(dukCtx);
|
||||
if (!duk_get_prop_literal(dukCtx, -1, DUK_HIDDEN_SYMBOL("radio_ctx"))) {
|
||||
printf("COULD NOT RETRIEVE POINTER\n");
|
||||
}
|
||||
|
||||
RadioModule* _this = (RadioModule*)duk_require_pointer(dukCtx, -1);
|
||||
|
||||
duk_pop_n(dukCtx, 2); // Pop demod name, this and context
|
||||
|
||||
duk_push_number(dukCtx, _this->bandWidth);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static duk_ret_t duk_getMaxBandwidth(duk_context* dukCtx) {
|
||||
duk_push_this(dukCtx);
|
||||
if (!duk_get_prop_literal(dukCtx, -1, DUK_HIDDEN_SYMBOL("radio_ctx"))) {
|
||||
printf("COULD NOT RETRIEVE POINTER\n");
|
||||
}
|
||||
|
||||
RadioModule* _this = (RadioModule*)duk_require_pointer(dukCtx, -1);
|
||||
|
||||
duk_pop_n(dukCtx, 2); // Pop demod name, this and context
|
||||
|
||||
duk_push_number(dukCtx, _this->bandWidthMax);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static duk_ret_t duk_getMinBandwidth(duk_context* dukCtx) {
|
||||
duk_push_this(dukCtx);
|
||||
if (!duk_get_prop_literal(dukCtx, -1, DUK_HIDDEN_SYMBOL("radio_ctx"))) {
|
||||
printf("COULD NOT RETRIEVE POINTER\n");
|
||||
}
|
||||
|
||||
RadioModule* _this = (RadioModule*)duk_require_pointer(dukCtx, -1);
|
||||
|
||||
duk_pop_n(dukCtx, 2); // Pop demod name, this and context
|
||||
|
||||
duk_push_number(dukCtx, _this->bandWidthMin);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string name;
|
||||
int demod = 1;
|
||||
int deemp = 0;
|
||||
|
Reference in New Issue
Block a user