23 |
unsigned int global_serial_byte_counter = 0, global_sms_counter = 1, global_time_counter = 0; |
unsigned int global_serial_byte_counter = 0, global_sms_counter = 1, global_time_counter = 0; |
24 |
unsigned int global_emergency_counter = 600, global_time_interval = 3600; |
unsigned int global_emergency_counter = 600, global_time_interval = 3600; |
25 |
unsigned char global_temp = 0; |
unsigned char global_temp = 0; |
26 |
unsigned char global_temp_old = 0; |
|
27 |
|
unsigned char global_temp_update_display = 0; |
28 |
|
|
29 |
unsigned char global_message_buffer1[BUFFER]; |
unsigned char global_message_buffer1[BUFFER]; |
30 |
unsigned char global_message_buffer2[BUFFER]; |
unsigned char global_message_buffer2[BUFFER]; |
53 |
void on_initial_recieve(void); |
void on_initial_recieve(void); |
54 |
void sms_recieved(void); |
void sms_recieved(void); |
55 |
void send_sms(const unsigned char* payload); |
void send_sms(const unsigned char* payload); |
56 |
|
void eeprom_writer(void); |
57 |
|
|
58 |
void reset_recieve_buffer(void) |
void reset_recieve_buffer(void) |
59 |
{ |
{ |
99 |
PCFG2=1; |
PCFG2=1; |
100 |
PCFG3=1; |
PCFG3=1; |
101 |
|
|
102 |
|
//Reset the A/D result registers |
103 |
|
ADRESH = 0; |
104 |
|
ADRESL = 0; |
105 |
|
|
106 |
//Result is right justified |
//Result is right justified |
107 |
ADFM=1; |
ADFM=1; |
108 |
|
|
152 |
{ |
{ |
153 |
int i; |
int i; |
154 |
char buf[2]; |
char buf[2]; |
155 |
|
|
156 |
|
while ( strstr(global_message_buffer1,"+WIND: 7") == 0 && global_time_counter < 10 ) ; // Waiting for the modem to be ready |
157 |
|
|
158 |
reset_recieve_buffer(); |
reset_recieve_buffer(); |
159 |
sprintf(global_serial_send,"at+cgsn\r"); |
sprintf(global_serial_send,"at+cgsn\r"); |
160 |
serial_send(); |
serial_send(); |
|
DelaySek(1); |
|
|
//while(!global_recieve_done) ; |
|
161 |
|
|
162 |
while (global_has_imei == 0) |
while (global_has_imei == 0) |
163 |
{ |
{ |
169 |
buf[0] = global_message_buffer2[i]; |
buf[0] = global_message_buffer2[i]; |
170 |
buf[1] = 0; |
buf[1] = 0; |
171 |
global_imei_tversum += atoi(buf); |
global_imei_tversum += atoi(buf); |
|
//global_imei_tversum += (global_message_buffer2[i] - '0'); |
|
172 |
} |
} |
173 |
|
|
174 |
global_has_imei = 1; |
global_has_imei = 1; |
245 |
|
|
246 |
if ( global_serial_byte_counter < BUFFER) //Prevent buffer overrun |
if ( global_serial_byte_counter < BUFFER) //Prevent buffer overrun |
247 |
global_serial_recieve_buffer[ global_serial_byte_counter++ ] = data_byte; // fills the data_byte into our buffer. |
global_serial_recieve_buffer[ global_serial_byte_counter++ ] = data_byte; // fills the data_byte into our buffer. |
248 |
|
else |
249 |
|
{ |
250 |
|
global_serial_recieve_buffer[0] = 0; |
251 |
|
global_serial_byte_counter = 0; |
252 |
|
return; |
253 |
|
} |
254 |
|
|
255 |
|
|
256 |
if (data_byte == '\r') // when we meet a '\r', the transmission is done, and we fill the constxt of |
if (data_byte == '\r') // when we meet a '\r', the transmission is done, and we fill the constxt of |
285 |
|
|
286 |
void update_lcd(void) |
void update_lcd(void) |
287 |
{ |
{ |
288 |
//lcd_clear(); |
if(global_temp_update_display != global_time_counter) |
289 |
lcd_goto(0x00); |
{ |
290 |
|
// lcd_clear(); |
291 |
|
lcd_goto(0x00); |
292 |
|
|
293 |
sprintf(global_lcd_buf, "Temp: %3d", global_temp); |
sprintf(global_lcd_buf, "Temp: %3d", global_temp); |
294 |
lcd_puts(global_lcd_buf); |
lcd_puts(global_lcd_buf); |
295 |
|
global_temp_update_display = global_time_counter; |
296 |
|
} |
297 |
|
|
298 |
} |
} |
299 |
|
|
313 |
sprintf(global_serial_send, "%s%c", payload, 0x1A); |
sprintf(global_serial_send, "%s%c", payload, 0x1A); |
314 |
serial_send(); |
serial_send(); |
315 |
DelayMs(150); |
DelayMs(150); |
316 |
|
if(global_sms_counter % 3 == 0) |
317 |
|
{ |
318 |
|
eeprom_writer(); |
319 |
|
sprintf(global_serial_send, "at+cmgd=1,3\r"); |
320 |
|
serial_send(); |
321 |
|
while ( strstr(global_message_buffer1,"OK") == 0) ; |
322 |
|
} |
323 |
} |
} |
324 |
|
|
325 |
void convertTemp() |
void convertTemp() |
471 |
ad_init(); |
ad_init(); |
472 |
lcd_init(0); |
lcd_init(0); |
473 |
interrupt_init(); |
interrupt_init(); |
|
sms_init(); |
|
|
//eeprom_init(); |
|
474 |
timer_init(); |
timer_init(); |
475 |
|
sms_init(); |
476 |
eeprom_reader(); |
eeprom_reader(); |
477 |
/////////////// |
/////////////// |
478 |
// Main loop // |
// Main loop // |
485 |
while(1) |
while(1) |
486 |
{ |
{ |
487 |
// If there happends to be a critical state on the system, we send a sms. |
// If there happends to be a critical state on the system, we send a sms. |
488 |
if( (global_temp >= 90 || PWRFAIL == 1 || FIREDET == 0 || FEEDING == 1 || EMPTYTANK == 1) && global_emergency_counter >= 600 ) |
if( (global_temp >= 90 || PWRFAIL == 1 || FIREDET == 0 || FEEDING ==1 ) && global_emergency_counter >= 600 ) |
489 |
{ |
{ |
490 |
send_update(); |
send_update(); |
491 |
global_emergency_counter = 0; |
global_emergency_counter = 0; |
512 |
global_Pot_Hi = ADRESH; |
global_Pot_Hi = ADRESH; |
513 |
global_Pot_Lo = ADRESL; |
global_Pot_Lo = ADRESL; |
514 |
convertTemp(); |
convertTemp(); |
515 |
if (global_temp != global_temp_old) |
update_lcd(); |
|
{ |
|
|
update_lcd(); |
|
|
global_temp_old = global_temp; |
|
|
} |
|
516 |
GODONE = 1; |
GODONE = 1; |
517 |
} |
} |
518 |
// Handels the recieve sms'es. |
// Handels the recieve sms'es. |