diff --git a/README.md b/README.md index 42b0565..c42a6a8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A utility for application developers to talk to web servers to exchange blocks of data, such as high scores, game progress. The `.http` dot command can also download and save to files over the web. -Usage: +## Usage ``` ; Send 1024 bytes from bank 22 to http://192.168.1.100:8080/send @@ -70,32 +70,12 @@ I've written a number of [example servers](https://github.com/remy/next-http/tre - I've noticed when using Cspect's emulation, if the host can't be reached, Cspect will hang indefinitely. - When using the `offset` you are constrained to 16K, so if the offset is 8,192, then the max length is also 8,192 (there's no error checking on this currently) -## Not supported / future +## Not supported / potential future +- 7bit / cspect emulated ESP support for file saving isn't working (yet) - http chunked encoding (just make sure your server isn't sending chunked encoding) - Support length on GET - -## Debugging and problems - -This repo also includes a debug build of `http`. The difference is that it will add all the ESP read and write to the second half of the bank you use. This way you can debug from the real hardware and capture exactly what's going on. - -**Important** the debug dot command uses the second half of the bank you use, so ideally test with less than 8K to help debugging. - -If you need to file an issue, this information is extremely valuable for debugging - and if you're not comfortable including the file in [an issue](https://github.com/remy/next-http/issues/new) as an attachment, you can email me directly at remy@remysharp.com. To capture this, run: - -``` -10 ../http-debug.dot -h example.com -u / -b 20 -20 SAVE "http-debug.bin" BANK 20 -``` - -Then include the `http-debug.bin` that was saved on your Next to help debug the issue. - -### Notes on http-debug.dot - -1. Does not erase the bank -2. The contents of the `State` structure (in `state.asm`) are written to the 2nd half of the bank, i.e. the second 8K page -3. After the `State` object, around 519 bytes later, the ESP exchange are stored, including the AT commands and ESP raw response. -4. `Wifi.getPacket` writes to the end of the bank with the `IX` register state as a stack like array - this is to debug the final parsing of the base64 encoded packet +- File POST and offsets in file saving ## Error codes @@ -119,11 +99,39 @@ Then include the `http-debug.bin` that was saved on your Next to help debug the - `I` Filename or bank must be specified (command is missing the `-b` or `-f` argument) - `J` Could not open file for writing -## Development +## Testing + +Assuming that `http` is in your `/dot/` directory, there are two verification programs in the [example](https://github.com/remy/next-http/tree/main/example) folder. Download [verify.bas](https://github.com/remy/next-http/blob/main/example/verify.bas) and run it and if it succeeds you'll see the following screen: + +![](https://user-images.githubusercontent.com/13700/114017829-68f57380-9864-11eb-9590-71cad0e4c4a1.png) + +If any of the sections fail however, there is a debug script available in [capture-esp.bas](https://github.com/remy/next-http/blob/main/example/capture-esp.bas) which uses [`http-debug.dot`](https://github.com/remy/next-http/blob/main/http-debug.dot) in the **same** directory as capture-esp.bas. + +The `capture-esp.bas` will test a simple 4K file and generate `4k-esp-bank.bin` in the same working directory which contains full debug exchange between your machine and the ESP chip uses to send data. If you share that file with me either [via issues](https://github.com/remy/next-http/issues/new) or via [email](mailto:remy@remysharp.com) I can use it to debug. + + +## Debugging and problems + +This repo also includes a debug build of `http`. The difference is that it will add all the ESP read and write to the second half of the bank you use. This way you can debug from the real hardware and capture exactly what's going on. + +**Important** the debug dot command uses the second half of the bank you use, so ideally test with less than 8K to help debugging. + +If you need to file an issue, this information is extremely valuable for debugging - and if you're not comfortable including the file in [an issue](https://github.com/remy/next-http/issues/new) as an attachment, you can email me directly at remy@remysharp.com. To capture this, run: + +``` +10 ../http-debug.dot -h example.com -u / -b 20 +20 SAVE "http-debug.bin" BANK 20 +``` + +Then include the `http-debug.bin` that was saved on your Next to help debug the issue. + +### Notes on http-debug.dot + +1. Does not erase the bank +2. The contents of the `State` structure (in `state.asm`) are written to the 2nd half of the bank, i.e. the second 8K page +3. After the `State` object, around 519 bytes later, the ESP exchange are stored, including the AT commands and ESP raw response. +4. `Wifi.getPacket` writes to the end of the bank with the `IX` register state as a stack like array - this is to debug the final parsing of the base64 encoded packet -- Uses [sjasmplus](https://z00m128.github.io/sjasmplus/documentation.html) from VS Code task -- Follows this [code convention](https://github.com/remy/z80-code-conventions) -- Entry point is main.asm ## With special thanks to @@ -132,6 +140,12 @@ Then include the `http-debug.bin` that was saved on your Next to help debug the - [Peter Ped Helcmanovsky](https://github.com/ped7g/) - via dot commands and answering endless questions on discord - [David Saphier](https://github.com/em00k/) - for starting and inspiring full "save to file" support +## Development + +- Uses [sjasmplus](https://z00m128.github.io/sjasmplus/documentation.html) from VS Code task +- Follows this [code convention](https://github.com/remy/z80-code-conventions) +- Entry point is main.asm + ## License It's in the license link, but all the same: diff --git a/example/capture-esp.bas b/example/capture-esp.bas new file mode 100644 index 0000000..7dc5cab Binary files /dev/null and b/example/capture-esp.bas differ diff --git a/example/verify.bas b/example/verify.bas index 38f0c5f..f67599e 100644 Binary files a/example/verify.bas and b/example/verify.bas differ diff --git a/example/verify.bas.txt b/example/verify.bas.txt index cbe4947..fe706fd 100644 --- a/example/verify.bas.txt +++ b/example/verify.bas.txt @@ -1,24 +1,37 @@ #program verify -10 LAYER 0: CLS +1 RUN AT 3 +10 LAYER 0 20 BANK 20 ERASE -30 PRINT AT 0,0; INVERSE 1;"HTTP test suite"; INVERSE 0 -40 ON ERROR GO SUB 9000 -45 t$="4k":u$="/10":%r=2: GO SUB 1060 -50 t$="8k":u$="/8":%r=4: GO SUB 1060 -60 t$="16k":u$="/9":%r=6: GO SUB 1060 -70 t$="32k":u$="/7":%r=8: GO SUB 1060 -80 ON ERROR -90 PRINT FLASH 1;"Success" -1000 PAUSE 0: STOP -1060 PRINT AT %r,0;t$+" test..." -1070 t$=t$+".bin" -1080 .http -h data.remysharp.com -u u$ -f t$ -v 6 -1090 PRINT AT %r,11;"done. Verifying: " -1100 c$=t$+" -1 -mb 20" -1110 .$ extract c$ -1120 %i=% BANK 20 PEEK 0 -1130 IF %i=$FF THEN PRINT AT %r,27; INVERSE 1;"OK"; INVERSE 0: ELSE PRINT AT %r,27; FLASH 1;"BAD": PAUSE 0: STOP -1140 RETURN +30 ON ERROR GO SUB 9000 +40 CLS : PRINT INVERSE 1;"HTTP bit bank tests"; INVERSE 0:%e=1 +145 t$="4k":%l=%$1000:u$="/10":%r=1: GO SUB 1000 +150 t$="8k":%l=%$2000:u$="/8":%r=2: GO SUB 1000 +160 t$="16k":%l=%$4000:u$="/9":%r=3: GO SUB 1000 +500 PRINT INVERSE 1;"HTTP file tests"; INVERSE 0:%e=2 +510 t$="4k":u$="/10":%r=5: GO SUB 1000 +520 t$="8k":u$="/8":%r=6: GO SUB 1000 +530 t$="16k":u$="/9":%r=7: GO SUB 1000 +540 t$="32k":u$="/7":%r=8: GO SUB 1000 +900 ON ERROR +910 PRINT FLASH 1;"All OK" +920 PAUSE 0: STOP +1010 PRINT AT %r,0;t$+" test..." +1020 t$=t$+".bin" +1030 IF %e=1 THEN GO TO 7000: ; banking +1040 REM file test logic +1200 .http -h data.remysharp.com -u u$ -f t$ -v 6 +5090 PRINT AT %r,11;"done. Verifying: " +5100 c$=t$+" -1 -mb 20" +5110 .$ extract c$ +5120 %i=% BANK 20 PEEK 0 +5130 GO TO 8000 +5140 REM bank testing logic +7000 .http -h data.remysharp.com -u u$ -b 20 -v 5 +7090 PRINT AT %r,11;"done. Verifying: " +7120 %i=% BANK 20 PEEK (l-1) + +8000 IF %i=$FF THEN PRINT AT %r,27; INVERSE 1;"OK"; INVERSE 0: ELSE PRINT AT %r,27; FLASH 1;"BAD": PAUSE 0: STOP +8010 RETURN 9000 ON ERROR 9050 PRINT FLASH 1;"ERROR": ERROR : PAUSE 0: STOP diff --git a/example/verify7.bas b/example/verify7.bas index 8e8e588..7e2bb49 100644 Binary files a/example/verify7.bas and b/example/verify7.bas differ diff --git a/example/verify7.bas.txt b/example/verify7.bas.txt index d6224be..52fe10a 100644 --- a/example/verify7.bas.txt +++ b/example/verify7.bas.txt @@ -14,7 +14,7 @@ 540 ; t$="32k":u$="/14":%r=7: GO SUB 1000 900 ON ERROR 910 PRINT FLASH 1;"7bit - All OK" -920 STOP +920 PAUSE 0: STOP 1010 PRINT AT %r,0;t$+" test..." 1020 t$=t$+".bin" 1030 IF %e=1 THEN GO TO 7000: ; banking diff --git a/http b/http index 3e834a9..853923c 100644 Binary files a/http and b/http differ diff --git a/http-debug.dot b/http-debug.dot index bd34416..c888bb6 100644 Binary files a/http-debug.dot and b/http-debug.dot differ diff --git a/src/main.asm b/src/main.asm index 2080c24..760fe11 100644 --- a/src/main.asm +++ b/src/main.asm @@ -2,7 +2,7 @@ SLDOPT COMMENT WPMEM, LOGPOINT, ASSERTION OPT reset --zxnext --syntax=abfw - DEFINE TESTING + ; DEFINE TESTING INCLUDE "version.inc.asm" INCLUDE "macros.inc.asm" diff --git a/src/uart.asm b/src/uart.asm index 18628e6..a2b710c 100644 --- a/src/uart.asm +++ b/src/uart.asm @@ -49,12 +49,15 @@ init ret .baudTable: - DW 243,248,256,260,269,278,286,234 + ; IFDEF TESTING + ; DEFW 486,496,512,521,538,556,573,469 ; 56k - slower on the off chance it helps with debug + ; ELSE + DEFW 243,248,256,260,269,278,286,234 ; 115K + ; ENDIF ; A <- result ; Modifies: BC read: - call Border call InitESPTimeout ld bc, UART_GetStatus .wait: diff --git a/src/version.inc.asm b/src/version.inc.asm index 43027b4..cbad7d4 100644 --- a/src/version.inc.asm +++ b/src/version.inc.asm @@ -1,5 +1,5 @@ IFNDEF TESTING - DEFINE VERSION "1.0-18b" + DEFINE VERSION "1.0-19b" ELSE DEFINE VERSION "TEST" ENDIF diff --git a/src/wifi.asm b/src/wifi.asm index 6755615..534b7b9 100644 --- a/src/wifi.asm +++ b/src/wifi.asm @@ -23,16 +23,21 @@ init: call Uart.init EspCmdOkErr "ATE0" jr c, .initError + + EspCmdOkErr "AT+CIPSERVER=0" EspCmdOkErr "AT+CIPCLOSE" ; Close if there some connection was. Don't care about result EspCmdOkErr "AT+CIPMUX=0" ; Single connection mode jr c, .initError + EspCmdOkErr "AT+CIPDINFO=0" ; Disable additional info + jr c, .initError + and a ret .initError call RetartESP jr c, .failed - jr Wifi.init + jp Wifi.init .failed ld hl, Err.wifiInit scf @@ -486,7 +491,7 @@ getPacket: call esxDOS.fWrite pop de pop hl - ld de, (Bank.buffer) + ld de, Bank.buffer .skipWriteToFile ex de, hl ; update the tip of our result buffer