inline void send_data_to_server(){
if(timer_counter == 10){
	payload_length = 0;

	// Clear Tx packet buffer
	cntr = 0;
	for (cntr=RF_BUFFER_SIZE; cntr > 0; cntr--)
		TxPacket[cntr] = 0;

	// Construct the packet
	// This is the place where you can put your own data to send
	TxPacket[payload_length++] = PKT_CTRL | PKT_CTRL_REQUEST;
	//TxPacket[payload_length++] = PKT_TYPE_VOLTAGE;
	TxPacket[payload_length++] = 68;						// Setting packet type as 'D'
	TxPacket[payload_length++] = water_high_byte;
	TxPacket[payload_length++] = water_low_byte;
	TxPacket[payload_length++] = water_temperature;

	// Print out all data that we are goind to send

	// Payload length includes Control packet and does not take into account
	// packet encryption nor source, destination adress bytes. Only actual payload that
	// you have defined above
	/*UART_Send_Data("\r\nPayload length:\t");
	UART0_Send_ByteToChar(&payload_length);

	UART_Send_Data("\r\nDestination address: ");

	UART0_Send_ByteToChar(&addr_remote);

	UART_Send_Data("\r\nMessage: ");
	for (cntr = 1; cntr < payload_length; cntr++) {
		UART0_Send_ByteToChar(&TxPacket[cntr]);
	} */
	/* NWK level data sending */
	Print_Error(Radio_Send_Data(TxPacket, payload_length, addr_remote, PAYLOAD_ENC_OFF, PCKT_ACK_ON));

	// reset water data
	water_high_byte = 0;
	water_low_byte = 0;

	//UART_Send_Data("\r\nERR: ");
	//UART0_Send_ByteToChar((uint8 *)exit_code);
	exit_code = 0;

	//UART_Send_Data("\r\n");		// Insert new line to separate packets


	// Add some delay (around 2sec)
	//__delay_cycles(5000000*SYSTEM_SPEED_MHZ);
}
}
/***************************************************************************************************
 *         Main section                                                                            *
 ***************************************************************************************************/
void main(void) {

	WDTCTL = WDTPW | WDTHOLD;

		if(CALBC1_1MHZ==0xFF)
		{
			while(1);
		}
		DCOCTL = 0;
		BCSCTL1 = CALBC1_1MHZ;
		DCOCTL = CALDCO_1MHZ;

//	    LED_DIR = (LED_0 ); //LEDs are set as output
//	    LED_OUT &= ~(LED_0 ); //LEDs are turned off

		P1SEL  |= BIT1 + BIT2;	 	//Enable module function on pin
		P1SEL2 |= BIT1 + BIT2;  	//Select second module; P1.1 = RXD, P1.2=TXD

		UCA0CTL1 |= UCSSEL_2;    	// Set clock source SMCLK
		UCA0BR0 = 104;           	// 1MHz 9600 (N=BRCLK/baudrate)
		UCA0BR1 = 0;             	// 1MHz 9600
		UCA0MCTL = UCBRS0;       	// Modulation UCBRSx = 1
		UCA0CTL1 &= ~UCSWRST;    	// **Initialize USCI state machine**

		IE2 |= UCA0RXIE;         	//enable RX interrupt

		__enable_interrupt();
//	uint8 cntr = 0;

	// Initialize system
	Print_Error(System_Init());

	while (1) {

		if (process == 1)
		{
				request = compareArrays(data_transmit_buffer, data_memory_buffer, data_slots);
//				request = critical_request(model_output);
				process = 0;
		}
		if (request == 1)
		{
			payload_length = 0;

			// Construct the packet
			// This is the place where you can put your own data to send
			TxPacket[payload_length++] = PKT_CTRL | PKT_CTRL_REQUEST;
			TxPacket[payload_length++] = 'S';
			TxPacket[payload_length++] = data_transmit_buffer[0];
			TxPacket[payload_length++] = data_transmit_buffer[1];
			TxPacket[payload_length++] = data_transmit_buffer[2];
			TxPacket[payload_length++] = data_transmit_buffer[3];
			TxPacket[payload_length++] = data_transmit_buffer[4];
			TxPacket[payload_length++] = data_transmit_buffer[5];

			// Send data over RF and get the exit code to check for errors
			exit_code = Radio_Send_Data(TxPacket, payload_length, ADDR_REMOTE, PAYLOAD_ENC_OFF, PCKT_ACK_ON);

			// Add some delay (around 2sec)
			__delay_cycles(5000000*SYSTEM_SPEED_MHZ);

			request = 0;
		}
	}
}
Esempio n. 3
0
/***************************************************************************************************
 *         Main section                                                                            *
 ***************************************************************************************************/
void main(void) {

	// Initialize system
	Print_Error(System_Init());

	WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

	/* Start : CPU clock configuration */

	if (CALBC1_1MHZ==0xFF)		    // If calibration constant erased
	{
		while(1);                   // do not load, trap CPU
	}
	DCOCTL = 0;                     // Select lowest DCOx and MODx settings
	BCSCTL1 = CALBC1_1MHZ;          // Set DCO to 1MHz
	DCOCTL = CALDCO_1MHZ;

	/* End : CPU clock configuration */

	/* Start : data pin configuration */

	P1IE |= DATA_PIN;					// DATA_PIN interrupt enabled
//    P1IES |= DATA_PIN;					// DATA_PIN HI to LOW edge
	P1IFG &= ~DATA_PIN;					// DATA_PIN IFG cleared

	/* End : data pin configuration */

	/* Start : Timer interrupt configuration */

	TACCTL0 = CCIE;						// TACCR0 interrupt enabled
	TACCR0 = 32768;						// Interrupt every one second (
	TACTL = TASSEL_1 + ID_0 + MC_1; 	// Set the timer A to ACLK, divide clock cycle by 1, Up mode

	/* End : Timer interrupt configuration */

	__enable_interrupt();				// Enabling interrupt
	__bis_SR_register(LPM0 + GIE);		// LPM0 with interrupts enabled

	while (1) {

		payload_length = 0;

		// Clear Tx packet buffer
		cntr = 0;
		for (cntr=RF_BUFFER_SIZE; cntr > 0; cntr--)
			TxPacket[cntr] = 0;

		// Construct the packet
		// This is the place where you can put your own data to send
		TxPacket[payload_length++] = PKT_CTRL | PKT_CTRL_REQUEST;
		TxPacket[payload_length++] = PKT_TYPE_VOLTAGE;
		TxPacket[payload_length++] = 255;
		TxPacket[payload_length++] = 90;

		// Print out all data that we are goind to send

		// Payload length includes Control packet and does not take into account
		// packet encryption nor source, destination adress bytes. Only actual payload that
		// you have defined above
		UART_Send_Data("\r\nPayload length:\t");
		UART0_Send_ByteToChar(&payload_length);

		UART_Send_Data("\r\nDestination address: ");

		UART0_Send_ByteToChar(&addr_remote);

		UART_Send_Data("\r\nMessage: ");
		for (cntr = 1; cntr < payload_length; cntr++) {
			UART0_Send_ByteToChar(&TxPacket[cntr]);
		}

		/* NWK level data sending */
		Print_Error(Radio_Send_Data(TxPacket, payload_length, addr_remote, PAYLOAD_ENC_ON, PCKT_ACK_ON));

		//UART_Send_Data("\r\nERR: ");
		//UART0_Send_ByteToChar((uint8 *)exit_code);
		exit_code = 0;

		UART_Send_Data("\r\n");		// Insert new line to separate packets


		// Add some delay (around 2sec)
		__delay_cycles(5000000*SYSTEM_SPEED_MHZ);

	}
}		/* END: main */