Browse Source

Added binary file send/receive routines.

master
Alec Murphy 5 years ago
parent
commit
8aac78fb62
  1. 116
      Browser.HC

116
Browser.HC

@ -1,20 +1,98 @@
#define URIEL_BINARY_EOF "*[U_EOF]"
#define URIEL_BINARY_SOF "*[U_SOF]"
#define URIEL_FCMD_GET "*[U_GET]"
#define URIEL_FCMD_PUT "*[U_PUT]"
#define URIEL_PORT 2
#include "::/Doc/Comm"
U8 *WebPageBuf[1048576];
I64 port = 2;
CComm *c=CommInit8n1(port,38400);
U8 UrielPageBuf[2097152];
U8 UrielFileBuf[2097152];
I64 UrielFileBufSize=0;
CComm *c=CommInit8n1(URIEL_PORT,115200);
U0 Get(U8 *remote_file, U8 *local_file="file") {
Bool load=FALSE;
I64 b=0;
UrielFileBufSize=0;
CommPutS(URIEL_PORT, URIEL_FCMD_GET);
CommPutS(URIEL_PORT, remote_file);
CommPutS(URIEL_PORT, "|");
CommPutS(URIEL_PORT, Define("DD_OS_NAME_VERSION"));
CommPutS(URIEL_PORT, "^");
progress1_max=100;
progress1=0;
StrCpy(progress1_desc, "Receiving file");
while (!load) {
Sleep(0);
while (FifoU8Rem(c->RX_fifo,&b)) {
if (b != 0x00) {
UrielFileBuf[UrielFileBufSize] = b;
UrielFileBufSize++;
progress1++;
if (progress1>progress1_max) { progress1=0; };
}
else {
if (StrCmp(UrielFileBuf+(UrielFileBufSize-8), URIEL_BINARY_EOF)==0) {
UrielFileBufSize -= 8;
load=TRUE;
break;
}
else {
UrielFileBuf[UrielFileBufSize] = b;
UrielFileBufSize++;
progress1++;
if (progress1>progress1_max) { progress1=0; };
}
}
}
}
FileWrite(local_file, UrielFileBuf, UrielFileBufSize);
ProgressBarsRst;
}
U0 Send(U8 *local_file, U8 *remote_file="") {
CDirEntry *d_file = FilesFind(local_file);
U8 *s_file = FileRead(d_file->full_name, d_file->size);
I64 f_pos=0;
CommPutS(URIEL_PORT, URIEL_FCMD_PUT);
CommPutS(URIEL_PORT, local_file);
CommPutS(URIEL_PORT, "|");
CommPutS(URIEL_PORT, remote_file);
CommPutS(URIEL_PORT, URIEL_BINARY_SOF);
progress1_max=d_file->size;
progress1=0;
StrCpy(progress1_desc, "Sending file");
for (f_pos=0;f_pos<d_file->size;f_pos++) {
Sleep(0);
progress1=f_pos;
CommPutChar(URIEL_PORT, s_file[f_pos]);
}
CommPutS(URIEL_PORT, URIEL_BINARY_EOF);
ProgressBarsRst;
Free(s_file);
Free(d_file);
}
U0 CloseBrowser() {
Bool close=FALSE;
close = PopUpCancelOk("Close Browser?");
if (close) { In("xn"); };
}
U0 Browser(U8 *url)
{
WinMax;
I64 WebPageBufSize=0;
I64 WebPageBufPos=0;
U8 *Cmd;
I64 UrielPageBufSize=0;
I64 UrielPageBufPos=0;
CommPutS(port, url);
CommPutS(port, "V5.02");
CommPutS(port, "^");
CommPutS(URIEL_PORT, url);
CommPutS(URIEL_PORT, "|");
CommPutS(URIEL_PORT, Define("DD_OS_NAME_VERSION"));
CommPutS(URIEL_PORT, "^");
CDoc *WebPage = DocNew();
CDoc *UrielPage = DocNew();
I64 b=0;
Bool load=FALSE;
Bool proc=FALSE;
@ -24,15 +102,15 @@ U0 Browser(U8 *url)
progress1=0;
StrCpy(progress1_desc, "Request sent, waiting for response");
while (!load) {
if (InU8(0x60)==0x01) { WebPageBufSize=0; break; };
if (InU8(0x60)==0x01) { UrielPageBufSize=0; break; };
Sleep(0);
while (FifoU8Rem(c->RX_fifo,&b)) {
if (b == 0xFF && !pad) { load=TRUE; break; };
if (b != 0xFF && pad) { pad=FALSE; };
if (b != 0xFF && !pad) {
if (!proc) { proc=TRUE; StrCpy(progress1_desc, "Processing DolDoc"); };
WebPageBuf[WebPageBufSize] = b;
WebPageBufSize++;
UrielPageBuf[UrielPageBufSize] = b;
UrielPageBufSize++;
progress1++;
if (progress1>progress1_max) { progress1=0; };
}
@ -40,17 +118,19 @@ U0 Browser(U8 *url)
}
ProgressBarsRst;
while (WebPageBufPos<WebPageBufSize) {
DocPrintPartial(WebPage, "%c", WebPageBuf[WebPageBufPos]);
WebPageBufPos++;
while (UrielPageBufPos<UrielPageBufSize) {
DocPrintPartial(UrielPage, "%c", UrielPageBuf[UrielPageBufPos]);
UrielPageBufPos++;
}
DocClear;
DocInsDoc(DocPut, WebPage);
DocInsDoc(DocPut, UrielPage);
DocTop;
DocDel(WebPage);
DocDel(UrielPage);
while (TRUE) {
GetStr;
Cmd = GetStr;
if(StrCmp(Cmd, "x")==0) { break; };
}
Free(Cmd);
DocBottom;
}
Loading…
Cancel
Save