diff --git a/documentation/groundStation/packets.md b/documentation/groundStation/packets.md index fdb0e8eac4db58fecbf009cd171d17052cfdb276..cb3ced14b543f234ab5e34018d144f20ef7860f8 100644 --- a/documentation/groundStation/packets.md +++ b/documentation/groundStation/packets.md @@ -1,13 +1,123 @@ +# Packet Information # + The MicroCART project uses custom packets to communicate with the quad. This may seem complex at first but the structure of all packets is the same it is just the way the data is formatted that changes -between packets. The basic structure is shown below. +between packets. + +## Introduction ## +All packets are the same in the sense that they have consistent headers with a start character and all end with a checksum as well as +a end character. The basic structure is shown below. | Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | |:-----------------:|:---------------:|:------------:|:----------:|:-----------:|:----:|:--------:|:-------------:| | Message Parameter | Begin Character | Message Type | Message ID | Data Length | Data | Checksum | End Character | | Bytes | 1 | 2 | 2 | 2 | var | 1 | 1 | -Both the begin and end characters are defined in (communication.h)[]. Message types are defined within an enum in -(commands.h)[]. Message ID is managed within the backend and is just a counter that is defined in (backend.c)[] of. -Data length varies with the command that is being sent, but the length of a command is constant. The data is sent -in a specific format set by commands. Lastly, checksum is computed within (backend.c)[]. \ No newline at end of file +Both the begin and end characters are defined in the Message enum in [commands.h](../../quad/src/commands/commands.h). Message types +are defined within the MessageTypeID enum in [commands.h](../../quad/src/commands/commands.h). Message ID is managed within the backend +[backend.c](../../groundStation/src/backend/backend.c) and is just a counter that is used in client_recv to number packets. Data length +varies with the command that is being sent, but the length of a command is constant. The data is sent in a specific format set by commands. +Lastly, checksum is computed within [packet.c](../../groundStation/src/backend/packet.c). + +All packets sent within the system are commands, defined by the MessageTypeID enum referenced earlier, or a VPRN packet. Much of the time when +flying autonomously the commands that the user is responsible for are the getparam and setparam packets that are used to set waypoints or change +values within the computation graph, see [control_algorithm.c](../../quad/src/quad_app/control_algorithm.c) for the PID blocks. + +## Adding a new packet ## + +//TODO - Matt + +## Data Format ## + +For all commands other than the message bundle packet there is a defined length and format for sending and receiving packets. Many of the formats +will be discussed below. These packet formats are referenced from [callbacks.c](../../quad/src/quad_app/callbacks.c). + +**Note:** this document may get out of date, [callbacks.c](../../quad/src/quad_app/callbacks.c) should have all the up to data packet formats. + +### setparam ### + +** Sent from Ground Station ** + +| data index | 0 - 1 | 2 - 3 | 4 - 7 | +|:----------:|:-----------:|:-----------:|:-----------:| +| parameter | node ID | node parmID | param val | +| bytes | 2 | 2 | 4 | + +Does not send any response. + +### getparam and getoutput ### + +** Sent from Ground Station ** + +| data index | 0 - 1 | 2 - 3 | +|:-----------:|:-------------:|:-----------:| +| parameter | node ID | node parmID | +| bytes | 2 | 2 | + +** Response to Ground Station ** + +The response will be of type RESPPARAM_ID. + +| data index | 0 - 1 | 2 - 3 | 4 - 7 | +|:-----------:|:------------:|:-----------:|:-----------:| +| parameter | node ID | node parmID | param val | +| bytes | 2 | 2 | 4 | + +### setsource ### + +** Sent from Ground Station ** + +| data index | 0 - 1 | 2 - 3 | 4 - 5 | 6 - 7 | +|:----------:|:------------:|:-------------:|:-----------:|:-------------:| +| parameter | dest node ID | dest input ID | src node ID | src output ID | +| bytes | 2 | 2 | 2 | 2 | + +Does not send any response. + +### getsource ### + +** Sent from Ground Station ** + +| data index | 0 - 1 | 2 - 3 | +|:-----------:|:-------------:|:-----------:| +| parameter | node ID | node parmID | +| bytes | 2 | 2 | + +** Response to Ground Station ** + +The response will be of type RESPSOURCE_ID. + +| data index | 0 - 1 | 2 - 3 | 4 - 5 | 6 - 7 | +|:----------:|:------------:|:-------------:|:-----------:|:-------------:| +| parameter | dest node ID | dest input ID | src node ID | src output ID | +| bytes | 2 | 2 | 2 | 2 | + +### getnodes ### + +** Sent from Ground Station ** + +//TODO - Does not list in callbacks.c, does this exist? + +** Response to Ground Station ** + +| data index | 0 - 2*N-1 | 2*N - 4*N-1 | 4*N - (< 4096) | +|:-----------:|:------------:|:--------------:|:---------------:| +| parameter | Node IDs | Node type Is | Node names | +| bytes | 2*N | 2*N | < 4096 | + +### addnode ### + +** Sent from Ground Station ** + +| data index | 0 - 1 | 2 + | +|:-----------:|:------------:|:-------------:| +| parameter | type ID | New node name | +| bytes | 2 | var | + +** Response to Ground Station ** + +| data index | 0 - 1 | +|:-----------:|:------------:| +| parameter | node ID | +| bytes | 2 | + diff --git a/quad/src/quad_app/callbacks.c b/quad/src/quad_app/callbacks.c index 8c06e3bdd5283a234578398a2246a1a322291ba5..d4c839bef19746020afe887433a3e0616adea8d7 100644 --- a/quad/src/quad_app/callbacks.c +++ b/quad/src/quad_app/callbacks.c @@ -389,7 +389,7 @@ int cb_getnodes(struct modular_structs *structs, struct metadata *meta, unsigned * | data index || 0 - 1 | * |-----------------------------| * | parameter || node ID | - * |------------------------------ + * |-----------------------------| * | bytes || 2 | * |-----------------------------| */