/**************************************************************************
* 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 2048 神、上帝以及老天爷(递归,错排,dp,概率)

    中文题,错排,求概率,不解释,核心思路同 HDU 1465 错排简单思路可看:http://www.cnblogs.com/laiba2004/p/3235934.html //错排,但是我之前叫了几 ...

  2. POJ 2724

    Purifying Machine Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4014   Accepted: 1127 ...

  3. POJ 2182

    #include <iostream> #define MAXN 8005 using namespace std; int _m[MAXN]; int main() { //freope ...

  4. 安装mysql之后,存入中文出现乱码

    如图显示:安装mysql之后,存入中文出现乱码 解决方案: 找到如图的文件位置 打开进行如图的修改: 结果:

  5. Codeforces Round #336 (Div. 2) D. Zuma 区间dp

    D. Zuma   Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gems ...

  6. BZOJ 1015: [JSOI2008]星球大战starwar 并查集

    1015: [JSOI2008]星球大战starwar Description 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系.某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝 ...

  7. BZOJ 3224: Tyvj 1728 普通平衡树 vector

    3224: Tyvj 1728 普通平衡树 Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除 ...

  8. python--httplib模块使用

    httplib是一个相对底层的http请求模块,其上有专门的包装模块,如urllib内建模块,goto等第三方模块,但是封装的越高就越不灵 活,比如urllib模块里请求错误时就不会返回结果页的内容, ...

  9. border-radius几种写法的原理剖析

    border-radius:40px; border-radius:40px/20px; border-radius:40px 20px; border-radius:40px 20px 10px 5 ...

  10. 267. Palindrome Permutation II

    题目: Given a string s, return all the palindromic permutations (without duplicates) of it. Return an ...