teste de publish

Dependencies:   DS1820 HighSpeedAnalogIn devices mbed

Committer:
brunofgc
Date:
Wed Jun 07 19:38:31 2017 +0000
Revision:
5:7801f913384e
Parent:
4:13ff9c81dc10
Child:
6:d4ebbaaba295
Ultima versao com erro no IR 07/06/2017

Who changed what in which revision?

UserRevisionLine numberNew contents of line
brunofgc 0:1c0a769988ee 1 #include "diversos.h"
brunofgc 0:1c0a769988ee 2 bool eventosRTC::segundos;
brunofgc 0:1c0a769988ee 3 bool eventosRTC::minutos;
brunofgc 0:1c0a769988ee 4 bool eventosRTC::rotina10Segundos;
brunofgc 0:1c0a769988ee 5 bool eventosRTC::rotina15Minutos;
brunofgc 0:1c0a769988ee 6 bool eventosRTC::rotina1hora;
brunofgc 0:1c0a769988ee 7 bool eventosRTC::rotina1segundo;
brunofgc 0:1c0a769988ee 8 WatchdogTimer diversos::wdt;
brunofgc 0:1c0a769988ee 9 //char diversos::msg[200];
brunofgc 0:1c0a769988ee 10 //bool eventosRTC::hora_completa;
brunofgc 0:1c0a769988ee 11 char commands::buffer[tamBufferCommands];
brunofgc 0:1c0a769988ee 12
brunofgc 0:1c0a769988ee 13 /*void WatchdogTimer::WatchdogTimer(void){
brunofgc 0:1c0a769988ee 14 //Constructor
brunofgc 0:1c0a769988ee 15 }*/
brunofgc 0:1c0a769988ee 16
brunofgc 0:1c0a769988ee 17 uint32_t diversos::memAvailable(){
brunofgc 0:1c0a769988ee 18 char stackVariable;
brunofgc 0:1c0a769988ee 19 char *heap;
brunofgc 0:1c0a769988ee 20 uint32_t result;
brunofgc 0:1c0a769988ee 21 heap = (char*)malloc(1);
brunofgc 0:1c0a769988ee 22 result = (uint32_t) ((&stackVariable) - heap);
brunofgc 0:1c0a769988ee 23 free(heap);
brunofgc 0:1c0a769988ee 24 return result;
brunofgc 0:1c0a769988ee 25 }
brunofgc 0:1c0a769988ee 26
brunofgc 0:1c0a769988ee 27 void WatchdogTimer::kick(float s) {
brunofgc 0:1c0a769988ee 28 LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK
brunofgc 0:1c0a769988ee 29 uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4
brunofgc 0:1c0a769988ee 30 LPC_WDT->WDTC = s * (float)clk;
brunofgc 0:1c0a769988ee 31 LPC_WDT->WDMOD = 0x3; // Enabled and Reset
brunofgc 0:1c0a769988ee 32 kick();
brunofgc 0:1c0a769988ee 33 }
brunofgc 0:1c0a769988ee 34 // "kick" or "feed" the dog - reset the watchdog timer
brunofgc 0:1c0a769988ee 35 // by writing this required bit pattern
brunofgc 0:1c0a769988ee 36 void WatchdogTimer::kick() {
brunofgc 0:1c0a769988ee 37 LPC_WDT->WDFEED = 0xAA;
brunofgc 0:1c0a769988ee 38 LPC_WDT->WDFEED = 0x55;
brunofgc 0:1c0a769988ee 39 }
brunofgc 0:1c0a769988ee 40
brunofgc 0:1c0a769988ee 41 /*double diversos::stringToFloat(char *p,uint16_t max){
brunofgc 0:1c0a769988ee 42 uint16_t caractere=0;
brunofgc 0:1c0a769988ee 43 double iPart=0.0,dPart=0.0,f=0.0,mult=0.1;
brunofgc 0:1c0a769988ee 44 while(*p != '.') {
brunofgc 0:1c0a769988ee 45 caractere++;
brunofgc 0:1c0a769988ee 46 if(caractere>(max-1)){return 0.0;}
brunofgc 0:1c0a769988ee 47 iPart = (iPart*10) + (double)((*(p++)-'0'));
brunofgc 0:1c0a769988ee 48 }
brunofgc 0:1c0a769988ee 49 p++;
brunofgc 0:1c0a769988ee 50 while(*p!= '\0') {
brunofgc 0:1c0a769988ee 51 if(caractere>(max-1)){return 0.0;}
brunofgc 0:1c0a769988ee 52 dPart += (double)(((*(p++)-'0'))*mult);
brunofgc 0:1c0a769988ee 53 mult /= 10;
brunofgc 0:1c0a769988ee 54 }
brunofgc 0:1c0a769988ee 55 f = iPart + dPart;
brunofgc 0:1c0a769988ee 56 return f;
brunofgc 0:1c0a769988ee 57 }*/
brunofgc 0:1c0a769988ee 58
brunofgc 0:1c0a769988ee 59 /*double diversos::stringToFloat(char *p,uint16_t max){
brunofgc 0:1c0a769988ee 60 uint16_t caractere=0;
brunofgc 0:1c0a769988ee 61 double iPart=0.0,dPart=0.0,f=0.0,mult=0.1;
brunofgc 0:1c0a769988ee 62 while(p[caractere] != '.'){
brunofgc 0:1c0a769988ee 63 caractere++;
brunofgc 0:1c0a769988ee 64 if(caractere>(max-1)){return 0.0;}
brunofgc 0:1c0a769988ee 65 iPart = (iPart*10) + (((uint8_t)p[caractere])-30);
brunofgc 0:1c0a769988ee 66 }
brunofgc 0:1c0a769988ee 67 caractere++;
brunofgc 0:1c0a769988ee 68 while(p[caractere]!= '\0'){
brunofgc 0:1c0a769988ee 69 if(caractere>(max-1)){return 0.0;}
brunofgc 0:1c0a769988ee 70 dPart += (((uint8_t)p[caractere])-30)*mult;
brunofgc 0:1c0a769988ee 71 mult /= 10;
brunofgc 0:1c0a769988ee 72 }
brunofgc 0:1c0a769988ee 73 f = iPart + dPart;
brunofgc 0:1c0a769988ee 74 return f;
brunofgc 0:1c0a769988ee 75 }*/
brunofgc 0:1c0a769988ee 76
brunofgc 3:9598af355293 77 void diversos::strReplace(char *str, char *find, char *replace){
brunofgc 3:9598af355293 78 char aux[100];
brunofgc 3:9598af355293 79 char *ptr;
brunofgc 3:9598af355293 80 char replaced = 0;
brunofgc 3:9598af355293 81 char maxIterations = 0;
brunofgc 3:9598af355293 82 replaced = 0;
brunofgc 3:9598af355293 83 strcpy(aux,"");
brunofgc 3:9598af355293 84 ptr = strtok(str,find);
brunofgc 3:9598af355293 85 while((ptr!=NULL)&&(maxIterations<9)){
brunofgc 3:9598af355293 86 replaced = 1;
brunofgc 3:9598af355293 87 maxIterations++;
brunofgc 3:9598af355293 88 strcat(aux,ptr);
brunofgc 3:9598af355293 89 strcat(aux,replace);
brunofgc 3:9598af355293 90 ptr = strtok(NULL,find);
brunofgc 3:9598af355293 91 pc.printf("Tirando <%s> em <%s>.\r\n",find,str);
brunofgc 3:9598af355293 92 }
brunofgc 3:9598af355293 93 if(replaced){
brunofgc 3:9598af355293 94 aux[strlen(aux)-1]=0;
brunofgc 3:9598af355293 95 strcpy(str,aux);
brunofgc 3:9598af355293 96 }
brunofgc 3:9598af355293 97 //--------------------
brunofgc 3:9598af355293 98 }
brunofgc 3:9598af355293 99
brunofgc 4:13ff9c81dc10 100 void diversos::processaPulsosEDs(){
brunofgc 4:13ff9c81dc10 101 if(ED1 && (!estadoAnteriorEDs[0])){pulsosEDs[0]++;}
brunofgc 4:13ff9c81dc10 102 estadoAnteriorEDs[0]=ED1;
brunofgc 4:13ff9c81dc10 103 if(ED2 && (!estadoAnteriorEDs[1])){pulsosEDs[1]++;}
brunofgc 4:13ff9c81dc10 104 estadoAnteriorEDs[1]=ED2;
brunofgc 4:13ff9c81dc10 105 if(ED3 && (!estadoAnteriorEDs[2])){pulsosEDs[2]++;}
brunofgc 4:13ff9c81dc10 106 estadoAnteriorEDs[2]=ED3;
brunofgc 4:13ff9c81dc10 107 if(ED4 && (!estadoAnteriorEDs[3])){pulsosEDs[3]++;}
brunofgc 4:13ff9c81dc10 108 estadoAnteriorEDs[3]=ED4;
brunofgc 4:13ff9c81dc10 109 if(ED5 && (!estadoAnteriorEDs[4])){pulsosEDs[4]++;}
brunofgc 4:13ff9c81dc10 110 estadoAnteriorEDs[4]=ED5;
brunofgc 4:13ff9c81dc10 111 if(ED6 && (!estadoAnteriorEDs[5])){pulsosEDs[5]++;}
brunofgc 4:13ff9c81dc10 112 estadoAnteriorEDs[5]=ED6;
brunofgc 4:13ff9c81dc10 113 if(ED7 && (!estadoAnteriorEDs[6])){pulsosEDs[6]++;}
brunofgc 4:13ff9c81dc10 114 estadoAnteriorEDs[6]=ED7;
brunofgc 4:13ff9c81dc10 115 if(ED8 && (!estadoAnteriorEDs[7])){pulsosEDs[7]++;}
brunofgc 4:13ff9c81dc10 116 estadoAnteriorEDs[7]=ED8;
brunofgc 4:13ff9c81dc10 117 if(ED9 && (!estadoAnteriorEDs[8])){pulsosEDs[8]++;}
brunofgc 4:13ff9c81dc10 118 estadoAnteriorEDs[8]=ED9;
brunofgc 4:13ff9c81dc10 119 //if(ED1 || ED2 || ED3 || ED4 || ED5 || ED6 || ED7 || ED8 || ED9){osDelay(25);}
brunofgc 4:13ff9c81dc10 120 }
brunofgc 4:13ff9c81dc10 121
brunofgc 0:1c0a769988ee 122 void diversos::progressBar(uint32_t progresso,uint32_t total){
brunofgc 0:1c0a769988ee 123 int i,j;
brunofgc 0:1c0a769988ee 124 char maxTam = 20;
brunofgc 0:1c0a769988ee 125 char engrenagem[4]={179,0x2F,0x2D,0x5C};
brunofgc 0:1c0a769988ee 126
brunofgc 0:1c0a769988ee 127 j=((double)progresso/(double)total)*maxTam;
brunofgc 0:1c0a769988ee 128 pc.printf("%c%c%c<",179,engrenagem[(unsigned int)progresso%4],179);
brunofgc 0:1c0a769988ee 129 for(i=0;i<maxTam;i++){
brunofgc 0:1c0a769988ee 130 if(i<=j){
brunofgc 0:1c0a769988ee 131 pc.printf("%c",178);
brunofgc 0:1c0a769988ee 132 }else{
brunofgc 0:1c0a769988ee 133 pc.printf("%c",176);
brunofgc 0:1c0a769988ee 134 }
brunofgc 0:1c0a769988ee 135 }
brunofgc 0:1c0a769988ee 136 pc.printf("> %3.0f%% Progresso %5lu de %5lu\r ",((double)progresso/(double)total)*100,progresso,total);
brunofgc 0:1c0a769988ee 137 }
brunofgc 0:1c0a769988ee 138
brunofgc 0:1c0a769988ee 139 void commands::exec(uint8_t idConnection){
brunofgc 0:1c0a769988ee 140 char *ptr,*pCharFile,*ptrComando;
brunofgc 0:1c0a769988ee 141 char msg[100];
brunofgc 0:1c0a769988ee 142 uint16_t currentCur,totalLengthCommands;
brunofgc 0:1c0a769988ee 143 static uint16_t fileCheckSum16BIT,checkSum16BIT_Lido;
brunofgc 0:1c0a769988ee 144
brunofgc 0:1c0a769988ee 145
brunofgc 0:1c0a769988ee 146 totalLengthCommands = strlen(commands::buffer);
brunofgc 0:1c0a769988ee 147 ptrComando = strtok(commands::buffer,";");
brunofgc 0:1c0a769988ee 148
brunofgc 0:1c0a769988ee 149 do{
brunofgc 2:55b7b466e742 150
brunofgc 2:55b7b466e742 151
brunofgc 2:55b7b466e742 152
brunofgc 0:1c0a769988ee 153 ptr=strstr(ptrComando,"DELETE_SENT_FILES");
brunofgc 0:1c0a769988ee 154 if(ptr) {
brunofgc 0:1c0a769988ee 155 pc.printf("Recebido comando para deletar arquivos enviados.\n");
brunofgc 0:1c0a769988ee 156 sdCard::deleteSentFiles = true;
brunofgc 0:1c0a769988ee 157 }
brunofgc 0:1c0a769988ee 158
brunofgc 0:1c0a769988ee 159 ptr=strstr(ptrComando,"SET_RTC:");
brunofgc 0:1c0a769988ee 160 if(ptr) {
brunofgc 0:1c0a769988ee 161 ptr = strtok(ptr,":");
brunofgc 0:1c0a769988ee 162 ptr = strtok(NULL,";");
brunofgc 0:1c0a769988ee 163 set_time(atoi(ptr));
brunofgc 0:1c0a769988ee 164 time_t seconds = time(NULL);
brunofgc 0:1c0a769988ee 165 pc.printf("Horario atualizado pelo server %s",ctime(&seconds));
brunofgc 0:1c0a769988ee 166 }
brunofgc 0:1c0a769988ee 167
brunofgc 0:1c0a769988ee 168 ptr=strstr(ptrComando,"sendArmazenamento");
brunofgc 0:1c0a769988ee 169 if(ptr) {
brunofgc 0:1c0a769988ee 170 eventosRTC::rotina1hora=1;
brunofgc 0:1c0a769988ee 171 }
brunofgc 0:1c0a769988ee 172
brunofgc 0:1c0a769988ee 173 ptr=strstr(ptrComando,"StartSendFile");
brunofgc 0:1c0a769988ee 174 if(ptr){
brunofgc 0:1c0a769988ee 175 modemCom::status.timeOut=100;
brunofgc 0:1c0a769988ee 176 strtok(ptr,",");//Descartando inicio
brunofgc 0:1c0a769988ee 177 pCharFile = strtok(NULL,",");//Selecionando nome do arquivo
brunofgc 0:1c0a769988ee 178 strcpy(sdCard::nomeArquivoEmRecebimento,pCharFile);
brunofgc 0:1c0a769988ee 179 pCharFile = strtok(NULL,";");//Selecionando string checkSum16BIT
brunofgc 0:1c0a769988ee 180 fileCheckSum16BIT = atoi(pCharFile);
brunofgc 0:1c0a769988ee 181 remove("/sd/RAD/tempFile.bin");
brunofgc 0:1c0a769988ee 182 pc.printf("Iniciando recepcao do server arquivo deviceCfg.\n");
brunofgc 0:1c0a769988ee 183 modemCom::status.recebendoArquivoDoServer = true;
brunofgc 0:1c0a769988ee 184
brunofgc 0:1c0a769988ee 185 sprintf(modemCom::bufIn,"AT+CIPSEND=%u,%lu\r\n",idConnection,10);
brunofgc 0:1c0a769988ee 186 modem.puts(modemCom::bufIn);
brunofgc 0:1c0a769988ee 187 osDelay(100);
brunofgc 0:1c0a769988ee 188 modem.puts("sendData\r\n");
brunofgc 0:1c0a769988ee 189
brunofgc 0:1c0a769988ee 190 pc.printf("sendData\n");
brunofgc 0:1c0a769988ee 191 modemCom::timeOutModem = 250;
brunofgc 0:1c0a769988ee 192 return;
brunofgc 0:1c0a769988ee 193 }
brunofgc 0:1c0a769988ee 194
brunofgc 0:1c0a769988ee 195 ptr=strstr(ptrComando,"StopSendFile");
brunofgc 0:1c0a769988ee 196 if(ptr){
brunofgc 0:1c0a769988ee 197 pc.printf("Finalizando recepcao do server arquivo deviceCfg.\n");
brunofgc 0:1c0a769988ee 198 modemCom::status.recebendoArquivoDoServer = false;
brunofgc 0:1c0a769988ee 199 checkSum16BIT_Lido = sdCard::calcCheckSum16BITFile("/sd/RAD/tempFile.bin");
brunofgc 0:1c0a769988ee 200 if(fileCheckSum16BIT == checkSum16BIT_Lido){
brunofgc 0:1c0a769988ee 201 if(sdCard::file_rename("/sd/RAD/tempFile.bin",sdCard::nomeArquivoEmRecebimento)){
brunofgc 0:1c0a769988ee 202 /*sprintf(diversos::msg,"File Received checkSum16BIT_Lido <%lu>.\r\n",checkSum16BIT_Lido);
brunofgc 0:1c0a769988ee 203 modemCom::sendBufferCommandMode(2,diversos::msg,strlen(diversos::msg));*/
brunofgc 0:1c0a769988ee 204 sprintf(msg,"File Received checkSum16BIT_Lido <%lu>.\r\n",checkSum16BIT_Lido);
brunofgc 0:1c0a769988ee 205 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 0:1c0a769988ee 206 pc.printf("File Received checkSum16BIT_Lido <%lu>.\r\n",checkSum16BIT_Lido);
brunofgc 0:1c0a769988ee 207
brunofgc 0:1c0a769988ee 208 if(strstr(sdCard::nomeArquivoEmRecebimento,"devices.cfg")!=NULL){
brunofgc 0:1c0a769988ee 209 pc.printf("Excluindo arquivo armazenamento.txt .\r\n");
brunofgc 0:1c0a769988ee 210 sdCard::excluiArquivo(&sdCard::armazenamento);
brunofgc 0:1c0a769988ee 211 pc.printf("Resetando o drome.\r\n");
brunofgc 0:1c0a769988ee 212 hardwareReset=true;
brunofgc 0:1c0a769988ee 213 }
brunofgc 0:1c0a769988ee 214
brunofgc 0:1c0a769988ee 215 }else{
brunofgc 0:1c0a769988ee 216 //modemCom::sendBufferCommandMode(2,"FileCorrupted.\r\n",strlen("FileCorrupted.\r\n"));
brunofgc 4:13ff9c81dc10 217 sprintf(msg,"erro");
brunofgc 0:1c0a769988ee 218 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 0:1c0a769988ee 219 pc.printf("Recebido correto mas n foi possivel renomear arquivo.\r\n");
brunofgc 0:1c0a769988ee 220 }
brunofgc 0:1c0a769988ee 221
brunofgc 0:1c0a769988ee 222 }else{
brunofgc 0:1c0a769988ee 223 /*sprintf(diversos::msg,"File Corrupted checkSum16BIT_Lido <%lu>.\r\n",checkSum16BIT_Lido);
brunofgc 0:1c0a769988ee 224 modemCom::sendBufferCommandMode(2,diversos::msg,strlen(diversos::msg));*/
brunofgc 0:1c0a769988ee 225 sprintf(msg,"File Corrupted checkSum16BIT_Lido <%lu>.\r\n",checkSum16BIT_Lido);
brunofgc 0:1c0a769988ee 226 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 0:1c0a769988ee 227 pc.printf("File Corrupted checkSum16BIT_Lido <%lu>.\r\n",checkSum16BIT_Lido);
brunofgc 0:1c0a769988ee 228 }
brunofgc 0:1c0a769988ee 229 modemCom::status.timeOut=10;
brunofgc 0:1c0a769988ee 230 modemCom::timeOutModem = 50;
brunofgc 0:1c0a769988ee 231 }
brunofgc 0:1c0a769988ee 232
brunofgc 0:1c0a769988ee 233 /*ptr=strstr(ptrComando,"requestFile,");
brunofgc 0:1c0a769988ee 234 if(ptr){
brunofgc 0:1c0a769988ee 235 FILE *fp;
brunofgc 0:1c0a769988ee 236 char c;
brunofgc 0:1c0a769988ee 237 strtok(ptr,",");
brunofgc 0:1c0a769988ee 238 pCharFile = strtok(NULL,";");
brunofgc 0:1c0a769988ee 239
brunofgc 0:1c0a769988ee 240 fp = fopen(pCharFile,"r");
brunofgc 0:1c0a769988ee 241 if(fp!=NULL){
brunofgc 0:1c0a769988ee 242 do{
brunofgc 0:1c0a769988ee 243 c = fgetc(fp);
brunofgc 0:1c0a769988ee 244 if(!feof(fp)){modem.printf("%c",c);}
brunofgc 0:1c0a769988ee 245 modemCom::status.timeOut=10;
brunofgc 0:1c0a769988ee 246 }while(!feof(fp));
brunofgc 0:1c0a769988ee 247 fclose(fp);
brunofgc 0:1c0a769988ee 248 }else{
brunofgc 0:1c0a769988ee 249 modem.printf("Nao foi possivel abrir o arquivo.\n");
brunofgc 0:1c0a769988ee 250 }
brunofgc 0:1c0a769988ee 251 }*/
brunofgc 0:1c0a769988ee 252
brunofgc 1:0e0967c88590 253 ptr=strstr(ptrComando,"execAct:");
brunofgc 1:0e0967c88590 254 if(ptr){
brunofgc 1:0e0967c88590 255 char *pChar;
brunofgc 1:0e0967c88590 256 uint32_t actId;
brunofgc 1:0e0967c88590 257 pChar = strtok(ptr,":");
brunofgc 1:0e0967c88590 258 pChar = strtok(NULL,"");
brunofgc 1:0e0967c88590 259 actId = atoi(pChar);
brunofgc 1:0e0967c88590 260 if(dispositivos[0]->execAct(actId)){
brunofgc 1:0e0967c88590 261 sprintf(msg,"execAct_ack");
brunofgc 1:0e0967c88590 262 }else{
brunofgc 1:0e0967c88590 263 sprintf(msg,"execAct_nack");
brunofgc 1:0e0967c88590 264 }
brunofgc 1:0e0967c88590 265 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 1:0e0967c88590 266 }
brunofgc 1:0e0967c88590 267
brunofgc 2:55b7b466e742 268 if(strstr(ptr,"enviaDadosAoServer")){
brunofgc 2:55b7b466e742 269 eventosRTC::rotina15Minutos=true;
brunofgc 2:55b7b466e742 270 sprintf(msg,"ack");
brunofgc 2:55b7b466e742 271 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 2:55b7b466e742 272 }
brunofgc 2:55b7b466e742 273
brunofgc 0:1c0a769988ee 274 ptr=strstr(ptrComando,"mbwrite:");
brunofgc 0:1c0a769988ee 275 if(ptr){
brunofgc 0:1c0a769988ee 276 uint8_t addr;
brunofgc 0:1c0a769988ee 277 uint16_t reg;
brunofgc 0:1c0a769988ee 278 uint32_t auxMod;
brunofgc 0:1c0a769988ee 279 char *pChar;
brunofgc 0:1c0a769988ee 280
brunofgc 1:0e0967c88590 281 //IR
brunofgc 1:0e0967c88590 282 if(strstr(ptr,"IR,")){
brunofgc 1:0e0967c88590 283 uint8_t freq=38,porta=0;
brunofgc 1:0e0967c88590 284 pChar = strtok(ptr,",");
brunofgc 1:0e0967c88590 285 porta = atoi(strtok(NULL,","));
brunofgc 1:0e0967c88590 286 porta--; //Trazendo para índice 0;
brunofgc 1:0e0967c88590 287
brunofgc 1:0e0967c88590 288 freq = atoi(strtok(NULL,","));
brunofgc 1:0e0967c88590 289 if(freq == 0){
brunofgc 1:0e0967c88590 290 //Se não tiver frequência, ponha 38.
brunofgc 1:0e0967c88590 291 freq = 38;
brunofgc 1:0e0967c88590 292 }
brunofgc 1:0e0967c88590 293
brunofgc 5:7801f913384e 294 pChar = strtok(NULL,"S");//Reaproveitando variável pTipoComando
brunofgc 5:7801f913384e 295 deserializaPacoteIR(pChar);
brunofgc 1:0e0967c88590 296 enviaComandoIR(freq,porta);
brunofgc 1:0e0967c88590 297 sprintf(msg,"WriteIR_ack");
brunofgc 1:0e0967c88590 298 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 1:0e0967c88590 299 }
brunofgc 1:0e0967c88590 300
brunofgc 0:1c0a769988ee 301 //Float
brunofgc 0:1c0a769988ee 302 if(strstr(ptr,"float,")){
brunofgc 0:1c0a769988ee 303 float v_float;
brunofgc 0:1c0a769988ee 304
brunofgc 0:1c0a769988ee 305 //Capturando parametros comuns
brunofgc 0:1c0a769988ee 306 pChar = strtok(ptr,",");
brunofgc 0:1c0a769988ee 307
brunofgc 0:1c0a769988ee 308 //Parametro 1
brunofgc 0:1c0a769988ee 309 pChar = strtok(NULL,",");
brunofgc 0:1c0a769988ee 310 addr = atoi(pChar);
brunofgc 0:1c0a769988ee 311
brunofgc 0:1c0a769988ee 312 //Parametro 2
brunofgc 0:1c0a769988ee 313 pChar = strtok(NULL,",");
brunofgc 0:1c0a769988ee 314 reg = atoi(pChar);
brunofgc 0:1c0a769988ee 315
brunofgc 0:1c0a769988ee 316 //Parametro 3
brunofgc 0:1c0a769988ee 317 pChar = strtok(NULL,",");
brunofgc 0:1c0a769988ee 318 //v_float = diversos::stringToFloat(pChar,50);
brunofgc 0:1c0a769988ee 319 v_float = atof(pChar);
brunofgc 1:0e0967c88590 320
brunofgc 1:0e0967c88590 321 //Envio o dado via Modbus
brunofgc 1:0e0967c88590 322 if(!modBusMaster1::writeFloat(addr,reg,1,&v_float)){
brunofgc 1:0e0967c88590 323 pc.printf("Valor <%f> escrito no registrador %lu do endereco modbus %u.\n",v_float,reg,addr);
brunofgc 0:1c0a769988ee 324 /*sprintf(diversos::msg,"WriteFloat_ack");
brunofgc 0:1c0a769988ee 325 modemCom::sendBufferCommandMode(2,diversos::msg,strlen(diversos::msg));*/
brunofgc 0:1c0a769988ee 326
brunofgc 1:0e0967c88590 327 sprintf(msg,"WriteFloat_ack");
brunofgc 1:0e0967c88590 328 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 1:0e0967c88590 329 }else{
brunofgc 1:0e0967c88590 330 pc.printf("Erro ao escrever valor <%f> no registrador %lu do endereco modbus %u.\n",v_float,reg,addr);
brunofgc 1:0e0967c88590 331 /*sprintf(diversos::msg,"WriteFloat_nack");
brunofgc 1:0e0967c88590 332 modemCom::sendBufferCommandMode(2,diversos::msg,strlen(diversos::msg));*/
brunofgc 1:0e0967c88590 333
brunofgc 1:0e0967c88590 334 sprintf(msg,"WriteFloat_nack");
brunofgc 0:1c0a769988ee 335 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 1:0e0967c88590 336 }
brunofgc 1:0e0967c88590 337 }
brunofgc 1:0e0967c88590 338
brunofgc 1:0e0967c88590 339 //PWM
brunofgc 1:0e0967c88590 340 if(strstr(ptr,"PWM,")){
brunofgc 1:0e0967c88590 341 float v_float;
brunofgc 1:0e0967c88590 342
brunofgc 1:0e0967c88590 343 //Capturando parametros comuns
brunofgc 1:0e0967c88590 344 pChar = strtok(ptr,",");
brunofgc 1:0e0967c88590 345
brunofgc 1:0e0967c88590 346 //Parametro 1
brunofgc 1:0e0967c88590 347 pChar = strtok(NULL,",");
brunofgc 1:0e0967c88590 348 addr = atoi(pChar);
brunofgc 1:0e0967c88590 349
brunofgc 1:0e0967c88590 350 //Parametro 2
brunofgc 1:0e0967c88590 351 pChar = strtok(NULL,",");
brunofgc 1:0e0967c88590 352 reg = atoi(pChar);
brunofgc 1:0e0967c88590 353
brunofgc 1:0e0967c88590 354 //Parametro 3
brunofgc 1:0e0967c88590 355 pChar = strtok(NULL,",");
brunofgc 1:0e0967c88590 356 //v_float = diversos::stringToFloat(pChar,50);
brunofgc 1:0e0967c88590 357 v_float = atof(pChar);
brunofgc 1:0e0967c88590 358
brunofgc 1:0e0967c88590 359 pc.printf("\r\n\r\nVerificando conteudo de pChar antes de converter para float <%s>.\r\n",pChar);
brunofgc 1:0e0967c88590 360
brunofgc 1:0e0967c88590 361 //Retirando a parte inteira referente ao periodo em us do pwm
brunofgc 1:0e0967c88590 362
brunofgc 1:0e0967c88590 363 auxMod = v_float/10;
brunofgc 1:0e0967c88590 364 v_float = v_float-(auxMod*10);
brunofgc 1:0e0967c88590 365 SD1.period_us(auxMod);
brunofgc 1:0e0967c88590 366 pwmPeriod = auxMod;
brunofgc 1:0e0967c88590 367 switch(reg){
brunofgc 1:0e0967c88590 368 case 0:
brunofgc 1:0e0967c88590 369 SD1.write(v_float);
brunofgc 1:0e0967c88590 370 break;
brunofgc 1:0e0967c88590 371 case 1:
brunofgc 1:0e0967c88590 372 SD2.write(v_float);
brunofgc 1:0e0967c88590 373 break;
brunofgc 1:0e0967c88590 374 case 2:
brunofgc 1:0e0967c88590 375 SD3.write(v_float);
brunofgc 1:0e0967c88590 376 break;
brunofgc 1:0e0967c88590 377 case 3:
brunofgc 1:0e0967c88590 378 SD4.write(v_float);
brunofgc 1:0e0967c88590 379 break;
brunofgc 1:0e0967c88590 380 case 4:
brunofgc 1:0e0967c88590 381 SD5.write(v_float);
brunofgc 1:0e0967c88590 382 break;
brunofgc 1:0e0967c88590 383 case 5:
brunofgc 1:0e0967c88590 384 SD6.write(v_float);
brunofgc 1:0e0967c88590 385 break;
brunofgc 0:1c0a769988ee 386 }
brunofgc 1:0e0967c88590 387 pc.printf("Valor puro %f, %lu escrito como periodo e %f como duty no reg %u.\n",v_float,auxMod,v_float,reg);
brunofgc 1:0e0967c88590 388 /*sprintf(diversos::msg,"WriteFloat_ack");
brunofgc 1:0e0967c88590 389 modemCom::sendBufferCommandMode(2,diversos::msg,strlen(diversos::msg));*/
brunofgc 1:0e0967c88590 390
brunofgc 1:0e0967c88590 391 sprintf(msg,"WritePWM_ack");
brunofgc 1:0e0967c88590 392 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 0:1c0a769988ee 393 }
brunofgc 0:1c0a769988ee 394
brunofgc 0:1c0a769988ee 395 //uint32_t
brunofgc 0:1c0a769988ee 396 if(strstr(ptr,"uint32_t,")){
brunofgc 0:1c0a769988ee 397 uint32_t v_uint32_t;
brunofgc 0:1c0a769988ee 398
brunofgc 0:1c0a769988ee 399 //Capturando parametros comuns
brunofgc 0:1c0a769988ee 400 pChar = strtok(ptr,",");
brunofgc 0:1c0a769988ee 401
brunofgc 0:1c0a769988ee 402 //Parametro 1
brunofgc 0:1c0a769988ee 403 pChar = strtok(NULL,",");
brunofgc 0:1c0a769988ee 404 addr = atoi(pChar);
brunofgc 0:1c0a769988ee 405
brunofgc 0:1c0a769988ee 406 //Parametro 2
brunofgc 0:1c0a769988ee 407 pChar = strtok(NULL,",");
brunofgc 0:1c0a769988ee 408 reg = atoi(pChar);
brunofgc 0:1c0a769988ee 409
brunofgc 0:1c0a769988ee 410 //Parametro 3
brunofgc 0:1c0a769988ee 411 pChar = strtok(NULL,",");
brunofgc 0:1c0a769988ee 412 v_uint32_t = atoi(pChar);
brunofgc 0:1c0a769988ee 413
brunofgc 0:1c0a769988ee 414 if(!modBusMaster1::writeRegister32BIT(addr,reg,1,&v_uint32_t)){
brunofgc 0:1c0a769988ee 415 pc.printf("Valor <%lu> escrito no registrador %lu do endereco modbus %u.\n",v_uint32_t,reg,addr);
brunofgc 0:1c0a769988ee 416 /*sprintf(diversos::msg,"Write_uint32_t_ack");
brunofgc 0:1c0a769988ee 417 modemCom::sendBufferCommandMode(2,diversos::msg,strlen(diversos::msg));*/
brunofgc 0:1c0a769988ee 418
brunofgc 1:0e0967c88590 419 sprintf(msg,"Write_uint32_t_ack");
brunofgc 0:1c0a769988ee 420 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 0:1c0a769988ee 421 }else{
brunofgc 0:1c0a769988ee 422 pc.printf("Erro ao escrever valor <%lu> no registrador %lu do endereco modbus %u.\n",v_uint32_t,reg,addr);
brunofgc 0:1c0a769988ee 423 /*sprintf(diversos::msg,"Write_uint32_t_nack");
brunofgc 0:1c0a769988ee 424 modemCom::sendBufferCommandMode(2,diversos::msg,strlen(diversos::msg));*/
brunofgc 0:1c0a769988ee 425
brunofgc 1:0e0967c88590 426 sprintf(msg,"Write_uint32_t_nack");
brunofgc 0:1c0a769988ee 427 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 0:1c0a769988ee 428 }
brunofgc 0:1c0a769988ee 429 }
brunofgc 0:1c0a769988ee 430
brunofgc 0:1c0a769988ee 431 //uint16_t
brunofgc 0:1c0a769988ee 432 if(strstr(ptr,"uint16_t,")){
brunofgc 0:1c0a769988ee 433 uint16_t v_uint16_t;
brunofgc 0:1c0a769988ee 434
brunofgc 0:1c0a769988ee 435 //Capturando parametros comuns
brunofgc 0:1c0a769988ee 436 pChar = strtok(ptr,",");
brunofgc 0:1c0a769988ee 437
brunofgc 0:1c0a769988ee 438 //Parametro 1
brunofgc 0:1c0a769988ee 439 pChar = strtok(NULL,",");
brunofgc 0:1c0a769988ee 440 addr = atoi(pChar);
brunofgc 0:1c0a769988ee 441
brunofgc 0:1c0a769988ee 442 //Parametro 2
brunofgc 0:1c0a769988ee 443 pChar = strtok(NULL,",");
brunofgc 0:1c0a769988ee 444 reg = atoi(pChar);
brunofgc 0:1c0a769988ee 445
brunofgc 0:1c0a769988ee 446 //Parametro 3
brunofgc 0:1c0a769988ee 447 pChar = strtok(NULL,",");
brunofgc 0:1c0a769988ee 448 v_uint16_t = atoi(pChar);
brunofgc 0:1c0a769988ee 449
brunofgc 0:1c0a769988ee 450 if(!modBusMaster1::writeRegister16BIT(addr,reg,1,&v_uint16_t)){
brunofgc 0:1c0a769988ee 451 pc.printf("Valor <%lu> escrito no registrador %lu do endereco modbus %u.\n",v_uint16_t,reg,addr);
brunofgc 0:1c0a769988ee 452 /*sprintf(diversos::msg,"Write_uint16_t_ack");
brunofgc 0:1c0a769988ee 453 modemCom::sendBufferCommandMode(2,diversos::msg,strlen(diversos::msg));*/
brunofgc 0:1c0a769988ee 454
brunofgc 1:0e0967c88590 455 sprintf(msg,"Write_uint16_t_ack");
brunofgc 0:1c0a769988ee 456 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 0:1c0a769988ee 457 }else{
brunofgc 0:1c0a769988ee 458 pc.printf("Erro ao escrever valor <%lu> no registrador %lu do endereco modbus %u.\n",v_uint16_t,reg,addr);
brunofgc 0:1c0a769988ee 459 /*sprintf(diversos::msg,"Write_uint16_t_nack");
brunofgc 0:1c0a769988ee 460 modemCom::sendBufferCommandMode(2,diversos::msg,strlen(diversos::msg)); */
brunofgc 0:1c0a769988ee 461
brunofgc 1:0e0967c88590 462 sprintf(msg,"Write_uint16_t_nack");
brunofgc 0:1c0a769988ee 463 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 0:1c0a769988ee 464 }
brunofgc 0:1c0a769988ee 465 }
brunofgc 0:1c0a769988ee 466
brunofgc 0:1c0a769988ee 467 //bit
brunofgc 0:1c0a769988ee 468 if(strstr(ptr,"bit,")){
brunofgc 0:1c0a769988ee 469 bool v_bool;
brunofgc 0:1c0a769988ee 470
brunofgc 0:1c0a769988ee 471 //Capturando parametros comuns
brunofgc 0:1c0a769988ee 472 pChar = strtok(ptr,",");
brunofgc 0:1c0a769988ee 473
brunofgc 0:1c0a769988ee 474 //Parametro 1
brunofgc 0:1c0a769988ee 475 pChar = strtok(NULL,",");
brunofgc 0:1c0a769988ee 476 addr = atoi(pChar);
brunofgc 0:1c0a769988ee 477
brunofgc 0:1c0a769988ee 478 //Parametro 2
brunofgc 0:1c0a769988ee 479 pChar = strtok(NULL,",");
brunofgc 0:1c0a769988ee 480 reg = atoi(pChar);
brunofgc 0:1c0a769988ee 481
brunofgc 0:1c0a769988ee 482 //Parametro 3
brunofgc 0:1c0a769988ee 483 pChar = strtok(NULL,",");
brunofgc 0:1c0a769988ee 484 v_bool = (atoi(pChar) > 0);
brunofgc 0:1c0a769988ee 485
brunofgc 5:7801f913384e 486 if(addr != enderecoControladoraVirtual){
brunofgc 0:1c0a769988ee 487 //writeSingleCoil(uint8_t,uint16_t,bool); //Endereço slave, registrador, bool
brunofgc 0:1c0a769988ee 488 if(!modBusMaster1::writeSingleCoil(addr,reg,v_bool)){
brunofgc 0:1c0a769988ee 489 pc.printf("Valor <%u> escrito no registrador %lu do endereco modbus %u.\n",v_bool,reg,addr);
brunofgc 0:1c0a769988ee 490 /*sprintf(diversos::msg,"Write_bool_ack");
brunofgc 0:1c0a769988ee 491 modemCom::sendBufferCommandMode(2,diversos::msg,strlen(diversos::msg));*/
brunofgc 0:1c0a769988ee 492
brunofgc 1:0e0967c88590 493 sprintf(msg,"Write_bool_ack");
brunofgc 0:1c0a769988ee 494 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 0:1c0a769988ee 495 }else{
brunofgc 0:1c0a769988ee 496 pc.printf("Erro ao escrever valor <%u> no registrador %lu do endereco modbus %u.\n",v_bool,reg,addr);
brunofgc 0:1c0a769988ee 497 /*sprintf(diversos::msg,"Write_bool_nack");
brunofgc 0:1c0a769988ee 498 modemCom::sendBufferCommandMode(2,diversos::msg,strlen(diversos::msg));*/
brunofgc 0:1c0a769988ee 499
brunofgc 1:0e0967c88590 500 sprintf(msg,"Write_bool_nack");
brunofgc 0:1c0a769988ee 501 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 0:1c0a769988ee 502 }
brunofgc 0:1c0a769988ee 503 }else{
brunofgc 0:1c0a769988ee 504 switch(reg){
brunofgc 0:1c0a769988ee 505 case 0:
brunofgc 0:1c0a769988ee 506 SD1.write(v_bool*1.0f);
brunofgc 0:1c0a769988ee 507 break;
brunofgc 0:1c0a769988ee 508 case 1:
brunofgc 0:1c0a769988ee 509 SD2.write(v_bool*1.0f);
brunofgc 0:1c0a769988ee 510 break;
brunofgc 0:1c0a769988ee 511 case 2:
brunofgc 0:1c0a769988ee 512 SD3.write(v_bool*1.0f);
brunofgc 0:1c0a769988ee 513 break;
brunofgc 0:1c0a769988ee 514 case 3:
brunofgc 0:1c0a769988ee 515 SD4.write(v_bool*1.0f);
brunofgc 0:1c0a769988ee 516 break;
brunofgc 0:1c0a769988ee 517 case 4:
brunofgc 0:1c0a769988ee 518 SD5.write(v_bool*1.0f);
brunofgc 0:1c0a769988ee 519 break;
brunofgc 0:1c0a769988ee 520 case 5:
brunofgc 0:1c0a769988ee 521 SD6.write(v_bool*1.0f);
brunofgc 0:1c0a769988ee 522 break;
brunofgc 0:1c0a769988ee 523 case 6:
brunofgc 0:1c0a769988ee 524 SD7 = v_bool;
brunofgc 0:1c0a769988ee 525 break;
brunofgc 0:1c0a769988ee 526 case 7:
brunofgc 0:1c0a769988ee 527 SD8 = v_bool;
brunofgc 0:1c0a769988ee 528 break;
brunofgc 0:1c0a769988ee 529 }
brunofgc 0:1c0a769988ee 530 pc.printf("Valor <%u> escrito no registrador %lu do endereco modbus %u.\n",v_bool,reg,addr);
brunofgc 0:1c0a769988ee 531 /*sprintf(diversos::msg,"Write_bool_ack");
brunofgc 0:1c0a769988ee 532 modemCom::sendBufferCommandMode(2,diversos::msg,strlen(diversos::msg));*/
brunofgc 0:1c0a769988ee 533
brunofgc 1:0e0967c88590 534 sprintf(msg,"Write_bool_ack");
brunofgc 0:1c0a769988ee 535 modemCom::sendBufferCommandMode(idConnection,msg,strlen(msg));
brunofgc 0:1c0a769988ee 536 }
brunofgc 0:1c0a769988ee 537 }
brunofgc 0:1c0a769988ee 538 modemCom::status.timeOut=10;
brunofgc 0:1c0a769988ee 539 }
brunofgc 0:1c0a769988ee 540
brunofgc 0:1c0a769988ee 541 currentCur = strlen(ptrComando) + 1; //Aqui eu pego onde devo buscar novamente mais algum comando.
brunofgc 0:1c0a769988ee 542 if(currentCur>=totalLengthCommands){
brunofgc 0:1c0a769988ee 543 //modemCom::status.timeOut=10;
brunofgc 0:1c0a769988ee 544 ptrComando = NULL;
brunofgc 0:1c0a769988ee 545 }else{
brunofgc 0:1c0a769988ee 546 ptrComando = strtok(&ptrComando[currentCur],";");
brunofgc 0:1c0a769988ee 547 }
brunofgc 0:1c0a769988ee 548 }while(ptrComando != NULL);//Este loop executa cada instrução.
brunofgc 0:1c0a769988ee 549 pc.printf("Atendidos todos os comandos.\n");
brunofgc 0:1c0a769988ee 550 }