Mercurial > templog
comparison main.c @ 81:4a2a82d6302c
try and be a bit more frugal with stack
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 11 Jul 2012 00:22:31 +0800 |
parents | 1e2068c5413a |
children | b9179968a272 |
comparison
equal
deleted
inserted
replaced
80:1e2068c5413a | 81:4a2a82d6302c |
---|---|
279 | 279 |
280 static void | 280 static void |
281 cmd_fetch() | 281 cmd_fetch() |
282 { | 282 { |
283 crc_out = 0; | 283 crc_out = 0; |
284 uint16_t millivolt_vcc = adc_vcc(); | 284 |
285 | 285 fprintf_P(crc_stdout, PSTR("START\n")); |
286 uint32_t epoch_copy; | 286 { |
287 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) | 287 uint32_t epoch_copy; |
288 { | 288 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) |
289 epoch_copy = clock_epoch; | 289 { |
290 } | 290 epoch_copy = clock_epoch; |
291 | 291 } |
292 fprintf_P(crc_stdout, PSTR("START\n" | 292 fprintf_P(crc_stdout, PSTR("now=%lu\n"), epoch_copy); |
293 "now=%lu\n" | 293 } |
294 "time_step=%hu\n" | 294 fprintf_P(crc_stdout, PSTR("time_step=%hu\n"), measure_wake); |
295 "first_time=%lu\n" | 295 fprintf_P(crc_stdout, PSTR("first_time=%lu\n"), first_measurement_clock); |
296 "last_time=%lu\n" | 296 fprintf_P(crc_stdout, PSTR("last_time=%lu\n"), last_measurement_clock); |
297 "comms_time=%lu\n" | 297 fprintf_P(crc_stdout, PSTR("comms_time=%lu\n"), last_comms_clock); |
298 "voltage=%hu\n" | 298 fprintf_P(crc_stdout, PSTR("voltage=%hu\n"), adc_vcc()); |
299 ), | 299 fprintf_P(crc_stdout, PSTR("sensors=%hhu\n"), n_sensors); |
300 epoch_copy, | |
301 measure_wake, | |
302 first_measurement_clock, | |
303 last_measurement_clock, | |
304 last_comms_clock, | |
305 millivolt_vcc | |
306 ); | |
307 fprintf_P(crc_stdout, PSTR("sensors=%u\n"), n_sensors); | |
308 for (uint8_t s = 0; s < n_sensors; s++) | 300 for (uint8_t s = 0; s < n_sensors; s++) |
309 { | 301 { |
310 fprintf_P(crc_stdout, PSTR("sensor_id%u="), s); | 302 fprintf_P(crc_stdout, PSTR("sensor_id%hhu="), s); |
311 printhex(sensor_id[s], ID_LEN, crc_stdout); | 303 printhex(sensor_id[s], ID_LEN, crc_stdout); |
312 fputc('\n', crc_stdout); | 304 fputc('\n', crc_stdout); |
313 } | 305 } |
314 fprintf_P(crc_stdout, PSTR("measurements=%hu\n"), n_measurements); | 306 fprintf_P(crc_stdout, PSTR("measurements=%hu\n"), n_measurements); |
315 for (uint16_t n = 0; n < n_measurements; n++) | 307 for (uint16_t n = 0; n < n_measurements; n++) |
363 | 355 |
364 static void | 356 static void |
365 cmd_sensors() | 357 cmd_sensors() |
366 { | 358 { |
367 uint8_t ret = simple_ds18b20_start_meas(NULL); | 359 uint8_t ret = simple_ds18b20_start_meas(NULL); |
368 printf_P(PSTR("All sensors, ret %d, waiting...\n"), ret); | 360 printf_P(PSTR("All sensors, ret %hhu, waiting...\n"), ret); |
369 long_delay(DS18B20_TCONV_12BIT); | 361 long_delay(DS18B20_TCONV_12BIT); |
370 simple_ds18b20_read_all(); | 362 simple_ds18b20_read_all(); |
371 } | 363 } |
372 | 364 |
373 static void | 365 static void |
390 } | 382 } |
391 | 383 |
392 if (n_sensors < MAX_SENSORS) | 384 if (n_sensors < MAX_SENSORS) |
393 { | 385 { |
394 memcpy(sensor_id[n_sensors], id, ID_LEN); | 386 memcpy(sensor_id[n_sensors], id, ID_LEN); |
395 printf_P(PSTR("Added sensor %d : "), n_sensors); | 387 printf_P(PSTR("Added sensor %hhu : "), n_sensors); |
396 printhex(id, ID_LEN, stdout); | 388 printhex(id, ID_LEN, stdout); |
397 putchar('\n'); | 389 putchar('\n'); |
398 n_sensors++; | 390 n_sensors++; |
399 } | 391 } |
400 else | 392 else |
420 } | 412 } |
421 | 413 |
422 static void | 414 static void |
423 cmd_get_params() | 415 cmd_get_params() |
424 { | 416 { |
425 printf_P(PSTR("measure %hu comms %hu wake %u tick %d sensors %u (%u) meas %hu (%hu)\n"), | 417 printf_P(PSTR("measure %hu\n"), measure_wake); |
426 measure_wake, comms_wake, wake_secs, TICK, | 418 printf_P(PSTR("comms %hu\n"), comms_wake); |
427 n_sensors, MAX_SENSORS, | 419 printf_P(PSTR("wake %hhu\n"), wake_secs); |
420 printf_P(PSTR("tick %d\n"), TICK); | |
421 printf_P(PSTR("sensors %hhu (%hhu)\n"), | |
422 n_sensors, MAX_SENSORS); | |
423 printf_P(PSTR("meas %hu (%hu)\n"), | |
428 max_measurements, TOTAL_MEASUREMENTS); | 424 max_measurements, TOTAL_MEASUREMENTS); |
429 } | 425 } |
430 | 426 |
431 static void | 427 static void |
432 cmd_set_params(const char *params) | 428 cmd_set_params(const char *params) |
433 { | 429 { |
434 uint16_t new_measure_wake; | 430 uint16_t new_measure_wake; |
435 uint16_t new_comms_wake; | 431 uint16_t new_comms_wake; |
436 uint8_t new_wake_secs; | 432 uint8_t new_wake_secs; |
437 int ret = sscanf_P(params, PSTR("%hu %hu %u"), | 433 int ret = sscanf_P(params, PSTR("%hu %hu %hhu"), |
438 &new_measure_wake, &new_comms_wake, &new_wake_secs); | 434 &new_measure_wake, &new_comms_wake, &new_wake_secs); |
439 | 435 |
440 if (ret != 3) | 436 if (ret != 3) |
441 { | 437 { |
442 printf_P(PSTR("Bad values\n")); | 438 printf_P(PSTR("Bad values\n")); |
449 eeprom_write(new_wake_secs, wake_secs); | 445 eeprom_write(new_wake_secs, wake_secs); |
450 uint16_t magic = EXPECT_MAGIC; | 446 uint16_t magic = EXPECT_MAGIC; |
451 eeprom_write(magic, magic); | 447 eeprom_write(magic, magic); |
452 sei(); | 448 sei(); |
453 printf_P(PSTR("set_params for next boot\n")); | 449 printf_P(PSTR("set_params for next boot\n")); |
454 printf_P(PSTR("measure %hu comms %hu wake %u\n"), | 450 printf_P(PSTR("measure %hu comms %hu wake %hhu\n"), |
455 new_measure_wake, new_comms_wake, new_wake_secs); | 451 new_measure_wake, new_comms_wake, new_wake_secs); |
456 } | 452 } |
457 } | 453 } |
458 | 454 |
459 static void | 455 static void |