/* blib - Library of useful things to hack the Blinkenlights
 *
 * Copyright (c) 2001-2002  The Blinkenlights Crew
 *                          Tim Pritlove <tim@ccc.de>
 *                          Sven Neumann <sven@gimp.org>
 *                          Michael Natterer <mitch@gimp.org>
 *                          Daniel Mack <daniel@yoobay.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef __B_PROTOCOL_H__
#define __B_PROTOCOL_H__

#include <sys/types.h>

#define MAGIC_MCU_SETUP     0x2342FEED  /* MCU Configuration packet              */
#define MAGIC_MCU_FRAME     0x23542666  /* MCU Frame packet                      */
#define MAGIC_MCU_DEVCTRL   0x23542667  /* MCU Device Control packet */

#define MAGIC_BLFRAME       0xDEADBEEF  /* Original BL Frame Packet              */
#define MAGIC_BLFRAME_256   0xFEEDBEEF  /* Extendend BL Frame Packet (Greyscale) */


#define MCU_LISTENER_PORT    2323
#define MCU_ID_ANY           -1

/***********************************************************/

/*
 * Legacy Blinkenlights bl_frame format
 */

typedef struct bl_frame_header bl_frame_header_t;

struct bl_frame_header
{
  u_int32_t frame_magic;  /* == MAGIC_BLFRAME */
  u_int32_t frame_count;
  u_int16_t frame_width;
  u_int16_t frame_height;
  /*
   * followed by
   * unsigned char data[rows][columns];
   */
};

/***********************************************************/

/*
 * MCU Frame packet
 */

typedef struct mcu_frame_header mcu_frame_header_t;

struct mcu_frame_header
{
  u_int32_t magic;     /* == MAGIC_MCU_FRAME                        */
  u_int16_t height;    /* rows                                      */
  u_int16_t width;     /* columns                                   */
  u_int16_t channels;  /* Number of channels (mono/grey: 1, rgb: 3) */
  u_int16_t maxval;    /* maximum pixel value (only 8 bits used)    */
  /*
   * followed by
   * unsigned char data[rows][columns][channels];
   */
};


/*
 * MCU Setup packet
 */

typedef struct mcu_setup_pixel mcu_setup_pixel_t;

struct mcu_setup_pixel
{
  unsigned char row;
  unsigned char column;
};


typedef struct mcu_setup_header mcu_setup_header_t;

struct mcu_setup_header
{
  u_int32_t     magic;        /* == MAGIC_MCU_SETUP        */

  char          mcu_id;       /* target MCU id ( -1 = any) */
  unsigned char _reserved[3]; /* padding                   */

  u_int16_t     height;
  u_int16_t     width;
  u_int16_t     channels;

  u_int16_t     pixels;       /* number of ports used (starting from 0) */
  /*
   * followed by
   * mcu_setup_pixel_t pixel[pixels];
   */
};


/*
 * MCU Device Control packet
 */

#define MCU_DEVCTRL_OFF  0    /* switch device off */
#define MCU_DEVCTRL_ON   1    /* switch device on  */

typedef struct mcu_devctrl_header  mcu_devctrl_header_t;

struct mcu_devctrl_header
{
  u_int32_t magic;        /* == MAGIC_MCU_DEVCTRL                    */
  u_int16_t pixels;       /* number of pixels used (starting from 0) */
  u_int16_t _reserved;    /* 32 bit padding                          */
  /*
   * followed by
   * unsigned char control[pixels];
   */
};


#endif /* __B_PROTOCOL_H__ */
