/**************************************************************************
* 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. 评论 ”[实例] 设计基于JQM的WebApp“

    点这里 DEMO 先上最近做的一个WebApp小应用,http://iwxy.me/m.html,大家可以先去玩玩儿,在移动终端访问查看最佳效果 实现的功能是微博上偶然看到的一个小测试,动物认识真实的 ...

  2. POJ 2105

    #include <iostream> #include <cmath> #include <string> using namespace std; int ma ...

  3. POJ 1468

    #include <iostream> #define MAXN 5005 using namespace std; struct node { int b_x; int b_y; int ...

  4. Java集合框架(一)

    Java中集合类的关系图:  Collection 先来集合中的最大接口——Collection 可以通过查看JDK帮助文档,了解Collection接口中的最共性的方法.通过以下代码示例演示这些方法 ...

  5. HTTP协议中TCP的三次握手,四次挥手总结

    建立TCP需要三次握手才能建立,而断开连接则需要四次挥手.整个过程如下图所示: 先来看看如何建立连接的. 首先Client端发送连接请求报文,Server段接受连接后回复ACK报文,并为这次连接分配资 ...

  6. Spring框架学习之第1节

    spring快速入门 ①   spring是什么? Struts是web框架(jsp/action/actionform) hibernate是orm框架(对象和关系映射框架),处于持久层 sprin ...

  7. iOS开发--开发者帐号

    iOS应用上线 http://www.jianshu.com/p/ffddc5e5f0b9 http://www.jianshu.com/p/986e02d38f1b 好不容易终于申请下来了ios 公 ...

  8. Java实现cache的基本机制

    我这里说的cache不是指CPU和RAM之间的缓存,而是Java应用中间常用的缓存.最常使用的场合就是访问数据库的时候为了提高效率而使用的 cache.一般的用法就是把数据从数据库读到内存,然后之后的 ...

  9. USACO Section 3.1: Agri-Net

    minimal spanning tree的经典题 /* ID: yingzho1 LANG: C++ TASK: agrinet */ #include <iostream> #incl ...

  10. Data Base Oracle下载及安装

    Oracle   下载及安装 一.官方下地址:   http://www.oracle.com/technetwork/database/enterprise-edition/downloads/in ...