Skip to content

Commit

Permalink
debug build to help see what goes wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Apr 8, 2021
1 parent 05da43a commit 6a86964
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 54 deletions.
70 changes: 42 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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:
Expand Down
Binary file added example/capture-esp.bas
Binary file not shown.
Binary file modified example/verify.bas
Binary file not shown.
51 changes: 32 additions & 19 deletions example/verify.bas.txt
Original file line number Diff line number Diff line change
@@ -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
Binary file modified example/verify7.bas
Binary file not shown.
2 changes: 1 addition & 1 deletion example/verify7.bas.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified http
Binary file not shown.
Binary file modified http-debug.dot
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 5 additions & 2 deletions src/uart.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/version.inc.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IFNDEF TESTING
DEFINE VERSION "1.0-18b"
DEFINE VERSION "1.0-19b"
ELSE
DEFINE VERSION "TEST"
ENDIF
Expand Down
9 changes: 7 additions & 2 deletions src/wifi.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6a86964

Please sign in to comment.