Dependencies:   ChaNFSSD mbed BMP085 SHT2x

Committer:
tosihisa
Date:
Sun Jan 29 14:06:48 2012 +0000
Revision:
3:844fbe607dae
Parent:
2:f546aaa0e1d5
Child:
4:879b8dcfee15
Add log function with push-SW.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tosihisa 1:83960ee4d9a2 1 /*
tosihisa 1:83960ee4d9a2 2 * このソフトウェアは、大阪市立大学と京都大学生存圏ミッション研究の共同研究の成果物です。
tosihisa 1:83960ee4d9a2 3 * ソースコードそのもののライセンスは、各ソースコードのライセンスに沿って公開します。
tosihisa 1:83960ee4d9a2 4 * 2012-1-4 Toshihisa T
tosihisa 1:83960ee4d9a2 5 */
tosihisa 3:844fbe607dae 6
tosihisa 3:844fbe607dae 7 //#define _I2C_TEST
tosihisa 3:844fbe607dae 8 #define HAVE_TOGGLE_SW
tosihisa 3:844fbe607dae 9 #define HAVE_MICROSD
tosihisa 3:844fbe607dae 10
tosihisa 0:6089ae824f06 11 #include "mbed.h"
tosihisa 0:6089ae824f06 12 #include "NMEA_parse.h"
tosihisa 0:6089ae824f06 13 #include "SDFileSystem.h"
tosihisa 0:6089ae824f06 14 #include "libT/mbed/tserialbuffer.h"
tosihisa 0:6089ae824f06 15 #include "BMP085.h"
tosihisa 0:6089ae824f06 16 #include "SHT2x.h"
tosihisa 0:6089ae824f06 17 #include "AD7994.h"
tosihisa 0:6089ae824f06 18 //#include "TextLCD.h"
tosihisa 0:6089ae824f06 19 #include "TextLCD_20X4.h"
tosihisa 1:83960ee4d9a2 20 #include "UBXPacket.h"
tosihisa 0:6089ae824f06 21
tosihisa 0:6089ae824f06 22 using namespace libT;
tosihisa 0:6089ae824f06 23
tosihisa 0:6089ae824f06 24 #define _USE_FS_NAME "sd"
tosihisa 0:6089ae824f06 25
tosihisa 0:6089ae824f06 26 Serial debug(USBTX,USBRX);
tosihisa 0:6089ae824f06 27
tosihisa 0:6089ae824f06 28 DigitalIn gps_int0(p24);
tosihisa 0:6089ae824f06 29 DigitalOut gps_reset(p25);
tosihisa 0:6089ae824f06 30 InterruptIn gps_pps(p26);
tosihisa 0:6089ae824f06 31 tSerialBuffer gps(p28,p27);
tosihisa 0:6089ae824f06 32 DigitalOut gps_pps_led(LED2);
tosihisa 1:83960ee4d9a2 33 #ifdef _I2C_TEST /* { */
tosihisa 1:83960ee4d9a2 34 I2C i2c(p9, p10); // sda, scl
tosihisa 1:83960ee4d9a2 35 #endif /* } */
tosihisa 0:6089ae824f06 36 BMP085 bmp085(p9, p10);
tosihisa 0:6089ae824f06 37 //SHT25 sht25(p9, p10);
tosihisa 2:f546aaa0e1d5 38 SHT2x sht25(p9,p10);
tosihisa 0:6089ae824f06 39 AD7994 ad7994(p9,p10);
tosihisa 0:6089ae824f06 40 TextLCD_20X4 lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7
tosihisa 3:844fbe607dae 41 #ifdef HAVE_TOGGLE_SW /* { */
tosihisa 3:844fbe607dae 42 DigitalIn toggleSW(p22);
tosihisa 3:844fbe607dae 43 int toggleSW_scan = 0;
tosihisa 3:844fbe607dae 44 int toggleSW_pre = -1;
tosihisa 3:844fbe607dae 45 #endif /* } */
tosihisa 3:844fbe607dae 46 int toggleSW_now = 0;
tosihisa 3:844fbe607dae 47 Ticker tick;
tosihisa 0:6089ae824f06 48
tosihisa 1:83960ee4d9a2 49 SDFileSystem sd(p5, p6, p7, p8, _USE_FS_NAME);
tosihisa 3:844fbe607dae 50 int avaiableSD = -1;
tosihisa 3:844fbe607dae 51 unsigned short logNextCount = 0;
tosihisa 3:844fbe607dae 52 FILE *csvFP = NULL;
tosihisa 3:844fbe607dae 53 FILE *gpsFP = NULL;
tosihisa 3:844fbe607dae 54 int logSW = 0;
tosihisa 3:844fbe607dae 55 DigitalOut logled(LED3);
tosihisa 0:6089ae824f06 56
tosihisa 0:6089ae824f06 57 DigitalOut myled(LED1);
tosihisa 0:6089ae824f06 58
tosihisa 0:6089ae824f06 59 tSerialBuffer CO2(p13,p14);
tosihisa 0:6089ae824f06 60
tosihisa 1:83960ee4d9a2 61 struct UBXPacket_s UBXPacket;
tosihisa 1:83960ee4d9a2 62
tosihisa 0:6089ae824f06 63 int pps_count = 0;
tosihisa 0:6089ae824f06 64 void gps_pps_rise()
tosihisa 0:6089ae824f06 65 {
tosihisa 0:6089ae824f06 66 gps_pps_led = ((pps_count+=1) & 1) ? 1 : 0;
tosihisa 0:6089ae824f06 67 }
tosihisa 0:6089ae824f06 68
tosihisa 3:844fbe607dae 69 void logFile_Init() {
tosihisa 0:6089ae824f06 70 DIR *d;
tosihisa 0:6089ae824f06 71 struct dirent *p;
tosihisa 3:844fbe607dae 72 unsigned short countCandidate;
tosihisa 3:844fbe607dae 73 char *endptr;
tosihisa 0:6089ae824f06 74
tosihisa 3:844fbe607dae 75 avaiableSD = 0;
tosihisa 0:6089ae824f06 76 d = opendir("/" _USE_FS_NAME);
tosihisa 0:6089ae824f06 77 if ( d != NULL ) {
tosihisa 0:6089ae824f06 78 while ( (p = readdir(d)) != NULL ) {
tosihisa 0:6089ae824f06 79 debug.printf("FILE - %s\x0d\x0a", p->d_name);
tosihisa 3:844fbe607dae 80 if (strlen(p->d_name) == (sizeof("ENVxxxxx.CSV")-1)) {
tosihisa 3:844fbe607dae 81 if ( ((p->d_name[0] == 'E') || (p->d_name[0] == 'e'))
tosihisa 3:844fbe607dae 82 && ((p->d_name[1] == 'N') || (p->d_name[1] == 'n'))
tosihisa 3:844fbe607dae 83 && ((p->d_name[2] == 'V') || (p->d_name[2] == 'v'))) {
tosihisa 3:844fbe607dae 84 }
tosihisa 3:844fbe607dae 85 countCandidate = (unsigned short)strtoul(&(p->d_name[3]),&endptr,10);
tosihisa 3:844fbe607dae 86 if (strcasecmp(endptr,".CSV") == 0) {
tosihisa 3:844fbe607dae 87 if (countCandidate > logNextCount) {
tosihisa 3:844fbe607dae 88 logNextCount = countCandidate;
tosihisa 3:844fbe607dae 89 }
tosihisa 3:844fbe607dae 90 }
tosihisa 3:844fbe607dae 91 }
tosihisa 0:6089ae824f06 92 }
tosihisa 0:6089ae824f06 93 closedir(d);
tosihisa 3:844fbe607dae 94 logNextCount++;
tosihisa 3:844fbe607dae 95 avaiableSD = 1;
tosihisa 0:6089ae824f06 96 }
tosihisa 0:6089ae824f06 97 }
tosihisa 0:6089ae824f06 98
tosihisa 0:6089ae824f06 99
tosihisa 0:6089ae824f06 100 int CO2_Read(unsigned short *val)
tosihisa 0:6089ae824f06 101 {
tosihisa 0:6089ae824f06 102 unsigned char sbuf[] = { 0xFE, 0x04, 0x00, 0x03, 0x00, 0x01, 0xD5, 0xC5 };
tosihisa 0:6089ae824f06 103 unsigned char rbuf[7];
tosihisa 0:6089ae824f06 104 int i;
tosihisa 0:6089ae824f06 105 unsigned short crc;
tosihisa 0:6089ae824f06 106 extern unsigned short modbus_CRC(unsigned char *DataPtr, unsigned short len);
tosihisa 0:6089ae824f06 107
tosihisa 0:6089ae824f06 108 for(i=0;i < sizeof(sbuf);i++){
tosihisa 0:6089ae824f06 109 //debug.printf("0x%02x ",sbuf[i]);
tosihisa 0:6089ae824f06 110 CO2.putc(sbuf[i]);
tosihisa 0:6089ae824f06 111 }
tosihisa 0:6089ae824f06 112 for(i=0;i < sizeof(rbuf);i++){
tosihisa 0:6089ae824f06 113 while(!CO2.readable()){}
tosihisa 0:6089ae824f06 114 rbuf[i] = CO2.getc();
tosihisa 0:6089ae824f06 115 }
tosihisa 1:83960ee4d9a2 116 if(rbuf[0] != 0xFE){
tosihisa 1:83960ee4d9a2 117 return -4;
tosihisa 1:83960ee4d9a2 118 }
tosihisa 1:83960ee4d9a2 119 if(rbuf[1] != 0x04){
tosihisa 1:83960ee4d9a2 120 return -1;
tosihisa 1:83960ee4d9a2 121 }
tosihisa 1:83960ee4d9a2 122 if(rbuf[2] != 0x02){
tosihisa 1:83960ee4d9a2 123 return -2;
tosihisa 1:83960ee4d9a2 124 }
tosihisa 0:6089ae824f06 125 crc = rbuf[6];
tosihisa 0:6089ae824f06 126 crc = (crc << 8) | rbuf[5];
tosihisa 0:6089ae824f06 127 if(crc != modbus_CRC(rbuf,5)){
tosihisa 1:83960ee4d9a2 128 return -3;
tosihisa 0:6089ae824f06 129 }
tosihisa 0:6089ae824f06 130 *val = rbuf[3];
tosihisa 0:6089ae824f06 131 *val = (*val << 8) | rbuf[4];
tosihisa 0:6089ae824f06 132 return 0;
tosihisa 0:6089ae824f06 133 }
tosihisa 0:6089ae824f06 134
tosihisa 0:6089ae824f06 135 // BMP085 0xee
tosihisa 0:6089ae824f06 136 // AD9774 0x44
tosihisa 1:83960ee4d9a2 137 #ifdef _I2C_TEST /* { */
tosihisa 0:6089ae824f06 138 int i2c_found() {
tosihisa 0:6089ae824f06 139 int count = 0;
tosihisa 1:83960ee4d9a2 140 lcd.locate(0,2);
tosihisa 1:83960ee4d9a2 141 lcd.printf("%-19s","I2C Dev:");
tosihisa 1:83960ee4d9a2 142 lcd.locate(8,2);
tosihisa 0:6089ae824f06 143 for (int address=0; address<256; address+=2) {
tosihisa 0:6089ae824f06 144 if (!i2c.write(address, NULL, 0)) { // 0 returned is ok
tosihisa 1:83960ee4d9a2 145 lcd.printf("%02X ",address);
tosihisa 0:6089ae824f06 146 count++;
tosihisa 0:6089ae824f06 147 }
tosihisa 0:6089ae824f06 148 }
tosihisa 1:83960ee4d9a2 149 lcd.printf("\n");
tosihisa 1:83960ee4d9a2 150 lcd.printf("%d devices found", count);
tosihisa 0:6089ae824f06 151 return count;
tosihisa 0:6089ae824f06 152 }
tosihisa 1:83960ee4d9a2 153 #endif /* } */
tosihisa 1:83960ee4d9a2 154
tosihisa 1:83960ee4d9a2 155 unsigned char NMEA_CalcSum(unsigned char *str,int len)
tosihisa 1:83960ee4d9a2 156 {
tosihisa 1:83960ee4d9a2 157 unsigned char sum = 0;
tosihisa 1:83960ee4d9a2 158 int i;
tosihisa 1:83960ee4d9a2 159 for(i = 0;i < len;i++){
tosihisa 1:83960ee4d9a2 160 sum = sum ^ (*(str + i));
tosihisa 1:83960ee4d9a2 161 }
tosihisa 1:83960ee4d9a2 162 return sum;
tosihisa 1:83960ee4d9a2 163 }
tosihisa 1:83960ee4d9a2 164
tosihisa 1:83960ee4d9a2 165 void UBX_CalcSum(unsigned char *str,int len,unsigned char *sum)
tosihisa 1:83960ee4d9a2 166 {
tosihisa 1:83960ee4d9a2 167 int i;
tosihisa 1:83960ee4d9a2 168 *(sum + 0) = *(sum + 1) = 0;
tosihisa 1:83960ee4d9a2 169 for(i = 0;i < len;i++){
tosihisa 1:83960ee4d9a2 170 *(sum + 0) = *(sum + 0) + *(str+i);
tosihisa 1:83960ee4d9a2 171 *(sum + 1) = *(sum + 1) + *(sum + 0);
tosihisa 1:83960ee4d9a2 172 }
tosihisa 1:83960ee4d9a2 173 }
tosihisa 1:83960ee4d9a2 174
tosihisa 1:83960ee4d9a2 175 int UBX_WaitAck(struct UBXPacket_s *info)
tosihisa 1:83960ee4d9a2 176 {
tosihisa 1:83960ee4d9a2 177 UBXPacket.cjobst = 0;
tosihisa 1:83960ee4d9a2 178
tosihisa 1:83960ee4d9a2 179 while(1){
tosihisa 1:83960ee4d9a2 180 while(gps.readable()) {
tosihisa 1:83960ee4d9a2 181 if(UBXPacket_Parse(&UBXPacket,gps.getc()) == 100){
tosihisa 1:83960ee4d9a2 182 if((UBXPacket.cls == 0x05) && (UBXPacket.id == 0x01)){
tosihisa 1:83960ee4d9a2 183 return 1; /* ACK */
tosihisa 1:83960ee4d9a2 184 } else if((UBXPacket.cls == 0x05) && (UBXPacket.id == 0x00)){
tosihisa 1:83960ee4d9a2 185 return 0; /* NAK */
tosihisa 1:83960ee4d9a2 186 } else {
tosihisa 1:83960ee4d9a2 187 UBXPacket.cjobst = 0;
tosihisa 1:83960ee4d9a2 188 }
tosihisa 1:83960ee4d9a2 189 }
tosihisa 1:83960ee4d9a2 190 }
tosihisa 1:83960ee4d9a2 191 }
tosihisa 3:844fbe607dae 192 }
tosihisa 3:844fbe607dae 193
tosihisa 3:844fbe607dae 194 unsigned long tickCount = 0;
tosihisa 3:844fbe607dae 195 unsigned long hzCount = 0;
tosihisa 3:844fbe607dae 196 unsigned long hzCount_tmp = 0;
tosihisa 3:844fbe607dae 197 unsigned long logTickCount = 0;
tosihisa 3:844fbe607dae 198 void tickHandler()
tosihisa 3:844fbe607dae 199 {
tosihisa 3:844fbe607dae 200 logTickCount++;
tosihisa 3:844fbe607dae 201 tickCount++;
tosihisa 3:844fbe607dae 202 hzCount_tmp++;
tosihisa 3:844fbe607dae 203 if(hzCount_tmp >= 50){
tosihisa 3:844fbe607dae 204 hzCount_tmp = 0;
tosihisa 3:844fbe607dae 205 hzCount++;
tosihisa 3:844fbe607dae 206 }
tosihisa 3:844fbe607dae 207 #ifdef HAVE_TOGGLE_SW /* { */
tosihisa 3:844fbe607dae 208 int nowRead;
tosihisa 3:844fbe607dae 209 nowRead = toggleSW.read();
tosihisa 3:844fbe607dae 210 if(nowRead != toggleSW_pre){
tosihisa 3:844fbe607dae 211 toggleSW_pre = nowRead;
tosihisa 3:844fbe607dae 212 toggleSW_scan = 0;
tosihisa 3:844fbe607dae 213 } else {
tosihisa 3:844fbe607dae 214 toggleSW_scan++;
tosihisa 3:844fbe607dae 215 if(toggleSW_scan >= 3){
tosihisa 3:844fbe607dae 216 toggleSW_now = toggleSW_pre;
tosihisa 3:844fbe607dae 217 toggleSW_scan = 0;
tosihisa 3:844fbe607dae 218 }
tosihisa 3:844fbe607dae 219 }
tosihisa 3:844fbe607dae 220 #endif
tosihisa 3:844fbe607dae 221 }
tosihisa 3:844fbe607dae 222
tosihisa 3:844fbe607dae 223 void logCheckProc()
tosihisa 3:844fbe607dae 224 {
tosihisa 3:844fbe607dae 225 if((logSW == 0) && (toggleSW_now != 0)){
tosihisa 3:844fbe607dae 226 if(csvFP != NULL){
tosihisa 3:844fbe607dae 227 fclose(csvFP);
tosihisa 3:844fbe607dae 228 csvFP = NULL;
tosihisa 3:844fbe607dae 229 if(gpsFP != NULL){
tosihisa 3:844fbe607dae 230 fclose(gpsFP);
tosihisa 3:844fbe607dae 231 gpsFP = NULL;
tosihisa 3:844fbe607dae 232 }
tosihisa 3:844fbe607dae 233 logled = 0; /* No logging */
tosihisa 3:844fbe607dae 234 logNextCount++;
tosihisa 3:844fbe607dae 235 } else {
tosihisa 3:844fbe607dae 236 char name[64];
tosihisa 3:844fbe607dae 237 sprintf(name,"/%s/ENV%05d.CSV",_USE_FS_NAME,logNextCount);
tosihisa 3:844fbe607dae 238 csvFP = fopen(name,"w+b");
tosihisa 3:844fbe607dae 239 sprintf(name,"/%s/ENV%05d.GPS",_USE_FS_NAME,logNextCount);
tosihisa 3:844fbe607dae 240 gpsFP = fopen(name,"w+b");
tosihisa 3:844fbe607dae 241 if((csvFP != NULL) && (gpsFP != NULL)){
tosihisa 3:844fbe607dae 242 logled = 1; /* logging */
tosihisa 3:844fbe607dae 243 logTickCount = 100;
tosihisa 3:844fbe607dae 244 } else {
tosihisa 3:844fbe607dae 245 if(csvFP) fclose(csvFP);
tosihisa 3:844fbe607dae 246 if(gpsFP) fclose(gpsFP);
tosihisa 3:844fbe607dae 247 logled = 0; /* Cannot start logging */
tosihisa 3:844fbe607dae 248 }
tosihisa 3:844fbe607dae 249 }
tosihisa 3:844fbe607dae 250 }
tosihisa 3:844fbe607dae 251 logSW = toggleSW_now;
tosihisa 1:83960ee4d9a2 252 }
tosihisa 1:83960ee4d9a2 253
tosihisa 1:83960ee4d9a2 254 unsigned char wbuf[1024];
tosihisa 2:f546aaa0e1d5 255 int widx = 0;
tosihisa 0:6089ae824f06 256
tosihisa 0:6089ae824f06 257 int main() {
tosihisa 0:6089ae824f06 258 int ret = 0;
tosihisa 3:844fbe607dae 259 float p, t1;
tosihisa 3:844fbe607dae 260 float h, t2;
tosihisa 0:6089ae824f06 261 int temp;
tosihisa 0:6089ae824f06 262 unsigned short CO2_val;
tosihisa 0:6089ae824f06 263 unsigned long scanCount = 0;
tosihisa 1:83960ee4d9a2 264 char c;
tosihisa 2:f546aaa0e1d5 265 unsigned long UBXCount = 0;
tosihisa 0:6089ae824f06 266
tosihisa 3:844fbe607dae 267 tick.attach_us(&tickHandler,(10*1000));
tosihisa 3:844fbe607dae 268
tosihisa 0:6089ae824f06 269 debug.format(8,Serial::None,1);
tosihisa 0:6089ae824f06 270 debug.baud(115200);
tosihisa 3:844fbe607dae 271 debug.printf("ENV Logger \"V0.7\" Start (BUILD:[" __DATE__ "/" __TIME__ "])\n");
tosihisa 0:6089ae824f06 272
tosihisa 0:6089ae824f06 273 debug.printf("LCD Display\n");
tosihisa 0:6089ae824f06 274
tosihisa 0:6089ae824f06 275 //lcd.cls();
tosihisa 0:6089ae824f06 276 lcd.locate(0,0);
tosihisa 3:844fbe607dae 277 lcd.printf("ENV Logger \"V0.7\"");
tosihisa 2:f546aaa0e1d5 278
tosihisa 2:f546aaa0e1d5 279 lcd.locate(0,1);
tosihisa 2:f546aaa0e1d5 280 lcd.printf("WAKE UP I/O...");
tosihisa 1:83960ee4d9a2 281 wait(5.0);
tosihisa 0:6089ae824f06 282
tosihisa 3:844fbe607dae 283 #ifdef HAVE_MICROSD
tosihisa 3:844fbe607dae 284 lcd.locate(0,2);
tosihisa 3:844fbe607dae 285 lcd.printf("CHECK MicroSD:");
tosihisa 3:844fbe607dae 286 logFile_Init();
tosihisa 3:844fbe607dae 287 #endif
tosihisa 3:844fbe607dae 288 lcd.locate(0,2);
tosihisa 3:844fbe607dae 289 switch(avaiableSD){
tosihisa 3:844fbe607dae 290 case 0:
tosihisa 3:844fbe607dae 291 lcd.printf("CHECK MicroSD:NG");
tosihisa 3:844fbe607dae 292 break;
tosihisa 3:844fbe607dae 293 case 1:
tosihisa 3:844fbe607dae 294 lcd.printf("CHECK MicroSD:OK");
tosihisa 3:844fbe607dae 295 break;
tosihisa 3:844fbe607dae 296 default:
tosihisa 3:844fbe607dae 297 lcd.printf("CHECK MicroSD:DO\'NT USE");
tosihisa 3:844fbe607dae 298 break;
tosihisa 3:844fbe607dae 299 }
tosihisa 3:844fbe607dae 300 wait(1.0);
tosihisa 3:844fbe607dae 301
tosihisa 0:6089ae824f06 302 //logFile_Init();
tosihisa 0:6089ae824f06 303 //FileWriteTest();
tosihisa 0:6089ae824f06 304
tosihisa 3:844fbe607dae 305 lcd.locate(0,3);
tosihisa 2:f546aaa0e1d5 306 lcd.printf("SETTING GPS...");
tosihisa 2:f546aaa0e1d5 307
tosihisa 1:83960ee4d9a2 308 UBXPacket.cjobst = 0;
tosihisa 1:83960ee4d9a2 309
tosihisa 0:6089ae824f06 310 gps_pps.rise(gps_pps_rise);
tosihisa 0:6089ae824f06 311 gps.format(8,Serial::None,1);
tosihisa 0:6089ae824f06 312 gps.baud(9600);
tosihisa 0:6089ae824f06 313
tosihisa 0:6089ae824f06 314 gps_reset = 1;
tosihisa 0:6089ae824f06 315 wait(0.5);
tosihisa 0:6089ae824f06 316 gps_reset = 0;
tosihisa 0:6089ae824f06 317
tosihisa 1:83960ee4d9a2 318 wait(0.5);
tosihisa 1:83960ee4d9a2 319 if(1){
tosihisa 1:83960ee4d9a2 320 //unsigned char modeStr[] = "PUBX,41,1,0007,0003,115200,0";
tosihisa 1:83960ee4d9a2 321 unsigned char modeStr[] = "PUBX,41,1,0007,0001,115200,0";
tosihisa 1:83960ee4d9a2 322 unsigned char sum = NMEA_CalcSum(modeStr,strlen((char *)modeStr));
tosihisa 1:83960ee4d9a2 323 debug.printf("SEND:[%s](0x%02X)\n",modeStr,sum);
tosihisa 1:83960ee4d9a2 324 gps.printf("$%s*%02X%c%c",modeStr,sum,0x0d,0x0a);
tosihisa 1:83960ee4d9a2 325
tosihisa 1:83960ee4d9a2 326 debug.printf("CHG BAUD:115200\n");
tosihisa 1:83960ee4d9a2 327 gps.format(8,Serial::None,1);
tosihisa 1:83960ee4d9a2 328 gps.baud(115200);
tosihisa 1:83960ee4d9a2 329 }
tosihisa 1:83960ee4d9a2 330
tosihisa 1:83960ee4d9a2 331 gps.recvStart();
tosihisa 1:83960ee4d9a2 332 wait(0.5);
tosihisa 0:6089ae824f06 333
tosihisa 1:83960ee4d9a2 334 if(1){
tosihisa 1:83960ee4d9a2 335 unsigned char chkStr[][11] = {
tosihisa 1:83960ee4d9a2 336 { 0xB5,0x62,0x06,0x01,0x03,0x00,0x02,0x10,0x02,0xFF,0xFF }, //RXM-RAW (0x02 0x10)
tosihisa 1:83960ee4d9a2 337 { 0xB5,0x62,0x06,0x01,0x03,0x00,0x02,0x30,0x02,0xFF,0xFF }, //RXM-ALM (0x02 0x30)
tosihisa 1:83960ee4d9a2 338 { 0xB5,0x62,0x06,0x01,0x03,0x00,0x02,0x31,0x02,0xFF,0xFF }, //RXM-EPH (0x02 0x31)
tosihisa 1:83960ee4d9a2 339 //{ 0xB5,0x62,0x06,0x01,0x03,0x00,0x02,0x41,0x02,0xFF,0xFF },
tosihisa 1:83960ee4d9a2 340 { 0xB5,0x62,0x06,0x01,0x03,0x00,0x02,0x11,0x02,0xFF,0xFF }, //RXM-SFRB (0x02 0x11)
tosihisa 1:83960ee4d9a2 341 { 0xB5,0x62,0x06,0x01,0x03,0x00,0x02,0x20,0x02,0xFF,0xFF }, //RXM-SVSI (0x02 0x20)
tosihisa 1:83960ee4d9a2 342 { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF }, //END
tosihisa 1:83960ee4d9a2 343 };
tosihisa 1:83960ee4d9a2 344 int i,j;
tosihisa 1:83960ee4d9a2 345
tosihisa 1:83960ee4d9a2 346 for(j=0;chkStr[j][0] != 0x00;j++){
tosihisa 1:83960ee4d9a2 347 UBX_CalcSum(&chkStr[j][2],7,&chkStr[j][9]);
tosihisa 1:83960ee4d9a2 348 for(i = 0; i < sizeof(chkStr[0]);i++){
tosihisa 1:83960ee4d9a2 349 gps.putc(chkStr[j][i]);
tosihisa 1:83960ee4d9a2 350 }
tosihisa 1:83960ee4d9a2 351 debug.printf("%d : SET UBX Rate : %s\n",j,(UBX_WaitAck(&UBXPacket) == 1) ? "ACK" : "NAK");
tosihisa 1:83960ee4d9a2 352 }
tosihisa 1:83960ee4d9a2 353 }
tosihisa 1:83960ee4d9a2 354 UBXPacket.cjobst = 0;
tosihisa 3:844fbe607dae 355 lcd.locate(0,3);
tosihisa 2:f546aaa0e1d5 356 lcd.printf("SETTING GPS...Done.");
tosihisa 1:83960ee4d9a2 357
tosihisa 1:83960ee4d9a2 358 // ad7994.Start();
tosihisa 1:83960ee4d9a2 359
tosihisa 0:6089ae824f06 360 CO2.format(8,Serial::None,1);
tosihisa 0:6089ae824f06 361 CO2.baud(9600);
tosihisa 0:6089ae824f06 362 CO2.recvStart();
tosihisa 0:6089ae824f06 363
tosihisa 3:844fbe607dae 364 //Clear Screen.
tosihisa 3:844fbe607dae 365 lcd.locate(0,0); lcd.printf("%20s"," ");
tosihisa 3:844fbe607dae 366 lcd.locate(0,1); lcd.printf("%20s"," ");
tosihisa 3:844fbe607dae 367 lcd.locate(0,2); lcd.printf("%20s"," ");
tosihisa 3:844fbe607dae 368 lcd.locate(0,3); lcd.printf("%20s"," ");
tosihisa 3:844fbe607dae 369
tosihisa 0:6089ae824f06 370 while(1) {
tosihisa 0:6089ae824f06 371 //lcd.cls();
tosihisa 2:f546aaa0e1d5 372 //lcd.locate(0,0);
tosihisa 2:f546aaa0e1d5 373 //lcd.printf("SCAN:%-10ld",scanCount);
tosihisa 3:844fbe607dae 374 lcd.locate(0,0);
tosihisa 3:844fbe607dae 375 lcd.printf("%d ",toggleSW_now);
tosihisa 3:844fbe607dae 376
tosihisa 3:844fbe607dae 377 logCheckProc();
tosihisa 0:6089ae824f06 378
tosihisa 0:6089ae824f06 379 while(gps.readable()) {
tosihisa 1:83960ee4d9a2 380 c = gps.getc();
tosihisa 1:83960ee4d9a2 381 if(UBXPacket_Parse(&UBXPacket,c) == 100){
tosihisa 2:f546aaa0e1d5 382 UBXCount++;
tosihisa 3:844fbe607dae 383 lcd.locate(2,0);
tosihisa 2:f546aaa0e1d5 384 lcd.printf("UBX Recv:%-10ld",UBXCount);
tosihisa 1:83960ee4d9a2 385 debug.printf("%ld : GET UBX Packet (Class=0x%02X,ID=0x%02X,LEN=%d)\n",
tosihisa 1:83960ee4d9a2 386 scanCount,
tosihisa 1:83960ee4d9a2 387 UBXPacket.cls,
tosihisa 1:83960ee4d9a2 388 UBXPacket.id,
tosihisa 1:83960ee4d9a2 389 UBXPacket.len );
tosihisa 1:83960ee4d9a2 390 UBXPacket.cjobst = 0;
tosihisa 1:83960ee4d9a2 391 }
tosihisa 3:844fbe607dae 392 if(gpsFP != NULL){
tosihisa 3:844fbe607dae 393 wbuf[widx] = c;
tosihisa 3:844fbe607dae 394 widx++;
tosihisa 3:844fbe607dae 395 if(widx >= sizeof(wbuf)){
tosihisa 3:844fbe607dae 396 fwrite(&wbuf,sizeof(wbuf[0]),widx,gpsFP);
tosihisa 3:844fbe607dae 397 widx = 0;
tosihisa 3:844fbe607dae 398 }
tosihisa 3:844fbe607dae 399 }
tosihisa 0:6089ae824f06 400 }
tosihisa 0:6089ae824f06 401
tosihisa 2:f546aaa0e1d5 402 if(1){
tosihisa 2:f546aaa0e1d5 403 bmp085.update();
tosihisa 2:f546aaa0e1d5 404 p = bmp085.get_pressure();
tosihisa 3:844fbe607dae 405 t1 = bmp085.get_temperature();
tosihisa 2:f546aaa0e1d5 406 lcd.locate(0,1);
tosihisa 3:844fbe607dae 407 lcd.printf("%-8.2fhPa %-6.2fC", p, t1);
tosihisa 2:f546aaa0e1d5 408 }
tosihisa 0:6089ae824f06 409
tosihisa 2:f546aaa0e1d5 410 if(1){
tosihisa 2:f546aaa0e1d5 411 sht25.SHT2x_MeasurePoll(TEMP,&temp);
tosihisa 3:844fbe607dae 412 t2 = sht25.SHT2x_CalcTemperatureC(temp);
tosihisa 2:f546aaa0e1d5 413 sht25.SHT2x_MeasurePoll(HUMIDITY,&temp);
tosihisa 3:844fbe607dae 414 h = sht25.SHT2x_CalcRH(temp);
tosihisa 2:f546aaa0e1d5 415 lcd.locate(0,2);
tosihisa 3:844fbe607dae 416 lcd.printf("%-6.2fC %-6.2fRH", t2, h);
tosihisa 2:f546aaa0e1d5 417 //sht25.SHT2x_SoftReset();
tosihisa 2:f546aaa0e1d5 418 }
tosihisa 1:83960ee4d9a2 419
tosihisa 1:83960ee4d9a2 420 #ifdef _I2C_TEST /* { */
tosihisa 1:83960ee4d9a2 421 i2c_found();
tosihisa 1:83960ee4d9a2 422 #endif /* } */
tosihisa 0:6089ae824f06 423
tosihisa 2:f546aaa0e1d5 424 lcd.locate(0,3);
tosihisa 1:83960ee4d9a2 425 ret = CO2_Read(&CO2_val);
tosihisa 1:83960ee4d9a2 426 if(ret == 0){
tosihisa 2:f546aaa0e1d5 427 lcd.printf("CO2:%5d.%1dppm\n",CO2_val/10,CO2_val%10);
tosihisa 0:6089ae824f06 428 } else {
tosihisa 1:83960ee4d9a2 429 lcd.printf("CO2:NG(%d) \n",ret);
tosihisa 0:6089ae824f06 430 }
tosihisa 1:83960ee4d9a2 431
tosihisa 3:844fbe607dae 432 if(csvFP){
tosihisa 3:844fbe607dae 433 if(logTickCount >= 100){
tosihisa 3:844fbe607dae 434 fprintf(csvFP,"%-8.2f,hPa,%-6.2f,C,%-6.2f,C,%-6.2f,RH,%5d.%1d,ppm\x0d\x0a", p, t1, t2, h,CO2_val/10,CO2_val%10);
tosihisa 3:844fbe607dae 435 logTickCount = 0;
tosihisa 3:844fbe607dae 436 }
tosihisa 3:844fbe607dae 437 }
tosihisa 3:844fbe607dae 438
tosihisa 1:83960ee4d9a2 439 #if 0
tosihisa 0:6089ae824f06 440 ad7994.update();
tosihisa 0:6089ae824f06 441 lcd.locate(0,3);
tosihisa 0:6089ae824f06 442 lcd.printf("A/D:%04X/%04X",
tosihisa 0:6089ae824f06 443 ad7994.readChn(0),
tosihisa 0:6089ae824f06 444 ad7994.readChn(1));
tosihisa 1:83960ee4d9a2 445 #endif
tosihisa 3:844fbe607dae 446 myled = (hzCount & 1);
tosihisa 0:6089ae824f06 447 scanCount++;
tosihisa 3:844fbe607dae 448 wait(0.1);
tosihisa 0:6089ae824f06 449 }
tosihisa 0:6089ae824f06 450 }
tosihisa 2:f546aaa0e1d5 451
tosihisa 2:f546aaa0e1d5 452 /*
tosihisa 3:844fbe607dae 453 * 2012-1-29 V0.7
tosihisa 3:844fbe607dae 454 * ログ機能の追加。スイッチを押すとログのON/OFFが出来る。
tosihisa 3:844fbe607dae 455 * ログ収集中は、mbed LED3 が点灯する。
tosihisa 3:844fbe607dae 456 */
tosihisa 3:844fbe607dae 457 /*
tosihisa 3:844fbe607dae 458 * 2012-1-29 V0.6
tosihisa 3:844fbe607dae 459 * 1) スキャンカウントの変更。今までは1秒周期だったが、
tosihisa 3:844fbe607dae 460 * 100ミリ秒周期でセンサーデータを得るようにした。
tosihisa 3:844fbe607dae 461 * 2) モーメンタリSW対応。
tosihisa 3:844fbe607dae 462 */
tosihisa 3:844fbe607dae 463 /*
tosihisa 2:f546aaa0e1d5 464 * 2012-1-23 V0.5
tosihisa 2:f546aaa0e1d5 465 * U-Blox,気圧センサー,温度センサー,CO2センサーの値を表示するようにした。
tosihisa 2:f546aaa0e1d5 466 * U-Blox は受信できたパケット数を表示する。
tosihisa 2:f546aaa0e1d5 467 * マイクロSDへの保存機能はまだ(H/W的に動くのは確認済み)
tosihisa 2:f546aaa0e1d5 468 */