├── test.cpp ├── 停车场管理系统设计说明书.doc ├── OOT └── .test.cpp.swp ├── main.cpp ├── sysconfig.ini ├── comeinplot.csv ├── cdisplaysplotinfo.h ├── cconfiglefile.h ├── employee_checkin.csv ├── myqueuecacheinfo.h ├── parkplotinfo.h ├── comeinplotthread.h ├── workthread.h ├── parklot.h ├── cdisplaysplotinfo.cpp ├── OOT.pro ├── logger.h ├── myqueuecacheinfo.cpp ├── README.md ├── common.h ├── cconfiglefile.cpp ├── logger.cpp ├── parkplotinfo.cpp ├── parklot.cpp ├── comeinplotthread.cpp ├── parklot.ui ├── workthread.cpp └── OOT.pro.user /test.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /停车场管理系统设计说明书.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stevezhou7020/QTCPP/HEAD/停车场管理系统设计说明书.doc -------------------------------------------------------------------------------- /OOT/.test.cpp.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stevezhou7020/QTCPP/HEAD/OOT/.test.cpp.swp -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"cconfiglefile.h" 3 | #include 4 | #include "parklot.h" 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QApplication a(argc, argv); 10 | parklot w; 11 | w.show(); 12 | return a.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /sysconfig.ini: -------------------------------------------------------------------------------- 1 | [SPARKPLOT] 2 | #停车位的个数: 3 | SPARKPLOT_MAX=20 4 | [REFREASHTIME] 5 | #刷新时间1S 6 | FREASHTIMEPROCESS=1 7 | #入库,出库线程反复调用的时间间隔(秒) 8 | THREADINTERVIAL=1 9 | [SPLOTTIME] 10 | #车在库中停顿的时间(单位s) 11 | EACHSPLOTTIME=5 12 | #读卡时间1s 13 | READCARDTIME=1 14 | #栏杆抬起放下2s 15 | OPERATEHANDRAIL=2 16 | #汽车行驶速度1s/1splot 17 | CARDSPEED=1 18 | #汽车出库,入库到行道上 19 | CARDOPERATE=2 20 | -------------------------------------------------------------------------------- /comeinplot.csv: -------------------------------------------------------------------------------- 1 | 编号,cardID,用户名,性别,车牌号 2 | 13,C00000012,周错误,男,陕A000012 3 | 1,C00000002,周2,男,陕A000002 4 | 2,C00000003,周3,男,陕A000003 5 | 3,C00000004,周4,男,陕A000004 6 | 4,C00000005,周5,男,陕A000005 7 | 5,C00000006,周6,男,陕A000006 8 | 6,C00000007,周7,男,陕A000007 9 | 7,C00000008,周8,男,陕A000008 10 | 8,C00000009,周9,男,陕A000009 11 | 9,C00000010,周10,男,陕A000010 12 | 10,C00000011,周11,男,陕A000011 13 | 11,C00000012,周12,男,陕A000012 14 | 12,C00000013,周13,男,陕A000013 15 | 13,C00000014,周14,男,陕A000014 16 | 14,C00000015,周15,男,陕A000015 17 | 15,C00000016,周16,男,陕A000016 18 | 16,C00000017,周17,男,陕A000017 19 | 17,C00000018,周18,男,陕A000018 20 | 18,C00000019,周19,男,陕A000019 21 | 19,C00000020,周20,男,陕A000020 22 | 20,C00000021,周21,男,陕A000021 23 | 21,C00000022,周22,男,陕A000022 24 | 22,C00000023,周23,男,陕A000023 25 | 23,C00000024,周24,男,陕A000024 26 | 24,C00000025,周25,男,陕A000025 27 | 25,C00000026,周26,男,陕A000026 28 | -------------------------------------------------------------------------------- /cdisplaysplotinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef CDISPLAYSPLOTINFO_H 2 | #define CDISPLAYSPLOTINFO_H 3 | #include 4 | #include "myqueuecacheinfo.h" 5 | #include "QCheckBox" 6 | #include 7 | #include 8 | #include 9 | #include "parkplotinfo.h" 10 | 11 | class CDisplaySplotInfo : public QThread 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit CDisplaySplotInfo(QObject* parent = nullptr); 16 | ~CDisplaySplotInfo() Q_DECL_OVERRIDE; 17 | void stopThread(); 18 | public: 19 | virtual void run() Q_DECL_OVERRIDE; 20 | signals: 21 | void timeReady(); 22 | public slots: 23 | void threadProcess(); 24 | private: 25 | void refreashTextEdit(queueInfo* tempqueueinfo); 26 | private: 27 | QMutex m_mutex; 28 | QSemaphore* sem; 29 | QTextEdit* parkinfoview; 30 | bool isStop; 31 | unsigned int starttimeSeconds; 32 | }; 33 | 34 | #endif // CDISPLAYSPLOTINFO_H 35 | -------------------------------------------------------------------------------- /cconfiglefile.h: -------------------------------------------------------------------------------- 1 | #ifndef CCONFIGLEFILE_H 2 | #define CCONFIGLEFILE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | /*单例模式*/ 15 | /*获取配置文件数据*/ 16 | class Cconfiglefile 17 | { 18 | public: 19 | ~Cconfiglefile(); 20 | Cconfiglefile(const Cconfiglefile & conf)=delete; 21 | Cconfiglefile& operator=(const Cconfiglefile &)=delete; 22 | 23 | static const Cconfiglefile* getconfigfileInstance(); 24 | 25 | /*判断出入库卡信息是否登记过*/ 26 | bool check_cardInfo(const QString& cardId,const QString& username) const; 27 | /*获取系统的配置文件*/ 28 | const QString getSysconfig(const QString & fieldname ,const QString subname) const; 29 | private: 30 | Cconfiglefile(); 31 | static Cconfiglefile* configinstance; 32 | }; 33 | 34 | #endif // CCONFIGLEFILE_H 35 | -------------------------------------------------------------------------------- /employee_checkin.csv: -------------------------------------------------------------------------------- 1 | 编号,cardID,用户名,性别,车牌号,"是否有效(0无效,1有效)" 2 | 1,C00000001,周1,男,陕A000001,1 3 | 2,C00000002,周2,男,陕A000002,1 4 | 3,C00000003,周3,男,陕A000003,1 5 | 4,C00000004,周4,男,陕A000004,1 6 | 5,C00000005,周5,男,陕A000005,0 7 | 6,C00000006,周6,男,陕A000006,1 8 | 7,C00000007,周7,男,陕A000007,1 9 | 8,C00000008,周8,男,陕A000008,1 10 | 9,C00000009,周9,男,陕A000009,1 11 | 10,C00000010,周10,男,陕A000010,1 12 | 11,C00000011,周11,男,陕A000011,1 13 | 12,C00000012,周12,男,陕A000012,0 14 | 13,C00000013,周13,男,陕A000013,1 15 | 14,C00000014,周14,男,陕A000014,1 16 | 15,C00000015,周15,男,陕A000015,1 17 | 16,C00000016,周16,男,陕A000016,0 18 | 17,C00000017,周17,男,陕A000017,1 19 | 18,C00000018,周18,男,陕A000018,1 20 | 19,C00000019,周19,男,陕A000019,1 21 | 20,C00000020,周20,男,陕A000020,0 22 | 21,C00000021,周21,男,陕A000021,1 23 | 22,C00000022,周22,男,陕A000022,1 24 | 23,C00000023,周23,男,陕A000023,1 25 | 24,C00000024,周24,男,陕A000024,1 26 | 25,C00000025,周25,男,陕A000025,1 27 | -------------------------------------------------------------------------------- /myqueuecacheinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef MYQUEUECACHEINFO_H 2 | #define MYQUEUECACHEINFO_H 3 | #include "common.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | /*单例模式*/ 9 | class myQueueCacheInfo 10 | { 11 | public: 12 | ~myQueueCacheInfo(); 13 | myQueueCacheInfo(const myQueueCacheInfo&) =delete ; 14 | myQueueCacheInfo& operator=(const myQueueCacheInfo&) =delete; 15 | 16 | static myQueueCacheInfo* getQueueCashInfoInstance(); 17 | 18 | public: 19 | /**入库队列信息*/ 20 | QList comeInInfoList; 21 | /*出库队列信息*/ 22 | QList outtingInfoList; 23 | 24 | QList& getOutFreeQueueInfoList(); 25 | 26 | void releaseLock_out(); 27 | private: 28 | static myQueueCacheInfo* myqueuecacheinfo; 29 | /*出库抬栏杆队列*/ 30 | QQueue outingqueue; 31 | 32 | QReadWriteLock lock_out; 33 | myQueueCacheInfo(); 34 | }; 35 | #endif // MYQUEUECACHEINFO_H 36 | -------------------------------------------------------------------------------- /parkplotinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef PARKPLOTINFO_H 2 | #define PARKPLOTINFO_H 3 | /*主要用来处理 停车场相关信息*/ 4 | #include "common.h" 5 | #include "cconfiglefile.h" 6 | #include 7 | #include 8 | 9 | /*单例模式*/ 10 | class parkplotInfo 11 | { 12 | public: 13 | static parkplotInfo* getparkplotInstance(); 14 | 15 | parkplotInfo(const parkplotInfo * info)=delete; 16 | parkplotInfo& operator=(const parkplotInfo & info)=delete; 17 | 18 | ~parkplotInfo(); 19 | /*获取下一块没被占用的停车位信息*/ 20 | myparkspotInfo* getNextParkspotInfo(); 21 | /*获取所有停车位信息*/ 22 | const myParkplotInfoMemory* getAllParkplotMemory(); 23 | /*释放车位资源*/ 24 | void releaseParkSpot(unsigned int IDNumber); 25 | 26 | /****************以下方法只是作为显示数据时候调用,不能用作多线程流程处理(结果有延时)*******************/ 27 | /*获取停车位的总数*/ 28 | unsigned int getAllSplotNum(); 29 | /*获取停车位空闲数目*/ 30 | unsigned int getUnusedSplotNum(); 31 | /*获取停车位占用数目*/ 32 | unsigned int getUsedSplotNum() ; 33 | private: 34 | parkplotInfo(); 35 | myParkplotInfoMemory* myparkplotmemory; 36 | static parkplotInfo* parkplotInstance; 37 | unsigned int IparkplotNum{0}; 38 | QReadWriteLock* lock; 39 | }; 40 | 41 | #endif // PARKPLOTINFO_H 42 | -------------------------------------------------------------------------------- /comeinplotthread.h: -------------------------------------------------------------------------------- 1 | #ifndef COMEINPLOTTHREAD_H 2 | #define COMEINPLOTTHREAD_H 3 | #include 4 | #include "cconfiglefile.h" 5 | #include 6 | #include "myqueuecacheinfo.h" 7 | #include "parkplotinfo.h" 8 | #include 9 | #include 10 | 11 | class ComeInPlotThread : public QThread 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit ComeInPlotThread(QObject* parent = nullptr,QObject* parent1 = nullptr,QObject* parent2 = nullptr,QObject* parent3 = nullptr); 16 | ~ComeInPlotThread() Q_DECL_OVERRIDE; 17 | void setQueueInfo(QList* queueinfo); 18 | void refreashTextEdit(queueInfo* tempoutqueueInfo); 19 | public: 20 | virtual void run() Q_DECL_OVERRIDE; 21 | signals: 22 | void comeinplottimeReady(); 23 | public slots: 24 | void comeinplotthreadProcess(); 25 | private: 26 | QCheckBox* checkbox; 27 | QTextEdit* TextEdit1; 28 | QTextEdit* TextEdit2; 29 | QTextEdit* TextCheckView; 30 | bool isStop; 31 | QMutex m_mutex; 32 | QSemaphore* sem; 33 | QList* tempqueueInfo; 34 | QString readyInUsers; 35 | int number; 36 | public: 37 | void stopThread(); 38 | }; 39 | 40 | #endif // COMEINPLOTTHREAD_H 41 | -------------------------------------------------------------------------------- /workthread.h: -------------------------------------------------------------------------------- 1 | #ifndef WORKTHREAD_H 2 | #define WORKTHREAD_H 3 | #include 4 | #include 5 | #include "myqueuecacheinfo.h" 6 | #include "parkplotinfo.h" 7 | #include "QCheckBox" 8 | #include "common.h" 9 | #include 10 | 11 | 12 | 13 | /*每隔1S中看入队缓存是否时间到,可以转达出库缓存*/ 14 | class workThread :public QThread 15 | { 16 | Q_OBJECT 17 | public: 18 | // workThread(QObject* parent = nullptr,void (*p)(QString ID,QString username,unsigned int IspotNum,unsigned int istatus)= nullptr); 19 | explicit workThread(QObject* parent = nullptr,QObject* parent1 = nullptr,QObject* parent2 = nullptr); 20 | ~workThread() Q_DECL_OVERRIDE; 21 | void stopThread(); 22 | public: 23 | virtual void run() Q_DECL_OVERRIDE; 24 | 25 | signals: 26 | void timeReady(); 27 | public slots: 28 | void threadProcess(); 29 | private: 30 | void refreashTextEdit(queueInfo* tempqueueinfo,int type=0);//0 正常出库 1 出库检测失败 31 | private: 32 | QMutex m_mutex; 33 | QSemaphore* sem; 34 | QCheckBox* checkbox; 35 | QTextEdit* TextEdit1; 36 | QTextEdit* TextEdit2; 37 | bool isStop; 38 | // void (*callback)(QString ID,QString usename,unsigned int, unsigned int istatus);//0 出库成功 1失败 39 | }; 40 | 41 | #endif // WORKTHREAD_H 42 | -------------------------------------------------------------------------------- /parklot.h: -------------------------------------------------------------------------------- 1 | #ifndef PARKLOT_H 2 | #define PARKLOT_H 3 | 4 | #include 5 | #include "common.h" 6 | #include "cconfiglefile.h" 7 | #include "parkplotinfo.h" 8 | #include "workthread.h" 9 | #include "comeinplotthread.h" 10 | #include 11 | #include 12 | #include 13 | #include "cdisplaysplotinfo.h" 14 | 15 | 16 | namespace Ui { 17 | class parklot; 18 | } 19 | 20 | class parklot : public QMainWindow 21 | { 22 | Q_OBJECT 23 | public: 24 | explicit parklot(QWidget *parent = nullptr); 25 | ~parklot(); 26 | /*启动线程*/ 27 | void startWorkThread(); 28 | // static void runOuttingRelationFunc(QString sID, QString susername, unsigned int IspotNum,unsigned int istatus); 29 | private slots: 30 | void on_safequit_clicked(); 31 | //导入入库资源 32 | void on_pushButton_clicked(); 33 | //仿真正式开始 34 | void on_startBtn_clicked(); 35 | public: 36 | /*临时存储*/ 37 | QList tempComeInInfo; 38 | private: 39 | Ui::parklot *ui; 40 | bool stoptimer; 41 | QString username; 42 | QString ID; 43 | unsigned int istatus;/*0 出库成功 1 出库失败*/ 44 | private: 45 | /*启动线程*/ 46 | workThread* myworkThread; 47 | /*入库线程*/ 48 | ComeInPlotThread* mycomInparkThread; 49 | /*刷新停车场信息*/ 50 | CDisplaySplotInfo* displaysplotinfo; 51 | }; 52 | 53 | #endif // PARKLOT_H 54 | -------------------------------------------------------------------------------- /cdisplaysplotinfo.cpp: -------------------------------------------------------------------------------- 1 | #include "cdisplaysplotinfo.h" 2 | 3 | CDisplaySplotInfo::CDisplaySplotInfo(QObject* parent) 4 | { 5 | parkinfoview = (QTextEdit*)parent; 6 | sem = new QSemaphore(1); 7 | sem->release(); 8 | isStop = false; 9 | starttimeSeconds = 1; 10 | } 11 | CDisplaySplotInfo::~CDisplaySplotInfo() 12 | { 13 | if(sem!=nullptr) 14 | { 15 | delete sem; 16 | sem=nullptr; 17 | } 18 | quit(); 19 | wait(); 20 | } 21 | void CDisplaySplotInfo::run() 22 | { 23 | connect(this,SIGNAL(timeReady()),this,SLOT(threadProcess())); 24 | while(!isStop) 25 | { 26 | if(sem == nullptr) break; 27 | while(!sem->tryAcquire(1)) 28 | { 29 | QThread::msleep(10); 30 | } 31 | emit timeReady(); 32 | starttimeSeconds++; 33 | QThread::sleep(1); 34 | } 35 | } 36 | void CDisplaySplotInfo::stopThread() 37 | { 38 | isStop = true; 39 | } 40 | void CDisplaySplotInfo::threadProcess() 41 | { 42 | unsigned int num=parkplotInfo::getparkplotInstance()->getUnusedSplotNum(); 43 | qDebug()<<"剩余停车位:"<clear(); 51 | parkinfoview->setPlaceholderText(tempdata); 52 | parkinfoview->repaint(); 53 | parkinfoview->show(); 54 | sem->release(); 55 | } 56 | -------------------------------------------------------------------------------- /OOT.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2018-11-13T21:08:27 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = OOT 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | CONFIG += c++11 26 | 27 | SOURCES += \ 28 | main.cpp \ 29 | parklot.cpp \ 30 | cconfiglefile.cpp \ 31 | parkplotinfo.cpp \ 32 | workthread.cpp \ 33 | myqueuecacheinfo.cpp \ 34 | comeinplotthread.cpp \ 35 | cdisplaysplotinfo.cpp \ 36 | logger.cpp 37 | 38 | HEADERS += \ 39 | parklot.h \ 40 | common.h \ 41 | cconfiglefile.h \ 42 | parkplotinfo.h \ 43 | workthread.h \ 44 | myqueuecacheinfo.h \ 45 | comeinplotthread.h \ 46 | cdisplaysplotinfo.h \ 47 | logger.h 48 | 49 | FORMS += \ 50 | parklot.ui 51 | 52 | # Default rules for deployment. 53 | qnx: target.path = /tmp/$${TARGET}/bin 54 | else: unix:!android: target.path = /opt/$${TARGET}/bin 55 | !isEmpty(target.path): INSTALLS += target 56 | 57 | DISTFILES += \ 58 | sysconfig.ini 59 | -------------------------------------------------------------------------------- /logger.h: -------------------------------------------------------------------------------- 1 | /***********Download from github**********/ 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | struct tm; 8 | 9 | namespace logger 10 | { 11 | enum class Level { Debug, Info, Warning, Error, Fatal }; 12 | class FileLogger; 13 | class ConsoleLogger; 14 | class BaseLogger; 15 | 16 | class BaseLogger 17 | { 18 | class LogStream; 19 | public: 20 | BaseLogger() = default; 21 | virtual ~BaseLogger() = default; 22 | 23 | virtual LogStream operator()(Level nLevel = Level::Debug); 24 | private: 25 | const tm* getLocalTime(); 26 | void endline(Level nLevel, std::string&& oMessage); 27 | virtual void output(const tm *p_tm, 28 | const char *str_level, 29 | const char *str_message) = 0; 30 | private: 31 | std::mutex _lock; 32 | tm _localTime; 33 | }; 34 | 35 | class BaseLogger::LogStream : public std::ostringstream 36 | { 37 | BaseLogger& m_oLogger; 38 | Level m_nLevel; 39 | public: 40 | LogStream(BaseLogger& oLogger, Level nLevel) 41 | : m_oLogger(oLogger), m_nLevel(nLevel) {}; 42 | LogStream(const LogStream& ls) 43 | : m_oLogger(ls.m_oLogger), m_nLevel(ls.m_nLevel) {}; 44 | ~LogStream() 45 | { 46 | m_oLogger.endline(m_nLevel, std::move(str())); 47 | } 48 | }; 49 | 50 | class ConsoleLogger : public BaseLogger 51 | { 52 | using BaseLogger::BaseLogger; 53 | virtual void output(const tm *p_tm, 54 | const char *str_level, 55 | const char *str_message); 56 | }; 57 | 58 | class FileLogger : public BaseLogger 59 | { 60 | public: 61 | FileLogger(std::string filename) noexcept; 62 | FileLogger(const FileLogger&) = delete; 63 | FileLogger(FileLogger&&) = delete; 64 | virtual ~FileLogger(); 65 | private: 66 | virtual void output(const tm *p_tm, 67 | const char *str_level, 68 | const char *str_message); 69 | private: 70 | std::ofstream _file; 71 | }; 72 | 73 | extern ConsoleLogger debug; 74 | extern FileLogger record; 75 | 76 | } // namespace logger 77 | -------------------------------------------------------------------------------- /myqueuecacheinfo.cpp: -------------------------------------------------------------------------------- 1 | #include "myqueuecacheinfo.h" 2 | 3 | /*单例模式*/ 4 | myQueueCacheInfo* myQueueCacheInfo::myqueuecacheinfo = new myQueueCacheInfo(); 5 | 6 | myQueueCacheInfo::~myQueueCacheInfo() 7 | { 8 | for(QList::iterator item = comeInInfoList.begin(); item != comeInInfoList.end() ; ++item) 9 | { 10 | queueInfo* temp = item.i->t(); 11 | if(temp == nullptr) continue; 12 | delete temp; 13 | } 14 | comeInInfoList.clear(); 15 | 16 | for(QList::iterator item = outtingInfoList.begin(); item != outtingInfoList.end() ; ++item) 17 | { 18 | queueInfo* temp = item.i->t(); 19 | if(temp == nullptr) continue; 20 | delete temp; 21 | } 22 | outtingInfoList.clear(); 23 | 24 | if(myqueuecacheinfo != nullptr) 25 | { 26 | delete myqueuecacheinfo; 27 | myqueuecacheinfo = nullptr; 28 | } 29 | } 30 | 31 | myQueueCacheInfo* myQueueCacheInfo::getQueueCashInfoInstance() 32 | { 33 | return myqueuecacheinfo; 34 | } 35 | 36 | myQueueCacheInfo::myQueueCacheInfo() 37 | { 38 | outtingInfoList.clear(); 39 | } 40 | 41 | QList& myQueueCacheInfo::getOutFreeQueueInfoList() 42 | { 43 | while(1) 44 | { 45 | if(lock_out.tryLockForWrite()) 46 | { 47 | return comeInInfoList; 48 | } 49 | QThread::msleep(50); 50 | } 51 | } 52 | 53 | void myQueueCacheInfo::releaseLock_out() 54 | { 55 | lock_out.unlock(); 56 | } 57 | //int myQueueCacheInfo::outQueueSize() 58 | //{ 59 | // return outingqueue.size(); 60 | //} 61 | //unsigned int myQueueCacheInfo::outQueuePop() 62 | //{ 63 | // unsigned int temp; 64 | // while(1) 65 | // { 66 | // if(lock.tryLockForWrite()) 67 | // { 68 | // temp = outingqueue.first(); 69 | // outingqueue.pop_front(); 70 | // lock.unlock(); 71 | // return temp; 72 | // } 73 | // QThread::msleep(10); 74 | // } 75 | //} 76 | //void myQueueCacheInfo::outQueuePushBack(unsigned int seconds) 77 | //{ 78 | // while(1) 79 | // { 80 | // if(lock.tryLockForWrite()) 81 | // { 82 | // outingqueue.push_back(seconds); 83 | // lock.unlock(); 84 | // break; 85 | // } 86 | // QThread::msleep(10); 87 | // } 88 | //} 89 | 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QTCPP 2 | 利用QT可视化编程实现停车场管理系统 3 | 4 | 5 | 停车场管理系统 6 | 7 | 用面向对象方法和面向对象程序设计语言,实现满足下述要求的停车场仿真程序。 8 | 1.问题域概述 9 | 某企业欲为其内部停车场建设一套信息系统,已经调查到的需求如下: 10 | (1)企业为每位员工均发放一张感应式IC卡,卡上记录员工号。该卡由专门的卡管理系统 M 制作和维护,本系统需通过 M 来验证卡的有效性。 11 | (2)在停车场的入口和出口处分别安装一个自动栏杆、一台感应式IC卡读卡器和一个车辆通过传感器,如下图所示。 12 | 13 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190122203452344.png) 14 | (3)入口处安装一个显示屏(上图中未给出),显示当前空闲车位数量。 15 | 若停车场当前没有空闲车位,则不允许汽车入场,只许场内的汽车出场。 16 | (4)当一辆入场汽车到达入口时,用读卡器读出驾驶员的卡上信息,系统根据读出内容检查该卡的合法性:若该卡有效(需问M)&& 未被记录于当前场内卡号集合(即其车在场内的员工集合)中,即为合法卡。 17 | a)若为合法卡,系统命令栏杆抬起;汽车通过入口后,入口传感器通知系统发出命令,栏杆放下,系统遂将该卡卡号记录于当前场内卡号集合中。 18 | b)若为非法卡,则系统不发出栏杆抬起的命令,并发出告警信号。 19 | (5)当一辆出场汽车到达出口时,用读入器读出驾驶员的卡上信息,系统根据读出内容检查该卡是否已经被记录在当前场内卡号集合中。 20 | a)若已被记录,系统命令栏杆抬起;汽车通过出口后,出口传感器通知系统发出命令,栏杆放下,系统遂将该卡从当前场内卡号集合中删除。 21 | b)若未被记录,系统不发出栏杆抬起的命令而发出告警信号,交由出口值班人员处理(见限定条件8)。 22 | 23 | 2.假设与限定条件 24 | (1)该企业的员工总人数为E人,员工号为1~E。 25 | (2)该停车场可容纳2*N辆汽车;入口到出口的距离=N+2个车位的宽度。 26 | (3)汽车入场、出场时的读卡均需1秒钟,栏杆抬起、放下均需2秒钟,汽车的长度为2个车位宽度,汽车的行驶速度为每秒1个车位宽度。 27 | (4)入场的汽车尾端通过入口传感器后,该传感器通知系统放下入口栏杆。 28 | 出场的汽车尾端通过出口传感器后,该传感器通知系统放下出口栏杆。 29 | (5)汽车进入停车场后,总是选择离入口最近的一个空车位停车。 30 | (6)汽车入场到达停车位后,需再用2秒从行车道停到车位上。 31 | 汽车出场时先用2秒从车位到达行车道,然后向出口行进。 32 | (7)行车道上不允许汽车并行。 33 | a)若有进场车与出场车争道冲突,让出场车先行; 34 | b)若有出场车争道冲突,让离出口较远者先行;若与出口距离相同,随机决定让其中一辆车先行。 35 | (8)出口值班人员处理不允许出场的汽车时,令该车返回原车位。若原车位已被占用,返回离出口最近的一个空车位。(很难) 36 | (9)在整个仿真过程中不考虑驾驶员走入或走出停车场。 37 | 3.须仿真的活动 38 | (1)程序开始时,停车场车位全空。此后随机产生要进场的汽车,并按上述描述进行入场仿真。 39 | (2)汽车在停车场中的停留时间随机产生(为仿真的方便,可限定在5分钟之内,并在入场后立即设置)。到达停车时间后汽车即按上述描述进行出场仿真。 40 | (3)定时报告(为方便,每分钟报告一次),应至少包括:当前时刻(包括时、分、秒)、当前场内车数、到目前为止的本次仿真“累计入场车数”、本次仿真“累计出场车数”、“本次仿真汽车的平均停车时间”。 41 | (4)应将上条报告的每条信息均写入指定的运行记录文件。文件名格式为“仿真日期-仿真起始时间.TXT”。 其中<仿真日期>为yyyyMMdd格式,<仿真起始时间>为hhmmss格式。 42 | (5)先按E=2*N进行上述仿真。达到预期目标后,再分别按E < 2*N和E > 2*N进行仿真。因此,要求E和N从命令行、或配置文件、或从界面上读入,不能写死在程序中。 43 | (6)为检验系统的控制功能,应随机产生以下三类事件,并将这些事件的细节记录到上述的运行记录文件。 44 | a)前文的两类争道冲突; 45 | b)非本单位员工汽车要求入场的情况; 46 | c)需按限定条件(8)处理的情况。 47 | 48 | 4.开发结果的行为特征 49 | (1)仿真活动中,每隔1秒钟改变一次所有相关对象的状态。 50 | (2)有简单的界面,以体现: 51 | •当前的时间;从仿真开始到目前所经历的时长(以秒为单位); 52 | •当前空闲车位数(入口处的显示屏); 53 | •停车场内汽车停放的情况(简图即可,表示汽车时应同时显示对应员工的卡号,下同); 54 | •入场与出场汽车在场内的行进情况;(没实现) 55 | •入口与出口自动栏杆的抬起与放下; 56 | •拒绝入场和拒绝出场的情况; 57 | •显示定时报告的数据。 58 | 注意能说明问题即可,切忌把主要精力放在界面上而忽视了实质问题。 59 | 5.提示 60 | 若没有学习过多进程或多线程实现技术,可能面临以下问题:既要计时,又要改变相关对象的状态,还要显示出当前所有对象的相关状态。 61 | 建议采用动画片的制作原理进行启发,即将多个固定和静止的画面定时、按顺序地放映出来,就变成了活动的画面。所以,可以在程序中定义一个主循环,在该循环之前进行必要的初始化,每1秒执行一次循环体,以遍历方式一一激励当前已经产生的对象,由它们根据自己的当前状态和相关的状态变化规则,决定是否需要改变、改变成什么样的状态,以及按照上述行为特征的设计展示必要的对象状态。这样,就可以用串行方式模拟并发的活动。 62 | -------------------------------------------------------------------------------- /common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "cconfiglefile.h" 8 | 9 | #define ID_NUMBER_LENGTH 12 10 | #define CARD_USERNAME 24 11 | 12 | 13 | /*用户卡片信息*/ 14 | struct userCardInfo 15 | { 16 | char ID[ID_NUMBER_LENGTH]; 17 | char username[CARD_USERNAME]; 18 | userCardInfo(){ 19 | memset(ID,0,sizeof(ID)); 20 | memset(username,0,sizeof(username)); 21 | } 22 | }; 23 | 24 | /*停车位信息*/ 25 | struct parkspotInfo 26 | { 27 | unsigned char type;/*0为空 1为被占用*/ 28 | /*被占用时的ID*/ 29 | char ID[ID_NUMBER_LENGTH]; 30 | char username[CARD_USERNAME]; 31 | /*还有多久出停车位的时间*/ 32 | // unsigned int outtime; 33 | /*停车位的数字编号*/ 34 | unsigned int plotIDNumber; 35 | /*清空缓存*/ 36 | void releaseParkspotInfo() 37 | { 38 | type = 0; 39 | //outtime = 0; 40 | memset(ID,0,ID_NUMBER_LENGTH*sizeof(char)); 41 | memset(username,0,CARD_USERNAME*sizeof(char)); 42 | /*取MAX*/ 43 | plotIDNumber = -1; 44 | } 45 | parkspotInfo(){ 46 | type = 0; 47 | //outtime = 0; 48 | memset(ID,0,ID_NUMBER_LENGTH*sizeof(char)); 49 | memset(username,0,CARD_USERNAME*sizeof(char)); 50 | /*取MAX*/ 51 | plotIDNumber = -1; 52 | } 53 | }; 54 | typedef struct parkspotInfo myparkspotInfo; 55 | 56 | /*停车位共享内存结构体*/ 57 | struct myParkplotInfoMemory 58 | { 59 | myparkspotInfo* ParkSpotInfo; 60 | /*剩余的停车位数目*/ 61 | unsigned int unUsedNumber; 62 | 63 | myParkplotInfoMemory()= delete; 64 | explicit myParkplotInfoMemory(unsigned int num) 65 | { 66 | ParkSpotInfo = new myparkspotInfo[num]; 67 | memset(ParkSpotInfo,0,num*sizeof(myparkspotInfo)); 68 | unUsedNumber = num; 69 | } 70 | ~myParkplotInfoMemory() 71 | { 72 | delete[] ParkSpotInfo; 73 | ParkSpotInfo =nullptr; 74 | unUsedNumber=0; 75 | } 76 | }; 77 | 78 | struct queueInfo 79 | { 80 | struct userCardInfo usercardinfo; 81 | /*入库剩下的时间,触发出库操作时间*/ 82 | unsigned int lefttime; 83 | /*出库需要多久时间*/ 84 | unsigned int IoutPlottime; 85 | /*停车位编号*/ 86 | unsigned int plotIDNumber; 87 | /*使用状态*/ 88 | bool isUsed; 89 | /*触发出库操作标志 1 开始出库 3刷卡成功 4 刷卡失败*/ 90 | unsigned int isOuttingplot; 91 | queueInfo() 92 | { 93 | lefttime = 0; 94 | plotIDNumber = -1; 95 | IoutPlottime=0; 96 | isUsed=false; 97 | isOuttingplot=0; 98 | } 99 | }; 100 | 101 | #endif // COMMON_H 102 | -------------------------------------------------------------------------------- /cconfiglefile.cpp: -------------------------------------------------------------------------------- 1 | #include "cconfiglefile.h" 2 | 3 | static QDir getCurrentPath() 4 | { 5 | QDir dir = QDir::currentPath(); 6 | dir.cdUp(); 7 | dir.cdUp(); 8 | dir.cdUp(); 9 | dir.cdUp(); 10 | dir.cd("OOT"); 11 | return dir; 12 | } 13 | 14 | Cconfiglefile* Cconfiglefile::configinstance = new Cconfiglefile(); 15 | 16 | Cconfiglefile::Cconfiglefile() 17 | { 18 | 19 | } 20 | Cconfiglefile::~Cconfiglefile(){ 21 | if(configinstance !=nullptr) 22 | { 23 | delete configinstance; 24 | configinstance = nullptr; 25 | } 26 | } 27 | const Cconfiglefile* Cconfiglefile::getconfigfileInstance(){ 28 | return configinstance; 29 | } 30 | 31 | 32 | bool Cconfiglefile::check_cardInfo(const QString& cardId,const QString& username) const 33 | { 34 | QDir dir = getCurrentPath(); 35 | QString filename("employee_checkin.csv"); 36 | QFile file(dir.filePath(filename)); 37 | qDebug()<readAll().split("\r\n");//每行以\r\n区分 44 | /*处理csv中的数据*/ 45 | bool status = false; 46 | qDebug("count:%d ",tempOption.count()); 47 | for(int i = 1 ; i < tempOption.count(); i++) 48 | { 49 | if(tempOption.at(i).isEmpty()){continue;} 50 | QStringList tempbar = tempOption.at(i).split(",");//一行中的单元格以,区分 51 | if(tempbar.isEmpty()){continue;} 52 | qDebug()< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "logger.h" 9 | 10 | using namespace std; 11 | using namespace logger; 12 | 13 | ConsoleLogger logger::debug; 14 | FileLogger logger::record("Logger" __DATE__ "_" __TIME__ ".log"); 15 | 16 | #ifdef WIN32 17 | #define localtime_r(_Time, _Tm) localtime_s(_Tm, _Time) 18 | #endif 19 | 20 | static const map LevelStr = 21 | { 22 | { Level::Debug, "Debug" }, 23 | { Level::Info, "Info" }, 24 | { Level::Warning, "Warning" }, 25 | { Level::Error, "Error" }, 26 | { Level::Fatal, "Fatal" }, 27 | }; 28 | 29 | ostream& operator<< (ostream& stream, const tm* tm) 30 | { 31 | return stream << 1900 + tm->tm_year << '-' 32 | << setfill('0') << setw(2) << tm->tm_mon + 1 << '-' 33 | << setfill('0') << setw(2) << tm->tm_mday << ' ' 34 | << setfill('0') << setw(2) << tm->tm_hour << ':' 35 | << setfill('0') << setw(2) << tm->tm_min << ':' 36 | << setfill('0') << setw(2) << tm->tm_sec; 37 | } 38 | 39 | BaseLogger::LogStream BaseLogger::operator()(Level nLevel) 40 | { 41 | return LogStream(*this, nLevel); 42 | } 43 | 44 | const tm* BaseLogger::getLocalTime() 45 | { 46 | auto now = chrono::system_clock::now(); 47 | auto in_time_t = chrono::system_clock::to_time_t(now); 48 | localtime_r(&in_time_t, &_localTime); 49 | return &_localTime; 50 | } 51 | 52 | void BaseLogger::endline(Level nLevel, string&& oMessage) 53 | { 54 | _lock.lock(); 55 | output(getLocalTime(), LevelStr.find(nLevel)->second, oMessage.c_str()); 56 | _lock.unlock(); 57 | } 58 | 59 | void ConsoleLogger::output(const tm *p_tm, 60 | const char *str_level, 61 | const char *str_message) 62 | { 63 | cout << '[' << p_tm << ']' 64 | << '[' << str_level << "]" 65 | << "\t" << str_message << endl; 66 | cout.flush(); 67 | } 68 | 69 | FileLogger::FileLogger(string filename) noexcept 70 | : BaseLogger() 71 | { 72 | string valid_filename(filename.size(), '\0'); 73 | regex express("/|:| |>|<|\"|\\*|\\?|\\|"); 74 | regex_replace(valid_filename.begin(), 75 | filename.begin(), 76 | filename.end(), 77 | express, 78 | "_"); 79 | _file.open(valid_filename, 80 | fstream::out | fstream::app | fstream::ate); 81 | assert(!_file.fail()); 82 | } 83 | 84 | FileLogger::~FileLogger() 85 | { 86 | _file.flush(); 87 | _file.close(); 88 | } 89 | 90 | void FileLogger::output(const tm *p_tm, 91 | const char *str_level, 92 | const char *str_message) 93 | { 94 | _file << '[' << p_tm << ']' 95 | << '[' << str_level << "]" 96 | << "\t" << str_message << endl; 97 | _file.flush(); 98 | } 99 | -------------------------------------------------------------------------------- /parkplotinfo.cpp: -------------------------------------------------------------------------------- 1 | #include "parkplotinfo.h" 2 | 3 | parkplotInfo::parkplotInfo() 4 | { 5 | IparkplotNum = Cconfiglefile::getconfigfileInstance()->getSysconfig("SPARKPLOT","SPARKPLOT_MAX").toUInt(); 6 | myparkplotmemory = new myParkplotInfoMemory(IparkplotNum); 7 | lock = new QReadWriteLock[IparkplotNum]; 8 | } 9 | parkplotInfo::~parkplotInfo() 10 | { 11 | if(parkplotInstance!=nullptr) 12 | { 13 | delete parkplotInstance; 14 | parkplotInstance =nullptr; 15 | } 16 | if(nullptr!=myparkplotmemory) 17 | { 18 | delete myparkplotmemory; 19 | myparkplotmemory=nullptr; 20 | } 21 | 22 | if(nullptr!=lock) 23 | { 24 | delete lock; 25 | lock=nullptr; 26 | } 27 | } 28 | 29 | parkplotInfo* parkplotInfo::parkplotInstance = new parkplotInfo(); 30 | 31 | parkplotInfo* parkplotInfo::getparkplotInstance() 32 | { 33 | return parkplotInstance; 34 | } 35 | 36 | /*获取下一块没被占用的停车位信息*/ 37 | myparkspotInfo* parkplotInfo::getNextParkspotInfo() 38 | { 39 | unsigned int count = 2; 40 | /*循环找一次*/ 41 | while(count-- >0) 42 | { 43 | /*总是返回离入库口最近的车位*/ 44 | for(unsigned int i = 0; i< IparkplotNum; i++) 45 | { 46 | if(1 == myparkplotmemory->ParkSpotInfo[i].type) continue; 47 | /*获取这块内存的写权限*/ 48 | if(lock[i].tryLockForWrite()) 49 | { 50 | do{ 51 | myparkplotmemory->ParkSpotInfo[i].type = 1; 52 | myparkplotmemory->ParkSpotInfo[i].plotIDNumber = i; 53 | myparkplotmemory->unUsedNumber--; 54 | }while(0); 55 | lock[i].unlock(); 56 | return &myparkplotmemory->ParkSpotInfo[i]; 57 | } 58 | } 59 | QThread::msleep(50); 60 | } 61 | /*没有找到空余的停车位*/ 62 | return nullptr; 63 | } 64 | 65 | 66 | void parkplotInfo::releaseParkSpot(unsigned int IDNumber) 67 | { 68 | if(IDNumber < IparkplotNum) 69 | { 70 | while(true) 71 | { 72 | if(lock[IDNumber].tryLockForWrite(50)) 73 | { 74 | do{ 75 | myparkplotmemory->ParkSpotInfo[IparkplotNum].releaseParkspotInfo(); 76 | myparkplotmemory->unUsedNumber++; 77 | }while(0); 78 | lock[IDNumber].unlock(); 79 | break; 80 | } 81 | QThread::msleep(100); 82 | } 83 | } 84 | } 85 | 86 | 87 | 88 | 89 | /*获取所有停车位信息*/ 90 | const myParkplotInfoMemory* parkplotInfo::getAllParkplotMemory() 91 | { 92 | return myparkplotmemory; 93 | } 94 | 95 | /*获取停车位空闲数目*/ 96 | unsigned int parkplotInfo::getUnusedSplotNum() 97 | { 98 | return myparkplotmemory->unUsedNumber; 99 | } 100 | /*获取停车位占用数目*/ 101 | unsigned int parkplotInfo::getUsedSplotNum() 102 | { 103 | return IparkplotNum - myparkplotmemory->unUsedNumber; 104 | } 105 | /*获取停车位的总数*/ 106 | unsigned int parkplotInfo::getAllSplotNum() 107 | { 108 | return IparkplotNum; 109 | } 110 | -------------------------------------------------------------------------------- /parklot.cpp: -------------------------------------------------------------------------------- 1 | #include "parklot.h" 2 | #include "ui_parklot.h" 3 | #include "logger.h" 4 | 5 | parklot::parklot(QWidget *parent) : 6 | QMainWindow(parent), 7 | ui(new Ui::parklot), 8 | stoptimer(false) 9 | { 10 | ui->setupUi(this); 11 | startWorkThread(); 12 | tempComeInInfo.clear(); 13 | ui->startBtn->setDisabled(true); 14 | ui->safequit->setDisabled(true); 15 | } 16 | 17 | parklot::~parklot() 18 | { 19 | delete ui; 20 | if(myworkThread!=nullptr){ 21 | delete myworkThread; 22 | myworkThread =nullptr; 23 | } 24 | if(mycomInparkThread != nullptr) 25 | { 26 | delete mycomInparkThread; 27 | mycomInparkThread = nullptr; 28 | } 29 | 30 | if(displaysplotinfo != nullptr) 31 | { 32 | delete displaysplotinfo; 33 | displaysplotinfo = nullptr; 34 | } 35 | for(QList::iterator item = tempComeInInfo.begin(); item != tempComeInInfo.end() ; ++item) 36 | { 37 | queueInfo* temp = item.i->t(); 38 | if(temp == nullptr) continue; 39 | delete temp; 40 | } 41 | tempComeInInfo.clear(); 42 | } 43 | 44 | 45 | /*开始初始化线程*/ 46 | void parklot::startWorkThread() 47 | { 48 | logger::record(logger::Level::Info) << "startWorkThread, done."; 49 | /*处理入库队列成功到出库成功or失败的所有过程 加日志 */ 50 | if(nullptr==myworkThread) 51 | { 52 | // myworkThread = new workThread(this->ui->checkOutBox,runOuttingRelationFunc); 53 | myworkThread = new workThread(this->ui->checkOutBox,this->ui->textEdit1,this->ui->textEdit2); 54 | } 55 | 56 | 57 | if(nullptr==mycomInparkThread) 58 | { 59 | mycomInparkThread = new ComeInPlotThread(this->ui->checkInBox,this->ui->textEdit1,this->ui->textEdit2,this->ui->checkInListView); 60 | } 61 | 62 | if(nullptr==displaysplotinfo) 63 | { 64 | displaysplotinfo = new CDisplaySplotInfo(this->ui->parkInfoView); 65 | } 66 | 67 | } 68 | 69 | void ChangeOutBoxState() 70 | { 71 | 72 | } 73 | 74 | void parklot::on_safequit_clicked() 75 | { 76 | myworkThread->stopThread(); 77 | myworkThread->quit(); 78 | displaysplotinfo->stopThread(); 79 | mycomInparkThread->stopThread(); 80 | 81 | displaysplotinfo->quit(); 82 | displaysplotinfo->wait(); 83 | 84 | mycomInparkThread->quit(); 85 | mycomInparkThread->wait(); 86 | myworkThread->wait(); 87 | this->close(); 88 | } 89 | /*刷新控件上的值*/ 90 | //void parklot::runOuttingRelationFunc(QString ID, QString username,unsigned int IspotNum, unsigned int istatus) 91 | //{//istatus=0 出库成功,出库检测失败1 92 | // qDebug()<<" ID: " << ID << " username " << username; 93 | // if(istatus == 0) 94 | // { 95 | // if(IspotNum%2 == 0){ 96 | 97 | // }else{ 98 | 99 | // } 100 | // } 101 | //} 102 | static QDir getCurrentPath() 103 | { 104 | QDir dir = QDir::currentPath(); 105 | dir.cdUp(); 106 | dir.cdUp(); 107 | dir.cdUp(); 108 | dir.cdUp(); 109 | dir.cd("OOT"); 110 | return dir; 111 | } 112 | void parklot::on_pushButton_clicked() 113 | { 114 | QStringList fileNameList; 115 | QString fileName0; 116 | QFileDialog* fd = new QFileDialog(this);//创建对话框 117 | fd->resize(240,320); //设置显示的大小 118 | fd->setWindowTitle(tr("select file")); 119 | fd->setDirectory(getCurrentPath().path()); 120 | fd->setNameFilter(tr("csv(*.csv)")); //设置文件过滤器 121 | fd->setViewMode(QFileDialog::List); //设置浏览模式,有 列表(list) 模式和 详细信息(detail)两种方式 122 | if(fd->exec() == QDialog::Accepted ) //如果成功的执行 123 | { 124 | QStringList fileNameList = fd->selectedFiles(); //返回文件列表的名称 125 | 126 | QFile file(fileNameList[0]); 127 | qDebug()<<"filename :"<readAll().split("\r\n");//每行以\r\n区分 135 | /*处理csv中的数据*/ 136 | for(int i = 1 ; i < tempOption.count(); i++) 137 | { 138 | if(tempOption.at(i).isEmpty()){continue;} 139 | QStringList tempbar = tempOption.at(i).split(",");//一行中的单元格以,区分 140 | if(tempbar.isEmpty()){continue;} 141 | qDebug("size : %d",tempbar.size()); 142 | if(tempbar.size() != 5) 143 | { 144 | QMessageBox::about(this,tr("文件格式错误"),tr("导入文件错误,请重新导入")); 145 | return; 146 | } 147 | 148 | QString tempcardID = tempbar[1]; 149 | QString tempusername = tempbar[4]; 150 | 151 | queueInfo* myqueueInfo = new queueInfo(); 152 | 153 | strncpy(myqueueInfo->usercardinfo.ID,tempcardID.toStdString().c_str(),tempcardID.toStdString().size()); 154 | strncpy(myqueueInfo->usercardinfo.username,tempusername.toStdString().c_str(),tempusername.toStdString().size()); 155 | 156 | qDebug()<<"usernae ID "<comeInInfoList.push_back(myqueueInfo); 159 | } 160 | file.close();//操作完成后记得关闭文件 161 | ui->startBtn->setEnabled(true); 162 | ui->pushButton->setEnabled(false); 163 | } 164 | qDebug()<<" comin info size : "<< tempComeInInfo.size(); 165 | fd->close(); 166 | delete fd; 167 | } 168 | 169 | void parklot::on_startBtn_clicked() 170 | { 171 | /*启动线程*/ 172 | ui->startBtn->setDisabled(true); 173 | mycomInparkThread->setQueueInfo(&tempComeInInfo); 174 | 175 | if(!mycomInparkThread->isRunning()) 176 | { 177 | mycomInparkThread->start(); 178 | } 179 | 180 | if(!myworkThread->isRunning()) 181 | { 182 | myworkThread->start(); 183 | } 184 | if(!displaysplotinfo->isRunning()) 185 | { 186 | displaysplotinfo->start(); 187 | } 188 | 189 | ui->safequit->setEnabled(true); 190 | ui->pushButton->setEnabled(false); 191 | 192 | } 193 | -------------------------------------------------------------------------------- /comeinplotthread.cpp: -------------------------------------------------------------------------------- 1 | #include "comeinplotthread.h" 2 | #include "logger.h" 3 | 4 | unsigned int intervalTime = Cconfiglefile::getconfigfileInstance()->getSysconfig("REFREASHTIME","THREADINTERVIAL").toUInt(); 5 | //#入库,出库线程反复调用的时间间隔(秒) 6 | unsigned int IspotTimeInterval = Cconfiglefile::getconfigfileInstance()->getSysconfig("REFREASHTIME","THREADINTERVIAL").toUInt(); 7 | // #栏杆抬起,放下分别2s 8 | unsigned int Ioperatehandrail = Cconfiglefile::getconfigfileInstance()->getSysconfig("SPLOTTIME","OPERATEHANDRAIL").toUInt(); 9 | //#汽车行驶速度1s/1splot 10 | unsigned int Icardspeed = Cconfiglefile::getconfigfileInstance()->getSysconfig("SPLOTTIME","CARDSPEED").toUInt(); 11 | //#汽车出库,入库到行道上 12 | unsigned int Icardoperate = Cconfiglefile::getconfigfileInstance()->getSysconfig("SPLOTTIME","CARDOPERATE").toUInt(); 13 | 14 | 15 | ComeInPlotThread::ComeInPlotThread(QObject* parent,QObject* parent1,QObject* parent2,QObject* parent3) 16 | { 17 | sem = new QSemaphore(1); 18 | sem->release(); 19 | isStop = false; 20 | number=5; 21 | checkbox = (QCheckBox*)parent; 22 | TextEdit1 =(QTextEdit*)parent1; 23 | TextEdit2=(QTextEdit*)parent2; 24 | TextCheckView=(QTextEdit*)parent3; 25 | readyInUsers.clear(); 26 | } 27 | 28 | void ComeInPlotThread::setQueueInfo(QList* ptempqueueinfo) 29 | { 30 | tempqueueInfo = ptempqueueinfo; 31 | } 32 | 33 | ComeInPlotThread::~ComeInPlotThread() 34 | { 35 | if(sem!=nullptr) 36 | { 37 | delete sem; 38 | sem=nullptr; 39 | } 40 | readyInUsers.clear(); 41 | quit(); 42 | wait(); 43 | } 44 | void ComeInPlotThread::run() 45 | { 46 | connect(this,SIGNAL(comeinplottimeReady()),this,SLOT(comeinplotthreadProcess())); 47 | while(!isStop) 48 | { 49 | if(sem == nullptr) break; 50 | while(!sem->tryAcquire(1)) 51 | { 52 | QThread::msleep(500); 53 | } 54 | QThread::sleep(intervalTime); 55 | emit comeinplottimeReady(); 56 | } 57 | } 58 | 59 | void ComeInPlotThread::stopThread() 60 | { 61 | isStop = true; 62 | } 63 | 64 | void ComeInPlotThread::comeinplotthreadProcess() 65 | { 66 | if(number == 0) 67 | { 68 | QList::iterator item = tempqueueInfo->begin(); 69 | for(;item!= tempqueueInfo->end(); ++item) 70 | { 71 | queueInfo* myqueueInfo = item.i->t(); 72 | if(readyInUsers.toStdString().find(myqueueInfo->usercardinfo.username) == std::string::npos) 73 | { 74 | readyInUsers.append(myqueueInfo->usercardinfo.username); 75 | qDebug()<<"add data to queue: ID: "<< item.i->t()->usercardinfo.ID << " username: "<< item.i->t()->usercardinfo.username; 76 | 77 | /*验证合法性*/ 78 | if(!Cconfiglefile::getconfigfileInstance()->check_cardInfo(myqueueInfo->usercardinfo.ID,myqueueInfo->usercardinfo.username)) 79 | { 80 | //非法车辆 81 | QString tempdata; 82 | tempdata.append(tr("非法车辆 用户名: ")).append(myqueueInfo->usercardinfo.username).append(tr(" 车牌号: ")).append(myqueueInfo->usercardinfo.ID).append(tr("\r\n")); 83 | TextCheckView->setPlaceholderText(TextCheckView->placeholderText()+tempdata); 84 | TextCheckView->repaint(); 85 | TextCheckView->show(); 86 | QThread::msleep(10); 87 | logger::record(logger::Level::Error) << "非法车辆 用户名:" << myqueueInfo->usercardinfo.username<<"车牌号: "\ 88 | <usercardinfo.ID; 89 | tempqueueInfo->erase(item); 90 | sem->release(); 91 | return; 92 | } 93 | /*是否有多余的车位*/ 94 | myparkspotInfo* myparkinfo; 95 | while((myparkinfo = parkplotInfo::getparkplotInstance()->getNextParkspotInfo()) == nullptr) 96 | { 97 | QString tempdata; 98 | tempdata.append(tr("没有多余的车位请等待 用户名: ")).append(myqueueInfo->usercardinfo.username).append(tr(" 车牌号: ")).append(myqueueInfo->usercardinfo.ID).append(tr("\r\n")); 99 | QString checkString = TextCheckView->placeholderText(); 100 | if(checkString.toStdString().find(tempdata.toStdString()) == std::string::npos) 101 | { 102 | TextCheckView->setPlaceholderText(TextCheckView->placeholderText()+tempdata); 103 | TextCheckView->repaint(); 104 | TextCheckView->show(); 105 | QThread::msleep(10); 106 | } 107 | logger::record(logger::Level::Warning) << "没有多余的车位请等待 用户名:" << myqueueInfo->usercardinfo.username<<"车牌号: "\ 108 | <usercardinfo.ID; 109 | QThread::sleep(3*intervalTime); 110 | } 111 | myqueueInfo->isUsed=true; 112 | //停车场占用 113 | strcpy(myparkinfo->ID,myqueueInfo->usercardinfo.ID); 114 | strcpy(myparkinfo->username,myqueueInfo->usercardinfo.username); 115 | myparkinfo->type=1; 116 | myqueueInfo->lefttime = Icardspeed*(myparkinfo->plotIDNumber/2)+Ioperatehandrail+Icardoperate+IspotTimeInterval; 117 | myqueueInfo->plotIDNumber = myparkinfo->plotIDNumber; 118 | 119 | myQueueCacheInfo::getQueueCashInfoInstance()->getOutFreeQueueInfoList().push_back(myqueueInfo); 120 | myQueueCacheInfo::getQueueCashInfoInstance()->releaseLock_out(); 121 | 122 | QString tempdata; 123 | logger::record(logger::Level::Info) << "入库成功 用户名:" << myqueueInfo->usercardinfo.username<<"车牌号: "\ 124 | <usercardinfo.ID; 125 | tempdata.append(tr("入库成功 用户名: ")).append(myqueueInfo->usercardinfo.username).append(tr(" 车牌号: ")).append(myqueueInfo->usercardinfo.ID).append(tr("\r\n")); 126 | TextCheckView->clear(); 127 | TextCheckView->setPlaceholderText(tempdata); 128 | TextCheckView->repaint(); 129 | TextCheckView->show(); 130 | QThread::msleep(10); 131 | refreashTextEdit(myqueueInfo); 132 | if(checkbox->checkState() == Qt::Unchecked) 133 | { 134 | checkbox->setCheckState(Qt::Checked); 135 | checkbox->repaint(); 136 | QThread::msleep(10); 137 | number=5; 138 | } 139 | break; 140 | } 141 | } 142 | if(item == tempqueueInfo->end()) 143 | { 144 | TextCheckView->clear(); 145 | TextCheckView->repaint(); 146 | QThread::msleep(10); 147 | readyInUsers.clear(); 148 | isStop=true; 149 | } 150 | } 151 | else 152 | { 153 | if(number-- ==3) 154 | { 155 | if(checkbox->checkState() == Qt::Checked) 156 | { 157 | checkbox->setCheckState(Qt::Unchecked); 158 | checkbox->repaint(); 159 | 160 | TextCheckView->clear(); 161 | TextCheckView->repaint(); 162 | QThread::msleep(10); 163 | } 164 | } 165 | } 166 | sem->release(); 167 | qDebug()<< "结束入库的线程--------"; 168 | } 169 | 170 | 171 | void ComeInPlotThread::refreashTextEdit(queueInfo* tempoutqueueInfo) 172 | { 173 | 174 | QTextEdit *ptextEdit; 175 | if(tempoutqueueInfo->plotIDNumber%2 == 0) 176 | { 177 | ptextEdit = TextEdit1; 178 | }else{ 179 | ptextEdit = TextEdit2; 180 | } 181 | QString resultData; 182 | char Plot[6]; 183 | std::sprintf(Plot,"%d",10000+tempoutqueueInfo->plotIDNumber); 184 | resultData.append(tempoutqueueInfo->usercardinfo.ID).append(" | ").append(tempoutqueueInfo->usercardinfo.username)\ 185 | .append(tr(" | 车位号:")).append(Plot).append("\r\n"); 186 | ptextEdit->setPlaceholderText(ptextEdit->placeholderText()+resultData); 187 | ptextEdit->repaint(); 188 | ptextEdit->show(); 189 | 190 | } 191 | -------------------------------------------------------------------------------- /parklot.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | parklot 4 | 5 | 6 | 7 | 0 8 | 0 9 | 780 10 | 572 11 | 12 | 13 | 14 | parklot 15 | 16 | 17 | 18 | 19 | false 20 | 21 | 22 | 23 | 50 24 | 30 25 | 600 26 | 331 27 | 28 | 29 | 30 | 31 | 800 32 | 1200 33 | 34 | 35 | 36 | 停车场概况 37 | 38 | 39 | 40 | 41 | 170 42 | 20 43 | 431 44 | 301 45 | 46 | 47 | 48 | 49 | 0 50 | 51 | 52 | 53 | 54 | false 55 | 56 | 57 | 58 | 80 59 | 30 60 | 61 | 62 | 63 | 入口 64 | 65 | 66 | 67 | 68 | 69 | 70 | 0 71 | 72 | 73 | 74 | 75 | false 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 0 89 | 90 | 91 | 92 | 93 | false 94 | 95 | 96 | 97 | 50 98 | 30 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | false 107 | 108 | 109 | 110 | 16777215 111 | 30 112 | 113 | 114 | 115 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 116 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 117 | p, li { white-space: pre-wrap; } 118 | </style></head><body style=" font-family:'.SF NS Text'; font-size:13pt; font-weight:400; font-style:normal;"> 119 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600; font-style:italic;"> 过 道(上面是单号,下面是双号)</span></p></body></html> 120 | 121 | 122 | 123 | 124 | 125 | 126 | false 127 | 128 | 129 | 130 | 50 131 | 30 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | false 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | false 151 | 152 | 153 | 154 | 50 155 | 30 156 | 157 | 158 | 159 | 出口 160 | 161 | 162 | 298 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 10 172 | 20 173 | 161 174 | 301 175 | 176 | 177 | 178 | 179 | 0 180 | 181 | 182 | 183 | 184 | false 185 | 186 | 187 | 188 | 16777215 189 | 30 190 | 191 | 192 | 193 | 停车场显示信息: 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 16777215 205 | 80 206 | 207 | 208 | 209 | 入门校验情况: 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 240 223 | 430 224 | 114 225 | 32 226 | 227 | 228 | 229 | 开始运行 230 | 231 | 232 | 233 | 234 | 235 | 420 236 | 430 237 | 114 238 | 32 239 | 240 | 241 | 242 | 安全退出 243 | 244 | 245 | 246 | 247 | 248 | 60 249 | 430 250 | 114 251 | 32 252 | 253 | 254 | 255 | 导入入库资源 256 | 257 | 258 | 259 | 260 | 261 | 262 | 0 263 | 0 264 | 780 265 | 22 266 | 267 | 268 | 269 | 270 | 271 | TopToolBarArea 272 | 273 | 274 | false 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | -------------------------------------------------------------------------------- /workthread.cpp: -------------------------------------------------------------------------------- 1 | #include "workthread.h" 2 | #include 3 | #include "logger.h" 4 | 5 | const unsigned int IsplotMax = Cconfiglefile::getconfigfileInstance()->getSysconfig("SPARKPLOT","SPARKPLOT_MAX").toUInt(); 6 | //#入库,出库线程反复调用的时间间隔(秒) 7 | const unsigned int IspotTimeInterval = Cconfiglefile::getconfigfileInstance()->getSysconfig("REFREASHTIME","THREADINTERVIAL").toUInt(); 8 | //---------------------------------------------- 9 | //#车在库中停顿的时间(单位s) 10 | const unsigned int IspotStoptime = Cconfiglefile::getconfigfileInstance()->getSysconfig("SPLOTTIME","EACHSPLOTTIME").toUInt(); 11 | //#读卡时间1s 12 | const unsigned int IreadCardTime = Cconfiglefile::getconfigfileInstance()->getSysconfig("SPLOTTIME","READCARDTIME").toUInt(); 13 | // #栏杆抬起,放下分别2s 14 | const unsigned int Ioperatehandrail = Cconfiglefile::getconfigfileInstance()->getSysconfig("SPLOTTIME","OPERATEHANDRAIL").toUInt(); 15 | //#汽车行驶速度1s/1splot 16 | const unsigned int Icardspeed = Cconfiglefile::getconfigfileInstance()->getSysconfig("SPLOTTIME","CARDSPEED").toUInt(); 17 | //#汽车出库,入库到行道上 18 | const unsigned int Icardoperate = Cconfiglefile::getconfigfileInstance()->getSysconfig("SPLOTTIME","CARDOPERATE").toUInt(); 19 | 20 | 21 | //workThread::workThread(QObject* parent,void(*p)(QString ID,QString username,unsigned int IspotNum,unsigned int istatus) ):isStop(false) 22 | //{ 23 | // sem = new QSemaphore(1); 24 | // sem->release(); 25 | // checkbox = (QCheckBox*)parent; 26 | // callback = p; 27 | //} 28 | 29 | 30 | workThread::workThread(QObject* parent ,QObject* parent1,QObject* parent2):isStop(false) 31 | { 32 | sem = new QSemaphore(1); 33 | sem->release(); 34 | checkbox = (QCheckBox*)parent; 35 | TextEdit1 =(QTextEdit*)parent1; 36 | TextEdit2=(QTextEdit*)parent2; 37 | } 38 | 39 | void workThread::run() 40 | { 41 | unsigned int intervalTime = Cconfiglefile::getconfigfileInstance()->getSysconfig("REFREASHTIME","THREADINTERVIAL").toUInt(); 42 | connect(this,SIGNAL(timeReady()),this,SLOT(threadProcess())); 43 | QThread::sleep(5*intervalTime); 44 | while(!isStop) 45 | { 46 | if(sem == nullptr) break; 47 | while(!sem->tryAcquire(1)) 48 | { 49 | QThread::msleep(50); 50 | } 51 | emit timeReady(); 52 | QThread::sleep(intervalTime); 53 | } 54 | } 55 | workThread::~workThread() 56 | { 57 | if(sem!=nullptr) 58 | { 59 | delete sem; 60 | sem=nullptr; 61 | } 62 | checkbox=nullptr; 63 | quit(); 64 | wait(); 65 | } 66 | 67 | void workThread::stopThread() 68 | { 69 | isStop = true; 70 | } 71 | 72 | /////-----------------------------------------------需要优化------------------------- 73 | /// ---------------1.根据需求需要将出车位的车位让出来,让进来的车可以选此车位 74 | /// ---------------2.倘若出库失败,车库车后面有几量车跟随,这些车如何安排让道,如何控制进库车和这些车争道问题 75 | /// ---------------3.根据需求1,如果车位在车道及时让出来,进库车马上能识别有车位,进库车成功进来,出库车出去失败,出库车之前的车位被占用又没有空余的车位,导致出库车一直占道,如何处理??? 76 | /// 77 | /// --------------------------由于时间原因,我采用简化处理的: 78 | /// ----------------1》车只要进库就分配车位给他,直到成功出库才释放车位。 79 | /// ----------------2》出库车出库失败,他自己以及后面几量跟随的车都默认回到自己的车位,此时进车不与出车发生争道冲突。 80 | /// 81 | void workThread::threadProcess() 82 | { 83 | /*检查入库队列的时间,等于0,就将数据拷贝到出库队列*/ 84 | qDebug()<<"threadProcess"; 85 | QList & comeInfoList = myQueueCacheInfo::getQueueCashInfoInstance()->getOutFreeQueueInfoList(); 86 | if(comeInfoList.size() == 0){ 87 | qDebug()<<"threadProcess end ----"; sem->release(); 88 | myQueueCacheInfo::getQueueCashInfoInstance()->releaseLock_out(); 89 | return; 90 | } 91 | QList & outtingInfoList = myQueueCacheInfo::getQueueCashInfoInstance()->outtingInfoList; 92 | /*判断入库缓存,如果时间达到,复制到出库缓存,修改相关值*/ 93 | QList::iterator comeIniter = comeInfoList.begin(); 94 | /*这一秒变化过没有*/ 95 | bool bLabstatus = false; 96 | bool bcheckststus = (checkbox->checkState() == Qt::Checked); 97 | for( ;comeIniter != comeInfoList.end();) 98 | { 99 | if(comeIniter.i->t()== nullptr|| !comeIniter.i->v){ 100 | ++comeIniter;continue; 101 | } 102 | queueInfo* tempqueueInfo = comeIniter.i->t(); 103 | if(!tempqueueInfo->isUsed) { ++comeIniter;continue;} 104 | if(tempqueueInfo->lefttime <= IspotTimeInterval) 105 | { 106 | //车在车库中等待的时间 107 | comeIniter.i->t()->lefttime = IspotStoptime; 108 | /*多加了IspotTimeInterval 为了下面循环容易判断*/ 109 | comeIniter.i->t()->IoutPlottime = Icardoperate + Icardspeed * (IsplotMax-tempqueueInfo->plotIDNumber)/2 +\ 110 | IreadCardTime + Ioperatehandrail + Icardspeed+IspotTimeInterval; 111 | outtingInfoList.push_front(tempqueueInfo); 112 | /*因为删除会破坏迭代器*/ 113 | QList::iterator iter_e=comeIniter++; 114 | comeInfoList.erase(iter_e); 115 | continue; 116 | } 117 | /*每个时间减去IspotTimeInterval*/ 118 | tempqueueInfo->lefttime -= IspotTimeInterval; 119 | ++comeIniter; 120 | } 121 | 122 | /*判断出库缓存 相对于来说要难很多 */ 123 | 124 | /*首先判断是否有需要出库的,同时将时间都减小IspotTimeInterval*/ 125 | unsigned int IneedoutqueueNum = 0; 126 | QList::iterator tempoutIterator=outtingInfoList.begin(); 127 | for(; tempoutIterator != outtingInfoList.end();++tempoutIterator) 128 | { 129 | queueInfo* tempoutqueueInfo = tempoutIterator.i->t(); 130 | if(tempoutqueueInfo->isOuttingplot != 0){ 131 | continue; 132 | } 133 | if(tempoutqueueInfo->lefttime <= IspotTimeInterval) 134 | { 135 | tempoutqueueInfo->isOuttingplot = 1;/*开始出库*/ 136 | continue; 137 | } 138 | /*小心越界 加continue */ 139 | tempoutqueueInfo->lefttime -= IspotTimeInterval; 140 | } 141 | QList::iterator outtingInfoIterator = outtingInfoList.begin(); 142 | while(outtingInfoIterator != outtingInfoList.end()) 143 | { 144 | queueInfo* tempoutqueueInfo = outtingInfoIterator.i->t(); 145 | if(!tempoutqueueInfo || !tempoutqueueInfo->isUsed || tempoutqueueInfo->isOuttingplot == 0) { ++outtingInfoIterator; continue;} 146 | //如果剩余时间小于时间间隔 代表出库成功 147 | 148 | /*代表可以触发出库操作,但是不一定能出库成功*/ 149 | /*代表有2个同时触发出库,距离出口远的先出库,没有出库的剩余时间再加上 IspotTimeInterval 没有出库的需要设置 isOuttingplot */ 150 | if(IneedoutqueueNum >= 2) 151 | { 152 | /*距离出口远的先行 判断争道冲突的条件:IoutPlottime是否一样 */ 153 | for(QList::iterator item = outtingInfoList.begin();item!=outtingInfoList.end();++item) 154 | { 155 | queueInfo* tempIteminfo = item.i->t(); 156 | if(tempIteminfo->isOuttingplot != 1 || item != outtingInfoIterator) continue; 157 | /*争道冲突*/ 158 | if(tempIteminfo->IoutPlottime == tempoutqueueInfo->IoutPlottime) 159 | { 160 | if(tempIteminfo->IoutPlottime > tempoutqueueInfo->IoutPlottime) 161 | { 162 | tempoutqueueInfo->isOuttingplot = 0; 163 | tempoutqueueInfo->lefttime += IspotTimeInterval; 164 | } 165 | else{ 166 | /*包含 同道默认后面这个后出库*/ 167 | tempIteminfo->isOuttingplot = 0; 168 | tempIteminfo->lefttime += IspotTimeInterval; 169 | } 170 | } 171 | } 172 | } 173 | 174 | if(tempoutqueueInfo->isOuttingplot != 0)//包含 出库成功 或者 等待刷卡 175 | { 176 | /*出库失败退回到原来的车位,或者 返回离出口最近的一个空车位 */ 177 | //出库时间比他小的都没有问题,出库时间大的就有麻烦,默认都原路返回,然后 178 | if(tempoutqueueInfo->IoutPlottime <= IreadCardTime + Ioperatehandrail + Icardspeed + IspotTimeInterval) 179 | { 180 | //开始检测卡 181 | //查看前面是否有车正在出 182 | if((tempoutqueueInfo->isOuttingplot == 1) && tempoutqueueInfo->IoutPlottime == IreadCardTime + Ioperatehandrail + Icardspeed +IspotTimeInterval ) 183 | { 184 | qDebug("checkstatus : %d ",bcheckststus); 185 | if(bLabstatus || bcheckststus)// checkbox->checkState() 有延时 186 | { 187 | tempoutqueueInfo->IoutPlottime += (2*Ioperatehandrail); 188 | qDebug()<<"增加时间: " << " ID: " << tempoutqueueInfo->usercardinfo.ID << " IoutPlottime : "<IoutPlottime ; 189 | ++outtingInfoIterator; 190 | continue; 191 | } 192 | else 193 | { 194 | bLabstatus = true;/*下一秒,这秒只能一个识别卡*/ 195 | if(!Cconfiglefile::getconfigfileInstance()->check_cardInfo(tempoutqueueInfo->usercardinfo.ID,tempoutqueueInfo->usercardinfo.username)) 196 | { //出库卡检测失败 现在只有他一辆车在过道上 197 | //过道上有几辆车,后面的车全部退回之前的车库,全部重新开始出库---------有缺陷 198 | for(QList::iterator item = outtingInfoList.begin();item!=outtingInfoList.end();++item) 199 | { 200 | queueInfo* tempIteminfo = item.i->t(); 201 | if(tempIteminfo->isOuttingplot != 1 ) continue; 202 | if(tempIteminfo->IoutPlottime >= tempoutqueueInfo->IoutPlottime) 203 | { 204 | tempIteminfo->isOuttingplot = 0; 205 | tempIteminfo->lefttime = Icardspeed * (IsplotMax-tempIteminfo->plotIDNumber)/2+Icardoperate; 206 | tempIteminfo->IoutPlottime = Icardoperate + Icardspeed * (IsplotMax-tempIteminfo->plotIDNumber)/2 +\ 207 | IreadCardTime + Ioperatehandrail + Icardspeed+IspotTimeInterval; 208 | } 209 | } 210 | logger::record(logger::Level::Error) << "检测卡失败 用户名:" << tempoutqueueInfo->usercardinfo.username<<"车牌号: "\ 211 | <usercardinfo.ID; 212 | tempoutqueueInfo->isOuttingplot= 4;/*检测卡失败*/ 213 | // callback(tempoutqueueInfo->usercardinfo.ID,tempoutqueueInfo->usercardinfo.username,tempoutqueueInfo->plotIDNumber,1); 214 | ++outtingInfoIterator; 215 | refreashTextEdit(tempoutqueueInfo,1); 216 | continue;//出库失败,不往下执行 217 | } 218 | tempoutqueueInfo->isOuttingplot = 3;//检测卡成功 219 | } 220 | // qDebug()<<" ID: " << tempoutqueueInfo->usercardinfo.ID << " IoutPlottime : "<IoutPlottime; 221 | } 222 | else if(tempoutqueueInfo->isOuttingplot == 3 && tempoutqueueInfo->IoutPlottime == Ioperatehandrail + Icardspeed + IspotTimeInterval) 223 | { 224 | bLabstatus = true; 225 | // myQueueCacheInfo::getQueueCashInfoInstance()->outQueuePushBack(tempoutqueueInfo->IoutPlottime); 226 | qDebug()<<"检测卡成功" << " ID: " << tempoutqueueInfo->usercardinfo.ID << " IoutPlottime : "<IoutPlottime ; 227 | qDebug("检测卡成功 checkstatus : %d ",bcheckststus); 228 | if(!bcheckststus ) 229 | { 230 | checkbox->setCheckState(Qt::Checked); 231 | checkbox->repaint(); 232 | QThread::msleep(10); 233 | } 234 | qDebug("检测卡成功 checkstatus 2 : %d ",bcheckststus); 235 | } 236 | else if(tempoutqueueInfo->isOuttingplot == 3 && tempoutqueueInfo->IoutPlottime == IspotTimeInterval) 237 | { 238 | bLabstatus = true; 239 | /*释放车位资源*/ 240 | /*出库成功*/ 241 | qDebug()<<"出库成功"<< " ID: " << tempoutqueueInfo->usercardinfo.ID << " IoutPlottime : "<<\ 242 | tempoutqueueInfo->IoutPlottime << "plotIDNumber "<plotIDNumber; 243 | logger::record(logger::Level::Info) << "出库成功 用户名:" << tempoutqueueInfo->usercardinfo.username<<"车牌号: "\ 244 | <usercardinfo.ID; 245 | /*刷新控件*/ 246 | refreashTextEdit(tempoutqueueInfo); 247 | 248 | parkplotInfo::getparkplotInstance()->releaseParkSpot(tempoutqueueInfo->plotIDNumber); 249 | if(bcheckststus) 250 | { 251 | checkbox->setCheckState(Qt::Unchecked); 252 | checkbox->repaint(); 253 | QThread::msleep(10); 254 | } 255 | //回掉函数更新控件上的值 256 | // callback(tempoutqueueInfo->usercardinfo.ID,tempoutqueueInfo->usercardinfo.username,tempoutqueueInfo->plotIDNumber,0); 257 | outtingInfoIterator = outtingInfoList.erase(outtingInfoIterator); 258 | delete tempoutqueueInfo; 259 | tempoutqueueInfo = nullptr; 260 | continue; 261 | } 262 | } 263 | tempoutqueueInfo->IoutPlottime -= IspotTimeInterval; 264 | } 265 | ++outtingInfoIterator; 266 | } 267 | myQueueCacheInfo::getQueueCashInfoInstance()->releaseLock_out(); 268 | sem->release(); 269 | qDebug()<<"------- threadProcess end -----------"; 270 | } 271 | 272 | void workThread::refreashTextEdit(queueInfo* tempoutqueueInfo,int type) 273 | { 274 | QString data; 275 | QTextEdit *ptextEdit; 276 | if(tempoutqueueInfo->plotIDNumber%2 == 0) 277 | { 278 | data = TextEdit1->placeholderText(); 279 | ptextEdit = TextEdit1; 280 | }else{ 281 | data = TextEdit2->placeholderText(); 282 | ptextEdit = TextEdit2; 283 | } 284 | 285 | QString resultData; 286 | if(!data.isEmpty()) 287 | { 288 | QStringList templist = data.split("\r\n"); 289 | for(int i = 0; i< templist.size();++i) 290 | { 291 | if(templist[i].isEmpty()|| templist[i].isNull()) continue; 292 | if(templist[i].toStdString().find(("出库检测失败")) != std::string::npos){ 293 | resultData.append(templist[i]); 294 | continue; 295 | } 296 | if((templist[i].toStdString().find(tempoutqueueInfo->usercardinfo.ID) == std::string::npos \ 297 | || templist[0].toStdString().find(tempoutqueueInfo->usercardinfo.username) == std::string::npos)) 298 | { 299 | resultData.append(templist[i]); 300 | if(type==1) 301 | { 302 | resultData.append("(出库检测失败)"); 303 | } 304 | resultData.append(tr("\r\n")); 305 | qDebug()<<" resultdata: "<< resultData; 306 | } 307 | } 308 | ptextEdit->clear(); 309 | ptextEdit->setPlaceholderText(resultData); 310 | ptextEdit->repaint(); 311 | ptextEdit->show(); 312 | QThread::msleep(10); 313 | } 314 | } 315 | -------------------------------------------------------------------------------- /OOT.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {d8933a34-cfc1-4afc-bf96-1c1839f3fd26} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | true 60 | false 61 | 62 | 63 | 64 | true 65 | 66 | 67 | 68 | ProjectExplorer.Project.Target.0 69 | 70 | Desktop Qt 5.11.2 clang 64bit 71 | Desktop Qt 5.11.2 clang 64bit 72 | qt.qt5.5112.clang_64_kit 73 | 0 74 | 0 75 | 0 76 | 77 | /Users/stevezhou/xidian_code_homework/object_to_object/build-OOT-Desktop_Qt_5_11_2_clang_64bit-Debug 78 | 79 | 80 | true 81 | qmake 82 | 83 | QtProjectManager.QMakeBuildStep 84 | true 85 | 86 | false 87 | false 88 | false 89 | 90 | 91 | true 92 | Make 93 | 94 | Qt4ProjectManager.MakeStep 95 | 96 | -w 97 | -r 98 | 99 | false 100 | 101 | 102 | 103 | 2 104 | Build 105 | 106 | ProjectExplorer.BuildSteps.Build 107 | 108 | 109 | 110 | true 111 | Make 112 | 113 | Qt4ProjectManager.MakeStep 114 | 115 | -w 116 | -r 117 | 118 | true 119 | clean 120 | 121 | 122 | 1 123 | Clean 124 | 125 | ProjectExplorer.BuildSteps.Clean 126 | 127 | 2 128 | false 129 | 130 | Debug 131 | Debug 132 | Qt4ProjectManager.Qt4BuildConfiguration 133 | 2 134 | true 135 | 136 | 137 | /Users/stevezhou/xidian_zuoye/object_to_object/build-OOT-Desktop_Qt_5_11_2_clang_64bit-Release 138 | 139 | 140 | true 141 | qmake 142 | 143 | QtProjectManager.QMakeBuildStep 144 | false 145 | 146 | false 147 | false 148 | true 149 | 150 | 151 | true 152 | Make 153 | 154 | Qt4ProjectManager.MakeStep 155 | 156 | -w 157 | -r 158 | 159 | false 160 | 161 | 162 | 163 | 2 164 | Build 165 | 166 | ProjectExplorer.BuildSteps.Build 167 | 168 | 169 | 170 | true 171 | Make 172 | 173 | Qt4ProjectManager.MakeStep 174 | 175 | -w 176 | -r 177 | 178 | true 179 | clean 180 | 181 | 182 | 1 183 | Clean 184 | 185 | ProjectExplorer.BuildSteps.Clean 186 | 187 | 2 188 | false 189 | 190 | Release 191 | Release 192 | Qt4ProjectManager.Qt4BuildConfiguration 193 | 0 194 | true 195 | 196 | 197 | /Users/stevezhou/xidian_zuoye/object_to_object/build-OOT-Desktop_Qt_5_11_2_clang_64bit-Profile 198 | 199 | 200 | true 201 | qmake 202 | 203 | QtProjectManager.QMakeBuildStep 204 | true 205 | 206 | false 207 | true 208 | true 209 | 210 | 211 | true 212 | Make 213 | 214 | Qt4ProjectManager.MakeStep 215 | 216 | -w 217 | -r 218 | 219 | false 220 | 221 | 222 | 223 | 2 224 | Build 225 | 226 | ProjectExplorer.BuildSteps.Build 227 | 228 | 229 | 230 | true 231 | Make 232 | 233 | Qt4ProjectManager.MakeStep 234 | 235 | -w 236 | -r 237 | 238 | true 239 | clean 240 | 241 | 242 | 1 243 | Clean 244 | 245 | ProjectExplorer.BuildSteps.Clean 246 | 247 | 2 248 | false 249 | 250 | Profile 251 | Profile 252 | Qt4ProjectManager.Qt4BuildConfiguration 253 | 0 254 | true 255 | 256 | 3 257 | 258 | 259 | 0 260 | 部署 261 | 262 | ProjectExplorer.BuildSteps.Deploy 263 | 264 | 1 265 | Deploy Configuration 266 | 267 | ProjectExplorer.DefaultDeployConfiguration 268 | 269 | 1 270 | 271 | 272 | false 273 | false 274 | 1000 275 | 276 | true 277 | 278 | false 279 | false 280 | false 281 | false 282 | true 283 | 0.01 284 | 10 285 | true 286 | 1 287 | 25 288 | 289 | 1 290 | true 291 | false 292 | true 293 | valgrind 294 | 295 | 0 296 | 1 297 | 2 298 | 3 299 | 4 300 | 5 301 | 6 302 | 7 303 | 8 304 | 9 305 | 10 306 | 11 307 | 12 308 | 13 309 | 14 310 | 311 | 2 312 | 313 | OOT 314 | OOT2 315 | Qt4ProjectManager.Qt4RunConfiguration:/Users/stevezhou/xidian_code_homework/object_to_object/OOT/OOT.pro 316 | false 317 | true 318 | 319 | OOT.pro 320 | 321 | /Users/stevezhou/xidian_code_homework/object_to_object/build-OOT-Desktop_Qt_5_11_2_clang_64bit-Debug/OOT.app/Contents/MacOS 322 | 3768 323 | false 324 | true 325 | false 326 | false 327 | true 328 | 329 | 1 330 | 331 | 332 | 333 | ProjectExplorer.Project.TargetCount 334 | 1 335 | 336 | 337 | ProjectExplorer.Project.Updater.FileVersion 338 | 18 339 | 340 | 341 | Version 342 | 18 343 | 344 | 345 | --------------------------------------------------------------------------------