comparison main.c @ 114:b0ec7b783c0b

start of fridge bits
author Matt Johnston <matt@ucc.asn.au>
date Wed, 03 Oct 2012 12:04:36 +0000
parents 2ba9065e7c4f
children 90d1ebb941ab
comparison
equal deleted inserted replaced
106:5c8404549cc0 114:b0ec7b783c0b
66 // be a multiple of TICK (6 seconds probably) 66 // be a multiple of TICK (6 seconds probably)
67 static uint16_t measure_wake = 138; // not a divisor of comms_wake 67 static uint16_t measure_wake = 138; // not a divisor of comms_wake
68 static uint16_t comms_wake = 3600; 68 static uint16_t comms_wake = 3600;
69 static uint8_t wake_secs = 30; 69 static uint8_t wake_secs = 30;
70 70
71
71 // ---- Atomic guards required accessing these variables 72 // ---- Atomic guards required accessing these variables
72 static uint32_t clock_epoch; 73 static uint32_t clock_epoch;
73 static uint16_t comms_count; 74 static uint16_t comms_count;
74 static uint16_t measure_count; 75 static uint16_t measure_count;
76 // decidegrees
77 static uint16_t fridge_temp = 175;
75 // ---- End atomic guards required 78 // ---- End atomic guards required
76 79
77 static uint16_t n_measurements; 80 static uint16_t n_measurements;
78 81
79 // calculated at startup as TOTAL_MEASUREMENTS/n_sensors 82 // calculated at startup as TOTAL_MEASUREMENTS/n_sensors
127 #define eeprom_write(src, eeprom_field) { eeprom_write_from(&src, eeprom_field, sizeof(src)); } 130 #define eeprom_write(src, eeprom_field) { eeprom_write_from(&src, eeprom_field, sizeof(src)); }
128 131
129 #define EXPECT_MAGIC 0x67c9 132 #define EXPECT_MAGIC 0x67c9
130 133
131 struct __attribute__ ((__packed__)) __eeprom_data { 134 struct __attribute__ ((__packed__)) __eeprom_data {
132 // XXX eeprom unused at present
133 uint16_t magic; 135 uint16_t magic;
134 uint16_t measure_wake; 136 uint16_t measure_wake;
135 uint16_t comms_wake; 137 uint16_t comms_wake;
136 uint8_t wake_secs; 138 uint8_t wake_secs;
139
140 uint16_t fridge_temp;
141
142
137 }; 143 };
138 144
139 static void deep_sleep(); 145 static void deep_sleep();
140 146
141 // Very first setup 147 // Very first setup
479 sei(); 485 sei();
480 printf_P(PSTR("set_params for next boot\n")); 486 printf_P(PSTR("set_params for next boot\n"));
481 printf_P(PSTR("measure %hu comms %hu wake %hhu\n"), 487 printf_P(PSTR("measure %hu comms %hu wake %hhu\n"),
482 new_measure_wake, new_comms_wake, new_wake_secs); 488 new_measure_wake, new_comms_wake, new_wake_secs);
483 } 489 }
490 }static void
491 cmd_set_fridge(const char *params)
492 {
493 uint16_t new_measure_wake;
494 uint16_t new_comms_wake;
495 uint8_t new_wake_secs;
496 int ret = sscanf_P(params, PSTR("%hu %hu %hhu"),
497 &new_measure_wake, &new_comms_wake, &new_wake_secs);
498
499 if (ret != 3)
500 {
501 printf_P(PSTR("Bad values\n"));
502 }
503 else
504 {
505 cli();
506 eeprom_write(new_measure_wake, measure_wake);
507 eeprom_write(new_comms_wake, comms_wake);
508 eeprom_write(new_wake_secs, wake_secs);
509 uint16_t magic = EXPECT_MAGIC;
510 eeprom_write(magic, magic);
511 sei();
512 printf_P(PSTR("set_params for next boot\n"));
513 printf_P(PSTR("measure %hu comms %hu wake %hhu\n"),
514 new_measure_wake, new_comms_wake, new_wake_secs);
515 }
484 } 516 }
485 517
486 static void 518 static void
487 cmd_awake() 519 cmd_awake()
488 { 520 {
518 cmd_get_params(); 550 cmd_get_params();
519 } 551 }
520 else if (strncmp_P(readbuf, PSTR("set_params "), 11) == 0) 552 else if (strncmp_P(readbuf, PSTR("set_params "), 11) == 0)
521 { 553 {
522 cmd_set_params(&readbuf[11]); 554 cmd_set_params(&readbuf[11]);
555 }
556 else if (strncmp_P(readbuf, PSTR("set_fridge "), 11) == 0)
557 {
558 cmd_set_fridge(&readbuf[11]);
523 } 559 }
524 else if (strcmp_P(readbuf, PSTR("awake")) == 0) 560 else if (strcmp_P(readbuf, PSTR("awake")) == 0)
525 { 561 {
526 cmd_awake(); 562 cmd_awake();
527 } 563 }