首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Linux内核事件: timeval或timespec

Linux内核事件: timeval或timespec
EN

Stack Overflow用户
提问于 2019-07-23 22:33:55
回答 2查看 562关注 0票数 1

我正在阅读(触摸)来自linux内核的事件。我想记录这些事件的时间,但我不知道这些事件是以timespec还是timeval的形式传递的。有人能指出我的正确方向吗?

示例代码(在从缓冲区读取事件之后)

代码语言:javascript
复制
switch(evnt.code) {
    case ABS_X:
    case ABS_Y:
      break;
        case ABS_MT_SLOT: 
       // this one sets the digit (virtual representation of the finger)
           current.setSlot(evnt.value);
          break;
    case ABS_MT_POSITION_X:
      current.setX(evnt.value, evnt.time);
      break;
    case ABS_MT_POSITION_Y:
      current.setY(evnt.value, evnt.time);
      break;
    case ABS_MT_TRACKING_ID:
      current.setActive(evnt.value >= 0, evnt.time);
      break;
    default:
      W_MOD("EV_ABS, unhandled event code " << evnt.code);
    }

其中一个过程职能是:

代码语言:javascript
复制
inline void setY(int value, struct timeval KernelTime)
{
    if (slot < ndigits) {
    // store both time and value
        digit[slot].y = value;
        digit[slot].TimeOfEvent = KernelTime.tv_sec*1000000 +  KernelTime.tv_usec;;
        digit[slot].changed = true;
}
}

随着时间的推移,它可以工作,但这是否也是一个自动幸运的类型转换?

编辑:一旦我写了这篇文章,我就想出了一些方法来检查它。读取linux内核事件的代码“evtest”是开源的。在第1060项上,他们使用timeval结构来报告事件时间。我猜这是一个明确的答案:或者它仍然是一个不可预见的类型化?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-07-24 05:48:28

有人能指出我的正确方向吗?

文件/输入/输入

/dev/input/eventX设备读取数据将返回struct input_event的数据,该struct input_event的第一个成员是struct timeval time;

代码语言:javascript
复制
Event interface
===============
...
    struct input_event {
        struct timeval time;
        unsigned short type;
        unsigned short code;
        unsigned int value;
    };

``time`` is the timestamp, it returns the time at which the event happened.
票数 1
EN

Stack Overflow用户

发布于 2019-07-23 23:39:54

C++不会自动转换结构,尽管它们可以定义转换。( Linux中的C结构永远不会这么做。)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57173044

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档