-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendingPC.py
66 lines (47 loc) · 1.77 KB
/
sendingPC.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
import warnings
import serial
import serial.tools.list_ports
from serial import Serial
import time
import math
from constants import *
# import receive
import send
######## serial setup ######
# tx = serial.Serial(SENDINGDEVICE, BAUDRATE, timeout=1)
############################
######## data setup ######
print("___________ Reading File ___________")
# read file
inputFile = open(INPUTFILE, 'r')
fileContent = inputFile.read()
inputFile.close()
fileContent = fileContent + (" " * int(PAYLOADLENGHT * 2 / 8))
############################
######## prep for main loop #######
PACKETCOUNT = math.ceil(len(fileContent * 8) / (PAYLOADLENGHT - PARITYLENGHT) + 1)
frameIndex = 0
############################
######## main loop #######
while True:
payload = ""
##### Grab payload from file or make the header
if(frameIndex != 0):
payload = fileContent[(frameIndex - 1) * (int(PAYLOADLENGHT / 8) - int(PARITYLENGHT / 8)):(frameIndex) * (int(PAYLOADLENGHT / 8) - int(PARITYLENGHT / 8))]
else:
payload = ((8 - len(str(int(PACKETCOUNT)))) * "0") + str(PACKETCOUNT) + "HEADER__" + (PAYLOADLENGHT * "b")
##### Send the frame
send.sendFrame(payload, frameIndex)
##### Print debugging data
print("\n\n___________ Frame " + str(frameIndex) + "/" + str(PACKETCOUNT) + " ___________")
print(payload)
frameIndex = frameIndex + 1
receivedAcknowledgement = False
if(frameIndex >= PACKETCOUNT - 1):
# while(receivedAcknowledgement != True):
# received, frameCorrect, frameNumber, frame = receive.readFrame()
# if(received and frameCorrect):
# print("Acknowledgement received")
# if(frame[:4] == "YESS"):
# receivedAcknowledgement = True
frameIndex = 0