add log; redefine the first message as HAND_SHAKE

This commit is contained in:
gb 2023-12-25 17:39:34 +08:00
parent 15fb8c3a6b
commit fbe158c845
9 changed files with 40 additions and 16 deletions

File diff suppressed because one or more lines are too long

View File

@ -168,7 +168,7 @@ public:
// "cur": 1000,
// "default": 1000
// },
// "fram-h": {
// "frame-h": {
// "cat": "none",
// "group": "CIS",
// "title": "帧高度",

View File

@ -42,11 +42,12 @@ async_scanner::async_scanner() : usb_(nullptr), cfg_mgr_(nullptr), scan_id_(0)
return handle_bulk_cmd(pack, used, required);
};
auto on_connect = [&](bool connected) -> void
auto on_connect = [this](bool connected) -> void
{
utils::to_log(LOG_LEVEL_ALL, "USB %s\n", connected ? "connected" : "dis-connected");
// if(!connected)
// stop_scan();
connected_ = connected;
if(!connected)
cis_->stop_scan();
};
auto user = [&](int priv) -> bool
@ -58,9 +59,11 @@ async_scanner::async_scanner() : usb_(nullptr), cfg_mgr_(nullptr), scan_id_(0)
utils::log_info(msg, LOG_LEVEL_DEBUG);
};
cfg_mgr_ = new device_option(user, on_log);
utils::to_log(LOG_LEVEL_DEBUG, "OPT - initializing ...\n");
const_opts_ = new scanner_const_opts();
cfg_mgr_->add(const_opts_);
cfg_mgr_->add(cis_);
utils::to_log(LOG_LEVEL_DEBUG, "OPT - initialized %u options.\n", cfg_mgr_->count());
usb_ = new async_usb_gadget(bulk_handle, on_connect);
last_err_ = usb_->last_error();

View File

@ -26,6 +26,7 @@ class async_scanner : public refer
scanner_hw *cis_ = nullptr;
MUTEX locker_;
volatile bool connected_ = false;
uint32_t img_cnt_;
uint32_t scan_id_;
uint32_t scan_err_;

View File

@ -12,7 +12,7 @@
#ifndef VER_MAIN
#define VER_MAIN 2
#define VER_MINOR 0
#define VER_DATE 20231219
#define VER_DATE 20231225
#define VER_BUILD 1
#endif

View File

@ -46,7 +46,7 @@ enum cancel_io
};
enum ep0_req
{
USB_REQ_EP0_GET_PEER_CONFIG = 100, // get protocol version (PROTOCOL_VER), req = me, ind = 0, val = 0, len = sizeof(PEERCFG)
USB_REQ_EP0_HAND_SHAKE = 100, // hand-shake[in/out] with data LPPEERCFG, req = me, ind = 0, val = 0, len = sizeof(PEERCFG)
USB_REQ_EP0_GET_STATUS, // 获取各工作线程状态, return EP0REPLYSTATUS. req = me, ind = 0, val = bool: whether write log, len = sizeof(EP0REPLYSTATUS)
USB_REQ_EP0_CANCEL_IO, // 设置当前IO数据的有效性. req = me, ind = 0, val = 0, len = sizeof(uint32_t), discard IO data when data is CANCEL_IO_CANCEL
// work-flow: write control with 'CANCEL_IO_CANCEL', write bulk with 1 byte, write control with not 'CANCEL_IO_CANCEL' to restore
@ -258,8 +258,9 @@ typedef struct _ep0_reply
typedef struct _peer_config
{
uint16_t ver; // protocol version
uint64_t pid; // [in] - host pc process id; [out] - usb service process id
uint32_t io_size; // IO buffer size
uint16_t ver; // protocol version
}PEERCFG, *LPPEERCFG;
typedef struct _pack_base // A piece of data has only one header

View File

@ -1207,7 +1207,11 @@ void device_option::insert_option(gb_json* opt, sane_opt_provider* from, const c
if (!opt->get_value("auto", can_auto) || can_auto)
{
std::string type("");
opt->get_value("type", type);
val.resize(size);
type = sane_opt_provider::sane_value_2_text(type.c_str(), &val[0]);
utils::to_log(LOG_LEVEL_ALL, "Set option '%s' to default value: '%s'\n", opt->key().c_str(), type.c_str());
from->set_value(opt->key().c_str(), &val[0]);
}
}

View File

@ -206,6 +206,7 @@ dyn_mem_ptr async_usb_gadget::handle_ctrl_message(dyn_mem_ptr data)
session_id_++;
utils::to_log(LOG_LEVEL_DEBUG, "////////////// EP0 FFS ENABLE, start session %u ...\n", session_id_);
online_ = true;
cancel_io_ = false;
wait_in_.trigger();
wait_out_.trigger();
if(dev_connect_)
@ -213,6 +214,7 @@ dyn_mem_ptr async_usb_gadget::handle_ctrl_message(dyn_mem_ptr data)
break;
case FUNCTIONFS_DISABLE:
online_ = false;
cancel_io_ = true;
if(dev_connect_)
dev_connect_(online_);
utils::to_log(LOG_LEVEL_DEBUG, "////////////// EP0 FFS DISABLE, end session %u ...\n\n", session_id_);
@ -221,8 +223,8 @@ dyn_mem_ptr async_usb_gadget::handle_ctrl_message(dyn_mem_ptr data)
reply = handle_ctrl_setup(data);
break;
case FUNCTIONFS_BIND:
// utils::to_log(LOG_LEVEL_ALL, "EP0 FFS BIND\n");
utils::log_mem_info("EP0 FFS BIND:", pev, sizeof(*pev), LOG_LEVEL_DEBUG);
utils::to_log(LOG_LEVEL_ALL, "EP0 FFS BIND\n");
// utils::log_mem_info("EP0 FFS BIND:", pev, sizeof(*pev), LOG_LEVEL_DEBUG);
break;
case FUNCTIONFS_UNBIND:
utils::to_log(LOG_LEVEL_ALL, "EP0 FFS UNBIND\n");
@ -267,11 +269,20 @@ dyn_mem_ptr async_usb_gadget::handle_ctrl_setup(dyn_mem_ptr data)
{
switch (pev->u.setup.bRequest)
{
case USB_REQ_EP0_GET_PEER_CONFIG:
case USB_REQ_EP0_HAND_SHAKE:
if(pev->u.setup.bRequestType & USB_DIR_IN)
{
reply = dyn_mem::memory(sizeof(PEERCFG));
((LPPEERCFG)reply->ptr())->ver = PROTOCOL_VER;
((LPPEERCFG)reply->ptr())->io_size = unit_out_;
((LPPEERCFG)reply->ptr())->pid = GetCurrentProcessId();
reply->set_len(sizeof(PEERCFG));
}
else
{
host_pid_ = ((LPPEERCFG)(pev + 1))->pid;
utils::to_log(LOG_LEVEL_DEBUG, "Host process %llu connected.\n", host_pid_);
}
break;
case USB_REQ_EP0_GET_STATUS:
reply = dyn_mem::memory(sizeof(struct _ep0_reply));
@ -455,7 +466,7 @@ void async_usb_gadget::thread_read_ep0(void)
}
// timeout.tv_sec = 0;
ret = read(fd, ptr, headl);
ret = read(fd, ptr, headl + datal);
if (ret < 0)
{
utils::to_log(LOG_LEVEL_ALL, "read EP0 failed: %d(%s)\n", errno, strerror(errno));
@ -464,7 +475,9 @@ void async_usb_gadget::thread_read_ep0(void)
bool good = true;
if(pe->u.setup.bRequestType & USB_DIR_IN)
{
mem->set_len(headl);
}
else
{
if (pe->u.setup.wLength > datal)

View File

@ -70,6 +70,8 @@ class async_usb_gadget : public refer
uint32_t task_cmd_ = 0;
uint32_t task_packet_id_ = 0;
uint64_t host_pid_ = 0;
#ifdef MEM_POOL
dyn_mem_pool *io_buf_ = nullptr;
#else