Exemplo n.º 1
0
/**
  * @brief  This function generates a device to base station packet, uses a reverse COBS format that requires working backwards from end of packet
  * @param  Pointer to output buffer, pointer to input data, number of data bytes, device ID on the network, pointer to sequence number (iterates)
  * @retval None
  */
void RN42_generate_packet(uint8_t* data_payload, uint8_t number_bytes, uint8_t device_network_id, uint8_t* sequence_number) {
	const uint8_t header=HEAD;
	Add_To_Buffer(&header,&Usart1_tx_buff);
	Add_To_Buffer(&device_network_id,&Usart1_tx_buff);//Packet header consists of device network id byte and sequence number (for scrolling graph smoothness)
	Add_To_Buffer(sequence_number,&Usart1_tx_buff);//This is similar to HDLC packet format
	uint8_t skip=1;
	for(uint8_t n=0; n<number_bytes; n++) {
		if(data_payload[n]==HEAD) {
			__usart_send_char(skip);	//The send_char routine is used here as it will kick start the interrupt driven usart comms if needs be
			skip=1;
		}
		else {
			skip++;
			__usart_send_char(data_payload[n]);
		}
	}
	__usart_send_char(skip);			//Work backwards from the end of the packet, skipping skip bytes and replacing with HEAD until packet header
	*sequence_number++;				//Incriment this
}
Exemplo n.º 2
0
void usart_send_str(char* str) {
    unsigned short int i = 0;
    while(str[i] != 0x00)
        __usart_send_char(str[i++]);
}