RocketLogger  1.0
rl_server.c File Reference
#include <sys/statvfs.h>
#include <stdio.h>
#include <stdint.h>
#include <libgen.h>
#include "rl_lib.h"
#include "rl_util.h"
+ Include dependency graph for rl_server.c:

Go to the source code of this file.

Macros

#define ARG_COUNT   4
 Number of input arguments required. More...
 
#define MAX_STRING_LENGTH   150
 Maximum string line length. More...
 
#define MAX_STRING_VALUE   20
 Maximum string value length. More...
 
#define TIME_MARGIN   10
 Time margin for buffer number (in ms) More...
 

Functions

int64_t get_free_space (char *path)
 
void print_json_32 (int32_t data[], int length)
 
void print_json_64 (int64_t data[], int length)
 
void print_status (void)
 
void print_data (void)
 
int main (int argc, char *argv[])
 

Variables

int sem_id
 ID of semaphore set. More...
 
struct web_shmweb_data
 Pointer to shared memory data. More...
 
uint32_t id
 Client request id. More...
 
uint8_t get_data
 1: data requested, 0: no data requested More...
 
uint32_t t_scale
 Requested time scale. More...
 
int64_t last_time
 Last client time stamp. More...
 
int64_t curr_time
 Time stamp of last buffer stored to shared memory. More...
 
int8_t num_channels
 Number of channels sampled. More...
 
struct rl_status status
 Current status of RocketLogger. More...
 
int buffer_sizes [WEB_RING_BUFFER_COUNT] = {BUFFER1_SIZE, BUFFER10_SIZE, BUFFER100_SIZE}
 Buffer sizes for different time scales. More...
 

Macro Definition Documentation

#define ARG_COUNT   4

Number of input arguments required.

Copyright (c) 2016-2017, ETH Zurich, Computer Engineering Group

Definition at line 14 of file rl_server.c.

Referenced by main().

#define MAX_STRING_LENGTH   150

Maximum string line length.

Definition at line 16 of file rl_server.c.

Referenced by print_json_32(), and print_json_64().

#define MAX_STRING_VALUE   20

Maximum string value length.

Definition at line 18 of file rl_server.c.

Referenced by print_json_32(), and print_json_64().

#define TIME_MARGIN   10

Time margin for buffer number (in ms)

Definition at line 20 of file rl_server.c.

Referenced by print_data().

Function Documentation

int64_t get_free_space ( char *  path)

Get free disk space in a directory

Parameters
pathPath to selected directory
Returns
Free disk space in bytes

Definition at line 54 of file rl_server.c.

Referenced by print_status().

int main ( int  argc,
char *  argv[] 
)

RocketLogger server program. Returns status and current sampling data (if available) when running and default configuration otherwise

Parameters
argcNumber of input arguments
argvInput argument string, consists of:
  • Request ID (can be used for client synchronisation)
  • Data requested (1 for yes, 0 for no)
  • Requested time scale (0: 100 samples/s, 1: 10 samples/s, 2: 1 sample/s)
  • Time stamp in UNIX time (UTC) of most recent data available at web client
Returns
standard Linux return codes

Definition at line 212 of file rl_server.c.

References ARG_COUNT, rl_status::conf, curr_time, DATA_SEM, rl_conf::enable_web_server, ERROR, FAILURE, get_data, last_time, num_channels, web_shm::num_channels, open_sem(), open_web_shm(), print_data(), print_status(), rl_log(), rl_read_status(), RL_RUNNING, S1, S10, S100, rl_status::sampling, SAMPLING_OFF, sem_id, SEM_TIME_OUT, set_sem(), rl_status::state, status, SUCCESS, t_scale, web_shm::time, wait_sem(), WAIT_SEM, and WARNING.

+ Here is the call graph for this function:

void print_data ( void  )

Print requested data in JSON format

Definition at line 137 of file rl_server.c.

References web_shm::buffer, buffer_get(), buffer_sizes, curr_time, DATA_SEM, ringbuffer::element_size, ERROR, ringbuffer::filled, last_time, num_channels, print_json_64(), print_status(), rl_log(), sem_id, SEM_TIME_OUT, set_sem(), SUCCESS, t_scale, TIME_MARGIN, and wait_sem().

Referenced by main().

+ Here is the call graph for this function:

void print_json_32 ( int32_t  data[],
int  length 
)

Print a 32-bit integer array in JSON format

Parameters
dataData array to print
lengthLength of array

Definition at line 68 of file rl_server.c.

References MAX_STRING_LENGTH, and MAX_STRING_VALUE.

Referenced by print_status().

void print_json_64 ( int64_t  data[],
int  length 
)

Print a 64-bit integer array in JSON format

Parameters
dataData array to print
lengthLength of array

Definition at line 86 of file rl_server.c.

References MAX_STRING_LENGTH, and MAX_STRING_VALUE.

Referenced by print_data().

Variable Documentation

Buffer sizes for different time scales.

Definition at line 45 of file rl_server.c.

Referenced by print_data(), and pru_sample().

int64_t curr_time

Time stamp of last buffer stored to shared memory.

Definition at line 37 of file rl_server.c.

Referenced by main(), and print_data().

uint8_t get_data

1: data requested, 0: no data requested

Definition at line 31 of file rl_server.c.

Referenced by main().

uint32_t id

Client request id.

Definition at line 29 of file rl_server.c.

int64_t last_time

Last client time stamp.

Definition at line 35 of file rl_server.c.

Referenced by main(), and print_data().

int8_t num_channels

Number of channels sampled.

Definition at line 39 of file rl_server.c.

Referenced by handle_data_buffer(), main(), meter_print_buffer(), and print_data().

int sem_id

ID of semaphore set.

Definition at line 24 of file rl_server.c.

Referenced by create_sem(), main(), open_sem(), print_data(), and pru_sample().

struct rl_status status
uint32_t t_scale

Requested time scale.

Definition at line 33 of file rl_server.c.

Referenced by main(), and print_data().

struct web_shm* web_data

Pointer to shared memory data.

Definition at line 26 of file rl_server.c.

Referenced by create_web_shm(), handle_data_buffer(), open_web_shm(), and pru_sample().