1 /* 2 * Copyright (c) 2014 Brian Swetland 3 * 4 * Use of this source code is governed by a MIT-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/MIT 7 */ 8 #pragma once 9 10 typedef struct { 11 unsigned char opcode; 12 unsigned char extra; 13 unsigned short length; 14 } msg_hdr_t; 15 16 // unless otherwise specified, extra is always zero. 17 18 #define MSG_OKAY 0x00 19 // length must be zero. 20 // server indicates command was successful. 21 22 #define MSG_FAIL 0xFF 23 // length may be nonzero, if so data is a human readable error message 24 // extra may be nonzero, if so it is a more specific error code 25 26 #define MSG_LOG 0xFE 27 // data contains human readable log message from server 28 // server may issue these at any time 29 30 #define MSG_GO_AHEAD 0x01 31 // length must be zero 32 // server indicates that command was valid and it is ready for data 33 // client should send MSG_SEND_DATA messages to transfer data 34 35 #define MSG_CMD 0x40 36 // length must be greater than zero 37 // data will contain an ascii command 38 // server may reject excessively large commands 39 40 #define MSG_SEND_DATA 0x41 41 // client sends data to server 42 // length is datalen -1 (to allow for full 64k chunks) 43 44 #define MSG_END_DATA 0x42 45 // client ends data stream 46 // server will then respond with MSG_OKAY or MSG_FAIL 47 48 // command strings are in the form of 49 // <command> ':' <decimal-datalen> ':' <optional-arguments> 50 51 // example: 52 // C: MSG_CMD "flash:32768:bootloader" 53 // S: MSG_GO_AHEAD 54 // C: MSG_SEND_DATA 16384 ... 55 // C: MSG_SEND_DATA 16384 ... 56 // C: MSG_END_DATA 57 // S: MSG_LOG "erasing sectors" 58 // S: MSG_LOG "writing sectors" 59 // S: MSG_OKAY 60 // 61 // C: MSG_CMD "eraese:0:bootloader" 62 // S: MSG_FAIL "unknown command 'eraese'" 63 // 64 // C: MSG_CMD "reboot:0:" 65 // S: MSG_OKAY 66