[telemetry] store periodic telemetry msg names as const to save ram

This commit is contained in:
Felix Ruess
2015-03-27 23:14:54 +01:00
parent 01534f24ab
commit 64128c6bda
4 changed files with 19 additions and 20 deletions
+7 -6
View File
@@ -30,10 +30,11 @@
#include "subsystems/datalink/telemetry_common.h" #include "subsystems/datalink/telemetry_common.h"
#include "generated/periodic_telemetry.h" #include "generated/periodic_telemetry.h"
/** Implement global structures from generated header /* Implement global structures from generated header
*/ */
struct telemetry_msg telemetry_msgs[TELEMETRY_NB_MSG] = TELEMETRY_STRUCT; telemetry_msg telemetry_msgs[TELEMETRY_NB_MSG] = TELEMETRY_MSG_NAMES;
struct periodic_telemetry pprz_telemetry = { TELEMETRY_NB_MSG, telemetry_msgs }; telemetry_cb telemetry_cbs[TELEMETRY_NB_MSG];
struct periodic_telemetry pprz_telemetry = { TELEMETRY_NB_MSG, telemetry_msgs, telemetry_cbs };
/** Register a telemetry callback function. /** Register a telemetry callback function.
@@ -49,10 +50,10 @@ bool_t register_periodic_telemetry(struct periodic_telemetry *_pt, const char *_
// look for message name // look for message name
uint8_t i; uint8_t i;
for (i = 0; i < _pt->nb; i++) { for (i = 0; i < _pt->nb; i++) {
if (str_equal(_pt->msgs[i].msg, _msg)) { if (str_equal(_pt->msgs[i], _msg)) {
// register callback if not already done // register callback if not already done
if (_pt->msgs[i].cb == NULL) { if (_pt->cbs[i] == NULL) {
_pt->msgs[i].cb = _cb; _pt->cbs[i] = _cb;
return TRUE; return TRUE;
} else { return FALSE; } } else { return FALSE; }
} }
+2 -3
View File
@@ -54,12 +54,11 @@
#include "subsystems/datalink/downlink.h" #include "subsystems/datalink/downlink.h"
#include "generated/periodic_telemetry.h" #include "generated/periodic_telemetry.h"
/** Global telemetry structures /** Global telemetry structure
* *
* Contains the list of message and register callbacks. * Contains the list of message names and registered callbacks.
* Filled with generated structure from periodic_telemetry.h * Filled with generated structure from periodic_telemetry.h
*/ */
extern struct telemetry_msg telemetry_msgs[TELEMETRY_NB_MSG];
extern struct periodic_telemetry pprz_telemetry; extern struct periodic_telemetry pprz_telemetry;
/** Set default periodic telemetry /** Set default periodic telemetry
@@ -38,20 +38,19 @@
*/ */
typedef void (*telemetry_cb)(struct transport_tx *trans, struct link_device *dev); typedef void (*telemetry_cb)(struct transport_tx *trans, struct link_device *dev);
/** Telemetry header /** periodic telemetry msg name definition
*/ */
struct telemetry_msg { typedef const char telemetry_msg[64];
char msg[64]; ///< name in telemetry xml file
telemetry_cb cb; ///< callback funtion
};
/** Periodic telemetry structure. /** Periodic telemetry structure.
* Contains the total number of messages (from generated telemetry file) * Contains the total number of messages (from generated telemetry file)
* and the list of registered callbacks * and the list of registered callbacks
*/ */
struct periodic_telemetry { struct periodic_telemetry {
uint8_t nb; ///< number of messages uint8_t nb; ///< number of messages
struct telemetry_msg *msgs; ///< the list of (msg name, callbacks) telemetry_msg *msgs; ///< the array of msg names
telemetry_cb *cbs; ///< array of associated callbacks
}; };
/** Register a telemetry callback function. /** Register a telemetry callback function.
+4 -4
View File
@@ -82,9 +82,9 @@ let output_modes = fun out_h process_name modes freq modules ->
l := (p, !phase) :: !l; l := (p, !phase) :: !l;
i := !i + freq/10; i := !i + freq/10;
right (); right ();
lprintf out_h "if (telemetry->msgs[TELEMETRY_MSG_%s_ID].cb != NULL)\n" message_name; lprintf out_h "if (telemetry->cbs[TELEMETRY_MSG_%s_ID] != NULL)\n" message_name;
right (); right ();
lprintf out_h "telemetry->msgs[TELEMETRY_MSG_%s_ID].cb(trans, dev);\n" message_name; lprintf out_h "telemetry->cbs[TELEMETRY_MSG_%s_ID](trans, dev);\n" message_name;
left (); left ();
fprintf out_h "#if USE_PERIODIC_TELEMETRY_REPORT\n"; fprintf out_h "#if USE_PERIODIC_TELEMETRY_REPORT\n";
lprintf out_h "else periodic_telemetry_err_report(TELEMETRY_PROCESS_%s, telemetry_mode_%s, TELEMETRY_MSG_%s_ID);\n" process_name process_name message_name; lprintf out_h "else periodic_telemetry_err_report(TELEMETRY_PROCESS_%s, telemetry_mode_%s, TELEMETRY_MSG_%s_ID);\n" process_name process_name message_name;
@@ -151,8 +151,8 @@ let print_message_table = fun out_h xml ->
) messages 0 in ) messages 0 in
Xml2h.define "TELEMETRY_NB_MSG" (sprintf "%d" nb); Xml2h.define "TELEMETRY_NB_MSG" (sprintf "%d" nb);
(* Structure initialization *) (* Structure initialization *)
fprintf out_h "#define TELEMETRY_STRUCT { \\\n"; fprintf out_h "#define TELEMETRY_MSG_NAMES { \\\n";
Hashtbl.iter (fun n _ -> fprintf out_h " { \"%s\", NULL }, \\\n" n) messages; Hashtbl.iter (fun n _ -> fprintf out_h " \"%s\", \\\n" n) messages;
fprintf out_h "};\n\n" fprintf out_h "};\n\n"
let print_process_send = fun out_h xml freq modules -> let print_process_send = fun out_h xml freq modules ->