ARPDAS_QNX6 1.0
|
00001 /* Copyright 2012 by the President and Fellows of Harvard College */ 00002 00003 /*! \file tm.h 00004 * \brief Defines basic telemetry formats 00005 */ 00006 00007 #ifndef TM_H 00008 #define TM_H 00009 00010 #include <sys/types.h> /* this is for pid_t and nid_t and time_t */ 00011 #include <fcntl.h> /* for arguments to tm_open_name() */ 00012 00013 #ifndef __GNUC__ 00014 #define __attribute__(x) 00015 #endif 00016 00017 /* 00018 * Message structures 00019 * I am assuming a short has 16 bits and a long has 32 bits 00020 * should probably add: 00021 * assert( sizeof(tm_hdrw_t) == 2 ); 00022 * assert( sizeof(tmcks_t) == 4 ); 00023 * to the initialization somewhere. 00024 */ 00025 typedef unsigned short mfc_t; 00026 typedef unsigned short tm_hdrw_t; 00027 typedef unsigned long tmcks_t; 00028 typedef struct { 00029 tm_hdrw_t tm_id; /* 'TM' TMHDR_WORD */ 00030 tm_hdrw_t tm_type; 00031 } tm_hdr_t; 00032 #define TMHDR_WORD 0x4D54 00033 #define TMBUFSIZE 16384 00034 00035 /* Recognized tm_type codes: */ 00036 #define TMTYPE_INIT 0x0100 00037 #define TMTYPE_TSTAMP 0x0200 00038 #define TMTYPE_DATA_T1 0x0301 00039 #define TMTYPE_DATA_T2 0x0302 00040 #define TMTYPE_DATA_T3 0x0303 00041 #define TMTYPE_DATA_T4 0x0304 00042 #define TM_HDR_SIZE_T1 6 00043 #define TM_HDR_SIZE_T2 10 00044 #define TM_HDR_SIZE_T3 8 00045 00046 00047 /** 00048 * The time stamp establishes the relationship between 00049 * minor frame counter and real time. The precision is 00050 * intended to be at least the minor frame rate. 00051 * Accuracy depends on many other factors. 00052 */ 00053 typedef struct { 00054 mfc_t mfc_num; 00055 time_t secs; 00056 } __attribute__((packed)) tstamp_t; 00057 00058 typedef struct { 00059 unsigned char version[16]; /* 1.0 etc. contents of VERSION */ 00060 unsigned char md5[16]; /* MD5 digest of core TM frame definitions */ 00061 } tmid_t; 00062 00063 /** 00064 * tm_dac_t defines the core parameters of a telemetry frame 00065 * including the MD5 digest of the .pcm frame summary, which 00066 * includes signal names and their placement in the frame. 00067 * This information in stored in tm.dac, which is stored 00068 * along with the data. If the tm.dac data does not match, 00069 * then the format is probably incompatible. 00070 * 00071 * note: nrowsper/nsecsper = rows/sec 00072 */ 00073 typedef struct { 00074 tmid_t tmid; 00075 tm_hdrw_t nbminf; 00076 tm_hdrw_t nbrow; 00077 tm_hdrw_t nrowmajf; 00078 tm_hdrw_t nsecsper; 00079 tm_hdrw_t nrowsper; 00080 tm_hdrw_t mfc_lsb; 00081 tm_hdrw_t mfc_msb; 00082 tm_hdrw_t synch; 00083 tm_hdrw_t flags; 00084 } __attribute__((packed)) tm_dac_t; 00085 #define TMF_INVERTED 1 00086 00087 /** 00088 * tm_info_t extends the tm_dac_t information with some 00089 * calculated values for easy reference and the current 00090 * timestamp. 00091 */ 00092 typedef struct { 00093 tm_dac_t tm; /* data info */ 00094 unsigned short nrowminf; /* number rows per minor frame */ 00095 unsigned short max_rows; /* maximum number of rows allowed to be sent in a message */ 00096 tstamp_t t_stmp; /* current time stamp */ 00097 } tm_info_t; 00098 00099 /** 00100 tm_data_t1_t applies when tmtype is TMTYPE_DATA_T1 00101 This structure type can be used when entire minor frames are 00102 being transmitted. This is true iff nrows is a multiple 00103 of nrowminf and the first row transmitted is the first row 00104 (row 0) of the minor frame. MFCtr and Synch can be extracted 00105 from the data that follows. data consists of n_rows * nbrow 00106 bytes. 00107 00108 TMbfr will only output TMTYPE_DATA_T1 records when 00109 nrowminf == 1. 00110 00111 TM data begins at offset 6 of the complete message. 00112 */ 00113 typedef struct { 00114 tm_hdrw_t n_rows; 00115 unsigned char data[2]; 00116 } __attribute__((packed)) tm_data_t1_t; 00117 00118 /** 00119 tm_data_t2_t applies when tmtype is TMTYPE_DATA_T2 00120 This structure type can be used to transmit rows even 00121 when the whole minor frame is not present since the 00122 mfctr and rownum of the first row are included in 00123 the header. Subsequent rows are guaranteed to be 00124 consecutive. data consists of n_rows * nbrow bytes. 00125 00126 For practical implementation reasons, TMTYPE_DATA_T2 00127 will be legal only when nrowminf > 1. 00128 00129 TM data begins at offset 10 of the complete message. 00130 */ 00131 typedef struct { 00132 tm_hdrw_t n_rows; 00133 mfc_t mfctr; 00134 mfc_t rownum; 00135 unsigned char data[2]; 00136 } __attribute__((packed)) tm_data_t2_t; 00137 00138 /** 00139 tm_data_t3_t applies when tmtype is TMTYPE_DATA_T3 00140 This structure type can be used only in the case where 00141 nrowminf=1, mfc_lsb=0 and mfc_msb=1. data is compressed 00142 by stripping off the leading mfctr and trailing synch 00143 from each minor frame. Hence data consists of 00144 n_rows * (nbrow-4) bytes. All rows are guaranteed to 00145 be sequential (since there is no way to determine 00146 their sequence without the mfctr). 00147 00148 TM data begins at offset 8 of the complete message. 00149 */ 00150 typedef struct { 00151 tm_hdrw_t n_rows; 00152 mfc_t mfctr; 00153 unsigned char data[2]; 00154 } __attribute__((packed)) tm_data_t3_t; 00155 00156 /** 00157 tm_data_t4_t applies when tmtype is TMTYPE_DATA_T4 00158 This structure type can be used under the same conditions 00159 as tm_data_t3_t. The difference is the inclusion of a 00160 cksum dword which can be used to verify the data. 00161 The algorithm for calculating the cksum has yet to be 00162 defined. 00163 00164 TM data begins at offset 12 of the complete message buffer. 00165 00166 For the time being, we will reserve this type for 00167 actual disk storage. TMbfr may support it on input, but 00168 will disregard the cksum value. lgr/rdr will be tasked 00169 with calculating and checking the values respectively. 00170 */ 00171 typedef struct { 00172 tm_hdrw_t n_rows; 00173 mfc_t mfctr; 00174 tmcks_t cksum; 00175 unsigned char data[2]; 00176 } __attribute__((packed)) tm_data_t4_t; 00177 00178 /** 00179 * tm_msg_t is the logical format of TM messages to and 00180 * from TMbfr. 00181 */ 00182 typedef struct tm_msg { 00183 tm_hdr_t hdr; 00184 union { 00185 tstamp_t ts; 00186 tm_info_t init; 00187 tm_data_t1_t data1; 00188 tm_data_t2_t data2; 00189 tm_data_t3_t data3; 00190 tm_data_t4_t data4; 00191 } body; 00192 } __attribute__((packed)) tm_msg_t; 00193 00194 /** 00195 tm_hdrs_t is a combination of all the header types, 00196 defining the minimum size struct we need to read 00197 in to understand the rest of the message. The message 00198 layout is best understood in the tm_msg_t structure, 00199 but in actual practice, I will use tm_hdrs_t, then 00200 access the data directly. 00201 */ 00202 typedef union tm_hdrs { 00203 char raw[1]; 00204 struct { 00205 tm_hdr_t hdr; 00206 union { 00207 tstamp_t ts; 00208 struct { 00209 tm_hdrw_t n_rows; 00210 tm_hdrw_t mfctr; 00211 tm_hdrw_t rownum; 00212 } dhdr; 00213 } u; 00214 } s; 00215 } __attribute__((packed)) tm_hdrs_t; 00216 00217 typedef union { 00218 tm_msg_t msg; 00219 char raw[TMBUFSIZE]; 00220 } tm_packet_t; 00221 00222 /* Global variables */ 00223 extern tm_info_t tm_info; 00224 #define tmi(x) tm_info.tm.x 00225 #define tm_mfctr(mf) (mf[tmi(mfc_lsb)] + (mf[tmi(mfc_msb)]<<8)) 00226 extern int TM_fd; 00227 extern char *TM_buf; 00228 00229 /* Function prototypes: */ 00230 #ifdef __cplusplus 00231 extern "C" { 00232 #endif 00233 00234 extern const char *tm_dev_name(const char *base); 00235 extern int tm_open_name(const char *name, const char *node, int flags); 00236 00237 /* Command Interpreter Client (CIC) and Server (CIS) Utilities 00238 Message-level definition is in cmdalgo.h 00239 */ 00240 void cic_options(int argc, char **argv, const char *def_prefix); 00241 int cic_init(void); 00242 void cic_reset(void); 00243 extern char ci_version[]; 00244 void cic_transmit(char *buf, int n_chars, int transmit); 00245 int ci_sendcmd(const char *cmdtext, int mode); 00246 int ci_sendfcmd(int mode, const char *fmt, ...); 00247 void ci_settime( long int time ); 00248 extern int cic_cmd_quit_fd; 00249 const char *ci_time_str( void ); 00250 #define CMD_MAX_COMMAND_IN 300 // Maximum command message input length 00251 void ci_server(void); /* in nortlib/cis.c */ 00252 void cis_initialize(void); /* in cmdgen.skel or .cmd */ 00253 void cis_terminate(void); /* in cmdgen.skel of .cmd */ 00254 int ci_cmdee_init( const char *name ); 00255 void ci_report_version(void); 00256 00257 /* tmcalgo (tma) support routines */ 00258 void tma_new_state(unsigned int partition, const char *name); 00259 void tma_new_time(unsigned int partition, long int t1, const char *next_cmd); 00260 void tma_hold(int hold); 00261 00262 /* tmdac.c */ 00263 void load_tmdac( const char *path ); 00264 00265 #ifdef __cplusplus 00266 }; 00267 #endif 00268 00269 #endif