# See COPYING.Runtime file for copyrights details.
from datetime import timedelta as td
class IEC_STRING(Structure):
Must be changed according to changes in iec_types.h
_fields_ = [("len", c_uint8),
class IEC_TIME(Structure):
Must be changed according to changes in iec_types.h
_fields_ = [("s", c_long), # tv_sec
("ns", c_long)] # tv_nsec
def _t(t, u=lambda x: x.contents, p=lambda t, x: t(x)):
lambda x: td(0, x.contents.s, x.contents.ns/1000.0),
lambda t, x: t(x.days * 24 * 3600 + x.seconds, x.microseconds*1000))
SameEndianessTypeTranslator = {
"BOOL": _t(c_uint8, lambda x: bool(x.contents)),
"TRANSITION": _t(c_uint8),
lambda x: x.contents.body[:x.contents.len],
lambda t, x: t(len(x), x)),
SwapedEndianessTypeTranslator = {
TypeTranslator = SameEndianessTypeTranslator
# Construct debugger natively supported types
DebugTypesSize = dict([(key, sizeof(t)) for key, (t, p, u) in SameEndianessTypeTranslator.items() if t is not None])
def UnpackDebugBuffer(buff, indexes):
buffptr = cast(cast(buff, c_char_p), c_void_p).value
c_type, unpack_func, _pack_func = TypeTranslator.get(iectype,
cursor = c_void_p(buffptr + buffoffset)
# strlen is stored in c_uint8 and sizeof(c_uint8) is 1
# first check we can read size
if (buffoffset + 1) <= buffsize:
size = 1 + cast(cursor,POINTER(c_type)).contents.len
if c_type is not None and (buffoffset + size) <= buffsize:
n = cast(cursor, POINTER(c_type))
if iectype not in ["BOOL", "DATE", "DT", "STRING", "TIME", "TOD"]:
elif iectype == "STRING":
if buffoffset and buffoffset == buffsize: