void *force_thread(void *ptr) { FILE* wf = NULL; force_thread_active = 1; // force_card.init(0); wf = fopen("dat.txt", "wt+"); initial_record_data(); while (force_thread_active) { // force_card.getvalue(); // printf("force : %f \t\n", force_card.magnitude); record_data(wf); usleep(100*1000); } printf("force_thread_exit\n"); fclose(wf); }
/* This method gets called back by DDS when one or more data samples * have been received. */ void HelloListener::on_data_available(::DDS::DataReader *reader) { /* Perform a safe type-cast from a generic data reader into a * specific data reader for the type "ThroughputTestDataReader" */ ThroughputTestDataReader * test_reader = ThroughputTestDataReader::narrow(reader); if (!test_reader) { /* In this specific case, this will never fail */ ACE_ERROR ((LM_ERROR, ACE_TEXT ("::DDS::StringDataReader::narrow failed.\n"))); return; } ThroughputTest *instance = new ThroughputTest; /* Loop until there are messages available in the queue */ for(;;) { ::DDS::SampleInfo info; ::DDS::ReturnCode_t retcode = test_reader->take_next_sample(*instance, info); if (retcode == DDS_RETCODE_NO_DATA) { /* No more samples */ break; } else if (retcode != DDS_RETCODE_OK) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to take data from data reader," " error %d.\n"), retcode)); return; } if (info.valid_data) { record_data(*instance); } } }
/* Start listening the buffers sent from uav */ int start_comm(void) { udp_struct udp_uav; int msglen_uav; if(udpserver_init(&udp_uav,UDP_UAV,1)) diep("udp_UAV init"); while (start_listen) { //printf("listen\n"); do { msglen_uav = udpserver_receive(&udp_uav, buf_uav, 512); } while(msglen_uav<=0); //printf("udp uav received\n"); record_data(buf_uav); } udpserver_close(&udp_uav); return 0; }
static void *StartDevSoundThread(void *threadarg) { GstDevsoundSrc *devsoundsrc= GST_DEVSOUND_SRC (threadarg); int buffersize; TUint8* gBuffer; GstBuffer* pushBuffer= NULL; //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "StartDevSoundThread ",NULL); int ret = open_devsound(&(devsoundsrc->handle)); if( KErrNone != ret ) { pthread_mutex_lock(&(create_mutex1)); return_error = ret; pthread_cond_signal(&(create_condition1)); pthread_mutex_unlock(&(create_mutex1)); pthread_exit(NULL); } getsupporteddatatypes(devsoundsrc); // TODO obtain mutex to update variable here??? consumer_thread_state = CONSUMER_THREAD_INITIALIZED; //pre_init_setconf(devsoundsrc); //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After Record Init ",NULL); pthread_mutex_lock(&(create_mutex1)); return_error = ret; pthread_cond_signal(&(create_condition1)); pthread_mutex_unlock(&(create_mutex1)); // Wait until we receive a command from the main thread // TODO obtain mutex to read variable here??? while ( cmd == OPEN ) { pthread_mutex_lock(&create_mutex1); pthread_cond_wait(&create_condition1, &create_mutex1); pthread_mutex_unlock(&create_mutex1); } // This could happen if client creates sink and deletes it // without putting it to play state if ( cmd != CLOSE ) { gst_update_devsound_speech_bitrate(devsoundsrc); ret = initialize_devsound(devsoundsrc); if( KErrNone == ret ) { ret = recordinit(devsoundsrc->handle); if( KErrNone == ret ) initproperties(devsoundsrc); } /// if initialization of devsound failed, return error, /// on return other thread will send CLOSE cmd to exit from thread. if( ret ) { pthread_mutex_lock(&(create_mutex1)); return_error = ret; pthread_cond_signal(&(create_condition1)); pthread_mutex_unlock(&(create_mutex1)); pthread_mutex_lock(&create_mutex1); pthread_cond_wait(&create_condition1, &create_mutex1); pthread_mutex_unlock(&create_mutex1); } } while (TRUE) { switch (cmd) { case PAUSE: pause_devsound(devsoundsrc); break; case RESUME: resume_devsound(devsoundsrc); break; case STOP: stop_devsound(devsoundsrc); break; case RECORDING: { pre_init_setconf(devsoundsrc); // gst_Apply_SpeechEncoder_Update(devsoundsrc); gst_Apply_G711Encoder_Update(devsoundsrc); gst_Apply_G729Encoder_Update(devsoundsrc ); gst_Apply_IlbcEncoder_Update(devsoundsrc ); populateproperties(devsoundsrc); supportedbitrates = devsoundsrc->supportedbitrates; //numofbitrates = devsoundsrc->numofbitrates; speechbitrate = devsoundsrc->speechbitrate; speechvadmode = devsoundsrc->speechvadmode; g711vadmode = devsoundsrc->g711vadmode; g729vadmode = devsoundsrc->g729vadmode; ilbcvadmode = devsoundsrc->ilbcvadmode; buffersize = get_databuffer_size(devsoundsrc->handle); get_databuffer(devsoundsrc->handle, &gBuffer); pushBuffer = gst_buffer_new_and_alloc(buffersize); memcpy(GST_BUFFER_DATA(pushBuffer),gBuffer,buffersize); GST_OBJECT_LOCK(devsoundsrc); g_queue_push_head (dataqueue,pushBuffer); GST_OBJECT_UNLOCK(devsoundsrc); record_data(devsoundsrc->handle); } break; case CLOSE: { //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "Before Close DevSound ",NULL); close_devsound(devsoundsrc); //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After Close DevSound ",NULL); devsoundsrc->handle= NULL; //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After handle NULL ",NULL); pthread_mutex_lock(&(create_mutex1)); pthread_cond_signal(&(create_condition1)); pthread_mutex_unlock(&(create_mutex1)); // TODO obtain mutex here consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED; pthread_exit(NULL); } break; default: // TODO obtain mutex here consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED; pthread_exit(NULL); break; } pthread_mutex_lock(&(create_mutex1)); return_error = call_back_error(devsoundsrc->handle); pthread_cond_signal(&(create_condition1)); pthread_mutex_unlock(&(create_mutex1)); pthread_mutex_lock(&create_mutex1); pthread_cond_wait(&create_condition1, &create_mutex1); pthread_mutex_unlock(&create_mutex1); } }
main(int argc, char *argv[]) { FILE *fp; FILE *op; char buf[256], *p,bname[20]; char date[80]; int mode; int c[3]; int max[3]; unsigned int ave[3]; int now,sec; int i, j,k; char *blk[10] = { "£ß", "£ß", "¨x", "¨y", "¨z", "¨{", "¨|", "¨}", "¨~", "¨€", }; mode=atoi(argv[1]); sprintf(buf,"%s/use_board", BBSHOME); if ((fp = fopen(buf, "r")) == NULL) { printf("cann't open use_board\n"); return 1; } sprintf(buf,"%s/0Announce/bbslist/todayboard%d", BBSHOME, ( mode == 1 ) ? 2 : 1); if ((op = fopen(buf, "w")) == NULL) { printf("Can't Write file\n"); return 1; } fillboard(); now=time(0); getdatestring(now); sprintf(date,"%14.14s",datestring); while (fgets(buf, 256, fp)) { if(strlen(buf)<57) continue; if(strstr(buf,date)!=buf) continue; if ( !strncmp(buf+23, "USE", 3)) { p=strstr(buf,"USE"); p+=4; p=strtok(p," "); strcpy(bname,p); if ( p = (char *)strstr(buf+48, "Stay: ")) { sec=atoi( p + 6); } else sec=0; record_data(bname,sec); } } fclose(fp); qsort(st, numboards, sizeof( st[0] ), brd_cmp); ave[0]=0; ave[1]=0; ave[2]=0; max[1]=0; max[0]=0; max[2]=0; for(i=0;i<numboards;i++) { ave[0]+=st[i].times; ave[1]+=st[i].sum; ave[2]+=st[i].times==0?0:st[i].sum/st[i].times; if(max[0]<st[i].times) { max[0]=st[i].times; } if(max[1]<st[i].sum) { max[1]=st[i].sum; } if(max[2]<(st[i].times==0?0:st[i].sum/st[i].times)) { max[2]=(st[i].times==0?0:st[i].sum/st[i].times); } } c[0]=max[0]/30+1; c[1]=max[1]/30+1; c[2]=max[2]/30+1; numboards++; st[numboards-1].times=ave[0]/numboards; st[numboards-1].sum=ave[1]/numboards; strcpy(st[numboards-1].boardname,"Average"); strcpy(st[numboards-1].expname,"×Üƽ¾ù"); if(mode==1) { fprintf(op,"[1;37mÃû´Î %-21.21s%-24.24s %5s %8s %10s[m\n","ÌÖÂÛÇøÃû³Æ","ÖÐÎÄÐðÊö","ÈË´Î","ÀÛ»ýʱ¼ä","ƽ¾ùʱ¼ä"); }else { fprintf(op," [1;37m1 [m[34m%2s[1;37m= %d (×ÜÈË´Î) [1;37m1 [m[32m%2s[1;37m= %s (ÀÛ»ý×ÜʱÊý) [1;37m1 [m[31m%2s[1;37m= %d Ãë(ƽ¾ùʱÊý)\n\n", blk[9],c[0],blk[9],timetostr(c[1]),blk[9],c[2]); } for(i=0;i<numboards;i++) { if(!strcmp(st[i].boardname,"Others")) printf("ok"); if(mode==1) fprintf(op,"[1m%4d[m %-21.21s%-24.24s %5d %-.8s %10d\n",i+1,st[i].boardname,st[i].expname,st[i].times,timetostr(st[i].sum),st[i].times==0?0:st[i].sum/st[i].times); else { fprintf(op," [1;37mµÚ[31m%3d [37mÃû ÌÖÂÛÇøÃû³Æ£º[31m%s [35m%s[m\n",i+1,st[i].boardname,st[i].expname); fprintf(op,"[1;37m ©°¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª\n"); fprintf(op,"[1;37mÈ˴Ω¦[m[34m"); for(j=0;j<st[i].times/c[0];j++) { fprintf(op,"%2s",blk[9]); } fprintf(op,"%2s [1;37m%d[m\n",blk[(st[i].times%c[0])*10/c[0]],st[i].times); fprintf(op,"[1;37mʱ¼ä©¦[m[32m"); for(j=0;j<st[i].sum/c[1];j++) { fprintf(op,"%2s",blk[9]); } fprintf(op,"%2s [1;37m%s[m\n",blk[(st[i].sum%c[1])*10/c[1]],timetostr(st[i].sum)); j=st[i].times==0?0:st[i].sum/st[i].times; fprintf(op,"[1;37mƽ¾ù©¦[m[31m"); for(k=0;k<j/c[2];k++) { fprintf(op,"%2s",blk[9]); } fprintf(op,"%2s [1;37m%s[m\n",blk[(j%c[2])*10/c[2]],timetostr(j)); fprintf(op,"[1;37m ©¸¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª[m\n\n"); } if(!strcmp(st[i].boardname,"Others")) printf("ok"); } fclose(op); }
int fetch_monitored_data() { int error = 0; int data_pos = 0; lock_holder(worldlock, &world.lock); lock_take(worldlock); if (world.paused == 1) { usleep(1000); goto cleanup; } if (world.config == NULL) { goto cleanup; } lock_release(worldlock); usleep(1000); // wait a sec btween PSUs to not overload RT scheduling // threshold while(world.stored_data[data_pos] != NULL && data_pos < MAX_ACTIVE_ADDRS) { uint8_t addr = world.stored_data[data_pos]->addr; //log("readpsu %02x\n", addr); for(int r = 0; r < world.config->num_intervals; r++) { register_range_data* rd = &world.stored_data[data_pos]->range_data[r]; monitor_interval* i = rd->i; uint16_t regs[i->len]; int err = read_registers(&world.rs485, world.modbus_timeout, addr, i->begin, i->len, regs); if (err) { log("Error %d reading %02x registers at %02x from %02x\n", err, i->len, i->begin, addr); continue; } struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); uint32_t timestamp = ts.tv_sec; if (rd->i->flags & MONITOR_FLAG_ONLY_CHANGES) { int pitch = sizeof(timestamp) + (sizeof(uint16_t) * i->len); int lastpos = rd->mem_pos - pitch; if (lastpos < 0) { lastpos = (pitch * rd->i->keep) - pitch; } if (!memcmp(rd->mem_begin + lastpos + sizeof(timestamp), regs, sizeof(uint16_t) * i->len) && memcmp(rd->mem_begin, "\x00\x00\x00\x00", 4)) { continue; } if (world.status_log) { time_t rawt; struct tm* ti; time(&rawt); ti = localtime(&rawt); char timestr[80]; strftime(timestr, sizeof(timestr), "%b %e %T", ti); fprintf(world.status_log, "%s: Change to status register %02x on address %02x. New value: %02x\n", timestr, i->begin, addr, regs[0]); fflush(world.status_log); } } lock_take(worldlock); record_data(rd, timestamp, regs); lock_release(worldlock); } data_pos++; } cleanup: lock_release(worldlock); return error; }
void main(void) { init_system(); volatile enum states state; state = IDLE; volatile enum button_states button_state; button_state = NO_PUSH; __enable_interrupt(); while(1) { /* Check push button */ if (button_flag == 1) { button_flag = 0; // Check push button unsigned int push_cnt = 0; button_state = NO_PUSH; __delay_cycles(200000); // Wait 25 msec to debounce __delay_cycles(200000); // Wait 25 msec to debounce while (!(P4IN & BIT0)) { // Button pushed __delay_cycles(8000); // Wait 1 msec push_cnt++; if (push_cnt > TIME_SHORT_PUSH) { // Push button was pushed a short time button_state = SHORT_PUSH; LED1_on(); } if (push_cnt > TIME_LONG_PUSH) { // Push button was pushed a long time button_state = LONG_PUSH; LED2_on(); } } LED1_off(); LED2_off(); __delay_cycles(400000); // Wait 50 msec to debounce __delay_cycles(400000); // Wait 50 msec to debounce } /* Check states */ switch (state) { case IDLE: // toggle_led(LED1_PIN, TIME_3SEC); switch (button_state) { case LONG_PUSH: state = TRANSMIT; wdt_disable(); LED1_off(); toggle_led(LED2_PIN, TIME_05SEC); transmit_data(); break; case SHORT_PUSH: state = RECORD; wdt_disable(); LED2_off(); toggle_led(LED1_PIN, TIME_1SEC); record_data(); break; default: break; } break; case RECORD: switch (button_state) { case LONG_PUSH: // Delete data delete_data(); state = IDLE; break; case SHORT_PUSH: // Stop recording // Recording stop from inside recorde() state = IDLE; break; default: break; } // state = IDLE; break; case TRANSMIT: switch (button_state) { case LONG_PUSH: break; case SHORT_PUSH: break; default: break; } state = IDLE; break; default: break; } //button_state = NO_PUSH; PAIE |= BIT0; // Enable interrupt for push button if (state == IDLE) { toggle_led(LED1_PIN, TIME_3SEC); wdt_enable(); // Activate auto-deep-sleep-watchdog LPM3; _nop(); } } }