void processControl(warpnetControl* controlStruct) {
	unsigned char newMod, newCode;

	newMod = ((controlStruct->modOrderPayload) & 0xF);
	newCode = ((controlStruct->codeRatePayload) & 0xF);

	pktGen_length = (controlStruct->pktGen_length);
	pktGen_period = (controlStruct->pktGen_period);

	txPower = ((controlStruct->txPower) & 0x3F);
	warpphy_setTxPower(txPower);
	
	chan = controlStruct->channel;

	xil_printf("Ctrl struct: mod=%d, code=%d, hdr=%d, pktLen=%d, pktPeriod=%d, chan=%d\n", newMod, newCode, controlStruct->modOrderHeader, pktGen_length, pktGen_period, chan);

	switch(newMod) {
		case 1: pktFullRate = HDR_FULLRATE_BPSK; break;
		case 2:	pktFullRate = HDR_FULLRATE_QPSK; break;
		case 4:	pktFullRate = HDR_FULLRATE_QAM_16; break;
		case 6:	pktFullRate = HDR_FULLRATE_QAM_64; break;
		default: pktFullRate = HDR_FULLRATE_QPSK; break;
	}
	
	switch(newCode) {
		case HDR_CODE_RATE_12: pktCodeRate = HDR_CODE_RATE_12; break;
		case HDR_CODE_RATE_23: pktCodeRate = HDR_CODE_RATE_23; break;
		case HDR_CODE_RATE_34: pktCodeRate = HDR_CODE_RATE_34; break;
		case HDR_CODE_RATE_NONE: pktCodeRate = HDR_CODE_RATE_NONE; break;
		default: pktCodeRate = HDR_CODE_RATE_NONE; break;
	}
	
	switch(controlStruct->modOrderHeader) {
		case 1: warpmac_setBaseRate(BPSK); break;
		case 2:	warpmac_setBaseRate(QPSK); break;
		default: warpmac_setBaseRate(QPSK); break;
	}
	
	warpphy_setChannel(GHZ_2, chan);
}
///@brief Main function
///
///This function configures MAC parameters, enables the underlying frameworks, and then loops forever.
int main(){
	
	//Initialize global variables
	chan = 4;
	
	//Assign the packet buffers in the PHY
	// The auto responder can't transmit from buffer 0, so we use it for Rx packets
	// The other assignments (DATA/ACK) are arbitrary; any buffer in [1,30] will work
	pktBuf_rx = 1;
	pktBuf_tx_DATA = 2;
	
	//Set the full-rate modulation to QPSK by default
//	pktFullRate = HDR_FULLRATE_QPSK;
	pktFullRate = HDR_FULLRATE_QAM_16;
	
	//Set the payload coding rate to 3/4 rate by default
	pktCodeRate = HDR_CODE_RATE_34;
	
	//Initialize the MAC/PHY frameworks
	warpmac_init();
	maximumReSend = 8;
	warpmac_setMaxResend(maximumReSend);
	warpmac_setMaxCW(5);
	warpmac_setTimeout(120);
	warpmac_setSlotTime(22);
	
	//Read Dip Switch value from FPGA board.
	//This value will be used as an index into the routing table for other nodes
	myID = (unsigned short int)warpmac_getMyId();
	warpmac_rightHex(myID);
	
	//Configure the PHY and radios for single antenna (SISO) mode
	warpphy_setAntennaMode(TX_ANTMODE_SISO_ANTA, RX_ANTMODE_SISO_ANTA);
	//warpphy_setAntennaMode(TX_ANTMODE_MULTPLX, RX_ANTMODE_MULTPLX);
	//warpphy_setAntennaMode(TX_ANTMODE_ALAMOUTI_ANTA, RX_ANTMODE_ALAMOUTI_ANTA);
	
	//Set the packet detection thresholds
	warpphy_setEnergyDetThresh(7000);		//Min RSSI (in [0,16368])
	warpphy_setAutoCorrDetParams(90, 0);	//Min auto-correlation (in [0,2047])
	warpphy_setLongCorrThresh(8000);		//Min cross-correlation (in [0,45e3])
	
	//Rx buffer is where the EMAC will DMA Wireless payloads from
	warpmac_setRxBuffers(&rxMacframe, pktBuf_rx);
	
	//Tx buffer is where the EMAC will DMA Ethernet payloads to
	warpmac_setPHYTxBuffer(pktBuf_tx_DATA);
	warpmac_setEMACRxBuffer(pktBuf_tx_DATA);
	
	//Set the modulation scheme use for base rate (header) symbols
	warpmac_setBaseRate(QPSK);
	
	//Copy this node's MAC address into the Tx buffer's source address field
	txMacframe.header.srcAddr = (unsigned short int)(NODEID_TO_ADDR(myID));
	
	//Register callbacks
	warpmac_setCallback(EVENT_TIMER, (void *)timer_callback);
	warpmac_setCallback(EVENT_DATAFROMNETWORK, (void *)dataFromNetworkLayer_callback);
	warpmac_setCallback(EVENT_PHYGOODHEADER, (void *)phyRx_goodHeader_callback);
	warpmac_setCallback(EVENT_PHYBADHEADER, (void *)phyRx_badHeader_callback);
	warpmac_setCallback(EVENT_UARTRX, (void *)uartRecv_callback);
	
	//Set the default center frequency
	warpphy_setChannel(GHZ_2, chan);
	
	//Enable carrier sensing
	warpmac_setCSMA(1);
	
	txSeqNum = 0;
	
	//halfmac_server doesn't send ACKs, so skip autoResponder setup
	
	//Listen for new packets to send (either from Ethernet or local dummy packets)
	warpmac_enableDataFromNetwork();
	
	xil_printf("Reference Design v16.1 HALFMAC SERVER\r\n");
	
	xil_printf("Beginning main loop\r\n");
	
	while(1)
	{
		//Poll the timer, PHY and user I/O forever; actual processing will happen via callbacks above
		warpmac_pollPeripherals();
	}
	
	return 0;
}