68 const int incr_nsec = (1E9 / timerInfo->
frequency);
71 struct timespec now = {0};
72 clock_gettime(CLOCK_MONOTONIC, &now);
75 (1000 * now.tv_sec + now.tv_nsec / 1000000));
84 time_t nstamp = time(NULL);
85 if (nstamp != lstamp) {
90 "[Timer:%s] Error pushing message to queue", args->
tag);
98 struct timespec nextIter = now;
99 nextIter.tv_nsec += incr_nsec;
100 if (nextIter.tv_nsec >= 1E9) {
101 int nsec = nextIter.tv_nsec / 1000000000;
102 nextIter.tv_nsec = nextIter.tv_nsec % 1000000000;
103 nextIter.tv_sec += nsec;
105 nextIter.tv_nsec -= (nextIter.tv_nsec % incr_nsec);
107 struct timespec target = {0};
108 clock_gettime(CLOCK_MONOTONIC, &now);
114 nanosleep(&target, NULL);
154 log_error(args->
pstate,
"[Timer:%s] Error pushing channel name to queue",
170 log_error(args->
pstate,
"[Timer:%s] Error pushing channel map to queue",
221 "[Timer:%s] Unable to allocate memory for device parameters", lta->
tag);
247 "[Timer:%s] Invalid frequency requested (%d) - must be positive and non-zero",
257 int sn = strtol(t->
value, NULL, 0);
260 lta->
tag, strerror(errno));
277 "[Timer:%s] Unexpected Source ID number (0x%02x)- this may cause analysis problems",
char * config_qstrdup(const char *c)
Duplicate string, stripping optional leading/trailing quote marks.
config_kv * config_get_key(const config_section *cs, const char *kn)
Find configugration key within specific section, by name.
void signalHandlersBlock(void)
Block signals that we have handlers for.
msg_t * msg_new_string(const uint8_t source, const uint8_t type, const size_t len, const char *str)
Create a new message with a single string embedded.
void msg_destroy(msg_t *msg)
Destroy a message.
msg_t * msg_new_string_array(const uint8_t source, const uint8_t type, const strarray *array)
Create a new message containing an array of strings.
msg_t * msg_new_timestamp(const uint8_t source, const uint8_t type, const uint32_t ts)
Create a timestamp message.
#define SLCHAN_TSTAMP
Source timestamp (milliseconds, arbitrary epoch)
#define SLCHAN_MAP
Channel name map (excludes log channels)
#define SLCHAN_NAME
Name of source device.
#define SLSOURCE_TIMER
Local/Software timers.
void * timer_logging(void *ptargs)
Generate timer message at requested frequency.
timer_params timer_getParams()
Fill out default timer parameters.
void * timer_shutdown(void *ptargs)
No shutdown required - does nothing.
void * timer_setup(void *ptargs)
Check parameters, but no other setup required.
bool timer_parseConfig(log_thread_args_t *lta, config_section *s)
Take a configuration section and parse parameters.
void * timer_channels(void *ptargs)
Generate channel map and push to logging queue.
device_callbacks timer_getCallbacks()
Fill out device callback functions for logging.
atomic_bool shutdownFlag
Trigger clean software shutdown.
bool timespec_subtract(struct timespec *result, struct timespec *x, struct timespec *y)
Difference between timespecs (used for rate keeping)
#define DEFAULT_MARK_FREQUENCY
Default sample/marker frequency.
void log_info(const program_state *s, const int level, const char *format,...)
Output formatted information message at a given level.
void log_warning(const program_state *s, const char *format,...)
Output formatted warning message.
void log_error(const program_state *s, const char *format,...)
Output formatted error message.
bool queue_push(msgqueue *queue, msg_t *msg)
Add a message to the tail of the queue.
void sa_destroy(strarray *sa)
Destroy array and contents.
strarray * sa_new(int entries)
Allocate storage for a new array.
bool sa_create_entry(strarray *array, const int index, const size_t len, const char *src)
Create an string in a given position from a character array and length.
Represent a key=value pair.
char * value
Configuration item value.
Configuration file section.
Device specific function information.
device_fn startup
Called serially at startup, opens devices etc.
Logging thread information.
msgqueue * logQ
Main message queue. Pushed to by threads, consumed by main()
char * tag
Tag/source name for messages etc.
void * dParams
Device/Thread specific data.
program_state * pstate
Current program state, used for logging.
int returnCode
Thread return code (output)
Timer specific parameters.
uint8_t sourceNum
Source ID for messages.
char * sourceName
Name to report for this timer.
int frequency
Aim to sample this many times per second.