void lhmsv_print(lhmsv_t* pmap) { for (int index = 0; index < pmap->array_length; index++) { lhmsve_t* pe = &pmap->entries[index]; const char* key_string = (pe == NULL) ? "none" : pe->key == NULL ? "null" : pe->key; printf( "| stt: %-8s | idx: %6d | nidx: %6d | key: %12s | pvvalue: %p |\n", get_state_name(pmap->states[index]), index, pe->ideal_index, key_string, pe->pvvalue); } printf("+\n"); printf("| phead: %p | ptail %p\n", pmap->phead, pmap->ptail); printf("+\n"); for (lhmsve_t* pe = pmap->phead; pe != NULL; pe = pe->pnext) { const char* key_string = (pe == NULL) ? "none" : pe->key == NULL ? "null" : pe->key; printf( "| prev: %p curr: %p next: %p | nidx: %6d | key: %12s | pvvalue: %p |\n", pe->pprev, pe, pe->pnext, pe->ideal_index, key_string, pe->pvvalue); } }
// Prepare deck to go into 'READY' state void do_cue(float cuepoint) { if (verbose) printf("-> do_cue(%f)\n", cuepoint); // Stop first if (get_state() == MADJACK_STATE_PLAYING || get_state() == MADJACK_STATE_PAUSED) { do_stop(); } // Had cue-point changed? if (get_state() == MADJACK_STATE_READY && input_file->position != cuepoint) { if (verbose) printf("Stopping because cuepoint changed.\n"); do_stop(); } // Start the new thread if (get_state() == MADJACK_STATE_LOADING || get_state() == MADJACK_STATE_STOPPED ) { // Set the decoder running start_decoder_thread( input_file, cuepoint ); } else if (get_state() != MADJACK_STATE_READY) { fprintf(stderr, "Warning: Can't change from %s to state READY.\n", get_state_name(get_state()) ); } }
void set_state(syslog_parser *parser, syslog_state next_state) { // Print the state switch if we're compiled in DEBUG mode #if DEBUG_OUTPUT printf("Setting state to: %s\n", get_state_name(next_state)); #endif parser->state = next_state; set_token_state(parser, ts_before); }
/* * Returns a state name identifier. Uses the symbolic name if it exists, * otherwise it will return the value with an "s" in front. */ char * etf_state_value(etf_model_t model, int state, int value) { if (sanitized_types==NULL) sanitize_types(model); int type_no = lts_type_get_state_typeno(etf_type(model), state); int v_count = etf_get_value_count(model, type_no); if (v_count > value) { return sanitized_types[type_no][value]; } else { return get_state_name(value); } }
int main(int argc, char **argv) { ros::init(argc, argv, "prx_decision_making"); ros::NodeHandle nh; if (argc != 2) { std::cout << "Usage:\n prx_decision_making_node <work order Json file>" << std::endl; return (1); } std::string work_order_json_file_name(argv[1]); number_of_orders = read_file(work_order_json_file_name, work_order, bin_contents); // Publishers ros::Publisher decison_making_state_publisher = nh.advertise<prx_decision_making::DecisionMakingStateMessage>("decision_making_state", 1); ros::Publisher baxter_display_image_publisher = nh.advertise<sensor_msgs::Image>("/robot/xdisplay", 1, true); g_baxter_display_image_publisher = &baxter_display_image_publisher; //Subscribers ros::Subscriber motion_planner_subscriber = nh.subscribe("/motion_planner_state", 1, motion_planner_subscriber_callback); ros::Rate loop_rate(40); prx_decision_making::DecisionMakingStateMessagePtr decision_making_state_msg(new prx_decision_making::DecisionMakingStateMessage); init_decision_making_state_msg(decision_making_state_msg); std::cout << "\n"; int error = 0; static int previous_state = -1; while (ros::ok() && (error == 0)) { decison_making_state_publisher.publish(decision_making_state_msg); error = run_decision_making_state_machine(decision_making_state_msg); if (decision_making_state_msg->state != previous_state) { std::cout << get_state_name(decision_making_state_msg->state) << " \n"; previous_state = decision_making_state_msg->state; } ros::spinOnce(); loop_rate.sleep(); } return 0; }
// Pause Deck (if playing) void do_pause() { if (verbose) printf("-> do_pause()\n"); if (get_state() == MADJACK_STATE_PLAYING ) { set_state( MADJACK_STATE_PAUSED ); } else if (get_state() != MADJACK_STATE_PAUSED) { fprintf(stderr, "Warning: Can't change from %s to state PAUSED.\n", get_state_name(get_state()) ); } }
void hss_print(hss_t* pset) { for (int index = 0; index < pset->array_length; index++) { hsse_t* pe = &pset->array[index]; const char* key_string = (pe == NULL) ? "none" : pe->key == NULL ? "null" : pe->key; printf( "| stt: %-8s | idx: %6d | nidx: %6d | key: %12s |\n", get_state_name(pe->state), index, pe->ideal_index, key_string); } }
static int state_handler(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data) { lo_address src = lo_message_get_source( msg ); lo_server serv = (lo_server)user_data; int result; // Send back reply result = lo_send_from( src, serv, LO_TT_IMMEDIATE, "/deck/state", "s", get_state_name( get_state() ) ); if (result<1) fprintf(stderr, "Error: sending reply failed: %s\n", lo_address_errstr(src)); return 0; }
// Start playing void do_play() { if (verbose) printf("-> do_play()\n"); if (get_state() == MADJACK_STATE_PAUSED || get_state() == MADJACK_STATE_READY) { set_state( MADJACK_STATE_PLAYING ); } else if (get_state() == MADJACK_STATE_LOADING) { play_when_ready = 1; } else if (get_state() != MADJACK_STATE_PLAYING) { fprintf(stderr, "Warning: Can't change from %s to state PLAYING.\n", get_state_name(get_state()) ); } }
// Load Track into Deck void do_load( const char* filepath ) { if (verbose) printf("-> do_load(%s)\n", filepath); // Can only load if Deck is empty if (get_state() != MADJACK_STATE_EMPTY ) { do_eject(); } // Check it really is empty if (get_state() == MADJACK_STATE_EMPTY ) { char* fullpath; set_state( MADJACK_STATE_LOADING ); // Pre-pend the root directory path fullpath = build_fullpath( root_directory, filepath ); if (!quiet) printf("Loading: %s\n", fullpath); // Open the new file input_file->file = fopen( fullpath, "r" ); if (input_file->file==NULL) { error_handler( "%s: %s", strerror( errno ), fullpath); free( fullpath ); return; } // Copy string input_file->filepath = strdup( filepath ); free( fullpath ); // Cue up the new file do_cue(0.0f); } else if (get_state() != MADJACK_STATE_EMPTY) { fprintf(stderr, "Warning: Can't change from %s to state LOADING.\n", get_state_name(get_state()) ); } }
// Eject track from Deck void do_eject() { if (verbose) printf("-> do_eject()\n"); // Stop first if (get_state() == MADJACK_STATE_PLAYING || get_state() == MADJACK_STATE_PAUSED || get_state() == MADJACK_STATE_READY) { do_stop(); } if (get_state() == MADJACK_STATE_STOPPED || get_state() == MADJACK_STATE_ERROR) { // Ensure decoder thread is terminated finish_decoder_thread(); // Close the input file if (input_file->file) { fclose(input_file->file); input_file->file = NULL; free(input_file->filepath); input_file->filepath = NULL; } // Reset positions input_file->position = 0.0; input_file->duration = 0.0; input_file->bitrate = 0; input_file->samplerate = 0; input_file->framesize = 0; // Deck is now empty set_state( MADJACK_STATE_EMPTY ); } else if (get_state() != MADJACK_STATE_EMPTY) { fprintf(stderr, "Warning: Can't change from %s to state EMPTY.\n", get_state_name(get_state()) ); } }
static void catch_task_print_task (CatchTask *task, guint level) { GList *iter; guint i; for (i = 0; i < level; i++) { g_print(" "); } g_print("Task[%p] [%s] (%d)\n", task, get_state_name(task->priv->state), g_list_length(task->priv->deps)); for (iter = task->priv->deps; iter; iter = iter->next) { catch_task_print_task(iter->data, level + 1); } }
// Stop deck (and close down decoder) void do_stop() { if (verbose) printf("-> do_stop()\n"); if (get_state() == MADJACK_STATE_PLAYING || get_state() == MADJACK_STATE_PAUSED || get_state() == MADJACK_STATE_READY || get_state() == MADJACK_STATE_LOADING ) { // Store our new state set_state( MADJACK_STATE_STOPPED ); // Stop decoder thread finish_decoder_thread(); } else if (get_state() != MADJACK_STATE_STOPPED) { fprintf(stderr, "Warning: Can't change from %s to state STOPPED.\n", get_state_name(get_state()) ); } }
STATE_E PlaylistFactory::get_new_state(std::string & tag) { STATE_E new_state = INVALID; if(segment.find(tag) != segment.end()) { new_state = SEGMENT; if(segment_start_key.empty()) { if(segment.find(tag) != segment.end()) { segment_start_key = tag; new_state = NEW_SEGMENT; } } else if(tag.compare(segment_start_key) == 0) new_state = NEW_SEGMENT; } else if(header.find(tag) != header.end()) new_state = HEADER; else if(footer.find(tag) != footer.end()) new_state = FOOTER; PRINT(std::cout << "state is " << get_state_name(new_state) << " for " << tag << std::endl;) return new_state;
void StateMachine :: set_state(const state_t new_state) { *log << "\tChanging state from " << get_state_name(); current_state = new_state; *log << " to " << get_state_name() << std::endl; }
void* BTThreadProc(void* data) { struct sockaddr_l2 addr = { 0 }; int s, status; char buffer[100]; char dest[18] = "00:02:72:16:1A:C1"; /* This is the address of the dongle on my laptop */ char sendbuffer[100] = { 0 }; while(1) { sleep(1); // allocate a socket s = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP); // set the connection parameters (who to connect to) addr.l2_family = AF_BLUETOOTH; addr.l2_psm = htobs(0x1001); str2ba( dest, &addr.l2_bdaddr ); // connect to server status = connect(s, (struct sockaddr *)&addr, sizeof(addr)); // send a message if (status == 0) { memset(sendbuffer, 0, sizeof(sendbuffer)); strcpy(sendbuffer, "mode: "); sprintf(buffer, "%i", GLOBAL_MODE); strcat(sendbuffer, buffer); strcat(sendbuffer, ", "); strcat(sendbuffer, get_state_name(GLOBAL_MODE)); strcat(sendbuffer, "\n"); strcat(sendbuffer, "speed: "); sprintf(buffer, "%i", GLOBAL_SPEED); strcat(sendbuffer, buffer); strcat(sendbuffer, "\n"); strcat(sendbuffer, "distance.right: "); if (GLOBAL_SENSOR_RIGHT < 0xFF) { sprintf(buffer, "%i", GLOBAL_SENSOR_RIGHT); strcat(sendbuffer, buffer); } else strcat(sendbuffer, "Far, far, away..."); strcat(sendbuffer, "\n"); strcat(sendbuffer, "distance.center: "); if (GLOBAL_SENSOR_CENTER < 0xFF) { sprintf(buffer, "%i", GLOBAL_SENSOR_CENTER); strcat(sendbuffer, buffer); } else strcat(sendbuffer, "Far, far, away..."); strcat(sendbuffer, "\n"); strcat(sendbuffer, "distance.right: "); if (GLOBAL_SENSOR_LEFT < 0xFF) { sprintf(buffer, "%i", GLOBAL_SENSOR_LEFT); strcat(sendbuffer, buffer); } else strcat(sendbuffer, "Far, far, away..."); strcat(sendbuffer, "\n"); status = write(s, sendbuffer, sizeof(sendbuffer)); } if( status < 0 ) perror("DERP!"); } }
void print_process(WINDOW* wnd, PROCESS p) { wprintf(wnd, "%-24s %c %-4d %-8s\n", get_state_name(p->state), is_active_proc(p), p->priority, p->name); }
int check_state(int sockfd, char* state){ return !(strcmp((char*)get_state_name(gTcp_Block[sockfd].tcp_current_state), state)); }