teste de publish

devices.h

Committer:
brunofgc
Date:
2018-05-01
Revision:
17:c046e4b07ded
Parent:
5:8efd609dea7d
Child:
19:d52176ff683d

File content as of revision 17:c046e4b07ded:

#include "mbed.h"
#include "funcoesSDCard.h"
#include "modbusMaster1.h"
#include "SDFileSystem.h"
#ifndef _devices_h_
#define _devices_h_
#define maxCaractereLeLinha 40
#include <cstdlib>

#define enderecoControladoraVirtual 0

enum {        
    modBusType_float=1,
    modBusType_bit,
    modBusType_uint8_t,
    modBusType_uint16_t,
    modBusType_uint32_t,
    modBusType_int16_t,
    modBusType_int32_t,
    IrCommandType,
    PWMCommandType
};

typedef struct _alarm{
    uint32_t id;
    //Tempos de confirmação
    uint32_t seconds;
    //Var Read block
    uint8_t type;
    uint16_t addrModbusRead;
    uint8_t funcModbusRead;
    uint16_t regModbusRead;             
    uint8_t max; //1 Max; 0 Min
    uint8_t value[4];
    
    //Act block
    uint32_t idAct;    

    //Maquina de estados alarme    
    uint32_t secAlarm;    
    bool alarmFound;
    bool on;
}alarm;



typedef struct _reading{    
    uint8_t type;
    uint8_t addr;
    uint8_t func;
    uint16_t reg;               
    uint8_t numRegs;        
}reading;

typedef struct _scheduleException{
    uint32_t id_schedule;
    uint32_t timestamp;
}scheduleException;

typedef struct _schedule{    
    uint32_t id;
    uint8_t weekday;
    uint16_t minute; // Minuto do dia em que será executada a ação programada
    
    //Act block
    uint32_t idAct;
    //Maquina de estados alarme
    bool actSent;
}schedule;

class device{
    private:
    public: 
        uint8_t execAct(uint32_t);        
        uint8_t numAlarms;
        uint8_t numSchedules;
        uint8_t numScheduleExceptions;                
        uint16_t numReadings;
        alarm *alarms;
        reading *readings;
        schedule *schedules;
        scheduleException *scheduleExceptions;
        //uint32_t id;
        
        device();
        
        void floatToBin(uint8_t,float *,uint8_t *);                
        void uint32_t_ToBin(uint8_t,uint32_t *,uint8_t *);
        void uint16_t_ToBin(uint8_t,uint16_t *,uint8_t *);
        void setAlarm(char *);
        void setReading(char *);
        void setSchedule(char *);
        void setScheduleException(char *);        
        void verifyAlarms();
        void verifySchedules();        
        void writeReadingsToSD();
        void alarmOnOff(uint32_t,bool);
};

int criaDevices(FILE *);
int configuraDevices(FILE *); 
//uint8_t resizeArray(uint32_t,uint32_t,char **,uint16_t);
void testaTudoDevices();
void writeReadingsToSD();
void verifyAlarms();
void verifySchedules();
#endif