void EnviaHistorico(){ LCD_Clear(); LCD_Write(" ENVIA ", 1); LCD_Write(" HISTORICO", 2); B16 cal; uint16_t mem_mes = MES1; uint8_t day[3]; uint8_t hour[3]; DADOMEDIDA hist; int ind_mes; for(ind_mes = 0; ind_mes < 6; ind_mes++) { mem_mes = mem_mes + (ind_mes*0x1173); cal = GetMesAno(mem_mes); int ler; for(ler = 0; ler < 744; ler++) { hist = LeSequencia((ind_mes*0x1173), ler); day[0] = hist.datetime[0]; day[1] = cal.byte[1]; day[2] = cal.byte[0]; hour[0] = hist.datetime[1]; hour[1] = hist.datetime[2]; hour[2] = hist.datetime[3]; Bluetooth_EnviaDados(hist.med.word, day, hour); } } Delay(1000); LCD_Clear(); }
void main(void) { Inicia_Tiva(); REFTEMPO referencia; uint8_t date[6] = {0x00,0x00,0x0C,0x1B,0x08,0x10}; uint8_t modo_atual = START, aberta = 0x00; uint16_t leituras_salvas= 0; LCD_BlackLight_Enable(); LCD_Clear(); LCD_Write(" BEM VINDO!!!", 1); LCD_Write(" MEDIDOR DE AGUA!", 2); InitSensores(); Delay(2000); LCD_Clear(); StartMonit(date, &referencia); while(1) { Delay(250); LeSensores(); // OpenValve(); // Delay(5000); // CloseValve(); // Delay(5000); recebeDadosBluetooth = Bluetooth_RecebeDados(); char comando; // char temp[5]; // for(i = 0; i < 5; i++){ // temp[i] = recebeDadosBluetooth[i]; // } comando = recebeDadosBluetooth[5]; if(comando == '1'){ // if( strcmp(temp, "atual") == 0 ){ LCD_Clear(); LCD_Write(" ENVIA", 0); LCD_Write(" ULTIMO", 1); LCD_Write(" VALOR", 2); DADOMEDIDA ultimo; uint16_t mes_atual = referencia.end_proxmes - 0x1173; if(referencia.end_diaria.word - 3 != mes_atual) ultimo = EEPROM_PegaLeitura(referencia.end_diaria.word - 6); else ultimo.med.word = 0; Bluetooth_EnviaMedicao(ultimo.med.word); Delay(1000); } if(comando == '2'){ // if( strcmp(temp, "anter") == 0 ){ LCD_Clear(); LCD_Write(" ENVIA", 0); LCD_Write(" MEDIA ", 1); LCD_Write(" ANUAL", 2); DADOANUAL media; media = EEPROM_PegaMedia(referencia.end_proxano.word - 9); uint32_t valor = ((media.acu_hi.word*65536) + media.acu_lo.word)/media.cnt_ms.word; Bluetooth_EnviaMedicao(valor); Delay(1000); } if(comando == '3'){ // if( strcmp(temp, "histo") == 0 ){ LCD_Clear(); LCD_Write(" ENVIA ", 1); LCD_Write(" HISTORICO", 2); B16 cal; uint16_t mem_mes = MES1; uint8_t day[3]; uint8_t hour[3]; DADOMEDIDA hist; for(int ind_mes = 0; ind_mes < 6; ind_mes++) { mem_mes = mem_mes + (ind_mes*0x1173); cal = GetMesAno(mem_mes); for(int ler = 0; ler < 744; ler++) { hist = LeSequencia((ind_mes*0x1173), ler); day[0] = his.datetime[0]; day[1] = cal.byte[1]; day[2] = cal.byte[0]; hour[0] = his.datetime[1]; hour[1] = his.datetime[2]; hour[2] = his.datetime[3]; Bluetooth_EnviaDados(hist.med.word, day, hour); } } Delay(1000); } if(comando == '4'){ // if( strcmp(temp, "reset") == 0 ){ LCD_Clear(); LCD_Write(" RESET", 1); LCD_Write(" MEMORIA", 2); ResetMem(); } if(comando == '5'){ // if( strcmp(temp, "ajust") == 0 ){ LCD_Clear(); LCD_Write(" RECEBENDO DADOS", 0); //recebe data char imprime[15]; char auxData[6] = "999999"; Delay(1000); while(auxData[0] == '9'){ Delay(200); recebeDadosBluetooth = Bluetooth_RecebeDados(); for(index = 0; index < 6; index++){ auxData[index] = recebeDadosBluetooth[index]; } } date[3] = ((auxData[0] - 0x30 ) * 10) + (auxData[1] - 0x30); date[4] = ((auxData[2] - 0x30 ) * 10) + (auxData[3] - 0x30); date[5] = ((auxData[4] - 0x30 ) * 10) + (auxData[5] - 0x30); sprintf(imprime, "DATA %02d/%02d/%02d", date[3], date[4], date[5]); LCD_Write(imprime, 1); //recebe hora char auxTime[6] = "999999"; Delay(1000); while(auxTime[0] == '9'){ Delay(200); recebeDadosBluetooth = Bluetooth_RecebeDados(); for(index = 0; index < 6; index++){ auxTime[index] = recebeDadosBluetooth[index]; } } date[2] = ((auxTime[0] - 0x30 ) * 10) + (auxTime[1] - 0x30); date[1] = ((auxTime[2] - 0x30 ) * 10) + (auxTime[3] - 0x30); date[0] = ((auxTime[4] - 0x30 ) * 10) + (auxTime[5] - 0x30); sprintf(imprime, "HORA %02d:%02d:%02d", date[2], date[1], date[0]); LCD_Write(imprime, 2); Delay(1000); //HORA - MINUTO - SEGUNDO DS1307_SetTime(date[2],date[1],date[0]); //DIA - MES - ANO DS1307_SetDate(date[3],date[4],date[5]); } if(comando == '6'){ // if( strcmp(temp, "abrir") == 0 ){ LCD_Clear(); OpenValve(); LCD_Write(" ABRE VALVULA", 0); LCD_Write("---------/ /--------", 2); Delay(1000); } if(comando == '7'){ // if( strcmp(temp, "fecha") == 0 ){ LCD_Clear(); CloseValve(); LCD_Write(" FECHA VALVULA", 0); LCD_Write("--------------------", 2); Delay(1000); } if(comando == '8'){ // if( strcmp(temp, "volts") == 0 ){ LCD_Clear(); LCD_Write("FONTES DE ENERGIAS", 0); char imprime[10]; float volt = bateria / 1.67; sprintf(imprime, "BATERIA = %.2f V", volt); // 9.0v -> 2.18V LCD_Write(imprime, 1); volt = rede / 2; sprintf(imprime, "REDE = %.2f V", volt); //12.4V -> 2.80V LCD_Write(imprime, 2); Delay(1000); } ShowDateTime(); Scan(&referencia, &modo_atual, &tempo_passado, &pulsos_contados, &leituras_salvas); if(modo_atual == ENABLED) { TimerEnable(TIMER0_BASE, TIMER_A); } else if(modo_atual == RESTART || modo_atual == DISABLED) { TimerDisable(TIMER0_BASE, TIMER_A); modo_atual = START; Delay(1); } if(modo_atual != DISABLED) { if(aberta == 0x00) { OpenValve(); aberta = 0x01; } } else { if(aberta == 0x01) { CloseValve(); aberta = 0x00; } } LCD_Process(); } }
//--------------------------------------------------------------------------- void __fastcall TExpPHNormal::ProcessaRegistros(TObject *Sender) { Evolucao1->SetProcess(); try { double TotalFat = 0.00; double ValorTotal = 0.00; int QuantidadeFat = 0; int QuantidadeDocs = 0; int MesAtual; int AnoAtual; AnsiString Arquivo = IntToStr(0).sprintf("%sMOVSAI_%s.TXT",GetArquivo(),DataStr(GetMesAno())); TSMensagens->Add("SAÍDAS:"); TSMensagens->Add("-------"); GPH = new TGrvPH; TStringList *Notas = new TStringList; try { Notas->Duplicates = dupAccept; Notas->Sorted = true; GPH->AbreArquivo(Arquivo); //Seta Registro 10 SetReg10(); for(int m = 0; m < 2; m++) { if(m == 0) { MesAtual = MesAnterior; AnoAtual = AnoAnterior; } else { MesAtual = Mes; AnoAtual = Ano; } //Determina o mês do faturamento DSFat->Close(); DSFat->MesNomeArq = MesAtual; DSFat->AnoNomeArq = AnoAtual; DSFat->IndiceNome = "DataEmissao"; DSFat->Open(true); SrcFat = (struct FAT *)DSFat->Buffer; DSFat->First(); //Determina o mês dos detalhamentos DSDetFat->Close(); DSDetFat->MesNomeArq = MesAtual; DSDetFat->AnoNomeArq = AnoAtual; DSDetFat->Range = false; DSDetFat->Filtrado = false; DSDetFat->Open(true); SrcDetFat = (struct DETFAT *)DSDetFat->Buffer; //Determina o mês dos detalhamentos das retenções DSDetRet->Close(); DSDetRet->MesNomeArq = MesAtual; DSDetRet->AnoNomeArq = AnoAtual; DSDetRet->Open(true); SrcDetRet = (struct DETRET *)DSDetRet->Buffer; Evolucao1->StartProcess(DSFat->CountReg()); while(!DSFat->Eof) { Evolucao1->Label1->Caption = "Faturamento: " + DSFat->GTLK(FAT_CLIENTE,CLI_NOME,0); Evolucao1->Label1->Update(); Evolucao1->ProcessAdd(); if(SrcFat->DataEmissao / 100 != MesAno) { DSFat->Next(); continue; } SetValorContabil(); QuantidadeFat++; TotalFat += GetValorContabil(); if(GetValorContabil() > 0.0099 && SrcFat->NotaFiscal > 0) //Para não gerar dos Lançamentos que não for selecionado pelo menos um Item { ValorTotal += GetValorContabil(); QuantidadeDocs++; SetReg20S(SrcFat->DataEmissao); SetReg21S(); SetReg22S(); SetReg23S(); SetReg26(); SetReg33(); SetReg35(); SetReg37(GetValorContabil()); GPH->GravaRegistros(); } else { if(SrcFat->NotaFiscal < 1) { TSMensagens->Add("Lançamento '" + IntToStr(SrcFat->Lancamento) + "' não foi gerado pois não possui número da NF."); } else { TSMensagens->Add("Lançamento '" + IntToStr(SrcFat->Lancamento) + "' não foi gerado por falta de valores."); } } Notas->Add(IntToStr(0).sprintf("%08d", SrcFat->NotaFiscal)); DSFat->Next(); Application->ProcessMessages(); if(Evolucao1->Interrompe()) { throw Exception("Processamento interrompido."); } } } GPH->Reg90(); // verifica sequencia de notas long NotaAnterior = -1; long NotaAtual; for(int n = 0; n < Notas->Count; n++) { if(NotaAnterior != -1) { NotaAtual = StrToInt(Notas->Strings[n]); if(NotaAnterior == NotaAtual) { TSMensagens->Add("Nota Fiscal número '" + IntToStr(NotaAtual) + "' está duplicada."); } else if(NotaAtual > NotaAnterior + 1) { for(int NotaFaltando = NotaAnterior + 1; NotaFaltando < NotaAtual; NotaFaltando++) { TSMensagens->Add("Nota Fiscal número '" + IntToStr(NotaFaltando) + "' está faltando."); } } } NotaAnterior = StrToInt(Notas->Strings[n]); } } __finally { GPH->FechaArquivo(); delete GPH; delete Notas; } TSMensagens->Add("Quantidade Total de Lançamentos encontrados: " + FloatToStr(QuantidadeFat)); TSMensagens->Add("Valor Total dos Lançamentos encontrados: " + FormValor(FloatToStr(TotalFat), 1, 2)); TSMensagens->Add("Quantidade Total dos Documentos gerados: " + FloatToStr(QuantidadeDocs)); TSMensagens->Add("Valor Total dos Documentos gerados: " + FormValor(FloatToStr(ValorTotal), 1, 2)); TSMensagens->Add("Arquivo Gerado: " + Arquivo); ValorTotal = 0.00; QuantidadeDocs = 0; Arquivo = IntToStr(0).sprintf("%sMOVENT_%s.TXT",GetArquivo(),DataStr(GetMesAno())); TSMensagens->Add(""); TSMensagens->Add("ENTRADAS:"); TSMensagens->Add("---------"); DSCntPg->First(); GPH = new TGrvPH; try { Evolucao1->ResetEvolucao("Gerando Arquivo","Contas a Pagar"); Evolucao1->StartProcess(DSCntPg->CountReg()); GPH->AbreArquivo(Arquivo); //Seta Registro 10 SetReg10(); while(!DSCntPg->Eof) { Evolucao1->Label1->Caption = "Contas a Pagar:" + DSCntPg->GTLK(CNTPG_FORNECEDORCREDOR,FORN_NOME,0); Evolucao1->Label1->Update(); Evolucao1->ProcessAdd(); ValorTotal += SrcCntPg->Valor; QuantidadeDocs++; SetReg20E(); SetReg21E(); SetReg22E(); SetReg23E(); SetReg37(SrcCntPg->Valor); GPH->GravaRegistros(); DSCntPg->Next(); Application->ProcessMessages(); if(Evolucao1->Interrompe()) { throw Exception("Processamento interrompido."); } } GPH->Reg90(); } __finally { GPH->FechaArquivo(); delete GPH; } TSMensagens->Add("Quantidade Total de Documentos: " + FloatToStr(QuantidadeDocs)); TSMensagens->Add("Valor Total dos Documentos: " + FormValor(FloatToStr(ValorTotal), 1, 2)); TSMensagens->Add("Arquivo Gerado: " + Arquivo); } __finally { Evolucao1->Close(); } }