// ---------------------------------------------------------------------------------------------------- // Watchdog v3 - Leonardo // EoF 2017 // Header // ---------------------------------------------------------------------------------------------------- #include #include #include "GPRS_Shield_Arduino.h" #include /* * EEPROM mapping * 1024 Kb * 10 x 16 = 160 - address book | first addr 0 * 16 x 1 = 16 - parameters | first addr 160 * ------------- * 176 bytes * 848 bytes free */ #define AB_ADDR 0 #define AB_MAX_INDEX 9 #define PARAM_ADDR 160 #define PARAM_MAX_INDEX 15 #define SMS_ON_INDEX 0 #define AUTH_ON_INDEX 1 #define FWD_ON_INDEX 2 #define EEPROM_INIT_INDEX 15 #define INIT_FLAG 0xAC const char cmd_status[] PROGMEM = {"status"}; const char cmd_help[] PROGMEM = {"help"}; const char cmd_sms_on[] PROGMEM = {"sms on"}; const char cmd_sms_off[] PROGMEM = {"sms off"}; const char cmd_on[] PROGMEM = {"on"}; const char cmd_off[] PROGMEM = {"off"}; const char cmd_reset[] PROGMEM = {"reset"}; const char cmd_a[] PROGMEM = {"a"}; const char cmd_b[] PROGMEM = {"b"}; const char cmd_forward[] PROGMEM = {"forward"}; const char cmd_modem_reset[] PROGMEM = {"modem reset"}; const char cmd_modem_console[] PROGMEM = {"modem console"}; const char cmd_edit_ab[] PROGMEM = {"edit ab"}; const char cmd_show_ab[] PROGMEM = {"show ab"}; const char cmd_show[] PROGMEM = {"show"}; const char cmd_clear[] PROGMEM = {"clear"}; const char cmd_exit[] PROGMEM = {"exit"}; const char cmd_auth_on[] PROGMEM = {"auth on"}; const char cmd_auth_off[] PROGMEM = {"auth off"}; const char cmd_fwd_on[] PROGMEM = {"forward on"}; const char cmd_fwd_off[] PROGMEM = {"forward off"}; const char str_init_eeprom[] PROGMEM = {"EEPROM init complete"}; const char str_eab[] PROGMEM = {"Edit address book mode"}; const char str_modem_cons_on[] PROGMEM = {"Modem console mode on"}; const char str_modem_cons_off[] PROGMEM = {"Modem console mode off"}; const char str_help[] PROGMEM = {"Usage: help/status/on/off/reset/a/b/modem reset|console/edit ab/show ab/sms on|off/auth on|off/fwd on|off"}; const char str_help_ab[] PROGMEM = {"Type \"show\" to view, \"clear\" to erase, \"exit\" to return"}; const char str_format_ab[] PROGMEM = {"Format: \"i:+xxxxxxxxxxx\" to update or \"i:delete\" to delete"}; // Всякое #define TIMEOUT 60000 #define PERIOD 15000 #define MAX_ERROR 5 #define CALL_TIMEOUT 60000 #define BTN_COUNT 3 // Сенсоры #define A_PIN A0 #define T_PIN A1 #define VOUT_PIN A2 #define VBAT_PIN A3 #define V5_PIN A4 #define V12_PIN A5 #define LED_PIN 13 #define BTN_PIN 12 #define FAN_PIN 11 // GSM-модем #define MOD_PWR 9 #define MOD_BR 115200 #define COM_BR 115200 #define SMS_LEN 160 // Размеры буферов; #define CMD_SIZE 16 #define SMS_SIZE 160 #define PHONE_SIZE 16 #define DATE_SIZE 24 #define BUFFER_SIZE 64 #define LONG_BUFFER_SIZE 240 // Флаги статуса #define TEMP_WARN 0x01 #define HUM_WARN 0x02 #define LOUD_WARN 0x04 #define POWER_WARN 0x08 #define BAT_WARN 0x016 word getStatus(); void getStatusMessage(char * message); bool isCommandMatchIndex(const char * command, byte index); void checkModem(); void modemConsole(); void incomingCall(); void readModem(char* msg, byte size); void readSerial(char *com, byte size); void returnAnswer(const char * answer = "OK"); void sendHelp(); void mainPowerOn(); void mainPowerOff(); void mainReset(); void a_PowerBreak(); void b_PowerBreak(); bool isPowerOn(); // Адресная книга bool savePhoneNumber(byte index, char * phone); bool delPhoneNumber(byte index); bool loadPhoneNumber(byte index, char * phone); bool entryNotEmpty(byte index); void printPhoneNumber(byte index); void printAddressBook(); void clearAddressBook(); void editAddressBook(); // Утилиты void clearBuffer(char *buffer, byte size); void printShortString(byte index, bool ln = true); void printLongString(byte index, bool ln = true); void printHelp(); void printParams(); bool authOK(char *phone); void sprint(const char *description, const byte data, const bool ln = true); void sprint(const char *description, const char *data, const bool ln = true); void sprint(const char *description, const int data, const bool ln = true); void sprint(const char *description, const unsigned int data, const bool ln = true); void sprint(const char *description, const long int data, const bool ln = true); void sprint(const char *description, const long unsigned int data, const bool ln = true); void sprint(const char *description, const float data, const bool ln = true); void sprint(const char *description, const bool ln = true); void sprint_P(const char *description, const bool ln = true); bool smsOn(); void smsOn(bool temp); bool authOn(); void authOn(bool temp); bool fwdOn(); void fwdOn(bool temp); void fanPWM(byte power = 128); void fanOn(); void fanOff(); void ledPWM(byte power = 128); void ledOn(); void ledOff(); void flash(byte count = 3); bool buttonPressed(); float readvcc(); void getVs(); void printVs(); void getTH(); void initEEPROM();