rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2014 Brian Swetland |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | #pragma once |
| 24 | |
| 25 | typedef struct { |
| 26 | unsigned char opcode; |
| 27 | unsigned char extra; |
| 28 | unsigned short length; |
| 29 | } msg_hdr_t; |
| 30 | |
| 31 | // unless otherwise specified, extra is always zero. |
| 32 | |
| 33 | #define MSG_OKAY 0x00 |
| 34 | // length must be zero. |
| 35 | // server indicates command was successful. |
| 36 | |
| 37 | #define MSG_FAIL 0xFF |
| 38 | // length may be nonzero, if so data is a human readable error message |
| 39 | // extra may be nonzero, if so it is a more specific error code |
| 40 | |
| 41 | #define MSG_LOG 0xFE |
| 42 | // data contains human readable log message from server |
| 43 | // server may issue these at any time |
| 44 | |
| 45 | #define MSG_GO_AHEAD 0x01 |
| 46 | // length must be zero |
| 47 | // server indicates that command was valid and it is ready for data |
| 48 | // client should send MSG_SEND_DATA messages to transfer data |
| 49 | |
| 50 | #define MSG_CMD 0x40 |
| 51 | // length must be greater than zero |
| 52 | // data will contain an ascii command |
| 53 | // server may reject excessively large commands |
| 54 | |
| 55 | #define MSG_SEND_DATA 0x41 |
| 56 | // client sends data to server |
| 57 | // length is datalen -1 (to allow for full 64k chunks) |
| 58 | |
| 59 | #define MSG_END_DATA 0x42 |
| 60 | // client ends data stream |
| 61 | // server will then respond with MSG_OKAY or MSG_FAIL |
| 62 | |
| 63 | // command strings are in the form of |
| 64 | // <command> ':' <decimal-datalen> ':' <optional-arguments> |
| 65 | |
| 66 | // example: |
| 67 | // C: MSG_CMD "flash:32768:bootloader" |
| 68 | // S: MSG_GO_AHEAD |
| 69 | // C: MSG_SEND_DATA 16384 ... |
| 70 | // C: MSG_SEND_DATA 16384 ... |
| 71 | // C: MSG_END_DATA |
| 72 | // S: MSG_LOG "erasing sectors" |
| 73 | // S: MSG_LOG "writing sectors" |
| 74 | // S: MSG_OKAY |
| 75 | // |
| 76 | // C: MSG_CMD "eraese:0:bootloader" |
| 77 | // S: MSG_FAIL "unknown command 'eraese'" |
| 78 | // |
| 79 | // C: MSG_CMD "reboot:0:" |
| 80 | // S: MSG_OKAY |