From cb6b8944a3b9a419fe87772c8f1cbfdcf4c4d55c Mon Sep 17 00:00:00 2001 From: LongHairedHacker Date: Mon, 19 Dec 2016 11:46:33 +0100 Subject: [PATCH] Staretd work on Python port --- software/python/sss7.py | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 software/python/sss7.py diff --git a/software/python/sss7.py b/software/python/sss7.py new file mode 100644 index 0000000..714de99 --- /dev/null +++ b/software/python/sss7.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python2 + +from ctypes import * + +LIBSSS7_PATH = "../linux/libsss7.so" +LIBSSS7_PAYLOAD_SIZE = 16 + +_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]); +_LIB_SSS7.libsss7_send.argtypes = [c_ubyte * LIBSSS7_PAYLOAD_SIZE] +_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); +_LIB_SSS7.libsss7_get_received = [c_ubyte * LIBSSS7_PAYLOAD_SIZE] +_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 + + def can_send(): + return _LIB_SSS7.libsss7_can_send() == 1 + + def send(msg): + _LIB_SSS7.libsss7_send(msg) + + def send_failed(): + return _LIB_SSS7.libsss7_send_failed() == 1 + + def has_received(): + return _LIB_SSS7.libsss7_get_received() + + def get_received(): + payload = [0] * LIBSSS7_PAYLOAD_SIZE + _LIB_SSS7.libsss7_get_received(payload) + return payload + + def stop(): + _LIB_SSS7.libsss7_stop()