From 1877919fa4d424cc93b93b2b1e8718b4a99ddc50 Mon Sep 17 00:00:00 2001 From: LongHairedHacker Date: Mon, 19 Dec 2016 11:46:33 +0100 Subject: [PATCH 1/4] 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() From cb6b8944a3b9a419fe87772c8f1cbfdcf4c4d55c Mon Sep 17 00:00:00 2001 From: LongHairedHacker Date: Mon, 19 Dec 2016 11:46:33 +0100 Subject: [PATCH 2/4] 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() From 714fe175ee1cbe17ba51434297e2e06cc3bed469 Mon Sep 17 00:00:00 2001 From: LongHairedHacker Date: Thu, 22 Dec 2016 17:50:02 +0100 Subject: [PATCH 3/4] Fixed sending part --- software/python/sss7.py | 30 +++++++++++++++++++----------- software/python/test.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 software/python/test.py diff --git a/software/python/sss7.py b/software/python/sss7.py index 714de99..e469e69 100644 --- a/software/python/sss7.py +++ b/software/python/sss7.py @@ -2,9 +2,11 @@ from ctypes import * -LIBSSS7_PATH = "../linux/libsss7.so" +LIBSSS7_PATH = "../linux/bin/libsss7.so" LIBSSS7_PAYLOAD_SIZE = 16 +_SSS7_PAYLOAD_TYPE = c_ubyte * LIBSSS7_PAYLOAD_SIZE + _LIB_SSS7 = cdll.LoadLibrary(LIBSSS7_PATH) # int libsss7_start(char *serialport); @@ -16,7 +18,7 @@ _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.argtypes = [_SSS7_PAYLOAD_TYPE] _LIB_SSS7.libsss7_send.restype = c_int # int libsss7_send_failed(void); @@ -28,7 +30,7 @@ _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.argtypes = [_SSS7_PAYLOAD_TYPE] _LIB_SSS7.libsss7_get_received.restype = c_int # void libsss7_stop(); @@ -40,22 +42,28 @@ class _SSS7(object): def start(self, port): return _LIB_SSS7.libsss7_start(port) == 0 - def can_send(): + def can_send(self): return _LIB_SSS7.libsss7_can_send() == 1 - def send(msg): - _LIB_SSS7.libsss7_send(msg) + def send(self,msg): + msg += [0] * (LIBSSS7_PAYLOAD_SIZE - len(msg)) + payload = _SSS7_PAYLOAD_TYPE(*msg) + _LIB_SSS7.libsss7_send(payload) - def send_failed(): - return _LIB_SSS7.libsss7_send_failed() == 1 + def send_failed(self): + tmp = _LIB_SSS7.libsss7_send_failed() + print tmp + return tmp == 1 - def has_received(): + def has_received(self): return _LIB_SSS7.libsss7_get_received() - def get_received(): + def get_received(self): payload = [0] * LIBSSS7_PAYLOAD_SIZE _LIB_SSS7.libsss7_get_received(payload) return payload - def stop(): + def stop(self): _LIB_SSS7.libsss7_stop() + +SSS7 = _SSS7() diff --git a/software/python/test.py b/software/python/test.py new file mode 100644 index 0000000..602924b --- /dev/null +++ b/software/python/test.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python2 + +from time import sleep + +from sss7 import SSS7 + +def to_byte_list(data): + return [ord(c) for c in data] + +def to_string(data): + data = [chr(c) for c in data] + return "".join(data) + +def main(): + SSS7.start("/dev/ttyUSB0") + + while not SSS7.can_send() : + sleep(0.1) + + SSS7.send(to_byte_list("Hello python")) + while not SSS7.can_send(): + sleep(0.1) + + if SSS7.send_failed(): + print "Send failed" + + + #while(!bus.hasReceived()); + #byte[] data = bus.getReceived(); + #String str = new String(data); + #System.out.println(str); + + + SSS7.stop() + + +if __name__ == '__main__': + main() From 26696599b3ca7b95adc2eaa084c1f6cdcfbb0f25 Mon Sep 17 00:00:00 2001 From: LongHairedHacker Date: Fri, 23 Dec 2016 02:08:57 +0100 Subject: [PATCH 4/4] Python should work now --- software/python/sss7.py | 6 +++--- software/python/test.py | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/software/python/sss7.py b/software/python/sss7.py index 6069fa0..3529a13 100644 --- a/software/python/sss7.py +++ b/software/python/sss7.py @@ -57,12 +57,12 @@ class _SSS7(object): return tmp == 1 def has_received(self): - return _LIB_SSS7.libsss7_get_received() + return _LIB_SSS7.libsss7_has_received() def get_received(self): - payload = [0] * LIBSSS7_PAYLOAD_SIZE + payload = _SSS7_PAYLOAD_TYPE() _LIB_SSS7.libsss7_get_received(payload) - return payload + return [payload[i] for i in range(0, LIBSSS7_PAYLOAD_SIZE)] def stop(self): _LIB_SSS7.libsss7_stop() diff --git a/software/python/test.py b/software/python/test.py index 602924b..88b0418 100644 --- a/software/python/test.py +++ b/software/python/test.py @@ -25,10 +25,11 @@ def main(): print "Send failed" - #while(!bus.hasReceived()); - #byte[] data = bus.getReceived(); - #String str = new String(data); - #System.out.println(str); + while not SSS7.has_received(): + sleep(0.1) + + print to_string(SSS7.get_received()) + SSS7.stop()