mirror of
https://github.com/nasa/trick.git
synced 2025-06-23 17:17:34 +00:00
SIM_fibonacci_time demonstrates how to schedule an automatic job. #1235
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
/*************************************************************************
|
||||
PURPOSE: (Example of "automatic" job, i.e., a self scheduling job.)
|
||||
LIBRARY DEPENDENCIES:
|
||||
((fibonacci_time/src/Fibonacci_time.o))
|
||||
**************************************************************************/
|
||||
#ifndef _fibonacci_time_hh_
|
||||
#define _fibonacci_time_hh_
|
||||
|
||||
class Fibonacci_time {
|
||||
|
||||
public:
|
||||
int N;
|
||||
int tics_per_second;
|
||||
|
||||
int default_data();
|
||||
int state_init();
|
||||
int scheduled_job_1();
|
||||
int automatic_job_1();
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -0,0 +1,59 @@
|
||||
/********************************* TRICK HEADER *******************************
|
||||
PURPOSE: ( Example of an "automatic" (self-scheduling) job. )
|
||||
LIBRARY DEPENDENCY:
|
||||
((Fibonacci_time.o))
|
||||
*******************************************************************************/
|
||||
#include "../include/Fibonacci_time.hh"
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "trick/exec_proto.hh"
|
||||
#include "trick/exec_proto.h"
|
||||
|
||||
const char * ISO_6429_Restore_Default = "\x1b[00m";
|
||||
const char * ISO_6429_Red_Foreground = "\x1b[31m";
|
||||
const char * ISO_6429_Green_Foreground = "\x1b[32m";
|
||||
|
||||
int Fibonacci(int n) {
|
||||
if (n<=1) {
|
||||
return n;
|
||||
} else {
|
||||
return Fibonacci(n-1) + Fibonacci(n-2) ;
|
||||
}
|
||||
}
|
||||
|
||||
int Fibonacci_time::default_data() {
|
||||
N = 1;
|
||||
tics_per_second = exec_get_time_tic_value();
|
||||
return (0);
|
||||
}
|
||||
|
||||
int Fibonacci_time::state_init() {
|
||||
return (0);
|
||||
}
|
||||
|
||||
int Fibonacci_time::scheduled_job_1() {
|
||||
|
||||
double time_in_seconds = (double)exec_get_time_tics() / tics_per_second;
|
||||
std::cout << ISO_6429_Green_Foreground
|
||||
<< "Scheduled Job Time = " << time_in_seconds
|
||||
<< ISO_6429_Restore_Default << std::endl;
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
int Fibonacci_time::automatic_job_1() {
|
||||
|
||||
double time_in_seconds = (double)exec_get_time_tics() / tics_per_second;
|
||||
std::cout << ISO_6429_Red_Foreground
|
||||
<< "Automatic Job Time = " << time_in_seconds
|
||||
<< ISO_6429_Restore_Default << std::endl;
|
||||
|
||||
N++;
|
||||
double next_time = Fibonacci(N);
|
||||
|
||||
Trick::JobData * thisJob = exec_get_curr_job() ;
|
||||
thisJob->set_next_call_time(next_time * tics_per_second);
|
||||
|
||||
return(0);
|
||||
}
|
Reference in New Issue
Block a user