/****************************************************************************/
/* Copyright 2012 MBARI.                                                    */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/\

/**
 * packet.h declares a set of functions to easily construct data packets sent
 * over SPI1, used to communicate to other boards in the PLU.
 * <p>
 * A packet is a 32-bit integer packed with relevant data.  Starting from the
 * MSB downward, a packet's regions are:
 * <ol>
 * <li>Board address (3 bits): The slot number of the target daughterboard</li>
 * <li>Command type (8 bits): The type of command issued to the target</li>
 * <li>Arguments (21 bits): Any additional information needed for the command
 * </li></ol>
 * For example, if an environment board were placed in slot 3, and the user
 * were to input the following command:
 * <blockquote><code>GET ENVR 01 HUM08</code></quote>
 * The resulting packet would have the following fields:
 * <ol>
 * <li>Board address = 3</li>
 * <li>Command type = TYPE_READ</li>
 * </ol>
 * Finish this when you've figured out how big the SPI buffers are.
 */

#ifndef PACKET_H
#define PACKET_H

#include <stdint.h>

#define PKT_CMD 29
#define PKT_ADDR 26

/** Returns a packet created from the given criteria
 *  @param command the type of command.  Either CMD_GET, CMD_SET, or CMD_CLR.
 *  @param bdType the type of daughterboard.  Can be any of the types specified
 *  in sys_defs.h
 *  @param bdAddress which daughterboard of bdType to send this packet.
 *  @param args additional arguments to append to packet, should they fit
 *  @param nargs number of additional arguments
 *  @return a 32-bit binary string packed with data corresponding to these
 *  given parameters.
 */
uint64_t pktCreate(uint8_t command, uint8_t *args, uint8_t nargs);

/**
 * Prints a packet to the console, for testing purposes
 */
void pktDebPrint(uint64_t pkt);

typedef struct Packet {
    unsigned char command;
    unsigned char[8] args;
};

#endif