The Internet Power Line Adapter - University of Queensland
The Internet Power Line Adapter - University of Queensland
The Internet Power Line Adapter - University of Queensland
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
/*<br />
* continually update logical link background process<br />
*/<br />
UpdateLL();<br />
/*<br />
* REMOTE DEVICE:<br />
*<br />
* after the "get count" packet has been received, and<br />
when the transmit<br />
* buffer becomes available, load the "received valid<br />
counter" value<br />
* and transmit to the transmitter device<br />
*/<br />
if(GetCountRecd && TxBfrAvailable) {<br />
GetCountRecd = FALSE;<br />
txLPDU.LPDUheader = rxLPDU.LPDUheader;<br />
txLPDU.DA.LSB = 0x01;<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] = COUNT_RESP_PKT;<br />
txLPDU.LSDU[1] = HIGH_BYTE_OF(rxValidCount);<br />
txLPDU.LSDU[2] = LOW_BYTE_OF(rxValidCount);<br />
txLPDU.LPDUlength = CEBUS_HEADER_LEN + 3;<br />
transmitCompleted = FALSE;<br />
TransmitPacket(USE_WTI | USE_DELAY); /* use<br />
WTI w/ delay */<br />
/*<br />
* background processing is complete--free<br />
receive packet buffer resource<br />
*/<br />
RxBfrAvailable = TRUE;<br />
}<br />
/*<br />
* REMOTE DEVICE:<br />
*<br />
* after the "transmit" packet has been received, and<br />
when the transmit buffer becomes available, validate the<br />
received "transmit" packet and, if valid, create the "loop<br />
back" packet and queue the transmission via<br />
LoopbackPktReady (see ProcessValidPacket())<br />
*<br />
* toggle progress LED after every 10 packets with valid<br />
counts<br />
* NOTE: A "valid" packet contains valid count AND<br />
valid info in rest<br />
* <strong>of</strong> body (see ProcessValidPacket())<br />
*/<br />
if (TransPktRecd && TxBfrAvailable) {<br />
TransPktRecd = FALSE;<br />
/*<br />
* get received packet's count<br />
*/<br />
tempCtr = (((unsigned short int)rxLPDU.LSDU[1]) rxCount) {<br />
rxCount = tempCtr + 1;<br />
ProcessValidPacket();<br />
}<br />
if ((rxCount % 10) == 0)<br />
LED_1 = !LED_1;<br />
/*<br />
* background processing is complete--free<br />
receive packet buffer resource<br />
*/<br />
RxBfrAvailable = TRUE;<br />
}<br />
/*<br />
* TRANSMITTER & REMOTE DEVICES:<br />
* get current transmit status and process<br />
*/<br />
status = ConfirmTransmitPacket();<br />
if (status==SUCCESS || status==FAILURE)<br />
if(transmitting && (status==SUCCESS) )<br />
txSuccess++;<br />
transmitCompleted = TRUE;<br />
}<br />
/*<br />
* TRANSMITTER DEVICE:<br />
* when currently transmitting and after completing a<br />
transmit and when<br />
* no longer waiting for the remote device to loop back<br />
the packet,<br />
* process the next transmit packet unless the transmit<br />
test is ended<br />
*/<br />
if (transmitting && !waitingForLoopback &&<br />
transmitCompleted)<br />
if(!ProcessTransmitEnd(FALSE)) /* if not end,<br />
transmit next packet */<br />
XmitOriginal();<br />
/*<br />
* REMOTE DEVICE:<br />
* when loopback packet is loaded and transmit<br />
completed, send loopback<br />
* packet to transmitter device<br />
*/<br />
if(LoopbackPktReady && transmitCompleted) {<br />
LoopbackPktReady = FALSE;<br />
transmitCompleted = FALSE;<br />
TransmitPacket(USE_WTI | USE_DELAY);<br />
}<br />
/*<br />
* TRANSMITTER DEVICE:<br />
* if "loopback" or response packet has not been<br />
received from remote device<br />
* in two seconds, continue with next transmit or send<br />
transmitter device ONLY<br />
* statistics to host<br />
*/<br />
if(responseTimerRunning) {<br />
if(response_timer == GetVeryLowResTimeByte()<br />
) else {<br />
responseTimerRunning = FALSE;<br />
if(waitingForLoopback) {<br />
if(!ProcessTransmitEnd(FALSE)) /* if not end, transmit<br />
next packet */<br />
XmitOriginal();<br />
} else {