UKHAS Wiki

UK High Altitude Society

User Tools

Site Tools


projects:high_altitude_slug:software:protocol

This is an old revision of the document!


Protocol documentation

This is for coordinating our development.

Basics

First two bytes contain the command. The next two bytes is the length of the data, then the rest is data.

Commands

Human messages (0 - 9)

All processes (10 - 4999)

GPS reader (5000 - 5999)

Flight management (6000 - 6999)

Roll control (7000 - 7999)

Pitch control (8000 - 8999)

Client Library Functions

client_init

The client_init function should be called before any other client related functions and connects to serverAddr (probably localhost) on port port. Both of these values should be #defined in config.h as SERVER and PORT respectively. The function is prototyped as:

unsigned short client_init (char *serverAddr, unsigned short port);

in client.h

On success client_init function returns the socket file descriptor of the server that it has connected to which should be passed to all client-related functions. On failure the function returns -1 and makes a note in the client error log.

client_recv_packet

The client_recv_packet function is used to read packets of data from the server. It reads a single packet of data from serverFD (the servers network file descriptor returned by client_init) and then places the packet into packet which should be a pointer to a client_packet structure. It is prototyped as:

int client_recv_packet (unsigned short serverFD, struct client_packet *packet);

in client.h

The client_recv_packet function will automatically perform byte-conversions on packet→command and packet→len using the ntohs function.

First of all the function will read 4 bytes of data from the serverFD, convert them to the host byte order and then use the packet→len variable to work out the length of the data segment of the packet. Next, malloc is used to allocate enough memory to store the data segment of the packet and the null byte (packet→len + 1), before going onto reading the data segment into the newly allocated string and then setting the last byte to \0.

Please note the the data segment of the packet (packet→data) is made up of memory allocated off of the heap, and so needs to be free()'ed when no longer needed to prevent a memory leak!

On success this function will return 0 while on failure this function will return -1 and will make a note in the error log about exactly what went wrong.

client_send_packet

The client_send_packet function should be used to send a packet of information to the server (aka the 'party line'). It sends packet to serverFD (which is the servers file descriptor) and is prototyped as:

int client_send_packet (unsigned short serverFD, struct client_packet *packet);

in client.h

Like the client_recv_packet function the client_send_packet function will automatically perform byte-conversions on both packet→command and packet→len to convert them to the network byte order using htons function.

On success the function will return 0 otherwise, on failure, will return -1 and make a note in the error log about what went wrong.

client_close

The client_close function simply closes serverFD by calling the close function (which it is no more than a wrapper over) and is prototyped as:

void client_close (unsigned short serverFD)

in client.h

client_close should be called when the connection to the server ('party line') is no longer needed.

projects/high_altitude_slug/software/protocol.1151946242.txt.gz · Last modified: 2008/07/19 23:31 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki