Beispiel #1
0
// Handles different menu selection
//
// leftRightIndex: index for determining menus
// upDownIndex, currDollars, currCents: needed for calling print_menu
void select_menu(int *leftRightIndex, int upDownIndex, int currDollars, int currCents) {
  if (*leftRightIndex == 0) {
      print_welcome();
  } else if (*leftRightIndex == 1) {
    print_menu(upDownIndex, currDollars, currCents);
  }
  else {
    clear_display();
    delay(1000); //1ms
    LED_toggle();
    display_string("Order Confirmed!");
    display_string("                        ");
    delay(1000000); //1sec
    display_string("Preparing Now...");
    delay(3000000); //3sec
    clear_display();
    delay(1000); //1ms
    display_string("Order Ready!");
    LED_toggle();
    delay(3000000); //3sec
    *leftRightIndex = 0;
    clear_display();
    delay(1000); //1ms
    print_welcome();
  }
}
static int telnet_new_connection(struct osmo_fd *fd, unsigned int what)
{
	struct telnet_connection *connection;
	struct sockaddr_in sockaddr;
	socklen_t len = sizeof(sockaddr);
	int new_connection = accept(fd->fd, (struct sockaddr*)&sockaddr, &len);

	if (new_connection < 0) {
		LOGP(0, LOGL_ERROR, "telnet accept failed\n");
		return new_connection;
	}

	connection = talloc_zero(tall_telnet_ctx, struct telnet_connection);
	connection->priv = fd->data;
	connection->fd.data = connection;
	connection->fd.fd = new_connection;
	connection->fd.when = BSC_FD_READ;
	connection->fd.cb = client_data;
	osmo_fd_register(&connection->fd);
	llist_add_tail(&connection->entry, &active_connections);

	print_welcome(new_connection);

	connection->vty = vty_create(new_connection, connection);
	if (!connection->vty) {
		LOGP(0, LOGL_ERROR, "couldn't create VTY\n");
		close(new_connection);
		talloc_free(connection);
		return -1;
	}

	return 0;
}
Beispiel #3
0
static int prompt_timezone(void) {
        _cleanup_strv_free_ char **zones = NULL;
        int r;

        if (arg_timezone)
                return 0;

        if (!arg_prompt_timezone)
                return 0;

        r = get_timezones(&zones);
        if (r < 0)
                return log_error_errno(r, "Cannot query timezone list: %m");

        print_welcome();

        printf("\nAvailable Time Zones:\n\n");
        r = show_menu(zones, 3, 22, 30);
        if (r < 0)
                return r;

        putchar('\n');

        r = prompt_loop("Please enter timezone name or number", zones, timezone_is_valid, &arg_timezone);
        if (r < 0)
                return r;

        return 0;
}
Beispiel #4
0
static int prompt_keymap(void) {
        _cleanup_strv_free_ char **kmaps = NULL;
        int r;

        if (arg_keymap)
                return 0;

        if (!arg_prompt_keymap)
                return 0;

        r = get_keymaps(&kmaps);
        if (r == -ENOENT) /* no keymaps installed */
                return r;
        if (r < 0)
                return log_error_errno(r, "Failed to read keymaps: %m");

        print_welcome();

        printf("\nAvailable keymaps:\n\n");
        r = show_menu(kmaps, 3, 22, 60);
        if (r < 0)
                return r;

        putchar('\n');

        return prompt_loop("Please enter system keymap name or number",
                           kmaps, keymap_is_valid, &arg_keymap);
}
Beispiel #5
0
int main(void)
{
pOperate OP=NULL;		///会话开始,定义标志变量
operate_init(OP);		///初始化标志变量
pCmm cmd=NULL;
print_welcome();
while(1)
{
	cmd=get_command(OP);
	switch (cmd->code)
	{
		case 0x0	: if(open_file(OP,cmd)); 		break;
		case 0x2	: remove_file(OP,cmd); 			break;
		case 0x3	: rm_a_score(OP,cmd); 			break;
		case 0x4	: rm_some_score(OP,cmd); 		break;
		case 0x5	: rm_a_stu_score(OP,cmd);		break;
		case 0x6	: rm_a_student(OP,cmd); 		break;
		case 0x7	: find_a_score(OP,cmd); 		break;
		case 0x8	: find_some_score(OP,cmd); 		break;
		case 0x9	: find_a_stu_score(OP,cmd); 	break;
		case 0xa	: find_a_student(OP,cmd); 		break;
		case 0xb	: insert_a_score(OP,cmd); 		break;
		case 0xc	: insert_a_stu_score(OP,cmd); 	break;
		case 0xd	: if(!strcmp("exit",cmd->cmd_str)) exit(0);
						system(cmd->cmd_str); 		break;
		case 0xf	: save_file(OP,cmd); 			break;
		default		: printf("未知命令\n");			break;
	}
	free(cmd);
}
    return 0;
}
Beispiel #6
0
void main(void) {
	volatile packet_t *p;
	volatile uint8_t t=20;
	uint8_t chan;
	char c;

	gpio_data(0);
	
	gpio_pad_dir_set( 1ULL << LED );
        /* read from the data register instead of the pad */
	/* this is needed because the led clamps the voltage low */
	gpio_data_sel( 1ULL << LED);

	/* trim the reference osc. to 24MHz */
	trim_xtal();

	uart_init(UART1, 115200);

	vreg_init();

	maca_init();

        /* sets up tx_on, should be a board specific item */
        *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2));
	gpio_pad_dir_set( 1ULL << 44 );

	set_power(0x0f); /* 0dbm */
	chan = 0;
	set_channel(chan); /* channel 11 */

	*MACA_MACPANID = 0xaaaa;
	*MACA_MAC16ADDR = 0x1111;
	*MACA_TXACKDELAY = 68; /* 68 puts the tx ack at about the correct spot */
	set_prm_mode(AUTOACK);

	print_welcome("rftest-rx");
	while(1) {		

		/* call check_maca() periodically --- this works around */
		/* a few lockup conditions */
		check_maca();

		if((p = rx_packet())) {
			/* print and free the packet */
			printf("autoack-rx --- ");
			print_packet(p);
			maca_free_packet(p);
		}

		if(uart1_can_get()) {
			c = uart1_getc();
			if(c == 'z') t++;
			if(c == 'x') t--;
			*MACA_TXACKDELAY = t;
			printf("tx ack delay: %d\n\r", t);
		}

	}
}
Beispiel #7
0
int main(){
	print_welcome();
	print_menu();
	while(1){
		main_menu();
	}
	return 0;
}
Beispiel #8
0
void usage() {
    print_welcome();
    printf("terra [OPTIONS] [source-file] [arguments-to-source-file]\n"
           "    -v enable verbose debugging output\n"
           "    -h print this help message\n"
           "    -i enter the REPL after processing source files\n"
           "    -l <language_file> specify a module that defines a language extension (can be repeated)\n");
}
Beispiel #9
0
void usage() {
    print_welcome();
    printf("terra [OPTIONS] [source-file] [arguments-to-source-file]\n"
           "    -v enable verbose debugging output\n"
           "    -h print this help message\n"
           "    -i enter the REPL after processing source files\n"
           "    -p <path> append <path> to package.path before executing code\n"
           "    -  Execute stdin instead of script and stop parsing options\n");
}
Beispiel #10
0
int main(int argc, char *argv[], char *envp[])
{
	char input[255] = {0,};
	print_welcome();
	int fd=open("/dev/nish",O_RDWR,0);
	if (fd<0) {
		printf("\e[31mCannot connect to nish\e[m\n");
		exit(1);
	}
Beispiel #11
0
static int prompt_root_password(void) {
        const char *msg1, *msg2, *etc_shadow;
        int r;

        if (arg_root_password)
                return 0;

        if (!arg_prompt_root_password)
                return 0;

        etc_shadow = prefix_roota("/etc/shadow");
        if (faccessat(AT_FDCWD, etc_shadow, F_OK, AT_SYMLINK_NOFOLLOW) >= 0)
                return 0;

        print_welcome();
        putchar('\n');

        msg1 = strappenda(draw_special_char(DRAW_TRIANGULAR_BULLET), " Please enter a new root password (empty to skip): ");
        msg2 = strappenda(draw_special_char(DRAW_TRIANGULAR_BULLET), " Please enter new root password again: ");

        for (;;) {
                _cleanup_free_ char *a = NULL, *b = NULL;

                r = ask_password_tty(msg1, 0, false, NULL, &a);
                if (r < 0) {
                        log_error("Failed to query root password: %s", strerror(-r));
                        return r;
                }

                if (isempty(a)) {
                        log_warning("No password entered, skipping.");
                        break;
                }

                r = ask_password_tty(msg2, 0, false, NULL, &b);
                if (r < 0) {
                        log_error("Failed to query root password: %s", strerror(-r));
                        clear_string(a);
                        return r;
                }

                if (!streq(a, b)) {
                        log_error("Entered passwords did not match, please try again.");
                        clear_string(a);
                        clear_string(b);
                        continue;
                }

                clear_string(b);
                arg_root_password = a;
                a = NULL;
                break;
        }

        return 0;
}
Beispiel #12
0
void main(void) {
	nvmType_t type=0;
	nvmErr_t err;
	uint32_t buf[WRITE_NBYTES/4];
	uint32_t i;

	uart_init(INC, MOD, SAMP);

	print_welcome("nvm-write");

	vreg_init();

	if(NVM_INTERFACE == gNvmInternalInterface_c)
	{
		printf("Detecting internal nvm\n\r");
	} else {
		printf("Setting up gpio\r\n");
		/* set SPI func */
		GPIO->FUNC_SEL.GPIO_04 = 1;
		GPIO->FUNC_SEL.GPIO_05 = 1;
		GPIO->FUNC_SEL.GPIO_06 = 1;
		GPIO->FUNC_SEL.GPIO_07 = 1;
		printf("Detecting external nvm\n\r");
	}

	err = nvm_detect(NVM_INTERFACE, &type);
		
	printf("nvm_detect returned: 0x%02x type is: 0x%08x\r\n", err, (unsigned int)type);

	buf[0] = WRITEVAL0;
	buf[1] = WRITEVAL1;

	err = nvm_erase(NVM_INTERFACE, type, 1 << WRITE_ADDR/4096);
	printf("nvm_erase returned: 0x%02x\r\n", err);

	err = nvm_write(NVM_INTERFACE, type, (uint8_t *)buf, WRITE_ADDR, WRITE_NBYTES);
	printf("gnychis nvm_write returned: 0x%02x\r\n", err);

	printf("writing\n\r");
	for(i=0; i<WRITE_NBYTES/4; i++) {
		printf("0x%08x\r\n", (unsigned int)buf[i]);
		buf[i] = 0x00000000; /* clear buf for the read */
	}

	err = nvm_read(NVM_INTERFACE, type, (uint8_t *)buf, WRITE_ADDR, WRITE_NBYTES);
	printf("nvm_read returned: 0x%02x\r\n", err);

	printf("reading\r\n");
	for(i=0; i<WRITE_NBYTES/4; i++) {
		printf("0x%08x\r\n", (unsigned int)buf[i]);
	}
		

	while(1) {continue;};
}
Beispiel #13
0
int main()
{
	print_welcome();

	print_prompt();

	wait_for_enter();

	print_goodbye();

	return 0;
}
Beispiel #14
0
static int prompt_root_password(void) {
        const char *msg1, *msg2, *etc_shadow;
        int r;

        if (arg_root_password)
                return 0;

        if (!arg_prompt_root_password)
                return 0;

        etc_shadow = prefix_roota(arg_root, "/etc/shadow");
        if (laccess(etc_shadow, F_OK) >= 0)
                return 0;

        print_welcome();
        putchar('\n');

        msg1 = strjoina(special_glyph(SPECIAL_GLYPH_TRIANGULAR_BULLET), " Please enter a new root password (empty to skip): ");
        msg2 = strjoina(special_glyph(SPECIAL_GLYPH_TRIANGULAR_BULLET), " Please enter new root password again: ");

        for (;;) {
                _cleanup_strv_free_erase_ char **a = NULL, **b = NULL;

                r = ask_password_tty(-1, msg1, NULL, 0, 0, NULL, &a);
                if (r < 0)
                        return log_error_errno(r, "Failed to query root password: %m");
                if (strv_length(a) != 1) {
                        log_warning("Received multiple passwords, where we expected one.");
                        return -EINVAL;
                }

                if (isempty(*a)) {
                        log_warning("No password entered, skipping.");
                        break;
                }

                r = ask_password_tty(-1, msg2, NULL, 0, 0, NULL, &b);
                if (r < 0)
                        return log_error_errno(r, "Failed to query root password: %m");

                if (!streq(*a, *b)) {
                        log_error("Entered passwords did not match, please try again.");
                        continue;
                }

                arg_root_password = TAKE_PTR(*a);
                break;
        }

        return 0;
}
Beispiel #15
0
int main(){
 // Seed the RNG for computer randomized selections
    srand(time(NULL));
 
 // Initialization Block
    int coins                   =  30;  /* Total coins used in the game */
    int psel                    =   0;
    int csel                    =   0;
    int i                       =   0;

    print_welcome();

    while(coins > 0){
        //print the amount of coins
        print_coins(coins, i);

        //get player input
        printf("Please choose 1, 2, or 3: ");
        scanf("\n%d", &psel);
  
        //check that player input is within the bounds
        do{
            if(psel < 1){
                printf("You have to take at least one coin. ");
                scanf("\n%d", &psel);
            } else if(psel > 3 || psel > coins){
                printf("Dont take that many coins, greedy! ");
                scanf("\n%d", &psel);
            }
        }while(psel < 1 || psel > 3 || psel > coins);
  
        coins -= psel;
        if(coins == 0){
            printf("You took the last coin! You Win!\n");
            break;
        } else{
            printf("You take %d coins, there are %d coins left.\n", psel, coins);
        }  

        csel = gen_random_num(coins);
        coins -= csel;
        if(coins == 0){
            printf("The computer took the last coin. You lose.\n");
            break;
        } else{
            printf("The computer takes %d coins, there are %d coins left.\n", csel, coins);
        }
    }
    return 0;
}
Beispiel #16
0
static int prompt_root_password(void) {
        const char *msg1, *msg2, *etc_shadow;
        int r;

        if (arg_root_password)
                return 0;

        if (!arg_prompt_root_password)
                return 0;

        etc_shadow = prefix_roota(arg_root, "/etc/shadow");
        if (laccess(etc_shadow, F_OK) >= 0)
                return 0;

        print_welcome();
        putchar('\n');

        msg1 = strjoina(special_glyph(TRIANGULAR_BULLET), " Please enter a new root password (empty to skip): ");
        msg2 = strjoina(special_glyph(TRIANGULAR_BULLET), " Please enter new root password again: ");

        for (;;) {
                _cleanup_string_free_erase_ char *a = NULL, *b = NULL;

                r = ask_password_tty(msg1, NULL, 0, 0, NULL, &a);
                if (r < 0)
                        return log_error_errno(r, "Failed to query root password: %m");

                if (isempty(a)) {
                        log_warning("No password entered, skipping.");
                        break;
                }

                r = ask_password_tty(msg2, NULL, 0, 0, NULL, &b);
                if (r < 0)
                        return log_error_errno(r, "Failed to query root password: %m");

                if (!streq(a, b)) {
                        log_error("Entered passwords did not match, please try again.");
                        continue;
                }

                arg_root_password = a;
                a = NULL;
                break;
        }

        return 0;
}
Beispiel #17
0
void usage() {
    print_welcome();
    printf(
      "ebb [OPTIONS] [source-file] [arguments-to-source-file]\n"
      "    -v terra enable verbose debugging output for terra\n"
      "    -d enable debugging symbols\n"
      "    -h print this help message\n"
      "    -i enter the REPL after processing source files\n"
      "    -g run tasks on a gpu by default\n"
      "    -l enable Legion support\n"
      "    -r runtime options\n"
      "       for legion : -r debug,legionspy,legionprof\n"
      "    -p use partitioning\n"
      "    -a additional arguments (if spaces or special characters, include in quotes)\n"
      "    -  Execute stdin instead of script and stop parsing options\n");
}
Beispiel #18
0
/* ---
*/
int init_parser(int argc, char **argv)
{
	print_welcome();
	process_cla(argc, argv, 1);
	print_hs_1();
	init_storage();
	init_subrs();
	init_trace();
	init_slibu();
	init_ss();
	init_ndbm();
	init_regex();
	init_tar();

	return 0;
}
int
shell( int argc, char *argv[] ) {

  init_shell(); // initialize the shell
  
  pid_t pid = getpid();	       // get current processe's PID
  pid_t ppid = getppid();      // get parent's PID 
  pid_t cpid, tcpid, cpgid;

  print_welcome( argv[0], pid, ppid );
  print_prompt();
  char *s = malloc(INPUT_STRING_SIZE + 1); // user input string
  
  while( (s = freadln(stdin)) ){ // read in the input string
    process *p = create_process( s );
    if( p != NULL ){ // do we need to run a newly created process?
      cpid = fork(); // fork off a child
      if( cpid == 0 ) { // child
	p->pid = getpid();
	launch_process( p );
      } // if( cpid == 0 )
      else if( cpid > 0 ){ // parent
	p->pid = cpid;
	if( shell_is_interactive ){ // are we running shell from a terminal?
	  // put 'p' into its own process group
	  // since our shell is not supporting pipes, we treat
	  // each process by itself as a 'job' to be done
	  if( setpgid( cpid, cpid ) < 0 ) 
	    printf( "Failed to put the child into its own process group.\n" );
	  if( p->background )
	    put_in_background( p, false );
	  else
	    put_in_foreground( p, false );
	} // if( shell_is_interactive )
	else
	  wait_for_process( p );
      } // else if( cpid > 0 )
      else // fork() failed
	printf( "fork() failed\n" );
    } // if( p != NULL )
    print_prompt();
  } // while

  return EXIT_SUCCESS;
} // shell
Beispiel #20
0
int main()
{
   int board[BOARD_SIZE_HORIZ][BOARD_SIZE_VERT] = { {0} };
   int player_num, computer_num;
   int last_move; 


   /* Ask Alice if she wants to go first */
   player_num = print_welcome();
   if (player_num == 1) computer_num = 2;
   else computer_num = 1;

   /* If Alice wants to go first, let her make a move */
   if (player_num == 1)
   {
      display_board(board);
      last_move = player_move(board,player_num);
      display_board(board);
   }


   /* The main loop */
   
   while (1)
   {
      /* Make a computer move, then display the board */
      last_move = random_move(board,computer_num);
      printf("Computer moved in column: %d\n", last_move);
      display_board(board);

      /* Check whether the computer has won */
      if (check_win_or_tie(board,last_move)) return 0;


      /* Let Alice make a move, then display the board */
      last_move = player_move(board,player_num);
      display_board(board);

      /* Check whether Alice has won */
      if (check_win_or_tie(board,last_move)) return 0;


   } /* end of while (1) */

} /* end of main() */
Beispiel #21
0
void init(int argc, char *argv[])
{
    Parser::check_if_user_needs_help(argc, argv);

    if (!sdl_init(SCREEN_WIDTH, SCREEN_HEIGHT, Parser::get_display_mode_from_command_line(argc, argv), main_window, main_context)) {
        Error::throw_error(Error::display_init_fail);
    }
    init_input();

    print_welcome();

    renderer.init();
    renderer.init_uniforms(camera);

    Loader::load_scene(Parser::get_scene_file_from_command_line(argc, argv), &camera);
    renderer.init_tweak_bar(&camera);

    Light::init();
}
Beispiel #22
0
static void dotty (lua_State *L) {
  int status;
  print_welcome();
  while ((status = loadline(L)) != -1) {
    if (status == 0) status = docall(L, 0, 0);
    report(L,status);
    if (status == 0 && lua_gettop(L) > 0) {  /* any result to print? */
      lua_getglobal(L, "print");
      lua_insert(L, 1);
      if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
        lua_pushfstring(L,
                        "error calling " LUA_QL("print") " (%s)",
                        lua_tostring(L, -1));
        report(L,status);
    }
  }
  lua_settop(L, 0);  /* clear stack */
  fputs("\n", stdout);
  fflush(stdout);
}
Beispiel #23
0
/* ---
*/
int init_parser(int argc, char **argv)
{
	print_welcome();
	process_cla(siod_argc, siod_argv, 1);
	process_cla(argc, argv, 1);
	print_hs_1();
	init_storage();
	init_subrs();
	init_trace();
	init_slibu();
	init_ss();
	init_ndbm();
	init_regex();
	init_tar();
	init_subr_0("row", get_row);
	init_subr_0("col", get_col);
	init_subr_2("exec-expr", lexec_expr);

	/*XtAppAddActions(app_context, actions, XtNumber(actions));*/
	return register_interpreter("SIOD", NULL, execute_siod);
}
Beispiel #24
0
static int prompt_locale(void) {
        _cleanup_strv_free_ char **locales = NULL;
        int r;

        if (arg_locale || arg_locale_messages)
                return 0;

        if (!arg_prompt_locale)
                return 0;

        r = get_locales(&locales);
        if (r < 0) {
                log_error("Cannot query locales list: %s", strerror(-r));
                return r;
        }

        print_welcome();

        printf("\nAvailable Locales:\n\n");
        r = show_menu(locales, 3, 22, 60);
        if (r < 0)
                return r;

        putchar('\n');

        r = prompt_loop("Please enter system locale name or number", locales, locale_is_valid, &arg_locale);
        if (r < 0)
                return r;

        if (isempty(arg_locale))
                return 0;

        r = prompt_loop("Please enter system message locale name or number", locales, locale_is_valid, &arg_locale_messages);
        if (r < 0)
                return r;

        return 0;
}
Beispiel #25
0
static int prompt_hostname(void) {
        int r;

        if (arg_hostname)
                return 0;

        if (!arg_prompt_hostname)
                return 0;

        print_welcome();
        putchar('\n');

        for (;;) {
                _cleanup_free_ char *h = NULL;

                r = ask_string(&h, "%s Please enter hostname for new system (empty to skip): ", draw_special_char(DRAW_TRIANGULAR_BULLET));
                if (r < 0) {
                        log_error("Failed to query hostname: %s", strerror(-r));
                        return r;
                }

                if (isempty(h)) {
                        log_warning("No hostname entered, skipping.");
                        break;
                }

                if (!hostname_is_valid(h)) {
                        log_error("Specified hostname invalid.");
                        continue;
                }

                arg_hostname = h;
                h = NULL;
                break;
        }

        return 0;
}
static FILE *
script_fu_open_siod_console (void)
{
  if (siod_output == stdout)
    {
      if (pipe (siod_output_pipe))
	{
	  gimp_message (_("Unable to open SIOD output pipe"));
	}
      else if ((siod_output = fdopen (siod_output_pipe [1], "w")) == NULL)
	{
	  gimp_message (_("Unable to open a stream on the SIOD output pipe"));
	  siod_output = stdout;
	}
      else
	{
	  siod_verbose_level = 2;
	  print_welcome ();
	}
    }

  return siod_output;
}
Beispiel #27
0
static int prompt_hostname(void) {
        int r;

        if (arg_hostname)
                return 0;

        if (!arg_prompt_hostname)
                return 0;

        print_welcome();
        putchar('\n');

        for (;;) {
                _cleanup_free_ char *h = NULL;

                r = ask_string(&h, "%s Please enter hostname for new system (empty to skip): ", draw_special_char(DRAW_TRIANGULAR_BULLET));
                if (r < 0)
                        return log_error_errno(r, "Failed to query hostname: %m");

                if (isempty(h)) {
                        log_warning("No hostname entered, skipping.");
                        break;
                }

                if (!hostname_is_valid(h, true)) {
                        log_error("Specified hostname invalid.");
                        continue;
                }

                /* Get rid of the trailing dot that we allow, but don't want to see */
                arg_hostname = hostname_cleanup(h);
                h = NULL;
                break;
        }

        return 0;
}
Beispiel #28
0
void main(void) {
	volatile packet_t *p;
	char c;
	uint16_t r=30; /* start reception 100us before ack should arrive */
	uint16_t end=180; /* 750 us receive window*/

	/* trim the reference osc. to 24MHz */
	trim_xtal();

	uart_init(UART1, 115200);

	vreg_init();

	maca_init();

	set_channel(0); /* channel 11 */
//	set_power(0x0f); /* 0xf = -1dbm, see 3-22 */
//	set_power(0x11); /* 0x11 = 3dbm, see 3-22 */
	set_power(0x12); /* 0x12 is the highest, not documented */

        /* sets up tx_on, should be a board specific item */
	GPIO->FUNC_SEL_44 = 1;	 
	GPIO->PAD_DIR_SET_44 = 1;	 

	GPIO->FUNC_SEL_45 = 2;	 
	GPIO->PAD_DIR_SET_45 = 1;	 

	*MACA_RXACKDELAY = r;
	
	printf("rx warmup: %d\n\r", (int)(*MACA_WARMUP & 0xfff));

	*MACA_RXEND = end;

	printf("rx end: %d\n\r", (int)(*MACA_RXEND & 0xfff));

	set_prm_mode(AUTOACK);

	print_welcome("rftest-tx");

	while(1) {		
	    		
		/* call check_maca() periodically --- this works around */
		/* a few lockup conditions */
		check_maca();

		while((p = rx_packet())) {
			if(p) {
				printf("RX: ");
				print_packet(p);
				free_packet(p);
			}
		}

		if(uart1_can_get()) {
			c = uart1_getc();

			switch(c) {
			case 'z':
				r++;
				if(r > 4095) { r = 0; }
				*MACA_RXACKDELAY = r;
				printf("rx ack delay: %d\n\r", r);
				break;
			case 'x':
				if(r == 0) { r = 4095; } else { r--; }
				*MACA_RXACKDELAY = r;
				printf("rx ack delay: %d\n\r", r);
				break;
			case 'q':
				end++;
				if(r > 4095) { r = 0; }
				*MACA_RXEND = end;
				printf("rx end: %d\n\r", end);
				break;
			case 'w':
				end--;
				if(r == 0) { r = 4095; } else { r--; }
				*MACA_RXEND = end;
				printf("rx end: %d\n\r", end);
				break;
			default:
				p = get_free_packet();
				if(p) {
					fill_packet(p);
					
					printf("autoack-tx --- ");
					print_packet(p);
					
					tx_packet(p);				
				}
				break;
			}
		}
		
	}

}
Beispiel #29
0
main()
{
    // variable to store the users option selection, char used instead of int for error checking purposes
    char option;

    // array to store the user's selected numbers
    int user_nums[USER_SIZE];

    // validity check, variable for passing to function enter_nums1(), to check if user's input is valid before allowing access to options 2-6
    int valid = 0;

    // frequency check, variable for passing to function check_frequency5(), to check if the user has entered new numbers before incrementing the frequency again
    int flag_freq = 0;

    // welcome message to user
    print_welcome();


    // do-while option !=6, this loops around after each option ends and reprints the menu, asking for the user's next option choice
    do
    {

        // print the menu for user and ask their menu option
        print_menu();

        // scanf to hold the user option choice, using a char type to assist in error checking the user's input
        scanf("%1s", &option);

        // switch statement to control the menu options (1-6)
        switch(option)
        {

        // Menu Option 1: user selects 6 numbers from the range 1 to 42
        case '1':
        {
            // call function 'enter_nums1'
            enter_nums1(&valid, &flag_freq, user_nums);

            // break out of option 1
            break;

        } // end case 1


        // Menu Option 2: display user numbers
        case '2':
        {

            // control to prevent the user beginning the game without having first selected menu option 1 (enter numbers)
            if (valid == 0)
            {
                printf("\n*** ERROR: You must enter valid numbers first!\n");

            } // end if()

            else
            {
                // call function 'display_user_nums2'
                display_user_nums2(user_nums);

            } // end else

            // break out of option 2
            break;

        } // end case 2


        // Menu Option 3: Sort the user's numbers
        case '3':
        {

            // control to prevent the user beginning the game without having first selected menu option 1 (enter numbers)
            if (valid == 0)
            {
                printf("\n*** ERROR: You must enter valid numbers first!\n");

            } // end if()

            else
            {
                // call function 'sort3'
                sort3(user_nums);

            } // end else

            // break out of option 3
            break;

        } // end case 3, sorting numbers


        // Menu Option 4: Check winnings
        case '4':
        {
            // control to prevent the user beginning the game without having first selected menu option 1 (enter numbers)
            if (valid == 0)
            {
                printf("\n*** ERROR: You must enter valid numbers first!\n");

            } // end if()

            else
            {
                // call function 'check_nums4'
                check_wins4(user_nums);

            } // end else

            // break out of option 4
            break;

        } // end case 4, check for winnings


        // Menu Option 5: Check Frequency
        case '5':
        {

            // control to prevent the user beginning the game without having first selected menu option 1 (enter numbers)
            if (valid == 0)
            {
                printf("\n*** ERROR: You must enter valid numbers first!\n");

            } // end if()

            else
            {
                // call function 'check_frequency5'
                check_frequency5(&flag_freq, user_nums);

            } // end else

            // break out of option 5
            break;

        } // end case 5, check frequency


        // Menu Option 6: Exit Game
        case '6':
        {

            // if the user selects char '6', it must be converted to an int value in order to exit the do-while loop and therefore the program
            option = 6;
            getchar();

            // print exit message to user
            printf("\n\t\t\tYou selected Option 6 - Exit Game\n");
            printf("\n   Thank You for Playing - Goodbye!\n");
            printf("\n   - Press 'enter' to exit.");

            // break out of option 6
            break;

        } // end case 6, game ends


        // Default, if option != 1, 2, 3, 4, 5, 6
        default:
        {
            // print error message
            printf("\n*** ERROR: Please enter a VALID OPTION 1-6\n");

            // break out of switch_default
            break;

        } // end default

        } // end switch (option)

    } // end do-while
    while (option !=6);

    // to keep the window open for the user
    getchar();

} // end main()
Beispiel #30
0
/*
 * main
 */
int main(int argc, char** argv)
{
  fluid_settings_t* settings;
  int arg1 = 1;
  char buf[512];
  int c, i;
  int interactive = 1;
  int midi_in = 1;
  fluid_player_t* player = NULL;
  fluid_midi_router_t* router = NULL;
  //fluid_sequencer_t* sequencer = NULL;
  fluid_midi_driver_t* mdriver = NULL;
  fluid_audio_driver_t* adriver = NULL;
  fluid_synth_t* synth = NULL;
  fluid_server_t* server = NULL;
  char* config_file = NULL;
  int audio_groups = 0;
  int audio_channels = 0;
  int with_server = 0;
  int dump = 0;
  int fast_render = 0;
  int connect_lash = 1;
  char *optchars = "a:C:c:dE:f:F:G:g:hijK:L:lm:nO:o:p:R:r:sT:Vvz:";
#ifdef LASH_ENABLED
  int enabled_lash = 0;		/* set to TRUE if lash gets enabled */
  fluid_lash_args_t *lash_args;

  lash_args = fluid_lash_extract_args (&argc, &argv);
#endif

  print_welcome ();

  settings = new_fluid_settings();

#ifdef GETOPT_SUPPORT	/* pre section of GETOPT supported argument handling */
  opterr = 0;

  while (1) {
    int option_index = 0;

    static struct option long_options[] = {
      {"audio-bufcount", 1, 0, 'c'},
      {"audio-bufsize", 1, 0, 'z'},
      {"audio-channels", 1, 0, 'L'},
      {"audio-driver", 1, 0, 'a'},
      {"audio-file-endian", 1, 0, 'E'},
      {"audio-file-format", 1, 0, 'O'},
      {"audio-file-type", 1, 0, 'T'},
      {"audio-groups", 1, 0, 'G'},
      {"chorus", 1, 0, 'C'},
      {"connect-jack-outputs", 0, 0, 'j'},
      {"disable-lash", 0, 0, 'l'},
      {"dump", 0, 0, 'd'},
      {"fast-render", 1, 0, 'F'},
      {"gain", 1, 0, 'g'},
      {"help", 0, 0, 'h'},
      {"load-config", 1, 0, 'f'},
      {"midi-channels", 1, 0, 'K'},
      {"midi-driver", 1, 0, 'm'},
      {"no-midi-in", 0, 0, 'n'},
      {"no-shell", 0, 0, 'i'},
      {"option", 1, 0, 'o'},
      {"portname", 1, 0, 'p'},
      {"reverb", 1, 0, 'R'},
      {"sample-rate", 1, 0, 'r'},
      {"server", 0, 0, 's'},
      {"verbose", 0, 0, 'v'},
      {"version", 0, 0, 'V'},
      {0, 0, 0, 0}
    };

    c = getopt_long(argc, argv, optchars, long_options, &option_index);
    if (c == -1) {
      break;
    }
#else	/* "pre" section to non getopt argument handling */
  for (i = 1; i < argc; i++) {
    char *optarg;

    /* Skip non switch arguments (assume they are file names) */
    if ((argv[i][0] != '-') || (argv[i][1] == '\0')) break;

    c = argv[i][1];

    optarg = strchr (optchars, c);	/* find the option character in optchars */
    if (optarg && optarg[1] == ':')	/* colon follows if switch argument expected */
    {
      if (++i >= argc)
      {
	printf ("Option -%c requires an argument\n", c);
	print_usage();
	exit(0);
      }
      else
      {
	optarg = argv[i];
	if (optarg[0] == '-')
	{
	  printf ("Expected argument to option -%c found switch instead\n", c);
	  print_usage();
	  exit(0);
	}
      }
    }
    else optarg = "";
#endif

    switch (c) {
#ifdef GETOPT_SUPPORT
    case 0:	/* shouldn't normally happen, a long option's flag is set to NULL */
      printf ("option %s", long_options[option_index].name);
      if (optarg) {
	printf (" with arg %s", optarg);
      }
      printf ("\n");
      break;
#endif
    case 'a':
      if (FLUID_STRCMP (optarg, "help") == 0)
      {
        printf ("-a options (audio driver):\n   ");
        show_settings_str_options (settings, "audio.driver");
        exit (0);
      }
      else fluid_settings_setstr(settings, "audio.driver", optarg);
      break;
    case 'C':
      if ((optarg != NULL) && ((strcmp(optarg, "0") == 0) || (strcmp(optarg, "no") == 0))) {
	fluid_settings_setint(settings, "synth.chorus.active", FALSE);
      } else {
	fluid_settings_setint(settings, "synth.chorus.active", TRUE);
      }
      break;
    case 'c':
      fluid_settings_setint(settings, "audio.periods", atoi(optarg));
      break;
    case 'd':
      fluid_settings_setint(settings, "synth.dump", TRUE);
      dump = 1;
      break;
    case 'E':
      if (FLUID_STRCMP (optarg, "help") == 0)
      {
        printf ("-E options (audio file byte order):\n   ");
        show_settings_str_options (settings, "audio.file.endian");

#if LIBSNDFILE_SUPPORT
        printf ("\nauto: Use audio file format's default endian byte order\n"
                "cpu: Use CPU native byte order\n");
#else
        printf ("\nNOTE: No libsndfile support!\n"
                "cpu: Use CPU native byte order\n");
#endif
        exit (0);
      }
      else fluid_settings_setstr(settings, "audio.file.endian", optarg);
      break;
    case 'f':
      config_file = optarg;
      break;
    case 'F':
      fluid_settings_setstr(settings, "audio.file.name", optarg);
      fast_render = 1;
      break;
    case 'G':
      audio_groups = atoi(optarg);
      break;
    case 'g':
      fluid_settings_setnum(settings, "synth.gain", atof(optarg));
      break;
    case 'h':
      print_help(settings);
      break;
    case 'i':
      interactive = 0;
      break;
    case 'j':
      fluid_settings_setint(settings, "audio.jack.autoconnect", 1);
      break;
    case 'K':
      fluid_settings_setint(settings, "synth.midi-channels", atoi(optarg));
      break;
    case 'L':
      audio_channels = atoi(optarg);
      fluid_settings_setint(settings, "synth.audio-channels", audio_channels);
      break;
    case 'l':			/* disable LASH */
      connect_lash = 0;
      break;
    case 'm':
      if (FLUID_STRCMP (optarg, "help") == 0)
      {
        printf ("-m options (MIDI driver):\n   ");
        show_settings_str_options (settings, "midi.driver");
        exit (0);
      }
      else fluid_settings_setstr(settings, "midi.driver", optarg);
      break;
    case 'n':
      midi_in = 0;
      break;
    case 'O':
      if (FLUID_STRCMP (optarg, "help") == 0)
      {
        printf ("-O options (audio file format):\n   ");
        show_settings_str_options (settings, "audio.file.format");

#if LIBSNDFILE_SUPPORT
        printf ("\ns8, s16, s24, s32: Signed PCM audio of the given number of bits\n");
        printf ("float, double: 32 bit and 64 bit floating point audio\n");
        printf ("u8: Unsigned 8 bit audio\n");
#else
        printf ("\nNOTE: No libsndfile support!\n");
#endif
        exit (0);
      }
      else fluid_settings_setstr(settings, "audio.file.format", optarg);
      break;
    case 'o':
      process_o_cmd_line_option(settings, optarg);
      break;
    case 'p' :
      fluid_settings_setstr(settings, "midi.portname", optarg);
      break;
    case 'R':
      if ((optarg != NULL) && ((strcmp(optarg, "0") == 0) || (strcmp(optarg, "no") == 0))) {
	fluid_settings_setint(settings, "synth.reverb.active", FALSE);
      } else {
	fluid_settings_setint(settings, "synth.reverb.active", TRUE);
      }
      break;
    case 'r':
      fluid_settings_setnum(settings, "synth.sample-rate", atof(optarg));
      break;
    case 's':
      with_server = 1;
      break;
    case 'T':
      if (FLUID_STRCMP (optarg, "help") == 0)
      {
        printf ("-T options (audio file type):\n   ");
        show_settings_str_options (settings, "audio.file.type");

#if LIBSNDFILE_SUPPORT
        printf ("\nauto: Determine type from file name extension, defaults to \"wav\"\n");
#else
        printf ("\nNOTE: No libsndfile support!\n");
#endif
        exit (0);
      }
      else fluid_settings_setstr(settings, "audio.file.type", optarg);
      break;
    case 'V':
      printf("FluidSynth %s\n", VERSION);
      exit (0);
      break;
    case 'v':
      fluid_settings_setint(settings, "synth.verbose", TRUE);
      break;
    case 'z':
      fluid_settings_setint(settings, "audio.period-size", atoi(optarg));
      break;
#ifdef GETOPT_SUPPORT
    case '?':
      printf ("Unknown option %c\n", optopt);
      print_usage();
      exit(0);
      break;
    default:
      printf ("?? getopt returned character code 0%o ??\n", c);
      break;
#else			/* Non getopt default case */
    default:
      printf ("Unknown switch '%c'\n", c);
      print_usage();
      exit(0);
      break;
#endif
    }	/* end of switch statement */
  }	/* end of loop */

#ifdef GETOPT_SUPPORT
  arg1 = optind;
#else
  arg1 = i;
#endif

  /* option help requested?  "-o help" */
  if (option_help)
  {
    printf ("FluidSynth settings:\n");
    fluid_settings_foreach (settings, settings, settings_foreach_func);
    exit (0);
  }

#ifdef WIN32
  SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
#endif

#ifdef LASH_ENABLED
  /* connect to the lash server */
  if (connect_lash)
    {
      enabled_lash = fluid_lash_connect (lash_args);
      fluid_settings_setint (settings, "lash.enable", enabled_lash ? 1 : 0);
    }
#endif

  /* The 'groups' setting is only relevant for LADSPA operation
   * If not given, set number groups to number of audio channels, because
   * they are the same (there is nothing between synth output and 'sound card')
   */
  if ((audio_groups == 0) && (audio_channels != 0)) {
      audio_groups = audio_channels;
  }
  fluid_settings_setint(settings, "synth.audio-groups", audio_groups);

  if (fast_render) {
    midi_in = 0;
    interactive = 0;
    with_server = 0;
    fluid_settings_setstr(settings, "player.timing-source", "sample");  
    fluid_settings_setint(settings, "synth.parallel-render", 1); /* TODO: Fast_render should not need this, but currently do */
  }
  
  /* create the synthesizer */
  synth = new_fluid_synth(settings);
  if (synth == NULL) {
    fprintf(stderr, "Failed to create the synthesizer\n");
    exit(-1);
  }

  cmd_handler = new_fluid_cmd_handler(synth);
  if (cmd_handler == NULL) {
    fprintf(stderr, "Failed to create the command handler\n");
    goto cleanup;
  }

  /* load the soundfonts (check that all non options are SoundFont or MIDI files) */
  for (i = arg1; i < argc; i++) {
    if (fluid_is_soundfont(argv[i]))
    {
      if (fluid_synth_sfload(synth, argv[i], 1) == -1)
	fprintf(stderr, "Failed to load the SoundFont %s\n", argv[i]);
    }
    else if (!fluid_is_midifile(argv[i]))
      fprintf (stderr, "Parameter '%s' not a SoundFont or MIDI file or error occurred identifying it.\n",
	       argv[i]);
  }

#ifdef HAVE_SIGNAL_H
/*   signal(SIGINT, handle_signal); */
#endif

  /* start the synthesis thread */
  if (!fast_render) {
    adriver = new_fluid_audio_driver(settings, synth);
    if (adriver == NULL) {
      fprintf(stderr, "Failed to create the audio driver\n");
      goto cleanup;
    }
  }


  /* start the midi router and link it to the synth */
#if WITH_MIDI
  if (midi_in) {
    /* In dump mode, text output is generated for events going into and out of the router.
     * The example dump functions are put into the chain before and after the router..
     */
    //sequencer = new_fluid_sequencer2(0);

    router = new_fluid_midi_router(
      settings,
      dump ? fluid_midi_dump_postrouter : fluid_synth_handle_midi_event,
      (void*)synth);

    if (router == NULL) {
      fprintf(stderr, "Failed to create the MIDI input router; no MIDI input\n"
	      "will be available. You can access the synthesizer \n"
	      "through the console.\n");
    } else {
      fluid_synth_set_midi_router(synth, router); /* Fixme, needed for command handler */
//      fluid_sequencer_register_fluidsynth(sequencer, synth);
      mdriver = new_fluid_midi_driver(
	settings,
	dump ? fluid_midi_dump_prerouter : fluid_midi_router_handle_midi_event,
	(void*) router);
      if (mdriver == NULL) {
	fprintf(stderr, "Failed to create the MIDI thread; no MIDI input\n"
		"will be available. You can access the synthesizer \n"
		"through the console.\n");
      }
    }
  }
#endif

  /* run commands specified in config file */
  if (config_file != NULL) {
    fluid_source(cmd_handler, config_file);
  } else if (fluid_get_userconf(buf, 512) != NULL) {
    fluid_source(cmd_handler, buf);
  } else if (fluid_get_sysconf(buf, 512) != NULL) {
    fluid_source(cmd_handler, buf);
  }



  /* play the midi files, if any */
  for (i = arg1; i < argc; i++) {
    if ((argv[i][0] != '-') && fluid_is_midifile(argv[i])) {

      if (player == NULL) {
	player = new_fluid_player(synth);
	if (player == NULL) {
	  fprintf(stderr, "Failed to create the midifile player.\n"
		  "Continuing without a player.\n");
	  break;
	}
      }

      fluid_player_add(player, argv[i]);
    }
  }

  if (player != NULL) {
    fluid_player_play(player);
  }

  /* run the server, if requested */
#if !defined(MACINTOSH)
  if (with_server) {
    server = new_fluid_server(settings, newclient, synth);
    if (server == NULL) {
      fprintf(stderr, "Failed to create the server.\n"
	     "Continuing without it.\n");
    }
  }
#endif


#ifdef LASH_ENABLED
  if (enabled_lash)
    fluid_lash_create_thread (synth);
#endif

  /* run the shell */
  if (interactive) {
    printf ("Type 'help' for help topics.\n\n");

    /* In dump mode we set the prompt to "". The UI cannot easily
     * handle lines, which don't end with CR.  Changing the prompt
     * cannot be done through a command, because the current shell
     * does not handle empty arguments.  The ordinary case is dump ==
     * 0.
     */
    fluid_settings_setstr(settings, "shell.prompt", dump ? "" : "> ");
    fluid_usershell(settings, cmd_handler);
  }

  if (fast_render) {
    char *filename;
    if (player == NULL) {
      fprintf(stderr, "No midi file specified!\n");
      goto cleanup;
    } 

    fluid_settings_dupstr (settings, "audio.file.name", &filename);
    printf ("Rendering audio to file '%s'..\n", filename);
    if (filename) FLUID_FREE (filename);

    fast_render_loop(settings, synth, player);
  }

 cleanup:

#if !defined(MACINTOSH) && !defined(WIN32)
  if (server != NULL) {
    /* if the user typed 'quit' in the shell, kill the server */
    if (!interactive) {
      fluid_server_join(server);
    }
    delete_fluid_server(server);
  }
#endif

  if (cmd_handler != NULL) {
    delete_fluid_cmd_handler(cmd_handler);
  }

  if (player != NULL) {
    /* if the user typed 'quit' in the shell, stop the player */
    if (interactive) {
      fluid_player_stop(player);
    }
    if (adriver != NULL || !fluid_settings_str_equal(settings,  "player.timing-source", "sample")) {
      /* if no audio driver and sample timers are used, nothing makes the player advance */  
      fluid_player_join(player);
    }
    delete_fluid_player(player);
  }

  if (router) {
#if WITH_MIDI
    if (mdriver) {
      delete_fluid_midi_driver(mdriver);
    }
    delete_fluid_midi_router(router);
#endif
  }

  /*if (sequencer) {
    delete_fluid_sequencer(sequencer);
  }*/

  if (adriver) {
    delete_fluid_audio_driver(adriver);
  }

  if (synth) {
    delete_fluid_synth(synth);
  }

  if (settings) {
    delete_fluid_settings(settings);
  }

  return 0;
}

static fluid_cmd_handler_t* newclient(void* data, char* addr)
{
  fluid_synth_t* synth = (fluid_synth_t*) data;
  return new_fluid_cmd_handler(synth);
}