/**************************************************************************
* Qt 控制watchdog app hacking
* 声明:
* 本文主要是为了查看之前朋友留下的Qt控制watchdog软件运作机制。
*
* 2015-12-31 深圳 南山平山村 曾剑锋
*************************************************************************/ 一、参考文档:
. Qt Documentation:
http://doc.qt.io/qt-4.8/qbasictimer.html
. QTimer和QBasicTimer使用:
http://blog.csdn.net/thinkme2010/article/details/9112785
. stm32独立看门狗和窗口看门狗的区别是什么?
http://www.zhixinrui.com/thread-1192-1-1.html
. Linux下Watchdog
http://blog.csdn.net/hshl1214/article/details/6248942 二、QBasicTimer Class:
This is a fast, lightweight, and low-level class used by Qt internally. We recommend using the higher-level QTimer class rather than this class if you want to use timers in your applications. Note that this timer is a repeating timer that will send subsequent timer events unless the stop() function is called. 三、Linux下watchdog的工作原理
Watchdog在实现上可以是硬件电路也可以是软件定时器,能够在系统出现故障时自动重新启动系统。在Linux 内核下, watchdog的基本工作原理是:当watchdog启动后(即/dev/watchdog 设备被打开后),如果在某一设定的时间间隔内/dev/watchdog没有被执行写操作, 硬件watchdog电路或软件定时器就会重新启动系统。 四、cat mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/watchdog.h>
#include <QMessageBox> MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this); fd = ;
times = ;
} MainWindow::~MainWindow()
{
delete ui;
::close(fd);
} void MainWindow::timerEvent(QTimerEvent *)
{
int dummy;
QString str; times++; /**
* timer每次都会执行,有点不合理
*/
if(ui->checkBox->isChecked())
::ioctl(fd,WDIOC_KEEPALIVE,&dummy); ui->times->setText(str.sprintf("%d",times));
} void MainWindow::on_pushButton_clicked()
{
// 打开watchdog设备文件,就相当于开机了watchdog,并设置了一个默认值
// 这个默认值是多少,目前不知道,去跟一下驱动,应该是可以获知的。
if(ui->pushButton->text() == QString("open watchdog"))
{
ui->pushButton->setText("close watchdog");
ui->checkBox->setDisabled(true); fd = ::open("/dev/watchdog",O_WRONLY);
if(fd < )
{
QMessageBox::about(this,"error","open watchdog failure");
exit(-);
} times = ;
ui->times->setText("");
timer.start(,this);
}
else // 关闭fd,就相当于关闭了watchdog
{
ui->pushButton->setText("open watchdog");
ui->checkBox->setEnabled(true);
timer.stop();
::close(fd);
}
} void MainWindow::moveEvent(QMoveEvent *)
{
this->move(QPoint(,));
} void MainWindow::resizeEvent(QResizeEvent *)
{
this->showMaximized();
} void MainWindow::closeEvent(QCloseEvent *)
{
exit();
}

Qt 控制watchdog app hacking的更多相关文章

  1. Qt Quick Hello World hacking

    /********************************************************************************************* * Qt ...

  2. linux watchdog demo hacking

    /********************************************************************** * linux watchdog demo hackin ...

  3. 利用Qt开发跨平台APP

    本文将手把手教你如何在Windows环境下,使用Qt编译出安卓应用程序. Qt是一个优秀的跨平台开发工具.我们利用Qt可以很方便地将一次编写的应用,多次编译到不同平台上,如Windows.Linux. ...

  4. 利用Qt开发跨平台APP(二)(iOS,使用Qt5.9,很详细,有截图)

    本文将手把手教你如何使用Qt编译出iOS应用程序. Qt是一个优秀的跨平台开发工具.我们利用Qt可以很方便地将一次编写的应用,多次编译到不同平台上,如Windows.Linux.MAC.Android ...

  5. 支持Tasker控制的app合集

    跟各种Tasker插件打交道,原因有两点: 1.站在开发者的角度:Tasker虽为神器,也不能面面俱到,一个原因就是Android自身过于分裂化造成的,不可能兼顾全平台和机型:个人开发者精力有限,也满 ...

  6. 用 Qt 控制 Nikon 显微镜的电动物镜转盘

    用 Qt 控制 Nikon 显微镜的电动物镜转盘 最近的一个项目,用到了一台 Nikon 的金相显微镜,并且配了个电动的物镜转盘.为了控制这个电动物镜转盘,我折腾了差不多有4-5天.中间遇到了各种问题 ...

  7. 控制游戏/app使用期限/过期,证书有效期,弹出公告支持离线使用/后端控制,支持Swift、Objective-C集成非常简单,永久免费框架

    CertCheck.framework (for iOS) 只能运行于真机上,切勿在模拟器上使用 这是一个控制游戏/app使用期限(到设定的时间无法打开app),或发布弹出公告永久免费的框架,可以全版 ...

  8. QT 控制LED实验

    1.实验准备 在PC 机D:盘下创建文件夹qt-led,将光盘qt_led_exp 文件夹下的images 文件夹拷贝到E:盘下qt-led 文件夹qt-led 内 2.新建工程 新建一个Empty ...

  9. QT开发安卓APP的中文字体问题

    1.安卓默认的字体为DroidSansFallback:谷歌中文字体 由于手机和PC字体的不一致,导致PC上开发的APP到目的安卓设备中文显示为小方框. 故需要要在qt的main函数中设置系统字体: ...

随机推荐

  1. HDU 4496 D-City(并查集,逆思维)

    题目 熟能生巧...常做这类题,就不会忘记他的思路了... //可以反过来用并查集,还是逐个加边,但是反过来输出...我是白痴.....又没想到 //G++能过,C++却wa,这个也好奇怪呀... # ...

  2. POJ 2227 The Wedding Juicer (优先级队列+bfs+dfs)

    思路描述来自:http://hi.baidu.com/perfectcai_/item/701f2efa460cedcb0dd1c820也可以参考黑书P89的积水. 题意:Farmer John有一个 ...

  3. POJ 2181

    #include <iostream> #include <cstdio> #include <cmath> #define MAXN 150005 #includ ...

  4. Eclipse里面开发ExtJS程序

    首先在http://extjs.org.cn/download下载ext ,我下载的版本是ext-3.4.1.1-gpl,下载好以后解压. 然后在eclipse里面先建立一个web项目,建立好后再we ...

  5. 安装wps for linux无法启动

    我下载的是deb包,双击安装完之后,打开wps没有反应,重启了一下 计算机也不行. 改从命令行出现如下信息: /opt/kingsoft/wps-office/office6/wps: error w ...

  6. ExtJs之Ext.util.CSS

    <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...

  7. 标准管道(popen)

    NAME popen, pclose - pipe stream to or from a process SYNOPSIS #include <stdio.h> FILE *popen( ...

  8. Struts2 Convention插件的使用(1)

    刚刚查阅官方文档(convention-plugin.html)并学习了Struts2的Convention插件,文章这里只作为一个笔记,建议大家去看官方文档比较清晰和全面. 需要在项目添加这些包 c ...

  9. 安装 M2eclipse 插件

    安装 M2eclipse 插件 在 Eclipse 中集成 Maven 插件能极大的方便创建 Maven project 并对其进行操作.使用以下的步骤来完成 M2eclipse 插件的安装: 在 E ...

  10. Spark基础与Java Api介绍

    原创文章,转载请注明: 转载自http://www.cnblogs.com/tovin/p/3832405.html  一.Spark简介 1.什么是Spark 发源于AMPLab实验室的分布式内存计 ...