Esempio n. 1
0
static uint32_t write(t_hydra_console *con, uint8_t *tx_data, uint8_t nb_data)
{
	uint32_t status;
	mode_config_proto_t* proto = &con->mode->proto;
	uint8_t i = 0;
	can_tx_frame tx_msg;

	if(proto->config.can.dev_mode == BSP_CAN_MODE_RO) {
		cprintf(con, "Switching to normal bus operation\r\n");
		status = bsp_can_mode_rw(proto->dev_num, proto);
		if(status != BSP_OK){
			cprintf(con, str_bsp_init_err, status);
			return status;
		}
	}
	status = BSP_ERROR;

	if(can_slcan_in(tx_data, &tx_msg) != BSP_OK) {

		/* Is ID an extended one ? */
		if (proto->config.can.can_id < 0b11111111111) {
			tx_msg.header.StdId = proto->config.can.can_id;
			tx_msg.header.IDE = CAN_ID_STD;
		} else {
			tx_msg.header.ExtId = proto->config.can.can_id;
			tx_msg.header.IDE = CAN_ID_EXT;
		}

		tx_msg.header.RTR = CAN_RTR_DATA;
		tx_msg.header.DLC = 0;
		while(nb_data > i) {
			tx_msg.data[tx_msg.header.DLC] = tx_data[i];
			tx_msg.header.DLC++;

			if(tx_msg.header.DLC == 8) {
				status = can_send_msg(con, &tx_msg);
				tx_msg.header.DLC = 0;
			}
			i++;
		}
		/*Send leftover bytes*/
		if(tx_msg.header.DLC> 0) {
			status = can_send_msg(con, &tx_msg);
		}
	} else {
		status = can_send_msg(con, &tx_msg);
	}

	return status;
}
void init()
{
	ResetReason = MCUSR;		
 	cli();
    chip_init ();    				// Chip initialization
	init_leds ();
	delay(1000000);					// ~ 2 sec
	read_cal();						// Read everything including motor stops.	
	// yes can_init() needs MyInstance to be set already for filtering!
	can_init(CAN_250K_BAUD);		/* Enables Mob0 for Reception! */

    // INIT MYINSTANCE:	
	config_init();
	can_instance_init();
	
    set_rx_callback			( can_file_message );
	set_configure_callback	( config_change    );
	sei();

	OS_InitTask();
	pot_init();	
	motor_init ();

	can_prep_instance_request( &msg2, 0xBB );
	can_send_msg( 0, &msg2 );
}
void send_test_msgs()
{
	a = 0x00;
	while (1) 
	{
		a -= 0x11;			// Count down to distinguish clearly from the led_test_pattern()!
		msg1.data[0] = a;
		led_on (1);			led_off(2); led_off(3);
		can_send_msg( 0, &msg1 );
		delay  (one_second/2);
		led_off(1);
		delay  (one_second/2);
	} 
}
void send_test_msgs()
{
	a = 0x00;
	while (1) 
	{
		a += 0x01;
		msg1.data[0] = a;
		SET_LED_1
		RESET_LED_2   RESET_LED_3   RESET_LED_4 
		can_send_msg( 0, &msg1 	);
		delay  (one_second/10);
		RESET_LED_1 
		delay  (one_second/10);
	} 
}
Esempio n. 5
0
//---- Begin of function TalkRes::add_main_choices ------//
//
void TalkRes::add_main_choices()
{
//	static char* talkMsgArray[] =
//	{
//		"Propose a trade treaty.",
//		"Propose a friendly treaty.",
//		"Propose an alliance treaty.",
//		"Terminate our trade treaty.",
//		"Terminate our friendly treaty.",
//		"Terminate our alliance treaty.",
//		"Request immediate military aid.",
//		"Request a trade embargo.",
//		"Request a cease-fire.",
//		"Request a declaration of war against a foe.",
//		"Request to purchase food.",
//		"Declare war.",
//		"Offer to pay tribute.",
//		"Demand tribute.",
//		"Offer aid.",
//		"Request aid.",
//		"Offer to exchange technology.",
//		"Offer to purchase throne and unite kingdoms.",
//		"Surrender.",
//	};

	//-----------------------------------------//

	int rc;
	int relationStatus = (~nation_array)->get_relation_status(cur_talk_msg.to_nation_recno);

	for( int i=1 ; i<=MAX_TALK_TYPE ; i++ )	
	{
		if( !can_send_msg(cur_talk_msg.to_nation_recno, nation_array.player_recno, i) )
			continue;

		rc=0;

		if( !rc )
			// add_talk_choice( talkMsgArray[i-1], i );
			add_talk_choice( text_talk.str_msg_name(i), i );

		available_talk_id_array[i-1] = 1;

		if( talk_choice_count == MAX_TALK_CHOICE )
			break;
	}
}
Esempio n. 6
0
//------- Begin of function TalkRes::send_talk_msg --------//
//
// Now records in talk_msg_array cannot be deleted as
// news_array.diplomacy() use recno to refer to talk_msg_array.
//
// <talkMsg*> talkMsgPtr   - pointer to the TalkMsg structure
// <char>     remoteAction - remote action
// [int]  	  forceSend	   - if this is 1, the message will be sent without
//									  checking can_send_msg. (default: 0)
//
void TalkRes::send_talk_msg(TalkMsg* talkMsgPtr, char remoteAction, int forceSend)
{
	//-------- send multiplayer -----------//

	if( !remoteAction && remote.is_enable() )
	{
		// packet strcture : <TalkMsg>
		char* dataPtr = remote.new_send_queue_msg(MSG_SEND_TALK_MSG, sizeof(TalkMsg) );

		memcpy( dataPtr, talkMsgPtr, sizeof(TalkMsg) );
		return;
	}

	//------ the TalkMsg::reply_type ------//

	if( talkMsgPtr->is_reply_needed() )
		talkMsgPtr->reply_type = REPLY_WAITING;
	else
		talkMsgPtr->reply_type = REPLY_NOT_NEEDED;

	//-- If this is an AI message check if this message has already been sent --//

	if( nation_array[talkMsgPtr->from_nation_recno]->nation_type == NATION_AI )
	{
		if( talkMsgPtr->reply_type == REPLY_WAITING )	// for messages that do not need a reply, duplication in the message log is allowed.
		{
			if( is_talk_msg_exist(talkMsgPtr, 0) )		// 0-don't check talk_para1 & talk_para2
				return;
		}
	}

	//--- in a multiplayer game, when the msg comes back from the network, can_send_msg might be different, so we have to check it again ---//

	if( !forceSend && !can_send_msg( talkMsgPtr->to_nation_recno, talkMsgPtr->from_nation_recno, talkMsgPtr->talk_id ) )
		return;

	//-------- send the message now ---------//

	send_talk_msg_now(talkMsgPtr);

	//---- if it's a notification message ----//

	if( talkMsgPtr->reply_type == REPLY_NOT_NEEDED )
		talkMsgPtr->process_accepted_reply();
}
//***** main *****************************************************
int main(void)
{
	union uKeyRoster scan;
	
    chip_init();    // Chip initialization
	can_init();		/* Enables Mob0 for Reception! */
	can_init_test_msg();
	byte result = CANSTMOB;
	
	send_test_msgs();
	/* TEST A)  Initial Board Alive test, call this below.  Watch LEDs go. 
	led_test_pattern();	*/
	/* B) Enable Receive Interrupts and call Show_byte() in the ISR.
		ALL CODE IS IN ISR()	*/
	while (1) {};
	
    while (1)
    {  	  
		wait_for_press();
		
		// Result is stored in prev_keys & keys and hopefully keys2
		scan = pack_array( keys );
		can_prep_button_roster_msg( &msg1, scan );
        can_send_msg( 0, &msg1 );
		show_byte( scan.array[0], 1 );

//		result = CANEN2;		// shows MOb n in use   mob1 is staying "in use" after 1 can_tx()
//		result = CANSTMOB;		// shows TXOK or ERRs   BERR staying on instead of TXOK 
//		result = CANGSTA;		// shows TXOK or ERRs   TXBSY blinking (retires?)
//		result = 0x83;
//		result = scan.array[0];	
//		show_byte( a, 1 );
		// [0] upper nibble is front row
		// [0] lower        is top row
		// [1] upper nibble is 2nd row
		// [1] lower        is 3rd row
		// [2] upper nibble is 4th row
      /*  for (int j=0; j<4; j++)
        {
        	show_result_toggle(result);
        	delay (one_second/2);
        }  */
    }
    return(0);
} 
void button_magic( byte mKey )
{
	switch(mKey)
	{
	// Front Edge, Left to Right : 
	case 0: can_prep_board_presence_request( &msg2, 0 );
			break;
	case 1: can_prep_board_presence_request( &msg2, 1 );
			break;
	case 2: can_prep_board_presence_request( &msg2, 2 );
			break;
	case 3: can_prep_board_presence_request( &msg2, 3 );
			break;

	// Top Row, Left to Right: 
	case 4: can_prep_system_led_msg( &msg2, Instance, SYSTEM_LED_MODE_DEVICE, 0 );
			break;
	case 5: can_prep_system_led_msg( &msg2, Instance, SYSTEM_LED_MODE_PATTERN, 0x05 );
			break;
	case 6: can_prep_system_led_msg( &msg2, Instance, SYSTEM_LED_MODE_STROBE, 0x00 );
			break;
	case 7: can_prep_system_led_msg( &msg2, Instance, SYSTEM_LED_MODE_STROBE, 0x01 );
			break;
	case 8: can_prep_system_led_msg( &msg2, Instance, SYSTEM_LED_MODE_MYINSTANCE, 0 );
			break;

	case 0x0C:  Instance = 0x01;				break;
	case 0x0D:  Instance = 0x02;				break;
	case 0x0E:  Instance = 0x03;				break;
	case 0x0F:  Instance = 0x04;				break;
	
	case 9: Instance = 0;
			led_off(2);
			led_off(4);
			led_off(1);
			RESET_LED_2();
			break;
	default: break;	
	}
	can_send_msg( CAN_TRANSMIT_CHANNEL2, &msg2 );
}
void can_prep_eeprom_dump1_msg( )
{
	byte* addr = INSTANCE_EEPROM_ADDRESS;
	can_prep_eeprom_dump_msg( &msg1, addr );
	can_send_msg( 0, &msg1 );
}
void can_prep_eeprom_dump3_msg( )
{
	byte* addr = (byte*)(INSTANCE_EEPROM_ADDRESS+16);
	can_prep_eeprom_dump_msg( &msg1, addr );
	can_send_msg( 4, &msg1 );
}
void can_prep_eeprom_dump2_msg( )
{
	byte* addr = (byte*)(INSTANCE_EEPROM_ADDRESS+8);
	can_prep_eeprom_dump_msg( &msg2, addr );
	can_send_msg( 2, &msg2 );
}
Esempio n. 12
0
void TalkRes::disp_talk()
{
	//----- if the player can send no more message to the nation ---//

	if( !info.player_reply_mode &&
		 !can_send_any_msg(cur_talk_msg.to_nation_recno, nation_array.player_recno) )
	{
		if( !( choice_question && strcmp(choice_question, MESSAGE_SENT_STR)==0 ) )		// if it's currently displaying the has sent notification, display that message
		{
//			char* msgStr = "You've sent too many messages to this kingdom. "
//								"You cannot send any new messages until the existing ones are processed.";
			font_bld.put_paragraph( TALK_X1, TALK_Y1, TALK_X2, TALK_Y2, text_talk.str_too_many_msg(), 4 );
			return;
		}
	}

	//--- return whether the talk choices should be refreshed. ---//

	if( !reply_talk_msg_recno && !cur_talk_msg.talk_id )		// not replying and haven't selected a message type yet.
	{
		for( int i=0 ; i<MAX_TALK_TYPE ; i++ )
		{
			if( available_talk_id_array[i] != can_send_msg(cur_talk_msg.to_nation_recno, cur_talk_msg.from_nation_recno, i+1) )
			{
				set_talk_choices();
				break;
			}
		}
	}

	//------ repaint the area for displaying the sub-title ------//

	int 	 y=TALK_Y1;
	String str;

	//----- if there is a question on the choices ------//

	if( choice_question )
	{
		// ####### begin Gilbert 4/1 ######//
		// font_san.put( TALK_X1+3, y, choice_question );
		font_bld.put( TALK_X1+3, y, choice_question );
		// ####### end Gilbert 4/1 ######//
		y+=TALK_LINE_HEIGHT;
	}

	if( choice_question_second_line )		// second line message
	{
		// ####### begin Gilbert 4/1 ######//
		// font_san.put( TALK_X1+3, y, choice_question_second_line );
		font_bld.put( TALK_X1+3, y, choice_question_second_line );
		// ####### end Gilbert 4/1 ######//
		y+=TALK_LINE_HEIGHT;
	}

	//--------- display talk choices ---------//

	for( int i=0 ; i<talk_choice_count ; i++, y+=TALK_LINE_HEIGHT )
	{
		if( i+1 == cur_choice_id )		// this is the one the mouse cursor is currently on
			vga_back.bar_alpha( TALK_X1, y, TALK_X2, y+TALK_LINE_HEIGHT-1, 1, VGA_GRAY+8 );

		if( choice_question )
		{
			str  = "- ";		// display bullets in front of the text strings
			str += translate.process( talk_choice_array[i].str );
		}
		else
			str = talk_choice_array[i].str;

		// ###### begin Gilbert 4/1 ########//
		font_bld.put_paragraph( TALK_X1+3, y+2, TALK_X2-3, y+font_bld.height()+1, str );
		// ###### end Gilbert 4/1 ########//
	}
}