/*
ECE649 Spring 2010
Group 7
Justin Ray/justinr2
(other names would go here)
 */

package simulator.elevatorcontrol;

import java.util.BitSet;
import simulator.payloads.CanMailbox;
import simulator.payloads.translators.CanPayloadTranslator;



/************************************
CLASS:
VendCanPayloadTranslator
AUTHOR:
Justin Ray
REVISION DATE:
CONSTRUCTOR PARAMETERS:
CanMailbox payload
DESCRIPTION:
CanPayloadTranslators convert between bit-level message representations used in
the CAN network simulation and semantically valid typed representations (e.g.
boolean, int, enum types, etc) used by the Controller classes.

Translators are a convenience feature, but they are also required because they
are used by the MessageInjector to inject network messages into unit and
integration tests.

This translator is used by the CAN network simulation framework for the
mVend message
 *************************************/
public class VendCanPayloadTranslator extends CanPayloadTranslator {

    public VendCanPayloadTranslator(CanMailbox payload) {
        super(payload, 1, MessageDictionary.VEND_CAN_ID);
    }

    //this method is required for reflection
    public void set(boolean vend) {
        setVendState(vend);
    }

    public void setVendState(boolean vend) {
        BitSet b = mailbox.getMessagePayload();
        b.set(0, vend);
        mailbox.setMessagePayload(b, byteSize);
    }

    public boolean getVendState() {
        return mailbox.getMessagePayload().get(0);
    }

    @Override
    public String payloadToString() {
        return "Vend=" + getVendState();
    }

}
