Example #1
0
// Set senderid, packetcounter and CRC into the partly filled packet, encrypt it using the given AES key number and send it.
void send_packet(uint8_t aes_key_nr, uint8_t packet_len)
{
	pkg_header_set_senderid(device_id);

	inc_packetcounter();
	pkg_header_set_packetcounter(packetcounter);

	// set CRC32
	pkg_header_set_crc32(crc32(bufx + 4, packet_len - 4));
	
	// load AES key (0 is first AES key)
	if (aes_key_nr >= aes_key_count)
	{
		aes_key_nr = aes_key_count - 1;
	}
	
	e2p_basestation_get_aeskey(aes_key_nr, aes_key);
	
	// show info
	decode_data(packet_len);

	// encrypt and send
	__PACKETSIZEBYTES = packet_len;
	rfm12_send_bufx();
}
Example #2
0
// process message "brightness"
void process_brightness(MessageTypeEnum messagetype)
{
	// "Set" or "SetGet" -> modify dimmer state and abort any running animation
	if ((messagetype == MESSAGETYPE_SET) || (messagetype == MESSAGETYPE_SETGET))
	{
		start_brightness = end_brightness = msg_dimmer_brightness_get_brightness();

		UART_PUTF("Requested Brightness: %u%%;", start_brightness);
		
		animation_length = 0;
		animation_mode = 0;
		animation_position = 0;

		setPWMDutyCyclePercent(start_brightness);
						
		/* TODO: Write to EEPROM (?)
		// write back switch state to EEPROM
		switch_state[i] = req_state;
		switch_timeout[i] = req_timeout;
		
		eeprom_write_word((uint16_t*)EEPROM_POS_SWITCH_STATE + i * 2, u16);
		*/
	}

	// remember some values before the packet buffer is destroyed
	uint32_t acksenderid = pkg_header_get_senderid();
	uint32_t ackpacketcounter = pkg_header_get_packetcounter();

	inc_packetcounter();

	// "Set" -> send "Ack"
	if (messagetype == MESSAGETYPE_SET)
	{
		pkg_header_init_dimmer_brightness_ack();

		UART_PUTS("Sending Ack\r\n");
	}
	// "Get" or "SetGet" -> send "AckStatus"
	else
	{
		pkg_header_init_dimmer_brightness_ackstatus();
		
		// set message data
		msg_dimmer_brightness_set_brightness(start_brightness);

		UART_PUTS("Sending AckStatus\r\n");
	}

	// set common fields
	pkg_header_set_senderid(device_id);
	pkg_header_set_packetcounter(packetcounter);
	
	pkg_headerext_common_set_acksenderid(acksenderid);
	pkg_headerext_common_set_ackpacketcounter(ackpacketcounter);
	pkg_headerext_common_set_error(false); // FIXME: Move code for the Ack to a function and also return an Ack when errors occur before!
	
	pkg_header_calc_crc32();
	
	rfm12_send_bufx();
}
void send_prepared_message(void)
{
	inc_packetcounter();
	
	pkg_header_set_senderid(device_id);
	pkg_header_set_packetcounter(packetcounter);
	
	rfm12_send_bufx();
	rfm12_tick(); // send packet, and then WAIT SOME TIME BEFORE GOING TO SLEEP (otherwise packet would not be sent)

	led_blink(200, 0, 1);
}
Example #4
0
void send_version_status(void)
{
	inc_packetcounter();

	UART_PUTF4("Sending Version: v%u.%u.%u (%08lx)\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_HASH);
	
	// Set packet content
	pkg_header_init_generic_version_status();
	pkg_header_set_senderid(device_id);
	pkg_header_set_packetcounter(packetcounter);
	msg_generic_version_set_major(VERSION_MAJOR);
	msg_generic_version_set_minor(VERSION_MINOR);
	msg_generic_version_set_patch(VERSION_PATCH);
	msg_generic_version_set_hash(VERSION_HASH);
	pkg_header_calc_crc32();

	rfm12_send_bufx();
}
Example #5
0
void send_dimmer_status(void)
{
	UART_PUTS("Sending Dimmer Status:\r\n");

	inc_packetcounter();
	uint8_t bri = (uint8_t)current_brightness;
	
	// Set packet content
	pkg_header_init_dimmer_brightness_status();
	pkg_header_set_senderid(device_id);
	pkg_header_set_packetcounter(packetcounter);
	msg_dimmer_brightness_set_brightness(bri);

	pkg_header_calc_crc32();
	
	UART_PUTF("CRC32 is %lx (added as first 4 bytes)\r\n", getBuf32(0));
	UART_PUTF("Brightness: %u%%\r\n", bri);

	rfm12_send_bufx();
}