Sending binaries

Note: This page is a work in progress.  I'm still researching this.  So far, I've identified two ways to transfer a binary file using the sh shell of the TV.  Yes apart from the obvious "stick it on a USB and plug that in" method, I need something more instant.

Step 1: Enter debug mode debug <enter> d

Step 2: Drop to a shell with sh from the debug menu

Step 3: Make yourself a Base64 decoder utility (note: this is an excerpt from my bash script that sends this directly to the serial port.  You can stip off the first/last lines if you are in a terminal program, but also change "\\\$0" to "\$0"!

cat >> /dev/ttyUSB0 << EOL

cat > /tmp/ud.awk << EOL

function ba(v,x){r=0;for(li=128;li>=1;li/=2){z=0;if(v>=li){z++;v-=li}if(x>=li){z++;x-=li};if(z>1)r+=li;}return r;}

function ls(v,x){for(;x>0;x--)v*=2;return v;}

function rs(v,x){for(;x>0;x--)v=int(v/2);return v;}

BEGIN{c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";}

{l=\\\$0;for(a=1;a<=length(l);a+=4){

d=index(c,substr(l,a,1))-1;e=index(c,substr(l,a+1,1))-1;f=index(c,substr(l,a+2,1))-1;g=index(c,substr(l,a+3,1))-1;

b=3;if(d<0)d=0;if(e<0)e=0;if(f<0){f=0;b--;}if(g<0){g=0;b--;}

printf("%c",ls(ba(d,63),2)+rs(ba(e,48),4))>"out";

if(b>1)printf("%c",ls(ba(e,15),4)+rs(ba(f,60),2))>"out";

if(b>2)printf("%c",ls(ba(f,3),6)+g)>"out"}}

EOL

echo EOL >> /dev/ttyUSB0

Note: This is a cleaned up and shortened version of a script found here http://www.turtle.dds.nl/b64dec.awk -- I changed it to work off of stdin and also shortened variable names and a few other things here and there. Many thanks to Peter van Eerten for the original!

Step 4: Use base64 (or whatever you want really) to encode a file to the right format.  I recommend you compress it first with gzip or zip (the LG seems to 

have gunzip and unzip locally available)  Even for images this might make a lot of sense to use gzip for integrity checking.

Step 5: Either stream your data directly or cat it to a temp file (same EOL method as above) and then decode it

awk -f /tmp/uk.awk < myFile

You now have a binary fully intact transferred over the TTY shell stored in "/tmp/out".

OPTION 2: Use zmodem transfer

First off, many thanks to ox1001 for a lightning port of lrz.  See attachments below for the binary.  (The binary is for Saturn7 -- Sorry Saturn6 or BCM people)

Send the binary over to the TV

Method 1: Use the steps above -- may or may not work (I've had trouble with files > 4kb and I don't quite know why)

Method 2: Put it on a usb stick and stick that in the side of the TV.  Look @ /mnt/usb1/Drive1 for your file

Method 3: Include it in a build of the LGMOD filesystem when you flash the firmware.  Your call on how to make that work though, I've not done that.

Once you get the binary, unpack it in the directory you want to download files to (I recommend /tmp).  Leave the TV at the shell prompt

From the host:

echo lrz >> /dev/ttyUSB0

sz Your_filename_here < /dev/ttyUSB0 > /dev/ttyUSB0

That's it!  Your file is copied and you can do whatever evil/insane/misunderstood thing you were going to do with it.

Next stop: custom OSD displays.   Yeah, I'm getting there -- honestly!