@@ -2214,12 +2214,9 @@ NodeHamLib::NodeHamLib(const Napi::CallbackInfo & info): ObjectWrap(info) {
22142214 std::string portStr = info[1 ].As <Napi::String>().Utf8Value ();
22152215 strncpy (port_path, portStr.c_str (), HAMLIB_FILPATHLEN - 1 );
22162216 port_path[HAMLIB_FILPATHLEN - 1 ] = ' \0 ' ;
2217- } else {
2218- // If second argument exists but is not a string, treat it as debug level (backward compatibility)
2219- rig_set_debug_level (RIG_DEBUG_NONE);
22202217 }
2221- } else {
2222- rig_set_debug_level ( RIG_DEBUG_NONE);
2218+ // Note: Debug level is now controlled globally via HamLib.setDebugLevel()
2219+ // and set to RIG_DEBUG_NONE by default in addon initialization
22232220 }
22242221 // rig_model_t myrig_model;
22252222 // hamlib_port_t myport;
@@ -2241,19 +2238,21 @@ NodeHamLib::NodeHamLib(const Napi::CallbackInfo & info): ObjectWrap(info) {
22412238
22422239 // Check if port_path is a network address (contains colon)
22432240 is_network_rig = isNetworkAddress (port_path);
2244-
2241+
22452242 if (is_network_rig) {
22462243 // Use NETRIGCTL model for network connections
22472244 myrig_model = 2 ; // RIG_MODEL_NETRIGCTL
2248- printf ( " Using network connection to %s \n " , port_path);
2245+ // Network connection will be established on open()
22492246 }
22502247
22512248 my_rig = rig_init (myrig_model);
22522249 // int retcode = 0;
22532250 if (!my_rig) {
2254- fprintf (stderr, " Unknown rig num: %d\n " , myrig_model);
2255- fprintf (stderr, " Please check riglist.h\n " );
2256- Napi::TypeError::New (env, " Unable to Init Rig" ).ThrowAsJavaScriptException ();
2251+ // Create detailed error message
2252+ std::string errorMsg = " Unable to initialize rig (model: " +
2253+ std::to_string (myrig_model) +
2254+ " ). Please check if the model number is valid." ;
2255+ Napi::TypeError::New (env, errorMsg).ThrowAsJavaScriptException ();
22572256 }
22582257
22592258 // Set port path and type based on connection type
@@ -3724,6 +3723,8 @@ Napi::Function NodeHamLib::GetClass(Napi::Env env) {
37243723 // Static methods
37253724 NodeHamLib::StaticMethod (" getSupportedRigs" , & NodeHamLib::GetSupportedRigs),
37263725 NodeHamLib::StaticMethod (" getHamlibVersion" , & NodeHamLib::GetHamlibVersion),
3726+ NodeHamLib::StaticMethod (" setDebugLevel" , & NodeHamLib::SetDebugLevel),
3727+ NodeHamLib::StaticMethod (" getDebugLevel" , & NodeHamLib::GetDebugLevel),
37273728 });
37283729 constructor = Napi::Persistent (ret);
37293730 constructor.SuppressDestruct ();
@@ -3843,6 +3844,47 @@ Napi::Value NodeHamLib::GetHamlibVersion(const Napi::CallbackInfo& info) {
38433844 return Napi::String::New (env, hamlib_version2);
38443845}
38453846
3847+ // Set Hamlib debug level
3848+ // Debug levels: 0=NONE, 1=BUG, 2=ERR, 3=WARN, 4=VERBOSE, 5=TRACE
3849+ Napi::Value NodeHamLib::SetDebugLevel (const Napi::CallbackInfo& info) {
3850+ Napi::Env env = info.Env ();
3851+
3852+ if (info.Length () < 1 || !info[0 ].IsNumber ()) {
3853+ Napi::TypeError::New (env, " Debug level (number) required" ).ThrowAsJavaScriptException ();
3854+ return env.Undefined ();
3855+ }
3856+
3857+ int level = info[0 ].As <Napi::Number>().Int32Value ();
3858+
3859+ // Validate debug level (0-5)
3860+ if (level < 0 || level > 5 ) {
3861+ Napi::RangeError::New (env, " Debug level must be between 0 (NONE) and 5 (TRACE)" ).ThrowAsJavaScriptException ();
3862+ return env.Undefined ();
3863+ }
3864+
3865+ rig_set_debug ((enum rig_debug_level_e)level);
3866+
3867+ return env.Undefined ();
3868+ }
3869+
3870+ // Get current Hamlib debug level
3871+ Napi::Value NodeHamLib::GetDebugLevel (const Napi::CallbackInfo& info) {
3872+ Napi::Env env = info.Env ();
3873+
3874+ // hamlib_get_debug() is not available in all versions, so we use a workaround
3875+ // by calling rig_debug_level which is a global variable in hamlib
3876+ // However, this is internal implementation, so we use rig_debug with RIG_DEBUG_NONE
3877+ // to get the current level. For now, we'll just return a note that this is not
3878+ // directly accessible. In practice, applications should track the level they set.
3879+
3880+ // Since there's no public API to query debug level in Hamlib,
3881+ // we'll document that users should track it themselves
3882+ Napi::Error::New (env,
3883+ " Getting debug level is not supported by Hamlib API. "
3884+ " Please track the debug level you set using setDebugLevel()." ).ThrowAsJavaScriptException ();
3885+ return env.Undefined ();
3886+ }
3887+
38463888// Serial Port Configuration Methods
38473889
38483890// Set serial configuration parameter (data_bits, stop_bits, parity, handshake, etc.)
0 commit comments