暱稱:cmj 日期:2014年10月10日—2014年10月17日
1、本週已完成任務:可設置系統時間
2、本週未完成任務:qt界面在顯示屏的顯示
3、下週計劃:(1)、繼續解決qt在cvbs上的顯示問題 (2)、所要實現的功能需要各個模塊配合
4、關鍵鍵技術點說明:
4.1hi_rtc驅動源碼:
static long hi_rtc_ioctl(struct file *file,
unsigned int cmd,
unsigned long arg)
{
unsigned long flags;
int ret;
rtc_time_t time;
reg_data_t reg_info;
reg_temp_mode_t temp_mode;
switch (cmd)
{
...
...
case HI_RTC_RD_TIME: //讀取rtc時間
<span style="white-space:pre"> </span>HI_MSG("HI_RTC_RD_TIME");
hirtc_get_time(&time);
ret = copy_to_user((void *)arg, &time, sizeof(time));
if (ret) {
return -EFAULT;
}
break;
case HI_RTC_SET_TIME:
HI_MSG("HI_RTC_SET_TIME");
ret = copy_from_user(&time,
(struct rtc_time_t *) arg,
sizeof(time));
if (ret) {
return -EFAULT;
}
hirtc_set_time(time);
break;
...
default:
return -EINVAL;
}
return 0;
}
typedef struct {
unsigned int year;
unsigned int month;
unsigned int date;
unsigned int hour;
unsigned int minute;
unsigned int second;
unsigned int weekday;
} rtc_time_t;
#define HI_RTC_RD_TIME _IOR('p', 0x09, rtc_time_t)
#define HI_RTC_SET_TIME _IOW('p', 0x0a, rtc_time_t)
qt程序
<P>#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "hi_rtc.h"
#include <fcntl.h>
#include <sys/ioctl.h>
#include <QFile>
#include <QDebug>
#include <QDateTime>
static int fb;//靜態設備號 MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
} MainWindow::~MainWindow()
{
delete ui;
} void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
} void MainWindow::settime() //設置rtc時間
{
rtc_time_t tm;
tm.year = 2014;
tm.month = 10;
tm.date = 17;
tm.hour = 13;
tm.minute = 13;
tm.second = 00;
tm.weekday =0;
QFile f("/dev/hi_rtc");//定義led驅動文件
if (f.exists())//如果文件存在
{
fb = open("/dev/hi_rtc", QIODevice::ReadWrite);//讀寫方式打開文件
if (fb < 0)//打開驅動文件錯誤
{
perror("open device leds fail");//輸入錯誤信息
// return ;//返回
}
}
ioctl(fb, HI_RTC_SET_TIME, &tm);
::close(fb); }
void MainWindow::gettime()//讀取RTC時間
{
rtc_time_t tm;
QFile f("/dev/hi_rtc");//定義led驅動文件
qDebug()<<1;
if (f.exists())//如果文件存在
{
fb = open("/dev/hi_rtc", QIODevice::ReadWrite);//讀寫方式打開文件
qDebug()<<2;
if (fb < 0)//打開驅動文件錯誤
{
qDebug()<<3;
perror("open device leds fail");//輸入錯誤信息
// return ;//返回
}
}
ioctl(fb, HI_RTC_RD_TIME, &tm);//讀取rtc時間
qDebug()<<tm.year<<tm.month<<tm.date<<tm.hour<<tm.minute<<tm.second;
::close(fb);
} void MainWindow::setsystime() //設置系統時間
{
QString time;
time = "date 010101012000";
system(time.toLatin1().data()); //.toLatin1().data()作用是將QString轉char* ;
// system("date 010101012000");
} void MainWindow::getsystime() //獲得系統時間
{
QDateTime time = QDateTime::currentDateTime();//獲取系統現在的時間
QString str = time.toString("yyyy-MM-dd hh:mm:ss ddd"); //設置顯示格式
qDebug()<<str;
}