RocketLogger 2.1.0
rocketloggerd.c File Reference
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <signal.h>
#include <sys/reboot.h>
#include <unistd.h>
#include "gpio.h"
#include "log.h"
#include "rl.h"
#include "rl_lib.h"
+ Include dependency graph for rocketloggerd.c:

Go to the source code of this file.

Macros

#define RL_DAEMON_MIN_INTERVAL   1
 Minimal time interval between two interrupts (in seconds) More...
 
#define RL_CALIBRATION_DURATION_SEC   1
 Duration of calibration run (in seconds) More...
 
#define RL_POWERUP_DELAY_US   5000
 Delay on cape power up (in microseconds) More...
 
#define RL_BUTTON_LONG_PRESS_SEC   3
 Min duration of a long button press (in seconds) More...
 
#define RL_BUTTON_VERY_LONG_PRESS_SEC   6
 Min duration of a very long button press (in seconds) More...
 
#define RL_BUTTON_EXTRA_LONG_PRESS_SEC   10
 Min duration of an extra long button press (in seconds) More...
 

Typedefs

typedef enum system_action system_action_t
 

Enumerations

enum  system_action { SYSTEM_ACTION_NONE , SYSTEM_ACTION_REBOOT , SYSTEM_ACTION_POWEROFF }
 

Functions

int adc_calibrate (uint64_t duration)
 
void button_interrupt_handler (int value)
 
int main (void)
 

Variables

volatile bool daemon_shutdown = false
 Flag to terminate the infinite daemon loop. More...
 
volatile system_action_t system_action = SYSTEM_ACTION_NONE
 System action to perform when exiting the daemon. More...
 
gpio_tgpio_power = NULL
 GPIO handle for power switch. More...
 
gpio_tgpio_button = NULL
 GPIO handle for user button. More...
 

Macro Definition Documentation

◆ RL_BUTTON_EXTRA_LONG_PRESS_SEC

#define RL_BUTTON_EXTRA_LONG_PRESS_SEC   10

Min duration of an extra long button press (in seconds)

Definition at line 63 of file rocketloggerd.c.

◆ RL_BUTTON_LONG_PRESS_SEC

#define RL_BUTTON_LONG_PRESS_SEC   3

Min duration of a long button press (in seconds)

Definition at line 57 of file rocketloggerd.c.

◆ RL_BUTTON_VERY_LONG_PRESS_SEC

#define RL_BUTTON_VERY_LONG_PRESS_SEC   6

Min duration of a very long button press (in seconds)

Definition at line 60 of file rocketloggerd.c.

◆ RL_CALIBRATION_DURATION_SEC

#define RL_CALIBRATION_DURATION_SEC   1

Duration of calibration run (in seconds)

Definition at line 51 of file rocketloggerd.c.

◆ RL_DAEMON_MIN_INTERVAL

#define RL_DAEMON_MIN_INTERVAL   1

Minimal time interval between two interrupts (in seconds)

Copyright (c) 2016-2020, ETH Zurich, Computer Engineering Group 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 48 of file rocketloggerd.c.

◆ RL_POWERUP_DELAY_US

#define RL_POWERUP_DELAY_US   5000

Delay on cape power up (in microseconds)

Definition at line 54 of file rocketloggerd.c.

Typedef Documentation

◆ system_action_t

Typedef for daemon exit system action

Definition at line 77 of file rocketloggerd.c.

Enumeration Type Documentation

◆ system_action

Daemon exit system action definition

Enumerator
SYSTEM_ACTION_NONE 

perform no system action

SYSTEM_ACTION_REBOOT 

reboot the system

SYSTEM_ACTION_POWEROFF 

power off the system

Definition at line 68 of file rocketloggerd.c.

Function Documentation

◆ adc_calibrate()

int adc_calibrate ( uint64_t  duration)

Perform RocketLogger ADC reference voltage calibration.

Run a measurement without data output to file or web for the given duration. Resets the sampling status to default after completion.

Parameters
durationThe duration of the calibration run in seconds
Returns
Measurement run return value, 0 on success, negative on failure with errno set accordingly

Definition at line 105 of file rocketloggerd.c.

References rl_config::background_enable, rl_status::buffer_count, rl_config::file_enable, rl_config::interactive_enable, rl_config_reset(), rl_run(), RL_SAMPLE_RATE_MIN, rl_status_read(), rl_status_write(), rl_status::sample_count, rl_config::sample_limit, rl_config::sample_rate, and rl_config::web_enable.

Referenced by main().

+ Here is the call graph for this function:

◆ button_interrupt_handler()

void button_interrupt_handler ( int  value)

GPIO interrupt handler

Parameters
valueGPIO value after interrupt

Definition at line 139 of file rocketloggerd.c.

References daemon_shutdown, RL_BUTTON_EXTRA_LONG_PRESS_SEC, RL_BUTTON_LONG_PRESS_SEC, RL_BUTTON_VERY_LONG_PRESS_SEC, RL_DAEMON_MIN_INTERVAL, rl_log(), RL_LOG_ERROR, RL_LOG_INFO, rl_status_read(), rl_status::sampling, SYSTEM_ACTION_NONE, SYSTEM_ACTION_POWEROFF, and SYSTEM_ACTION_REBOOT.

Referenced by main().

+ Here is the call graph for this function:

◆ main()

int main ( void  )

Variable Documentation

◆ daemon_shutdown

volatile bool daemon_shutdown = false

Flag to terminate the infinite daemon loop.

Definition at line 84 of file rocketloggerd.c.

Referenced by button_interrupt_handler(), and main().

◆ gpio_button

gpio_t* gpio_button = NULL

GPIO handle for user button.

Definition at line 93 of file rocketloggerd.c.

Referenced by main().

◆ gpio_power

gpio_t* gpio_power = NULL

GPIO handle for power switch.

Definition at line 90 of file rocketloggerd.c.

Referenced by main().

◆ system_action

System action to perform when exiting the daemon.

Definition at line 87 of file rocketloggerd.c.