Exemplo n.º 1
0
// ----------------------------------------------------------------------------
// enocean_main function wird von while(1) aufgerufen
void enocean_main(void) {

	for (uint8_t i = 0; i < ENOCEAN_CHANNEL_COUNT; i++) {

		if (enocean_channel_state[i] & ENOCEAN_CHANNEL_ACT)
		{
			uint8_t ret = enocean_packet_send(ENOCEAN_CHANNEL_OFFSET+i,enocean_channel_state[i] & ENOCEAN_CHANNEL_STATUS);
			if (ret == true)
			{
				enocean_channel_state[i] &= ~ENOCEAN_CHANNEL_ACT;
			}
		}

		if (enocean_channel_state[i] & ENOCEAN_CHANNEL_EEPROM)
		{
			enocean_channel_state[i] &= ~ENOCEAN_CHANNEL_EEPROM;
			eeprom_write_byte((unsigned char *)ENOCEAN_CHANNEL_EEPROM_STORE+i, enocean_channel_state[i] & ENOCEAN_CHANNEL_STATUS);	
		}
	
	}
	
}
Exemplo n.º 2
0
void shackbus_main(void)
{
	if ( fifo_get_count(&can_outfifo) > 0  )
	{
		uint8_t cur_nr = fifo_read (&can_outfifo);
		if ( can_send_message(&framestorage_data[cur_nr]) )
		{
			fifo_get (&can_outfifo);
			framestorage_get(cur_nr);
		}
	}

	if (shackbus_msg_send_flag)
	{
		can_t msg;
		shackbus_id_t shackbus_id;


		shackbus_msg_send_flag = 0;

		shackbus_id.prio = 3;
		shackbus_id.vlan = 4;
		shackbus_id.dst  = 255;
		shackbus_id.src  = 6;
		shackbus_id.prot = 13;

		memset(&msg,0,sizeof(can_t));
		msg.id = shackbus_sb2id(&shackbus_id);
		msg.length = 1;
		msg.flags.extended = 1;
		msg.flags.rtr = 0;

		if (MAINSWITCH_STATE)
			msg.data[0] = 1;
		else
			msg.data[0] = 0;

		//Send the new message
		can_send_message_fifo(&msg);
	}


	// Check if a new messag was received
	if (can_check_message())
	{
		can_t msg;

		// Try to read the message
		if (can_get_message(&msg))
		{
			if (msg.id == 0x1FF && msg.flags.extended == 1)
			{
				led_set(99,0);
			}
			shackbus_id_t shackbus_id;
			shackbus_id2sb(&shackbus_id,&msg);

			if (shackbus_id.prot == 9 && shackbus_id.dst == 6 && msg.data[0]<12)
			{
				if (msg.data[1]==1) enocean_state_set(msg.data[0],ENOCEAN_CHANNEL_SE_SA_SS);
				if (msg.data[1]==0) enocean_state_set(msg.data[0],ENOCEAN_CHANNEL_SE_SA_CS);

				//Send the new message
				//shackbus_send_msg(msg.data[0], msg.data[1]);
			}

			//prot=10 = Basis IO data[0]=10 = Ping
			if (shackbus_id.prot == 10 && shackbus_id.dst == 6 && msg.data[0]==10)
			{
				shackbus_id.prio = 3;
				shackbus_id.vlan = 4;
				shackbus_id.dst  = shackbus_id.src;
				shackbus_id.src  = 6;
				shackbus_id.prot = 10;

				msg.id = shackbus_sb2id(&shackbus_id);
				msg.length = 2;
				msg.data[0] = 11;
				msg.data[1] = msg.data[1];

				//Send the new message
				can_send_message_fifo(&msg);
			}

			//prot=10 = Basis IO data[0]=04 = Jump2Bootloader
			if (shackbus_id.prot == 10 && shackbus_id.dst == 6 && msg.data[0]==04)
			{
				cli();
				wdt_enable(WDTO_15MS);
				while (1);
			}

			/* prot=11 = PowerManagement data[0]=1 =on/off data[1]=channel data[2]=state */
			/* channel 120 = Hauptschalter      */
			/* channel 140 0x8c = DLE Dusche    */
			/* channel 141 0x8d = DLE E-Lab     */
			/* channel 142 0x8e = Optionsraeume  */
			/* channel 143 0x8f = Kueche         */
			if (shackbus_id.prot == 11 && shackbus_id.dst == 6 && msg.data[0]==1)
			{
				shackbus_id.prio = 3;
				shackbus_id.vlan = 4;
				shackbus_id.dst  = shackbus_id.src;
				shackbus_id.src  = 6;
				shackbus_id.prot = 11;

				msg.id = shackbus_sb2id(&shackbus_id);
				msg.length = 3;
				msg.data[0] = 1;
				msg.data[1] = msg.data[1];
				msg.data[2] = msg.data[2];

				/* Send the message */
				can_send_message_fifo(&msg);
				enocean_packet_send(msg.data[1], msg.data[2]);
			}
		}
	}

	if (shackbus_system_time_send_flag >= 60)
	{
		shackbus_system_time_send_flag = 0;

		shackbus_id_t ka_id;
		ka_id.prio = 1;
		ka_id.vlan = 3;
		ka_id.dst  = 255;
		ka_id.src  = 6;
		ka_id.prot = 2;

		can_t ka;
		memset(&ka,0,sizeof(can_t));
		ka.id = shackbus_sb2id(&ka_id);
		ka.length = 8;

		ka.flags.extended = 1;
		ka.flags.rtr = 0;

		uint8_t sreg = SREG;
		cli();

		for (uint8_t i = 0;i<8;i++)
			ka.data[i] = system_time.type8[i];

		SREG = sreg;

		can_send_message_fifo(&ka);
	}

}