From ef6c6a018625030416fe9343a87752b162c98fa7 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Fri, 23 Feb 2024 15:59:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=A1=E6=AD=A3=E6=95=B0=E6=8D=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=ADUTF8=E5=AD=97=E7=AC=A6=E8=BD=ACWEB-UTF?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=EF=BC=9B=E5=A2=9E=E5=8A=A0=E6=B8=85=E7=90=86?= =?UTF-8?q?=E7=BA=B8=E9=81=93=E5=8A=9F=E8=83=BD=EF=BC=9B=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hardware/cis/cis_param.cpp | 25 +++++-- hardware/hardware.cpp | 15 +++++ hardware/hardware.h | 1 + imgproc/imgprc_mgr.cpp | 25 ++++++- imgproc/imgprc_mgr.h | 1 + scanner/async_scanner.cpp | 4 ++ sdk/base/ui.h | 2 + sdk/base/utils.cpp | 129 ++++++++++++++++++++++++++++++++++++- sdk/base/utils.h | 31 +++++++++ ui/dev_menu.cpp | 2 + ui/font.cpp | 10 +++ xmake.lua | 4 +- 12 files changed, 235 insertions(+), 14 deletions(-) diff --git a/hardware/cis/cis_param.cpp b/hardware/cis/cis_param.cpp index 5fad2aa..c302fcb 100644 --- a/hardware/cis/cis_param.cpp +++ b/hardware/cis/cis_param.cpp @@ -195,7 +195,7 @@ namespace correct else return l.clr > r.clr; } - + std::vector load_old_correct_data(const char* file, std::vector* dpis = nullptr) { std::vector old; @@ -276,12 +276,23 @@ namespace correct return std::move(old); } + int save_correct_data(CORDATA& data, std::vector& fixed_dpi, int init_dpi, bool init_clr) { correct::CONDDATA def; int err = 0; - std::string root(CIS_CORRECT_DATA_PATH), cont(""); + std::string root(CIS_CORRECT_DATA_PATH), cont(""), + clr(""), gray(""); gb_json *init = new gb_json(); + uint8_t *utf8 = (uint8_t*)WORDS_COLOR_COLOR; + + err = utils::utf8_2_web(utf8, clr); + if(err) + clr = WORDS_COLOR_COLOR; + utf8 = (uint8_t*)WORDS_COLOR_GRAY; + err = utils::utf8_2_web(utf8, gray); + if(err) + gray = WORDS_COLOR_GRAY; for(auto& item: data.data) { @@ -293,9 +304,9 @@ namespace correct key += "=="; if(item.clr) - key += WORDS_COLOR_COLOR; + key += clr; else - key += WORDS_COLOR_GRAY; + key += gray; key += "&&"; if(fixed_dpi.size()) { @@ -446,11 +457,11 @@ namespace cis child->get_value("default", def); if(def) { - printf("Before: %s\n", child->to_string().c_str()); + utils::to_log(LOG_LEVEL_ALL, "Correction-data of '%s' Before: %s\n", v, child->to_string().c_str()); def->attach_text(&data[0]); def->key() = "default"; def->release(); - printf("After: %s\n", child->to_string().c_str()); + utils::to_log(LOG_LEVEL_ALL, "Correction-data of '%s' After: %s\n", v, child->to_string().c_str()); } } child->release(); @@ -474,9 +485,11 @@ namespace cis child->get_value("default", def); if(def) { + utils::to_log(LOG_LEVEL_ALL, "Correction-data of '%s' Before: %s\n", fn.c_str(), child->to_string().c_str()); def->attach_text(&data[0]); def->key() = "default"; def->release(); + utils::to_log(LOG_LEVEL_ALL, "Correction-data of '%s' After: %s\n", fn.c_str(), child->to_string().c_str()); } } child->release(); diff --git a/hardware/hardware.cpp b/hardware/hardware.cpp index 8f1b0aa..43b9de0 100644 --- a/hardware/hardware.cpp +++ b/hardware/hardware.cpp @@ -1045,3 +1045,18 @@ bool scanner_hw::is_scanning(void) { return scanning_; } +void scanner_hw::clean_paper_passway(void) +{ + if(!motor_.get()) + { + auto cb = [this](int ev, unsigned int data) -> void + { + mb_events_.save(std::make_pair(ev, data), true); + }; + mb_events_.clear(); + motor_.reset(new MotorBoard(cb)); + } + + motor_->clean_paper_road(); +} + diff --git a/hardware/hardware.h b/hardware/hardware.h index e6c45a1..ac366e1 100644 --- a/hardware/hardware.h +++ b/hardware/hardware.h @@ -127,4 +127,5 @@ public: int trans_motorboard_err_2_hg_error(int mberr, bool to_ui = false, std::function bef_ui = std::function()); int hg_err_2_image_status(int hgerr); bool is_scanning(void); + void clean_paper_passway(void); }; diff --git a/imgproc/imgprc_mgr.cpp b/imgproc/imgprc_mgr.cpp index 3031ce2..af8ba67 100644 --- a/imgproc/imgprc_mgr.cpp +++ b/imgproc/imgprc_mgr.cpp @@ -147,10 +147,10 @@ void imgproc_mgr::process(RAWIMG* img) for(auto& v: processors_) { - send_image(*src, false); + send_image(*src, false); if(v->is_enable()) { - v->process(*src, *dst); + process(v, src, dst); src->clear(); swp = src; src = dst; @@ -165,7 +165,7 @@ void imgproc_mgr::process(RAWIMG* img) { if(v->is_enable()) { - v->process(*src, *dst); + process(v, src, dst); src->clear(); swp = src; src = dst; @@ -196,6 +196,25 @@ void imgproc_mgr::process(RAWIMG* img) ptr->release(); } } +void imgproc_mgr::process(image_processor* prc, std::vector* in, std::vector* out) +{ + try + { + prc->process(*in, *out); + } + catch(const exception_ex& e) + { + std::string msg(std::string("image process '") + prc->from() + "': " + e.what()); + + throw(exception_ex(msg.c_str())); + } + catch(const std::exception& e) + { + std::string msg(std::string("image process '") + prc->from() + "': " + e.what()); + + throw(exception_ex(msg.c_str())); + } +} void imgproc_mgr::send_image(LPPACKIMAGE head, uint8_t* data, size_t size, void* info, size_t info_l) { auto ovr = [&](uint64_t total, uint64_t cur_size, uint32_t err, void* user_data) -> int diff --git a/imgproc/imgprc_mgr.h b/imgproc/imgprc_mgr.h index 51d1040..1f07dba 100644 --- a/imgproc/imgprc_mgr.h +++ b/imgproc/imgprc_mgr.h @@ -51,6 +51,7 @@ class imgproc_mgr : public sane_opt_provider uint32_t add_busy_worker(int inc = 1); void thread_worker(void); void process(RAWIMG* img); + void process(image_processor* prc, std::vector* in, std::vector* out); void send_image(LPPACKIMAGE head, uint8_t* data, size_t size, void* info = nullptr, size_t info_l = 0); void send_image(std::vector& imgs, bool clear_after_send); diff --git a/scanner/async_scanner.cpp b/scanner/async_scanner.cpp index ff6dc42..5008329 100644 --- a/scanner/async_scanner.cpp +++ b/scanner/async_scanner.cpp @@ -303,6 +303,10 @@ void async_scanner::init(void) bool auto_scan = false; cis_->set_value(SANE_OPT_NAME(WAIT_TO_SCAN), &auto_scan); } + else if(devui::UI_CMD_CLEAN_PASSWAY == pack->msg) + { + cis_->clean_paper_passway(); + } }; devui::init_ui(uicb, false); diff --git a/sdk/base/ui.h b/sdk/base/ui.h index a965a6f..78a7818 100644 --- a/sdk/base/ui.h +++ b/sdk/base/ui.h @@ -23,6 +23,8 @@ namespace devui UI_CMD_COUNT_PAPER = 0x10, UI_CMD_STOP_SCAN, + UI_CMD_CLEAN_PASSWAY = 0x30, + UI_STATUS_SCANNING = 0x1000, // begin scanning. data: (LPSCANSTREAM) UI_STATUS_PAPER_CNT, // ONE paper has pass through. data: (uint32_t*)milliseconds for paper pass through UI_STATUS_MESSAGE, // status message, hold screen. data: LPSTATMSG diff --git a/sdk/base/utils.cpp b/sdk/base/utils.cpp index 228e76c..700f817 100644 --- a/sdk/base/utils.cpp +++ b/sdk/base/utils.cpp @@ -218,6 +218,7 @@ class log_cls FILE* file_; int level_; int type_; + int max_file_size_ = MAX_LOG_FILE_SIZE; std::mutex lock_; static log_cls* inst_; @@ -256,15 +257,16 @@ class log_cls static void log_file(const char* info, void* param, void* param2) { FILE** file = (FILE**)param; + log_cls *cls = (log_cls*)param2; if (*file == nullptr) - *file = create_log_file(((std::string*)param2)->c_str(), false); + *file = create_log_file(cls->path_file_.c_str(), false); if (*file) { fwrite(info, 1, strlen(info), *file); fflush(*file); - if (ftell(*file) >= MAX_LOG_FILE_SIZE) + if (ftell(*file) >= cls->max_file_size_) { fclose(*file); remove(((std::string*)param2)->c_str()); @@ -344,6 +346,10 @@ public: { level_ = level; } + void set_max_file_size(int size) + { + max_file_size_ = size; + } int level(void) { return level_; @@ -357,7 +363,7 @@ public: { std::lock_guard lock(lock_); - log_(info, &file_, &path_file_); + log_(info, &file_, this); } std::string get_log_file_path(const char* dst = nullptr) { @@ -661,6 +667,74 @@ namespace utils return ret; } + int utf8_2_16(uint8_t* &in, uint16_t& ch) + { + static uint8_t lead[] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; + int ret = 0; + + if(*in < 0x80) + { + ch = *in++; + } + else if(*in < 0x0E0) + { + ch = *in++; + ch &= ~0x0C0; + if(*in < 0x80) + ret = EINVAL; + else + { + ch <<= 6; + ch |= *in++ & 0x3f; + } + } + else if(*in < 0x0F0) + { + ch = *in++; + ch &= ~0x0E0; + if(*in < 0x80) + ret = EINVAL; + else + { + ch <<= 6; + ch |= *in++ & 0x3f; + if(*in < 0x80) + ret = EINVAL; + else + { + ch <<= 6; + ch |= *in++ & 0x3f; + } + } + } + else + { + ret = EINVAL; + } + + return ret; + } + int utf8_2_web(uint8_t* &in, std::string& web) + { + int ret = 0; + + while(*in) + { + uint16_t v = 0; + char buf[40] = {0}; + + ret = utf8_2_16(in, v); + if(ret) + break; + if(v < 0x80) + buf[0] = v; + else + sprintf(buf, "\\u%04X", v); + web += buf; + } + + return ret; + } std::string get_command_result(const char* cmd, int len, int *err) { @@ -1482,6 +1556,10 @@ namespace utils return std::move(file); } + void set_log_file_max_size(int size) + { + log_cls::instance()->set_max_file_size(size); + } void uninit(void) { log_info(("=====================================--Exited--" + std::to_string(GetCurrentProcessId()) + "=====================================\n\n\n\n").c_str(), LOG_LEVEL_FATAL); @@ -1604,6 +1682,26 @@ namespace utils return std::move(std::string((char*)&bfh, sizeof(bfh))); } + int save_bitmap(const char* file, int w, int h, int bpp, int dpix, int dpiy, void* bits) + { + int err = 0; + FILE* dst = fopen(file, "wb"); + + if(dst) + { + std::string bih(bitmap_info_header(w, h, bpp, dpix, dpiy)), + bfh(bitmap_file_header((BITMAPINFOHEADER*)&bih[0])); + + fwrite(bfh.c_str(), 1, bfh.length(), dst); + fwrite(bih.c_str(), 1, bih.length(), dst); + fwrite(bits, 1, ((BITMAPINFOHEADER*)&bih[0])->biSizeImage, dst); + fclose(dst); + } + else + err = errno; + + return err; + } #if OS_WIN bool run_get_message(HWND hwnd, UINT filter_min, UINT filter_max, std::function msghandler) @@ -2407,6 +2505,10 @@ void safe_thread::thread_worker(std::function func, std::string name utils::to_log(LOG_LEVEL_DEBUG, "--- safe_thread of '%s - %p' exited.\n", name.c_str(), GetCurrentThreadId()); return; } + catch (exception_ex e) + { + utils::to_log(LOG_LEVEL_FATAL, "Exception in thread '%p - %s': %s\n", GetCurrentThreadId(), name.c_str(), e.what()); + } catch (std::exception e) { utils::to_log(LOG_LEVEL_FATAL, "Exception in thread '%p - %s': %s\n", GetCurrentThreadId(), name.c_str(), e.what()); @@ -2658,3 +2760,24 @@ int safe_file::save(const void* data, uint16_t bytes) return rename((path_ + tmp_appendix_).c_str(), path_.c_str()); } + + +//////////////////////////////////////////////////////////////////////////////////////////////// +// exception_ex +exception_ex::exception_ex() : what_("exception_ex") +{} +exception_ex::exception_ex(const char* msg) : what_(msg ? msg : "") +{} +exception_ex::exception_ex(const exception_ex& r) : what_(r.what_) +{} +exception_ex::~exception_ex() +{} + +const char* exception_ex::what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT +{ + return what_.c_str(); +} +void exception_ex::set_info(const char* info) +{ + what_ = info ? info : ""; +} diff --git a/sdk/base/utils.h b/sdk/base/utils.h index 030acbb..163f05f 100644 --- a/sdk/base/utils.h +++ b/sdk/base/utils.h @@ -62,6 +62,18 @@ namespace utils // ENODATA - need more data int utf16_2_8(unsigned short* &in, char ch[8]); + // Function: transfere from utf8 to utf16 + // + // Parameters: in - [in]: head of utf8 beginning + // + // [out]: beginning of the next character if success or no changes on failure + // ch - to receive the character + // + // Return: 0 - success + // EINVAL - invalid utf8 string + int utf8_2_16(uint8_t* &in, uint16_t& ch); + int utf8_2_web(uint8_t* &in, std::string& web); // convert 'E5 A5 BD' to '\u597D' + std::string get_command_result(const char* cmd, int len = -1, int *err = nullptr); std::string get_local_data_path(void); std::string temporary_path(void); @@ -101,6 +113,7 @@ namespace utils // return logging file path if 'type' was LOG_TYPE_FILE std::string init_log(log_type type, log_level level = LOG_LEVEL_ALL, const char* fn_appendix = nullptr/*appendix to default log-file-name*/); + void set_log_file_max_size(int size = SIZE_MB(10)); void uninit(void); void log_info(const char* info, int level = LOG_LEVEL_ALL); void log_mem_info(const char* desc, const void* data, size_t bytes, int level = LOG_LEVEL_ALL); // log as 0x12345678 00 01 02 ... @@ -116,6 +129,7 @@ namespace utils // bitmap header ... std::string bitmap_info_header(int pixel_w, int pixel_h, int bpp, int dpix, int dpiy = 0); // return BITMPINFOHEADER + pallete if need. dpiy same as dpix if was ZERO std::string bitmap_file_header(BITMAPINFOHEADER *lpbi); // return BITMAPFILEHEADER + int save_bitmap(const char* file, int w, int h, int bpp, int dpix, int dpiy, void* bits); #if OS_WIN // Function: pump message recycle (GetMessageW) @@ -536,3 +550,20 @@ public: std::string load(void); int save(const void* data, uint16_t bytes); }; + +#include +class exception_ex : public std::exception +{ + std::string what_; + +public: + exception_ex(); + exception_ex(const char* msg); + exception_ex(const exception_ex& r); + ~exception_ex(); + +public: + virtual const char* + what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT override; + void set_info(const char* info); +}; diff --git a/ui/dev_menu.cpp b/ui/dev_menu.cpp index 18edac2..7a4ce3e 100644 --- a/ui/dev_menu.cpp +++ b/ui/dev_menu.cpp @@ -753,6 +753,8 @@ void ui_mgr::init(void) { auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET { + devui::send_message(devui::UI_CMD_CLEAN_PASSWAY); + return false; }; handler_[menu_command::MENU_CMD_ID_CLEAR_PASSWAY] = f; diff --git a/ui/font.cpp b/ui/font.cpp index a9e6733..338e6c8 100644 --- a/ui/font.cpp +++ b/ui/font.cpp @@ -24,6 +24,16 @@ namespace custom_font void init_8x8(void) { + static uint8_t zong[] = {8, 8 + , 0x00, 0x60, 0x6E, 0x4B, 0x7A, 0x4B, 0x6E, 0x60 + }; + font_map8x8_["\346\200\273"] = zong; + + static uint8_t maohao[] = {4, 8 + , 0x00, 0x50, 0x50, 0x00 + }; + font_map8x8_["\357\274\232"] = maohao; + static uint8_t colon[] = {3, 8 , 0x00, 0x28, 0x00 }; diff --git a/xmake.lua b/xmake.lua index 5a17d55..6a42ade 100644 --- a/xmake.lua +++ b/xmake.lua @@ -60,8 +60,8 @@ add_packagedirs("sdk") add_defines("BUILD_AS_DEVICE") add_defines("VER_MAIN=2") add_defines("VER_FAMILY=200") -add_defines("VER_DATE=20240222") -add_defines("VER_BUILD=19") +add_defines("VER_DATE=20240223") +add_defines("VER_BUILD=12") target("conf") set_kind("phony")