基于Qt的车载GPS监控系统(4)系统状态

系统状态界面

头文件

#ifndef SHOW_H
#define SHOW_H
#include <QtGui>
#include"dht9000.h" //配置系统头文件

class ShowDialog : public QDialog
{
    Q_OBJECT
public:
    ShowDialog(QWidget *parent=0);
public slots:
    void showState();   //更新系统状态SLOTS
protected:
    struct st_sys_dev g_dev[1]; //配置文件结构体
private:
    QLabel *labelBg;    //设置窗口背景label
    QLabel *labelTime;  //时间
    QLabel *labelTemp;  //温度
    QLabel *labelTmTime;//保鲜时长
    QLabel *labelGps;   //GPS定位信息
    QLabel *labelTired; //驾驶时长
    QLabel *labelSpeed; //即时车速

    QLineEdit *lineTitle;
    QLineEdit *lineTime;
    QLineEdit *lineTemp;
    QLineEdit *lineTmTime;
    QLineEdit *lineGps;
    QLineEdit *lineTired;
    QLineEdit *lineSpeed;

    QToolButton *toolButton;//返回按键
};
#endif // SHOW_H

配置头文件

#ifndef GP9000_H
#define GP9000_H
#include<unistd.h>
#include<string.h>
#include<stdio.h>
#include<fcntl.h>      /*文件控制定义*/
#include<termios.h>    /*PPSIX终端控制定义*/

#define ON          1
#define OFF         0
#define CONFIG_FILE     "g9.cfg"
#define MAX_SYS_USER_NUM 3
#define MAX_RECORD  20      //温湿度最大的记录条数N  (N+1)
#define LOG_TIME    5       //日志记录间隔(分)
#define DEF_T_UPP   30      //默认温度上限(C)
#define DEF_T_LOW   5       //默认温度下限(C)
#define DEF_T_SET   5       //默认温度回差(C)
#define DEF_M_TIME  5       //默认检测间隔时间(s)

#define SYS_NAME    "GP9001"    //系统名称
#define SYS_ID      9001        //系统ID号
#define MENU_BUF_SIZE   64

int make_default_config(struct st_sys_dev * dev);
int save_dev(struct st_sys_dev * dev);
int load_dev(struct st_sys_dev * dev);
int init_com(int fd);

//时间
struct st_date_time{
    int year;
    int month;
    int day;
    int hour;
    int minute;
    int second;
};

//GPS信息
struct st_gps_info{
    double  latitude;                       //经度
    double  longitude;                      //纬度
    float   speed;                          //速度
    float   direction;                      //航向
    unsigned char NS;
    unsigned char EW;
};


//报警参数设置
struct st_alarm_set{
        char temp_upper;//温度上限
        char temp_lower;//温度下限
        char temp;
        char temp_change_set;//温度回差
        char monitor_time;//检测间隔时间
};

//用户帐号信息
struct st_user{
        char    name[8];            //帐号名
        char    passwd[8];          //密码
        int     purview;            //权限
        int     enable;             //启用标志
};


//记录内容:序号 日期 时间 温度 湿度: 2010/10/23 12:34 23 65
struct st_log_data{
        float log_temp;             //温度
        float log_humi;             //湿度
        char  state;                //记录报警状态
        char  date[10];
        char  time[8];
};

//系统设置
struct st_sys_info{
   char supplier[10];           //制造商编号
   char hd_ver[10];             //硬件版本号
   char sw_ver[10];             //软件版本号
   char serial[10];             //设备生产系列号
   char manu_data[10];      //Manufacture date
};


//系统总体数据结构
struct st_sys_dev{
    struct st_sys_info    sys_info; //系统基本信息
    struct st_alarm_set   alarm_set;//湿温度报警
    struct st_gprs        gprs_set; //gprs模块设置
    struct st_user        user[MAX_SYS_USER_NUM];//用户设置
    struct st_log_data    logd[MAX_RECORD];
    int                   log_time; //记录间隔时长
    int                   log_index;//记录下标
    int                   log_count;//有效记录总数
};


#endif // GP9000_H

系统状态实现程序

#include<QDebug>
#include"show.h"
#include"dht9000.h"

ShowDialog::ShowDialog( QWidget *parent)
    : QDialog( parent)
{
    load_dev(g_dev);

    //计时器对象,1秒钟发送一个timeout()信号,调用showState()函数
    QTimer *timer = new QTimer(this);
    timer->start(1000);
    connect(timer, SIGNAL(timeout()), this, SLOT(showState()));

    this->setMinimumSize(800,480);
    this->setMaximumSize(800,480);

    //窗口标题
    this->setWindowIcon(QPixmap( ":/images/1.png") );
    this->setWindowTitle(tr("GP9001车载GPS监控系统"));
    //窗口背景
    labelBg = new QLabel(this);
    labelBg->setGeometry(QRect(0, 0, 800, 480));
    labelBg->setPixmap(QPixmap(":/images/9001bg.jpg"));
    labelBg->setScaledContents(true);
    //窗口功能标题
    lineTitle = new QLineEdit(this);
    //设置显示数字字体大小
    QFont font = lineTitle->font();
    font.setPointSize(font.pointSize() + 5);
    lineTitle->setFont(font);
    lineTitle->setText(tr("系统状态"));
    lineTitle->setReadOnly(true);
    lineTitle->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
    lineTitle->setGeometry(QRect(300, 110, 200, 35));
    //获取系统时间
    QTime time = QTime::currentTime();
    QString textTime = time.toString("hh:mm:ss A");

    labelTime= new QLabel(this);
    labelTime->setText(tr("系统时间:"));
    labelTime->setGeometry(QRect(80, 200, 80, 25));

    lineTime = new QLineEdit(this);
    lineTime->setGeometry(QRect(180, 200, 180, 25));
    lineTime->setReadOnly(true);
    lineTime->setAlignment(Qt::AlignHCenter);
    lineTime->setText(textTime);

    labelTemp = new QLabel(this);
    labelTemp->setText(tr("车厢温度:"));
    labelTemp->setGeometry(QRect(80, 250, 80, 25));

    lineTemp = new QLineEdit(this);
    lineTemp->setGeometry(QRect(180, 250, 180, 25));
    lineTemp->setReadOnly(true);
    lineTemp->setAlignment(Qt::AlignHCenter);
    lineTemp->setText(QString::number(15.55,'f',2)+tr("℃"));

    labelTmTime = new QLabel(this);
    labelTmTime->setText(tr("保鲜时长:"));
    labelTmTime->setGeometry(QRect(80, 300, 80, 25));

    lineTmTime = new QLineEdit(this);
    lineTmTime->setGeometry(QRect(180, 300, 180, 25));
    lineTmTime->setReadOnly(true);
    lineTmTime->setAlignment(Qt::AlignHCenter);
    lineTmTime->setText(QString::number(3)+tr("小时")+QString::number(22)+tr("分"));

    labelGps= new QLabel(this);
    labelGps->setText(tr("卫星定位:"));
    labelGps->setGeometry(QRect(420, 200, 80, 25));

    lineGps = new QLineEdit(this);
    lineGps->setGeometry(QRect(520, 200, 180, 25));
    lineGps->setReadOnly(true);
    lineGps->setAlignment(Qt::AlignHCenter);
    lineGps->setText(tr("经度:123.44 纬度:34.54"));

    labelTired = new QLabel(this);
    labelTired->setText(tr("行驶时长:"));
    labelTired->setGeometry(QRect(420, 250, 80, 25));

    lineTired = new QLineEdit(this);
    lineTired->setGeometry(QRect(520, 250, 180, 25));
    lineTired->setReadOnly(true);
    lineTired->setAlignment(Qt::AlignHCenter);
    lineTired->setText(QString::number(3)+tr("小时")+QString::number(22)+tr("分"));


    labelSpeed = new QLabel(this);
    labelSpeed->setText(tr("即时速度:"));
    labelSpeed->setGeometry(QRect(420, 300, 80, 25));

    lineSpeed = new QLineEdit(this);
    lineSpeed->setGeometry(QRect(520, 300, 180, 25));
    lineSpeed->setReadOnly(true);
    lineSpeed->setAlignment(Qt::AlignHCenter);
    lineSpeed->setText(QString::number(12.55,'f',2)+tr("公里/小时"));


    toolButton = new QToolButton(this);
    toolButton->setGeometry(QRect(350, 360, 100, 100));
    toolButton->setText( tr( "返  回" ) );
    toolButton->setIcon( QPixmap( ":/images/6.png") );
    toolButton->setIconSize( QPixmap( ":/images/6.png").size() );
    toolButton->setAutoRaise( TRUE );
    toolButton->setToolButtonStyle( Qt::ToolButtonTextUnderIcon);
    connect(toolButton,SIGNAL(clicked()),this,SLOT(accept()));
}

void ShowDialog::showState()
{
    QTime time = QTime::currentTime();
    QString textTime = time.toString("hh:mm:ss A");
    lineTime->setText(textTime);

    float temp;
    temp = rand()%100;
    lineTemp->setText(QString::number(temp,'f',2));

    int tem_max,tem_min;
    tem_max = g_dev->alarm_set.temp_upper;
    tem_min = g_dev->alarm_set.temp_lower;

    //判断一下极限值是否报警
    QPalette pal = lineTemp->palette();//调色板对象
    QColor color;
    if(temp>tem_max || temp<tem_min){
        color = QColor(Qt::red);
    }else{
        color = QColor(Qt::green);
    }
    pal.setColor(QPalette::Base, color);//设置控件背景色
    lineTemp->setPalette(pal);//设置对象调色板
    lineTemp->update();//更新对象

}

Copyright © 2016 www.91arm.com 【91创客学堂】