From a7ef30e16bf603a93a85b3775a3fc2013ea2ffd6 Mon Sep 17 00:00:00 2001 From: cuu Date: Thu, 10 Feb 2022 14:35:45 +0800 Subject: [PATCH] correctly read utf8 string into int32_t --- Code/thermal_printer/devterm_thermal_printer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Code/thermal_printer/devterm_thermal_printer.c b/Code/thermal_printer/devterm_thermal_printer.c index 82ad8cd..f529033 100644 --- a/Code/thermal_printer/devterm_thermal_printer.c +++ b/Code/thermal_printer/devterm_thermal_printer.c @@ -691,16 +691,17 @@ void parse_serial_stream(CONFIG*cfg,uint8_t input_ch){ if(bskip == 1) { //append this to int32_t [8:8:8:8] 0xffffffff 4294967295 - ser_cache.data[ser_cache.idx] |= input_ch << (8 * (ser_cache.utf8idx+1)); - ser_cache.utf8idx++; - if( ser_cache.utf8idx >= get_slice_len( ser_cache.data[ser_cache.idx] & 0xff) ) { - ser_cache_idx++; + ser_cache.data[ser_cache.idx] |= input_ch << (8 * (ser_cache.utf8idx)); + if( ser_cache.utf8idx == get_slice_len( ser_cache.data[ser_cache.idx] & 0xff) -1 ) { + ser_cache.idx++; ser_cache.utf8idx=0;//next character + }else { + ser_cache.utf8idx++; } } if(bskip > 1) { - ser_cache.utf8idx =0; + ser_cache.utf8idx =1; ser_cache.data[ser_cache.idx] = input_ch; }