Example #1
0
int main (void) {
    /*
     * SPI-Modul initialisieren */
    spi_init();

    /*
     * Funkmodul initialisieren */
    rfm12_init();
    rfm12_rx_on();

    /*
     * CAN-Bus initialisieren */
    mcp2515_init();

    /* Interrupts initialisieren */
    interrupt_init();

    /*
     * Hauptprogramm */
    while (1) {
        if (rfm_new_data) {
            rfm_new_data = 0;
            cli();
            struct rfm_message tmp_rfm_message;
            if (rfm_copy_data(&tmp_rfm_message)) {
                struct can_message tmp_can_message;
                tmp_can_message.typ = tmp_rfm_message.typ;
                tmp_can_message.rtr = tmp_rfm_message.rtr;
                tmp_can_message.id = tmp_rfm_message.id;
                tmp_can_message.length = tmp_rfm_message.length;
                for (uint8_t i=0; i<8; i++) {
                    tmp_can_message.data[i] = tmp_rfm_message.data[i];
                }
                can_send_message(&tmp_can_message);
            }
            sei();
        }

        if (rfm_crc_error != rfm_crc_error_last) {
            struct can_message tmp_can_message;
            tmp_can_message.typ = Einzelmeldung;
            tmp_can_message.id = Funkkoppler_CRC_Error;
            tmp_can_message.length = Laenge_Einzelmeldung;
            tmp_can_message.data[0] = rfm_crc_error;
            can_send_message(&tmp_can_message);
            rfm_crc_error_last = rfm_crc_error;
        }

        set_sleep_mode(SLEEP_MODE_STANDBY);
        sleep_mode();
    }
}
void send_write_response(void)
{
	uint8_t passkey, write_data, ret_val, verify, req_by;
	uint8_t* write_ptr;
	
	passkey = write_arr[3];
	write_ptr = write_arr[1];
	write_data = write_arr[0];
	req_by = read_arr[7];	// Used to coordinating with tasks on the OBC.
	
	/*	Execute the Write	*/
	*write_ptr = write_data;
	
	/* Verify the write worked correctly	*/
	verify = *write_ptr;
	if (verify != write_data)
		ret_val = -1;
	else
		ret_val = 1;
	
	send_arr[7] = (SELF_ID << 4)|req_by;
	send_arr[6] = MT_COM;
	send_arr[5] = ACK_WRITE;
	send_arr[4] = CURRENT_MINUTE;
	send_arr[3] = passkey;
	send_arr[0] = ret_val;
	
	can_send_message(&(send_arr[0]), CAN1_MB7);
	write_response = 0;
	return;	
}
Example #3
0
/**
 * \brief send CAN message to instrument cluster
 * \param msg - pointer to CAN message
 */
void ic_comm_send2Cluster(can_t* msg)
{
   while(0 == can_send_message(CAN_CHIP1, msg))
   {
      _delay_us(10);
   }
}
Example #4
0
int main(void)
{
	// Initialize MCP2515
	can_init(BITRATE_125_KBPS);
	
	// Load filters and masks
	can_static_filter(can_filter);
	
	// Create a test messsage
	can_t msg;
	
	msg.id = 0x123456;
	msg.flags.rtr = 0;
	msg.flags.extended = 1;
	
	msg.length = 4;
	msg.data[0] = 0xde;
	msg.data[1] = 0xad;
	msg.data[2] = 0xbe;
	msg.data[3] = 0xef;
	
	// Send the message
	can_send_message(&msg);
	
	while (1)
	{
		// 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 we received a message resend it with a different id
				msg.id += 10;
				
				// Send the new message
				can_send_message(&msg);
			}
		}
	}
	
	return 0;
}
// It is assumed that send_arr[3-0] have already been filled before executing this function.
static void send_tc_can_msg(uint8_t packet_count)
{
	send_arr[7] = (SELF_ID << 4)|OBC_PACKET_ROUTER_ID;
	send_arr[6] = MT_COM;
	send_arr[5] = SEND_TC;
	send_arr[4] = packet_count;
	can_send_message(&(send_arr[0]), CAN1_MB7);
	return;
}
// Lets the OBC know that we have a TC packet ready.
void alert_obc_tcp_ready(void)
{
	send_arr[7] = (SELF_ID << 4)|OBC_PACKET_ROUTER_ID;
	send_arr[6] = MT_COM;
	send_arr[5] = TC_PACKET_READY;
	send_arr[4] = CURRENT_MINUTE;
	can_send_message(&(send_arr[0]), CAN1_MB7);
	return;
}
void send_ask_alive(void)
{
	send_arr[7] = (SELF_ID << 4)|OBC_ID;
	send_arr[6] = MT_COM;
	send_arr[5] = ASK_OBC_ALIVE;
	send_arr[4] = CURRENT_MINUTE;
	can_send_message(&(send_arr[0]), CAN1_MB7);
	ask_alive = 0;
	return;
}
void send_housekeeping(void)
{	
	send_arr[7] = (SELF_ID << 4)|HK_TASK_ID;
	send_arr[6] = MT_HK;	// HK will likely require multiple message in the future.
	send_arr[4] = CURRENT_MINUTE;

	can_send_message(&(send_arr[0]), CAN1_MB6);		//CAN1_MB6 is the HK reception MB.
	send_hk = 0;
	return;
}
// Let the OBC know that you are ready to receive TM packet.
static void start_tm_packet(void)
{
	send_arr[7] = (SELF_ID << 4)|COMS_TASK_ID;
	send_arr[6] = MT_COM;
	send_arr[5] = OK_START_TM_PACKET;
	send_arr[4] = CURRENT_MINUTE;
	receiving_tmf = 1;
	can_send_message(&(send_arr[0]), CAN1_MB7);
	return;
}
void send_response(void)
{
	send_arr[7] = (SELF_ID << 4)|OBC_ID;
	send_arr[6] = MT_COM;
	send_arr[5] = RESPONSE;
	send_arr[4] = CURRENT_MINUTE;

	can_send_message(&(send_arr[0]), CAN1_MB7);		//CAN1_MB7 is the command reception MB.
	send_now = 0;
	return;
}
void exit_take_over(void)
{
	TAKEOVER = 0;
	exit_take_overf = 0;
	send_arr[7] = (SELF_ID << 4)|OBC_ID;
	send_arr[6] = MT_COM;
	send_arr[5] = COMS_TAKEOVER_EXITED;
	send_arr[4] = CURRENT_MINUTE;
	can_send_message(&(send_arr[0]), CAN1_MB7);
	return;
}
void resume_operations(void)
{
	PAUSE = 0;
	resume_operationsf = 0;
	send_arr[7] = (SELF_ID << 4)|OBC_ID;
	send_arr[6] = MT_COM;
	send_arr[5] = OPERATIONS_RESUMED;
	send_arr[4] = CURRENT_MINUTE;
	can_send_message(&(send_arr[0]), CAN1_MB7);
	return;	
}
Example #13
0
File: poti.cpp Project: uqs/avalon
int main (int argc, const char * argv[])
{
    double angle;
    int num_tick;
    can_init("/dev/ttyUSB4");
    
	//can_send_message(&msg_poti_set_counterclockwise);
	can_send_message(&msg_poti_save);
	rtx_message("0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X", message.id, message.content[0], message.content[1], message.content[2], message.content[3], message.content[4], message.content[5], message.content[6], message.content[7]);
    while (0)
    {
		can_send_message(&msg_poti_pos_request);
	can_read_message();
	num_tick = int(message.content[4])+int(message.content[5])*256+int(message.content[6])*256*256 + int(message.content[7])*256*256*256;
	angle = remainder((num_tick%AV_POTI_RESOLUTION)*360.0/AV_POTI_RESOLUTION,360.0);
	rtx_message("angle: %f",angle);
	}
	// The destructors will take care of cleaning up the memory
    return (0);

}
void send_coms_packet(void)
{			
	send_arr[7] = (SELF_ID << 4)|OBC_ID;
	send_arr[6] = MT_DATA;
	send_arr[5] = COMS_PACKET;
	send_arr[4] = CURRENT_MINUTE;
	send_arr[0] = trans_msg[0];	// ASCII character which was received.
	
	can_send_message(&(send_arr[0]), CAN1_MB0);		//CAN1_MB0 is the data reception MB.
	msg_received = 0;
	return;
}
void exit_low_power(void)
{	
	// Sam: Fill this in with what needs to be done to exit low power mode.
	LOW_POWER_MODE = 0;
	exit_low_powerf = 0;
	send_arr[7] = (SELF_ID << 4)|OBC_ID;
	send_arr[6] = MT_COM;
	send_arr[5] = LOW_POWER_MODE_EXITED;
	send_arr[4] = CURRENT_MINUTE;
	can_send_message(&(send_arr[0]), CAN1_MB7);
	return;	
}
// Helper
static void send_tm_transaction_response(uint8_t req_by, uint8_t code)
{			
	send_arr[7] = (SELF_ID << 4)|req_by;
	send_arr[6] = MT_COM;
	send_arr[5] = TM_TRANSACTION_RESP;
	send_arr[4] = CURRENT_MINUTE;
	send_arr[3] = 0;
	send_arr[2] = 0;
	send_arr[1] = 0;
	send_arr[0] = code;
	can_send_message(&(send_arr[0]), CAN1_MB7);
	return;
}
Example #17
0
void sendResolverNMTMessage(void)
{
	can_t NMTMsg;
    NMTMsg.id = 0x00; 
    NMTMsg.flags.rtr = 0;	// The sent message is NOT a remote-transmit-request frame
    NMTMsg.flags.extended = 0;	// Sends the message with standard ID
    NMTMsg.length = 2;	// Message length is 8 bytes
   
	NMTMsg.data[0] = 0x01;
	NMTMsg.data[1] = 0x00;	//0x00 for all resolvers

	can_send_message(&NMTMsg);
}
// event_readyf should be set when an event to report on has been placed in event_arr[]
void send_event(void)
{
	send_arr[7] = (SELF_ID << 4)|OBC_PACKET_ROUTER_ID;
	send_arr[6] = MT_COM;
	send_arr[5] = SEND_EVENT;
	send_arr[4] = CURRENT_MINUTE;
	send_arr[3] = event_arr[3];		// 1=Normal, 2=low-sev error, 3=med-sev, 4=high-sev
	send_arr[2] = event_arr[2];		// ReportID
	send_arr[1] = event_arr[1];
	send_arr[0] = event_arr[0];
	can_send_message(&(send_arr[0]), CAN1_MB7);
	return;
}
Example #19
0
void status(char *msg)
{
	cmsg.id = CAN_STATUS_ID;
	if( msg != NULL )
	{
		cmsg.length = 8;
		memcpy((void *)cmsg.data, msg, 8);
	}
	else
	{
		cmsg.length = 0;
	}
	can_send_message((const can_t *)&cmsg);
}
Example #20
0
/**
 * @brief Envia o estado do sistema via CAN
 *
 * @param estados é a variável que armazena os estados
 *
 */
void sendSystemStatusCAN(estados_t estados)
{
	// Cria e define o tamanho do pacote
	can_t msg;
	msg.id = MY_CAN_ID;			    // define o ID da mensagem
	msg.flags.rtr = 0;				// define como um data frame
	msg.length = MY_CAN_MSG_LENGHT;	// define o comprimento da mensagem
	
	// Empacota os dados a serem enviados via can.
    //msg.data[0] = estados;
	msg.data[0] = 123;

	// Envia o pacote
	can_send_message(&msg);
}
Example #21
0
void Speedo_CAN::process_incoming_messages(){
	while(can_get_message(&message)!=0xff){ //0xff=no more frames available
#ifdef CAN_DEBUG /////////////// DEBUG //////////
		Serial.print("*");
#endif
		if(can_missed_count==999){
			can_missed_count=0;
		} else if(can_missed_count>1){
			can_missed_count-=2;
		} else if(can_missed_count>0){
			can_missed_count-=1;
		};
		last_received=millis();
		//		Serial.println("New CAN Message found");
		////////////////////////////////////////////////////////////////////////////////
		/////////////////// Triumph Daytone 675 Tacho request //////////////////////////
		////////////////////////////////////////////////////////////////////////////////
		if(message.id==0x568){
			message.length=2;
			message.id=0x569;
			message.data[0]=0x00;
			message.data[1]=0x01;
			can_send_message(&message);
		}
		////////////////////////////////////////////////////////////////////////////////
		//////////////////// Triumph Daytone 675 RPM/Speed  ////////////////////////////
		////////////////////////////////////////////////////////////////////////////////
		else if(message.id==0x530){ // Triumph Daytone 675 Tacho request
			can_rpm=(message.data[1]<<6)|(message.data[0]>>2);
			can_speed=round(pSensors->flatIt((int)(((message.data[3]<<8)|(message.data[2]))/10),&can_speed_counter,4,can_speed)); // IIR 4 Tabs
			//can_speed=(((message.data[3]<<8)|(message.data[2]))/10); // raw
#ifdef CAN_DEBUG /////////////// DEBUG //////////
			Serial.print("RPM:");
			Serial.print(can_rpm);
			Serial.print(" Speed:");
			Serial.print(can_speed);
#endif
			if(can_rpm>0){
				high_prio_processing=false;
			};
		}
		////////////////////////////////////////////////////////////////////////////////
		///////////////////// Triumph Daytone 675 Temperatur ///////////////////////////
		////////////////////////////////////////////////////////////////////////////////
		else if(message.id==0x570){ // Triumph Daytone 675 Tacho request
Example #22
0
void canix_frame_send_with_prio(const canix_frame *frame, uint8_t prio)
{
	// Nachschauen, ob der TX Buffer des MCP frei ist:
	
	if (can_any_sendable())
	{
		// Frame ueber CAN versenden ...
		uint32_t extid;
		extid = (frame->src & ADDR_MASK) |
			((uint32_t)(frame->dst & ADDR_MASK) << 10) |
			((uint32_t)(frame->proto & PROTO_MASK) << 20) |
			((uint32_t)(prio) << 24);
		can_send_message(extid, frame->data, frame->size);
	}

	// und jetzt noch lokal zustellen - auch wenn das Frame in die TX Queue
	// gestellt wurde:
	canix_deliver_frame(frame);
}
Example #23
0
/********************************************* CAN FUNCTIONS ***********************************/
void Speedo_CAN::request(char mode,char PID){
	byte can_first_byte=0x02; //frame im Datenstrom


	//check valid msg
	if(mode!=CAN_CURRENT_INFO && mode!=CAN_DTC){
		return;
	} else if(mode==CAN_DTC) {
		can_first_byte=0x01;
		can_dtc_errors_processed=0; //reset value since we are asing for a new one
		can_dtc_nr=PID; // we reuse PID to save the number of the error code we are locking for, so we can ask for up to 255 error codes
		can_dtc_value=0x00;
	} else if(mode==CAN_CURRENT_INFO){
		if(PID!=CAN_AIR_TEMP && PID!=CAN_WATER_TEMPERATURE && PID!=CAN_RPM && PID!=CAN_SPEED && PID!=CAN_MIL_STATUS){
			return;
		}
		can_first_byte=0x02;
	}

	// BUILD MESSAGE
	message.id = 0x07DF; // motor steuergerät .. TODO: Ist die fix?
	message.rtr = 0;

	message.length = 8;
	message.data[0] = can_first_byte;
	message.data[1] = mode; //mode 01==data, 03=dtc
	message.data[2] = PID;
	message.data[3] = 0x00; // fill up thus 8 byte are needed
	message.data[4] = 0x00;
	message.data[5] = 0x00;
	message.data[6] = 0x00;
	message.data[7] = 0x00;

	// Nachricht verschicken
	last_request=millis();
	can_send_message(&message);
	return;
};
void send_read_response(void)
{
	uint8_t read_val, passkey, req_by;
	uint8_t* read_ptr;
	
	passkey = read_arr[3];
	read_ptr = read_arr[0];
	req_by = read_arr[7];	// Used to coordinating with tasks on the OBC.
	
	/*	Execute the read	*/
	read_val = *read_ptr;
	
	send_arr[7] = (SELF_ID << 4)|req_by;
	send_arr[6] = MT_COM;
	send_arr[5] = ACK_READ;
	send_arr[4] = CURRENT_MINUTE;
	send_arr[3] = passkey;
	send_arr[0] = read_val;
	
	can_send_message(&(send_arr[0]), CAN1_MB7);
	read_response = 0;
	return;
}
Example #25
0
/**
 * Generate CAN-Message
 *
 * \param cmd The ReKick command
 * \param str A char array which holds the message.
 * \param len The length of the message
 */
void can_put_cmd(uint8_t cmd, uint8_t* str, uint8_t len) {

	tExtendedCAN message;

	// 0x00, priority, sender, receiver
	uint8_t id[4] = {0x00, PRIORITY_NORM, SENSORBOARD_ID, USB2CAN_ID};
	generate_extCAN_ID(id, message.id);
	message.header.rtr = 0;

	// packet length is limited to 8 chars but one char
	// is already used for the cmd.
	if (len > 7)
		len = 7;

	message.data[0] = cmd;
	memcpy(message.data+1, str, len);
	message.header.length = len+1;

	// send to buffer
	can_send_message(&message);


	return;
}
//send status message
void Can::send_status(){
  CanMessage message;
  message.id = aux_status_msg.id();
  message.length = aux_status_msg.len();
  can_send_message(&message);
}
Example #27
0
File: main.cpp Project: L31N/source
int main () {

    uart_init(38400);

    // initialisation of the buttons and leds //
    DDRE &= ~(0xF0);    // buttons as input
    PORTE |= 0xF0;      // activate internal pull-ups
    DDRA |= 0xFF;       // leds as output

    /** CAN TESTING HERE **/
    can_init(BITRATE_1_MBPS);
    sei();

    // motor 1
    can_filter_t filter0;
    filter0.id = 9;
    //filter0.mask = 0x7FF;
    filter0.mask = 0;
    filter0.flags.rtr = 0;

    can_set_filter(0, &filter0);

    PORTA ^= 0x02;

    /*while(true) {
        if (can_check_message()) {
            can_t msg;
            can_get_message(&msg);
            PORTA ^= 0x01;
        }

    }*/

    PORTA = 0x01;
    _delay_ms(1000);
    PORTA = 0x02;

    int j = 0;

    while(true) {
        can_t frame;
        frame.id = 0x42;
        frame.flags.rtr = 0;
        frame.length = 8;
        for(int i = 0; i < 8; i++) {
            frame.data[i] = 42;//j + i;
        }
        j++;

        for (int k = 0; k < 8; k++) {
            if (can_send_message(&frame)) {
                PORTA &= ~0x0F;
                PORTA ^= 0xF0;
            }
            else {
                PORTA |= 0x0F;
            }
        }

        //_delay_ms(1);
        _delay_ms(1);

    }


   while(true) {
        if (can_check_message()) {
            PORTA ^= 0x03;

            /*can_t msg;
            can_get_message(&msg);*/

            can_t message;
            can_get_message(&message);
            for (int i = 0; i < 8; i++) {
                uart_debug("%d: %d\n\r", i, message.data[i]);
                _delay_ms(5);
            }
            uart_debug("##########################\n\n\r");
        }
        if (PINE < 0xF0) {
            can_t frame;
            frame.id = 0x09;
            frame.flags.rtr = 0;
            frame.length = 2;
            frame.data[0] = 0x2A;
            frame.data[1] = 0x06;

            if (can_send_message(&frame)) {
                PORTA &= ~0xE0;
                PORTA ^= 0x10;
            }
            else PORTA = 0xE0;

            uart_debug(".\n\r");
            _delay_ms(500);
        }
    }


    /** ** ++++++++++ ** **/

    return 0;
}
Example #28
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);
		}
	}

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

		// Try to read the message
		if (can_get_message(&msg))
		{
			shackbus_id_t shackbus_id;
			shackbus_id2sb(&shackbus_id,&msg);

			//prot=10 = Basis IO data[0]=10 = Ping
			if (shackbus_id.prot == 10 && shackbus_id.dst == 8 && msg.data[0]==10)
			{
				shackbus_id.prio = 3;
				shackbus_id.vlan = 4;
				shackbus_id.dst  = shackbus_id.src;
				shackbus_id.src  = 8;
				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 == 8 && 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 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 \
				&& msg.data[1] >= 140 && msg.data[1] <= 143)
			{
				shackbus_id.prio = 3;
				shackbus_id.vlan = 4;
				shackbus_id.dst  = shackbus_id.src;
				shackbus_id.src  = 8;
				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);

				if (msg.data[2]==1) enocean_state_set(msg.data[1],ENOCEAN_CHANNEL_SE_SA_SS);
				if (msg.data[2]==0) enocean_state_set(msg.data[1],ENOCEAN_CHANNEL_SE_SA_CS);
			}



			/* prot=11 = PowerManagement data[0]=0 =on/off data[1]=channel data[2]=state */
			/* 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]==0 \
				&& msg.data[1] >= 140 && msg.data[1] <= 143)
			{
				shackbus_id.prio = 3;
				shackbus_id.vlan = 4;
				shackbus_id.dst  = shackbus_id.src;
				shackbus_id.src  = 8;
				shackbus_id.prot = 11;

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

				/* Send the message */
				can_send_message_fifo(&msg);

				void power_mgt_set_input_1(uint8_t _channel, uint8_t _state);
				void power_mgt_set_wait_off(uint8_t _channel, uint16_t _value);
				power_mgt_set_input_1(msg.data[1]-140, msg.data[2]);
				power_mgt_set_wait_off(msg.data[1]-140, 20);
			}

			/* prot=13 = Hauptschalterstate length=1 data[0]=state */
			/* 0 => OFF    */
			/* 1 => ON     */
			if (shackbus_id.prot == 13 && shackbus_id.dst == 255 && msg.length == 1)
			{
				shackbus_id.prio = 3;
				shackbus_id.vlan = 4;
				shackbus_id.dst  = shackbus_id.src;
				shackbus_id.src  = 8;
				shackbus_id.prot = 13;

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

				/* Send the message */
//				can_send_message(&msg);

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

				//power_mgt_set_input_1 (1, msg.data[0]);
				power_mgt_set_wait_on (1, 4); //DLE Kueche
				power_mgt_set_wait_off(1, 5);
				power_mgt_set_input_1 (2, msg.data[0]);
				power_mgt_set_wait_on (2, 2); //OR
				power_mgt_set_wait_off(2, 4);
				power_mgt_set_input_1 (3, msg.data[0]);
				power_mgt_set_wait_on (3, 3); //Kueche
				power_mgt_set_wait_off(3, 90 * 60); //Sekunden
			}



		}
	}

	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  = 8;
		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);
	}

}
Example #29
0
// ----------------------------------------------------------------------------
bool usbcan_decode_message(char *str, uint8_t length)
{
	can_t msg;
	uint8_t dlc_pos;
	bool extended;
	
	if (str[0] == 'R' || str[0] == 'T') {
		extended = true;
		dlc_pos = 9;
	}
	else {
		extended = false;
		dlc_pos = 4;
	}
	
	if (length < dlc_pos + 1)
		return false;
	
	// get the number of data-bytes for this message
	msg.length = str[dlc_pos] - '0';
	
	if (msg.length > 8)
		return false;		// too many data-bytes
	
	
	if (str[0] == 'r' || str[0] == 'R') {
		msg.flags.rtr = true;
		if (length != (dlc_pos + 1))
			return false;
	}
	else {
		msg.flags.rtr = false;
		if (length != (msg.length * 2 + dlc_pos + 1))
			return false;
	}
	
	// read the messge-identifier
	if (extended)
	{
		uint16_t id;
		uint16_t id2;
		
		id  = hex_to_byte(&str[1]) << 8;
		id |= hex_to_byte(&str[3]);
		
		id2  = hex_to_byte(&str[5]) << 8;
		id2 |= hex_to_byte(&str[7]);
		
		msg.id = (uint32_t) id << 16 | id2;
	}
	else {
		uint16_t id;
		
		id  = char_to_byte(&str[1]) << 8;
		id |= hex_to_byte(&str[2]);
		
		msg.id = id;
	}
	
	msg.flags.extended = extended;
	
	// read data if the message is no rtr-frame
	if (!msg.flags.rtr)
	{
		char *buf = str + dlc_pos + 1;
		uint8_t i;
		
		for (i=0; i < msg.length; i++)
		{
			msg.data[i] = hex_to_byte(buf);
			buf += 2;
		}
	}
	
	// finally try to send the message
	if (can_send_message( &msg ))
		return true;
	else
		return false;
}
void send_sensor_data(void)
{
	uint8_t high, low, sensor_name, req_by;			
	sensor_name = data_req_arr[4];
	req_by = data_req_arr[7] >> 4;
	send_arr[3] = 0;
	send_arr[2] = 0;
	send_arr[1] = 0;
	send_arr[0] = 0;
	
	if(sensor_name == EPS_TEMP)
	{
		spi_retrieve_temp(&high, &low);
		send_arr[1] = high;			// SPI temperature sensor readings.
		send_arr[0] = low;
	}
	
	if(sensor_name == PANELX_V)
	{
		send_arr[0] = pxv;
	}
	if(sensor_name == PANELX_I)
	{
		send_arr[0] = pxi;
	}
	if(sensor_name == PANELY_V)
	{
		send_arr[0] = pyv;
	}
	if(sensor_name == PANELY_I)
	{
		send_arr[0] = pyi;
	}
	//if(sensor_name == BATTM_V)
	//{
	//}
	//if(sensor_name == BATT_V)
	//{
	//}
	//if(sensor_name == BATT_I)
	//{
	//}
	//if(sensor_name == BATT_TEMP)
	//{
	//}
	//if(sensor_name == COMS_V)
	//{
	//}
	//if(sensor_name == COMS_I)
	//{
	//}
	//if(sensor_name == PAY_V)
	//{
	//}
	//if(sensor_name == PAY_I)
	//{
	//}
	//if(sensor_name == OBC_V)
	//{
	//}
	//if(sensor_name == OBC_I)
	//{
	//}

	send_arr[7] = (SELF_ID << 4)|req_by;
	send_arr[6] = MT_DATA;
	send_arr[5] = sensor_name;
	send_arr[4] = CURRENT_MINUTE;			
			
	can_send_message(&(send_arr[0]), CAN1_MB0);		//CAN1_MB0 is the data reception MB.
	send_data = 0;
	
	return;
}