Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetNetIf NTPClient_NetServices mbed ConfigFile
config_env.c
00001 /************************************************************* 00002 00003 config_env.c 00004 00005 *************************************************************/ 00006 #include "mbed.h" 00007 #include "TextLCD.h" 00008 #define CHUNK 1 00009 #define AVERAGE_MIN 10*60/CHUNK 00010 #define TMP_TEXT_BUF_SIZE (256) 00011 00012 static char envini[] = "/local/env.ini"; 00013 #define default_fwserver "http://diytec.web.fc2.com/mark2r2/firmware" 00014 //char default_fwserver[] = "http://diytec.web.fc2.com/mark2r2/firmware"; 00015 00016 extern int mode,gps_mode; 00017 extern int shape_mode; 00018 extern int AnalogInput_pin_number; 00019 extern int GMInterrupt_pin_number; 00020 extern int LED_pin_number; 00021 extern int Buzzer_pin_number; 00022 extern int GPStx_pin_number; 00023 extern int GPSrx_pin_number; 00024 extern float carib; 00025 extern int updateinterval; 00026 extern int updatetype; /* 0: no 1: twitter 2: pachube */ 00027 extern int sound; /* 0: off 1: on */ 00028 extern float volt; /* voltage executed to GM tube */ 00029 extern float offset_usv; 00030 extern TextLCD lcd; 00031 extern int firmware_update_interval; 00032 extern time_t tz_offset; 00033 extern Serial pc; 00034 extern int init_stabilize_time; 00035 extern int cpu_speed; 00036 00037 extern float carib_cpm0; 00038 extern float carib_usv0; 00039 extern float carib_cpm1; 00040 extern float carib_usv1; 00041 extern unsigned int cpm_array_max; 00042 extern unsigned int long_cpm_array_max; 00043 00044 void trim(char *retbuff, char *inbuff) { 00045 int i,j,len; 00046 00047 len=strlen(inbuff); 00048 for(i=0,j=0;i<len; i++){ 00049 if(inbuff[i]>0x20) { 00050 retbuff[j]=inbuff[i]; 00051 j++; 00052 } 00053 } 00054 retbuff[j]='\0'; 00055 00056 00057 } 00058 00059 00060 int GetStatus(char *path, char *tag, char *text){ 00061 char TmpText[TMP_TEXT_BUF_SIZE]; 00062 char TmpTag[TMP_TEXT_BUF_SIZE]; 00063 FILE *stm = fopen(path, "r"); 00064 00065 if(stm != NULL){ 00066 text[0] = '\0'; 00067 sprintf(TmpTag, "%s:%%s",tag); 00068 00069 while(fgets(TmpText, TMP_TEXT_BUF_SIZE, stm) != NULL){ 00070 if(sscanf(TmpText, TmpTag, text)==EOF){ 00071 printf("error reading %s",tag); 00072 } 00073 } 00074 fclose(stm); 00075 } 00076 else { 00077 printf("file open error: %s\r\n",path); 00078 lcd.cls(); 00079 lcd.printf("open err: %s",path); 00080 abort(); 00081 } 00082 00083 return(0); 00084 } 00085 00086 /*----------- 00087 // 00088 // See http://mbed.org/users/no2chem/notebook/mbed-clock-control--benchmarks/ 00089 00090 // NOTE:if the clock speed is down, the power consumption becomes low but the timer becomes slow. 00091 00092 void cpu_setting() { // 2011/08/19 00093 char msgs[80]; 00094 00095 if(GetStatus(envfile,"cpu_speed",msgs)==0){ 00096 int m = atoi(msgs); 00097 if(m >= 6 && m <= 12){ 00098 cpu_speed=atof(msgs); 00099 } 00100 } 00101 } 00102 --------------*/ 00103 00104 #define IntVal 1 //int (positive only) 00105 #define IntVal_t1 2 //int (-1 is permitted) 00106 #define TimeVal 3 //time_t 00107 #define UintVal 4 //unsigned int 00108 #define FloatVal 5 //float 00109 #define FloatVal_t1 6 //float (negative permitted) 00110 #define FloatVal_t2 7 //float (negative & 0 permitted) 00111 00112 static char gmfile[20]; 00113 00114 // For env.ini 00115 struct envGet { 00116 char* str; 00117 int envtype; 00118 void* datval; 00119 char* file_id; 00120 } EnvGetTable[] = { 00121 {"mode", IntVal_t1, &mode, envini}, 00122 {"shape", IntVal, &shape_mode, envini}, 00123 {"gps", IntVal, &gps_mode, envini}, 00124 {"updateinterval",IntVal,&updateinterval, envini}, 00125 {"updatetype", IntVal, &updatetype, envini}, 00126 {"sound", IntVal, &sound, envini}, 00127 {"firmware_update_interval",IntVal,&firmware_update_interval, envini}, 00128 {"timezone",TimeVal, &tz_offset, envini}, 00129 {"init_stabilize_time", IntVal, &init_stabilize_time, envini}, 00130 {"GMInterrupt", IntVal, &GMInterrupt_pin_number, envini}, 00131 {"LED", IntVal, &LED_pin_number, envini}, 00132 {"Buzzer", IntVal, &Buzzer_pin_number, envini}, 00133 {"GPStx", IntVal, &GPStx_pin_number, envini}, 00134 {"GPSrx", IntVal, &GPSrx_pin_number, envini}, 00135 {"cpm_array_max", UintVal, &cpm_array_max, envini}, 00136 {"long_cpm_array_max", UintVal, &long_cpm_array_max, envini}, 00137 {"cariburation",FloatVal, &carib, gmfile}, 00138 {"voltage",FloatVal, &volt, gmfile}, 00139 {"offset_usv", FloatVal_t1, &offset_usv, gmfile}, 00140 {"cpm0", FloatVal, &carib_cpm0, gmfile}, 00141 {"usv0", FloatVal, &carib_usv0, gmfile}, 00142 {"cpm1", FloatVal, &carib_cpm1, gmfile}, 00143 {"usv1", FloatVal, &carib_usv1, gmfile}, 00144 {"uSv0", FloatVal_t2, &carib_usv0, gmfile}, 00145 {"uSv1", FloatVal_t2, &carib_usv1, gmfile} 00146 }; 00147 00148 void environment_setting(char *fws){ 00149 char msgs[80]; 00150 char gmtype[50]; 00151 00152 // GM tube characteristic feature reading // 00153 if(GetStatus(envini,"gmtype",gmtype)==0){ 00154 strcpy(gmfile,"/local/"); 00155 strcat(gmfile,gmtype); 00156 printf("%s will be used for GM tube cariburation\n",gmfile); 00157 00158 for(int i=0; i<sizeof(EnvGetTable)/sizeof(envGet) ; i++ ) { 00159 if(GetStatus(EnvGetTable[i].file_id,EnvGetTable[i].str,msgs)==0){ 00160 switch(EnvGetTable[i].envtype) { 00161 case IntVal: 00162 if(atoi(msgs)>0){ 00163 *((int*)EnvGetTable[i].datval)=atoi(msgs); 00164 } 00165 printf("%s=%d\r\n", EnvGetTable[i].str, *((int*)EnvGetTable[i].datval)); 00166 break; 00167 case IntVal_t1: 00168 if(atoi(msgs)>0 || atoi(msgs)==-1){ 00169 *((int*)EnvGetTable[i].datval)=atoi(msgs); 00170 } 00171 printf("%s=%d\r\n", EnvGetTable[i].str, *((int*)EnvGetTable[i].datval)); 00172 break; 00173 case TimeVal: 00174 if(msgs[0] != '\0'){ 00175 *((time_t*)EnvGetTable[i].datval)=atoi(msgs); 00176 } 00177 printf("%s=%d\r\n", EnvGetTable[i].str, *((time_t*)EnvGetTable[i].datval)); 00178 break; 00179 case UintVal: 00180 if(atoi(msgs)>0){ 00181 *((unsigned int*)EnvGetTable[i].datval)=atoi(msgs); 00182 } 00183 printf("%s=%d\r\n", EnvGetTable[i].str, *((unsigned int*)EnvGetTable[i].datval)); 00184 break; 00185 case FloatVal: 00186 if(atof(msgs)>= 0){ 00187 *((float*)EnvGetTable[i].datval)=atof(msgs); 00188 } 00189 printf("%s=%f\r\n", EnvGetTable[i].str, *((float*)EnvGetTable[i].datval)); 00190 break; 00191 case FloatVal_t1: 00192 *((float*)EnvGetTable[i].datval)=atof(msgs); 00193 printf("%s=%f\r\n", EnvGetTable[i].str, *((float*)EnvGetTable[i].datval)); 00194 break; 00195 case FloatVal_t2: 00196 if(atof(msgs)> 0){ 00197 *((float*)EnvGetTable[i].datval)=atof(msgs); 00198 printf("%s=%f\r\n", EnvGetTable[i].str, *((float*)EnvGetTable[i].datval)); 00199 } 00200 break; 00201 00202 } 00203 } 00204 } 00205 00206 if(GetStatus(envini,"fwserver",msgs)==0){ 00207 if(strlen(msgs) <= 3){ 00208 strcpy(fws, default_fwserver); 00209 } else { 00210 trim(fws,msgs); 00211 } 00212 } 00213 printf("fwserver=%s\r\n", fws); 00214 00215 updateinterval*=(60/CHUNK); 00216 tz_offset *= 3600; 00217 00218 // override by 2 point cariburation 00219 if (carib_cpm0 > 0 && carib_usv0 > 0 && 00220 carib_cpm1 > 0 && carib_usv1 > 0 && 00221 (carib_cpm0 < carib_cpm1 && carib_usv0 < carib_usv1) || 00222 (carib_cpm0 > carib_cpm1 && carib_usv0 > carib_usv1)) { 00223 carib = (carib_cpm1 - carib_cpm0) / (carib_usv1 - carib_usv0); 00224 offset_usv = carib_usv0 - (carib_cpm0 / carib); 00225 printf("2 point cariburation=%f\r\n", carib); 00226 printf("2 point offset_usv=%f\r\n", offset_usv); 00227 } 00228 00229 if( (updatetype == 0) && (cpm_array_max <10)) { 00230 } else { 00231 cpm_array_max = 10; 00232 } 00233 cpm_array_max *= 60/CHUNK; 00234 } 00235 }
Generated on Tue Jul 12 2022 10:57:43 by
1.7.2