void table_add_player(table *t, player *p) { if (t->num_players == 3) { logging_critical("Can't add player %s to table %s because limit has been reached.", p->name, t->name); return; } *(t->players + t->num_players) = p; t->num_players++; send_str(p->socket, "Welcome to the table. Please wait for others to join.\n"); send_str(p->socket, "(you can talk to other users in the room whilst you wait)\n"); logging_debug("\nNow %i players on table %s. Waiting for %d more.\n", t->num_players, t->name, (3 - t->num_players) ); table_broadcast(t, "Player %s has joined %s.\n", p->name, t->name); if (t->num_players == 3) init_new_game(t); }
void connect_send_automat() { switch (css) { case CSSTART: { if (timer18 > 18) { //debug_print('T', 1, 4); timer18 = 0; css = C0PING; debug_print("Установка соединения", 20, 8); send_str("C0", 2); debug_print("C0", 2, Dmy); whetherC0 = 1; } break; } case C0PING: { if (timer18 > 18) { //debug_print('T', 1, 4); timer18 = 0; cgs = CGSTART; send_str("C0", 2); debug_print("C0", 2, Dmy); whetherC0 = 1; } break; } default: {} } }
cmd_err_t console_do_enter( void ) { cmd_err_t err = ERR_CMD_OK; console_current_line = 0; send_str( (char*) "\r\n" ); if ( strlen( console_buffer ) ) /* if theres something in the buffer */ { if ( strlen( console_buffer ) > strspn( console_buffer, console_delimit_string ) ) /* and it's not just delimit characters */ { /* store it and invoke the command parser */ history_store_line( console_buffer ); err = console_parse_cmd( console_buffer ); } } else { if ( history_get_num_lines( ) ) /* if theres a previous history line */ { /* load it and invoke the command parser */ history_load_line( 0, console_buffer ); err = console_parse_cmd( console_buffer ); } } /* prepare for a new line of entry */ console_buffer[0] = 0; console_cursor_position = 0; send_str( console_prompt_string ); return err; }
static void cmd_status(int argcp, char **argvp) { resp_begin(rsp_STATUS); switch(conn_state) { case STATE_CONNECTING: send_sym(tag_CONNSTATE, st_CONNECTING); send_str(tag_DEVICE, opt_dst); break; case STATE_CONNECTED: send_sym(tag_CONNSTATE, st_CONNECTED); send_str(tag_DEVICE, opt_dst); break; case STATE_SCANNING: send_sym(tag_CONNSTATE, st_SCANNING); send_str(tag_DEVICE, opt_dst); break; case STATE_ADVERTISING: send_sym(tag_CONNSTATE, st_ADVERTISING); send_str(tag_DEVICE, opt_dst); break; default: send_sym(tag_CONNSTATE, st_DISCONNECTED); break; } send_uint(tag_MTU, opt_mtu); send_str(tag_SEC_LEVEL, opt_sec_level); resp_end(); }
void print(char *print_str){ send_str(print_str); /* fio_write(1, print_str, strlen(print_str)); */ if(print_str[strlen(print_str)-1] == '\n') { //fio_write(1, "\r", 1); send_str("\r"); } }
void init_new_game(table *t) { int i; player *p; t->state = IN_PROGRESS; t->current_player = 0; t->card_deck = NULL; logging_debug("A game has started on table: %s!", t->name); table_broadcast(t, "The game has started!!!\n"); table_broadcast(t, "\n-- BEGIN LIST OF PLAYERS --\n"); for (i = 0; i < t->num_players; i++) { p = t->players[i]; table_broadcast(t, "%d: %s\n", (i + 1), p->name); } table_broadcast(t, "-- END LIST OF PLAYERS --\n"); //print the game rules table_broadcast(t, "Hopefully you already know how to play\n"); table_broadcast(t, "Texas Hold'em Poker. You will be dealt\n"); table_broadcast(t, "Your two cards and you make your choices\n"); table_broadcast(t, "(when prompted to) of\n"); table_broadcast(t, "b <<amount>> to bet or raise\n"); table_broadcast(t, "c to call\n"); table_broadcast(t, "f to fold\n"); deal_out_new_cards(t); t->deck = generate_new_deck(); //deal out the cards for (i = 0; i < t->num_players; i++) { p = t->players[i]; p->card_one = (card*) stack_pop(t->deck); send_str(t->players[i]->socket, "Your first card is a %s\n", card_tostring(p->card_one)); logging_info("%s dealt %s", t->players[i]->name, card_tostring(p->card_one)); } for (i = 0; i < t->num_players; i++) { p = t->players[i]; p->card_two = (card*) stack_pop(t->deck); send_str(t->players[i]->socket, "Your second card is a %s\n", card_tostring(p->card_two)); logging_info("%s dealt %s", t->players[i]->name, card_tostring(p->card_two)); } }
/** * Closes the damper shut. */ void CloseDamper( uint8_t damper) { if(DamperVerbose) { send_str(PSTR("\r\nDamper: ")); usb_serial_putchar((damper + '0')); send_str(PSTR("\r\nEnter CloseDamper Section \r\n")); } ActivateDamper(damper); _delay_ms(500); //step the device close uint8_t DamperStatus = CheckDamper(damper); // if already close, return if(DamperStatus == 1) { return; } unsigned int timeout = 0; // make sure the motor doesn't spin MotorDirection1LOW;// go in opposite direction //MotorDirection2HIGH; // set a timeout to 5 seconds while(DamperStatus != 1 || timeout == 50) { // step a lot MotorStepHIGH; DamperStatus = CheckDamper(damper); _delay_ms(100); MotorStepLOW; timeout++; if(DamperVerbose) { send_str(PSTR("ModTimer: ")); usb_serial_putchar((timeout / '0')); send_str(PSTR("\r\n")); } } if(timeout == 10000) { // report error to main Could be the wrong board that // we are trying to access. if(DamperVerbose) { send_str(PSTR(" Damper Close Error:TIMEOUT\r\n")); } } }
/** * this activates the correct damper * Then while checking the Damper's status * runs the stepper motor. */ void OpenDamper( uint8_t damper) { if(DamperVerbose) { send_str(PSTR("\r\nDamper: ")); usb_serial_putchar((damper + '0')); send_str(PSTR("\r\nEnter OpenDamper Section \r\n")); } //set the Damper Demux correctly ActivateDamper(damper); // for(int i; i < 10000; i++);// wait for signal propagation 0.5 seconds is _delay_ms(100); //step the device open uint8_t DamperStatus = CheckDamper(damper); // if already open, return if(DamperStatus == 0) { return; } // if not run the motor MotorDirection1HIGH; // MotorDirection2LOW; // current setting for A4988 // set a timeout unsigned int timeout = 0; // make sure the motor doesn't spin forever // timeout is 5 seconds is 100ms * 50 = 5 seconds while(DamperStatus != 0 || timeout > 50) { // step a lot// need a pause MotorStepHIGH; DamperStatus = CheckDamper(damper); // add ~500 milisec plenty of time for stepper motor not to crush everything _delay_ms(100); MotorStepLOW; timeout++; } if(timeout > 50) { // report error to main Could be the wrong board that // we are trying to access. if(DamperVerbose) { send_str(PSTR(" Damper Open Error:TIMEOUT\r\n")); } } }
void QHimePlatformInputContext::setFocusObject(QObject* object) { dbg("QHimePlatformInputContext::setFocusObject\n"); QWindow *window = qApp->focusWindow(); if (!window) { dbg("no window, focus out\n"); focused_win = 0; char *rstr = NULL; hime_im_client_focus_out2(hime_ch, &rstr); if (rstr) { send_str(rstr); } else { dbg("no str in preedit\n"); } return; } WId win = window->winId(); if (focused_win && win != focused_win) { if (hime_ch) { hime_im_client_focus_out(hime_ch); } } focused_win = win; if (hime_ch) { hime_im_client_set_window(hime_ch, win); hime_im_client_focus_in(hime_ch); cursorMoved(); } }
int __attribute__((format(printf,1,2))) printc(char *fmt, ...) { char s[MAX_LEN]; va_list arg_ptr; unsigned int ret; int len = MAX_LEN; /* Stable approach below. */ #if (NUM_CPU > 1) va_start(arg_ptr, fmt); ret = vsnprintf(s, len, fmt, arg_ptr); va_end(arg_ptr); cos_print(s, ret); return 0; #endif va_start(arg_ptr, fmt); ret = vsnprintf(s, len, fmt, arg_ptr); va_end(arg_ptr); if (unlikely(ret == 0)) goto done; send_str(s, ret); done: return ret; }
void deal_out_new_cards(table *t) { int i; card *tmp; card *one, *two; clean_up_game(t); t->card_deck = generate_new_deck(); //burn a card. tmp = (card*) stack_pop(t->card_deck); logging_debug("table %s, burning: %s", t->name, card_tostring(tmp)); //first pass for (i = 0; i < t->num_players; i++) { t->players[i]->cards[0] = (card*) stack_pop(t->card_deck); } //second pass for (i = 0; i < t->num_players; i++) { t->players[i]->cards[1] = (card*) stack_pop(t->card_deck); // send_str(t->players[i]->socket, // logging_debug("%s, you have been dealt:\n%s,\n%s\n", t->players[i]->name, card_tostring(t->players[i]->cards[0]), card_tostring(t->players[i]->cards[1])); send_str(t->players[i]->socket, "%s, you have been dealt: %s, %s ", t->players[i]->name, card_tostring(t->players[i]->cards[0]), card_tostring(t->players[i]->cards[1])); } }
static void console_insert_char( char c ) { uint32_t i; uint32_t len = strlen( console_buffer ); /* move the end of the line out to make space */ for ( i = len + 1; i > console_cursor_position; i-- ) { console_buffer[i] = console_buffer[i - 1]; } /* insert the character */ len++; console_buffer[console_cursor_position] = c; /* print out the modified part of the ConsoleBuffer */ send_str( &console_buffer[console_cursor_position] ); /* move the cursor back to where it's supposed to be */ console_cursor_position++; for ( i = len; i > console_cursor_position; i-- ) { send_char( '\b' ); } }
rt_public int app_start(char *cmd) /* The command string (without i/o redirection) */ { /* Start application under ised control and establish communication link * with ewb for debugging purpose. Return 0 if ok, -1 for failure. */ Request rqst; Request_Clean (rqst); rqst.rq_type = APPLICATION; /* Request application start-up */ ewb_send_packet(ewb_sp, &rqst); /* Send request for ised processing */ if (-1 == send_str(ewb_sp, cmd)) { /* Send command string */ #ifdef USE_ADD_LOG add_log(2, "ERROR cannot send command string"); #endif return -1; } #ifdef EIF_WINDOWS ewb_recv_packet(ewb_sp, &rqst, TRUE); /* Acknowledgment */ #else ewb_recv_packet(ewb_sp, &rqst); /* Acknowledgment */ #endif return AK_OK == rqst.rq_ack.ak_type ? 0 : -1; }
/* 接受客户端的连接请求 */ int accept_client(int sock_listen) { int i; socklen_t socklen; struct sockaddr_in peer_addr; int sock; /* 接受 */ socklen = sizeof(peer_addr); sock = accept(sock_listen, (struct sockaddr *)&peer_addr, &socklen); if (sock < 0) { perror("start_server: accept()"); return -1; } /* 在客户端数据的数组中查找一个未用的,并将新客户端的数据填入 */ for (i = 0; i < CLIENT_NUM; i++) { if (client[i].sockfd > 0) continue; client[i].sockfd = sock; strcpy(client[i].ip, inet_ntoa(peer_addr.sin_addr)); client[i].port = ntohs(peer_addr.sin_port); break; } /* 如果找不到说明能接受的客户端数目已达最大值 */ if (i == CLIENT_NUM) { printf("Cannot accept more client!\n"); close(sock); return -1; } printf("Accept remote %s:%d\n", client[i].ip, client[i].port); /* 发送字符串 OK */ send_str(sock, "server accept OK"); return 0; }
void Example_UART_Print(void) { /* Initialize system */ SIO_Configuration(UART1); SIO_ChInit(); /* enable SIO1 trx int */ NVIC_EnableIRQ(INTTX1_IRQn); //Send char one by one send_char('C'); send_char('o'); send_char('o'); send_char('C'); send_char('o'); send_char('x'); send_char('\r'); send_char('\n'); //Send chars as string send_str("Hello, CooCox\r\n"); while (1); }
// Basic command interpreter for controlling port pins int main(void) { char buf[32]; uint8_t n; // set for 16 MHz clock, and turn on the LED CPU_PRESCALE(0); LED_CONFIG; LED_ON; // initialize the USB, and then wait for the host // to set configuration. If the Teensy is powered // without a PC connected to the USB port, this // will wait forever. usb_init(); while (!usb_configured()) /* wait */ ; _delay_ms(1000); while (1) { // wait for the user to run their terminal emulator program // which sets DTR to indicate it is ready to receive. while (!(usb_serial_get_control() & USB_SERIAL_DTR)) /* wait */ ; // discard anything that was received prior. Sometimes the // operating system or other software will send a modem // "AT command", which can still be buffered. usb_serial_flush_input(); // print a nice welcome message send_str(PSTR("\r\nTeensy USB Serial Example, " "Simple Pin Control Shell\r\n\r\n" "Example Commands\r\n" " B0? Read Port B, pin 0\r\n" " C2=0 Write Port C, pin 1 LOW\r\n" " D6=1 Write Port D, pin 6 HIGH (D6 is LED pin)\r\n\r\n")); // and then listen for commands and process them while (1) { usb_serial send_str(PSTR("> ")); n = recv_str(buf, sizeof(buf)); if (n == 255) break; send_str(PSTR("\r\n")); parse_and_execute_command(buf, n); } } }
int main() { while (1) { send_str("Message test", "127.0.0.1", 33666); sleep(1); } }
void mpu_write_byte(unsigned char addr,unsigned char dat){ i2c_start(); if(i2c_send_byte(SlaveAddress)){ //Address for mpu6050 send_str("i2c_send_byte(SlaveAddress) success!"); } i2c_send_byte(addr); //Address for register i2c_send_byte(dat); //write data to rigister i2c_stop(); }
static void cmd_info(int argcp, char **argvp) { struct hci_dev_info di = { 0 }; char s[18]; hci_devinfo(opt_src_idx, &di); if (ba2str(&di.bdaddr, s) != 17) memset(s, 0xFF, sizeof(s) - 1); resp_begin(rsp_MGMT); send_sym(tag_ERRCODE, err_SUCCESS); /* Always returns the programmed public bdaddr of the device */ send_str(tag_ADDR, s); send_str(tag_TYPE, "public"); resp_end(); }
cmd_err_t console_do_newline_without_command_repeat( void ) { cmd_err_t err = ERR_CMD_OK; if ( strlen( console_buffer ) ) /* if theres something in the buffer */ { err = console_do_enter( ); } else { /* prepare for a new line of entry */ console_buffer[0] = 0; console_cursor_position = 0; send_str( (char*) "\r\n" ); send_str( console_prompt_string ); } return err; }
static const char *send_command(const char *cmd) { static const char *s; send_str(cmd); wait_ms(500); s = rn42_gets(100); xprintf("%s\r\n", s); print_rn42(); return s; }
static void console_load_line( uint32_t new_line ) { uint32_t i; uint32_t old_len; uint32_t new_len; old_len = strlen( console_buffer ); if ( new_line > 0 ) { history_load_line( new_line - 1, console_buffer ); } else { console_buffer[0] = 0; } new_len = strlen( console_buffer ); /* seek to the start of the line */ send_char('\r'); /* print out the prompt and new line */ send_str( console_prompt_string ); send_str( console_buffer ); /* write spaces over the rest of the old line */ for ( i = new_len; i < old_len; i++ ) { send_char( ' ' ); } /* then move back the same amount */ for ( i = new_len; i < old_len; i++ ) { send_char( '\b' ); } console_current_line = new_line; /* position the cursor at the end of the line */ console_cursor_position = new_len; }
bool QHimePlatformInputContext::send_key_press(quint32 keysym, quint32 state) { dbg("send_key_press\n"); char *rstr = NULL; int result = hime_im_client_forward_key_press(hime_ch, keysym, state, &rstr); if (rstr) { send_str(rstr); } return result; }
// parse a user command and execute it, or print an error message // void parse_and_execute_command(const char *buf, uint8_t num) { uint8_t port, pin, val; if (num < 3) { return; } // first character is the port letter if (buf[0] >= 'A' && buf[0] <= 'F') { port = buf[0] - 'A'; } else if (buf[0] >= 'a' && buf[0] <= 'f') { port = buf[0] - 'a'; } else { return; } // second character is the pin number if (buf[1] >= '0' && buf[1] <= '7') { pin = buf[1] - '0'; } else { return; } // if the third character is a question mark, read the pin if (buf[2] == '?') { // make the pin an input *(uint8_t *)(0x21 + port * 3) &= ~(1 << pin); // drive it high for high impedance *(uint8_t *)(0x22 + port * 3) |= (1 << pin); // read the pin val = *(uint8_t *)(0x20 + port * 3) & (1 << pin); usb_serial_putchar(val ? '1' : '0'); send_str(PSTR("\r\n")); return; } // if the third character is an equals sign, write the pin if (num >= 4 && buf[2] == '=') { if (buf[3] == '0') { // make the pin an output *(uint8_t *)(0x21 + port * 3) |= (1 << pin); // drive it low *(uint8_t *)(0x22 + port * 3) &= ~(1 << pin); return; } else if (buf[3] == '1') { // make the pin an output *(uint8_t *)(0x21 + port * 3) |= (1 << pin); // drive it high *(uint8_t *)(0x22 + port * 3) |= (1 << pin); return; } else { return; } } }
void sendSS() { if (timer18 >= 18) { if (argslen >= 2) debug_print("SS", 2, Dmy); send_str("SS", 2); timer18 = 0; } if (timer55 >= 55) { debug_print("Потеряна связь с противником", 28, 4); ggs = GGCONNECT; } }
int prints(char *str) { unsigned int len; len = cos_strlen(str); if (unlikely(len == 0)) goto done; send_str(str, len); done: return 0; }
/** * So the Damper has a procedure to access the status * first to have to activate the section * second you have to check if it is open = 0 * third you have to check if it is close = 1 * fourth you have to check if it is in the middle = 2 * damper is a number from 0 to 15 */ uint8_t CheckDamper(uint8_t damper) { //Go through each damper and check if the input on the Bus is high or low. //double make sure it is good. ActivateDamper(damper); // check if it is in the middle for(int i; i < 10000; i++);// wait for signal propagation 0.5 seconds is // enough // it is in the middle of turning if(ISBUTTONOPENBUSHIGH & ISBUTTONCLOSEBUSHIGH) { if(DamperVerbose) { send_str(PSTR("Both inputs are HIGH\r\n")); } return 2; } else if(!ISBUTTONOPENBUSHIGH & ISBUTTONCLOSEBUSHIGH) { if(DamperVerbose) { send_str(PSTR("OPENBUS is LOW and CLOSE Button is HIGH\r\n")); } return 0; } else { if(DamperVerbose) { send_str(PSTR("CloseButton is Low and Open Button is HIGH\r\n")); } return 1; } }
void uplink_cmd_handler(void) { static char cmd[20]; static uint8_t index = 0; // No data received, return if(buffer_level(UPLINK_USART,RX) < 1) return; // flush cmd buffer if cmd is out of a valid length if(index == MAX_CMD_LENGTH) { index = 0; } // append char to cmd recv_char(UPLINK_USART, &cmd[index]); switch(cmd[index]) { case '\r': // carriage return received, replace with stringtermination and parse send_str(UPLINK_USART, "\r\n"); cmd[index] = '\0'; parse_cmd(cmd); index = 0; break; case '\n': // do nothing, but avoid index from incrementing break; case '\b': // backspace, remove last received char index--; send_char(UPLINK_USART, '\b'); break; // char is part of an ESC sequence case 0x1B: case 0x5B: index++; break; // each other if the last two char was not part of an ESC sequence default: if(cmd[index - 1] == 0x5B && cmd[index - 2] == 0x1B) { index = index - 2; } else { send_char(UPLINK_USART, cmd[index]); index++; } } }
byte cx_send() { if (whetherC0) { STR[0] = 'C'; STR[1] = Cx + 48; /* send_str("C0", 2); debug_print("C0", 2, Dmy);*/ send_str(STR, 2); debug_print(STR, 2, Dmy); // Если через 18 не будет ответного Cx, идем на начало. timer18 = 0; css = C0PING; return 1; } css = C0PING; return 0; }
wiced_result_t command_console_init( wiced_uart_t uart, uint32_t line_len, char* buffer, uint32_t history_len, char* history_buffer_ptr, const char* delimiter_string ) { wiced_result_t result; UNUSED_PARAMETER(result); cons.uart = uart; cons.command_table_count = 0; cons.console_line_len = line_len; cons.console_buffer = buffer; cons.console_buffer[0] = 0; cons.console_cursor_position = 0; cons.console_current_line = 0; cons.console_in_esc_seq = WICED_FALSE; cons.console_esc_seq_last_char = ' '; cons.history_buffer = history_buffer_ptr; cons.history_length = history_len; cons.history_num_lines = 0; cons.history_newest_line = 0; cons.quit = WICED_FALSE; cons.console_delimit_string = delimiter_string; cons.console_prompt_string = "> "; cons.console_thread_is_running = WICED_FALSE; console_add_cmd_table( commands ); if( uart != STDIO_UART ) { /* Init uart the same as stdio uart configuration */ ring_buffer_init( (wiced_ring_buffer_t*) &cons.console_rx_ring_buffer, (uint8_t*) console_rx_ring_data, sizeof(console_rx_ring_data) ); result = wiced_uart_init(uart, &uart_console_config, &cons.console_rx_ring_buffer); } wiced_rtos_init_semaphore(&cons.console_quit_semaphore); send_str(cons.console_prompt_string); /* create a console thread */ result = wiced_rtos_create_thread( &cons.console_thread, WICED_DEFAULT_LIBRARY_PRIORITY, "console", console_thread_func, CONSOLE_THREAD_STACK_SIZE, NULL); return result; }