192 lines
4.9 KiB
C
192 lines
4.9 KiB
C
// ----------------------------------------------------------------------------------------------------
|
|
// Watchdog v3 - Leonardo
|
|
// EoF 2017
|
|
// Header
|
|
// ----------------------------------------------------------------------------------------------------
|
|
|
|
#include <EEPROM.h>
|
|
#include "GPRS_Shield_Arduino.h"
|
|
#include <TroykaDHT11.h>
|
|
|
|
//#define INIT
|
|
#define MAIN
|
|
|
|
/*
|
|
* EEPROM mapping
|
|
* 1024 B
|
|
* 10 x 16 = 160 - address book | first addr 0
|
|
* 16 x 1 = 16 - parameters | first addr 160
|
|
* 24 x 16 = 384 - commands | first addr 176
|
|
* 4 x 32 = 128 - short strings | first addr 560
|
|
* 4 x 64 = 256 - long strings | first addr 688
|
|
* -------------
|
|
* 944 bytes
|
|
* 80 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 CMD_ADDR 176
|
|
#define CMD_MAX_INDEX 23
|
|
|
|
#define S_STRING_ADDR 560
|
|
#define S_STRING_MAX_INDEX 3
|
|
|
|
#define L_STRING_ADDR 688
|
|
#define L_STRING_MAX_INDEX 3
|
|
|
|
#define CMD_INDEX_STATUS 0
|
|
#define CMD_INDEX_HELP 1
|
|
#define CMD_INDEX_SMS_ON 2
|
|
#define CMD_INDEX_SMS_OFF 3
|
|
#define CMD_INDEX_ON 4
|
|
#define CMD_INDEX_OFF 5
|
|
#define CMD_INDEX_RESET 6
|
|
#define CMD_INDEX_A 7
|
|
#define CMD_INDEX_B 8
|
|
#define CMD_INDEX_FORWARD 9
|
|
#define CMD_INDEX_10 10
|
|
#define CMD_INDEX_MODEM_RESET 11
|
|
#define CMD_INDEX_MODEM_CONSOLE 12
|
|
#define CMD_INDEX_EDIT_AB 13
|
|
#define CMD_INDEX_SHOW_AB 14
|
|
#define CMD_INDEX_SHOW 15
|
|
#define CMD_INDEX_CLEAR 16
|
|
#define CMD_INDEX_EXIT 17
|
|
#define CMD_INDEX_AUTH_ON 18
|
|
#define CMD_INDEX_AUTH_OFF 19
|
|
#define CMD_INDEX_FWD_ON 20
|
|
#define CMD_INDEX_FWD_OFF 21
|
|
#define CMD_INDEX_22 22
|
|
#define CMD_INDEX_23 23
|
|
|
|
#define S_STRING_INDEX_1 0
|
|
#define S_STRING_INDEX_EAB_MODE 1
|
|
#define S_STRING_INDEX_MODEM_CONS_ON 2
|
|
#define S_STRING_INDEX_MODEM_CONS_OFF 3
|
|
|
|
#define L_STRING_INDEX_HELP_1 0
|
|
#define L_STRING_INDEX_HELP_AB 1
|
|
#define L_STRING_INDEX_FORMAT_AB 2
|
|
#define L_STRING_INDEX_HELP_2 3
|
|
|
|
|
|
// Всякое
|
|
#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 BAT_T_PIN A2
|
|
#define VBAT_PIN A3
|
|
#define VUSB_PIN A4
|
|
#define VIN_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 SHORT_BUFFER_SIZE 32
|
|
#define LONG_BUFFER_SIZE 64
|
|
#define VLONG_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);
|
|
|
|
// EEPROM utils
|
|
bool setCommand(byte index, const char *command);
|
|
bool getCommand(byte index, char *command);
|
|
bool setShortString(byte index, const char *s_buffer);
|
|
bool getShortString(byte index, char *s_buffer);
|
|
bool setLongString(byte index, const char *l_buffer);
|
|
bool getLongString(byte index, char *l_buffer);
|
|
|
|
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();
|