void handle_init() { send_ack(message.sequence); send_version(); state = StateConnected; led_on(UART0_LED_STATE); }
static void sig_recv_iq(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type, const char *id, const char *from, const char *to) { LmMessageNode *node, *child; char *name, *version, *os; if (type == LM_MESSAGE_SUB_TYPE_RESULT && (node = lm_find_node(lmsg->node,"query", XMLNS, XMLNS_VERSION)) != NULL) { name = version = os = NULL; for (child = node->children; child != NULL; child = child->next) { if (child->value == NULL) continue; if (name == NULL && strcmp(child->name, "name") == 0) g_strstrip(name = xmpp_recode_in(child->value)); else if (version == NULL && strcmp(child->name, "version") == 0) g_strstrip(version = xmpp_recode_in(child->value)); else if (os == NULL && strcmp(child->name, "os") == 0) g_strstrip(os = xmpp_recode_in(child->value)); } signal_emit("xmpp version", 5, server, from, name, version, os); g_free(name); g_free(version); g_free(os); } else if (type == LM_MESSAGE_SUB_TYPE_GET && (node = lm_find_node(lmsg->node,"query", XMLNS, XMLNS_VERSION)) != NULL) send_version(server, from, id); }
// all watcher callbacks have a similar signature // this callback is called when data is readable on stdin static void stdin_cb (EV_P_ struct ev_io *w, int revents) { // Read a line char *line = 0; unsigned int len = 0; getline(&line, &len, stdin); char cmd[64] = {0}; // this will crash if you enter bad strings in stdin! sscanf(line, " %s ", cmd); // Main interactive command dispatch if (!strcmp(cmd, "ping")) { printf("you said ping\n"); } else if (!strcmp(cmd, "help")) { printf("Commands: [cmd] [argument] ... \n"); printf(" help : shows this message\n"); printf(" quit : quits\n"); printf(" version : sends version message client\n"); printf(" ping : sends ping message to connected client\n"); printf("\n"); } else if (!strcmp(cmd, "version")) { printf("sending version\n"); send_version(); } else if (!strcmp(cmd, "quit")) { printf("Quitting...\n"); ev_unloop(EV_A_ EVUNLOOP_ALL); } else if (!strcmp(cmd, "")) { } else { printf("command not recognized: '%s'\n", cmd); } }
static int connect_to_server(tc_event_loop_t *ev_lp) { int i, j, fd; uint32_t target_ip; conns_t *conns; uint16_t target_port; for (i = 0; i < clt_settings.real_servers.num; i++) { conns = &(clt_settings.real_servers.conns[i]); target_ip = conns[i].ip; target_port = conns[i].port; if (target_port == 0) { target_port = clt_settings.srv_port; } if (conns[i].active != 0) { continue; } for (j = 0; j < conns->num; j++) { fd = conns->fds[j]; if (fd > 0) { tc_log_info(LOG_NOTICE, 0, "it close socket:%d", fd); tc_socket_close(fd); tc_event_del(clt_settings.ev[fd]->loop, clt_settings.ev[fd], TC_EVENT_READ); tc_event_destroy(clt_settings.ev[fd], 0); conns->fds[j] = -1; } } clt_settings.real_servers.conns[i].num = 0; clt_settings.real_servers.conns[i].remained_num = 0; for (j = 0; j < clt_settings.par_conns; j++) { fd = tc_message_init(ev_lp, target_ip, target_port); if (fd == TC_INVALID_SOCK) { return TC_ERR; } if (!send_version(fd)) { return TC_ERR; } if (j == 0) { clt_settings.real_servers.active_num++; conns[i].active = 1; } clt_settings.real_servers.conns[i].fds[j] = fd; clt_settings.real_servers.conns[i].num++; clt_settings.real_servers.conns[i].remained_num++; } } return TC_OK; }
static int start_handshake(struct vio_driver_state *vio) { int err; viodbg(HS, "START HANDSHAKE\n"); vio->hs_state = VIO_HS_INVALID; err = send_version(vio, vio->ver_table[0].major, vio->ver_table[0].minor); if (err < 0) return err; return 0; }
static int process_ver_nack(struct vio_driver_state *vio, struct vio_ver_info *pkt) { struct vio_version *nver; viodbg(HS, "GOT VERSION NACK maj[%u] min[%u] devclass[%u]\n", pkt->major, pkt->minor, pkt->dev_class); if (pkt->major == 0 && pkt->minor == 0) return handshake_failure(vio); nver = find_by_major(vio, pkt->major); if (!nver) return handshake_failure(vio); if (send_version(vio, nver->major, nver->minor) < 0) return handshake_failure(vio); return 0; }
static void init(void) { config_load(); #ifdef ENABLE_LOCALIZE locale_init(); #endif heartrate_init(); s_gpsdata.heartrate = 255; // no data at startup bg_color_data_main = BG_COLOR_DATA_MAIN; #ifdef ENABLE_NAVIGATION_FULL for (uint16_t i = 0; i < NAV_NB_POINTS_STORAGE - 1; i++) { s_gpsdata.nav_xpos[i] = s_gpsdata.nav_ypos[i] = INT16_MAX; } #endif #ifdef ENABLE_DEBUG_FIELDS_SIZE strcpy(s_data.speed, "188.8"); strcpy(s_data.distance, "88.8"); strcpy(s_data.avgspeed, "888.8"); strcpy(s_data.altitude, "888.8"); strcpy(s_data.ascent, "1342"); strcpy(s_data.ascentrate, "548"); strcpy(s_data.slope, "5"); strcpy(s_data.accuracy, "9"); strcpy(s_data.bearing, "270"); strcpy(s_data.elapsedtime, "1:05:28"); strcpy(s_data.maxspeed, "25.3"); strcpy(s_data.heartrate, "128"); strcpy(s_data.cadence, "90"); #endif #ifdef ENABLE_DEMO strcpy(s_data.maxspeed, "26.1"); strcpy(s_data.distance, "2.0"); strcpy(s_data.avgspeed, "14.0"); strcpy(s_data.altitude, "1139"); strcpy(s_data.accuracy, "4"); strcpy(s_data.steps, "7548"); strcpy(s_data.elapsedtime, "1:15:28"); strcpy(s_data.heartrate, "154"); s_gpsdata.heartrate = 154; heartrate_new_data(s_gpsdata.heartrate); s_data.live = 1; s_data.state = STATE_START; s_gpsdata.nav_distance_to_destination100 = 12100; s_gpsdata.nav_next_distance1000 = 1345; s_gpsdata.nav_error1000 = 55; snprintf(s_data.nav_next_distance, sizeof(s_data.nav_next_distance), "%d", s_gpsdata.nav_next_distance1000); #else strcpy(s_data.speed, "0.0"); strcpy(s_data.distance, "-"); strcpy(s_data.avgspeed, "-"); strcpy(s_data.altitude, "-"); strcpy(s_data.ascent, "-"); strcpy(s_data.ascentrate, "-"); strcpy(s_data.slope, "-"); strcpy(s_data.accuracy, "-"); strcpy(s_data.bearing, "-"); strcpy(s_data.elapsedtime, "00:00:00"); strcpy(s_data.maxspeed, "-"); strcpy(s_data.heartrate, "-"); strcpy(s_data.cadence, "-"); strcpy(s_data.nav_next_distance, "-"); strcpy(s_data.nav_distance_to_destination, "-"); strcpy(s_data.nav_ttd, "-"); strcpy(s_data.nav_eta, "-"); #endif //strcpy(s_data.lat, "-"); //strcpy(s_data.lon, "-"); //strcpy(s_data.nbascent, "-"); s_data.phone_battery_level = -1; #ifdef PBL_PLATFORM_CHALK font_roboto_bold_16 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_16)); #endif font_roboto_bold_62 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_62)); // set default unit of measure change_units(UNITS_IMPERIAL, true); buttons_init(); s_data.window = window_create(); window_set_background_color(s_data.window, BG_COLOR_WINDOW); #ifdef PBL_SDK_2 window_set_fullscreen(s_data.window, true); #endif topbar_layer_init(s_data.window); screen_data_layer_init(s_data.window); //screen_altitude_layer_init(s_data.window); #ifdef ENABLE_FUNCTION_LIVE screen_live_layer_init(s_data.window); #endif screen_map_layer_init(s_data.window); #ifdef PRODUCTION #ifndef ENABLE_DEMO screen_reset_instant_data(); #endif #endif action_bar_init(s_data.window); menu_init(); // Reduce the sniff interval for more responsive messaging at the expense of // increased energy consumption by the Bluetooth module // The sniff interval will be restored by the system after the app has been // unloaded //app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); communication_init(); screen_data_update_config(true); //screen_altitude_update_config(); graph_init(); window_stack_push(s_data.window, true /* Animated */); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); bluetooth_connection_service_subscribe(bt_callback); send_version(true); }
static int connect_to_server(tc_event_loop_t *event_loop) { int i, j, fd; uint32_t target_ip; #if (TCPCOPY_DR) uint16_t target_port; #else ip_port_pair_mapping_t *pair, **mappings; #endif #if (TCPCOPY_DR) /* * add connections to the real servers for sending router info * and receiving response packet */ for (i = 0; i < clt_settings.real_servers.num; i++) { target_ip = clt_settings.real_servers.ips[i]; target_port = clt_settings.real_servers.ports[i]; if (target_port == 0) { target_port = clt_settings.srv_port; } if (clt_settings.real_servers.active[i] != 0) { continue; } clt_settings.real_servers.connections[i].num = 0; clt_settings.real_servers.connections[i].remained_num = 0; for (j = 0; j < clt_settings.par_connections; j++) { fd = tc_message_init(event_loop, target_ip, target_port); if (fd == TC_INVALID_SOCKET) { return TC_ERROR; } if (!send_version(fd)) { return TC_ERROR; } if (j == 0) { clt_settings.real_servers.active_num++; clt_settings.real_servers.active[i] = 1; } clt_settings.real_servers.connections[i].fds[j] = fd; clt_settings.real_servers.connections[i].num++; clt_settings.real_servers.connections[i].remained_num++; } tc_log_info(LOG_NOTICE, 0, "add dr tunnels for exchanging info:%u:%u", target_ip, target_port); } #else mappings = clt_settings.transfer.mappings; for (i = 0; i < clt_settings.transfer.num; i++) { pair = mappings[i]; target_ip = pair->target_ip; for ( j = 0; j < clt_settings.par_connections; j++) { fd = tc_message_init(event_loop, target_ip, clt_settings.srv_port); if (fd == TC_INVALID_SOCKET) { return TC_ERROR; } if (!send_version(fd)) { return TC_ERROR; } address_add_sock(pair->online_ip, pair->online_port, fd); } tc_log_info(LOG_NOTICE, 0, "add tunnels for exchanging info:%u:%u", target_ip, clt_settings.srv_port); } #endif return TC_OK; }
int main(int argc, char *argv[]) { struct server_settings settings = {30000, 0, 1}; handle_arguments(argc, argv, &settings); struct player_character hero; init_player_character(&hero); char stat_buffer[256]; randomize_player_character_stats(&hero); snprintf(stat_buffer, 255, "STR - %i\r\nDEX - %i\r\nCON - %i\r\n", hero.strength, hero.dexterity, hero.constitution); if (catch_signal(SIGINT, handle_shutdown) == -1) { error("Can't set the interrupt handler"); } else if (settings.verbose) { puts("Interrupt handler set"); } listener_d = open_listener_socket(); bind_to_port(listener_d, settings.port_number); if (listen(listener_d, 10) == -1) { error("Can't listen"); } else if (settings.verbose) { printf("Listening on port %i", settings.port_number); } struct sockaddr_storage client_addr; unsigned int address_size = sizeof(client_addr); if (settings.verbose) { puts("Waiting for connection"); } while(1) { int connect_d = accept(listener_d, (struct sockaddr *)&client_addr, &address_size); if (connect_d == -1) { error("Can't open secondary socket"); } else if (settings.verbose) { puts("New connection started"); } if (!fork()) { close(listener_d); char input_buffer[512]; char output_buffer[512]; char send_buffer[512]; char action_buffer[3]; send_version(connect_d); while (1) { get_command(connect_d, action_buffer); puts(action_buffer); if (action_buffer[0] == 's') { puts("opening chat buffer"); listen_to_client(connect_d, input_buffer); parse_command(input_buffer, output_buffer); sprintf(send_buffer, "You said: \"%s\"\r\n", output_buffer); puts(send_buffer); send_to_client(connect_d, send_buffer); } else { handle_user_command(connect_d, action_buffer); } } close(connect_d); exit(0); } close(connect_d); } return 0; }
void ControlPack::parse() { uint8_t src = _buffer[0]; uint8_t dst = _buffer[1]; uint8_t cmd = _buffer[2]; if (dst == _me || dst == CP_EVERYONE) { switch (cmd) { case CPC_HEARTBEAT: if (_cb_heartbeat != 0) { _cb_heartbeat(src, dst); } break; case CPC_VERSION_QUERY: send_version(dst); break; case CPC_VERSION_INFO: if (_cb_version_info != 0) { uint16_t version = (_buffer[3] << 8) + _buffer[4]; _cb_version_info(src, dst, version); } break; case CPC_MODEL_QUERY: send_model(dst); break; case CPC_MODEL_INFO: if (_cb_model_info != 0) { _cb_model_info(src, dst, _buffer[3]); } break; case CPC_PORT_QUERY: send_ports(dst); break; case CPC_PORT_INFO: if (_cb_port_info != 0) { _cb_port_info(src, dst, _buffer[3]); } break; case CPC_ALL_OFF: if (_cb_all_off != 0) { _cb_all_off(src, dst); } break; case CPC_ALL_ON: if (_cb_all_on != 0) { _cb_all_on(src, dst); } break; case CPC_ALL_TIMED: if (_cb_all_timed != 0) { uint16_t millis = (_buffer[3] << 8) + _buffer[4]; _cb_all_timed(src, dst, millis); } break; case CPC_PORT_OFF: if (_cb_port_off != 0) { _cb_port_off(src, dst, _buffer[3]); } break; case CPC_PORT_ON: if (_cb_port_on != 0) { _cb_port_on(src, dst, _buffer[3]); } break; case CPC_PORT_TIMED: if (_cb_port_timed != 0) { uint16_t millis = (_buffer[4] << 8) + _buffer[5]; _cb_port_timed(src, dst, _buffer[3], millis); } break; case CPC_SEQUENCE_UP: if (_cb_sequence_up != 0) { uint16_t millis = (_buffer[3] << 8) + _buffer[4]; _cb_sequence_up(src, dst, millis); } break; case CPC_SEQUENCE_DOWN: if (_cb_sequence_down != 0) { uint16_t millis = (_buffer[3] << 8) + _buffer[4]; _cb_sequence_down(src, dst, millis); } break; default: break; } } }
static int connect_to_server(tc_event_loop_t *event_loop) { int i, j, fd; uint32_t target_ip; uint16_t target_port; connections_t *connections; /* * add connections to the real servers for sending router info * and receiving response packet */ for (i = 0; i < clt_settings.real_servers.num; i++) { target_ip = clt_settings.real_servers.ips[i]; target_port = clt_settings.real_servers.ports[i]; if (target_port == 0) { target_port = clt_settings.srv_port; } if (clt_settings.real_servers.active[i] != 0) { continue; } connections = &(clt_settings.real_servers.connections[i]); for (j = 0; j < connections->num; j++) { fd = connections->fds[j]; if (fd > 0) { tc_log_info(LOG_NOTICE, 0, "it close socket:%d", fd); tc_socket_close(fd); tc_event_del(clt_settings.ev[fd]->loop, clt_settings.ev[fd], TC_EVENT_READ); tc_event_destroy(clt_settings.ev[fd]); connections->fds[j] = -1; } } clt_settings.real_servers.connections[i].num = 0; clt_settings.real_servers.connections[i].remained_num = 0; for (j = 0; j < clt_settings.par_connections; j++) { fd = tc_message_init(event_loop, target_ip, target_port); if (fd == TC_INVALID_SOCKET) { return TC_ERROR; } if (!send_version(fd)) { return TC_ERROR; } if (j == 0) { clt_settings.real_servers.active_num++; clt_settings.real_servers.active[i] = 1; } clt_settings.real_servers.connections[i].fds[j] = fd; clt_settings.real_servers.connections[i].num++; clt_settings.real_servers.connections[i].remained_num++; } tc_log_info(LOG_NOTICE, 0, "add dr tunnels for exchanging info:%u:%u", target_ip, target_port); } return TC_OK; }