void elevator_system_drawer::initialize_arrivals() { auto const entry_width = get_entry_width(); auto const person_width = get_person_width(); auto const queue_gap_width = get_queue_gap_width(); double max_distance = 0.0; for(size_t f = 0; f < m_sys.m_num_floors; ++f) { auto const& flr = m_sys.m_transitions.floor_arrivals[f]; for(size_t dir = 0; dir < 2; ++dir) { auto const queuing = get_queue_length(f, (Direction)dir);//m_sys.m_state.floors[f].queues[dir].size(); auto const arrival_count = flr[dir]; if(arrival_count > 0) { auto dist = entry_width - queuing * (person_width + queue_gap_width); max_distance = std::max(max_distance, dist); } } } m_end_step = (size_t)(max_distance / WalkingSpeed); if(max_distance > 0.0) { // Round up ++m_end_step; } }
void elevator_system_drawer::draw_all_queues(Wt::WPainter& painter, Wt::WRectF const& rc) { auto const num_floors = get_num_floors(); auto const floor_height = get_floor_height(SizeFormat::Pixels); auto const q_height = get_queue_height(SizeFormat::Pixels); for(elevator_system::floor_t floor = 0; floor < num_floors; ++floor) { auto rc_floor = floor_rect(floor, rc); for(size_t dir = 0; dir < 2; ++dir) { if( m_stage == AnimationStage::GettingOn && floor == get_current_floor() && dir == m_sys.m_state.direction ) { continue; } auto length = get_queue_length(floor, (Direction)dir); if(length > 0) { auto rc_q_corridor = queue_corridor_rect((Direction)dir, rc_floor); auto rc_q = queue_rect( length, QueueSide::Right, rc_q_corridor ); draw_queue(length, painter, rc_q); } } } }
static void render_queued(SlidingWindow *priv) { int queue_length = get_queue_length(priv); while (queue_length) { blk_report_t *cur_rep = blk_rep_read(priv); render_update_vis(priv, cur_rep); queue_length--; } render_update_stats(priv); wnoutrefresh(priv->vis); doupdate(); }
static void render_queued(WholeSpace *priv) { int queue_length = get_queue_length(priv); while (queue_length) { blk_report_t *cur_rep = blk_rep_read(priv); update_blocks_info(priv, cur_rep); queue_length--; } render_update_stats(priv); render_map(priv); doupdate(); }
static char * format_monitor(struct iwinfo_assoclist_entry *e,bool *isAlive) { static char buf[256]; *isAlive = false; memset (buf,0x00,256); if (NULL == e) { sprintf(buf,"Station|Rssi/Nf/Snr|na|MCS r/t|Mbps r/t |load| online |R rate|T rate"); } else { // unsigned char qlen = 0x000000ff & e->drop_qlen; // unsigned int drop = 0x00fffff & (e->drop_qlen >> 24); unsigned int drop = 0; unsigned char qlen = get_queue_length(); uint32_t delta_tx_packets = e->tx_packets - last_tx_packets; uint32_t delta_tx_failed = (drop + e->tx_failed) - last_tx_failed; int tx_KBps = 0; int rx_KBps = 0; struct timeval current_time; gettimeofday (¤t_time,NULL); time_t diff_in_ms = (current_time.tv_sec - last_count_time.tv_sec) * 1000 + (current_time.tv_usec - last_count_time.tv_usec) / 1000; last_count_time.tv_sec = current_time.tv_sec; last_count_time.tv_usec = current_time.tv_usec; last_tx_packets = e->tx_packets; last_tx_failed = drop + e->tx_failed; if (diff_in_ms > 0) { if (last_rx_bytes < e->rx_bytes) rx_KBps = (e->rx_bytes - last_rx_bytes) / diff_in_ms; if (last_tx_bytes < e->tx_bytes) tx_KBps = (e->tx_bytes - last_tx_bytes) / diff_in_ms; last_rx_bytes = e->rx_bytes; last_tx_bytes = e->tx_bytes; } *isAlive = (e->inactive <= MAX_INACTIVE_MS) ? true : false; sprintf(buf,"%s|% 11s|%s|% 7s|% 9s|%3d%%|%8s|% 6s|% 6s", format_bssid(e->mac), format_snr(e->signal,e->noise), format_timer(e->inactive), format_mcs(&e->rx_rate,&e->tx_rate), format_bps(&e->rx_rate,&e->tx_rate), 100 * qlen / MAX_QUEUE_LEN, format_online_time(e->t_connect), format_throughput_rx(8 * rx_KBps), format_throughput_tx(8 * tx_KBps) ); } return buf; }
void elevator_system_drawer::draw_arrivals(Wt::WPainter& painter, Wt::WRectF const& rc) { auto const num_floors = get_num_floors(); for(elevator_system::floor_t floor = 0; floor < num_floors; ++floor) { auto rc_floor = floor_rect(floor, rc); for(size_t direction = 0; direction < 2; ++direction) { auto num_arrivals = m_sys.m_transitions.floor_arrivals[floor][direction]; if(num_arrivals > 0) { auto rc_q_corridor = queue_corridor_rect((Direction)direction, rc_floor); auto rc_q = queue_rect( num_arrivals, QueueSide::Left, rc_q_corridor ); auto existing_length = get_queue_length(floor, (Direction)direction); auto walked = WalkingSpeed * m_stage_step * m_pix_multiplier; auto max = rc_floor.width(); max -= get_queue_width(existing_length, SizeFormat::Pixels); if(existing_length > 0) { max -= get_queue_gap_width(SizeFormat::Pixels); } walked = std::min(walked, max); rc_q = Wt::WRectF( rc_q_corridor.left() - rc_q.width() + walked, rc_q.top(), rc_q.width(), rc_q.height() ); draw_queue(num_arrivals, painter, rc_q); } } } }
void playqueue_display (int argc, char * * argv) { int qlength = get_queue_length (); audtool_report ("%d queued tracks.", qlength); int total = 0; for (int qpos = 0; qpos < qlength; qpos ++) { int pos = get_queue_entry (qpos); char * title = get_entry_title (pos); int length = get_entry_length (pos) / 1000; total += length; /* adjust width for multi byte characters */ int column = 60; for (const char * p = title; * p; p = g_utf8_next_char (p)) { int stride = g_utf8_next_char (p) - p; if (g_unichar_iswide (g_utf8_get_char (p)) || g_unichar_iswide_cjk (g_utf8_get_char (p))) column += (stride - 2); else column += (stride - 1); } char * fmt = g_strdup_printf ("%%4d | %%4d | %%-%ds | %%d:%%.2d", column); audtool_report (fmt, qpos + 1, pos + 1, title, length / 60, length % 60); g_free (fmt); } audtool_report ("Total length: %d:%.2d", total / 60, total % 60); }
void playqueue_length (int argc, char * * argv) { audtool_report ("%d", get_queue_length ()); }
void ThreadFunc(Params* params) { printf("=========================================================================\n"); printf(" SubThread %ld is watching over %s port \n", GetCurrentThreadId(), params->gszPort); printf("=========================================================================\n"); HANDLE hComm = openPort(params->gszPort); if (hComm == INVALID_HANDLE_VALUE) { printf("failed to open serial port %s \n", params->gszPort); return; } else { printf("serial port %s opened \n", params->gszPort); if (setupPort(hComm)) { // all sensors use the same calibration matrix and offset while(isCalibratorInitialized == false) { if(isCalibratorBeingInitialized == true) continue; isCalibratorBeingInitialized = true; printf("\n************** please rotate your sensor with port %s *************\n", params->gszPort); initCalibrator(hComm); } printf("======================= Now collect test data!! =================== \n"); SqQueue * queue = create_empty_queue(); char rawDataFileName[60]; //The file stores raw data char correctedDataFileName[60]; //The file stores corrected magnetic data printf("======================== THE TEST ====================== \n"); sprintf(rawDataFileName, "C:/Users/xing/Desktop/%s_Raw_Mag_Data.txt",params->gszPort); sprintf(correctedDataFileName, "C:/Users/xing/Desktop/%s_Corrected_Mag_Data.txt",params->gszPort); //the models of the four gestures char *gestureModel[DTW_NUM] = {"./gesture_model/target.txt" ,"./gesture_model/point.txt" ,"./gesture_model/rotate_right.txt" ,"./gesture_model/rotate_left.txt" ,"./gesture_model/slide_over.txt" ,"./activity_model/stand_up.txt" ,"./activity_model/sit_down.txt" ,"./activity_model/walk.txt"}; //the tresholds of four model gestures double threshold[DTW_NUM] = {TARGET_THRESHOLD,POINT_THRESHOLD,ROTATE_RIGHT_THRESHOLD,ROTATE_LEFT_THRESHOLD ,SLIDE_OVER_THRESHOLD,STAND_UP_THRESHOLD,SIT_DOWN_THRESHOLD,WALK_THRESHOLD}; //the time limit of four model gestures double timeLimit[DTW_NUM] = {TARGET_TIMELIMIT,POINT_TIMELIMIT,ROTATE_RIGHT_TIMELIMIT,ROTATE_LEFT_TIMELIMIT ,SLIDE_OVER_TIMELIMIT,STAND_UP_TIMELIMIT,SIT_DOWN_TIMELIMIT,WALK_TIMELIMIT}; //initialize the four models and their GestureRecognitionProcess //the order is : //0->point //1->rotate right //2->rotate left //3->slide over OriginalGesture *og[DTW_NUM]; GRProcess grp[DTW_NUM]; int gt = 0; for(gt = 0; gt < DTW_NUM; gt++) { og[gt] = read_file_to_init_original_gesture(gestureModel[gt]); int m = og[gt]->m; //Pay attention to Free memory !!! double *distanceArray = (double *)malloc(sizeof(double) * (m + 1)); double *distanceArrayLast = (double *)malloc(sizeof(double) * (m + 1)); int *startArray = (int *)malloc(sizeof(int) * (m + 1)); int *startArrayLast = (int *)malloc(sizeof(int) * (m + 1)); long int *timeArray = (long int *)malloc(sizeof(long int) * (m + 1)); long int *timeArrayLast = (long int *)malloc(sizeof(long int) * (m + 1)); double dmin = DBL_MAX; int te = 1; int ts = 1; int k = 0; for(k = 0; k <= m; k++) { distanceArrayLast[k] = DBL_MAX; startArrayLast[k] = 0; timeArrayLast[k] = 0; } grp[gt].distanceArray = distanceArray; grp[gt].distanceArrayLast = distanceArrayLast; grp[gt].dmin = dmin; grp[gt].originalGesture = *(og[gt]); grp[gt].startArray = startArray; grp[gt].startArrayLast = startArrayLast; grp[gt].timeArray = timeArray; grp[gt].timeArrayLast = timeArrayLast; grp[gt].threshold = threshold[gt]; grp[gt].te = te; grp[gt].ts = ts; grp[gt].times = 0; grp[gt].times = 0; grp[gt].type = gt; grp[gt].timeLimit = timeLimit[gt]; } //Before read, flush the buffer. purgePort(hComm); int trueNum = 0; bool hasTarget = false; DataHeadNode *targetHead = create_list_with_head(); PktData pktData; int i; for(i = 0; i < params->magDataNum; i ++) { pktData = blockingReadOnePacket(hComm); if(equals(pktData, ZERO_PKT)) { continue; } //Notice: it will override original raw data if queue is full int position = add_to_queue(queue, pktData); //input the current data into the SPRING if(SPRING(pktData, &grp[0],position, queue) == TARGET_TYPE) { trueNum++; add_to_list_head(targetHead, pktData); } if(trueNum >= 20) { /** compute target using the list of the target data list */ printf("\n!!!!!!!!!!!!!!!!!!!!!!%s target selected!!!!!!!!!!!!!!!!!!\n", params->gszPort); trueNum = 0; clear_list(targetHead); hasTarget = true; } if(hasTarget) { int l = 0; for(l = 1; l <= 4; l++) { SPRING(pktData, &grp[l],position, queue); } } //compare_list_and_delete_queue(queue,startList,4); } int magLen = get_queue_length(queue); printf("Actual mag data length: %d\n", magLen); //This is the same heading in Cali.mat double heading[magLen]; write_queue_to_file(rawDataFileName, queue); calibrateMagData(queue->magXData, queue->magYData, queue->magZData, heading, magLen); write_mag_to_file(correctedDataFileName, queue->magXData, queue->magYData, queue->magZData, heading, magLen); //clear_queue(queue); printf("\nSee %s \nand %s\nfor more detail!\n",rawDataFileName, correctedDataFileName); free_queue(queue); free_list(targetHead); } closePort(hComm); } }