APM:Libraries
Util.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <AP_HAL/AP_HAL.h>
6 
7 #include <AP_Param/AP_Param.h>
9 
10 extern "C" {
11  void get_board_serial(uint8_t *serialid);
12 };
13 
14 class F4Light::Util : public AP_HAL::Util {
15 public:
16  Util(): gps_shift(0) {}
17 
18  bool run_debug_shell(AP_HAL::BetterStream *stream) { return false; } // shell in FC? you must be kidding!
19 
20  void set_soft_armed(const bool b) {
21  if(soft_armed != b){
22  soft_armed = b;
24  }
25  }
26 
27  inline bool get_soft_armed() { return soft_armed; }
28 
29  uint64_t get_system_clock_ms() const {
30  int32_t offs= hal_param_helper->_time_offset * 3600 * 1000; // in ms
31 
32  return AP_HAL::millis() + (gps_shift+500)/1000 + offs;
33  }
34 
35  void set_system_clock(uint64_t time_utc_usec){
36  gps_shift = time_utc_usec - Scheduler::_micros64();
37  }
38 
39 
40  uint32_t available_memory(void) override
41  {
42  return 128*1024;
43  }
44 
45  bool get_system_id(char buf[40]) override {
46  uint8_t serialid[12];
47  memset(serialid, 0, sizeof(serialid));
48  get_board_serial(serialid);
49 
50  const char *board_type = BOARD_OWN_NAME;
51 
52  // this format is chosen to match the human_readable_serial()
53  // function in auth.c
54  snprintf(buf, 40, "%s %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X",
55  board_type,
56  (unsigned)serialid[0], (unsigned)serialid[1], (unsigned)serialid[2], (unsigned)serialid[3],
57  (unsigned)serialid[4], (unsigned)serialid[5], (unsigned)serialid[6], (unsigned)serialid[7],
58  (unsigned)serialid[8], (unsigned)serialid[9], (unsigned)serialid[10],(unsigned)serialid[11]);
59  return true;
60  }
61 
62  // create a new semaphore
63  Semaphore *new_semaphore(void) override { return new F4Light::Semaphore; }
64 
65  void *malloc_type(size_t size, Memory_Type mem_type) override;
66  void free_type(void *ptr, size_t size, Memory_Type mem_type) override;
67 
68 private:
69  uint64_t gps_shift; // shift from board time to real time
70 };
71 
72 
void set_soft_armed(const bool b)
Definition: Util.h:20
void get_board_serial(uint8_t *serialid)
Definition: syscalls.c:217
static void arming_state_changed(bool v)
Definition: Scheduler.h:459
void free_type(void *ptr, size_t size, Memory_Type mem_type) override
Definition: Util.cpp:37
A system for managing and storing variables that are of general interest to the system.
bool run_debug_shell(AP_HAL::BetterStream *stream)
Definition: Util.h:18
static uint64_t _micros64()
Definition: Scheduler.cpp:492
bool get_soft_armed()
Definition: Util.h:27
uint32_t millis()
Definition: system.cpp:157
uint32_t available_memory(void) override
Definition: Util.h:40
Semaphore * new_semaphore(void) override
Definition: Util.h:63
uint64_t get_system_clock_ms() const
Definition: Util.h:29
int snprintf(char *str, size_t size, const char *format,...)
Definition: Util.cpp:44
#define BOARD_OWN_NAME
Definition: board.h:151
uint64_t gps_shift
Definition: Util.h:69
void * malloc_type(size_t size, Memory_Type mem_type) override
Definition: Util.cpp:14
bool get_system_id(char buf[40]) override
Definition: Util.h:45
bool soft_armed
Definition: Util.h:125
void set_system_clock(uint64_t time_utc_usec)
Definition: Util.h:35