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 |
|
|
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]; |
31 |
unsigned char global_message_buffer_length1; |
unsigned char global_message_buffer_length1; |
52 |
void on_recieve(void); |
void on_recieve(void); |
53 |
void on_initial_recieve(void); |
void on_initial_recieve(void); |
54 |
void sms_recieved(void); |
void sms_recieved(void); |
55 |
void send_sms(unsigned char* payload); |
void send_sms(const unsigned char* payload); |
56 |
|
|
57 |
|
|
58 |
void reset_recieve_buffer(void) |
void reset_recieve_buffer(void) |
220 |
while(TRMT==0) ; |
while(TRMT==0) ; |
221 |
DelayMs(10); |
DelayMs(10); |
222 |
} |
} |
223 |
DelayMs(250); |
DelayMs(150); |
224 |
global_serial_send[0] = 0; |
global_serial_send[0] = 0; |
225 |
DelayMs(250); |
DelayMs(150); |
226 |
} |
} |
227 |
|
|
228 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
230 |
// global_serial_recieve_buffer, to global_message_buffer1, and sets the flag global_recieve_done. |
// global_serial_recieve_buffer, to global_message_buffer1, and sets the flag global_recieve_done. |
231 |
void serial_recieved(void) |
void serial_recieved(void) |
232 |
{ |
{ |
233 |
char data_byte, saved_data[LCD_LENGTH]; |
char data_byte; |
234 |
|
|
235 |
data_byte = RCREG; |
data_byte = RCREG; |
236 |
|
|
240 |
if (global_serial_byte_counter == 0 && data_byte == '\r') // don't care about '\r', if it's the first byte we recieve. |
if (global_serial_byte_counter == 0 && data_byte == '\r') // don't care about '\r', if it's the first byte we recieve. |
241 |
return; |
return; |
242 |
|
|
|
// if (global_serial_byte_counter == BUFFER -1) |
|
|
// global_seriaæl_recieve_buffer[global_serial_byte_counter] = 0; |
|
243 |
|
|
244 |
// if (data_byte != '\r' && (global_serial_byte_counter-1) < BUFFER) |
if ( global_serial_byte_counter < BUFFER) //Prevent buffer overrun |
245 |
// 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. |
246 |
global_serial_recieve_buffer[ global_serial_byte_counter] = data_byte; |
|
247 |
|
|
248 |
|
|
249 |
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 |
265 |
|
|
266 |
global_serial_byte_counter = 0; |
global_serial_byte_counter = 0; |
267 |
} |
} |
|
else |
|
|
{ |
|
|
global_serial_byte_counter++; |
|
|
} |
|
|
|
|
268 |
} |
} |
269 |
|
|
270 |
void timer1_interrupt(void) |
void timer1_interrupt(void) |
278 |
|
|
279 |
void update_lcd(void) |
void update_lcd(void) |
280 |
{ |
{ |
281 |
lcd_clear(); |
if(global_temp_update_display != global_time_counter) |
282 |
lcd_goto(0x00); |
{ |
283 |
|
lcd_clear(); |
284 |
|
lcd_goto(0x00); |
285 |
|
|
286 |
sprintf(global_lcd_buf, "Temp: %d", global_temp); |
sprintf(global_lcd_buf, "Temp: %3d", global_temp); |
287 |
lcd_puts(global_lcd_buf); |
lcd_puts(global_lcd_buf); |
288 |
|
global_temp_update_display = global_time_counter; |
289 |
|
} |
290 |
|
|
291 |
} |
} |
292 |
|
|
299 |
global_sms_counter++; |
global_sms_counter++; |
300 |
} |
} |
301 |
|
|
302 |
void send_sms(unsigned char* payload) |
void send_sms(const unsigned char* payload) |
303 |
{ |
{ |
304 |
sprintf(global_serial_send, "at+cmgs=\"%s\"\r", global_cell_nr); |
sprintf(global_serial_send, "at+cmgs=\"%s\"\r", global_cell_nr); |
305 |
serial_send(); |
serial_send(); |
306 |
sprintf(global_serial_send, "%s%c", payload, 0x1A); |
sprintf(global_serial_send, "%s%c", payload, 0x1A); |
307 |
serial_send(); |
serial_send(); |
308 |
DelayMs(250); |
DelayMs(150); |
309 |
|
|
310 |
} |
} |
311 |
|
|