Initial commit
89
maps/bin/astc_conv.py
Normal file
@@ -0,0 +1,89 @@
|
||||
# uncompyle6 version 3.7.4
|
||||
# Python bytecode 3.7 (3394)
|
||||
# Decompiled from: Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 15 2019, 00:11:34) [MSC v.1916 64 bit (AMD64)]
|
||||
# Embedded file name: astc_conv.py
|
||||
from PIL import Image, ImageChops
|
||||
import array, tempfile, os, struct
|
||||
|
||||
def astc_dims(fmt):
|
||||
if isinstance(fmt, int):
|
||||
return astc_dims({37808:'COMPRESSED_RGBA_ASTC_4x4_KHR',
|
||||
37809:'COMPRESSED_RGBA_ASTC_5x4_KHR',
|
||||
37810:'COMPRESSED_RGBA_ASTC_5x5_KHR',
|
||||
37811:'COMPRESSED_RGBA_ASTC_6x5_KHR',
|
||||
37812:'COMPRESSED_RGBA_ASTC_6x6_KHR',
|
||||
37813:'COMPRESSED_RGBA_ASTC_8x5_KHR',
|
||||
37814:'COMPRESSED_RGBA_ASTC_8x6_KHR',
|
||||
37815:'COMPRESSED_RGBA_ASTC_8x8_KHR',
|
||||
37816:'COMPRESSED_RGBA_ASTC_10x5_KHR',
|
||||
37817:'COMPRESSED_RGBA_ASTC_10x6_KHR',
|
||||
37818:'COMPRESSED_RGBA_ASTC_10x8_KHR',
|
||||
37819:'COMPRESSED_RGBA_ASTC_10x10_KHR',
|
||||
37820:'COMPRESSED_RGBA_ASTC_12x10_KHR',
|
||||
37821:'COMPRESSED_RGBA_ASTC_12x12_KHR'}[fmt])
|
||||
dims = str(fmt).split('_')[3]
|
||||
return [int(c) for c in dims.split('x')]
|
||||
|
||||
|
||||
def tile(f):
|
||||
_, w, h, _, iw, _, ih, _, _, _ = struct.unpack('<IBBBHBHBHB', f.read(16))
|
||||
bw, bh = (iw + (w - 1)) // w, (ih + (h - 1)) // h
|
||||
d = f.read()
|
||||
return (bw, bh, tile2(d, bw, bh))
|
||||
|
||||
|
||||
def tile2(d, bw, bh):
|
||||
assert len(d) == 16 * bw * bh
|
||||
fe = [d[i:i + 16] for i in range(0, len(d), 16)]
|
||||
assert len(fe) == bw * bh
|
||||
r = []
|
||||
for j in range(0, bh - 1, 2):
|
||||
for i in range(0, bw, 2):
|
||||
if i < bw - 1:
|
||||
r += [
|
||||
fe[(bw * j + i)],
|
||||
fe[(bw * (j + 1) + i)],
|
||||
fe[(bw * (j + 1) + (i + 1))],
|
||||
fe[(bw * j + (i + 1))]]
|
||||
else:
|
||||
r += [
|
||||
fe[(bw * j + i)],
|
||||
fe[(bw * (j + 1) + i)]]
|
||||
|
||||
if bh & 1:
|
||||
r += fe[bw * (bh - 1):]
|
||||
assert len(r) == bh * bw
|
||||
return (b'').join(r)
|
||||
|
||||
|
||||
def pad(im, mult):
|
||||
w = (im.size[0] + (mult - 1)) // mult * mult
|
||||
n = Image.new('RGBA', (w, im.size[1]))
|
||||
n.paste(im, (0, 0))
|
||||
return n
|
||||
|
||||
|
||||
def round_up(n, d):
|
||||
return d * ((n + d - 1) // d)
|
||||
|
||||
|
||||
def convert(im, fmt='COMPRESSED_RGBA_ASTC_4x4_KHR', effort='thorough', astc_encode='astcenc', astc_opt=''):
|
||||
w, h = astc_dims(fmt)
|
||||
ni = Image.new('RGBA', (round_up(im.size[0], w), round_up(im.size[1], h)))
|
||||
ni.paste(im, (0, 0))
|
||||
png = tempfile.NamedTemporaryFile(delete=False)
|
||||
#ni.transpose(Image.FLIP_TOP_BOTTOM).save(png, 'png')
|
||||
ni.save(png, 'png')
|
||||
png.close()
|
||||
astc = tempfile.NamedTemporaryFile(suffix='.astc',delete=False)
|
||||
os.system('"%s" -cl %s %s %dx%d -%s -silent %s' % (astc_encode, png.name, astc.name, w, h, effort, astc_opt))
|
||||
bw, bh, d0 = tile(open(astc.name, 'rb'))
|
||||
astc.close()
|
||||
if os.path.exists(astc.name):
|
||||
os.unlink(astc.name)
|
||||
if os.path.exists(png.name):
|
||||
os.unlink(png.name)
|
||||
stride = 16 * bw
|
||||
dd = array.array('B', d0)
|
||||
return (
|
||||
stride, ni.size, dd)
|
1
maps/bin/build_image.bat
Normal file
@@ -0,0 +1 @@
|
||||
C:\Applications\Python37\python build_image.py maps.bin zulu24.bin picasso.bin
|
79
maps/bin/build_image.py
Normal file
@@ -0,0 +1,79 @@
|
||||
import json
|
||||
import msgpack
|
||||
import struct
|
||||
import sys
|
||||
import os.path
|
||||
import io
|
||||
from os import path
|
||||
|
||||
def pad(o, m):
|
||||
if m>0 :
|
||||
barray = bytearray(m)
|
||||
for i in range(0,m):
|
||||
barray[i] = 0xFF
|
||||
o.write(barray)
|
||||
return
|
||||
|
||||
|
||||
def alignFile(o, position, aligment):
|
||||
m = position % aligment
|
||||
if m>0 :
|
||||
m = aligment-m
|
||||
barray = bytearray(m)
|
||||
for i in range(0,m):
|
||||
barray[i] = 0xFF
|
||||
o.write(barray)
|
||||
return m
|
||||
|
||||
|
||||
def main():
|
||||
output = sys.argv[1]
|
||||
maps = []
|
||||
maps_meta = []
|
||||
position = 0
|
||||
with io.open(output, 'wb') as o:
|
||||
for i, arg in enumerate(sys.argv):
|
||||
if i>1:
|
||||
maps.append(arg)
|
||||
for map in maps:
|
||||
with open(map, mode='rb') as file:
|
||||
mapContent = file.read()
|
||||
with open(map+'.json') as f:
|
||||
mapMeta = json.load(f)
|
||||
mapMeta["base_address"] = position
|
||||
o.write(mapContent)
|
||||
position += len(mapContent)
|
||||
position += alignFile(o,position,4096)
|
||||
maps_meta.append(mapMeta)
|
||||
|
||||
with io.open(output+'.json', 'w') as f:
|
||||
f.write(json.dumps(maps_meta,indent=6))
|
||||
|
||||
with io.open(output+'.dat', 'wb') as f:
|
||||
cnt = len(maps_meta)
|
||||
f.write(struct.pack('<b',cnt))
|
||||
i = 0
|
||||
pos = 1+cnt*60
|
||||
for map in maps_meta:
|
||||
f.seek(pos)
|
||||
baseAddress = map['base_address']
|
||||
f.write(struct.pack('<b',len(map['tile_matrix'])))
|
||||
for zl in map['tile_matrix']:
|
||||
b = zl['bounds']
|
||||
ps = zl['pixel_size']
|
||||
ts = zl['tile_size']
|
||||
f.write(struct.pack('<H4f4f',int(zl['id']),b[0],b[1],b[2],b[3],ps[0],ps[1],ts[0],ts[1]))
|
||||
f.write(struct.pack('<H',len(zl['images'])))
|
||||
for image in zl['images']:
|
||||
s = image['size']
|
||||
b = image['bounds']
|
||||
f.write(struct.pack('<2I6H2f4f',image['address']+baseAddress,image['image_size'],s[0],s[1],image['image_stride'],image['image_fmt'],image['x'],image['y'],b[2]-b[0],b[1]-b[3],b[0],b[1],b[2],b[3]))
|
||||
endPos = f.seek(0,io.SEEK_CUR)
|
||||
|
||||
f.seek(1+i*60)
|
||||
b = map['bounds']
|
||||
f.write(struct.pack('<32s4fIII',bytes(map['name'], 'utf-8'),b[0],b[1],b[2],b[3],map['base_address'],pos,endPos-pos))
|
||||
pos = endPos
|
||||
i+=1
|
||||
|
||||
main()
|
2
maps/bin/build_map.bat
Normal file
@@ -0,0 +1,2 @@
|
||||
C:\Applications\Python37\python build_map.py ../zulu24/zulu24/ zulu24.bin
|
||||
C:\Applications\Python37\python build_map.py ../picasso/tiles/ picasso.bin
|
121
maps/bin/build_map.py
Normal file
@@ -0,0 +1,121 @@
|
||||
import json
|
||||
import sys
|
||||
import os.path
|
||||
import io
|
||||
import astc_conv
|
||||
from os import path
|
||||
from PIL import Image
|
||||
|
||||
def pad(o, m):
|
||||
if m>0 :
|
||||
barray = bytearray(m)
|
||||
for i in range(0,m):
|
||||
barray[i] = 0xFF
|
||||
o.write(barray)
|
||||
return
|
||||
|
||||
|
||||
def alignFile(o, position, aligment):
|
||||
m = position % aligment
|
||||
if m>0 :
|
||||
m = aligment-m
|
||||
barray = bytearray(m)
|
||||
for i in range(0,m):
|
||||
barray[i] = 0xFF
|
||||
o.write(barray)
|
||||
return m
|
||||
|
||||
|
||||
def loadImage(filenameBase,x,y):
|
||||
filename = filenameBase+str(x)+'/'+str(y)+'.png'
|
||||
if path.exists(filename):
|
||||
im=Image.open(filename)
|
||||
return im
|
||||
return None
|
||||
|
||||
def main():
|
||||
folder = sys.argv[1]
|
||||
output = sys.argv[2]
|
||||
print('Processing '+folder)
|
||||
tmeta = {}
|
||||
position = 0
|
||||
with open(folder+'/metadata.json') as f:
|
||||
meta = json.load(f)
|
||||
tmeta['name'] = meta['name']
|
||||
tmeta['bounds'] = [meta['extent'][0],meta['extent'][3],meta['extent'][2],meta['extent'][1]]
|
||||
tmeta['tile_matrix'] = []
|
||||
with io.open(output, 'wb') as o:
|
||||
for zl in meta['tile_matrix']:
|
||||
zitem = {}
|
||||
zitem['id'] = zl['id']
|
||||
zitem['bounds'] = [zl['origin'][0],zl['origin'][1],zl['extent'][2],zl['extent'][1]]
|
||||
zitem['images'] = []
|
||||
zitem['pixel_size'] = zl['pixel_size']
|
||||
zitem['tile_size'] = [zl['pixel_size'][0]*zl['tile_size'][0],zl['pixel_size'][1]*zl['tile_size'][1]]
|
||||
xc = zl['origin'][0]
|
||||
yc = zl['origin'][1]
|
||||
xp = zl['pixel_size'][0]
|
||||
yp = zl['pixel_size'][1]
|
||||
fmt = 37808
|
||||
hasImages = False
|
||||
if zl['matrix_size'][0]*zl['matrix_size'][1] >=8:
|
||||
fmt = 37812
|
||||
for x in range(zl['matrix_size'][0]):
|
||||
for y in range(zl['matrix_size'][1]):
|
||||
filenameBase = folder+'/'+zl['id']+'/'
|
||||
filename = filenameBase+str(x)+'/'+str(y)+'.png'
|
||||
if path.exists(filename):
|
||||
im=Image.open(filename)
|
||||
expand = 1
|
||||
nim = Image.new('RGBA',(im.size[0]+expand*2,im.size[1]+expand*2))
|
||||
nim.putalpha(0)
|
||||
nim.paste(im,(expand,expand))
|
||||
|
||||
pim = loadImage(filenameBase,x,y-1)
|
||||
if pim!=None:
|
||||
nim.paste(pim.crop((0,pim.size[1]-expand,pim.size[0],pim.size[1])),(expand,0))
|
||||
|
||||
pim = loadImage(filenameBase,x,y+1)
|
||||
if pim!=None:
|
||||
nim.paste(pim.crop((0,0,pim.size[0],expand)),(expand,nim.size[1]-expand))
|
||||
|
||||
pim = loadImage(filenameBase,x-1,y)
|
||||
if pim!=None:
|
||||
nim.paste(pim.crop((pim.size[0]-expand,0,pim.size[0],pim.size[1])),(0,expand))
|
||||
|
||||
pim = loadImage(filenameBase,x+1,y)
|
||||
if pim!=None:
|
||||
nim.paste(pim.crop((0,0,expand,pim.size[1])),(nim.size[0]-expand,expand))
|
||||
|
||||
rsize = im.size
|
||||
im = nim
|
||||
stride,asize,astc = astc_conv.convert(im,fmt)
|
||||
if len(astc)>0:
|
||||
hasImages = True
|
||||
fileinfo = {}
|
||||
fileinfo['size'] = im.size
|
||||
fileinfo['bounds'] = [xc+x*rsize[0]*xp-xp*expand,yc+y*rsize[1]*yp-yp*expand,xc+(x+1)*rsize[0]*xp+xp*expand,yc+(y+1)*rsize[1]*yp+yp*expand]
|
||||
fileinfo['x'] = x
|
||||
fileinfo['y'] = y
|
||||
fileinfo['address'] = position
|
||||
fileinfo['image_stride'] = stride
|
||||
fileinfo['image_size'] = len(astc)
|
||||
fileinfo['image_fmt'] = fmt
|
||||
o.write(astc)
|
||||
with open(filename+'.bin','wb') as f:
|
||||
f.write(astc)
|
||||
position += len(astc)
|
||||
pad(o,64)
|
||||
position += 64
|
||||
position += alignFile(o,position,64)
|
||||
zitem['images'].append(fileinfo)
|
||||
if hasImages==True:
|
||||
tmeta['tile_matrix'].append(zitem)
|
||||
alignFile(o,position,4096)
|
||||
with io.open(output+'.json', 'w', encoding='utf-8') as f:
|
||||
f.write(json.dumps(tmeta, indent=4))
|
||||
|
||||
|
||||
|
||||
|
||||
main()
|
36
maps/bin/calc_tiles.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import json
|
||||
import sys
|
||||
import os.path
|
||||
import io
|
||||
from os import path
|
||||
from PIL import Image
|
||||
|
||||
def main():
|
||||
folder = sys.argv[1]
|
||||
print('Processing '+folder)
|
||||
with open(folder+'/metadata.json') as f:
|
||||
meta = json.load(f)
|
||||
for zl in meta['tile_matrix']:
|
||||
xc = zl['origin'][0]
|
||||
yc = zl['origin'][1]
|
||||
xp = zl['pixel_size'][0]
|
||||
yp = zl['pixel_size'][1]
|
||||
for x in range(zl['matrix_size'][0]):
|
||||
yc = zl['origin'][1]
|
||||
for y in range(zl['matrix_size'][1]):
|
||||
filename = folder+'/'+zl['id']+'/'+str(x)+'/'+str(y)+'.png'
|
||||
if path.exists(filename):
|
||||
fileprops = {}
|
||||
im=Image.open(filename)
|
||||
fileprops['size'] = im.size
|
||||
fileprops['bounds'] = [xc,yc,xc+im.size[0]*xp,yc+im.size[1]*yp]
|
||||
xn = xc + im.size[0]*xp
|
||||
yc = yc + im.size[1]*yp
|
||||
with io.open(filename+'.json', 'w', encoding='utf-8') as f:
|
||||
f.write(json.dumps(fileprops, ensure_ascii=False))
|
||||
xc = xn
|
||||
|
||||
|
||||
|
||||
|
||||
main()
|
338
maps/bin/map_image_tool.py
Normal file
@@ -0,0 +1,338 @@
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
import os.path
|
||||
import io
|
||||
from os import path
|
||||
import serial
|
||||
import time
|
||||
import struct
|
||||
import ntpath
|
||||
|
||||
show_r = False
|
||||
PMC_SCREEN_FLASH_START = 1
|
||||
PMC_SCREEN_FLASH_START_RESPONSE=2
|
||||
PMC_SCREEN_FLASH_END =3
|
||||
PMC_SCREEN_FLASH_WRITE =4
|
||||
PMC_SCREEN_FLASH_WRITE_COMPRESSED =14
|
||||
PMC_SCREEN_FLASH_READ =5
|
||||
PMC_SCREEN_FLASH_READ_RESPONSE =6
|
||||
PMC_SCREEN_FLASH_META_START =7
|
||||
PMC_SCREEN_FLASH_META_DATA =8
|
||||
PMC_SCREEN_FLASH_META_END =9
|
||||
PMC_SCREEN_FLASH_FILE_START =10
|
||||
PMC_SCREEN_FLASH_FILE_DATA =11
|
||||
PMC_SCREEN_FLASH_FILE_END =12
|
||||
|
||||
PMC_SCREEN_FLASH_EXIT =99
|
||||
PMC_SCREEN_FLASH_ACK =100
|
||||
PMC_SCREEN_FLASH_ERR =101
|
||||
SERIAL_APP_1=0x85
|
||||
SERIAL_APP_2=0x3B
|
||||
SERIAL_APP_3=0xDE
|
||||
SERIAL_APP_4=0x02
|
||||
|
||||
def csum(dd,extra):
|
||||
result = extra & 0xFF
|
||||
for b in dd:
|
||||
result ^= (b & 0xFF)
|
||||
return result
|
||||
|
||||
def readPacket(ser,timeout=2):
|
||||
global show_r
|
||||
packet = bytearray([])
|
||||
readState = 0
|
||||
size = 0
|
||||
startTime = time.time()
|
||||
while True:
|
||||
if ser.inWaiting()>0:
|
||||
b = ser.read(1)[0]
|
||||
if(show_r==True):
|
||||
print(hex(b), end ="", flush=True)
|
||||
#print(bytearray([b]).decode('ascii'), end ="", flush=True)
|
||||
if readState==0:
|
||||
if b==SERIAL_APP_1:
|
||||
readState = 1
|
||||
elif readState==1:
|
||||
if b==SERIAL_APP_2:
|
||||
readState = 2
|
||||
else:
|
||||
readState = 0
|
||||
elif readState==2:
|
||||
if b==SERIAL_APP_3:
|
||||
readState = 3
|
||||
else:
|
||||
readState = 0
|
||||
elif readState==3:
|
||||
if b==SERIAL_APP_4:
|
||||
readState = 4
|
||||
else:
|
||||
readState = 0
|
||||
elif readState==4:
|
||||
size = b
|
||||
readState = 5
|
||||
elif readState==5:
|
||||
size = size + (b<<8)
|
||||
if size<8192:
|
||||
readState = 6
|
||||
else:
|
||||
readState = 0
|
||||
elif readState==6:
|
||||
if len(packet)<(size-1):
|
||||
packet.extend([b])
|
||||
else:
|
||||
cs = csum(packet,0)
|
||||
if b==cs:
|
||||
return packet
|
||||
else:
|
||||
print('BAD CS '+hex(cs)+' '+hex(b)+' '+packet.hex())
|
||||
return bytearray([])
|
||||
else:
|
||||
time.sleep(0.001)
|
||||
if(time.time()-startTime)>=timeout:
|
||||
print('Timeout')
|
||||
#show_r = True
|
||||
return bytearray([])
|
||||
|
||||
return bytearray([])
|
||||
|
||||
def createSerialPacket(cmd,dd):
|
||||
result = bytearray([SERIAL_APP_1,SERIAL_APP_2,SERIAL_APP_3,SERIAL_APP_4])
|
||||
s = len(dd)+2
|
||||
result.extend([s & 0xFF,(s>>8) & 0xFF,cmd])
|
||||
result.extend(dd)
|
||||
result.extend([csum(dd,cmd)])
|
||||
#print(result.hex())
|
||||
return result
|
||||
|
||||
|
||||
def writeImage(ser,imagedata,metadata):
|
||||
print("Writing image...")
|
||||
ser.write(createSerialPacket(PMC_SCREEN_FLASH_START,bytearray([])))
|
||||
packet = readPacket(ser)
|
||||
if len(packet)>0:
|
||||
if packet[0]==PMC_SCREEN_FLASH_START_RESPONSE:
|
||||
s = struct.Struct('<BI')
|
||||
resp = s.unpack(packet)
|
||||
print("Start flash result "+str(resp[1]))
|
||||
if resp[1]==0:
|
||||
print("Writing flash")
|
||||
cnt = int(len(imagedata)/4096)
|
||||
sector = bytearray(4096+6)
|
||||
sector[0] = 00
|
||||
sector[1] = 0x10
|
||||
for i in range(cnt):
|
||||
for j in range(4096):
|
||||
if(j%2==0):
|
||||
sector[j+6] = imagedata[i*4096+j] ^ 0xAA
|
||||
else:
|
||||
sector[j+6] = imagedata[i*4096+j] ^ 0x55
|
||||
address = 4096+i*4096
|
||||
sector[2] = address & 0xFF
|
||||
sector[3] = (address >> 8) & 0xFF
|
||||
sector[4] = (address >> 16) & 0xFF
|
||||
sector[5] = (address >> 24) & 0xFF
|
||||
while 1:
|
||||
print("Sector "+str(cnt)+"/"+str(i)+".", end ="", flush=True)
|
||||
packet = createSerialPacket(PMC_SCREEN_FLASH_WRITE_COMPRESSED,sector)
|
||||
spackets = [packet[i:i+1512] for i in range(0, len(packet), 1512)]
|
||||
#spackets = [packet[i:i+32] for i in range(0, len(packet), 32)]
|
||||
for p in spackets:
|
||||
ser.write(p)
|
||||
ser.flush()
|
||||
time.sleep(0.0001)
|
||||
packet = readPacket(ser)
|
||||
if len(packet)>0:
|
||||
if packet[0]!=PMC_SCREEN_FLASH_ACK:
|
||||
print("ERR "+hex(packet[1]))
|
||||
else:
|
||||
print("OK")
|
||||
break
|
||||
time.sleep(0.02)
|
||||
ser.write(createSerialPacket(PMC_SCREEN_FLASH_END,bytearray([])))
|
||||
readPacket(ser)
|
||||
else:
|
||||
print("Error")
|
||||
print("Writing meta...")
|
||||
ser.write(createSerialPacket(PMC_SCREEN_FLASH_META_START,bytearray([])))
|
||||
packet = readPacket(ser)
|
||||
if len(packet)>0:
|
||||
if packet[0]==PMC_SCREEN_FLASH_ACK:
|
||||
|
||||
cnt = len(metadata)
|
||||
i = 0
|
||||
while cnt>0:
|
||||
if cnt>512:
|
||||
s = 512
|
||||
else:
|
||||
s = cnt
|
||||
cnt -= s
|
||||
sector = metadata[i:(i+s)]
|
||||
while 1:
|
||||
print("Sector "+str(i)+".", end ="", flush=True)
|
||||
packet = createSerialPacket(PMC_SCREEN_FLASH_META_DATA,sector)
|
||||
ser.write(packet)
|
||||
ser.flush()
|
||||
packet = readPacket(ser)
|
||||
if len(packet)>0:
|
||||
if packet[0]!=PMC_SCREEN_FLASH_ACK:
|
||||
print("ERR")
|
||||
else:
|
||||
print("OK")
|
||||
break
|
||||
time.sleep(0.01)
|
||||
i += s
|
||||
ser.write(createSerialPacket(PMC_SCREEN_FLASH_META_END,bytearray([])))
|
||||
packet = readPacket(ser)
|
||||
else:
|
||||
print("Error")
|
||||
|
||||
print("Done.")
|
||||
return
|
||||
|
||||
def writeFile(ser,imagedata,filename):
|
||||
print("Writing file...")
|
||||
ser.write(createSerialPacket(PMC_SCREEN_FLASH_FILE_START,bytearray(filename.encode())+ b'\x00'))
|
||||
packet = readPacket(ser)
|
||||
if len(packet)>0:
|
||||
if packet[0]==PMC_SCREEN_FLASH_ACK:
|
||||
|
||||
cnt = len(imagedata)
|
||||
i = 0
|
||||
while cnt>0:
|
||||
if cnt>512:
|
||||
s = 512
|
||||
else:
|
||||
s = cnt
|
||||
cnt -= s
|
||||
sector = imagedata[i:(i+s)]
|
||||
while 1:
|
||||
print("Sector "+str(i)+".", end ="", flush=True)
|
||||
packet = createSerialPacket(PMC_SCREEN_FLASH_FILE_DATA,sector)
|
||||
ser.write(packet)
|
||||
ser.flush()
|
||||
packet = readPacket(ser)
|
||||
if len(packet)>0:
|
||||
if packet[0]!=PMC_SCREEN_FLASH_ACK:
|
||||
print("ERR")
|
||||
else:
|
||||
print("OK")
|
||||
break
|
||||
time.sleep(0.01)
|
||||
i += s
|
||||
ser.write(createSerialPacket(PMC_SCREEN_FLASH_FILE_END,bytearray([])))
|
||||
packet = readPacket(ser)
|
||||
else:
|
||||
print("Error")
|
||||
|
||||
print("Done.")
|
||||
return
|
||||
|
||||
def readImage(ser,size):
|
||||
print("Reading image...")
|
||||
result = bytearray([])
|
||||
ser.write(createSerialPacket(PMC_SCREEN_FLASH_START,bytearray([])))
|
||||
packet = readPacket(ser)
|
||||
if len(packet)>0:
|
||||
if packet[0]==PMC_SCREEN_FLASH_START_RESPONSE:
|
||||
s = struct.Struct('<BI')
|
||||
resp = s.unpack(packet)
|
||||
print("Start flash result "+str(resp[1]))
|
||||
if resp[1]==0:
|
||||
print("Reading flash")
|
||||
cnt = int(size*1024/4096)
|
||||
sector = bytearray(6)
|
||||
sector[0] = 00
|
||||
sector[1] = 0x10
|
||||
for i in range(cnt):
|
||||
address = 4096+i*4096
|
||||
sector[2] = address & 0xFF
|
||||
sector[3] = (address >> 8) & 0xFF
|
||||
sector[4] = (address >> 16) & 0xFF
|
||||
sector[5] = (address >> 24) & 0xFF
|
||||
while 1:
|
||||
print("Sector "+str(i)+".", end ="", flush=True)
|
||||
packet = createSerialPacket(PMC_SCREEN_FLASH_READ,sector)
|
||||
ser.write(packet)
|
||||
packet = readPacket(ser)
|
||||
if len(packet)>0:
|
||||
if packet[0]!=PMC_SCREEN_FLASH_READ_RESPONSE:
|
||||
print("ERR")
|
||||
else:
|
||||
print("OK")
|
||||
result.extend(packet[1:])
|
||||
break
|
||||
ser.write(createSerialPacket(PMC_SCREEN_FLASH_END,bytearray([])))
|
||||
else:
|
||||
print("Error")
|
||||
print("Done.")
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Airsoft Tracker Maps Image Tool')
|
||||
parser.add_argument('image', help='Image file name')
|
||||
parser.add_argument('-c','--comm', required=False, help='COM port')
|
||||
parser.add_argument('-r','--read',action='store_true', help='Read image')
|
||||
parser.add_argument('-s','--size',type=int, default=16*1024, help='Read size in KB')
|
||||
parser.add_argument('-w','--wfile',action='store_true', help='Write file')
|
||||
args = parser.parse_args()
|
||||
comm = args.comm
|
||||
if not comm:
|
||||
print("Looking for COM port")
|
||||
import serial.tools.list_ports as list_ports
|
||||
for each_port in reversed(sorted(list_ports.comports())):
|
||||
if each_port[1].find("Silicon Labs")>=0:
|
||||
comm = each_port[0]
|
||||
print("Comm port found "+comm)
|
||||
break
|
||||
|
||||
imagefile = args.image
|
||||
readSize = args.size
|
||||
ser = serial.Serial(comm,baudrate=115200)
|
||||
ser.set_buffer_size(rx_size = 8192, tx_size=256)
|
||||
|
||||
print("Connecting", end ="", flush=True)
|
||||
while True:
|
||||
if ser.inWaiting()>0:
|
||||
ser.read(ser.inWaiting())
|
||||
print(".", end ="", flush=True)
|
||||
values = bytearray([0x92,0x5A])
|
||||
ser.write(values)
|
||||
startTime = time.time()
|
||||
while (time.time()-startTime)<2:
|
||||
if ser.inWaiting()>0:
|
||||
b = ser.read(1)[0]
|
||||
#print(bytearray([b]).decode('ascii'), end ="", flush=True)
|
||||
if b==0x07:
|
||||
print("")
|
||||
print("Connected")
|
||||
time.sleep(0.01)
|
||||
values = bytearray([0x07])
|
||||
ser.write(values)
|
||||
ser.baudrate = 921600
|
||||
time.sleep(1)
|
||||
|
||||
if args.read==True:
|
||||
imagedata = readImage(ser,readSize)
|
||||
with open(imagefile,"wb") as f:
|
||||
f.write(imagedata)
|
||||
else:
|
||||
if args.wfile==True:
|
||||
with open(imagefile,"rb") as f:
|
||||
imagedata = f.read()
|
||||
writeFile(ser,imagedata,ntpath.basename(imagefile))
|
||||
else:
|
||||
with open(imagefile,"rb") as f:
|
||||
imagedata = f.read()
|
||||
with open(imagefile+'.dat',"rb") as f:
|
||||
metadata = f.read()
|
||||
writeImage(ser,imagedata,metadata)
|
||||
|
||||
ser.write(createSerialPacket(PMC_SCREEN_FLASH_EXIT,bytearray([])))
|
||||
return
|
||||
else:
|
||||
time.sleep(0.01)
|
||||
|
||||
|
||||
main()
|
2948
maps/bin/maps.bin.json
Normal file
1832
maps/bin/picasso.bin.json
Normal file
1
maps/bin/read_image.bat
Normal file
@@ -0,0 +1 @@
|
||||
C:\Applications\Python37\python map_image_tool.py -c COM22 maps_old.bin -r -s 1024
|
1
maps/bin/write_image.bat
Normal file
@@ -0,0 +1 @@
|
||||
C:\Applications\Python37\python map_image_tool.py maps.bin
|
2
maps/bin/write_points.bat
Normal file
@@ -0,0 +1,2 @@
|
||||
C:\Applications\Python37\python map_image_tool.py ../zulu24/p_zulu24.json -w
|
||||
C:\Applications\Python37\python map_image_tool.py ../picasso/p_picasso.json -w
|
1112
maps/bin/zulu24.bin.json
Normal file
13
maps/picasso/p_picasso.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"points": [
|
||||
{ "type": 0, "color": 16776960, "name": "Office", "coordinates": [ -74.91830945685942,39.73604280105904 ] },
|
||||
{ "type": 0, "color": 16776960, "name": "Beach", "coordinates": [ -74.91917130906181,39.73630893810271 ] },
|
||||
{ "type": 0, "color": 16776960, "name": "Kill Box", "coordinates": [ -74.91902077980406,39.7355752412219 ] },
|
||||
{ "type": 0, "color": 16776960, "name": "Zero", "coordinates": [ -74.9189932630288,39.73718782439224 ] },
|
||||
{ "type": 0, "color": 16776960, "name": "Ridge", "coordinates": [ -74.91831533834912,39.73829361377636 ] },
|
||||
{ "type": 0, "color": 16776960, "name": "Calypso", "coordinates": [ -74.91990159096781,39.73872089766842 ] },
|
||||
{ "type": 0, "color": 16776960, "name": "Maze", "coordinates": [ -74.91634869800787,39.73697446559213 ] },
|
||||
{ "type": 0, "color": 16776960, "name": "Congo", "coordinates": [ -74.91602222829101,39.73763561652714 ] },
|
||||
{ "type": 0, "color": 16776960, "name": "Trenches", "coordinates": [ -74.91581248157634,39.73862186136292 ] }
|
||||
]
|
||||
}
|
BIN
maps/picasso/picasso.tif
Normal file
32
maps/picasso/picasso.tif.aux.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<PAMDataset>
|
||||
<PAMRasterBand band="1">
|
||||
<Metadata>
|
||||
<MDI key="STATISTICS_APPROXIMATE">YES</MDI>
|
||||
<MDI key="STATISTICS_MAXIMUM">255</MDI>
|
||||
<MDI key="STATISTICS_MEAN">37.088994056078</MDI>
|
||||
<MDI key="STATISTICS_MINIMUM">0</MDI>
|
||||
<MDI key="STATISTICS_STDDEV">23.597758036199</MDI>
|
||||
<MDI key="STATISTICS_VALID_PERCENT">100</MDI>
|
||||
</Metadata>
|
||||
</PAMRasterBand>
|
||||
<PAMRasterBand band="2">
|
||||
<Metadata>
|
||||
<MDI key="STATISTICS_APPROXIMATE">YES</MDI>
|
||||
<MDI key="STATISTICS_MAXIMUM">255</MDI>
|
||||
<MDI key="STATISTICS_MEAN">38.660669983202</MDI>
|
||||
<MDI key="STATISTICS_MINIMUM">0</MDI>
|
||||
<MDI key="STATISTICS_STDDEV">22.602363004851</MDI>
|
||||
<MDI key="STATISTICS_VALID_PERCENT">100</MDI>
|
||||
</Metadata>
|
||||
</PAMRasterBand>
|
||||
<PAMRasterBand band="3">
|
||||
<Metadata>
|
||||
<MDI key="STATISTICS_APPROXIMATE">YES</MDI>
|
||||
<MDI key="STATISTICS_MAXIMUM">255</MDI>
|
||||
<MDI key="STATISTICS_MEAN">28.796404574234</MDI>
|
||||
<MDI key="STATISTICS_MINIMUM">0</MDI>
|
||||
<MDI key="STATISTICS_STDDEV">19.640798405489</MDI>
|
||||
<MDI key="STATISTICS_VALID_PERCENT">100</MDI>
|
||||
</Metadata>
|
||||
</PAMRasterBand>
|
||||
</PAMDataset>
|
BIN
maps/picasso/tiles/1/0/0.png
Normal file
After Width: | Height: | Size: 106 KiB |
BIN
maps/picasso/tiles/1/0/0.png.bin
Normal file
BIN
maps/picasso/tiles/1/0/1.png
Normal file
After Width: | Height: | Size: 108 KiB |
BIN
maps/picasso/tiles/1/0/1.png.bin
Normal file
BIN
maps/picasso/tiles/1/0/2.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
maps/picasso/tiles/1/0/2.png.bin
Normal file
BIN
maps/picasso/tiles/1/1/0.png
Normal file
After Width: | Height: | Size: 92 KiB |
BIN
maps/picasso/tiles/1/1/0.png.bin
Normal file
BIN
maps/picasso/tiles/1/1/1.png
Normal file
After Width: | Height: | Size: 93 KiB |
BIN
maps/picasso/tiles/1/1/1.png.bin
Normal file
BIN
maps/picasso/tiles/1/1/2.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
maps/picasso/tiles/1/1/2.png.bin
Normal file
BIN
maps/picasso/tiles/2/0/0.png
Normal file
After Width: | Height: | Size: 109 KiB |
BIN
maps/picasso/tiles/2/0/0.png.bin
Normal file
BIN
maps/picasso/tiles/2/0/1.png
Normal file
After Width: | Height: | Size: 109 KiB |
BIN
maps/picasso/tiles/2/0/1.png.bin
Normal file
BIN
maps/picasso/tiles/2/0/2.png
Normal file
After Width: | Height: | Size: 113 KiB |
BIN
maps/picasso/tiles/2/0/2.png.bin
Normal file
BIN
maps/picasso/tiles/2/0/3.png
Normal file
After Width: | Height: | Size: 113 KiB |
BIN
maps/picasso/tiles/2/0/3.png.bin
Normal file
BIN
maps/picasso/tiles/2/0/4.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
maps/picasso/tiles/2/0/4.png.bin
Normal file
BIN
maps/picasso/tiles/2/1/0.png
Normal file
After Width: | Height: | Size: 106 KiB |
BIN
maps/picasso/tiles/2/1/0.png.bin
Normal file
BIN
maps/picasso/tiles/2/1/1.png
Normal file
After Width: | Height: | Size: 100 KiB |
BIN
maps/picasso/tiles/2/1/1.png.bin
Normal file
BIN
maps/picasso/tiles/2/1/2.png
Normal file
After Width: | Height: | Size: 100 KiB |
BIN
maps/picasso/tiles/2/1/2.png.bin
Normal file
BIN
maps/picasso/tiles/2/1/3.png
Normal file
After Width: | Height: | Size: 112 KiB |
BIN
maps/picasso/tiles/2/1/3.png.bin
Normal file
BIN
maps/picasso/tiles/2/1/4.png
Normal file
After Width: | Height: | Size: 8.1 KiB |
BIN
maps/picasso/tiles/2/1/4.png.bin
Normal file
BIN
maps/picasso/tiles/2/2/0.png
Normal file
After Width: | Height: | Size: 112 KiB |
BIN
maps/picasso/tiles/2/2/0.png.bin
Normal file
BIN
maps/picasso/tiles/2/2/1.png
Normal file
After Width: | Height: | Size: 115 KiB |
BIN
maps/picasso/tiles/2/2/1.png.bin
Normal file
BIN
maps/picasso/tiles/2/2/2.png
Normal file
After Width: | Height: | Size: 113 KiB |
BIN
maps/picasso/tiles/2/2/2.png.bin
Normal file
BIN
maps/picasso/tiles/2/2/3.png
Normal file
After Width: | Height: | Size: 114 KiB |
BIN
maps/picasso/tiles/2/2/3.png.bin
Normal file
BIN
maps/picasso/tiles/2/2/4.png
Normal file
After Width: | Height: | Size: 8.1 KiB |
BIN
maps/picasso/tiles/2/2/4.png.bin
Normal file
BIN
maps/picasso/tiles/2/3/0.png
Normal file
After Width: | Height: | Size: 75 KiB |
BIN
maps/picasso/tiles/2/3/0.png.bin
Normal file
BIN
maps/picasso/tiles/2/3/1.png
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
maps/picasso/tiles/2/3/1.png.bin
Normal file
BIN
maps/picasso/tiles/2/3/2.png
Normal file
After Width: | Height: | Size: 77 KiB |
BIN
maps/picasso/tiles/2/3/2.png.bin
Normal file
BIN
maps/picasso/tiles/2/3/3.png
Normal file
After Width: | Height: | Size: 77 KiB |
BIN
maps/picasso/tiles/2/3/3.png.bin
Normal file
BIN
maps/picasso/tiles/2/3/4.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
maps/picasso/tiles/2/3/4.png.bin
Normal file
BIN
maps/picasso/tiles/3/0/0.png
Normal file
After Width: | Height: | Size: 108 KiB |
BIN
maps/picasso/tiles/3/0/0.png.bin
Normal file
BIN
maps/picasso/tiles/3/0/1.png
Normal file
After Width: | Height: | Size: 104 KiB |
BIN
maps/picasso/tiles/3/0/1.png.bin
Normal file
BIN
maps/picasso/tiles/3/0/2.png
Normal file
After Width: | Height: | Size: 102 KiB |
BIN
maps/picasso/tiles/3/0/2.png.bin
Normal file
BIN
maps/picasso/tiles/3/0/3.png
Normal file
After Width: | Height: | Size: 104 KiB |
BIN
maps/picasso/tiles/3/0/3.png.bin
Normal file
BIN
maps/picasso/tiles/3/0/4.png
Normal file
After Width: | Height: | Size: 113 KiB |
BIN
maps/picasso/tiles/3/0/4.png.bin
Normal file
BIN
maps/picasso/tiles/3/0/5.png
Normal file
After Width: | Height: | Size: 111 KiB |
BIN
maps/picasso/tiles/3/0/5.png.bin
Normal file
BIN
maps/picasso/tiles/3/0/6.png
Normal file
After Width: | Height: | Size: 109 KiB |
BIN
maps/picasso/tiles/3/0/6.png.bin
Normal file
BIN
maps/picasso/tiles/3/0/7.png
Normal file
After Width: | Height: | Size: 110 KiB |
BIN
maps/picasso/tiles/3/0/7.png.bin
Normal file
BIN
maps/picasso/tiles/3/0/8.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
maps/picasso/tiles/3/0/8.png.bin
Normal file
BIN
maps/picasso/tiles/3/1/0.png
Normal file
After Width: | Height: | Size: 102 KiB |
BIN
maps/picasso/tiles/3/1/0.png.bin
Normal file
BIN
maps/picasso/tiles/3/1/1.png
Normal file
After Width: | Height: | Size: 99 KiB |
BIN
maps/picasso/tiles/3/1/1.png.bin
Normal file
BIN
maps/picasso/tiles/3/1/2.png
Normal file
After Width: | Height: | Size: 102 KiB |
BIN
maps/picasso/tiles/3/1/2.png.bin
Normal file
BIN
maps/picasso/tiles/3/1/3.png
Normal file
After Width: | Height: | Size: 112 KiB |
BIN
maps/picasso/tiles/3/1/3.png.bin
Normal file
BIN
maps/picasso/tiles/3/1/4.png
Normal file
After Width: | Height: | Size: 108 KiB |
BIN
maps/picasso/tiles/3/1/4.png.bin
Normal file
BIN
maps/picasso/tiles/3/1/5.png
Normal file
After Width: | Height: | Size: 110 KiB |
BIN
maps/picasso/tiles/3/1/5.png.bin
Normal file
BIN
maps/picasso/tiles/3/1/6.png
Normal file
After Width: | Height: | Size: 107 KiB |