This commit is contained in:
ABelliqueux 2021-05-16 16:13:35 +02:00
parent 7bf316c9f9
commit 362bdb244b
1 changed files with 136 additions and 103 deletions

View File

@ -44,9 +44,9 @@ LOAD = '06'
OPEN = '00'
loadParams = {'memAddr':-1,'flagAddr':-1, 'loadFile':-1}
loadParams = {'memAddr':-1,'bufferAddr':-1, 'loadFile':-1}
openParams = {'fileName':-1,'mode':-1}
openParams = {'fileName':-1,'bufferAddr':-1,'mode':-1}
paramBuffer = {}
@ -85,15 +85,13 @@ loadFile = -1
# One byte
#uno = int(1).to_bytes(1, byteorder='little', signed=False)
data = 0
# checkSum is the checkSum for the full data
checkSum = 0
checkSumLen = 9 # Corresponding value in pcdrv.h, l.54
checkSumLen = 10 # Corresponding value in pcdrv.h, l.54
# If set, it means the data transfer has been initiated
@ -245,11 +243,7 @@ def getData(dataInBuffer):
return [dataInBuffer, parsedData] # does it break ?
dataLen = dataInBuffer[:2]
# We're receiving 8 chars to describe a 4 bytes pointer, hence the * 2
dataLen = int(dataLen) * 2
dataLen = int( dataInBuffer[:2] )
dataInBuffer = dataInBuffer[2:]
@ -555,9 +549,9 @@ def main(args):
print( "Incoming data : " + inputBuffer )
# We're expecting the command with format : 00 01 06 04 xx xx xx xx 04 xx xx xx xx 01 xx xx xx xx xx (38 Bytes)
# LOAD command format : 00 01 06 04 xx xx xx xx 04 xx xx xx xx 01 xx xx xx xx (37 Bytes)
if len(inputBuffer) == 37:
# ~ if len(inputBuffer) == 37:
if DEBUG:
@ -567,13 +561,20 @@ def main(args):
CmdCheckSum = inputBuffer[-checkSumLen:]
if CmdCheckSum.islower() or CmdCheckSum.isupper() :
print("Checksum sould not contain letters ! Aborting.")
break
if DEBUG:
print( "Received ChkSm: " + CmdCheckSum )
print( "Received ChkSm: " + CmdCheckSum)
# Remove checksum from data
inputBuffer = inputBuffer[:28]
# ~ inputBuffer = inputBuffer[:28]
inputBuffer = inputBuffer[:-checkSumLen]
dataCheckSum = hash_djb2(bytes(inputBuffer, 'ascii'))
@ -674,13 +675,13 @@ def main(args):
break
else:
# ~ else:
ser.reset_input_buffer()
# ~ ser.reset_input_buffer()
inputBuffer = ""
# ~ inputBuffer = ""
break
# ~ break
if len(paramBuffer):
@ -698,7 +699,7 @@ def main(args):
if DEBUG > 1:
print("Received addresses and file ID : " + paramBuffer['memAddr'] + " - " + paramBuffer['flagAddr'] + " - " + paramBuffer['loadFile'] )
print("Received addresses and file ID : " + paramBuffer['memAddr'] + " - " + paramBuffer['bufferAddr'] + " - " + paramBuffer['loadFile'] )
binFileName = overlayFiles[ paramBuffer['loadFile'] ]
@ -708,7 +709,7 @@ def main(args):
"Load Data to : " + paramBuffer['memAddr'] + "\n" +
"Reset flag at: " + paramBuffer['flagAddr'] + "\n" +
"Reset flag at: " + paramBuffer['bufferAddr'] + "\n" +
"LoadFile : " + paramBuffer['loadFile'] + "\n" +
@ -740,7 +741,7 @@ def main(args):
# Send ACK
SendBin( b'OKYA' , paramBuffer['flagAddr'])
SendBin( b'OKYA' , paramBuffer['bufferAddr'])
# Reset everything
@ -756,7 +757,39 @@ def main(args):
if Command == OPEN:
print("Received OPEN. Not yet implemented !")
print("Received OPEN.")
# paramBuffer['mode'] can be 0 (RO), 1(WO), 2 (RW)
osMode = os.O_RDONLY
if int(paramBuffer['mode']) == 1:
osMode = os.O_WRONLY
else:
osMode = os.O_RDWR
if os.path.isfile( 'work/' + paramBuffer['fileName']):
localFile = os.open( 'work/' + paramBuffer['fileName'], osMode )
SendBin( b'DT' + bytes( str(localFile), 'ascii' ), paramBuffer['bufferAddr'])
# ~ time.sleep( sleepTime )
# ~ SendBin( bytes( str(localFile), 'ascii' ), paramBuffer['bufferAddr'])
else:
SendBin( b'-1', paramBuffer['bufferAddr'])
resetListener()
print("DONE!")
# ~ break
return 0