import sys from _pi_cffi import ffi, lib from pprint import pprint def print_message( message, bsize): for x in range(bsize): c = message[x] if c[0] == 0x0d: print("\n", end='') else: print(chr(c[0]), end='') print("") def print_subfields( subpacket): done = 0 subfield = lib.JAM_GetSubfield(subpacket) if subfield == ffi.NULL: done = 1 else: print("SubField ID:", subfield[0].LoID, " ", end='') print_message(subfield.Buffer, subfield.DatLen) while done == 0: subfield = lib.JAM_GetSubfield(ffi.NULL) if subfield == ffi.NULL: done = 1 else: print("SubField ID:", subfield[0].LoID, " ", end='') print_message(subfield.Buffer, subfield.DatLen) jambase = ffi.new("s_JamBase **") ret = lib.JAM_OpenMB(b"fsx_bot", jambase) if ret == 0: print("OpenMB Success!") else: print("OpenMB ret=", ret) sys.exit(2) size = ffi.new("uint32_t *") ret = lib.JAM_GetMBSize(jambase[0], size) if ret == 0: print("Mesasgebase size=", size[0]) else: print("GetMBSize ret=", ret) # int JAM_ReadMsgHeader( s_JamBase* Base_PS, # ulong MsgNo_I, # s_JamMsgHeader* Header_PS, # s_JamSubPacket** Subfields_PPS ); msgno = 0 # msgheader = ffi.new("s_JamMsgHeader") msgheader = ffi.new("s_JamMsgHeader *") subpacket = ffi.new("s_JamSubPacket **") subfield = ffi.new("s_JamSubfield *") basesize = int( ffi.cast("long", size[0]) ) pprint(basesize) basesize = 10 buffer = ffi.new("char []", 4096) for msgno in range(basesize): # size): ret = lib.JAM_ReadMsgHeader(jambase[0], msgno, msgheader, subpacket) if ret == 0: print("ReadMsgHeader Success") print_subfields(subpacket[0]) if msgheader.TxtLen < 4096: # buffer = ffi.new("char []", msgheader.TxtLen) ret = lib.JAM_ReadMsgText(jambase[0], msgheader.TxtOffset, msgheader.TxtLen, buffer) if ret == 0: print_message(buffer, msgheader.TxtLen) else: print("ReadMsgText ret=", ret) else: print("Failed: > 4096") # buffer = None lib.JAM_DelSubPacket(subpacket[0]) else: print("ReadMsgHeader ret=", ret) print("Jam_Errno=", lib.JAM_Errno(jambase[0])) buffer = None subfield = None subpacket = None msgheader = None # pprint(jambase) ret = lib.JAM_CloseMB( jambase[0] ) lib.free(jambase[0]) jambase = None print("CloseMB ret=", ret)