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