#include <stdio.h>
#include "IbcCardInfo.h"

IbcCardInfo::Info IbcCardInfo::_validInfo[] = 
{ 
  { 0,     0,    0x10, "CPU196" },
  { 0x10,  0x7,  2,    "12V Low Pwr Switch" },
  { 0x18,  0x7,  2,    "24V Low Pwr Switch" },
  { 0x20,  0x7,  2,    "48V Low Pwr Switch" },
  { 0x28,  0x7,  2,    "Var Low Pwr Switch" },
  { 0x40,  0x7,  4,    "Parallel I/O"},
  { 0x48,  0x7,  2,    "Ground Fault"},
  { 0x50,  0x7,  2,    "Quad A/D"},
  { 0x60,  0,    4,    "Nav Interface"},
  { 0x63,  0,    1,    "Hydrophone PSU"},
  { 0x64,  0x1,  1,    "Regen Control"},
  { 0x70,  0x0f, 2,    "High Pwr Switch"},
  { 0x80,  0x1f, 0x20, "Quad Serial"},
  { 0xc0,  0x0f, 4,    "Isolated I/O"},
  { 0x200, 0x1,  1,    "Dual Vicor"},
  { 0x210, 0,    1,    "Data Switch"},

  /* Marks end of list */
  { 0x0, 0,    0,    NULL}
};


int IbcCardInfo::sprint(Word cardAddr, char *buf)
{
  Reg Info *info = &_validInfo[0];

  while (info->name != NULL)
  {
    if ( (cardAddr & ~info->mask) == info->addr )
    {
      sprintf(buf, "%s %d", 
	      info->name, 
	      (cardAddr - info->addr) / info->range );
		
      return 0;
    }
    info++;
  }

  sprintf(buf, "Unknown");
  return -1;
}
