From b1a1173075fb9486947461f86e9743714fabed2c Mon Sep 17 00:00:00 2001 From: linuswck Date: Mon, 25 Mar 2024 12:27:35 +0800 Subject: [PATCH] cmd_handler: Add newline at the end of json sent --- src/net/cmd_handler.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/net/cmd_handler.rs b/src/net/cmd_handler.rs index f4bf0b5..2668013 100644 --- a/src/net/cmd_handler.rs +++ b/src/net/cmd_handler.rs @@ -179,7 +179,9 @@ pub fn send_response(buffer: &mut [u8], msg_type: ResponseEnum, msg: MsgType, so }; debug!("{:?}", response.json); - let num_bytes = response.get_json("/json", buffer).unwrap(); + let mut num_bytes = response.get_json("/json", buffer).unwrap(); + buffer[num_bytes] = b'\n'; + num_bytes += 1; net::eth_send(buffer, num_bytes, *socket); } @@ -190,7 +192,9 @@ pub fn send_settings_summary(buffer: &mut [u8], laser: &mut LdDrive, thermostat: thermostat: thermostat.get_settings_summary(), } }; - let num_bytes = settings_summary.get_json("/json", buffer).unwrap(); + let mut num_bytes = settings_summary.get_json("/json", buffer).unwrap(); + buffer[num_bytes] = b'\n'; + num_bytes += 1; net::eth_send(buffer, num_bytes, *socket); } @@ -203,7 +207,9 @@ pub fn send_status_report(buffer: &mut [u8], laser: &mut LdDrive, thermostat: &m thermostat: thermostat.get_status_report(), } }; - let num_bytes = status_report.get_json("/json", buffer).unwrap(); + let mut num_bytes = status_report.get_json("/json", buffer).unwrap(); + buffer[num_bytes] = b'\n'; + num_bytes += 1; net::eth_send(buffer, num_bytes, *socket); }