[openrtm-commit:00780] r541 - in branches/work/OpenRTM-aist-Python/OpenRTM_aist: . test
openrtm @ openrtm.org
openrtm @ openrtm.org
2012年 3月 19日 (月) 13:28:59 JST
Author: kurihara
Date: 2012-03-19 13:28:58 +0900 (Mon, 19 Mar 2012)
New Revision: 541
Added:
branches/work/OpenRTM-aist-Python/OpenRTM_aist/test/test_ClockManager.py
Modified:
branches/work/OpenRTM-aist-Python/OpenRTM_aist/TimeMeasure.py
branches/work/OpenRTM-aist-Python/OpenRTM_aist/__init__.py
branches/work/OpenRTM-aist-Python/OpenRTM_aist/test/test_TimeMeasure.py
Log:
[incompat,impl,func] ClockManager class has been introduced. refs #2357
settimeofday has been added.
Modified: branches/work/OpenRTM-aist-Python/OpenRTM_aist/TimeMeasure.py
===================================================================
--- branches/work/OpenRTM-aist-Python/OpenRTM_aist/TimeMeasure.py 2012-03-14 08:39:40 UTC (rev 540)
+++ branches/work/OpenRTM-aist-Python/OpenRTM_aist/TimeMeasure.py 2012-03-19 04:28:58 UTC (rev 541)
@@ -19,6 +19,7 @@
#
#
+import sys, os
import time
import math
@@ -124,6 +125,54 @@
return OpenRTM_aist.TimeValue(self.sec, self.usec)
+ # inline int settimeofday(const struct timeval *tv , const struct timezone *tz)
+ def settimeofday(self, tv, tz):
+ if sys.platform == "win32":
+ from ctypes import windll, Structure, c_ushort, byref, c_ulong, c_long
+ class SYSTEMTIME(Structure):
+ _fields_ = [('wYear', c_ushort),
+ ('wMonth', c_ushort),
+ ('wDayOfWeek', c_ushort),
+ ('wDay', c_ushort),
+ ('wHour', c_ushort),
+ ('wMinute', c_ushort),
+ ('wSecond', c_ushort),
+ ('wMilliseconds', c_ushort)]
+
+
+ class LARGE_INTEGER(Structure):
+ _fields_ = [('low', c_ulong),
+ ('high', c_long)]
+
+
+ tm = long(tv.tv_sec*1e6) + long(tv.tv_usec)
+ st = SYSTEMTIME(0,0,0,0,0,0,0,0)
+ ft = LARGE_INTEGER(tm&0xFFFFFFFFL,tm>>32)
+ # 100 nanosecond units (since 16010101)
+ ret = windll.kernel32.FileTimeToSystemTime(byref(ft),
+ byref(st))
+ if not ret:
+ return -1
+
+ #windll.kernel32.SetSystemTime(byref(st))
+ print "settime Yer:", st.wYear, " Month:", st.wMonth, \
+ " DayOfWeek:", st.wDayOfWeek, " wDay:", st.wDay, \
+ " Hour:", st.wHour, "Minute:", st.wMinute, \
+ " Second:", st.wSecond, "Milliseconds:", st.wMilliseconds
+
+
+ else:
+ import ctypes
+ class timespec(ctypes.Structure):
+ _fields_ = [('tv_sec', ctypes.c_long),
+ ('tv_nsec', ctypes.c_long)]
+
+ librt = ctypes.cdll.LoadLibrary('librt.so')
+ ts = timespec(long(tv.tv_sec),long(tv.tv_usec*1000))
+ #return librt.clock_settime(0, ctypes.pointer(ts))
+
+ return 0
+
##
# TimeMeasure object
#
Modified: branches/work/OpenRTM-aist-Python/OpenRTM_aist/__init__.py
===================================================================
--- branches/work/OpenRTM-aist-Python/OpenRTM_aist/__init__.py 2012-03-14 08:39:40 UTC (rev 540)
+++ branches/work/OpenRTM-aist-Python/OpenRTM_aist/__init__.py 2012-03-19 04:28:58 UTC (rev 541)
@@ -20,6 +20,7 @@
from SystemLogger import *
from TimeValue import *
from TimeMeasure import *
+from ClockManager import *
from Singleton import *
from Factory import *
from GlobalFactory import *
Added: branches/work/OpenRTM-aist-Python/OpenRTM_aist/test/test_ClockManager.py
===================================================================
--- branches/work/OpenRTM-aist-Python/OpenRTM_aist/test/test_ClockManager.py (rev 0)
+++ branches/work/OpenRTM-aist-Python/OpenRTM_aist/test/test_ClockManager.py 2012-03-19 04:28:58 UTC (rev 541)
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file test_ClockManager.py
+# @brief test for ClockManager class
+# @date $Date$
+# @author Noriaki Ando <n-ando at aist.go.jp>
+#
+# Copyright (C) 2012
+# Noriaki Ando
+# Intelligent Systems Research Institute,
+# National Institute of
+# Advanced Industrial Science and Technology (AIST), Japan
+# All rights reserved.
+#
+# $Id$
+#
+
+import time
+import sys
+import math
+sys.path.insert(1,"../")
+
+import unittest
+from ClockManager import *
+
+
+
+class TestClockManager(unittest.TestCase):
+ def setUp(self):
+ self._cm = ClockManager.instance()
+ return
+
+ def test_LogicalClock(self):
+ tm = self._cm.getClock("logical").gettime()
+ self.assertEqual(0.0,tm.tv_sec)
+ self.assertEqual(0.0,tm.tv_usec)
+ stm = OpenRTM_aist.TimeValue(1,1)
+ tm = self._cm.getClock("logical").settime(stm)
+ tm = self._cm.getClock("logical").gettime()
+ self.assertEqual(1,tm.tv_sec)
+ self.assertEqual(1,tm.tv_usec)
+ tm = ClockManager.instance().getClock("logical").gettime()
+ self.assertEqual(1,tm.tv_sec)
+ self.assertEqual(1,tm.tv_usec)
+ return
+
+ def test_AdjustedClock(self):
+ tm = self._cm.getClock("adjusted").gettime()
+ stm = OpenRTM_aist.TimeValue(1,1)
+ tm = self._cm.getClock("adjusted").settime(stm)
+ tm = self._cm.getClock("adjusted").gettime()
+ return
+
+ def test_SystemClock(self):
+ tm = self._cm.getClock("system").gettime()
+ stm = OpenRTM_aist.TimeValue(1,1)
+ tm = self._cm.getClock("system").settime(stm)
+ return
+
+############### test #################
+if __name__ == '__main__':
+ unittest.main()
Modified: branches/work/OpenRTM-aist-Python/OpenRTM_aist/test/test_TimeMeasure.py
===================================================================
--- branches/work/OpenRTM-aist-Python/OpenRTM_aist/test/test_TimeMeasure.py 2012-03-14 08:39:40 UTC (rev 540)
+++ branches/work/OpenRTM-aist-Python/OpenRTM_aist/test/test_TimeMeasure.py 2012-03-19 04:28:58 UTC (rev 541)
@@ -150,7 +150,39 @@
self.assert_(math.fabs(mean[0] - wait_) < 0.03)
self.assert_(stdev[0] < (wait_ / 5.0))
return
-
+
+ def test_getsettimeofday(self):
+ """
+ if sys.platform == "win32":
+ from ctypes import windll, Structure, c_ushort, byref, c_ulong, c_long
+ class SYSTEMTIME(Structure):
+ _fields_ = [('wYear', c_ushort),
+ ('wMonth', c_ushort),
+ ('wDayOfWeek', c_ushort),
+ ('wDay', c_ushort),
+ ('wHour', c_ushort),
+ ('wMinute', c_ushort),
+ ('wSecond', c_ushort),
+ ('wMilliseconds', c_ushort)]
+
+
+ class LARGE_INTEGER(Structure):
+ _fields_ = [('low', c_ulong),
+ ('high', c_long)]
+
+
+ st = SYSTEMTIME(0,0,0,0,0,0,0,0)
+ windll.kernel32.GetSystemTime(byref(st))
+ ft = LARGE_INTEGER(0,0)
+ windll.kernel32.SystemTimeToFileTime(byref(st),byref(ft))
+ ret = windll.kernel32.FileTimeToSystemTime(byref(ft),
+ byref(st))
+ print "settime Yer:", st.wYear, " Month:", st.wMonth, \
+ " DayOfWeek:", st.wDayOfWeek, " wDay:", st.wDay, \
+ " Hour:", st.wHour, "Minute:", st.wMinute, \
+ " Second:", st.wSecond, "Milliseconds:", st.wMilliseconds
+ """
+ return
############### test #################
if __name__ == '__main__':
unittest.main()
openrtm-commit メーリングリストの案内