const eSenderId = {

    No_Id               : 0x00,
    Speed_Board         : 0x01,
    Speed_Depth_Board   : 0x02,
    Heading_Src         : 0x03,
	Depth_Board		    : 0x04,
    Wind_Board          : 0x05,
    ATP2_ANA            : 0x06,
    ATP2_3020           : 0x07,
    ATP2_MFD            : 0x08,
    TimeStamp           : 0x09,
    Analog_Board        : 0x0a,
    Fastnet             : 0x0b,
    NMEA0183            : 0x0c,
    CanBus              : 0x0d,
    Main_Iface_Board    : 0x0e,
    Processor           : 0x0f,
    Damping             : 0x10,
    DLA2_Board          : 0x11,
    Expedition          : 0x12,
    BootLoader          : 0x13,
    No_Source           : 0x14,
    Faro                : 0x15,
    BFD                 : 0x16,
    QBD                 : 0x27,
	Serial			    : 0x17,
	Drive_Unit		    : 0x18,
	Pilot_Iface_Board   : 0x1e,
	ATPilot			    : 0x1f,
	ATP2_PHD		    : 0x20,
	DCELL			    : 0x21,

	Config_Updated      : 0x97,
	System			    : 0x98,
    Dummy_ID            : 0x99
};

const eSenderInstance = {

    Zero        : 255,
    Internal    : 0,
    One         : 1,
    Two         : 2,
    Three       : 3,
    Four        : 4,
    Five        : 5,
    Six         : 6,
    Seven       : 7,
    Eight       : 8,
    Nine        : 9,
    Ten         : 10,
    Rx_Ext_1    : 20,
    Any         : 99,
    All         : 0xff
};

//
// Get sender name from the sender id.
//
function getSenderName(id) {

    switch(id) {
    case eSenderId.No_Id:
        return "No ID";
    case eSenderId.Speed_Board:
        return "Speed Board";
    case eSenderId.Speed_Depth_Board:
        return "Depth Board";
    case eSenderId.Heading_Src:
        return "Heading";
    case eSenderId.Wind_Board:
        return "Wind Board";
    case eSenderId.ATP2_3020:
        return "3020";
    case eSenderId.ATP2_MFD:
        return "MFD";
    case eSenderId.ATP2_ANA:
        return "ANA";
    case eSenderId.TimeStamp:
        return "Timestamp";
    case eSenderId.Analog_Board:
        return "Analogue";
    case eSenderId.Fastnet:
        return "Fastnet";
    case eSenderId.NMEA0183:
        return "NMEA0183";
    case eSenderId.Faro:
        return "Faro";
    case eSenderId.CanBus:
        return "CanBus";
    case eSenderId.Main_Iface_Board:
        return "Main Interface Board";
    case eSenderId.Processor:
        return "Processor";
    case eSenderId.Damping:
        return "Damping";
    case eSenderId.DLA2_Board:
        return "DLA2";
    case eSenderId.Expedition:
        return "Expedition";
    case eSenderId.BootLoader:
        return "Bootloader";
    case eSenderId.Config_Updated:
        return "Config";
    case eSenderId.BFD:
        return "BFD";
    case eSenderId.QBD:
        return "QBD";
    case eSenderId.DCELL:
        return "DCELL";
    case eSenderId.Dummy_ID:
        return "Dummy";
    default:
        return "Not Known";
    }
};

//
// Get the sender id from the name
//
function getSenderIdFromName(name) {

    name = name.toLowerCase();

    if (name.includes("rocessor"))
    {
        return eSenderId.Processor;
    }
    if (name.includes("astnet"))
    {
        return eSenderId.Fastnet;
    }
    if (name.includes("nterface"))
    {
        return eSenderId.Main_Iface_Board;
    }
    if (name.includes("nmea0"))
    {
        return eSenderId.NMEA0183;
    }
    if (name.includes("ilot"))
    {
        return eSenderId.ATPilot;
    }
    if (name.includes("aro") )
    {
        return eSenderId.Faro;
    }
    if (name.includes("n2k") )
    {
        return eSenderId.CanBus;
    }
    if (name.includes("nmea2") )
    {
        return eSenderId.CanBus;
    }
    if (name.includes("anbus") )
    {
        return eSenderId.CanBus;
    }
    if (name.includes("epth") )
    {
        return eSenderId.Speed_Depth_Board;
    }
    if (name.includes("peed") )
    {
        return eSenderId.Speed_Board;
    }
    if (name.includes("ind") )
    {
        return eSenderId.Wind_Board;
    }
    if (name.includes("nalog") )
    {
        return eSenderId.Analog_Board;
    }
    if (name.includes("amping") )
    {
        return eSenderId.Damping;
    }
    if (name.includes("xpedition") )
    {
        return eSenderId.Expedition;
    }
    if (name.includes("oader") )
    {
        return eSenderId.BootLoader;
    }
    if (name.includes("imestamp") )
    {
        return eSenderId.TimeStamp;
    }
    if (name.includes("ATP") )
    {
        return eSenderId.Processor;
    }
    if (name.includes("dla2") )
    {
        return eSenderId.DLA2_Board;
    }
    if (name.includes("mfd") )
    {
        return eSenderId.ATP2_MFD;
    }
    if (name.includes("3020") )
    {
        return eSenderId.ATP2_3020;
    }
    if (name.includes("ata")  || name.includes("ana") )
    {
        return eSenderId.ATP2_ANA;
    }
    if (name.includes("bfd") )
    {
        return eSenderId.BFD;
    }
    if (name.includes("qbd") )
    {
        return eSenderId.QBD;
    }
    return eSenderId.No_Id;
}


//
// Make a sender pair using a id and instance.
//
function makeSenderPair(id, instance) {
    return ((id & 0xff) << 8) | (instance & 0xff);
}

//
// Get sender ID from the pair.
//
function getSenderId(pair) {
    return (pair >> 8) & 0xff;
};

//
// Get sender instance from the pair.
//
function getSenderInstance(pair) {
    return pair & 0xff;
};

//
// Get the sender name from the sender pair.
//
function getSenderNameFromPair(pair) {
    return getSenderName(getSenderId(pair));
}