Edouard@592: #!/usr/bin/env python Edouard@592: # -*- coding: utf-8 -*- Edouard@592: # Edouard@592: #Copyright (C) 2011: Edouard TISSERANT and Laurent BESSARD Edouard@592: # Edouard@592: #See COPYING file for copyrights details. Edouard@592: # Edouard@592: #This library is free software; you can redistribute it and/or Edouard@592: #modify it under the terms of the GNU General Public Edouard@592: #License as published by the Free Software Foundation; either Edouard@592: #version 2.1 of the License, or (at your option) any later version. Edouard@592: # Edouard@592: #This library is distributed in the hope that it will be useful, Edouard@592: #but WITHOUT ANY WARRANTY; without even the implied warranty of Edouard@592: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Edouard@592: #General Public License for more details. Edouard@592: # Edouard@592: #You should have received a copy of the GNU General Public Edouard@592: #License along with this library; if not, write to the Free Software Edouard@592: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Edouard@592: Edouard@592: from ctypes import * edouard@593: from datetime import timedelta as td Edouard@592: Edouard@592: class IEC_STRING(Structure): Edouard@592: """ Edouard@592: Must be changed according to changes in iec_types.h Edouard@592: """ Edouard@592: _fields_ = [("len", c_uint8), Edouard@592: ("body", c_char * 126)] Edouard@592: Edouard@592: class IEC_TIME(Structure): Edouard@592: """ Edouard@592: Must be changed according to changes in iec_types.h Edouard@592: """ Edouard@592: _fields_ = [("s", c_long), #tv_sec Edouard@592: ("ns", c_long)] #tv_nsec Edouard@592: Edouard@592: def _t(t, u=lambda x:x.value, p=lambda t,x:t(x)): return (t, u, p) Edouard@595: def _ttime(): return (IEC_TIME, Edouard@595: lambda x:td(0, x.s, x.ns/1000), Edouard@595: lambda t,x:t(x.days * 24 * 3600 + x.seconds, x.microseconds*1000)) Edouard@592: Edouard@592: SameEndianessTypeTranslator = { Edouard@592: "BOOL" : _t(c_uint8, lambda x:x.value!=0), Edouard@592: "STEP" : _t(c_uint8), Edouard@592: "TRANSITION" : _t(c_uint8), Edouard@592: "ACTION" : _t(c_uint8), Edouard@592: "SINT" : _t(c_int8), Edouard@592: "USINT" : _t(c_uint8), Edouard@592: "BYTE" : _t(c_uint8), Edouard@595: "STRING" : (IEC_STRING, Edouard@592: lambda x:x.body[:x.len], Edouard@592: lambda t,x:t(len(x),x)), Edouard@592: "INT" : _t(c_int16), Edouard@592: "UINT" : _t(c_uint16), Edouard@592: "WORD" : _t(c_uint16), Edouard@592: "DINT" : _t(c_int32), Edouard@592: "UDINT" : _t(c_uint32), Edouard@592: "DWORD" : _t(c_uint32), Edouard@592: "LINT" : _t(c_int64), Edouard@592: "ULINT" : _t(c_uint64), Edouard@592: "LWORD" : _t(c_uint64), Edouard@592: "REAL" : _t(c_float), Edouard@592: "LREAL" : _t(c_double), Edouard@595: "TIME" : _ttime(), Edouard@595: "TOD" : _ttime(), Edouard@595: "DATE" : _ttime(), Edouard@595: "DT" : _ttime(), Edouard@592: } Edouard@592: Edouard@592: SwapedEndianessTypeTranslator = { Edouard@592: #TODO Edouard@592: } Edouard@592: Edouard@592: # Construct debugger natively supported types Edouard@592: DebugTypesSize = dict([(key,sizeof(t)) for key,(t,p,u) in SameEndianessTypeTranslator.iteritems() if t is not None]) Edouard@592: