-
Notifications
You must be signed in to change notification settings - Fork 3
/
pcsiSerial.py
93 lines (81 loc) · 2.71 KB
/
pcsiSerial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 11 23:59:08 2020
@author: showard
"""
import re
import os
import numpy as np
import imageio
import serial
from pcsi.pcsitximage import PCSItxImage
from pcsi.pcsikisstx import PCSIkissTX
from pcsi.pcsidecoder import PCSIDecoder
def parseTNC(packet):
destAddress = re.search(r'>([A-Z0-9\-]+)', packet).groups()[0]
return destAddress
txImage = PCSItxImage(filename="HAB2sstv.bmp",
imageID=0,
bitDepth=12,
chromaCompression=16,
infoBytes=256,
APRSprefixBytes=True, # if we change this, we have to change the decode too
base91=True)
serialport='/tmp/kisstnc'
#serialport='/dev/ttyUSB0'
decoder = PCSIDecoder()
try:
with serial.Serial(port=serialport, bytesize=8, parity='N', stopbits = 1, timeout = 1) as ser:
# with serial.Serial(port='/dev/ttyACM0', bytesize=8, parity='N', stopbits = 1, timeout = 1) as ser:
test = PCSIkissTX(txImage,
ser,
'KD9PDP-0',
'PCSI-0',
['WIDE1-1', 'WIDE2-1'])
# test.setPersistence(.65)
#test.setSlotTime(100)
test.send(3, 30)
# print(ser.read(1000))
# test.setPersistence(.3)
# receive
# with serial.Serial(port='/dev/ttyACM0', bytesize=8, parity='N', stopbits = 1, timeout = 1) as ser:
while len(decoder.pixelsY) < 1000: # some threshold for how long to sit for
print('checking for packet')
newdata = ser.read(1000)
print(newdata)
if newdata:
decoder.processSerial(newdata)
for key in decoder.Z:
if not os.path.exists(key):
os.makedirs(key)
imageio.imwrite(key+'/raw.bmp', decoder.Z[key])
with open(key+'/pixelsY.npy', 'wb') as f:
np.save(f,decoder.pixelsY[key])
np.save(f,decoder.pixelsCbCr[key])
# test.setPersistence(.3)
except serial.SerialException:
print('failed to connect to serial port')
pass
# this stuff for testing:
#dataToSend = txImage.genPayload(0)
#
#completePacket = addressHeader + dataToSend
#kissifiedPacket = kissifyPacket(completePacket)
#print(kissifiedPacket)
#
#decoder = PCISDecoder()
#
#decoder.processSerial(kissifiedPacket)
#imageio.imwrite('testing.bmp',decoder.Z)
#
#dataToSend = txImage.genPayload(1)
#
#
#
#
#completePacket = addressHeader + dataToSend
#kissifiedPacket = kissifyPacket(completePacket)
#
#decoder.processSerial(kissifiedPacket)
#imageio.imwrite('testing2.bmp', decoder.Z)