00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <drms_keyword.h>
00020 #include <printk.h>
00021
00022
00023
00024
00025
00026
00027 #define TABLE_PATH "/home/jsoc/cvs/Development/JSOC/proj/tables/hmi_mech/"
00028
00029
00030
00031 #define POL_TABLE "std_flight.p"
00032 #define TUNE_TABLE "std_flight.w"
00033 #define FOCUS_TABLE "std_flight.c"
00034
00035
00036 #define MECHMAXROWS 2000
00037 #define MECHINIT_OK 0
00038 #define MECHINIT_NOFILE 1
00039 #define MECHINIT_ROWS 2
00040 #define MECH_KEY_MISSING 3
00041 #define MECH_INDEX_MISSING 4
00042
00043 typedef struct mech_tabinfo
00044 {
00045 char *filename;
00046 char *index;
00047 char **keys;
00048 int *table;
00049 int cols;
00050 } MECH_TABINFO_t;
00051
00052
00053
00054
00055
00056
00057
00058 static int init_HMI_mech_tables(MECH_TABINFO_t *tabinfo, int tab)
00059 {
00060 for (tab=0; tab<3; tab++)
00061 {
00062 char tablepath[1024];
00063 char *tableroot;
00064 int idx, *res, val, vals;
00065 FILE *fp;
00066 char line[1024];
00067
00068
00069
00070
00071
00072 strcpy(tablepath, TABLE_PATH);
00073 strcat(tablepath, tabinfo[tab].filename);
00074 fp = fopen(tablepath, "r");
00075 if (!fp)
00076 {
00077 printk("Failed to open mech table %s, die.\n",tablepath);
00078 return(MECHINIT_NOFILE);
00079 }
00080 res = tabinfo[tab].table;
00081 vals = tabinfo[tab].cols;
00082
00083 for (idx=0; idx<MECHMAXROWS; idx++)
00084 for (val=0; val<vals+1; val++)
00085 res[val + (vals+1)*idx] = -1;
00086
00087 for (idx=0; idx<MECHMAXROWS && fgets(line,1024,fp); )
00088 {
00089 if (*line != '#')
00090 {
00091 char *e, *p=line;
00092 int d;
00093 for (val=0; val<vals+1; val++)
00094 {
00095 d = strtod(p, &e);
00096 if (e == p)
00097 break;
00098 else
00099 {
00100 p = e;
00101 res[val + (vals+1)*idx] = d;
00102 }
00103 }
00104 if (res[(vals+1)*idx] >= 0)
00105 idx++;
00106 }
00107 }
00108 fclose(fp);
00109 if (idx >= MECHMAXROWS)
00110 {
00111 printk("Failed in mech table init, too many rows in %s, fix MECHMAXROWS die.\n",tablepath);
00112 return(MECHINIT_ROWS);
00113 }
00114 }
00115 return(MECHINIT_OK);
00116 }
00117
00118
00119
00120
00121 #define HMI_MECH_TABLES 3
00122
00123 int set_HMI_mech_values(DRMS_Record_t *rec)
00124 {
00125 static int called = 0;
00126
00127 static int pol[MECHMAXROWS*4];
00128 static int tuning[MECHMAXROWS*5];
00129 static int focus[MECHMAXROWS*3];
00130
00131
00132 static char *pol_keys[] = {"HPL1POS", "HPL2POS", "HPL3POS"};
00133 static char *tuning_keys[] = {"HWL1POS", "HWL2POS", "HWL3POS", "HWL4POS"};
00134 static char *focus_keys[] = {"HCF1POS", "HCF2POS"};
00135
00136 static char *camkey = "HCAMID";
00137
00138 static MECH_TABINFO_t tabinfo[] = {
00139 {POL_TABLE, "HPLTID", pol_keys, pol, 3},
00140 {TUNE_TABLE, "HWLTID", tuning_keys, tuning, 4},
00141 {FOCUS_TABLE, "HCFTID", focus_keys, focus, 2}
00142 };
00143 int tab;
00144
00145
00146 if (!called)
00147 {
00148 int status = 0;
00149 called = 1;
00150
00151
00152 if (init_HMI_mech_tables(tabinfo, 4) != 0)
00153 {
00154 printk("Failed it initialize mechanism tables, code=%d\n",status);
00155 return(status);
00156 }
00157
00158 }
00159
00160 for (tab=0; tab < HMI_MECH_TABLES; tab++)
00161 {
00162 int retried = 0;
00163 int found_index;
00164 int row, index;
00165 int status;
00166 int val, vals = tabinfo[tab].cols;
00167 int *res = tabinfo[tab].table;
00168 char **keys = tabinfo[tab].keys;
00169 found_index = 0;
00170 index = drms_getkey_int(rec, tabinfo[tab].index, &status);
00171 if (status)
00172 {
00173 printk("Mech Index %s not found.\n",tabinfo[tab].index);
00174 return(MECH_KEY_MISSING);
00175 }
00176
00177 for (row=0; row<=MECHMAXROWS; row++)
00178 {
00179 if (row == MECHMAXROWS)
00180 {
00181 if (!retried)
00182 {
00183 if (init_HMI_mech_tables(tabinfo, 4) != 0)
00184 {
00185 printk("Failed it initialize mechanism tables, code=%d\n",status);
00186 return(status);
00187 }
00188 row = 0;
00189 retried = 1;
00190 }
00191 else
00192 {
00193 printk("Failed to find given index %d in mech table %d\n",index,tab);
00194 return(MECH_INDEX_MISSING);
00195 }
00196 }
00197 if (index == res[(vals+1)*row])
00198 {
00199 for (val=0; val<vals; val++)
00200 {
00201 drms_setkey_int(rec, keys[val], res[val+1+(vals+1)*row]);
00202 }
00203 break;
00204 }
00205 }
00206 }
00207 return(0);
00208 }
00209