emcIniFile.cc
1 /****************************************************************************** 2 * 3 * Copyright (C) 2007 Peter G. Vavaroutsos <pete AT vavaroutsos DOT com> 4 * 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of version 2.1 of the GNU General 8 * Public License as published by the Free Software Foundation. 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * THE AUTHORS OF THIS LIBRARY ACCEPT ABSOLUTELY NO LIABILITY FOR 19 * ANY HARM OR LOSS RESULTING FROM ITS USE. IT IS _EXTREMELY_ UNWISE 20 * TO RELY ON SOFTWARE ALONE FOR SAFETY. Any machinery capable of 21 * harming persons must have provisions for completely removing power 22 * from all motors, etc, before persons enter any danger area. All 23 * machinery must be designed to comply with local and national safety 24 * codes, and the authors of this software can not, and do not, take 25 * any responsibility for such compliance. 26 * 27 * This code was written as part of the EMC project. For more 28 * information, go to www.linuxcnc.org. 29 * 30 ******************************************************************************/ 31 32 #include <math.h> // M_PI. 33 #include "emcIniFile.hh" 34 35 36 IniFile::StrIntPair EmcIniFile::jointTypeMap[] = { 37 {"LINEAR", EMC_LINEAR}, 38 {"ANGULAR", EMC_ANGULAR}, 39 { NULL, 0 }, 40 }; 41 42 EmcIniFile::ErrorCode 43 EmcIniFile::Find(EmcJointType *result, 44 const char *tag, const char *section, int num) 45 { 46 return(IniFile::Find((int *)result, jointTypeMap, tag, section, num)); 47 } 48 49 50 IniFile::StrIntPair EmcIniFile::boolMap[] = { 51 {"TRUE", 1}, 52 {"YES", 1}, 53 {"1", 1}, 54 {"FALSE", 0}, 55 {"NO", 0}, 56 {"0", 0}, 57 { NULL, 0 }, 58 }; 59 60 EmcIniFile::ErrorCode 61 EmcIniFile::Find(bool *result, const char *tag, const char *section, int num) 62 { 63 ErrorCode errCode; 64 int value; 65 66 if((errCode = IniFile::Find(&value, boolMap, tag,section,num)) == ERR_NONE){ 67 *result = (bool)value; 68 } 69 70 return(errCode); 71 } 72 73 74 // The next const struct holds pairs for linear units which are 75 // valid under the [TRAJ] section. These are of the form {"name", value}. 76 // If the name "name" is encountered in the ini, the value will be used. 77 EmcIniFile::StrDoublePair EmcIniFile::linearUnitsMap[] = { 78 { "mm", 1.0 }, 79 { "metric", 1.0 }, 80 { "in", 1/25.4 }, 81 { "inch", 1/25.4 }, 82 { "imperial", 1/25.4 }, 83 { NULL, 0 }, 84 }; 85 86 EmcIniFile::ErrorCode 87 EmcIniFile::FindLinearUnits(EmcLinearUnits *result, 88 const char *tag, const char *section, int num) 89 { 90 return(IniFile::Find((double *)result, linearUnitsMap, tag, section, num)); 91 } 92 93 94 // The next const struct holds pairs for angular units which are 95 // valid under the [TRAJ] section. These are of the form {"name", value}. 96 // If the name "name" is encountered in the ini, the value will be used. 97 EmcIniFile::StrDoublePair EmcIniFile::angularUnitsMap[] = { 98 { "deg", 1.0 }, 99 { "degree", 1.0 }, 100 { "grad", 0.9 }, 101 { "gon", 0.9 }, 102 { "rad", M_PI / 180 }, 103 { "radian", M_PI / 180 }, 104 { NULL, 0 }, 105 }; 106 107 EmcIniFile::ErrorCode 108 EmcIniFile::FindAngularUnits(EmcAngularUnits *result, 109 const char *tag, const char *section, int num) 110 { 111 return(IniFile::Find((double *)result, angularUnitsMap, tag, section, num)); 112 }