--- trunk/Embedded/main.c 2007/12/06 13:36:07 175 +++ trunk/Embedded/main.c 2007/12/09 15:07:32 201 @@ -6,10 +6,7 @@ #include "lcd.h" #include "Delay.h" -// Delay.h is included inside lcd.c -#define LCD_LENGTH 16 -#define LCD_ROWS 2 #define BUFFER 128 #define PWRFAIL RB1 #define FIREDET RB2 @@ -33,7 +30,7 @@ unsigned char global_lcd_buf[16]; -unsigned short global_imei_tversum; +unsigned int global_imei_tversum; unsigned char global_cell_nr[15] = ""; // = "21681784"; bit global_modem_init = 0; @@ -154,7 +151,7 @@ RCSTA = 0x90; // 0x90 enables SPEN and CREN in the RCSTA register } -void sms_init(void) +void modem_init(void) { int i; char buf[2]; @@ -183,7 +180,7 @@ sprintf(global_serial_send,"%s", "at+cpin?\r"); serial_send(); - DelayMs(100); // To give the modem a chance to answer. + DelayMs(100); // Delay to give the modem a chance to answer. if (strstr(global_message_buffer1, "+CPIN: SIM PIN") != 0) { @@ -217,7 +214,28 @@ DelayMs(150); global_serial_send[0] = 0; DelayMs(150); -} +} + +void on_initial_recieve(void) +{ + char imei[16]; + char* ptr; + char i; + char buf[2]; + + if (strstr(global_serial_recieve_buffer,"+WIND: 11") != 0) + { + global_modem_init = 1; + + ptr = strstr(global_serial_recieve_buffer,"cgsn"); + ptr +=4; + strncpy(imei, ptr,15); + imei[15] = 0; + + reset_recieve_buffer(); + } +} + ////////// INTERRUPT HANDLER ////////// void interrupt interrupt_handler(void) { @@ -319,7 +337,7 @@ sprintf(global_serial_send, "%s%c", payload, 0x1A); serial_send(); DelayMs(150); - if(global_sms_counter % 3 == 0) + if(global_sms_counter % 4 == 0) { eeprom_writer(); sprintf(global_serial_send, "at+cmgd=1,3\r"); @@ -328,7 +346,7 @@ } } -void convertTemp() +void convert_temp() { short adVal; adVal = (global_Pot_Hi << 8) | global_Pot_Lo; @@ -373,25 +391,6 @@ global_cell_nr[i] = 0; //zero terminated! } -void on_initial_recieve(void) -{ - char imei[16]; - char* ptr; - char i; - char buf[2]; - - if (strstr(global_serial_recieve_buffer,"+WIND: 11") != 0) - { - global_modem_init = 1; - - ptr = strstr(global_serial_recieve_buffer,"cgsn"); - ptr +=4; - strncpy(imei, ptr,15); - imei[15] = 0; - - reset_recieve_buffer(); - } -} void on_recieve(void) { @@ -405,9 +404,9 @@ if (strstr(global_message_buffer1,"CMTI") != 0) // here we handles a incomming SMS { ptr = strstr(global_message_buffer1,","); // finds the point just before the nr. of the SMS. - strcat(tmp,ptr+1); // puts that number in tmp - global_sms_recieve_number[0] = 0; // wanna be sure that we write the new number from global_sms_recieve_number[0] - strcat(global_sms_recieve_number, tmp); // puts the sms number into the global variable. + strcat(tmp,ptr+1); // puts that number in tmp + global_sms_recieve_number[0] = 0; // wanna be sure that we write the new number from global_sms_recieve_number[0] + strcat(global_sms_recieve_number, tmp); // puts the sms number into the global variable. sms_recieved(); } reset_recieve_buffer(); @@ -455,7 +454,7 @@ global_time_interval = atoi(buf); global_time_interval *= 60; - eeprom_writer(); // writes the new cell nr. and time interval to the eeprom. + eeprom_writer(); // writes the new cell nr. and time interval to the eeprom. send_sms("conf ok"); } @@ -476,7 +475,7 @@ // Running init for various components. pic18_io_init(); - RA5 = 1; // Indicates that the board is running inits. + RA5 = 1; // Indicates that the board is running inits. rs232_init(); ad_init(); @@ -485,7 +484,7 @@ lcd_home(); interrupt_init(); timer_init(); - sms_init(); + modem_init(); eeprom_reader(); /////////////// // Main loop // @@ -525,7 +524,7 @@ { global_Pot_Hi = ADRESH; global_Pot_Lo = ADRESL; - convertTemp(); + convert_temp(); update_lcd(); GODONE = 1; }