laitimes

DVR control platform for vehicle terminals designed based on HiSilicon H3520DV400 and QT5.9

author:liwen01001

liwen01_2019.06.05

Preface:

With the development of 4G/5G, wireless bandwidth continues to expand, and data traffic costs continue to decrease, making real-time network video and video surveillance gradually popular.

Traditional security projects and vehicle monitoring systems are inseparable from audio and video recording, saving, playback, coupled with the current remote real-time video and remote video file retrieval and download, so that vehicle terminals and DVR equipment can continue to develop.

Here we introduce a control interface designed using QT and suitable for embedded terminals such as security or DVR.

Illustrate:

  • QT version: qt-everywhere-opensource-src-5.9.0
  • qt-creator version: qt-creator-opensource-linux-x86_64-4.7.0.run
  • Operating equipment: HI3520DV300, ARM Cortex A7 @Max. 800MHz, nand flash 128M
  • Compilation environment: Ubuntu 16.04
  • Cross-compilation tool: arm-hisiv300-linux-
  • Test platforms: HiSilicon HI3520DV300, Ubuntu 16.04

Function introduction:

Mainly related to audio and video applications: real-time video preview; recording settings; Video enquiry; Device status inquiry; trigger settings; System settings six functional modules.

Design Ideas:

  1. Due to the limited system resources, and in order to make the software more stable and reliable, the QT interface program and the module of the actual operation of HiSilicon audio and video data are separated into two independent processes to implement, HiSilicon program mainly handles hardware and HiSilicon platform related content, QT program mainly handles interface display and parameter query settings. They can exchange information with each other through interprocess communication (IPC).
  2. Video preview and video playback functions: Due to the limited system resources and limited running capabilities of embedded devices, the video display class is put into the embedded device to implement. The HiSilicon platform allows you to directly use HiSilicon's hardware codecs to process the display of video images.
  3. Parameter setting and saving: These parameters such as video encoding and video preview storage are saved in the HiSilicon program, and the QT interface needs to be displayed before going to the HiSilicon program to query the values of these parameters, so as to ensure that the parameters queried are the same as the actual parameters used, if you want to modify some parameters, they are also set through the QT interface, and then the parameters are transferred back to the HiSilicon program for saving.

Detailed design:

  1. HiSilicon automatically starts to detect the status of the device according to various parameters after the device is powered on, automatically starts video recording after the status is normal, and automatically overwrites the device according to the set conditions after the storage device is full.
  2. QT program, the main interface is divided into real-time video preview, video setting, video query, device status, trigger setting, system setting these 6 modules according to the function module, which is actually 6 buttons, and the user selects the operation through the mouse or touch screen.
  3. After the main interface of the QT program is started, a thread is established in the background to listen to and receive the data and commands sent by the HiSilicon module (the project uses IPCP message queue that encapsulates a layer of protocol on the basis of IPC queue).
  4. In the QT program, each Qt function module is an independent thread, that is, a submenu is a thread, which runs only when selected, and the submenu closes the thread to exit.
  5. In a QT program, the communication between each thread and object is implemented using QT's signal and slot functions.

QT interface design:

The main interface menu refers to Liu Dianwu's interface design, and the interface of the sub-menu is all made by itself, without art, it can only be said that these functions are implemented improvously.

DVR control platform for vehicle terminals designed based on HiSilicon H3520DV400 and QT5.9
DVR control platform for vehicle terminals designed based on HiSilicon H3520DV400 and QT5.9
DVR control platform for vehicle terminals designed based on HiSilicon H3520DV400 and QT5.9
DVR control platform for vehicle terminals designed based on HiSilicon H3520DV400 and QT5.9
DVR control platform for vehicle terminals designed based on HiSilicon H3520DV400 and QT5.9
DVR control platform for vehicle terminals designed based on HiSilicon H3520DV400 and QT5.9
DVR control platform for vehicle terminals designed based on HiSilicon H3520DV400 and QT5.9

Code implementation:

Full project code directory

biao@ubuntu:~/QT/qt_pro/HST_DVR_GUI$ 
biao@ubuntu:~/QT/qt_pro/HST_DVR_GUI$ tree
.
├── dvrGUI.pro
├── dvrGUI.pro.user
├── GUI_IPCPManager
│   ├── guiIPCManager.cpp
│   └── guiIPCManager.h
├── GUI_UI
│   ├── appinit.cpp
│   ├── appinit.h
│   ├── camaraview.cpp
│   ├── camaraview.h
│   ├── camaraview.ui
│   ├── dvrgui.cpp
│   ├── dvrgui.h
│   ├── dvrgui.ui
│   ├── head.h
│   ├── iconhelper.cpp
│   ├── iconhelper.h
│   ├── keyBoard.cpp
│   ├── keyBoard.h
│   ├── main.cpp
│   ├── main.qrc
│   ├── search.cpp
│   ├── search.h
│   ├── search.ui
│   ├── storage.cpp
│   ├── storage.h
│   ├── storage.ui
│   ├── SysInclude.h
│   ├── system.cpp
│   ├── system.h
│   ├── system.ui
│   ├── trigger.cpp
│   ├── trigger.h
│   ├── trigger.ui
│   ├── users.cpp
│   ├── users.h
│   ├── users.ui
│   ├── video.cpp
│   ├── video.h
│   └── video.ui
├── image
│   ├── DroidSansFallback.ttf
│   ├── fontawesome-webfont.ttf
│   └── main.bmp
├── IPCP_LIB
│   ├── AppDefine.h
│   ├── AppInclude.h
│   ├── HstlibIpcpCommon.h
│   ├── HstlibIpcpInterface.cpp
│   ├── HstlibIpcpInterface.h
│   ├── HstlibIPCPMsgStuct.h
│   ├── SysDebug.h
│   ├── SysDefine.h
│   └── SysInclude.h
└── main.qrc

4 directories, 51 files
biao@ubuntu:~/QT/qt_pro/HST_DVR_GUI$
           

Notes:

(1) QT runs slowly

I am running on HiSilicon HI3520DV300 device, when dragging the QT interface, the CPU usage will be very high, but it basically does not occupy the CPU when it is running normally, and the preliminary positioning is that the interface is refreshed and occupies a high CPU, not sure whether the processing power of the HI3520DV300 is not good or the migrated QT is not set correctly.

(2) QT layer hiding problem

There are many ways in Ubuntu that we want to hide the QT interface, but some do not work in HiSilicon HI3520. In HiSilicon, it comes out by layer, you need to hide the QT layer, in fact, you do not need to set the fb parameters of HiSilicon, but directly use the following method three in the QT program to achieve:

/************************************************* 
Function:	 on_btnMsg_pressed  
Description: 右上导航按键
Return: 
Others: 点击关闭不是实际关闭,而是隐藏
	1.注意鼠标的隐藏
	2.鼠标离开了菜单之后失效
	3.setVisible 在海思开发板上不生效
Author: Caibiao Lee
Date:	2019-06-05
*************************************************/
void DVRgui::on_btnMsg_pressed()
{
	  /**方法1**/
//    this->setWindowOpacity(0);
//    this->setAttribute( Qt::WA_TranslucentBackground,true );
//    this->setWindowFlags( Qt::WindowMinimizeButtonHint );
//    exit(0);GuiIPCPSendHeartBeat

	  /**方法2**/
//    this->setVisible(true);
//    this->setHidden(true);

     /**方法3**/
	this->setHidden(true);
	this->setCursor(Qt::BlankCursor);	//隐藏鼠标
}
           

(3) Mouse problems

To run QT on the HiSilicon platform and support the mouse control interface, you need to configure the kernel so that the kernel supports the type of mouse you are using. In the HI3520SDK I use, the kernel does not configure the project used by the mouse by default. QT mouse does not support hot swapping, so you need to plug in the mouse before the device starts When the mouse is configured normally and is running normally, you can see the following devices under /dev/input:

/dev # cd input/
/dev/input # ls
event0  mice    mouse0
/dev/input #
           

event0 mice mouse0 Of the three devices, one less will have an exception.

(4) Font problems

In QT5, we don't need to copy QT's font library files to ARM devices separately, nor do we need separate setting environment variables. Add the font library as a QT resource file to the QT project, load the library file in the program, so that QTcreater will package the QT character library file into the execution file when compiling the program

。 The font library I use here is the DroidSansFallback .ttf, which supports English, Chinese, and some special patterns and symbols for display.

/************************************************************
*Copyright (C), 2017-2027,lcb0281at163.com lcb0281atgmail.com
*FileName: main.cpp
*Date:     2019-06-05
*Author:   Caibiao Lee
*Version:  V1.0
*Description:
*Others:
*History:
***********************************************************/
#include "qapplication.h"
#include "appinit.h"
#include "dvrgui.h"
#include "video.h"
#include "search.h"
#include "storage.h"
#include "users.h"
#include "system.h"
#include "trigger.h"
#include "keyBoard.h"

#include <QFontDatabase>
#include <QDebug>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QFont iconFont;
    int fontId = QFontDatabase::addApplicationFont(":/image/DroidSansFallback.ttf");
    QStringList fontName = QFontDatabase::applicationFontFamilies(fontId);

    if (fontName.count() > 0) {
        iconFont = QFont(fontName.at(0));
    } else {
       qDebug() << "load DroidSansFallback.ttf error";
    }

    a.setFont(iconFont);

	/**添加虚拟键盘**/
    keyBoard keyBoard;
    keyBoard.hide();


    /**move the windows**/
    AppInit::Instance()->start();

    /**the main UI**/
    DVRgui w;
    w.show();

    return a.exec();
}
           

(5) Main interface pattern

The six patterns on the main interface are not hand animation, in fact, it is also a symbol in the font library, which has been implemented in the DroidSansFallback .ttf library, which finds specific patterns through digital codes, and digital codes can be queried in the following two networks:

http://fontawesome.dashgame.com https://fontawesome.com/cheatsheet?from=io

The setting code of the main interface box is as follows:

/************************************************* 
Function:	 initNav  
Description: 初始化选择菜单
Return: none
Others: none
Author: Caibiao Lee
Date:	2019-06-05
*************************************************/
void DVRgui::initNav()
{
    QList<QString> listColorBg;
    listColorBg << "#1570A5" << "#16A085" << "#C0392B" << "#047058" << "#9B59BB" << "#34495E";
    QList<QString> listColorText;
    listColorText << "#FEFEFE" << "#FEFEFE" << "#FEFEFE" << "#FEFEFE" << "#FEFEFE" << "#FEFEFE";

    /**Define QChar Variable**/
    QList<QChar> listChar;
    listChar << 0xf03d << 0xf1c8 << 0xf002 << 0xf030 << 0xf083 << 0xf085;
    QList<QString> listText;
    listText << "视频预览" << "录像设置" << "录像查询" << "设备状态"  << "触发设置" << "系统设置";

    /**Add QToolButton To QList**/
    btns << ui->btnViewMap << ui->btnViewPanel << ui->btnData << ui->btnMap << ui->btnDevice << ui->btnConfig;

    /**set Style Sheet of the QToolButton**/
    for (int i = 0; i < btns.count(); i++) {

        /**Returns the item at index position i in the list.**/
        QToolButton *btn = btns.at(i);
        btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
        btn->setIconSize(QSize(iconWidth, iconHeight));

        QPixmap pix = IconHelper::Instance()->getPixmap(listColorText.at(i), listChar.at(i), iconSize, iconWidth, iconHeight);
        btn->setIcon(QIcon(pix));
        btn->setText(listText.at(i));

        QStringList list;
        list.append(QString("QToolButton{font:%1px;background:%2;}").arg(iconSize / 2.5).arg(listColorBg.at(i)));
        list.append(QString("QToolButton{border:none;border-radius:8px;padding:30px;}"));
        list.append(QString("QToolButton:pressed{background:%1;}").arg("#737A97"));
        btn->setStyleSheet(list.join(""));

        connect(btn, SIGNAL(clicked(bool)), this, SLOT(buttonClicked()));
    }
}
           

(6) Mouse scope issues:

Running QT programs on the HiSilicon platform is still different from running on the PC and on, in the HiSilicon platform, QT mouse can only be effective within the QT window, if the window is dragged, or artificially moved the window position, but the position of the mouse does not make the corresponding movement, when the mouse is outside the QT window, any operation of the mouse QT program will not be detected.

Similarly, the mouse cannot be moved. After hiding the main interface, the QT program cannot wake up the QT program through the mouse, and then it can only send a signal externally, such as the button signal on the HiSilicon device, the signal of the touch screen, and when the QT receives the signal, the main interface is pulled back to the screen in its bound slot function.

Project acquisition

Reply to QT in the liwen01 public account to obtain the project code, the code project name of this chapter is: hisi_dvr_gui.rar

--------------End--------------

For more information

Please pay attention to the public number liwen01

Read on