From 7f9dc37c107e0f2125e155a7c4672886cc695a66 Mon Sep 17 00:00:00 2001 From: linuswck Date: Wed, 22 Jan 2025 15:48:46 +0800 Subject: [PATCH] cmd_handler: Add msg to InvalidCmd Response --- src/net/cmd_handler.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/net/cmd_handler.rs b/src/net/cmd_handler.rs index cae85d0..78c5566 100644 --- a/src/net/cmd_handler.rs +++ b/src/net/cmd_handler.rs @@ -163,6 +163,7 @@ const ERR_MSG_MISSING_POSTFILTER: &str = "Required field \"PostFilter\" does not const ERR_MSG_MISSING_SINC3FINEODR: &str = "Required field \"sinc3fineodr\" does not exist"; const ERR_MSG_INVALID_PDMON_SETTINGS: &str = "Invalid PD Mon Parameter Setting(s)"; const ERR_MSG_INVALID_LD_PWR_LIMIT_SETTING: &str = "Invalid LD Power Limit Setting"; +const ERR_MSG_CMD_NOT_FOUND: &str = "Command Not Found"; #[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)] pub struct CmdJsonObj { @@ -369,6 +370,10 @@ pub fn execute_cmd( info!("############ Thermostat Command Received {:?}", cmd.json.thermostat_cmd); info!("############ Device Command Received {:?}", cmd.json.device_cmd); + if cmd.json.laser_diode_cmd.is_none() && cmd.json.thermostat_cmd.is_none() && cmd.json.device_cmd.is_none() { + send_response(buffer, ResponseEnum::InvalidCmd, Some(ERR_MSG_CMD_NOT_FOUND), socket); + } + match cmd.json.device_cmd { Some(DeviceCmd::SetIPSettings) => match cmd.json.ip_settings { Some(val) => { @@ -456,8 +461,7 @@ pub fn execute_cmd( } None => { /* Do Nothing */ } _ => { - send_response(buffer, ResponseEnum::InvalidCmd, None, socket); - debug!("Unimplemented Command") + send_response(buffer, ResponseEnum::InvalidCmd, Some(ERR_MSG_CMD_NOT_FOUND), socket); } } @@ -580,8 +584,7 @@ pub fn execute_cmd( } None => { /* Do Nothing*/ } _ => { - send_response(buffer, ResponseEnum::InvalidCmd, Some(ERR_MSG_MISSING_DATA_F32), socket); - info!("Unimplemented Command") + send_response(buffer, ResponseEnum::InvalidCmd, Some(ERR_MSG_CMD_NOT_FOUND), socket); } } @@ -907,13 +910,13 @@ pub fn execute_cmd( }, None => { /* Do Nothing*/ } _ => { - send_response(buffer, ResponseEnum::InvalidCmd, None, socket); + send_response(buffer, ResponseEnum::InvalidCmd, Some(ERR_MSG_CMD_NOT_FOUND), socket); } } } Err(_) => { info!("cmd_recv: {:?}", buffer); - send_response(buffer, ResponseEnum::InvalidCmd, None, socket); + send_response(buffer, ResponseEnum::InvalidCmd, Some(ERR_MSG_CMD_NOT_FOUND), socket); } } }