ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/lev0/apps/set_HMI_mech_values.c
Revision: 1.2
Committed: Thu Jul 14 17:59:56 2011 UTC (12 years, 2 months ago) by production
Content type: text/plain
Branch: MAIN
CVS Tags: Ver_6-0, Ver_6-1, Ver_6-2, Ver_6-3, Ver_6-4, Ver_9-1, Ver_5-14, Ver_LATEST, Ver_9-3, Ver_9-41, Ver_9-2, Ver_8-8, Ver_8-2, Ver_8-3, Ver_8-0, Ver_8-1, Ver_8-6, Ver_8-7, Ver_8-4, Ver_8-5, Ver_7-1, Ver_7-0, Ver_9-5, Ver_9-4, Ver_8-10, Ver_8-11, Ver_8-12, Ver_9-0, HEAD
Changes since 1.1: +14 -8 lines
Log Message:
update to new dir and name of in_air_cal.*

File Contents

# Content
1 /* this block of code sets the mech table info for HMI
2 it assumes the mech tables are located at $JSOCROOT/TABLEPATH
3 and are named in the POL_TABLE, TUNE_TABLE, FOCUS_TABLE defines.
4 declaration below.
5
6 this code creates the kwywords in the lines:
7 static char *pol_keys[] = {"HPL1POS", "HPL2POS", "HPL3POS"};
8 static char *tuning_keys[] = {"HWL1POS", "HWL2POS", "HWL3POS", "HWL4POS"};
9 static char *focus_keys[] = {"HCF1POS", "HCF2POS"};
10
11 Call: status = set_HMI_mech_values(DRMS_Record_t *rec)
12
13 rec should be the lev0 record after the ISP values are inserted.
14
15 status != 0 probably should cause a severe warning that the mechanism
16 position keywords are wrong.
17 */
18
19 #include <drms_keyword.h>
20 #include <printk.h>
21
22 /* Function to set HMI mechanism position keywords */
23
24 /* The "mech" tables are found in $JSOCROOT at these locations */
25 /* #define TABLE_PATH "proj/lev0/apps/data/" */
26 /* path now absolute as users don't have a Development directory */
27 #define TABLE_PATH "/home/jsoc/cvs/Development/JSOC/proj/tables/hmi_mech/"
28 /* #define POL_TABLE "in_air_cal3.p" */
29 /* #define TUNE_TABLE "in_air_cal3.w" */
30 /* #define FOCUS_TABLE "in_air_cal.c" */
31 #define POL_TABLE "std_flight.p"
32 #define TUNE_TABLE "std_flight.w"
33 #define FOCUS_TABLE "std_flight.c"
34
35
36 #define MECHMAXROWS 2000
37 #define MECHINIT_OK 0
38 #define MECHINIT_NOFILE 1
39 #define MECHINIT_ROWS 2
40 #define MECH_KEY_MISSING 3
41 #define MECH_INDEX_MISSING 4
42
43 typedef struct mech_tabinfo
44 {
45 char *filename;
46 char *index;
47 char **keys;
48 int *table;
49 int cols;
50 } MECH_TABINFO_t;
51
52
53 /* Initialize mechanism lookup tables. Is used once on forst call
54 of set_HMI_mech_values and once if out of range index is found
55 to reset if tables have been updated.
56 */
57
58 static int init_HMI_mech_tables(MECH_TABINFO_t *tabinfo, int tab)
59 {
60 for (tab=0; tab<3; tab++)
61 {
62 char tablepath[1024];
63 char *tableroot;
64 int idx, *res, val, vals;
65 FILE *fp;
66 char line[1024];
67 /* get file for this table */
68 //if(!(tableroot = (char *)getenv("JSOCROOT"))) return(MECHINIT_NOFILE);
69 //strcpy(tablepath, tableroot);
70 //strcat(tablepath, "/");
71 //strcat(tablepath, TABLE_PATH);
72 strcpy(tablepath, TABLE_PATH);
73 strcat(tablepath, tabinfo[tab].filename);
74 fp = fopen(tablepath, "r");
75 if (!fp)
76 {
77 printk("Failed to open mech table %s, die.\n",tablepath);
78 return(MECHINIT_NOFILE);
79 }
80 res = tabinfo[tab].table;
81 vals = tabinfo[tab].cols;
82 /* fill table with missing entry flags */
83 for (idx=0; idx<MECHMAXROWS; idx++)
84 for (val=0; val<vals+1; val++)
85 res[val + (vals+1)*idx] = -1;
86 /* fill table from file */
87 for (idx=0; idx<MECHMAXROWS && fgets(line,1024,fp); )
88 {
89 if (*line != '#')
90 {
91 char *e, *p=line;
92 int d;
93 for (val=0; val<vals+1; val++)
94 {
95 d = strtod(p, &e);
96 if (e == p)
97 break;
98 else
99 {
100 p = e;
101 res[val + (vals+1)*idx] = d;
102 }
103 }
104 if (res[(vals+1)*idx] >= 0)
105 idx++;
106 }
107 }
108 fclose(fp);
109 if (idx >= MECHMAXROWS)
110 {
111 printk("Failed in mech table init, too many rows in %s, fix MECHMAXROWS die.\n",tablepath);
112 return(MECHINIT_ROWS);
113 }
114 }
115 return(MECHINIT_OK);
116 }
117
118 /* set mechanism state lookup table info */
119 /* returns 0 for OK or other status if program should terminate */
120
121 #define HMI_MECH_TABLES 3
122
123 int set_HMI_mech_values(DRMS_Record_t *rec)
124 {
125 static int called = 0;
126
127 static int pol[MECHMAXROWS*4];
128 static int tuning[MECHMAXROWS*5];
129 static int focus[MECHMAXROWS*3];
130
131 /* DRMS keyword names for mech table values - "short" names will be used. */
132 static char *pol_keys[] = {"HPL1POS", "HPL2POS", "HPL3POS"};
133 static char *tuning_keys[] = {"HWL1POS", "HWL2POS", "HWL3POS", "HWL4POS"};
134 static char *focus_keys[] = {"HCF1POS", "HCF2POS"};
135
136 static char *camkey = "HCAMID";
137
138 static MECH_TABINFO_t tabinfo[] = {
139 {POL_TABLE, "HPLTID", pol_keys, pol, 3},
140 {TUNE_TABLE, "HWLTID", tuning_keys, tuning, 4},
141 {FOCUS_TABLE, "HCFTID", focus_keys, focus, 2}
142 };
143 int tab;
144
145 /* on first time only, fetch and read each table. */
146 if (!called)
147 {
148 int status = 0;
149 called = 1;
150
151 /* init each table */
152 if (init_HMI_mech_tables(tabinfo, 4) != 0)
153 {
154 printk("Failed it initialize mechanism tables, code=%d\n",status);
155 return(status);
156 }
157
158 }
159
160 for (tab=0; tab < HMI_MECH_TABLES; tab++)
161 {
162 int retried = 0;
163 int found_index;
164 int row, index;
165 int status;
166 int val, vals = tabinfo[tab].cols;
167 int *res = tabinfo[tab].table;
168 char **keys = tabinfo[tab].keys;
169 found_index = 0;
170 index = drms_getkey_int(rec, tabinfo[tab].index, &status);
171 if (status)
172 {
173 printk("Mech Index %s not found.\n",tabinfo[tab].index);
174 return(MECH_KEY_MISSING);
175 }
176 /* search for row index in table */
177 for (row=0; row<=MECHMAXROWS; row++)
178 {
179 if (row == MECHMAXROWS)
180 { /* index not found, reset table once else giveup */
181 if (!retried)
182 {
183 if (init_HMI_mech_tables(tabinfo, 4) != 0)
184 {
185 printk("Failed it initialize mechanism tables, code=%d\n",status);
186 return(status);
187 }
188 row = 0; /* start over */
189 retried = 1;
190 }
191 else
192 {
193 printk("Failed to find given index %d in mech table %d\n",index,tab);
194 return(MECH_INDEX_MISSING);
195 }
196 }
197 if (index == res[(vals+1)*row])
198 { /* found proper row for this image */
199 for (val=0; val<vals; val++)
200 {
201 drms_setkey_int(rec, keys[val], res[val+1+(vals+1)*row]);
202 }
203 break;
204 }
205 }
206 }
207 return(0);
208 }
209