2016-12-19 11:46:33 +01:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
|
|
|
|
from ctypes import *
|
|
|
|
|
2016-12-22 17:58:22 +01:00
|
|
|
|
2016-12-22 17:50:02 +01:00
|
|
|
LIBSSS7_PATH = "../linux/bin/libsss7.so"
|
2016-12-19 11:46:33 +01:00
|
|
|
LIBSSS7_PAYLOAD_SIZE = 16
|
|
|
|
|
2016-12-22 17:50:02 +01:00
|
|
|
_SSS7_PAYLOAD_TYPE = c_ubyte * LIBSSS7_PAYLOAD_SIZE
|
|
|
|
|
2016-12-19 11:46:33 +01:00
|
|
|
_LIB_SSS7 = cdll.LoadLibrary(LIBSSS7_PATH)
|
|
|
|
|
|
|
|
# int libsss7_start(char *serialport);
|
|
|
|
_LIB_SSS7.libsss7_start.argtypes = [c_char_p]
|
|
|
|
_LIB_SSS7.libsss7_start.restype = c_int
|
|
|
|
|
|
|
|
# int libsss7_can_send(void);
|
|
|
|
_LIB_SSS7.libsss7_can_send.argtypes = None
|
|
|
|
_LIB_SSS7.libsss7_can_send.restype = c_int
|
|
|
|
|
|
|
|
# void libsss7_send(uint8_t msg[LIBSSS7_PAYLOAD_SIZE]);
|
2016-12-22 17:50:02 +01:00
|
|
|
_LIB_SSS7.libsss7_send.argtypes = [_SSS7_PAYLOAD_TYPE]
|
2016-12-19 11:46:33 +01:00
|
|
|
_LIB_SSS7.libsss7_send.restype = c_int
|
|
|
|
|
|
|
|
# int libsss7_send_failed(void);
|
|
|
|
_LIB_SSS7.libsss7_send_failed.argtypes = None
|
|
|
|
_LIB_SSS7.libsss7_send_failed.restype = c_int
|
|
|
|
|
|
|
|
# int libsss7_has_received(void);
|
|
|
|
_LIB_SSS7.libsss7_has_received.argtypes = None
|
|
|
|
_LIB_SSS7.libsss7_has_received.restype = c_int
|
|
|
|
|
|
|
|
# libsss7_get_received(uint8_t *msg);
|
2016-12-22 17:50:02 +01:00
|
|
|
_LIB_SSS7.libsss7_get_received.argtypes = [_SSS7_PAYLOAD_TYPE]
|
2016-12-19 11:46:33 +01:00
|
|
|
_LIB_SSS7.libsss7_get_received.restype = c_int
|
|
|
|
|
|
|
|
# void libsss7_stop();
|
|
|
|
_LIB_SSS7.libsss7_stop.argtypes = None
|
|
|
|
_LIB_SSS7.libsss7_stop.restype = None
|
|
|
|
|
|
|
|
class _SSS7(object):
|
|
|
|
|
|
|
|
def start(self, port):
|
|
|
|
return _LIB_SSS7.libsss7_start(port) == 0
|
|
|
|
|
2016-12-22 17:50:02 +01:00
|
|
|
def can_send(self):
|
2016-12-19 11:46:33 +01:00
|
|
|
return _LIB_SSS7.libsss7_can_send() == 1
|
|
|
|
|
2016-12-22 17:50:02 +01:00
|
|
|
def send(self,msg):
|
|
|
|
msg += [0] * (LIBSSS7_PAYLOAD_SIZE - len(msg))
|
|
|
|
payload = _SSS7_PAYLOAD_TYPE(*msg)
|
|
|
|
_LIB_SSS7.libsss7_send(payload)
|
2016-12-19 11:46:33 +01:00
|
|
|
|
2016-12-22 17:50:02 +01:00
|
|
|
def send_failed(self):
|
|
|
|
tmp = _LIB_SSS7.libsss7_send_failed()
|
|
|
|
print tmp
|
|
|
|
return tmp == 1
|
2016-12-19 11:46:33 +01:00
|
|
|
|
2016-12-22 17:50:02 +01:00
|
|
|
def has_received(self):
|
2016-12-23 02:08:57 +01:00
|
|
|
return _LIB_SSS7.libsss7_has_received()
|
2016-12-19 11:46:33 +01:00
|
|
|
|
2016-12-22 17:50:02 +01:00
|
|
|
def get_received(self):
|
2016-12-23 02:08:57 +01:00
|
|
|
payload = _SSS7_PAYLOAD_TYPE()
|
2016-12-19 11:46:33 +01:00
|
|
|
_LIB_SSS7.libsss7_get_received(payload)
|
2016-12-23 02:08:57 +01:00
|
|
|
return [payload[i] for i in range(0, LIBSSS7_PAYLOAD_SIZE)]
|
2016-12-19 11:46:33 +01:00
|
|
|
|
2016-12-22 17:50:02 +01:00
|
|
|
def stop(self):
|
2016-12-19 11:46:33 +01:00
|
|
|
_LIB_SSS7.libsss7_stop()
|
2016-12-22 17:50:02 +01:00
|
|
|
|
|
|
|
SSS7 = _SSS7()
|