Artemis Teensy Flight Software
The software on the Teensy in the Artemis cubesat.
helpers.h
Go to the documentation of this file.
1 
8 #ifndef _HELPERS_H
9 #define _HELPERS_H
10 
12 #define SECONDS 1000
13 
15 #include <Arduino.h>
16 #include <stdint.h>
17 
18 extern unsigned long _heap_start;
19 extern unsigned long _heap_end;
20 extern char *__brkval;
21 
23 namespace Helpers {
25 enum Short_Name : uint8_t {
26  RFM23 = 1,
27  PDU,
28  RPI,
29  MAIN,
30  TEST,
31 };
32 
33 void connect_serial_debug(long baud);
34 void print_hexdump(Short_Name channel, const char *msg, uint8_t *src,
35  uint8_t size);
36 
44 template <typename Arg> void print_args(std::ostream &oss, const Arg &arg) {
45 #ifdef DEBUG_PRINT
46  oss << arg;
47 #endif
48 }
49 
74 template <typename Arg, typename... Args>
75 void print_args(std::ostream &oss, const Arg &arg, const Args &...args) {
76  oss << arg;
77  print_args(oss, args...);
78 }
79 
87 template <typename... Args>
88 void print_debug(Short_Name channel, const Args &...args) {
89 #ifdef DEBUG_PRINT
90  std::ostringstream oss;
91 
92  switch (channel) {
93  case PDU:
94  oss << "[PDU ] ";
95  break;
96  case RFM23:
97  oss << "[RM23] ";
98  break;
99  case RPI:
100  oss << "[R-PI] ";
101  break;
102  case MAIN:
103  oss << "[MAIN] ";
104  break;
105  case TEST:
106  oss << "[TEST] ";
107  break;
108  default:
109  oss << "[????] ";
110  break;
111  }
112 
113  print_args(oss, args...);
114 
115  Serial.println(oss.str().c_str());
116 #endif
117 }
118 
126 template <typename... Args>
127 void print_debug_rapid(Short_Name channel, const Args &...args) {
128 #ifdef DEBUG_PRINT_RAPID
129  print_debug(channel, args...);
130 #endif
131 }
132 } // namespace Helpers
133 
134 #endif // _HELPERS_H
Headers and definitions common to all COSMOS Kernel.
Helper functions and debugging tools.
Definition: helpers.cpp:10
void connect_serial_debug(long baud)
Connects to a computer over USB Serial for debugging.
Definition: helpers.cpp:16
void print_args(std::ostream &oss, const Arg &arg)
Base case of the recursive debug print.
Definition: helpers.h:44
void print_debug_rapid(Short_Name channel, const Args &...args)
Helper function to print debug messages quickly.
Definition: helpers.h:127
void print_hexdump(Short_Name channel, const char *msg, uint8_t *src, uint8_t size)
Helper function to print the hexdump of a region of memory.
Definition: helpers.cpp:32
Short_Name
Enumeration of channels calling helper functions.
Definition: helpers.h:25
void print_debug(Short_Name channel, const Args &...args)
Helper function to print debug messages.
Definition: helpers.h:88