xmlNodePtr gnc_transaction_dom_tree_create(Transaction *trn) { xmlNodePtr ret; gchar *str = NULL; ret = xmlNewNode(NULL, BAD_CAST "gnc:transaction"); xmlSetProp(ret, BAD_CAST "version", BAD_CAST transaction_version_string); xmlAddChild(ret, guid_to_dom_tree("trn:id", xaccTransGetGUID(trn))); xmlAddChild(ret, commodity_ref_to_dom_tree("trn:currency", xaccTransGetCurrency(trn))); str = g_strdup (xaccTransGetNum(trn)); if (str && (g_strcmp0(str, "") != 0)) { xmlNewTextChild(ret, NULL, BAD_CAST "trn:num", checked_char_cast (str)); } g_free (str); add_timespec(ret, "trn:date-posted", xaccTransRetDatePostedTS(trn), TRUE); add_timespec(ret, "trn:date-entered", xaccTransRetDateEnteredTS(trn), TRUE); str = g_strdup (xaccTransGetDescription(trn)); if (str) { xmlNewTextChild(ret, NULL, BAD_CAST "trn:description", checked_char_cast (str)); } g_free (str); { xmlNodePtr kvpnode = kvp_frame_to_dom_tree("trn:slots", xaccTransGetSlots(trn)); if (kvpnode) { xmlAddChild(ret, kvpnode); } } add_trans_splits(ret, trn); return ret; }
xmlNodePtr gnc_transaction_dom_tree_create (Transaction* trn) { xmlNodePtr ret; gchar* str = NULL; ret = xmlNewNode (NULL, BAD_CAST "gnc:transaction"); xmlSetProp (ret, BAD_CAST "version", BAD_CAST transaction_version_string); xmlAddChild (ret, guid_to_dom_tree ("trn:id", xaccTransGetGUID (trn))); xmlAddChild (ret, commodity_ref_to_dom_tree ("trn:currency", xaccTransGetCurrency (trn))); str = g_strdup (xaccTransGetNum (trn)); if (str && (g_strcmp0 (str, "") != 0)) { xmlNewTextChild (ret, NULL, BAD_CAST "trn:num", checked_char_cast (str)); } g_free (str); add_timespec (ret, "trn:date-posted", xaccTransRetDatePostedTS (trn), TRUE); add_timespec (ret, "trn:date-entered", xaccTransRetDateEnteredTS (trn), TRUE); str = g_strdup (xaccTransGetDescription (trn)); if (str) { xmlNewTextChild (ret, NULL, BAD_CAST "trn:description", checked_char_cast (str)); } g_free (str); /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */ xmlAddChild (ret, qof_instance_slots_to_dom_tree ("trn:slots", QOF_INSTANCE (trn))); add_trans_splits (ret, trn); return ret; }
void wait_for_nonzero( pthread_mutex_t* mutex, pthread_cond_t* cond, volatile int* cond_variable ) { pthread_mutex_lock_block_signal( mutex, SIGNUM ); while ( bRunning && *cond_variable == 0 ) { struct timespec abstime; get_timespec_now(&abstime); add_timespec (&abstime, 0, 10000000); // add 10ms pthread_cond_timedwait( cond, mutex, &abstime); pthread_mutex_unlock_block_signal( mutex, SIGNUM ); // HACK The signal handler is now reenabled, so any queued signals can go pthread_mutex_lock_block_signal( mutex, SIGNUM ); } pthread_mutex_unlock_block_signal( mutex, SIGNUM ); }
/* RT EtherCAT thread */ OSAL_THREAD_FUNC_RT ecatthread(void *ptr) { struct timespec ts, tleft; int ht; int64 cycletime; clock_gettime(CLOCK_MONOTONIC, &ts); ht = (ts.tv_nsec / 1000000) + 1; /* round to nearest ms */ ts.tv_nsec = ht * 1000000; cycletime = *(int*)ptr * 1000; /* cycletime in ns */ toff = 0; dorun = 0; ec_send_processdata(); while(1) { /* calculate next cycle start */ add_timespec(&ts, cycletime + toff); /* wait to cycle start */ clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, &tleft); if (dorun>0) { wkc = ec_receive_processdata(EC_TIMEOUTRET); dorun++; /* if we have some digital output, cycle */ if( digout ) *digout = (uint8) ((dorun / 16) & 0xff); if (ec_slave[0].hasdc) { /* calulate toff to get linux time and DC synced */ ec_sync(ec_DCtime, cycletime, &toff); } ec_send_processdata(); } } }
int main(int argc, char *argv[]){ printf("Preparing...\n"); //Sound preparing wav_get_info(SOUND,&info); sound_dev_prepare(DEVICE, &(info.dev), info.fmt.sample_rate, info.fmt.channels); queue_init(&s_queue, info.dev.buff_size_bytes); //Done //Some usefull info about wav-file #ifdef WAV_INFO printf("File Name: %s\n Chunk ID: %s\n Data Size: %u\n RIFF type: %s\n Chunk ID: %s\n Fmt Data Size: %d\n Comression code: 0x%04x\n Channels: %u\n Sample Rate: %u\n Average Bytes Per Second: %u\n Block Align: %u\n Significant Bytes Per Second: %u\n Chunk ID: %s\n Data Size: %u\n",SOUND,info.riff.id, info.riff.data_size,info.riff.type, info.fmt.id, info.fmt.data_size, info.fmt.compression, info.fmt.channels, info.fmt.sample_rate, info.fmt.av_bps, info.fmt.block_align, info.fmt.sign_bps, info.data.id, info.data.size); #endif //Let's play some music! struct reader_t reader_info; int time; if (argc == 3){ sscanf(argv[1],"%u",&reader_info.start_sound); sscanf(argv[2],"%u",&time); } else { reader_info.start_sound = 0; time = 1; } reader_info.start_frame = (reader_info.start_sound * FPS) / 1000; reader_info.sound_offset = info.data.offset; reader_info.sound_buff_size = info.dev.buff_size_bytes; pthread_create(&r_th, NULL, reader, &(reader_info)); struct timeval time1; struct timezone tz; int fps_timeout = 1000000000 / FPS; memset(&tz, 0, sizeof(tz)); struct timespec timeout; timeout.tv_sec = 0; timeout.tv_nsec = 0; struct timeval tv; tv.tv_sec = 1; tv.tv_usec = 0; while(buffer_ready == FALSE) wait(&tv); struct packet_t *s_buff, *v_buff; sound_buff = (*(queue_pop(&s_queue))).data; s_buff = queue_pop_next(&s_queue); video_buff = (*(queue_pop(&v_queue))).data; v_buff = queue_pop_next(&s_queue); pthread_create(&s_th, NULL, sound_thread, &(info.dev)); pthread_create(&v_th, NULL, video_thread, NULL); printf("Threads started...\n"); while(v_ready == FALSE) wait(&tv); //----------------------* KICKER int frames = 0; int rc = 0; printf("Ready to play...\n"); int no_skip = 0; for(int i = 0; i < ((time * FPS )/ 1000); ++i){ pthread_cond_signal(&s_cond); pthread_cond_signal(&v_cond); v_buff = queue_pop_next(&v_queue); gettimeofday(&time1, &tz); pthread_mutex_lock(&k_mutex); timeout.tv_nsec = fps_timeout*1000; add_timespec(&timeout, &time1); rc = pthread_cond_timedwait(&k_cond, &k_mutex, (const struct timespec *restrict)&timeout); pthread_mutex_unlock(&k_mutex); if (rc == 0){ sound_buff = (*s_buff).data; pthread_cond_signal(&s_cond); queue_skip(&s_queue,1); frames = (s_buff->timestamp / 1000) - (v_buff->timestamp / 1000); printf("DEBUG: S: %ld V: %ld\n",s_buff->timestamp / 1000,v_buff->timestamp / 1000); if (frames > 0){ queue_skip(&v_queue,frames); printf("DEBUG: Skip frames: %d\n",frames); } else if (frames < 0) { printf("DEBUG: No skip: %d\n",-frames); no_skip = -frames; } s_buff = queue_pop_next(&s_queue); } video_buff = (*v_buff).data; if (no_skip > 0){ --no_skip; } else { queue_skip(&v_queue,1); } } pthread_cond_signal(&s_cond); printf("THE END\n"); //---------------------------* KICKER END termination(); return 0; }
/* RT EtherCAT thread */ void ecatthread( void *ptr ) { struct timespec ts; struct timeval tp; int rc; int ht; int i; int pcounter = 0; int64 cycletime; rc = pthread_mutex_lock(&mutex); rc = gettimeofday(&tp, NULL); /* Convert from timeval to timespec */ ts.tv_sec = tp.tv_sec; ht = (tp.tv_usec / 1000) + 1; /* round to nearest ms */ ts.tv_nsec = ht * 1000000; cycletime = *(int*)ptr * 1000; /* cycletime in ns */ toff = 0; dorun = 0; while(1) { /* calculate next cycle start */ add_timespec(&ts, cycletime + toff); /* wait to cycle start */ rc = pthread_cond_timedwait(&cond, &mutex, &ts); if (dorun>0) { rc = gettimeofday(&tp, NULL); ec_send_processdata(); ec_receive_processdata(EC_TIMEOUTRET); cyclecount++; if((in_EBOX->counter != pcounter) && (streampos < (MAXSTREAM - 1))) { // check if we have timing problems in master // if so, overwrite stream data so it shows up clearly in plots. if(in_EBOX->counter > (pcounter + 1)) for(i = 0 ; i < 50 ; i++) { stream1[streampos] = 20000; stream2[streampos++] = -20000; } else for(i = 0 ; i < 50 ; i++) { stream1[streampos] = in_EBOX->stream[i * 2]; stream2[streampos++] = in_EBOX->stream[(i * 2) + 1]; } pcounter = in_EBOX->counter; } /* calulate toff to get linux time and DC synced */ ec_sync(ec_DCtime, cycletime, &toff); } } }
static xmlNodePtr split_to_dom_tree(const gchar *tag, Split *spl) { xmlNodePtr ret; ret = xmlNewNode(NULL, BAD_CAST tag); xmlAddChild(ret, guid_to_dom_tree("split:id", xaccSplitGetGUID(spl))); { char *memo = g_strdup (xaccSplitGetMemo(spl)); if (memo && g_strcmp0(memo, "") != 0) { xmlNewTextChild(ret, NULL, BAD_CAST "split:memo", checked_char_cast (memo)); } g_free (memo); } { char *action = g_strdup (xaccSplitGetAction(spl)); if (action && g_strcmp0(action, "") != 0) { xmlNewTextChild(ret, NULL, BAD_CAST "split:action", checked_char_cast (action)); } g_free (action); } { char tmp[2]; tmp[0] = xaccSplitGetReconcile(spl); tmp[1] = '\0'; xmlNewTextChild(ret, NULL, BAD_CAST "split:reconciled-state", BAD_CAST tmp); } add_timespec(ret, "split:reconcile-date", xaccSplitRetDateReconciledTS(spl), FALSE); add_gnc_num(ret, "split:value", xaccSplitGetValue(spl)); add_gnc_num(ret, "split:quantity", xaccSplitGetAmount(spl)); { Account * account = xaccSplitGetAccount (spl); xmlAddChild (ret, guid_to_dom_tree("split:account", xaccAccountGetGUID (account))); } { GNCLot * lot = xaccSplitGetLot (spl); if (lot) { xmlAddChild (ret, guid_to_dom_tree("split:lot", gnc_lot_get_guid(lot))); } } { xmlNodePtr kvpnode = kvp_frame_to_dom_tree("split:slots", xaccSplitGetSlots(spl)); if (kvpnode) { xmlAddChild(ret, kvpnode); } } return ret; }
static xmlNodePtr split_to_dom_tree (const gchar* tag, Split* spl) { xmlNodePtr ret; ret = xmlNewNode (NULL, BAD_CAST tag); xmlAddChild (ret, guid_to_dom_tree ("split:id", xaccSplitGetGUID (spl))); { char* memo = g_strdup (xaccSplitGetMemo (spl)); if (memo && g_strcmp0 (memo, "") != 0) { xmlNewTextChild (ret, NULL, BAD_CAST "split:memo", checked_char_cast (memo)); } g_free (memo); } { char* action = g_strdup (xaccSplitGetAction (spl)); if (action && g_strcmp0 (action, "") != 0) { xmlNewTextChild (ret, NULL, BAD_CAST "split:action", checked_char_cast (action)); } g_free (action); } { char tmp[2]; tmp[0] = xaccSplitGetReconcile (spl); tmp[1] = '\0'; xmlNewTextChild (ret, NULL, BAD_CAST "split:reconciled-state", BAD_CAST tmp); } add_timespec (ret, "split:reconcile-date", xaccSplitRetDateReconciledTS (spl), FALSE); add_gnc_num (ret, "split:value", xaccSplitGetValue (spl)); add_gnc_num (ret, "split:quantity", xaccSplitGetAmount (spl)); { Account* account = xaccSplitGetAccount (spl); xmlAddChild (ret, guid_to_dom_tree ("split:account", xaccAccountGetGUID (account))); } { GNCLot* lot = xaccSplitGetLot (spl); if (lot) { xmlAddChild (ret, guid_to_dom_tree ("split:lot", gnc_lot_get_guid (lot))); } } /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */ xmlAddChild (ret, qof_instance_slots_to_dom_tree ("split:slots", QOF_INSTANCE (spl))); return ret; }