freemyipod r778 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r777‎ | r778 | r779 >
Date:23:26, 7 November 2011
Author:farthen
Status:new
Tags:
Comment:
Add real time clock support to emcore python tools
Modified paths:
  • /emcore/trunk/tools/emcore.py (modified) (history)
  • /emcore/trunk/tools/libemcore.py (modified) (history)

Diff [purge]

Index: emcore/trunk/tools/emcore.py
@@ -1322,6 +1322,23 @@
13231323 self.logger.info("Freeing all memory allocations created by the monitor thread\n")
13241324 self.emcore.free_all()
13251325 self.logger.info("Successfully freed all memory allocations created by the monitor thread\n")
 1326+
 1327+ @command
 1328+ def rtcread(self):
 1329+ """ Reads the real time clock on the device """
 1330+ import datetime
 1331+ self.logger.info("Reading the clock\n")
 1332+ dt = self.emcore.rtcread()
 1333+ self.logger.info("Successfully read the clock: %s\n" % (dt.ctime()))
 1334+
 1335+ @command
 1336+ def rtcwrite(self):
 1337+ """ Sets the real time clock on the device to the current local time """
 1338+ import datetime
 1339+ dt = datetime.datetime.now()
 1340+ self.logger.info("Setting the clock to: %s\n" % (dt.ctime()))
 1341+ self.emcore.rtcwrite(dt)
 1342+ self.logger.info("Successfully set the clock\n")
13261343
13271344
13281345 if __name__ == "__main__":
@@ -1331,4 +1348,4 @@
13321349 interface = Commandline()
13331350 interface._parsecommand(sys.argv[1], sys.argv[2:])
13341351 except KeyboardInterrupt:
1335 - sys.exit()
\ No newline at end of file
 1352+ sys.exit()
Index: emcore/trunk/tools/libemcore.py
@@ -31,6 +31,7 @@
3232 import ctypes
3333 import usb.core
3434 import base64
 35+import datetime
3536
3637 from libemcoredata import *
3738 from misc import Logger, Bunch, remote_pointer, Error, ArgumentError, getthread, gethwname
@@ -952,6 +953,23 @@
953954 """ Frees all memory allocations created by the monitor thread """
954955 self.logger.debug("Freeing all memory allocations created by the monitor thread\n")
955956 return self.lib.monitorcommand(struct.pack("<IIII", 57, 0, 0, 0), "III", (None, None, None))
 957+
 958+ @command()
 959+ def rtcread(self):
 960+ """ Reads the real time clock on the device """
 961+ self.logger.debug("Reading the clock\n")
 962+ date = self.lib.monitorcommand(struct.pack("<IIII", 60, 0, 0, 0), "BBBBBBBBI", ("second", "minute", "hour", "weekday", "day", "month", "year", None, None))
 963+ dt = datetime.datetime(date.year + 2000, date.month, date.day, date.hour, date.minute, date.second)
 964+ self.logger.debug("Read date '%s' from device", (dt.ctime()))
 965+ return dt
 966+
 967+ @command()
 968+ def rtcwrite(self, dt):
 969+ """ Sets the real time clock on the device to the datetime object 'dt' """
 970+ self.logger.debug("Setting the clock to: %s\n" % (dt.ctime()))
 971+ if dt.year < 2000 or dt.year > 2255:
 972+ raise ArgumentError("The Year must be between 2000 and 2255")
 973+ return self.lib.monitorcommand(struct.pack("<IBBBBBBBBI", 61, dt.second, dt.minute, dt.hour, dt.weekday(), dt.day, dt.month, dt.year - 2000, 0, 0), "III", (None, None, None))
956974
957975
958976 class Lib(object):