author | Surkov Sergey <surkovsv93@gmail.com> |
Thu, 29 Dec 2016 18:36:00 +0300 | |
changeset 1619 | 163d3a883575 |
parent 1571 | 486f94a8032c |
child 1667 | cefc9219bb48 |
permissions | -rw-r--r-- |
592 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
3 |
|
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
592 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
7 |
# Copyright (C) 2011: Edouard TISSERANT and Laurent BESSARD |
592 | 8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
592 | 10 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
592 | 15 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
19 |
# GNU General Public License for more details. |
592 | 20 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1433
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
592 | 24 |
|
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
25 |
import ctypes |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
26 |
ctypes.pythonapi.PyString_AsString.argtypes = (ctypes.c_void_p,) |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
27 |
ctypes.pythonapi.PyString_AsString.restype = ctypes.POINTER(ctypes.c_char) |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
28 |
|
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
29 |
|
592 | 30 |
from ctypes import * |
593 | 31 |
from datetime import timedelta as td |
592 | 32 |
|
33 |
class IEC_STRING(Structure): |
|
34 |
""" |
|
35 |
Must be changed according to changes in iec_types.h |
|
36 |
""" |
|
37 |
_fields_ = [("len", c_uint8), |
|
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
38 |
("body", c_char * 126)] |
592 | 39 |
|
40 |
class IEC_TIME(Structure): |
|
41 |
""" |
|
42 |
Must be changed according to changes in iec_types.h |
|
43 |
""" |
|
44 |
_fields_ = [("s", c_long), #tv_sec |
|
45 |
("ns", c_long)] #tv_nsec |
|
46 |
||
47 |
def _t(t, u=lambda x:x.value, p=lambda t,x:t(x)): return (t, u, p) |
|
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
48 |
def _ttime(): return (IEC_TIME, |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
49 |
lambda x:td(0, x.s, x.ns/1000), |
595
6348c0110e0f
Added support for handling ANY_DATE types in debugger type translation
Edouard Tisserant
parents:
594
diff
changeset
|
50 |
lambda t,x:t(x.days * 24 * 3600 + x.seconds, x.microseconds*1000)) |
592 | 51 |
|
52 |
SameEndianessTypeTranslator = { |
|
53 |
"BOOL" : _t(c_uint8, lambda x:x.value!=0), |
|
54 |
"STEP" : _t(c_uint8), |
|
55 |
"TRANSITION" : _t(c_uint8), |
|
56 |
"ACTION" : _t(c_uint8), |
|
57 |
"SINT" : _t(c_int8), |
|
58 |
"USINT" : _t(c_uint8), |
|
59 |
"BYTE" : _t(c_uint8), |
|
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
60 |
"STRING" : (IEC_STRING, |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
61 |
lambda x:x.body[:x.len], |
592 | 62 |
lambda t,x:t(len(x),x)), |
63 |
"INT" : _t(c_int16), |
|
64 |
"UINT" : _t(c_uint16), |
|
65 |
"WORD" : _t(c_uint16), |
|
66 |
"DINT" : _t(c_int32), |
|
67 |
"UDINT" : _t(c_uint32), |
|
68 |
"DWORD" : _t(c_uint32), |
|
69 |
"LINT" : _t(c_int64), |
|
70 |
"ULINT" : _t(c_uint64), |
|
71 |
"LWORD" : _t(c_uint64), |
|
72 |
"REAL" : _t(c_float), |
|
73 |
"LREAL" : _t(c_double), |
|
595
6348c0110e0f
Added support for handling ANY_DATE types in debugger type translation
Edouard Tisserant
parents:
594
diff
changeset
|
74 |
"TIME" : _ttime(), |
6348c0110e0f
Added support for handling ANY_DATE types in debugger type translation
Edouard Tisserant
parents:
594
diff
changeset
|
75 |
"TOD" : _ttime(), |
6348c0110e0f
Added support for handling ANY_DATE types in debugger type translation
Edouard Tisserant
parents:
594
diff
changeset
|
76 |
"DATE" : _ttime(), |
6348c0110e0f
Added support for handling ANY_DATE types in debugger type translation
Edouard Tisserant
parents:
594
diff
changeset
|
77 |
"DT" : _ttime(), |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
78 |
} |
592 | 79 |
|
80 |
SwapedEndianessTypeTranslator = { |
|
81 |
#TODO |
|
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
82 |
} |
592 | 83 |
|
1075
8078c01ae464
Now Debug Buffer Unpacking is a separate function, declared in typemapping.py
Edouard Tisserant
parents:
972
diff
changeset
|
84 |
TypeTranslator=SameEndianessTypeTranslator |
8078c01ae464
Now Debug Buffer Unpacking is a separate function, declared in typemapping.py
Edouard Tisserant
parents:
972
diff
changeset
|
85 |
|
592 | 86 |
# Construct debugger natively supported types |
87 |
DebugTypesSize = dict([(key,sizeof(t)) for key,(t,p,u) in SameEndianessTypeTranslator.iteritems() if t is not None]) |
|
88 |
||
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
89 |
def UnpackDebugBuffer(buff, indexes): |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
90 |
res = [] |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
91 |
buffoffset = 0 |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
92 |
buffsize = len(buff) |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
93 |
buffptr = cast(ctypes.pythonapi.PyString_AsString(id(buff)),c_void_p).value |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
94 |
for iectype in indexes: |
1075
8078c01ae464
Now Debug Buffer Unpacking is a separate function, declared in typemapping.py
Edouard Tisserant
parents:
972
diff
changeset
|
95 |
c_type,unpack_func, pack_func = \ |
8078c01ae464
Now Debug Buffer Unpacking is a separate function, declared in typemapping.py
Edouard Tisserant
parents:
972
diff
changeset
|
96 |
TypeTranslator.get(iectype, |
8078c01ae464
Now Debug Buffer Unpacking is a separate function, declared in typemapping.py
Edouard Tisserant
parents:
972
diff
changeset
|
97 |
(None,None,None)) |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
98 |
if c_type is not None and buffoffset < buffsize: |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
99 |
cursor = c_void_p( buffptr + buffoffset) |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
100 |
value = unpack_func( cast(cursor, |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
101 |
POINTER(c_type)).contents) |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
102 |
buffoffset += sizeof(c_type) if iectype != "STRING" else len(value)+1 |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
103 |
res.append(value) |
1075
8078c01ae464
Now Debug Buffer Unpacking is a separate function, declared in typemapping.py
Edouard Tisserant
parents:
972
diff
changeset
|
104 |
else: |
8078c01ae464
Now Debug Buffer Unpacking is a separate function, declared in typemapping.py
Edouard Tisserant
parents:
972
diff
changeset
|
105 |
break |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1075
diff
changeset
|
106 |
if buffoffset and buffoffset == buffsize: |
1075
8078c01ae464
Now Debug Buffer Unpacking is a separate function, declared in typemapping.py
Edouard Tisserant
parents:
972
diff
changeset
|
107 |
return res |
8078c01ae464
Now Debug Buffer Unpacking is a separate function, declared in typemapping.py
Edouard Tisserant
parents:
972
diff
changeset
|
108 |
return None |
8078c01ae464
Now Debug Buffer Unpacking is a separate function, declared in typemapping.py
Edouard Tisserant
parents:
972
diff
changeset
|
109 |
|
8078c01ae464
Now Debug Buffer Unpacking is a separate function, declared in typemapping.py
Edouard Tisserant
parents:
972
diff
changeset
|
110 |
|
8078c01ae464
Now Debug Buffer Unpacking is a separate function, declared in typemapping.py
Edouard Tisserant
parents:
972
diff
changeset
|
111 |
|
917 | 112 |
LogLevels = ["CRITICAL","WARNING","INFO","DEBUG"] |
113 |
LogLevelsCount = len(LogLevels) |
|
114 |
LogLevelsDict = dict(zip(LogLevels,range(LogLevelsCount))) |
|
115 |
LogLevelsDefault = LogLevelsDict["DEBUG"] |
|
972 | 116 |