*
* Sequence numbers, Quick data packets, data checksums and error codes
* The sequence number is on the 5 least significant bits of the sequence number field.
- * this gives 64 sequence numbers which is more than enough.
+ * this gives 31 sequence numbers which is more than enough.
+ * A sequence number of 0 means "Out of band" data (usually unrequested data from slave
+ * to master).
* When the most significant bit (bit 7) of the sequence number field (seq_num) is set
* in a request (master to slave), the slave MUST send an acknowledge packet or a reply
* with the same sequence number.
char start; /* Start of paquet indicator */
uint8_t type; /* Packet type, used to provide information on the data structure */
uint8_t checksum; /* Header checksum */
- uint8_t seq_num; /* Packet sequence number on bits 0:5, error indicator on bit 7 */
+ uint8_t seq_num; /* Packet sequence number on bits 0:4, error indicator on bit 7, quick data on bit 6 */
union {
struct data_information data;
struct error_information err;
/* The following struct defines a generic packet.
* Specific packets should be defined in specific structures.
*/
-#define PACKET_DATA_SIZE 64
+#define PACKET_DATA_SIZE (64 - sizeof(struct header))
struct packet {
struct header info; /* Packet header */
uint8_t data[PACKET_DATA_SIZE]; /* packet data */
tx_info->seq_num = question->info.seq_num;
len = sizeof(struct header); /* At least, send header on serial link */
- if (error) {
+ if (error != NO_ERROR) {
tx_info->seq_num |= PACKET_IS_ERROR;
tx_info->err.error_code = error;
if (error == GOT_MANY_ERRORS) {
/* Update length of data to send on serial link */
len += data_send_size;
}
+ } else {
+ tx_info->data.size = 0;
+ tx_info->data.checksum = 0;
}
}
if (data_sent < size) {
/* Move data pointer */
data_src += data_send_size;
- /* Update size to send. check against PACKET_DATA_SIZE is done at beginning of loop */
+ /* Update size to send. Check against PACKET_DATA_SIZE is done at beginning of loop */
data_send_size = (size - data_sent);
/* Set packet type to continued data packet for following packets */
type = PKT_TYPE_CONTINUED_DATA;