30.11.2012 Views

The Internet Power Line Adapter - University of Queensland

The Internet Power Line Adapter - University of Queensland

The Internet Power Line Adapter - University of Queensland

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />

* TRANSMITTING DEVICE:<br />

*<br />

* retrieve house code and initialize NIC<br />

*/<br />

config.systemAddr.MSB = rbuffer.buf[1];<br />

config.systemAddr.LSB = rbuffer.buf[0];<br />

config.unitAddr.LSB = 0x01;<br />

config.unitAddr.MSB = 0x00;<br />

transmitter = TRUE; /* set transmitter device<br />

status */<br />

testRunning = FALSE;<br />

DisableInterrupts();<br />

rbuffer.state = REC_IDLE; /* reset serial state to<br />

idle */<br />

EnableInterrupts();<br />

InitializeLL();<br />

/*<br />

* transmit "setup" packet to remote device if transmit<br />

buffer available<br />

*/<br />

if(TxBfrAvailable) {<br />

txLPDU.LPDUheader = UNACK |<br />

STD_PRIORITY | BASIC_SERVICE;<br />

txLPDU.DA.LSB = 0x00;<br />

txLPDU.DA.MSB = 0x00;<br />

txLPDU.DHC.LSB = 0x00;<br />

txLPDU.DHC.MSB = 0x00;<br />

txLPDU.SA.LSB = config.unitAddr.LSB;<br />

txLPDU.SA.MSB = config.unitAddr.MSB;<br />

txLPDU.SHC.LSB = config.systemAddr.LSB;<br />

txLPDU.SHC.MSB = config.systemAddr.MSB;<br />

txLPDU.LSDU[0] = SETUP_PKT;<br />

*(uint16 *)&txLPDU.LSDU[1] = config.systemAddr;<br />

txLPDU.LPDUlength = CEBUS_HEADER_LEN + 3;<br />

transmitCompleted = FALSE;<br />

TransmitPacket(0); /* use PT command w/o delay */<br />

/*<br />

* respond to host with NIC type<br />

*/<br />

if(!tbufferInUse) {<br />

tbuffer.functionID = NIC_ID_CMD;<br />

tbuffer.buf = &type;<br />

ResponseToHost(size<strong>of</strong>(uint8));<br />

}<br />

transmitting = FALSE; /* wait for "start"<br />

command */<br />

}<br />

}<br />

void RecdSetupPkt( void )<br />

{<br />

/*<br />

* REMOTE DEVICE:<br />

*<br />

* retrieve house code and initialize NIC<br />

*/<br />

config.systemAddr.MSB = rxLPDU.LSDU[2];<br />

config.systemAddr.LSB = rxLPDU.LSDU[1];<br />

config.unitAddr.LSB = 0x02;<br />

config.unitAddr.MSB = 0x00;<br />

transmitter = FALSE; /* set remote device<br />

status*/<br />

InitializeLL();<br />

/*<br />

* reset counters<br />

*/<br />

rxCount = 0;<br />

rxValidCount = 0;<br />

}<br />

- 56 -<br />

void XmitOriginal( void )<br />

{<br />

uint8 i; /* local counter */<br />

static uint8 temp[2]; /* temporary storage */<br />

/*<br />

* TRANSMITTING DEVICE:<br />

*<br />

* load contents <strong>of</strong> transmit buffer (if available) with<br />

running transmit<br />

* count and fill rest <strong>of</strong> info field (up to host specified<br />

length)<br />

* with predictable data (for comparison purposes at<br />

remote device)<br />

*/<br />

if (TxBfrAvailable) {<br />

txLPDU.LPDUheader = txService |<br />

STD_PRIORITY | BASIC_SERVICE;<br />

txLPDU.DA.LSB = 0x02;<br />

txLPDU.DA.MSB = 0x00;<br />

txLPDU.DHC.LSB = config.systemAddr.LSB;<br />

txLPDU.DHC.MSB = config.systemAddr.MSB;<br />

txLPDU.SA.LSB = config.unitAddr.LSB;<br />

txLPDU.SA.MSB = config.unitAddr.MSB;<br />

txLPDU.SHC.LSB = config.systemAddr.LSB;<br />

txLPDU.SHC.MSB = config.systemAddr.MSB;<br />

txLPDU.LSDU[0] = TRANS_PKT;<br />

txLPDU.LSDU[1] = HIGH_BYTE_OF(txCount);<br />

txLPDU.LSDU[2] = LOW_BYTE_OF(txCount);<br />

for(i=0;i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!