Vicent Ibanyez / Mbed 2 deprecated EcotronV10
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /************************************
00002 Software del mbed para el Ecotron.
00003 (c) Miquel Carbonell Piqueres
00004 Diciembre de 2011.
00005 ************************************/
00006 /************************************
00007 Arhivo: main.cpp
00008 Entrada principal y asignación del pin out.
00009 ************************************/
00010 
00011 #include "mbed.h"
00012 #include "ecocore.h"
00013 #include "ecocom.h"
00014 #include "ecocommand.h"
00015 
00016 ecocore nucleo; //Control de hardware.
00017 ecocom vt200;       //Control de comunicaciones.
00018 ecocommand comando; //Interprete de comandos.
00019 
00020 DigitalOut LedRx(LED1); //Para indicaciones.
00021 DigitalOut LedEvento(LED2);
00022 DigitalOut LedTx(LED3);
00023 
00024 
00025 int main(){
00026     LedRx=0;
00027     LedEvento=0;
00028     LedTx=0;
00029     while (1){ //Bucle principal.
00030         //Si Rx recibir e interpretar los datos.
00031         if (vt200.RxCompleta){
00032             LedRx=1;
00033             vt200.TxDatos(comando.InterpretarComando(vt200.RxCad,nucleo.entrada,nucleo.salida));
00034             vt200.RxCompleta=false;
00035             LedRx=0;
00036         }
00037         //Si hay evento transmitirlo.
00038         if (nucleo.Evento()){ //Forzamos el envio del estado de las entradas.
00039             LedEvento=1;
00040             vt200.TxDatos(comando.InterpretarComando("$VM+IN?",nucleo.entrada,nucleo.salida));
00041             nucleo.ReiniciarCuenta(); //Reiniciamos la cuenta por cada evento.
00042             LedEvento=0;
00043         }
00044         //Si expira el tiempo de letargo, transmitir estado general.
00045         if (nucleo.ExpiradoTiempoTx()){ //Forzamos un informe global.
00046             LedTx=1;
00047             vt200.TxDatos(comando.InterpretarComando("$VM+?",nucleo.entrada,nucleo.salida));
00048             LedTx=0;
00049         }
00050     }
00051 }