m4api.h
Go to the documentation of this file.
00001 /*
00002  * m4api, a tool for M4-ATX DC-DC power supplies
00003  * (c) 2009-2010 Ken Tossell <ktossell@umd.edu>
00004  *
00005  * This is free software; you can redistribute it and/or modify it
00006  * under the terms of the GNU Lesser General Public License, version 2.1,
00007  * as published by the Free Software Foundation. 
00008  *
00009  * This software is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00012  * for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this software; if not, write to the Free Software Foundation,
00016  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00017  */
00018 
00019 #ifndef M4API_H
00020 #define M4API_H
00021 
00022 #ifdef __cplusplus
00023 extern "C" {
00024 #endif // __cplusplus
00025 
00026 const int M4API_VERSION_MAJOR = 0;
00027 const int M4API_VERSION_MINOR = 1;
00028 const float M4API_VERSION = 0.1;
00029 
00030 enum m4Type {
00031   M4_VLT_12_11,
00032   M4_VLT_12_07,
00033   M4_VLT_5_03,
00034   M4_VLT_33_01,
00035   M4_DEG,
00036   M4_SEC,
00037   M4_MSC_1_1, // 1 byte
00038   M4_MSC_1_2, // 2 bytes
00039   M4_MSC_10_1, // 1 byte
00040   M4_MSC_10_2, // 2 bytes
00041   M4_TIM, // 2 bytes
00042   M4_TRY,
00043   M4_BYT
00044 };
00045 
00046 enum m4FieldID {
00047   M4_IGN_HIGH,
00048   M4_IGN_LOW,
00049   M4_IGN_DBC,
00050   M4_PSU_DELAY,
00051   M4_VIN_MIN_START,
00052   M4_VIN_MIN_ON,
00053   M4_VIN_MIN_5V,
00054   M4_VIN_MAX,
00055   M4_12V_MAX,
00056   M4_12V_MIN,
00057   M4_5V_MAX,
00058   M4_5V_MIN,
00059   M4_33V_MAX,
00060   M4_33V_MIN,
00061   M4_12V_TIME,
00062   M4_33V_TIME,
00063   M4_PWRSW,
00064   M4_PSU_ON_TIME,
00065   M4_ON_DELAY,
00066   M4_PSU_OFF_TIME,
00067   M4_OFF_DELAY,
00068   M4_EMG_TIME_5VSB,
00069   M4_EMG_TIMER,
00070   M4_PS_ON_0,
00071   M4_PS_ON_1,
00072   M4_THUMP,
00073   M4_TEMP_MAX,
00074   M4_TEMP_MIN,
00075   M4_EMG_OFF_MODE,
00076   M4_5V_SBY_DLY,
00077   M4_OFF_DELAY_0,
00078   M4_OFF_HARD_0,
00079   M4_OFF_DELAY_1,
00080   M4_OFF_HARD_1,
00081   M4_OFF_DELAY_2,
00082   M4_OFF_HARD_2,
00083   M4_OFF_DELAY_3,
00084   M4_OFF_HARD_3,
00085   M4_OFF_DELAY_4,
00086   M4_OFF_HARD_4,
00087   M4_OFF_DELAY_5,
00088   M4_OFF_HARD_5,
00089   M4_OFF_DELAY_6,
00090   M4_OFF_HARD_6,
00091   M4_OFF_DELAY_7,
00092   M4_OFF_HARD_7,
00093   M4_RESET,
00094   M4_NUM_CONFIG_FIELDS
00095 };
00096 
00097 enum m4Repr {
00098   M4_INTEG,
00099   M4_FLOAT,
00100   M4_TIMER
00101 };
00102 
00103 struct m4DiagField {
00104   enum m4Type type;
00105   unsigned int index;
00106   char *name;
00107   char *desc;
00108 };
00109 
00110 struct m4ConfigField {
00111   enum m4Type type;
00112   unsigned int index;
00113   char *name;
00114   char *desc;
00115 };
00116 
00117 struct m4Diagnostics {
00118   float vin;
00119   float vign;
00120   float v33;
00121   float v5;
00122   float v12;
00123   float temp;
00124 };
00125 
00126 struct m4Version {  
00127   int major;
00128   int minor;
00129 };
00130 
00131 extern struct m4DiagField m4DiagFields[];
00132 extern struct m4ConfigField m4ConfigFields[];
00133 extern char* m4TypeDescs[];
00134 
00135 /* Find and open the PSU */
00136 struct usb_dev_handle *m4Init();
00137 
00138 /* User-friendly-ish routines for setting/getting config values */
00139 int m4GetFloat(struct usb_dev_handle *dev, enum m4FieldID fid, float *out);
00140 int m4SetFloat(struct usb_dev_handle *dev, enum m4FieldID fid, float val);
00141 int m4GetInteger(struct usb_dev_handle *dev, enum m4FieldID fid, int *out);
00142 int m4SetInteger(struct usb_dev_handle *dev, enum m4FieldID fid, int val);
00143 
00144 /* Get the diagnostic string in its raw form (<0 = error) */
00145 int m4FetchDiag (struct usb_dev_handle *dev, char *buf);
00146 
00147 /* Get the diagnostic values in processed form (<0 = error) */
00148 int m4GetDiag (struct usb_dev_handle *dev, struct m4Diagnostics *diag);
00149 
00150 /* Get a floating-point representation of the value stored at specified memory location */
00151 float m4GetVal(enum m4Type type, char *posn);
00152 
00153 /* Print the formatted value of the element of type `type' and value `val' */
00154 void m4PrintVal(enum m4Type type, float val);
00155 
00156 /* Load the field's value from the PSU into buf */
00157 int m4GetConfig(struct usb_dev_handle *dev, struct m4ConfigField *field, char *buf);
00158 
00159 /* Parse a value (123, 1.23 or 00:00:10) into buffer, encoding it */
00160 int m4ParseValue(enum m4Type type, char const *strval, char *buf);
00161 
00162 /* Write the human-readable value to the field on the PSU */
00163 int m4SetConfig(struct usb_dev_handle *dev, struct m4ConfigField *field, char const *strval);
00164 
00165 /* Print the status variables in the (raw) buffer */
00166 void m4PrintDiag(char *buf);
00167 
00168 /* Find the m4ConfigField of the given name */
00169 int m4ConfigField(char const *name);
00170 
00171 #ifdef __cplusplus
00172 }
00173 #endif  // __cplusplus
00174 
00175 #endif


m4atx_battery_monitor
Author(s): Ken Tossell , Chris Dunkers , Russell Toris
autogenerated on Thu Jun 6 2019 19:29:30