149 lines
3.4 KiB
C++
149 lines
3.4 KiB
C++
|
|
#ifndef ArchivoSD_define
|
|
#define ArchivoSD_define 1
|
|
#include <SD.h>
|
|
#include "utiles.h"
|
|
|
|
#define TIMER_SMS_DATA 60000//cada 1 min
|
|
#define TIMER_SMS_INFO 600000//cada 10 min
|
|
#define TIMER_GPRS 60000//cada 1 min
|
|
#define TIMER_SD 5000//cada 5S
|
|
|
|
#define NLINEMAX 720 //numero max de lineas por archivo
|
|
#define BUFFSIZE 250
|
|
#define BUFFSIZECOL 512
|
|
#define NCOLS 23 //numero de columnas del archivo
|
|
#define NUM_INT 3 //numero de cifras enteras de los valores escritos
|
|
#define NUM_DEC 3 //numero de cifras decimales de los valores escritos
|
|
#define NUM_DEC_PREC 7 //numero de cifras decimales de los valores escritos con precision
|
|
#define NUM_MAX_TLF 5 //numero maximo de telefonos en la configuracion
|
|
|
|
|
|
/*
|
|
Clase para manejo de archivo de log
|
|
Valores por tiempos en cada fila, y dentro de cada fila, los valores separados por ;
|
|
*/
|
|
|
|
class ArchivoSD
|
|
{
|
|
int nLines; //para contar cuantas lineas lleva el archivo actual
|
|
int nFiles; //para contar cuantos archivos lleva
|
|
int iCol; //para contar por qué columna va
|
|
char fileName[24];
|
|
|
|
char buff[BUFFSIZE];
|
|
char buffHeaders[BUFFSIZECOL];
|
|
int pin_sd_cs;
|
|
public:
|
|
bool falloSD;
|
|
private:
|
|
File file;
|
|
|
|
public:
|
|
char Timestamp[16];
|
|
ArchivoSD(int pinCS);
|
|
|
|
bool init_();
|
|
|
|
/*
|
|
Actualiza el nombre del archivo en funcion de cuantos archivos lleve, empieza en datalog0000.txt
|
|
y acaba en datalog9999.txt
|
|
Si se necesitan mas archivos, aumentar el 4 cifras a mas
|
|
*/
|
|
void updatefileName();
|
|
|
|
/*
|
|
Escribe en el fichero los nombres a las cabeceras de las columnas
|
|
*/
|
|
void createColNames();
|
|
void writeColNames();
|
|
|
|
bool compruebaFile();
|
|
|
|
void openFile();
|
|
|
|
void closeFile();
|
|
|
|
/*
|
|
Para escribir al archivo una columna con un valor decimal
|
|
devuelve el buffer por si se quiere usar fuera
|
|
*/
|
|
void writeVal(float val_);
|
|
/*
|
|
Para escribir al archivo una columna con un valor decimal
|
|
devuelve el buffer por si se quiere usar fuera
|
|
*/
|
|
void writeValPrec(float val_);
|
|
/*
|
|
Para escribir al archivo una columna con un valor entero
|
|
devuelve el buffer por si se quiere usar fuera
|
|
*/
|
|
void writeVal(long unsigned int val_);
|
|
|
|
/*
|
|
Para escribir al archivo una columna con un valor de texto
|
|
devuelve el buffer por si se quiere usar fuera
|
|
*/
|
|
void writeVal(char *val_);
|
|
/*
|
|
Despues de cada dato, escribe un ; o bien un caracter vacio si es el ultimo
|
|
*/
|
|
void endCol();
|
|
|
|
/*
|
|
Escribe al archivo una linea entera
|
|
*/
|
|
void writeLine(char *line);
|
|
|
|
/*
|
|
Imprime el buff por el puerto com
|
|
*/
|
|
void printColCOM();
|
|
};
|
|
|
|
class DataConfig
|
|
{
|
|
public:
|
|
char tlf[13];
|
|
bool infoSMS;
|
|
bool dataSMS;
|
|
DataConfig() {}
|
|
};
|
|
|
|
class ArchivoConfig
|
|
{
|
|
DataConfig tlf[NUM_MAX_TLF];
|
|
char apn[32];
|
|
char srv[64];
|
|
int n;
|
|
|
|
|
|
File file;
|
|
public:
|
|
ArchivoConfig();
|
|
char* GetTlfInfo(int i);
|
|
char* GetTlfData(int i);
|
|
char* GetAPN();
|
|
char* GetSRV();
|
|
int GetLen();
|
|
bool ini();
|
|
|
|
unsigned long TimerSD;
|
|
unsigned long TimerGPRS;
|
|
unsigned long TimerSMSData;
|
|
unsigned long TimerSMSInfo;
|
|
|
|
private:
|
|
char* leeLinea(char*buf);
|
|
void leeSRV(char* buf);
|
|
void leeAPN(char* buf);
|
|
void leetlf(char* buf);
|
|
void leeTSMSD(char* buf);
|
|
void leeTSMSI(char* buf);
|
|
void leeTGPRS(char* buf);
|
|
void leeTSD(char* buf);
|
|
|
|
|
|
};
|
|
#endif
|