Ejemplo n.º 1
0
/*
  mca_network_cnxn_thread (MCACnxn *cnxn)

  Connects to server, wait for commands and executes them.
  It retrys to connect to the server in case the connection fails

  This function never returns
 */
cnxn_status_t
mca_network_cnxn_thread (MCACnxn *cnxn)
{
  gint32    retval = 0;
  gint32    cmd;

  while (1){
    DEBUG_PRINT ("mca_network_cnxn_thread(): Attempt to connect: %d\n", retval);
    retval = mca_connect_server(cnxn);
    if (!retval){
      DEBUG_PRINT("mca_network_cnxn_thread(): failed to connect to %s\n", cnxn->server_name);
      cnxn->connected = FALSE;
      count_seconds(cnxn->retrysec);
      continue; 
    }
    DEBUG_PRINT("mca_network_cnxn_thread(): connected to %s\n", cnxn->server_name);
    //identify myself to server
    send_signature(cnxn);

    //wait for commands and process them when we received 
    while ((cmd = mca_network_wait_for_cmd(cnxn))){
      retval = cnxn->cmd_cb(cmd, cnxn->cmd_data, cnxn->cmd_data_len);
      DEBUG_PRINT("mca_network_cnxn_thread(): executed [%08X], returned [%d]\n", cmd, retval);
    }
    //cmd == 0 - connection must have broken or flow was destroyed
    DEBUG_PRINT("mca_network_cnxn_thread(): connection to %s broke\n", cnxn->server_name);
    mca_network_close_connection(cnxn);
    count_seconds(cnxn->retrysec);
  }

  return 0;
}
Ejemplo n.º 2
0
int main()
{
	pololu_3pi_init(2000);  
	play_mode(PLAY_CHECK);
	clear();

	// start receiving data at 115.2 kbaud
	serial_set_baud_rate(115200);
	serial_receive_ring(buffer, 100);

	while(1)
	{
		// wait for a command
		char command = read_next_byte();

		// The list of commands is below: add your own simply by
		// choosing a command byte and introducing another case
		// statement.
		switch(command)
		{
		case (char)0x00:
			// silent error - probable master resetting
			break;

		case (char)0x81:
			send_signature();
			break;
		case (char)0x86:
			send_raw_sensor_values();
			break;
		case (char)0x87:
			send_calibrated_sensor_values(1);
			break;
		case (char)0xB0:
			send_trimpot();
			break;
		case (char)0xB1:
			send_battery_millivolts();
			break;
		case (char)0xB3:
			do_play();
			break;
		case (char)0xB4:
			calibrate_line_sensors(IR_EMITTERS_ON);
			send_calibrated_sensor_values(1);
			break;
		case (char)0xB5:
			line_sensors_reset_calibration();
			break;
		case (char)0xB6:
			send_line_position();
			break;
		case (char)0xB7:
			do_clear();
			break;
		case (char)0xB8:
			do_print();
			break;
		case (char)0xB9:
			do_lcd_goto_xy();
			break;
		case (char)0xBA:
			auto_calibrate();
			break;
		case (char)0xBB:
			set_pid();
			break;
		case (char)0xBC:
			stop_pid();
			break;

		case (char)0xC1:
			m1_forward();
			break;
		case (char)0xC2:
			m1_backward();
			break;
		case (char)0xC5:
			m2_forward();
			break;
		case (char)0xC6:
			m2_backward();
			break;

		default:
			clear();
			print("Bad cmd");
			lcd_goto_xy(0,1);
			print_hex_byte(command);

			play("o7l16crc");
			continue; // bad command
		}
	}
}