xxp1993111
守望者xxp
2020-01-15 18:43

jni使用ioctl操纵节点/dev/rtc0报错

5
  • c++
  • c语言
  • linux
  • android

android是32位操作系统android 7.1,linux kernel 是4.4

现象:如果用ioctl传RTC_SET_TIME_LISTEN, 底层ioctl获取没问题,OK
如果用ioctl传RTC_GETTIME_LISTEN, 底层ioctl获取不到,上层报错为: "+++++could not RTC_GETTIME_LISTEN val++++"

#define DRIVER_NAME "/dev/rtc0"

#define RTC_SET_TIME_LISTEN 1
#define RTC_GETTIME_LISTEN 3

namespace android
{

static jint android_server_RtcManager_RtcSetDefaultTime(JNIEnv* /* env /, jobject / thiz */)
{
struct rtc_time rtc;
int result;

ALOGE("++++android_server_RtcManager_RtcSetDefaultTime+++++");
int fd = open(DRIVER_NAME, O_RDWR);
if (fd < 0) {
    ALOGE("could not open %s", DRIVER_NAME);
    return false;
}

memset(&rtc, 0, sizeof(rtc));
rtc.tm_sec = 3;
rtc.tm_min = 3;
rtc.tm_hour = 3;
rtc.tm_mday = 3;
rtc.tm_mon = 3;
rtc.tm_year = 113;
rtc.tm_wday = 3;
rtc.tm_yday = 3;
rtc.tm_isdst = -1;

result = ioctl(fd, RTC_GETTIME_LISTEN, &rtc);
if(result < 0){
    ALOGE("+++++could not RTC_GETTIME_LISTEN val++++");
}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐