RocketLogger  1.1.6
rl_server.c File Reference
#include <libgen.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/statvfs.h>
#include "rl_lib.h"
#include "rl_util.h"
#include "sem.h"
#include "web.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]
 Buffer sizes for different time scales. More...
 

Macro Definition Documentation

#define ARG_COUNT   4

Number of input arguments required.

Copyright (c) 2016-2019, Swiss Federal Institute of Technology (ETH Zurich) All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition at line 43 of file rl_server.c.

Referenced by main().

#define MAX_STRING_LENGTH   150

Maximum string line length.

Definition at line 45 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 47 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 49 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 83 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 242 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, NUM_SEMS, open_sem(), print_data(), print_status(), rl_log(), rl_read_status(), RL_RUNNING, S1, S10, S100, rl_status::sampling, SAMPLING_OFF, sem_id, SEM_KEY, SEM_TIME_OUT, set_sem(), rl_status::state, status, SUCCESS, t_scale, web_shm::time, wait_sem(), WAIT_SEM, WARNING, and web_open_shm().

+ Here is the call graph for this function:

void print_data ( void  )

Print requested data in JSON format

Definition at line 164 of file rl_server.c.

References web_shm::buffer, 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, wait_sem(), and web_buffer_get().

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 96 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 114 of file rl_server.c.

References MAX_STRING_LENGTH, and MAX_STRING_VALUE.

Referenced by print_data().

Variable Documentation

int buffer_sizes[WEB_RING_BUFFER_COUNT]
Initial value:
#define BUFFER1_SIZE
Size of 1s/div buffer.
Definition: web.h:60
#define BUFFER10_SIZE
Size of 10s/div buffer.
Definition: web.h:62
#define BUFFER100_SIZE
Size of 100s/div buffer.
Definition: web.h:64

Buffer sizes for different time scales.

Definition at line 74 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 66 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 60 of file rl_server.c.

Referenced by main().

uint32_t id

Client request id.

Definition at line 58 of file rl_server.c.

int64_t last_time

Last client time stamp.

Definition at line 64 of file rl_server.c.

Referenced by main(), and print_data().

int8_t num_channels

Number of channels sampled.

Definition at line 68 of file rl_server.c.

Referenced by file_handle_data(), main(), meter_print_buffer(), print_data(), and web_handle_data().

int sem_id

ID of semaphore set.

Definition at line 53 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 62 of file rl_server.c.

Referenced by main(), and print_data().

struct web_shm* web_data

Pointer to shared memory data.

Definition at line 55 of file rl_server.c.

Referenced by pru_sample(), web_create_shm(), web_handle_data(), and web_open_shm().