targets/typemapping.py
author laurent
Thu, 28 Jun 2012 12:07:21 +0200
changeset 782 6f0e10085df9
parent 595 6348c0110e0f
child 917 401e44bae7c0
permissions -rw-r--r--
Adding support for file explorer for project files
592
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
     3
#
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
     4
#Copyright (C) 2011: Edouard TISSERANT and Laurent BESSARD
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
     5
#
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
     6
#See COPYING file for copyrights details.
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
     7
#
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
     8
#This library is free software; you can redistribute it and/or
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
     9
#modify it under the terms of the GNU General Public
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    10
#License as published by the Free Software Foundation; either
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    11
#version 2.1 of the License, or (at your option) any later version.
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    12
#
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    13
#This library is distributed in the hope that it will be useful,
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    14
#but WITHOUT ANY WARRANTY; without even the implied warranty of
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    15
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    16
#General Public License for more details.
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    17
#
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    18
#You should have received a copy of the GNU General Public
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    19
#License along with this library; if not, write to the Free Software
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    20
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    21
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    22
from ctypes import *
593
726f58cf97e3 fixed typo in latest debugger changes
edouard
parents: 592
diff changeset
    23
from datetime import timedelta as td
592
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    24
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    25
class IEC_STRING(Structure):
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    26
    """
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    27
    Must be changed according to changes in iec_types.h
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    28
    """
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    29
    _fields_ = [("len", c_uint8),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    30
                ("body", c_char * 126)] 
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    31
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    32
class IEC_TIME(Structure):
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    33
    """
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    34
    Must be changed according to changes in iec_types.h
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    35
    """
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    36
    _fields_ = [("s", c_long), #tv_sec
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    37
                ("ns", c_long)] #tv_nsec
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    38
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    39
def _t(t, u=lambda x:x.value, p=lambda t,x:t(x)): return  (t, u, p)
595
6348c0110e0f Added support for handling ANY_DATE types in debugger type translation
Edouard Tisserant
parents: 594
diff changeset
    40
def _ttime(): return (IEC_TIME, 
6348c0110e0f Added support for handling ANY_DATE types in debugger type translation
Edouard Tisserant
parents: 594
diff changeset
    41
                      lambda x:td(0, x.s, x.ns/1000), 
6348c0110e0f Added support for handling ANY_DATE types in debugger type translation
Edouard Tisserant
parents: 594
diff changeset
    42
                      lambda t,x:t(x.days * 24 * 3600 + x.seconds, x.microseconds*1000))
592
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    43
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    44
SameEndianessTypeTranslator = {
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    45
    "BOOL" :       _t(c_uint8,  lambda x:x.value!=0),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    46
    "STEP" :       _t(c_uint8),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    47
    "TRANSITION" : _t(c_uint8),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    48
    "ACTION" :     _t(c_uint8),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    49
    "SINT" :       _t(c_int8),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    50
    "USINT" :      _t(c_uint8),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    51
    "BYTE" :       _t(c_uint8),
595
6348c0110e0f Added support for handling ANY_DATE types in debugger type translation
Edouard Tisserant
parents: 594
diff changeset
    52
    "STRING" :     (IEC_STRING, 
592
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    53
                      lambda x:x.body[:x.len], 
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    54
                      lambda t,x:t(len(x),x)),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    55
    "INT" :        _t(c_int16),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    56
    "UINT" :       _t(c_uint16),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    57
    "WORD" :       _t(c_uint16),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    58
    "DINT" :       _t(c_int32),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    59
    "UDINT" :      _t(c_uint32),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    60
    "DWORD" :      _t(c_uint32),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    61
    "LINT" :       _t(c_int64),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    62
    "ULINT" :      _t(c_uint64),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    63
    "LWORD" :      _t(c_uint64),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    64
    "REAL" :       _t(c_float),
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    65
    "LREAL" :      _t(c_double),
595
6348c0110e0f Added support for handling ANY_DATE types in debugger type translation
Edouard Tisserant
parents: 594
diff changeset
    66
    "TIME" :       _ttime(),
6348c0110e0f Added support for handling ANY_DATE types in debugger type translation
Edouard Tisserant
parents: 594
diff changeset
    67
    "TOD" :        _ttime(),
6348c0110e0f Added support for handling ANY_DATE types in debugger type translation
Edouard Tisserant
parents: 594
diff changeset
    68
    "DATE" :       _ttime(),
6348c0110e0f Added support for handling ANY_DATE types in debugger type translation
Edouard Tisserant
parents: 594
diff changeset
    69
    "DT" :         _ttime(),
592
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    70
    } 
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    71
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    72
SwapedEndianessTypeTranslator = {
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    73
    #TODO
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    74
    } 
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    75
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    76
# Construct debugger natively supported types
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    77
DebugTypesSize =  dict([(key,sizeof(t)) for key,(t,p,u) in SameEndianessTypeTranslator.iteritems() if t is not None])
c6408f92da0a Initial TIME support in debugger
Edouard Tisserant
parents:
diff changeset
    78