cmd_handler: Add msg to InvalidCmd Response

This commit is contained in:
linuswck 2025-01-22 15:48:46 +08:00
parent 9bec46490d
commit 7f9dc37c10

View File

@ -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_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_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_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)] #[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)]
pub struct CmdJsonObj { pub struct CmdJsonObj {
@ -369,6 +370,10 @@ pub fn execute_cmd(
info!("############ Thermostat Command Received {:?}", cmd.json.thermostat_cmd); info!("############ Thermostat Command Received {:?}", cmd.json.thermostat_cmd);
info!("############ Device Command Received {:?}", cmd.json.device_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 { match cmd.json.device_cmd {
Some(DeviceCmd::SetIPSettings) => match cmd.json.ip_settings { Some(DeviceCmd::SetIPSettings) => match cmd.json.ip_settings {
Some(val) => { Some(val) => {
@ -456,8 +461,7 @@ pub fn execute_cmd(
} }
None => { /* Do Nothing */ } None => { /* Do Nothing */ }
_ => { _ => {
send_response(buffer, ResponseEnum::InvalidCmd, None, socket); send_response(buffer, ResponseEnum::InvalidCmd, Some(ERR_MSG_CMD_NOT_FOUND), socket);
debug!("Unimplemented Command")
} }
} }
@ -580,8 +584,7 @@ pub fn execute_cmd(
} }
None => { /* Do Nothing*/ } None => { /* Do Nothing*/ }
_ => { _ => {
send_response(buffer, ResponseEnum::InvalidCmd, Some(ERR_MSG_MISSING_DATA_F32), socket); send_response(buffer, ResponseEnum::InvalidCmd, Some(ERR_MSG_CMD_NOT_FOUND), socket);
info!("Unimplemented Command")
} }
} }
@ -907,13 +910,13 @@ pub fn execute_cmd(
}, },
None => { /* Do Nothing*/ } None => { /* Do Nothing*/ }
_ => { _ => {
send_response(buffer, ResponseEnum::InvalidCmd, None, socket); send_response(buffer, ResponseEnum::InvalidCmd, Some(ERR_MSG_CMD_NOT_FOUND), socket);
} }
} }
} }
Err(_) => { Err(_) => {
info!("cmd_recv: {:?}", buffer); info!("cmd_recv: {:?}", buffer);
send_response(buffer, ResponseEnum::InvalidCmd, None, socket); send_response(buffer, ResponseEnum::InvalidCmd, Some(ERR_MSG_CMD_NOT_FOUND), socket);
} }
} }
} }