コード例 #1
0
ファイル: DataRecordGroup.cpp プロジェクト: carylogan/Trick
int Trick::DataRecordGroup::data_record(double in_time) {

    unsigned int jj ;
    unsigned int buffer_offset ;
    Trick::DataRecordBuffer * drb ;
    bool change_detected = false ;

    //TODO: does not handle bitfields correctly!

    if ( record == true ) {
        if ( freq != DR_Always ) {
            for (jj = 0; jj < change_buffer.size() ; jj++) {
                drb = change_buffer[jj] ;
                if ( memcmp( drb->buffer , drb->ref->address , drb->ref->attr->size) ) {
                    change_detected = true ;
                    memcpy( drb->buffer , drb->ref->address , drb->ref->attr->size) ;
                }
            }

        }

        if ( freq == DR_Always || change_detected == true ) {

            // If this is not the ring buffer and
            // we are going to have trouble fitting 2 data sets then write the data now.
            if ( buffer_type != DR_Ring_Buffer ) {
                if ( buffer_num - writer_num >= (max_num - 2) ) {
                    write_data(true) ;
                }
            }

            curr_time = in_time ;

            if ( freq == DR_Changes_Step ) {
                buffer_offset = buffer_num % max_num ;
                *((double *)(rec_buffer[0]->last_value)) = in_time ;
                for (jj = 0; jj < rec_buffer.size() ; jj++) {
                    drb = rec_buffer[jj] ;
                    memcpy( drb->buffer + (buffer_offset * drb->ref->attr->size) , drb->last_value , drb->ref->attr->size ) ;
                }
                buffer_num++ ;
            }

            buffer_offset = buffer_num % max_num ;
            for (jj = 0; jj < rec_buffer.size() ; jj++) {
                drb = rec_buffer[jj] ;
                if ( drb->ref->pointer_present == 1 ) {
                    drb->ref->address = follow_address_path(drb->ref) ;
                }
                memcpy( drb->buffer + (buffer_offset * drb->ref->attr->size) , drb->ref->address , drb->ref->attr->size ) ;
            }
            buffer_num++ ;
        }
    }

    return(0) ;

}
コード例 #2
0
ファイル: RtiEvent.cpp プロジェクト: Arafatk/trick
void Trick::RtiEventBase::check_address() {
    if ( ref->pointer_present ) {
        ref->address = follow_address_path(ref) ;
    }
}
コード例 #3
0
int Trick::VariableServerThread::copy_sim_data() {

    unsigned int ii ;
    VariableReference * curr_var ;

    if ( vars.size() == 0 ) {
        return 0 ;
    }

    if ( pthread_mutex_trylock(&copy_mutex) == 0 ) { 

        // Get the simulation time we start this copy
        time = (double)exec_get_time_tics() / exec_get_time_tic_value() ;

        for ( ii = 0 ; ii < vars.size() ; ii++ ) {
            curr_var = vars[ii] ;

            // if this variable is unresolved, try to resolve it
            if ( retry_bad_ref ) {
                if (curr_var->ref->address == &bad_ref_int) {
                    REF2 *new_ref = ref_attributes(const_cast<char*>(curr_var->ref->reference));
                    if (new_ref != NULL) {
                        curr_var->ref = new_ref;
                    }
                }
            }

            // if there's a pointer somewhere in the address path, follow it in case pointer changed
            if ( curr_var->ref->pointer_present == 1 ) {
                curr_var->address = follow_address_path(curr_var->ref) ;
                if ( curr_var->address == NULL ) {
                    std::string save_name(curr_var->ref->reference) ;
                    if ( curr_var->ref->attr) {
                        free(curr_var->ref->attr) ;
                    }
                    free(curr_var->ref) ;
                    curr_var->ref = make_error_ref(save_name) ;
                    curr_var->address = curr_var->ref->address ;
                } else {
                    curr_var->ref->address = curr_var->address ;
                }
            }

            // if this variable is a string we need to get the raw character string out of it.
            if (( curr_var->string_type == TRICK_STRING ) && !curr_var->need_deref) {
                std::string * str_ptr = (std::string *)curr_var->ref->address ;
                curr_var->address = (void *)(str_ptr->c_str()) ;
            }

            // if this variable itself is a pointer, dereference it
            if ( curr_var->need_deref) {
                curr_var->address = *(void**)curr_var->ref->address ;
            }

            // handle c++ string and char*
            if ( curr_var->string_type == TRICK_STRING ) {
                if (curr_var->address == NULL) {
                    curr_var->size = 0 ;
                } else {
                    curr_var->size = strlen((char*)curr_var->address) + 1 ;
                }
            }
            // handle c++ wstring and wchar_t*
            if ( curr_var->string_type == TRICK_WSTRING ) {
                if (curr_var->address == NULL) {
                    curr_var->size = 0 ;
                } else {
                    curr_var->size = wcslen((wchar_t *)curr_var->address) * sizeof(wchar_t);
                }
            }
            memcpy( curr_var->buffer_in , curr_var->address , curr_var->size ) ;
        }

        retry_bad_ref = false ;

        // Indicate that sim data has been written and is now ready in the buffer_in's of the vars variable list.
        var_data_staged = true;
        packets_copied++ ;

        pthread_mutex_unlock(&copy_mutex) ;
    }


    return (0) ;

}
コード例 #4
0
ファイル: IPPythonEvent.cpp プロジェクト: lonnell/trick
bool Trick::IPPythonEvent::process_user_event( long long curr_time ) {

    int ii ;
    int return_val ;
    bool it_fired, it_ran;

    fired = false ;
    ran = false ;
    /** @li No need to evaluate any conditions if in manual mode. */
    if (! manual) {
        hold = false ;
        /** @li Loop thru all conditions. */
        for (ii=0; ii<condition_count; ii++) {
            /** @li Skip condition if it's been disabled. */
            if (! condition_list[ii]->enabled ) {
                condition_list[ii]->fired = false ;
                continue ;
            }
            /** @li No need to evaluate condition if previously fired and hold is on. */
            if (condition_list[ii]->hold && condition_list[ii]->fired) {
                ;
            } else {
                /** @li Evaluate the condition and set its fired state. */
                condition_list[ii]->fired = false ;
                return_val = 0 ;
                if (condition_list[ii]->ref != NULL) {
                // if it's a variable, get it as a boolean
                    if ( condition_list[ii]->ref->pointer_present ) {
                        condition_list[ii]->ref->address = follow_address_path(condition_list[ii]->ref) ;
                    }
                    if ( condition_list[ii]->ref->address != NULL ) {
                        return_val = *(bool *)condition_list[ii]->ref->address ;
                    }
                } else if (condition_list[ii]->job != NULL) {
                // if it's a job, get its return value
                    bool save_disabled_state = condition_list[ii]->job->disabled;
                    condition_list[ii]->job->disabled = false;
                    return_val = condition_list[ii]->job->call();
                    condition_list[ii]->job->disabled = save_disabled_state;
                } else {
                // otherwise use python to evaluate string
                    std::string full_in_string ;
                    ip->parse_condition(condition_list[ii]->str, return_val) ;
                }
                if (return_val) {
                //TODO: write to log/send_hs that trigger fired
                    condition_list[ii]->fired = true ;
                    condition_list[ii]->fired_count++ ;
                    condition_list[ii]->fired_time = curr_time ;
                }
            } // end evaluate condition
            /** @li If cond_all is true, only set event fired/hold after all enabled conditions evaluated. */
            if (ii==0) {
                fired = condition_list[ii]->fired ;
                hold  = condition_list[ii]->hold ;
            }  else {
                if (cond_all) {
                    fired &= condition_list[ii]->fired ;
                    hold  &= condition_list[ii]->hold ;
                } else {
                    fired |= condition_list[ii]->fired ;
                    hold  |= condition_list[ii]->hold ;
                }
            }
        } //end condition loop
    }
    it_fired = manual_fired || fired ;
    /** @li Set the event's fired state...cond_all: if all conditions fired , otherwise if any condition fired. */
    if (it_fired) {
        fired_count++ ;
        fired_time = curr_time ;
        if (info_msg) {
            message_publish( MSG_INFO , "%12.6f Event %s fired.\n" , exec_get_sim_time() , name.c_str()) ;
        }
        if (!manual_fired) {
            active = false ;
        }
    }

    /** @li If the user specified any actions, run them here if a condition fired or manually fired. */
    it_ran = false ;
    if (it_fired && (action_count > 0)) {
        /** @li Loop thru all actions. */
        for (ii=0; ii<action_count; ii++) {
            /** @li No need to run action if it's been disabled. */
            if (! action_list[ii]->enabled ) {
                action_list[ii]->ran = false ;
                continue ;
            }
            /** @li Run the action and set its ran state. */
            if (action_list[ii]->job != NULL) {
            // if it's a job, do what the action type tells you
                switch (action_list[ii]->act_type) {
                    case 0 : // python, should not get here
                        break;
                    case 1 : // On
                        action_list[ii]->job->disabled = false;
                        break;
                    case 2 : // Off
                        action_list[ii]->job->disabled = true;
                        break;
                    case 3 : // Call
                        bool save_disabled_state = action_list[ii]->job->disabled;
                        action_list[ii]->job->disabled = false;
                        action_list[ii]->job->call();
                        action_list[ii]->job->disabled = save_disabled_state;
                        break;
                }
            } else {
            // otherwise use python to evaluate string
                ip->parse(action_list[ii]->str) ;
            }
            it_ran = true ;
            action_list[ii]->ran = true ;
            action_list[ii]->ran_count++ ;
            action_list[ii]->ran_time = curr_time ;
            ran = true ;
        }
        /** @li Leave event fired state on if hold is on. */
        manual_fired &= hold ;
        fired &= hold ;
    }
    /** @li Set the event's ran state if any actions were run. */
    if (it_ran) {
        ran_count++ ;
        ran_time = curr_time ;
    }

    /** @li Return true if the event fired. */
    return(it_fired) ;
}