/// <summary> /// Set the RTC hardware clock to the given DateTime object. Note that this will not change the Kernel time, see <see cref="SetKernelTime"/> /// </summary> /// <param name="newTime"> /// The <see cref="System.DateTime"/> object with the new time /// </param> /// <returns> /// A <see cref="System.Int32"/> that indicates the status of the operation /// </returns> public static int SetHardwareTime(DateTime newTime) { rtc_time rtc_tm = new rtc_time(); rtc_tm.tm_mday = newTime.Day; rtc_tm.tm_mon = newTime.Month; rtc_tm.tm_year = newTime.Year - 1900; rtc_tm.tm_hour = newTime.Hour; rtc_tm.tm_min = newTime.Minute; rtc_tm.tm_sec = newTime.Second; int rtc_fd = Syscall.open("/dev/rtc", OpenFlags.O_RDONLY); if (rtc_fd == -1) { return(-1); } int rtc_ioctl = ioctl(rtc_fd, RTC_SET_TIME, ref rtc_tm); if (rtc_ioctl == -1) { return(-1); } Syscall.close(rtc_fd); return(0); }
/// <summary> /// Return the current RTC hardware clock time. /// </summary> /// <returns> /// The <see cref="System.DateTime"/> objekt represent the current RTC time /// </returns> public static DateTime GetHardwareTime() { rtc_time rtc_tm = new rtc_time(); int rtc_fd = Syscall.open("/dev/rtc", OpenFlags.O_RDONLY); if (rtc_fd == -1) { return new DateTime(); } int rtc_ioctl = ioctl(rtc_fd, RTC_RD_TIME, ref rtc_tm); if (rtc_ioctl == -1) { return new DateTime(); } Syscall.close(rtc_fd); return new DateTime(rtc_tm.tm_year + 1900, rtc_tm.tm_mon , rtc_tm.tm_mday, rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec); }
/// <summary> /// Return the current RTC hardware clock time. /// </summary> /// <returns> /// The <see cref="System.DateTime"/> objekt represent the current RTC time /// </returns> public static DateTime GetHardwareTime() { rtc_time rtc_tm = new rtc_time(); int rtc_fd = Syscall.open("/dev/rtc", OpenFlags.O_RDONLY); if (rtc_fd == -1) { return(new DateTime()); } int rtc_ioctl = ioctl(rtc_fd, RTC_RD_TIME, ref rtc_tm); if (rtc_ioctl == -1) { return(new DateTime()); } Syscall.close(rtc_fd); return(new DateTime(rtc_tm.tm_year + 1900, rtc_tm.tm_mon, rtc_tm.tm_mday, rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec)); }
/// <summary> /// Set the RTC hardware clock to the given DateTime object. Note that this will not change the Kernel time, see <see cref="SetKernelTime"/> /// </summary> /// <param name="newTime"> /// The <see cref="System.DateTime"/> object with the new time /// </param> /// <returns> /// A <see cref="System.Int32"/> that indicates the status of the operation /// </returns> public static int SetHardwareTime(DateTime newTime) { rtc_time rtc_tm = new rtc_time(); rtc_tm.tm_mday = newTime.Day; rtc_tm.tm_mon = newTime.Month; rtc_tm.tm_year = newTime.Year - 1900; rtc_tm.tm_hour = newTime.Hour; rtc_tm.tm_min = newTime.Minute; rtc_tm.tm_sec = newTime.Second; int rtc_fd = Syscall.open("/dev/rtc", OpenFlags.O_RDONLY); if (rtc_fd == -1) { return -1; } int rtc_ioctl = ioctl(rtc_fd, RTC_SET_TIME, ref rtc_tm); if (rtc_ioctl == -1) { return -1; } Syscall.close(rtc_fd); return 0; }
private static extern int ioctl(int fd, int request, ref rtc_time data);