调整整体的一个状态机流程,让无用状态不在响应
This commit is contained in:
parent
a792d08fce
commit
51afbd33e2
|
@ -16,15 +16,15 @@ std::map<std::string, std::shared_ptr<FsmState>> FsmStateManager::fsmStates;
|
||||||
|
|
||||||
void StandbyState::initial()
|
void StandbyState::initial()
|
||||||
{
|
{
|
||||||
LOG("StandbyState \n");
|
printf("INIT FSM:扫描仪准备完成 \n");
|
||||||
typeName = "StandbyState";
|
//typeName = "StandbyState";
|
||||||
scanner->getPanelLeds().setStatus(LedStatus::Ready);
|
scanner->getPanelLeds().setStatus(LedStatus::Ready);
|
||||||
doReset();
|
doReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
FsmState *StandbyState::on_event(ScanEvent event)
|
FsmState *StandbyState::on_event(ScanEvent event)
|
||||||
{
|
{
|
||||||
LOG("StandbyState on_event %d \n", event);
|
printf("FSM:扫描仪准备完成-->返回状态 %d \n", event);
|
||||||
if (event == S_EVT_COVER_OPENED)
|
if (event == S_EVT_COVER_OPENED)
|
||||||
{
|
{
|
||||||
return FsmStateManagerEx<CoverOpenState>::GetState();
|
return FsmStateManagerEx<CoverOpenState>::GetState();
|
||||||
|
@ -37,7 +37,6 @@ FsmState *StandbyState::on_event(ScanEvent event)
|
||||||
{
|
{
|
||||||
if (scanner->getSensor().isPaperStandby())
|
if (scanner->getSensor().isPaperStandby())
|
||||||
{
|
{
|
||||||
LOG("StandbyState on_event : %s \n", "true");
|
|
||||||
return FsmStateManagerEx<PaperReadyState>::GetState();
|
return FsmStateManagerEx<PaperReadyState>::GetState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,14 +57,14 @@ void StandbyState::doReset()
|
||||||
|
|
||||||
void CoverOpenState::initial()
|
void CoverOpenState::initial()
|
||||||
{
|
{
|
||||||
LOG("CoverOpenState \n");
|
printf("INIT 状态机检测:设备开盖 \n");
|
||||||
typeName = "CoverOpenState";
|
|
||||||
scanner->getPanelLeds().setStatus(LedStatus::CoverOpen);
|
scanner->getPanelLeds().setStatus(LedStatus::CoverOpen);
|
||||||
}
|
}
|
||||||
|
|
||||||
FsmState *CoverOpenState::on_event(ScanEvent event)
|
FsmState *CoverOpenState::on_event(ScanEvent event)
|
||||||
{
|
{
|
||||||
LOG("CoverOpenState on_event %d \n", event);
|
printf("状态机检测:设备开盖--->返回状态: %s %d \n", event == S_EVT_COVER_CLOSED?"关盖":"开盖",event);
|
||||||
if (event == S_EVT_COVER_CLOSED)
|
if (event == S_EVT_COVER_CLOSED)
|
||||||
{
|
{
|
||||||
if (!scanner->getSensor().isPaperAtScan())
|
if (!scanner->getSensor().isPaperAtScan())
|
||||||
|
@ -92,37 +91,34 @@ InitState::InitState()
|
||||||
|
|
||||||
FsmState *InitState::on_event(ScanEvent event)
|
FsmState *InitState::on_event(ScanEvent event)
|
||||||
{
|
{
|
||||||
LOG("InitState on_event %d \n", event);
|
|
||||||
if (!(scanner->getSensor().isCoverClosed()))
|
if (!(scanner->getSensor().isCoverClosed()))
|
||||||
{
|
{
|
||||||
|
printf("FSM:开盖\r\n");
|
||||||
return FsmStateManagerEx<CoverOpenState>::GetState();
|
return FsmStateManagerEx<CoverOpenState>::GetState();
|
||||||
}
|
}
|
||||||
|
else if ((scanner->getSensor().isPaperIn()))
|
||||||
|
{
|
||||||
|
printf("FSM:卡纸\r\n");
|
||||||
|
return FsmStateManagerEx<ErrorJamState>::GetState();
|
||||||
|
}
|
||||||
else if (scanner->getSensor().isPaperStandby())
|
else if (scanner->getSensor().isPaperStandby())
|
||||||
{
|
{
|
||||||
LOG("------------------有纸\r\n");
|
printf("FSM:有纸\r\n");
|
||||||
return FsmStateManagerEx<PaperReadyState>::GetState();
|
return FsmStateManagerEx<PaperReadyState>::GetState();
|
||||||
}
|
}
|
||||||
else if ((scanner->getSensor().isPaperAtScan()))
|
|
||||||
{
|
|
||||||
LOG("------------------卡纸\r\n");
|
|
||||||
return FsmStateManagerEx<ErrorJamState>::GetState();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
LOG("---------扫描仪已经准备完成------\r\n");
|
|
||||||
return FsmStateManagerEx<StandbyState>::GetState();
|
return FsmStateManagerEx<StandbyState>::GetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitState::initial()
|
void InitState::initial()
|
||||||
{
|
{
|
||||||
LOG("InitState 999 \n");
|
printf("INIT FSM:初始化设备\r\n");
|
||||||
typeName = "InitState"; //啥用?
|
|
||||||
scanner->put(S_EVT_NORES);
|
scanner->put(S_EVT_NORES);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ErrorJamState::initial()
|
void ErrorJamState::initial()
|
||||||
{
|
{
|
||||||
LOG("ErrorJamState \n");
|
printf("INIT FSM:卡纸\r\n");
|
||||||
typeName = "ErrorJamState";
|
|
||||||
scanner->getPanelLeds().setStatus(LedStatus::Abnormal);
|
scanner->getPanelLeds().setStatus(LedStatus::Abnormal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +129,7 @@ void ErrorJamState::doPaper_pullout()
|
||||||
|
|
||||||
FsmState *ErrorJamState::on_event(ScanEvent event)
|
FsmState *ErrorJamState::on_event(ScanEvent event)
|
||||||
{
|
{
|
||||||
//LOG("ErrorJamState on_event %d \n", event);
|
//printf("ErrorJamState on_event %d \n", event);
|
||||||
if (scanner->getSensor().isCoverClosed() && !scanner->getSensor().isPaperStandby() && !scanner->getSensor().isPaperIn())
|
if (scanner->getSensor().isCoverClosed() && !scanner->getSensor().isPaperStandby() && !scanner->getSensor().isPaperIn())
|
||||||
{
|
{
|
||||||
return FsmStateManagerEx<StandbyState>::GetState();
|
return FsmStateManagerEx<StandbyState>::GetState();
|
||||||
|
@ -144,6 +140,7 @@ FsmState *ErrorJamState::on_event(ScanEvent event)
|
||||||
}
|
}
|
||||||
else if (event == S_EVT_PAPER_PULLOUT) // && scanner->GetIsDoublePaper()
|
else if (event == S_EVT_PAPER_PULLOUT) // && scanner->GetIsDoublePaper()
|
||||||
{
|
{
|
||||||
|
printf("啥玩意?????????????\r\n");
|
||||||
scanner->paper_pullout();
|
scanner->paper_pullout();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -153,10 +150,8 @@ FsmState *ErrorJamState::on_event(ScanEvent event)
|
||||||
{
|
{
|
||||||
return FsmStateManagerEx<CoverOpenState>::GetState();
|
return FsmStateManagerEx<CoverOpenState>::GetState();
|
||||||
}
|
}
|
||||||
else //if (scanner->getSensor().isPaperStandby() && !scanner->getSensor().isPaperIn())
|
else
|
||||||
{
|
{
|
||||||
//LOG("ErrorJamState GetIsDoublePaper %s \n", scanner->GetIsDoublePaper() ? "TRUE" : "FALSE");
|
|
||||||
//LOG("ErrorJamState GetIsJamPaper %s \n", scanner->GetIsJamPaper() ? "TRUE" : "FALSE");
|
|
||||||
if (!scanner->GetIsDoublePaper() && !scanner->GetIsJamPaper() && !scanner->getSensor().isPaperAtScan())
|
if (!scanner->GetIsDoublePaper() && !scanner->GetIsJamPaper() && !scanner->getSensor().isPaperAtScan())
|
||||||
{
|
{
|
||||||
if (scanner->getSensor().isPaperStandby())
|
if (scanner->getSensor().isPaperStandby())
|
||||||
|
@ -171,15 +166,14 @@ FsmState *ErrorJamState::on_event(ScanEvent event)
|
||||||
|
|
||||||
void PaperReadyState::initial()
|
void PaperReadyState::initial()
|
||||||
{
|
{
|
||||||
|
printf("INIT FSM:设备已放纸\r\n");
|
||||||
LOG("PaperReadyState setStatus(PanelLeds::Ready) \n");
|
//typeName = "PaperReadyState";
|
||||||
typeName = "PaperReadyState";
|
|
||||||
scanner->getPanelLeds().setStatus(LedStatus::Ready);
|
scanner->getPanelLeds().setStatus(LedStatus::Ready);
|
||||||
}
|
}
|
||||||
|
|
||||||
FsmState *PaperReadyState::on_event(ScanEvent event)
|
FsmState *PaperReadyState::on_event(ScanEvent event)
|
||||||
{
|
{
|
||||||
LOG("FsmState PaperReadyState on_event %d \n",event);
|
printf("FSM :设备已放纸--->返回状态: %d \n",event);
|
||||||
if (event == S_EVT_COVER_OPENED)
|
if (event == S_EVT_COVER_OPENED)
|
||||||
{
|
{
|
||||||
return FsmStateManagerEx<CoverOpenState>::GetState();
|
return FsmStateManagerEx<CoverOpenState>::GetState();
|
||||||
|
@ -204,14 +198,14 @@ FsmState *PaperReadyState::on_event(ScanEvent event)
|
||||||
|
|
||||||
void ErrorState::initial()
|
void ErrorState::initial()
|
||||||
{
|
{
|
||||||
LOG("ErrorState \n");
|
printf("ErrorState \n");
|
||||||
typeName = "ErrorState";
|
//typeName = "ErrorState";
|
||||||
scanner->getPanelLeds().setStatus(LedStatus::Abnormal);
|
scanner->getPanelLeds().setStatus(LedStatus::Abnormal);
|
||||||
}
|
}
|
||||||
|
|
||||||
FsmState *ErrorState::on_event(ScanEvent event)
|
FsmState *ErrorState::on_event(ScanEvent event)
|
||||||
{
|
{
|
||||||
LOG("ErrorState on_event %d \n", event);
|
printf("ErrorState on_event %d \n", event);
|
||||||
if (event == S_EVT_COVER_OPENED)
|
if (event == S_EVT_COVER_OPENED)
|
||||||
{
|
{
|
||||||
return FsmStateManagerEx<CoverOpenState>::GetState();
|
return FsmStateManagerEx<CoverOpenState>::GetState();
|
||||||
|
@ -223,7 +217,7 @@ FsmState *ErrorState::on_event(ScanEvent event)
|
||||||
}
|
}
|
||||||
else if (event == S_EVT_PAPER_STANDBY)
|
else if (event == S_EVT_PAPER_STANDBY)
|
||||||
{
|
{
|
||||||
LOG("ErrorState on_event S_EVT_PAPER_STANDBY\n");
|
printf("ErrorState on_event S_EVT_PAPER_STANDBY\n");
|
||||||
if (scanner->getSensor().isPaperStandby()) //有纸 且没卡纸
|
if (scanner->getSensor().isPaperStandby()) //有纸 且没卡纸
|
||||||
{
|
{
|
||||||
return FsmStateManagerEx<PaperReadyState>::GetState();
|
return FsmStateManagerEx<PaperReadyState>::GetState();
|
||||||
|
@ -258,51 +252,52 @@ FsmState *ErrorState::on_event(ScanEvent event)
|
||||||
|
|
||||||
void ScanningState::initial()
|
void ScanningState::initial()
|
||||||
{
|
{
|
||||||
LOG("ScanningState \n");
|
printf("INIT FSM: 正在扫描中\n");
|
||||||
typeName = "ScanningState";
|
//typeName = "ScanningState";
|
||||||
scanner->getPanelLeds().setStatus(LedStatus::Scanning);
|
scanner->getPanelLeds().setStatus(LedStatus::Scanning);
|
||||||
scanner->startScan();
|
scanner->startScan();
|
||||||
}
|
}
|
||||||
|
|
||||||
FsmState *ScanningState::on_event(ScanEvent event)
|
FsmState *ScanningState::on_event(ScanEvent event)
|
||||||
{
|
{
|
||||||
LOG("ScanningState on_event \n");
|
printf("FSM: 正在扫描中-->返回状态:%d \n",event);
|
||||||
if (event == S_EVT_COVER_IN_OPEN)
|
if (event == S_EVT_COVER_IN_OPEN)
|
||||||
{
|
{
|
||||||
return FsmStateManagerEx<CoverOpenState>::GetState();
|
return FsmStateManagerEx<CoverOpenState>::GetState();
|
||||||
}
|
}
|
||||||
else if (event == S_EVT_STOP_SCAN)
|
else if (event == S_EVT_STOP_SCAN)
|
||||||
{
|
{
|
||||||
LOG("ScanningState call for %d \n", event);
|
printf("ScanningState call for %d \n", event);
|
||||||
scanner->getPanelLeds().setStatus(LedStatus::StopScan);
|
scanner->getPanelLeds().setStatus(LedStatus::StopScan);
|
||||||
scanner->stop_scan();
|
scanner->stop_scan();
|
||||||
auto ret = scanner->getSensor().isPaperStandby() ? FsmStateManagerEx<PaperReadyState>::GetState() : FsmStateManagerEx<StandbyState>::GetState();
|
auto ret = scanner->getSensor().isPaperStandby() ? FsmStateManagerEx<PaperReadyState>::GetState() : FsmStateManagerEx<StandbyState>::GetState();
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (event == S_EVT_COVER_OPENED)
|
else if (event == S_EVT_COVER_OPENED)
|
||||||
{
|
{
|
||||||
//scanner->stop_scan();
|
printf("FSM :正在扫描中:开盖状态\r\n");
|
||||||
scanner->emergency_stop(S_EVT_COVER_OPENED);
|
scanner->emergency_stop(S_EVT_COVER_OPENED);
|
||||||
return FsmStateManagerEx<CoverOpenState>::GetState();
|
return FsmStateManagerEx<CoverOpenState>::GetState();
|
||||||
}
|
}
|
||||||
else if (event == S_EVT_DOUBLEPAPER)
|
else if (event == S_EVT_DOUBLEPAPER)
|
||||||
{
|
{
|
||||||
scanner->SetIsDoublePaper(true);
|
scanner->SetIsDoublePaper(true);
|
||||||
scanner->emergency_stop(1);
|
scanner->emergency_stop(S_EVT_ERROR_DOUBLEPAPER);
|
||||||
LOG("\nScanningState S_EVT_DOUBLEPAPER %s \n",GetCurrentTimeStamp(2).c_str());
|
|
||||||
|
//scanner->stop_scan(); 保留双张就不需要紧急停止
|
||||||
|
printf("FSM :正在扫描中: 双张\n");
|
||||||
return FsmStateManagerEx<ErrorJamState>::GetState();
|
return FsmStateManagerEx<ErrorJamState>::GetState();
|
||||||
}
|
}
|
||||||
else if (event == S_EVT_JAM_IN)
|
else if (event == S_EVT_JAM_IN)
|
||||||
{
|
{
|
||||||
scanner->emergency_stop(0);
|
scanner->emergency_stop(S_EVT_JAM_IN);
|
||||||
LOG("ScanningState S_EVT_JAM_IN \n");
|
printf("FSM :正在扫描中: 搓纸失败 \n");
|
||||||
return FsmStateManagerEx<ErrorState>::GetState();
|
return FsmStateManagerEx<ErrorState>::GetState();
|
||||||
}
|
}
|
||||||
else if (event == S_EVT_JAM_OUT)
|
else if (event == S_EVT_JAM_OUT)
|
||||||
{
|
{
|
||||||
scanner->emergency_stop(0);
|
scanner->emergency_stop(S_EVT_JAM_OUT);
|
||||||
LOG("ScanningState S_EVT_JAM_OUT \n");
|
printf("FSM :正在扫描中: 卡纸 \n");
|
||||||
return FsmStateManagerEx<ErrorJamState>::GetState();
|
return FsmStateManagerEx<ErrorJamState>::GetState();
|
||||||
}
|
}
|
||||||
else if (event == S_EVT_PAPER_AT_SCAN)
|
else if (event == S_EVT_PAPER_AT_SCAN)
|
||||||
|
|
|
@ -43,6 +43,29 @@ enum ScanEvent {
|
||||||
class FsmState
|
class FsmState
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
char * int_to_string(ScanEvent event)
|
||||||
|
{
|
||||||
|
switch (event)
|
||||||
|
{
|
||||||
|
case S_EVT_COVER_OPENED:
|
||||||
|
return "开盖";
|
||||||
|
case S_EVT_COVER_CLOSED:
|
||||||
|
return "关盖";
|
||||||
|
case S_EVT_JAM_OUT:
|
||||||
|
return "卡纸";
|
||||||
|
case S_EVT_PAPER_STANDBY:
|
||||||
|
return "纸张准备完成";
|
||||||
|
case S_EVT_START_SCAN:
|
||||||
|
return "开始扫描";
|
||||||
|
case S_EVT_CLEAR_ERR:
|
||||||
|
return "清除错误";
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FsmState();
|
FsmState();
|
||||||
virtual ~FsmState();
|
virtual ~FsmState();
|
||||||
|
|
||||||
|
@ -62,6 +85,8 @@ class FsmStateManager
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
static std::map<std::string, std::shared_ptr<FsmState>> fsmStates;
|
static std::map<std::string, std::shared_ptr<FsmState>> fsmStates;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -72,12 +97,17 @@ public:
|
||||||
{
|
{
|
||||||
std::string type_name = typeid(T).name();
|
std::string type_name = typeid(T).name();
|
||||||
std::map<std::string, std::shared_ptr<FsmState>>::iterator iter = fsmStates.find(type_name);
|
std::map<std::string, std::shared_ptr<FsmState>>::iterator iter = fsmStates.find(type_name);
|
||||||
if (iter == fsmStates.end()) {
|
if (iter == fsmStates.end())
|
||||||
|
{
|
||||||
fsmStates.insert(std::pair<std::string, std::shared_ptr<FsmState>>(type_name, std::shared_ptr<FsmState>(new T)));
|
fsmStates.insert(std::pair<std::string, std::shared_ptr<FsmState>>(type_name, std::shared_ptr<FsmState>(new T)));
|
||||||
}
|
}
|
||||||
fsmStates[type_name]->initial();
|
fsmStates[type_name]->initial();
|
||||||
return fsmStates[type_name].get();
|
return fsmStates[type_name].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::map<ScanEvent , T> fsm;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//????
|
//????
|
||||||
|
|
|
@ -19,7 +19,6 @@ const int vsp_B = 45;
|
||||||
#define ARRAYLEN(table) (sizeof(table) / sizeof(table[0]))
|
#define ARRAYLEN(table) (sizeof(table) / sizeof(table[0]))
|
||||||
// using namespace cv;
|
// using namespace cv;
|
||||||
MultiFrameCapture::MultiFrameCapture(ScannerGlue glue) :
|
MultiFrameCapture::MultiFrameCapture(ScannerGlue glue) :
|
||||||
snaped_index(0),
|
|
||||||
frame_count(1),
|
frame_count(1),
|
||||||
b_snap_run(true),
|
b_snap_run(true),
|
||||||
b_stop_snap(false),
|
b_stop_snap(false),
|
||||||
|
@ -104,7 +103,6 @@ void MultiFrameCapture::snap()
|
||||||
|
|
||||||
video->HtCamStartVideoCapturing();
|
video->HtCamStartVideoCapturing();
|
||||||
|
|
||||||
snaped_index++;
|
|
||||||
m_cv_snap.notify_all();
|
m_cv_snap.notify_all();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -303,23 +301,28 @@ void MultiFrameCapture::waitsnapdone(int state)
|
||||||
StopWatch sw;
|
StopWatch sw;
|
||||||
sw.reset();
|
sw.reset();
|
||||||
|
|
||||||
printf("!!!!!!!!!!!!!!!! m_cv_snapdone wait \n");
|
HG_JpegCompressInfo ip;
|
||||||
V4L2_DATAINFO_Ex info;
|
ip.error_code = state;
|
||||||
info.snaped_index = snaped_index;
|
ip.height = 0;
|
||||||
info.snap_end = true;
|
ip.width = 0;
|
||||||
info.error_code = state;
|
ip.index_frame = 0;
|
||||||
|
ip.DataLength = sizeof("0");
|
||||||
|
ip.first_frame = false;
|
||||||
|
ip.last_frame = true;
|
||||||
|
ip.pJpegData = (unsigned char*)"0";
|
||||||
|
|
||||||
if (b_end_snap)
|
if (b_end_snap)
|
||||||
{
|
{
|
||||||
m_frameinfos.Put(info);
|
m_glue.m_imageready(ip);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sw.reset();
|
sw.reset();
|
||||||
std::unique_lock<std::mutex> lock(m_mtx_snapdone);
|
std::unique_lock<std::mutex> lock(m_mtx_snapdone);
|
||||||
m_cv_snapdone.wait(lock);
|
m_cv_snapdone.wait(lock);
|
||||||
b_end_snap = true;
|
|
||||||
m_frameinfos.Put(info);
|
|
||||||
printf("!!!!!!!!!!!!!!!! m_cv_snapdone wait done :%f \n",sw.elapsed_ms());
|
|
||||||
|
|
||||||
|
m_glue.m_imageready(ip); //发一次空包
|
||||||
|
b_end_snap = true;
|
||||||
|
printf("!!!!!!!!!!!!!!!! m_cv_snapdone wait done :%f \n",sw.elapsed_ms());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MultiFrameCapture::IsImageQueueEmpty()
|
bool MultiFrameCapture::IsImageQueueEmpty()
|
||||||
|
@ -376,7 +379,7 @@ void MultiFrameCapture::configFPGAParam(int mode, int dpi)
|
||||||
void MultiFrameCapture::snaprun()
|
void MultiFrameCapture::snaprun()
|
||||||
{
|
{
|
||||||
//frame_info 发送得数据信息 channels 图像位深 num 需要取得帧数 time_out读图超时时间设置
|
//frame_info 发送得数据信息 channels 图像位深 num 需要取得帧数 time_out读图超时时间设置
|
||||||
auto snap_func = [this](V4L2_DATAINFO_Ex frame_info, int channels,int &time_out,int i)
|
auto snap_func = [this](V4L2_DATAINFO_Ex info_ex, int channels,int &time_out,int i)
|
||||||
{
|
{
|
||||||
StopWatch sw;
|
StopWatch sw;
|
||||||
sw.reset();
|
sw.reset();
|
||||||
|
@ -391,9 +394,9 @@ void MultiFrameCapture::snaprun()
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
|
|
||||||
//cv::Mat mat = cv::Mat(frame_info.height, frame_info.width, CV_8UC1, data, cv::Mat::AUTO_STEP);
|
//cv::Mat mat = cv::Mat(info_ex.height, info_ex.width, CV_8UC1, data, cv::Mat::AUTO_STEP);
|
||||||
|
|
||||||
// printf("获取数据 width:%d height:%d \r\n",frame_info.width,frame_info.height);
|
// printf("获取数据 width:%d height:%d \r\n",info_ex.width,info_ex.height);
|
||||||
|
|
||||||
//cv::imwrite("/home/root/test+_" + to_string(i)+".bmp", mat);
|
//cv::imwrite("/home/root/test+_" + to_string(i)+".bmp", mat);
|
||||||
// printf("--------------frame_index------------:%d\r\n",frame_index);
|
// printf("--------------frame_index------------:%d\r\n",frame_index);
|
||||||
|
@ -403,7 +406,7 @@ void MultiFrameCapture::snaprun()
|
||||||
//cv::imwrite("/home/root/test.bmp", mat);
|
//cv::imwrite("/home/root/test.bmp", mat);
|
||||||
//savebitmap(data,15552,512,"1.bmp");
|
//savebitmap(data,15552,512,"1.bmp");
|
||||||
}
|
}
|
||||||
//frame_info.mat = mat.clone();
|
//info_ex.mat = mat.clone();
|
||||||
|
|
||||||
//JpegCompress cmp(90);
|
//JpegCompress cmp(90);
|
||||||
//HG_JpegCompressInfo info = cmp.GetCompressedImg(mat);
|
//HG_JpegCompressInfo info = cmp.GetCompressedImg(mat);
|
||||||
|
@ -413,20 +416,19 @@ void MultiFrameCapture::snaprun()
|
||||||
info.pJpegData = data;
|
info.pJpegData = data;
|
||||||
info.dpi = false ;
|
info.dpi = false ;
|
||||||
|
|
||||||
info.DataLength = frame_info.width * frame_info.height;
|
info.DataLength = info_ex.width * info_ex.height;
|
||||||
info.first_frame = frame_info.first_frame;
|
info.first_frame = info_ex.first_frame;
|
||||||
info.last_frame = frame_info.last_frame;
|
info.last_frame = info_ex.last_frame;
|
||||||
info.index_frame = frame_info.frame_index;
|
info.index_frame = info_ex.frame_index + 1; //这个 +1 是最后一帧的假包,作用是返回错误代码的时候和数据段一起。
|
||||||
info.data_type = 0;
|
info.width = info_ex.width;
|
||||||
info.width = frame_info.width;
|
info.height = info_ex.height;
|
||||||
info.height = frame_info.height;
|
|
||||||
|
|
||||||
//printf("获取数据 width:%d height:%d is_first:%d is_last:%d DataLength:%d\r\n",frame_info.width,frame_info.height,info.first_frame,info.last_frame,info.DataLength);
|
//printf("获取数据 width:%d height:%d is_first:%d is_last:%d DataLength:%d\r\n",info_ex.width,info_ex.height,info.first_frame,info.last_frame,info.DataLength);
|
||||||
|
|
||||||
m_glue.m_imageready(info);
|
m_glue.m_imageready(info);
|
||||||
|
|
||||||
//m_frameinfos.Put(frame_info);
|
//m_frameinfos.Put(info_ex);
|
||||||
//printf("采集图像耗时:%f\r\n",sw.elapsed_ms());
|
printf("采集图像耗时:%f\r\n",sw.elapsed_ms());
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
@ -438,15 +440,15 @@ void MultiFrameCapture::snaprun()
|
||||||
m_cv_snap_is_scaning = false;
|
m_cv_snap_is_scaning = false;
|
||||||
m_cv_snap.wait(lock);
|
m_cv_snap.wait(lock);
|
||||||
m_cv_snap_is_scaning = true;
|
m_cv_snap_is_scaning = true;
|
||||||
V4L2_DATAINFO_Ex frame_info;
|
|
||||||
frame_info.pixtype = color_mode_;
|
V4L2_DATAINFO_Ex frame_info_;
|
||||||
frame_info.dpi = resolution_;
|
frame_info_.pixtype = color_mode_;
|
||||||
frame_info.width = pixels_width_;
|
frame_info_.dpi = resolution_;
|
||||||
frame_info.height = pixels_height_;
|
frame_info_.width = pixels_width_;
|
||||||
frame_info.error_code = 0;
|
frame_info_.height = pixels_height_;
|
||||||
frame_info.snaped_index = snaped_index;
|
frame_info_.error_code = 0;
|
||||||
frame_info.first_frame = false;
|
frame_info_.first_frame = false;
|
||||||
frame_info.last_frame = false;
|
frame_info_.last_frame = false;
|
||||||
|
|
||||||
int channels = color_mode_ == 1 ? 3 : 1;
|
int channels = color_mode_ == 1 ? 3 : 1;
|
||||||
int color_mode = video->HtCamGetColorMode();
|
int color_mode = video->HtCamGetColorMode();
|
||||||
|
@ -472,7 +474,7 @@ void MultiFrameCapture::snaprun()
|
||||||
video->HtCamGetFrameCnt(frame_cnt);
|
video->HtCamGetFrameCnt(frame_cnt);
|
||||||
|
|
||||||
printf("获取设置的帧数:%d\r\n",frame_cnt);
|
printf("获取设置的帧数:%d\r\n",frame_cnt);
|
||||||
frame_info.frame_index = frame_cnt + 1;
|
frame_info_.frame_index = frame_cnt + 1;
|
||||||
// video->HtCamSetVsnpTime(ti);
|
// video->HtCamSetVsnpTime(ti);
|
||||||
// printf("设置 vsnp:%d\r\n",ti);
|
// printf("设置 vsnp:%d\r\n",ti);
|
||||||
//ti++;
|
//ti++;
|
||||||
|
@ -484,13 +486,13 @@ void MultiFrameCapture::snaprun()
|
||||||
printf("mill:%d\r\n",mill);
|
printf("mill:%d\r\n",mill);
|
||||||
StopWatch sw;
|
StopWatch sw;
|
||||||
sw.reset();
|
sw.reset();
|
||||||
for (size_t i = 1; i <= frame_info.frame_index ; i++)
|
for (size_t i = 1; i <= frame_info_.frame_index ; i++)
|
||||||
{
|
{
|
||||||
printf("***********设置的帧数:%d 正在采集第[%d]帧************\r\n",frame_info.frame_index,i);
|
printf("***********设置的帧数:%d 正在采集第[%d]帧************\r\n",frame_info_.frame_index,i);
|
||||||
frame_info.first_frame = i == 1 ? true : false;
|
frame_info_.first_frame = i == 1 ? true : false;
|
||||||
frame_info.last_frame = i == frame_info.frame_index ? true : false;
|
//frame_info_.last_frame = i == frame_info_.frame_index ? true : false;
|
||||||
|
|
||||||
func_sig = snap_func(frame_info, channels,time_out,i);
|
func_sig = snap_func(frame_info_, channels,time_out,i);
|
||||||
|
|
||||||
if (b_stop_snap)
|
if (b_stop_snap)
|
||||||
{
|
{
|
||||||
|
@ -501,12 +503,12 @@ void MultiFrameCapture::snaprun()
|
||||||
while (val > 0)
|
while (val > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
frame_info.last_frame = val == 1 ? true : false;
|
//frame_info_.last_frame = val == 1 ? true : false;
|
||||||
frame_info.frame_index = frame_num;
|
frame_info_.frame_index = frame_num;
|
||||||
ind++;
|
ind++;
|
||||||
printf("-----------当前采集到第:[%d]帧 CIS总共采集[%d]帧 -------\r\n",ind,frame_num);
|
printf("-----------当前采集到第:[%d]帧 CIS总共采集[%d]帧 -------\r\n",ind,frame_num);
|
||||||
|
|
||||||
func_sig = snap_func(frame_info, channels,time_out ,ind);//同上面一样
|
func_sig = snap_func(frame_info_, channels,time_out ,ind);//同上面一样
|
||||||
|
|
||||||
val--;
|
val--;
|
||||||
if(resolution_ == DPI_600)
|
if(resolution_ == DPI_600)
|
||||||
|
@ -538,47 +540,11 @@ void MultiFrameCapture::snaprun()
|
||||||
void MultiFrameCapture::updatesnapstatus(int papertype)
|
void MultiFrameCapture::updatesnapstatus(int papertype)
|
||||||
{
|
{
|
||||||
b_stop_snap = false;
|
b_stop_snap = false;
|
||||||
snaped_index = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiFrameCapture::procimage()
|
void MultiFrameCapture::procimage()
|
||||||
{
|
{
|
||||||
static int idx = 0;
|
|
||||||
ThreadPool prc_pool(4);
|
|
||||||
std::queue<std::future<cv::Mat>> prc_fu;
|
|
||||||
unsigned int frames_height;
|
|
||||||
unsigned int frames_width = 0;
|
|
||||||
int cnt_ =0;
|
|
||||||
|
|
||||||
while (b_imgproc)
|
|
||||||
{
|
|
||||||
|
|
||||||
V4L2_DATAINFO_Ex frame = m_frameinfos.Take();
|
|
||||||
static int inx = 0;
|
|
||||||
|
|
||||||
if (!frame.mat.empty())
|
|
||||||
{
|
|
||||||
JpegCompress cmp(100);
|
|
||||||
|
|
||||||
HG_JpegCompressInfo info = cmp.GetCompressedImg(frame.mat);
|
|
||||||
|
|
||||||
// info.pJpegData = (unsigned char *)malloc(frame.width * frame.height);
|
|
||||||
//memcpy(info.pJpegData,frame.mat.data,frame.width * frame.height);
|
|
||||||
//info.mat = frame.mat;
|
|
||||||
// frame.mat.copyTo(info.mat);
|
|
||||||
//info.mat = frame.mat.clone();
|
|
||||||
//info.DataLength = frame.width * frame.height;
|
|
||||||
info.first_frame = frame.first_frame;
|
|
||||||
info.last_frame = frame.last_frame;
|
|
||||||
info.index_frame = frame.frame_index;
|
|
||||||
info.data_type = 0;
|
|
||||||
info.width = frame.width;
|
|
||||||
info.height = frame.height;
|
|
||||||
//cv::imwrite("/home/root/opencv"+to_string(cnt_++)+".bmp",frame.mat);
|
|
||||||
m_glue.m_imageready(info);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
static int temp_val = 0;
|
static int temp_val = 0;
|
||||||
#define CIS_6CH
|
#define CIS_6CH
|
||||||
|
|
|
@ -29,7 +29,6 @@ typedef CSSIZE SIZE;
|
||||||
class MultiFrameCapture : public ICapturer
|
class MultiFrameCapture : public ICapturer
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int frame_height = 60;
|
int frame_height = 60;
|
||||||
int m_total_height = 0;
|
int m_total_height = 0;
|
||||||
int readframe_timeout = 100;
|
int readframe_timeout = 100;
|
||||||
|
@ -42,7 +41,6 @@ private:
|
||||||
bool b_end_snap;
|
bool b_end_snap;
|
||||||
bool b_imgproc;
|
bool b_imgproc;
|
||||||
bool is_size_error;
|
bool is_size_error;
|
||||||
int snaped_index;
|
|
||||||
bool bScanning;
|
bool bScanning;
|
||||||
std::atomic<int> iImageremain;
|
std::atomic<int> iImageremain;
|
||||||
FPGAConfigParam m_fpgaparam;
|
FPGAConfigParam m_fpgaparam;
|
||||||
|
|
|
@ -144,13 +144,21 @@ void Scanner::processevent(FsmState *fsmState, ScanEvent event)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//开盖模式:1 扫描中开盖 2 未扫描的时候开盖 ,目前我想不到更好的方法,暂时先这样处理
|
||||||
if (typeid(*fsmState) == typeid(CoverOpenState))
|
if (event == S_EVT_COVER_OPENED && isScaning)
|
||||||
{
|
{
|
||||||
|
//printf("回调:开盖\r\n");
|
||||||
m_glue.m_deviceevent(1, "Cover Open");
|
m_glue.m_deviceevent(1, "Cover Open");
|
||||||
}
|
}
|
||||||
|
else if (typeid(*fsmState) == typeid(CoverOpenState) && !isScaning)
|
||||||
|
{
|
||||||
|
//printf("回调:开盖\r\n");
|
||||||
|
m_glue.m_deviceevent(1, "Cover Open");
|
||||||
|
}
|
||||||
|
|
||||||
else if (event == S_EVT_SCAN_STOPPED)
|
else if (event == S_EVT_SCAN_STOPPED)
|
||||||
{
|
{
|
||||||
|
//printf("回调:停止\r\n");
|
||||||
if (!m_correctting)
|
if (!m_correctting)
|
||||||
{
|
{
|
||||||
m_glue.m_deviceevent(70, "Scan done");
|
m_glue.m_deviceevent(70, "Scan done");
|
||||||
|
@ -158,18 +166,24 @@ void Scanner::processevent(FsmState *fsmState, ScanEvent event)
|
||||||
}
|
}
|
||||||
else if (event == S_EVT_JAM_IN)
|
else if (event == S_EVT_JAM_IN)
|
||||||
{
|
{
|
||||||
|
//printf("回调:搓纸失败\r\n");
|
||||||
m_glue.m_deviceevent(4, "Feed error");
|
m_glue.m_deviceevent(4, "Feed error");
|
||||||
}
|
}
|
||||||
else if (event == S_EVT_DOUBLEPAPER)
|
else if (event == S_EVT_DOUBLEPAPER)
|
||||||
{
|
{
|
||||||
|
//printf("回调:双张\r\n");
|
||||||
m_glue.m_deviceevent(16, "Double feed");
|
m_glue.m_deviceevent(16, "Double feed");
|
||||||
}
|
}
|
||||||
else if (event == S_EVT_JAM_OUT || typeid(*fsmState) == typeid(ErrorJamState))
|
else if (event == S_EVT_JAM_OUT || typeid(*fsmState) == typeid(ErrorJamState))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//printf("回调:卡纸\r\n");
|
||||||
m_glue.m_deviceevent(8, "Jam out");
|
m_glue.m_deviceevent(8, "Jam out");
|
||||||
}
|
}
|
||||||
else if (typeid(*fsmState) == typeid(ErrorState) && m_jamIn == true)
|
else if (typeid(*fsmState) == typeid(ErrorState) && m_jamIn == true)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//printf("回调:搓纸失败\r\n");
|
||||||
m_glue.m_deviceevent(4, "Feed error");
|
m_glue.m_deviceevent(4, "Feed error");
|
||||||
}
|
}
|
||||||
if (!IsScanning() && (typeid(*fsmState) == typeid(ErrorJamState) ||
|
if (!IsScanning() && (typeid(*fsmState) == typeid(ErrorJamState) ||
|
||||||
|
@ -178,6 +192,7 @@ void Scanner::processevent(FsmState *fsmState, ScanEvent event)
|
||||||
{
|
{
|
||||||
if (!m_correctting)
|
if (!m_correctting)
|
||||||
{
|
{
|
||||||
|
//printf("回调:停止\r\n");
|
||||||
m_glue.m_deviceevent(70, "Scan Stop");
|
m_glue.m_deviceevent(70, "Scan Stop");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,6 +210,7 @@ void Scanner::runScan()
|
||||||
preFeed();
|
preFeed();
|
||||||
isPaperInit = true;
|
isPaperInit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this_thread::sleep_for(std::chrono::milliseconds(200));
|
this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||||
|
|
||||||
sensor->resetPaperPin();
|
sensor->resetPaperPin();
|
||||||
|
@ -208,8 +224,9 @@ void Scanner::runScan()
|
||||||
m_config.params.pageSize==(int)PaperSize::G400_MAXSIZE;
|
m_config.params.pageSize==(int)PaperSize::G400_MAXSIZE;
|
||||||
StopWatch sw;
|
StopWatch sw;
|
||||||
StopWatch sw1;
|
StopWatch sw1;
|
||||||
StopWatch sw2;
|
|
||||||
isScaning = true;
|
isScaning = true;
|
||||||
|
int error_code = 0;
|
||||||
while (m_DstScannum > 0)
|
while (m_DstScannum > 0)
|
||||||
{
|
{
|
||||||
isScaning = true;
|
isScaning = true;
|
||||||
|
@ -235,7 +252,7 @@ void Scanner::runScan()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
motorCuozhi.startAsyn();
|
motorCuozhi.startAsyn(); //
|
||||||
if (!sensor->isPaperStandby())
|
if (!sensor->isPaperStandby())
|
||||||
{
|
{
|
||||||
put(S_EVT_STOP_SCAN);
|
put(S_EVT_STOP_SCAN);
|
||||||
|
@ -270,29 +287,36 @@ void Scanner::runScan()
|
||||||
|
|
||||||
max = m_config.params.dpi > 2 ? 30 : max * m_config.params.dpi;
|
max = m_config.params.dpi > 2 ? 30 : max * m_config.params.dpi;
|
||||||
|
|
||||||
|
|
||||||
if(m_config.params.pageSize == 17 || m_config.params.pageSize == 19 || m_config.params.slow_moire)
|
if(m_config.params.pageSize == 17 || m_config.params.pageSize == 19 || m_config.params.slow_moire)
|
||||||
{
|
{
|
||||||
max = 200;
|
max = 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
waitpapertime = 200;
|
waitpapertime = 200;
|
||||||
sw2.reset();
|
|
||||||
while (!sensor->waitPaperOut(waitpapertime) && i < max)
|
while (!sensor->waitPaperOut(waitpapertime) && i < max)
|
||||||
{
|
{
|
||||||
|
//printf("max :%d i:%d\r\n",max,i);
|
||||||
i++;
|
i++;
|
||||||
if (!sensor->isPaperIn())
|
if (!sensor->isPaperIn())
|
||||||
{
|
{
|
||||||
LOG("paper 假卡纸了。。。。。\n");
|
printf("paper 假卡纸了。。。。。\n");
|
||||||
isScaning = false;
|
isScaning = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!sensor->isCoverClosed())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (i == max && sensor->isPaperIn())
|
if (i == max && sensor->isPaperIn())
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!m_isDoublePaper)
|
if (!m_isDoublePaper)
|
||||||
{
|
{
|
||||||
|
error_code = S_EVT_JAM_OUT;
|
||||||
m_glue.m_deviceevent(8, "Jam out"); //卡纸
|
m_glue.m_deviceevent(8, "Jam out"); //卡纸
|
||||||
m_jamPaper = true;
|
m_jamPaper = true;
|
||||||
put(S_EVT_JAM_OUT);
|
put(S_EVT_JAM_OUT);
|
||||||
|
@ -305,8 +329,7 @@ void Scanner::runScan()
|
||||||
// LOG("paper 双张了。。。。。\n");
|
// LOG("paper 双张了。。。。。\n");
|
||||||
m_scaninfo.DoubleNum++;
|
m_scaninfo.DoubleNum++;
|
||||||
}
|
}
|
||||||
capturer->stopsnap(b_autosize);
|
capturer->waitsnapdone(error_code);//等待采集完成
|
||||||
capturer->waitsnapdone(1);//等待采集完成
|
|
||||||
this_thread::sleep_for(std::chrono::milliseconds(500));//200 80ms 600 260ms
|
this_thread::sleep_for(std::chrono::milliseconds(500));//200 80ms 600 260ms
|
||||||
isScaning = false;
|
isScaning = false;
|
||||||
break;
|
break;
|
||||||
|
@ -345,16 +368,17 @@ void Scanner::runScan()
|
||||||
{
|
{
|
||||||
m_glue.m_deviceevent((int)HG_ScannerStatus::PAPER_HOLE,"paper have hole");
|
m_glue.m_deviceevent((int)HG_ScannerStatus::PAPER_HOLE,"paper have hole");
|
||||||
|
|
||||||
capturer->waitsnapdone(1);//等待采集完成
|
capturer->waitsnapdone((int)HG_ScannerStatus::PAPER_HOLE);//等待采集完成
|
||||||
|
|
||||||
capturer->stopsnap(b_autosize);
|
|
||||||
isScaning = false;
|
isScaning = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
capturer->stopsnap(b_autosize);
|
capturer->stopsnap(b_autosize);
|
||||||
capturer->waitsnapdone(m_isDoublePaper || m_jamPaper);//等待采集完成
|
|
||||||
|
error_code = m_isDoublePaper ? S_EVT_DOUBLEPAPER : m_jamPaper ? S_EVT_JAM_OUT :0;
|
||||||
|
|
||||||
|
capturer->waitsnapdone(error_code);//等待采集完成
|
||||||
m_DstScannum--;
|
m_DstScannum--;
|
||||||
m_scaninfo.RollerNum++;
|
m_scaninfo.RollerNum++;
|
||||||
m_scaninfo.TotalScanned++;
|
m_scaninfo.TotalScanned++;
|
||||||
|
@ -391,6 +415,7 @@ void Scanner::runScan()
|
||||||
sensor->enableDoubleSensor(false);
|
sensor->enableDoubleSensor(false);
|
||||||
sensor->resetPaperPin();
|
sensor->resetPaperPin();
|
||||||
capturer->setScanFlag(false);
|
capturer->setScanFlag(false);
|
||||||
|
capturer->stopsnap(b_autosize);
|
||||||
|
|
||||||
int t_delay = m_config.params.dpi == 0x02 ? 150 : (m_config.params.dpi == 0x03 ? 350 : 100);
|
int t_delay = m_config.params.dpi == 0x02 ? 150 : (m_config.params.dpi == 0x03 ? 350 : 100);
|
||||||
|
|
||||||
|
@ -444,3 +469,70 @@ std::string Scanner::GetSysInfo()
|
||||||
m_scansysinfo.reset(new SysInforTool(info));
|
m_scansysinfo.reset(new SysInforTool(info));
|
||||||
return m_scansysinfo->GetSysInfo();
|
return m_scansysinfo->GetSysInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Scanner::emergency_stop(int id)
|
||||||
|
{
|
||||||
|
sensor->cancelWaitPaper();
|
||||||
|
sensor->enableDoubleSensor(false);
|
||||||
|
m_DstScannum = 0;
|
||||||
|
if (id == S_EVT_ERROR_DOUBLEPAPER) //双张
|
||||||
|
m_glue.m_deviceevent(S_EVT_ERROR_DOUBLEPAPER, "double feed");
|
||||||
|
// else if(id == S_EVT_COVER_OPENED)
|
||||||
|
// m_glue.m_deviceevent(S_EVT_COVER_OPENED, "cover opened");
|
||||||
|
|
||||||
|
motorCuozhi.stop();
|
||||||
|
motorZouzhi.stop();
|
||||||
|
|
||||||
|
|
||||||
|
capturer->stopsnap(true);
|
||||||
|
put(S_EVT_SCAN_STOPPED);
|
||||||
|
SaveScaninfo(m_scaninfo);
|
||||||
|
start_enter_lowpwoer();
|
||||||
|
printf("emergency_stop capturer->close() \n");
|
||||||
|
}
|
||||||
|
void Scanner::stop_scan()
|
||||||
|
{
|
||||||
|
sensor->cancelWaitPaper();
|
||||||
|
sensor->enableDoubleSensor(false);
|
||||||
|
m_DstScannum = 0;
|
||||||
|
if (threadRunScan.joinable())
|
||||||
|
threadRunScan.join();
|
||||||
|
motorZouzhi.stop();
|
||||||
|
motorCuozhi.stop();
|
||||||
|
|
||||||
|
put(S_EVT_SCAN_STOPPED);
|
||||||
|
SaveScaninfo(m_scaninfo);
|
||||||
|
start_enter_lowpwoer();
|
||||||
|
printf("stop_scan stop_scan stop_scan\r\n");
|
||||||
|
}
|
||||||
|
void Scanner::reset()
|
||||||
|
{
|
||||||
|
if (!sensor->isPaperStandby())
|
||||||
|
{
|
||||||
|
motorCuozhi.reset();
|
||||||
|
isRested = true;
|
||||||
|
isPaperInit = false;
|
||||||
|
LOG("Scanner->motorCuozhi is reseted \n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Scanner::paper_pullout()
|
||||||
|
{
|
||||||
|
if (!m_isPulling)
|
||||||
|
m_isPulling = true;
|
||||||
|
|
||||||
|
motorCuozhi.stop();
|
||||||
|
motorZouzhi.speedChange(1);
|
||||||
|
motorZouzhi.setDirection(1);
|
||||||
|
motorZouzhi.start();
|
||||||
|
if (sensor->waitPaperOut(5000))
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||||
|
motorZouzhi.stop();
|
||||||
|
motorZouzhi.speedRecover();
|
||||||
|
m_isPulling = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Scanner::UpdateScanInfo()
|
||||||
|
{
|
||||||
|
m_scaninfo = GetScanInfoFromJson();
|
||||||
|
updateSpeedMode();
|
||||||
|
}
|
|
@ -23,146 +23,41 @@ class MemoryInfo;
|
||||||
|
|
||||||
class Scanner
|
class Scanner
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
bool isRested = false;
|
||||||
|
bool isScaning = false;
|
||||||
public:
|
public:
|
||||||
Scanner(ScannerGlue glue);
|
Scanner(ScannerGlue glue);
|
||||||
~Scanner();
|
~Scanner();
|
||||||
|
|
||||||
public:
|
|
||||||
bool isRested = false;
|
|
||||||
bool isScaning = false;
|
|
||||||
void startScan();
|
void startScan();
|
||||||
void emergency_stop(int id)
|
void emergency_stop(int id); //只要调用 直接停止整个扫描流程
|
||||||
{
|
void stop_scan(); //扫描线程结束才会停止
|
||||||
|
void reset();
|
||||||
sensor->cancelWaitPaper();
|
void paper_pullout();
|
||||||
m_DstScannum = 0;
|
void CreatCorrectData(int correctmode);
|
||||||
if (id == 1) //双张
|
void UpdateScanInfo();
|
||||||
m_glue.m_deviceevent(16, "double feed");
|
void updateSpeedMode();
|
||||||
|
std::string GetSysInfo();
|
||||||
motorCuozhi.stop();
|
|
||||||
motorZouzhi.stop();
|
|
||||||
|
|
||||||
put(S_EVT_SCAN_STOPPED);
|
|
||||||
SaveScaninfo(m_scaninfo);
|
|
||||||
start_enter_lowpwoer();
|
|
||||||
printf("emergency_stop capturer->close() \n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void stop_scan()
|
|
||||||
{
|
|
||||||
sensor->cancelWaitPaper();
|
|
||||||
m_DstScannum = 0;
|
|
||||||
if (threadRunScan.joinable())
|
|
||||||
threadRunScan.join();
|
|
||||||
motorZouzhi.stop();
|
|
||||||
motorCuozhi.stop();
|
|
||||||
|
|
||||||
put(S_EVT_SCAN_STOPPED);
|
|
||||||
SaveScaninfo(m_scaninfo);
|
|
||||||
start_enter_lowpwoer();
|
|
||||||
LOG("stop_scan() exit22222222 \n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public:
|
||||||
Sensor &getSensor() { return *sensor.get(); }
|
Sensor &getSensor() { return *sensor.get(); }
|
||||||
PanelLeds &getPanelLeds() { return panelLeds; }
|
PanelLeds &getPanelLeds() { return panelLeds; }
|
||||||
int readreg(int addr) { return capturer->read(addr); }
|
inline int readreg(int addr) { return capturer->read(addr); }
|
||||||
void put(ScanEvent evt) { sysEvent.Put(evt); }
|
inline bool isFeederLoaded() { return sensor->isPaperStandby(); }
|
||||||
void reset()
|
inline void put(ScanEvent evt) { sysEvent.Put(evt); }
|
||||||
{
|
|
||||||
if (!sensor->isPaperStandby())
|
|
||||||
{
|
|
||||||
motorCuozhi.reset();
|
|
||||||
isRested = true;
|
|
||||||
isPaperInit = false;
|
|
||||||
LOG("Scanner->motorCuozhi is reseted \n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void paperReady()
|
|
||||||
{
|
|
||||||
LOG("paperReady 22222222 \n");
|
|
||||||
motorZouzhi.start();
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
||||||
motorZouzhi.stop();
|
|
||||||
}
|
|
||||||
bool isFeederLoaded() { return sensor->isPaperStandby(); }
|
|
||||||
void ConfigScanParam(HG_ScanConfiguration config)
|
|
||||||
{
|
|
||||||
m_config = config;
|
|
||||||
LOG("m_config.params.dpi = %d \n \
|
|
||||||
m_config.params.isColor = %d \n \
|
|
||||||
m_config.params.pageSize = %d \n \
|
|
||||||
m_config.params.isCorrect = %d \n",
|
|
||||||
m_config.params.dpi,
|
|
||||||
m_config.params.isColor,
|
|
||||||
m_config.params.pageSize,
|
|
||||||
m_config.params.isCorrect);
|
|
||||||
capturer->UpdateScanParam(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CreatCorrectData(int correctmode);
|
inline void ConfigScanParam(HG_ScanConfiguration config) {capturer->UpdateScanParam(m_config = config); }
|
||||||
void SetDstScanNum(int scannum) { m_DstScannum = scannum; }
|
inline void SetDstScanNum(int scannum) { m_DstScannum = scannum; }
|
||||||
void paper_pullout()
|
inline void SetIsDoublePaper(bool isdoublepaper) { m_isDoublePaper = isdoublepaper; }
|
||||||
{
|
|
||||||
LOG("paper_pullout 22222222 \n");
|
|
||||||
if (!m_isPulling)
|
|
||||||
m_isPulling = true;
|
|
||||||
|
|
||||||
motorCuozhi.stop();
|
inline bool GetIsDoublePaper() { return m_isDoublePaper; }
|
||||||
motorZouzhi.speedChange(1);
|
inline bool GetIsJamPaper() { return m_jamPaper; }
|
||||||
motorZouzhi.setDirection(1);
|
inline bool GetIsJamIn() { return m_jamIn; }
|
||||||
motorZouzhi.start();
|
inline void ResetJamIn() { m_jamIn = false; }
|
||||||
if (sensor->waitPaperOut(5000))
|
inline bool IsScanning() { return !capturer->IsImageQueueEmpty(); }
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
inline void close_v4l2() { capturer->close(); }
|
||||||
motorZouzhi.stop();
|
|
||||||
motorZouzhi.speedRecover();
|
|
||||||
m_isPulling = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetIsDoublePaper(bool isdoublepaper)
|
|
||||||
{
|
|
||||||
m_isDoublePaper = isdoublepaper;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GetIsDoublePaper()
|
|
||||||
{
|
|
||||||
return m_isDoublePaper;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GetIsJamPaper()
|
|
||||||
{
|
|
||||||
return m_jamPaper;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GetIsJamIn()
|
|
||||||
{
|
|
||||||
return m_jamIn;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ResetJamIn()
|
|
||||||
{
|
|
||||||
m_jamIn = false;
|
|
||||||
}
|
|
||||||
bool IsScanning()
|
|
||||||
{
|
|
||||||
return !capturer->IsImageQueueEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
void close_v4l2()
|
|
||||||
{
|
|
||||||
capturer->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void writeParamars(std::string type, int *value)
|
|
||||||
{
|
|
||||||
// capturer->m_configprop->writeParamars(type, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateScanInfo()
|
|
||||||
{
|
|
||||||
m_scaninfo = GetScanInfoFromJson();
|
|
||||||
printf(" UpdateScanInfo speed mode = %d \n",m_scaninfo.SpeedMode);
|
|
||||||
updateSpeedMode();
|
|
||||||
}
|
|
||||||
CaptureParams GetCaptureParams()
|
CaptureParams GetCaptureParams()
|
||||||
{
|
{
|
||||||
CaptureParams param;
|
CaptureParams param;
|
||||||
|
@ -170,22 +65,11 @@ public:
|
||||||
// return capturer->m_configprop->captureParmars;
|
// return capturer->m_configprop->captureParmars;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScannerScanInfo &GetScanInfo()
|
ScannerScanInfo &GetScanInfo() { return m_scaninfo; }
|
||||||
{
|
|
||||||
return m_scaninfo;
|
|
||||||
}
|
|
||||||
void updateSpeedMode();
|
|
||||||
void ResetCorrectflags() { m_correctting = false; }
|
|
||||||
void StopScan(int Evt)
|
|
||||||
{
|
|
||||||
put(S_EVT_STOP_SCAN);
|
|
||||||
//capturer->clearimages();
|
|
||||||
//capturer->resetimageremain();
|
|
||||||
//m_glue.m_deviceevent(70, "Scan done");
|
|
||||||
}
|
|
||||||
std::string GetSysInfo();
|
|
||||||
|
|
||||||
ScannerSysInfo &GetSysinfoStruct() { return m_scansysinfo->GetInfo(); }
|
ScannerSysInfo &GetSysinfoStruct() { return m_scansysinfo->GetInfo(); }
|
||||||
|
void ResetCorrectflags() { m_correctting = false; }
|
||||||
|
void StopScan(int Evt) { put(S_EVT_STOP_SCAN); }
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//处理事件
|
//处理事件
|
||||||
|
@ -202,29 +86,37 @@ private:
|
||||||
private:
|
private:
|
||||||
ZouZhiMotor motorZouzhi;
|
ZouZhiMotor motorZouzhi;
|
||||||
CuoZhiMotor motorCuozhi;
|
CuoZhiMotor motorCuozhi;
|
||||||
std::shared_ptr<Sensor> sensor;
|
|
||||||
PanelLeds panelLeds;
|
PanelLeds panelLeds;
|
||||||
std::thread threadRunScan;
|
std::thread threadRunScan;
|
||||||
std::thread threadRunMessageLoop;
|
std::thread threadRunMessageLoop;
|
||||||
volatile bool bMsgLoop = true;
|
|
||||||
BlockingQueue<ScanEvent> sysEvent;
|
BlockingQueue<ScanEvent> sysEvent;
|
||||||
std::shared_ptr<ICapturer> capturer;
|
|
||||||
std::shared_ptr<huagao::Keyboard> m_keyboard;
|
|
||||||
ScannerGlue m_glue;
|
ScannerGlue m_glue;
|
||||||
HG_ScanConfiguration m_config;
|
HG_ScanConfiguration m_config;
|
||||||
ScannerScanInfo m_scaninfo;
|
ScannerScanInfo m_scaninfo;
|
||||||
std::thread m_correctThread;
|
std::thread m_correctThread;
|
||||||
volatile int m_DstScannum = 500;
|
|
||||||
bool m_isPulling;
|
bool m_isPulling;
|
||||||
|
|
||||||
|
volatile bool bMsgLoop = true;
|
||||||
|
volatile int m_DstScannum = 500;
|
||||||
volatile bool m_isDoublePaper;
|
volatile bool m_isDoublePaper;
|
||||||
volatile bool m_jamPaper;
|
volatile bool m_jamPaper;
|
||||||
volatile bool m_jamIn;
|
volatile bool m_jamIn;
|
||||||
bool isPaperInit;
|
|
||||||
volatile bool m_correctting;
|
volatile bool m_correctting;
|
||||||
|
|
||||||
|
bool isPaperInit;
|
||||||
|
|
||||||
int waitpapertime;
|
int waitpapertime;
|
||||||
MemoryInfo *meminfo;
|
MemoryInfo *meminfo;
|
||||||
CISVendor cisvendor;
|
CISVendor cisvendor;
|
||||||
|
|
||||||
std::shared_ptr<SysInforTool> m_scansysinfo;
|
std::shared_ptr<SysInforTool> m_scansysinfo;
|
||||||
std::shared_ptr<ICapturer> m_capturer;
|
std::shared_ptr<ICapturer> m_capturer;
|
||||||
std::shared_ptr<FpgaComm> m_fpga;
|
std::shared_ptr<FpgaComm> m_fpga;
|
||||||
|
std::shared_ptr<ICapturer> capturer;
|
||||||
|
std::shared_ptr<huagao::Keyboard> m_keyboard;
|
||||||
|
std::shared_ptr<Sensor> sensor;
|
||||||
};
|
};
|
||||||
|
|
|
@ -149,6 +149,7 @@ void Sensor::monitor()
|
||||||
StopWatch sw2;
|
StopWatch sw2;
|
||||||
num = read(pfd.fd, buf, 8); // This is to clear the avaible read
|
num = read(pfd.fd, buf, 8); // This is to clear the avaible read
|
||||||
std::cout<<"read time "<< sw.elapsed_ms()<<std::endl;
|
std::cout<<"read time "<< sw.elapsed_ms()<<std::endl;
|
||||||
|
int indx = 0;
|
||||||
while (bMonitor)
|
while (bMonitor)
|
||||||
{
|
{
|
||||||
ret = poll(&pfd, 1, 1000);
|
ret = poll(&pfd, 1, 1000);
|
||||||
|
@ -160,7 +161,13 @@ void Sensor::monitor()
|
||||||
{
|
{
|
||||||
if(sw.elapsed_ms() < 10)
|
if(sw.elapsed_ms() < 10)
|
||||||
{
|
{
|
||||||
printf("扫描传感器消抖。。。\r\n");
|
indx++;
|
||||||
|
if (indx % 10 == 0)
|
||||||
|
{
|
||||||
|
printf("扫描传感器消抖数:%d\r\n",indx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sw.reset();
|
sw.reset();
|
||||||
ret = poll(&pfd, 1, 1);
|
ret = poll(&pfd, 1, 1);
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
|
@ -178,6 +185,7 @@ void Sensor::monitor()
|
||||||
buf[num - 1] = '\0';
|
buf[num - 1] = '\0';
|
||||||
ret = atoi(buf);
|
ret = atoi(buf);
|
||||||
bool b = false;
|
bool b = false;
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
b = true;
|
b = true;
|
||||||
|
@ -189,8 +197,12 @@ void Sensor::monitor()
|
||||||
printf("检测纸张出去 time:%f\r\n",sw1.elapsed_ms());
|
printf("检测纸张出去 time:%f\r\n",sw1.elapsed_ms());
|
||||||
sw2.reset();
|
sw2.reset();
|
||||||
if (!b) //理论上来说
|
if (!b) //理论上来说
|
||||||
|
{
|
||||||
|
printf("没有检测到纸张进入\r\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
edges[ret]->notify_all();
|
edges[ret]->notify_all();
|
||||||
|
|
||||||
sw.reset();
|
sw.reset();
|
||||||
|
@ -270,11 +282,21 @@ void Sensor::monitor2()
|
||||||
}
|
}
|
||||||
if (i != 2 && i != 3)
|
if (i != 2 && i != 3)
|
||||||
{
|
{
|
||||||
if(i == 1)
|
|
||||||
|
int val = i * 2 + ret;
|
||||||
|
|
||||||
|
if (is_open_cover && (val == 1 || val == 2 ||val == 3)) //这个地方主要作用是在开盖以防其他状态消息发送
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(val == 1)
|
||||||
{
|
{
|
||||||
|
is_open_cover = true;
|
||||||
cv_paper_on.notify_all();
|
cv_paper_on.notify_all();
|
||||||
}
|
}
|
||||||
events.Put(evts[i * 2 + ret]);
|
if(val == 0)
|
||||||
|
is_open_cover = false;
|
||||||
|
|
||||||
|
events.Put(evts[val]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,7 @@ private:
|
||||||
volatile bool double_1 = false;
|
volatile bool double_1 = false;
|
||||||
volatile bool double_2 = false;
|
volatile bool double_2 = false;
|
||||||
volatile bool enbale_double_=false;
|
volatile bool enbale_double_=false;
|
||||||
|
volatile bool is_open_cover = false;
|
||||||
void monitor();
|
void monitor();
|
||||||
void monitor2();
|
void monitor2();
|
||||||
int readfile(int fd,int num , char* buf);
|
int readfile(int fd,int num , char* buf);
|
||||||
|
|
|
@ -133,7 +133,7 @@ UsbScanner::UsbScanner() : m_startscan(false),
|
||||||
{
|
{
|
||||||
imageremain++;
|
imageremain++;
|
||||||
m_images.Put(imageinfo);
|
m_images.Put(imageinfo);
|
||||||
printf("队列缓存张数 :%d\r\n",m_images.Size());
|
LOG("队列缓存张数:%d\r\n",m_images.Size());
|
||||||
};
|
};
|
||||||
|
|
||||||
auto deviceevent = [this](const int eventID, std::string capmsg)
|
auto deviceevent = [this](const int eventID, std::string capmsg)
|
||||||
|
@ -297,7 +297,12 @@ void UsbScanner::ClearHWError()
|
||||||
|
|
||||||
bool UsbScanner::GetImagequeueEmpty()
|
bool UsbScanner::GetImagequeueEmpty()
|
||||||
{
|
{
|
||||||
return imageremain == 0;
|
if (m_images.Size() != 0)
|
||||||
|
{
|
||||||
|
LOG("队列剩余图像帧数:%d\r\n",m_images.Size());
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_images.Size() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UsbScanner::GetEventQueueEmpty()
|
bool UsbScanner::GetEventQueueEmpty()
|
||||||
|
@ -358,8 +363,6 @@ void UsbScanner::SetFlatParam(int type, int *value)
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!ttype.empty())
|
|
||||||
m_hgScanner->writeParamars(ttype, value);
|
|
||||||
}
|
}
|
||||||
CaptureParams UsbScanner::GetCaptureParams()
|
CaptureParams UsbScanner::GetCaptureParams()
|
||||||
{
|
{
|
||||||
|
|
|
@ -311,6 +311,7 @@ int main(int argc, char *argv[])
|
||||||
// LOG("Scanning not scanning \n");
|
// LOG("Scanning not scanning \n");
|
||||||
if (!m_scanner->GetImagequeueEmpty())
|
if (!m_scanner->GetImagequeueEmpty())
|
||||||
{
|
{
|
||||||
|
|
||||||
HG_JpegCompressInfo info = m_scanner->GetFrontImage();
|
HG_JpegCompressInfo info = m_scanner->GetFrontImage();
|
||||||
sts.Data = (int)HG_ScannerStatus::HAVE_IMAGE;
|
sts.Data = (int)HG_ScannerStatus::HAVE_IMAGE;
|
||||||
sts.Length = info.DataLength;
|
sts.Length = info.DataLength;
|
||||||
|
@ -342,10 +343,11 @@ int main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
case USBCommand::GET_IMAGE:
|
case USBCommand::GET_IMAGE:
|
||||||
{
|
{
|
||||||
printf("传图中\r\n");
|
|
||||||
HG_JpegCompressInfo info = m_scanner->GetImage();
|
HG_JpegCompressInfo info = m_scanner->GetImage();
|
||||||
if (info.pJpegData != nullptr && info.DataLength != 0)
|
printf("USB error_code:%d\r\n",info.error_code);
|
||||||
|
if (info.pJpegData != nullptr && info.DataLength != 0 || info.error_code)
|
||||||
{
|
{
|
||||||
|
|
||||||
int tt = m_scanner->write_bulk((void *)&info, sizeof(int) * 8);
|
int tt = m_scanner->write_bulk((void *)&info, sizeof(int) * 8);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int total = info.DataLength;
|
int total = info.DataLength;
|
||||||
|
|
|
@ -83,7 +83,7 @@ enum class LedStatus
|
||||||
|
|
||||||
struct HG_JpegCompressInfo
|
struct HG_JpegCompressInfo
|
||||||
{
|
{
|
||||||
unsigned int data_type;
|
unsigned int error_code;
|
||||||
unsigned int first_frame;
|
unsigned int first_frame;
|
||||||
unsigned int last_frame;
|
unsigned int last_frame;
|
||||||
unsigned int index_frame;
|
unsigned int index_frame;
|
||||||
|
@ -222,7 +222,6 @@ struct V4L2_DATAINFO
|
||||||
|
|
||||||
struct V4L2_DATAINFO_Ex:V4L2_DATAINFO
|
struct V4L2_DATAINFO_Ex:V4L2_DATAINFO
|
||||||
{
|
{
|
||||||
unsigned int snaped_index;
|
|
||||||
unsigned int frame_index; //总帧数
|
unsigned int frame_index; //总帧数
|
||||||
unsigned int dpi; //dpi
|
unsigned int dpi; //dpi
|
||||||
unsigned int error_code;
|
unsigned int error_code;
|
||||||
|
|
Loading…
Reference in New Issue