00039 : bridgeporttool.cc,v 1.4 2001/06/29 20:27:29 wshackle Exp $";
00040
00041 // shortcuts to NML module subordinate statuses
00042 #define spindleStatus ((EMC_SPINDLE_STAT *) statusInData[spindleSubNum])
00043 #define coolantStatus ((EMC_COOLANT_STAT *) statusInData[coolantSubNum])
00044 #define auxStatus ((EMC_AUX_STAT *) statusInData[auxSubNum])
00045 #define lubeStatus ((EMC_LUBE_STAT *) statusInData[lubeSubNum])
00046
00047 /*
00048 load the tool table from file filename into toolTable[] array.
00049 Array is CANON_TOOL_MAX + 1 entries, since 0 is included.
00050
00051 If filename is "", use global established from ini file
00052 */
00053 static int loadToolTable(const char *filename, CANON_TOOL_TABLE toolTable[])
00054 {
00055 int t;
00056 FILE *fp;
00057 char buffer[CANON_TOOL_ENTRY_LEN];
00058 const char *name;
00059
00060 // check filename
00061 if (filename[0] == 0)
00062 {
00063 name = TOOL_TABLE_FILE;
00064 }
00065 else
00066 {
00067 // point to name provided
00068 name = filename;
00069 }
00070
00071 // open tool table file
00072 if (NULL == (fp = fopen(name, "r")))
00073 {
00074 // can't open file
00075 return -1;
00076 }
00077
00078 // clear out tool table
00079 for (t = 0; t <= CANON_TOOL_MAX; t++)
00080 {
00081 // unused tools are 0, 0.0, 0.0
00082 toolTable[t].id = 0;
00083 toolTable[t].length = 0.0;
00084 toolTable[t].diameter = 0.0;
00085 }
00086
00087 /*
00088 Override 0's with codes from tool file
00089
00090 File format is:
00091
00092 <header>
00093 <pocket # 0..CANON_TOOL_MAX> <FMS id> <length> <diameter>
00094 ...
00095
00096 */
00097
00098 // read and discard header
00099 if (NULL == fgets(buffer, 256, fp))
00100 {
00101 // nothing in file at all
00102 fclose(fp);
00103 return -1;
00104 }
00105
00106 while (!feof(fp))
00107 {
00108 int pocket;
00109 int id;
00110 double length;
00111 double diameter;
00112
00113 // just read pocket, ID, and length offset
00114 if (NULL == fgets(buffer, CANON_TOOL_ENTRY_LEN, fp))
00115 {
00116 break;
00117 }
00118
00119 if (4 != sscanf(buffer, "%d %d %lf %lf",
00120 &pocket, &id, &length, &diameter))
00121 {
00122 // bad entry-- skip
00123 continue;
00124 }
00125 else
00126 {
00127 if (pocket < 0 || pocket > CANON_TOOL_MAX)
00128 {
00129 continue;
00130 }
00131 else
00132 {
00133 toolTable[pocket].id = id;
00134 toolTable[pocket].length = length;
00135 toolTable[pocket].diameter = diameter;
00136 }
00137 }
00138 }
00139
00140 // close the file
00141 fclose(fp);
00142
00143 return 0;
00144 }