void GetReady(void) { /* get the parameters from the configure file. */ InitNetworkParam(); InitConfig(); /* connect the parameter server from the master node. */ InitParamClient(); /* get the parameters from the master node. */ GetParam(); /* connect the message server from the master node, * the message server is used for inform the slave nodes * that every nodes have loaded the data. */ InitMessageClient(); /* the semaphore is used to synchronize the storage process and the transaction process. */ InitSemaphore(); InitProc(); /* if the process-array is shared between storage and transaction, so is the process-array-lock. */ InitProcLock(); InitInvisibleTable(); }
int main(const int argc, const char* argv[]) { ArgInfo arg = {0}; if ((argc != 2) && (argc != 4)) { usage(argv[0]); return 2; } if (!InitProc(&arg, argc, argv + 1)) { fprintf(stderr, "Error! Can't Initialization.\n"); return 1; } if (argc == 4) { printf("%s %s %s的城市代码是:%s\n", argv[1], argv[2], argv[3], arg.citycode); return 0; } if (!StartSession(&arg)) { fprintf(stderr, "Error! Can't Start Session.\n"); return 1; } //Do something printf("%s", arg.output); EndSession(&arg); CleanupProc(&arg, argc); return 0; }
/*-------------- main starts here --------------------------*/ extern Int2 Main (void) { RecT r1, r2; #ifdef WIN_MAC m = AppleMenu (NULL); DeskAccGroup(m); m = PulldownMenu(NULL, "File"); s = SubMenu(m, "Open"); i = CommandItem(m, "Quit/Q", QuitProc); #endif InitProc(GetArgc(), GetArgv()); w = RoundWindow(-50, -33, -10, -10, "PDBeast: Taxonomy Assignment", NULL); #ifndef WIN_MAC SetUpDrawingTools(); /* Red(); SetColor(5); */ InvertColors(); wpdb = RoundWindow(-53, -33, -10, -10, "PDB File Display", NULL); p = StaticPrompt(wpdb, "Pdb File", 0, dialogTextHeight, systemFont, '1'); Advance(wpdb); PdbOpen = DefaultButton(wpdb, "Open", PdbOpenProc); Break(wpdb); p = StaticPrompt(wpdb, "Blast Search", 0, dialogTextHeight, systemFont, '1'); Advance(wpdb); lBlastChain = SingleList(wpdb, 10, 3, ListBlastChainProc); Advance(wpdb); BlastSearchAccept = DefaultButton(wpdb, "Send Query", BlastSearchAcceptProc); Break(wpdb); p = StaticPrompt(wpdb, "String Search", 0, dialogTextHeight, systemFont, '1'); Advance(wpdb); Pdbfile_string = DialogText(wpdb, "", 15, NULL); Advance(wpdb); Pdbfile_string_accept = DefaultButton(wpdb, "Find", PdbfileStringAcceptProc); Break(wpdb); pdbfile_panel = DocumentPanel(wpdb, 650, 20*stdLineHeight); Break(wpdb); p = StaticPrompt(wpdb," ", 0, dialogTextHeight, systemFont, '1'); Advance(wpdb); PdbClose = PushButton(wpdb,"Close", PdbCloseProc); Break(wpdb); m = PulldownMenu(w, "File"); s1 = SubMenu(m, "Open"); i = CommandItem(s1, "Entry", EntryProc); s2 = SubMenu(s1, "List"); c = ChoiceGroup(s2, ListOpenProc); ChoiceItem(c, myargs[6].strvalue); /* s3 = SubMenu(m, "Update"); c = ChoiceGroup(s3, ListUpdateProc); ChoiceItem(c, myargs[6].strvalue); */ i = CommandItem(m, "Quit/Q", QuitProc); /* edit = PulldownMenu(w, "Edit"); i = CommandItem(edit, "cut", StdCutTextProc); i = CommandItem(edit, "copy", StdCopyTextProc); i = CommandItem(edit, "paste", StdPasteTextProc); */ #endif infilemode = NormalGroup(w, 3, 0, "Data Mode of Input Entry",systemFont, InFileTypeProc); RadioButton(infilemode, "Text"); RadioButton(infilemode, "Binary"); /* SafeSetValue(infilemode, 2); */ GetPosition(infilemode, &r1); outfilemode = NormalGroup(w, 3, 0, "Data Mode of Output Entry",systemFont, OutFileTypeProc); RadioButton(outfilemode, "Text"); RadioButton(outfilemode, "Binary"); /* SafeSetValue(outfilemode, 2); */ r2.top = r1.top; r2.bottom = r1.bottom; r2.left = r1.right + 80; r2. right = r2.left + r1.right - r1.left; SetPosition(outfilemode, &r2); Break(w); p = StaticPrompt(w, "Seq-entry", 0, dialogTextHeight, systemFont, '1'); Advance (w); l = SingleList(w, 20, 3, ListProc); Disable(l); Advance(w); ListEntry_start = DefaultButton(w, "Start", ListEntryStartProc); Disable(ListEntry_start); Advance(w); ListEntry_next = DefaultButton(w, "Next", ListEntryNextProc); Disable(ListEntry_next); Advance(w); ListEntry_specific = DefaultButton(w, "Specific", ListEntrySpecificProc); Disable(ListEntry_specific); Break(w); p = StaticPrompt(w, "Enter Entry Code", 0, dialogTextHeight, systemFont, '1'); Advance (w); Entry_code = DialogText(w, "", 15, (TxtActnProc) EnableProc); Select(Entry_code); Advance (w); Entry_accept = DefaultButton(w, "Open", EntryOpenProc); Disable(Entry_accept); Break(w); p = StaticPrompt(w, "Chain", 0, dialogTextHeight, systemFont, '1'); chain_panel = DocumentPanel(w, 200, stdLineHeight); Break(w); p = StaticPrompt(w, "Pdb Source:", 0, dialogTextHeight, systemFont, '1'); pdb_source = ScrollText(w, 38, 3, systemFont, TRUE, NULL); Advance(w); Break(w); p = StaticPrompt(w, "Taxonomy Data:", 0, dialogTextHeight, systemFont, '1'); org = DocumentPanel(w,400,6*stdLineHeight); Break(w); p = StaticPrompt(w, "Taxonomy Accept?", 0, dialogTextHeight, systemFont, '1'); Break(w); Tax_accept = DefaultButton(w, "Yes", TaxAcceptProc); Advance(w); p = StaticPrompt(w, "to ", 0, dialogTextHeight, systemFont, '1'); Advance(w); Tax_all_accept = DefaultButton(w, "All", TaxAllAcceptProc); Disable(Tax_all_accept); Advance(w); p = StaticPrompt(w, " or ", 0, dialogTextHeight, systemFont, '1'); Advance(w); Tax_part_accept = DefaultButton(w, "Chain", TaxPartAcceptProc); Disable(Tax_part_accept); Advance(w); lchain = SingleList(w, 2, 4, TaxPartAssignProc); Advance(w); Tax_finish = DefaultButton(w, "All Done", TaxFinishProc); Disable(Tax_finish); Break(w); Tax_reject = DefaultButton(w, "No", ReLookupProc); Disable(Tax_accept); Disable(Tax_reject); Break(w); p = StaticPrompt(w, "Look up Taxonomy Database with another String?", 0, dialogTextHeight, systemFont, '1'); Advance(w); ReLookup_accept = DefaultButton(w, "Yes", AddStringProc); Advance(w); ReLookup_reject = DefaultButton(w, "No", ReLookupRejectProc); Disable(ReLookup_accept); Disable(ReLookup_reject); Break(w); p = StaticPrompt(w,"Search Taxonomy Database with", 0, dialogTextHeight, systemFont, '1'); Advance(w); Source_string = DialogText(w, "", 15, NULL); Advance(w); Source_string_accept = DefaultButton(w, "Start", SourceStringAcceptProc); Disable(Source_string_accept); Break(w); Show(w); Show(wpdb); ProcessEvents(); return 0; }
int main(int argc, char *argv[]) { union SIGNAL *Msg; unsigned char Buf[sizeof(union SIGNAL)]; char TimeStamp[100], TimeStampStop[100], FilePath[40]; unsigned char UpdateInterval, Idx; enum ProcTypes_e ProcessorType; char ByteportText[100]; int fd_Own, fd_ToOwn, fd_Timo, fd_BytePRep, fd_Sens; // First thing to do! Register signal and signal handler for (error) signals from operating system signal(SIGINT, SignalCallbackHandler); // Ctrl -c catched signal(SIGSEGV, SignalCallbackHandler); // Segmentation fault catched signal(SIGILL, SignalCallbackHandler); // Illegal instruction catched signal(SIGBUS, SignalCallbackHandler); // Bus error catched signal(SIGSTKFLT, SignalCallbackHandler); // Stack fault catched signal(SIGXFSZ, SignalCallbackHandler); // File size exceeded ctached //DebugOn = TRUE; // Start in Debug mode //ProcState.ModeState = Water; // Set initial value, for test purpose. TBD later ProcState.ModeState = MainMode; // Set initial value, for test purpose. TBD later ProcState.ServMode = AnchStop; // Set initial value ProcState.MinOutTemp = SENS_DEF_VAL; ProcState.MaxOutTemp = SENS_DEF_VAL; ProcState.OutTemp = SENS_DEF_VAL; ProcState.MinSeaTemp = SENS_DEF_VAL; ProcState.MaxSeaTemp = SENS_DEF_VAL; ProcState.SeaTemp = SENS_DEF_VAL; ProcState.MinRefrigTemp = SENS_DEF_VAL; ProcState.MaxRefrigTemp = SENS_DEF_VAL; ProcState.RefrigTemp = SENS_DEF_VAL; ProcState.MinBoxTemp = SENS_DEF_VAL; ProcState.MaxBoxTemp = SENS_DEF_VAL; ProcState.BoxTemp = SENS_DEF_VAL; ProcState.MinWaterTemp = SENS_DEF_VAL; ProcState.MaxWaterTemp = SENS_DEF_VAL; ProcState.WaterTemp = SENS_DEF_VAL; ProcState.WaterLevel = SENS_DEF_VAL; ProcState.HWTemp = SENS_DEF_VAL; ProcState.DieselLevel = SENS_DEF_VAL; ProcState.BatVoltS = 13.5; //SENS_DEF_VAL; Start value, avoids div by 0! ProcState.BatVoltF = 13.5; //SENS_DEF_VAL; Start value, avoids div by 0! ProcState.BatAmpS = SENS_DEF_VAL; ProcState.BatAmpF = SENS_DEF_VAL; ProcState.LCD_Id = 0; ProcState.fd.lcd = 0; ProcState.fd.RD_MainPipe = 0; ProcState.fd.WR_MainPipe = 0; ProcState.fd.RD_TimoPipe = 0; ProcState.fd.WR_TimoPipe = 0; ProcState.fd.WR_OWPipe = 0; ProcState.fd.RD_OWPipe = 0; ProcState.fd.WR_kbdButPipe = 0; ProcState.fd.RD_kbdButPipe = 0; ProcState.fd.WR_kbdKnobPipe = 0; ProcState.fd.RD_kbdKnobPipe = 0; ProcState.fd.RD_BPRepPipe = 0; ProcState.fd.WR_BPRepPipe = 0; ProcState.fd.OutTemp = 0; ProcState.fd.BoxTemp = 0; ProcState.fd.DieselLevel = 0; ProcState.fd.WaterLevel = 0; ProcState.fd.RefrigTemp = 0; ProcState.DevLCDDefined = FALSE; ProcState.UpdateInterval = 12; // Timeout intervall for data & display update ProcState.LCDBlkOnTimer = LCDBlkOnTimerVal; // Time before turning backlight off // Check if 1wire master ID present, set name accordingly. For now use default sprintf(ProcState.DeviceName,"%s", "JosefinSim"); // Initiate filter queue for (Idx = 0; Idx < NO_OF_ELEM_IN_FILTERQUEU; Idx++) { FQueue[Idx].ADDiesel = SENS_DEF_VAL; FQueue[Idx].ADWater = SENS_DEF_VAL; FQueue[Idx].ADBatVoltF = SENS_DEF_VAL; } memset(LCDText, ' ', 100); // Clear display buffer InitProc(&ProcState); //LOG_MSG("All processes initiated\r\n");sleep(0); fd_ToOwn = ProcState.fd.WR_MainPipe; fd_Own = ProcState.fd.RD_MainPipe; fd_BytePRep = ProcState.fd.WR_BPRepPipe; fd_Timo = ProcState.fd.WR_TimoPipe; fd_Sens = ProcState.fd.WR_OWPipe; sprintf(&LCDText[0], " %s started Ver: %s Golding production ", ProcState.DeviceName, __DATE__ ); // Now we must wait for the LCD to be initiated... int idx = 0; while (!ProcState.DevLCDDefined) { usleep(200000); // LOG_MSG("."); idx++; if (idx >= 1000) { LOG_MSG("Err: Not able to start, no LCD found..exit! \r\n"); exit(0); } } if (ProcState.DevLCDDefined) { // If LCD attached LCD1W_WRITE(LCD1, 1, &LCDText[Line1]); LCD1W_WRITE(LCD1, 3, &LCDText[Line2]); LCD1W_WRITE(LCD1, 2, &LCDText[Line3]); LCD1W_WRITE(LCD1, 4, &LCDText[Line4]); } else { // report error sprintf(InfoText, "Err: LCD not initated fd = %d \n", ProcState.fd.lcd); LOG_MSG(InfoText); } REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitTOut", SIGInitMeasTempOut, 3 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitTBox", SIGInitMeasTempBox, 8 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitTRefrig", SIGInitMeasTempRefrig, 3 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitTWater", SIGInitMeasTempWater, 15 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitTHWater", SIGInitMeasTempHW, 15 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitTSea", SIGInitMeasTempSea, 20 Sec); // REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitADInt", SIGInitMeasADInt, 2 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitADExt", SIGInitMeasADExt, 10 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitBlkOn", SIGMinuteTick, 60 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitLCDBlink", SIGSecondTick, 1 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainSend BPReport", SIGInitByteportReport, 10 Sec); Msg = (void *) Buf; if (fd_BytePRep != 0) { Msg->SigNo = SIGByteportInit; sprintf(Msg->ByteportReport.Str, ProcState.DeviceName); SEND(fd_BytePRep, Msg, sizeof(union SIGNAL)); } else LOG_MSG ("Error: No Byteport handler defined \r\n"); sprintf(InfoText, "%s started Ver: %s\n", ProcState.DeviceName, __DATE__); LOG_MSG(InfoText); while (TRUE) { WAIT(fd_Own, Buf, sizeof(union SIGNAL)); //if (Msg->SigNo == 10) {DbgTest = 1;} fflush(stdout); // Flush stdout, used if we print to file Msg = (void *) Buf; if (DbgTest == 1) {printf("2: %d\r\n", Msg->SigNo);usleep(200000);} switch(Msg->SigNo) { case SIGSecondTick: LCDDisplayUpdate(&ProcState); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainLCDBlink", SIGSecondTick, 1 Sec); break; case SIGMinuteTick: // Wait until backlight should be turned off REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MinuteTick", SIGMinuteTick, 60 Sec); // printf("Tick: %d\r\n", ProcState.LCDBlkOnTimer); if (ProcState.fd.lcd >= 0) { // First check that we have a LCD attached if (ProcState.LCDBlkOnTimer <= 0) Set1WLCDBlkOff(LCD1); // Turn off backlight on display else ProcState.LCDBlkOnTimer--; } break; case SIGInitByteportReport: // Select below which values to report to Byteport, and how often! Msg->SigNo = SIGByteportReport; sprintf(Msg->ByteportReport.Str, "OutTemp=%-.1f;BoxTemp=%-.1f;RefrigTemp=%-.1f;WaterTemp=%-.1f;WaterLevel=%-.1f;DieselLevel=%-.1f;BatVoltF=%-.1f", ProcState.OutTemp, ProcState.BoxTemp,ProcState.RefrigTemp,ProcState.WaterLevel, ProcState.DieselLevel, ProcState.BatVoltF); //sprintf(Msg->ByteportReport.Str, "OutTemp=%-.1f;BoxTemp=%-.1f;RefrigTemp=%-.1f;WaterTemp=%-.1f;HWaterTemp=%-.1f;SeaTemp=%-.1f;WaterLevel=%-.1f;DieselLevel=%-.1f;BatVoltF=%-.1f", ProcState.OutTemp, ProcState.BoxTemp,ProcState.RefrigTemp, ProcState.WaterTemp, ProcState.HWaterTemp, ProcState.SeaTemp, ProcState.WaterLevel, ProcState.DieselLevel, ProcState.BatVoltF); if (DebugOn == 1) { printf(" %s \r\n", Msg->ByteportReport.Str); } SEND(fd_BytePRep, Msg, sizeof(union SIGNAL)); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainSend BPReport", SIGInitByteportReport, 60 Sec); // Time between each report to Byteport break; case SIGInitMeasTempBox: // Initiate loop to read Temperature sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = BOX_TEMP; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGInitMeasTempRefrig: // Initiate loop to read Temperature sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = REFRIG_TEMP; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGInitMeasTempWater: // Initiate loop to read Temperature sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = WATER_TEMP; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGInitMeasTempSea: // Initiate loop to read Temperature sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = SEA_TEMP; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGInitMeasTempHW: // Initiate loop to read Temperature sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = HWATER_TEMP; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGInitMeasTempOut: // Initiate loop to read Temperature sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = OUT_TEMP; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGInitMeasADInt: // Initiate loop to read AD sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = ADINT; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGInitMeasADExt: // Initiate loop to read AD sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = ADEXT; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGReadSensorResp: if (DbgTest == 1) { printf(" SenRsp %d: %10.5f sec V1: %f V2: %f Status: %s \r\n", Msg->SensorResp.Sensor, Msg->SensorResp.CmdTime, Msg->SensorResp.Val[0], Msg->SensorResp.Val[1], Msg->SensorResp.Status ? "OK" : "ERROR"); } switch (Msg->SensorResp.Sensor) { case OUT_TEMP: ProcState.OutTemp = Msg->SensorResp.Val[0]; if (Msg->SensorResp.Status) { // Valid data recieved if ((ProcState.MinOutTemp == SENS_DEF_VAL) || (ProcState.OutTemp < ProcState.MinOutTemp)) ProcState.MinOutTemp = Msg->SensorResp.Val[0]; if ((ProcState.MaxOutTemp == SENS_DEF_VAL) || (ProcState.OutTemp > ProcState.MaxOutTemp)) ProcState.MaxOutTemp = Msg->SensorResp.Val[0]; } // No valid data REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitTOut", SIGInitMeasTempOut, 30 Sec); LCDDisplayUpdate(&ProcState); break; case BOX_TEMP: ProcState.BoxTemp = Msg->SensorResp.Val[0]; if (Msg->SensorResp.Status) { // Valid data recieved if ((ProcState.MinBoxTemp == SENS_DEF_VAL) || (ProcState.BoxTemp < ProcState.MinBoxTemp)) ProcState.MinBoxTemp = Msg->SensorResp.Val[0]; if ((ProcState.MaxBoxTemp == SENS_DEF_VAL) || (ProcState.BoxTemp > ProcState.MaxBoxTemp)) ProcState.MaxBoxTemp = Msg->SensorResp.Val[0]; } REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitTBox", SIGInitMeasTempBox, 15 Sec); LCDDisplayUpdate(&ProcState); break; case REFRIG_TEMP: ProcState.RefrigTemp = Msg->SensorResp.Val[0]; if (Msg->SensorResp.Status) { // Valid data recieved if ((ProcState.MinRefrigTemp == SENS_DEF_VAL) || (ProcState.RefrigTemp < ProcState.MinRefrigTemp)) ProcState.MinRefrigTemp = Msg->SensorResp.Val[0]; if ((ProcState.MaxRefrigTemp == SENS_DEF_VAL) || (ProcState.RefrigTemp > ProcState.MaxRefrigTemp)) ProcState.MaxRefrigTemp = Msg->SensorResp.Val[0]; } REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitTRefrig", SIGInitMeasTempRefrig, 20 Sec); LCDDisplayUpdate(&ProcState); break; case WATER_TEMP: ProcState.WaterTemp = Msg->SensorResp.Val[0]; if (Msg->SensorResp.Status) { // Valid data recieved if ((ProcState.MinWaterTemp == SENS_DEF_VAL) || (ProcState.WaterTemp < ProcState.MinWaterTemp)) ProcState.MinWaterTemp = Msg->SensorResp.Val[0]; if ((ProcState.MaxWaterTemp == SENS_DEF_VAL) || (ProcState.WaterTemp > ProcState.MaxWaterTemp)) ProcState.MaxWaterTemp = Msg->SensorResp.Val[0]; } REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitTWater", SIGInitMeasTempWater, 20 Sec); LCDDisplayUpdate(&ProcState); break; case HWATER_TEMP: ProcState.HWTemp = Msg->SensorResp.Val[0]; if (Msg->SensorResp.Status) { // Valid data recieved if ((ProcState.MinHWTemp == SENS_DEF_VAL) || (ProcState.HWTemp < ProcState.MinHWTemp)) ProcState.MinHWTemp = Msg->SensorResp.Val[0]; if ((ProcState.MaxHWTemp == SENS_DEF_VAL) || (ProcState.HWTemp > ProcState.MaxHWTemp)) ProcState.MaxHWTemp = Msg->SensorResp.Val[0]; } REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitHW", SIGInitMeasTempHW, 20 Sec); LCDDisplayUpdate(&ProcState); break; case SEA_TEMP: ProcState.SeaTemp= Msg->SensorResp.Val[0]; if (Msg->SensorResp.Status) { // Valid data recieved if ((ProcState.MinSeaTemp == SENS_DEF_VAL) || (ProcState.SeaTemp < ProcState.MinSeaTemp)) ProcState.MinSeaTemp = Msg->SensorResp.Val[0]; if ((ProcState.MaxSeaTemp == SENS_DEF_VAL) || (ProcState.SeaTemp > ProcState.MaxSeaTemp)) ProcState.MaxSeaTemp = Msg->SensorResp.Val[0]; } REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitTSea", SIGInitMeasTempSea, 40 Sec); LCDDisplayUpdate(&ProcState); break; case ADINT: /* if (Msg->SensorResp.Status) { // Valid data recieved ProcState.BatVoltF = 11* (Msg->SensorResp.Val[0]) + 0.65; //Correction due to ... //sprintf(InfoText, "BatF %f AD %6.3f\n", ProcState.BatVoltF, Msg->SensorResp.Val[0]); //LOG_MSG(InfoText); } REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitADInt", SIGInitMeasADInt, 5 Sec); // TIMER_START(TM1AD); LCDDisplayUpdate(&ProcState); */ break; case ADEXT: if (Msg->SensorResp.Status) { // Valid data recieved // Filter data to get better readings with less variation if (FQueue[0].ADWater == SENS_DEF_VAL) { // Not initiated yet, do it! for (Idx = 0; Idx < NO_OF_ELEM_IN_FILTERQUEU; Idx++) { FQueue[Idx].ADDiesel = Msg->SensorResp.Val[0]; FQueue[Idx].ADWater = Msg->SensorResp.Val[1]; FQueue[Idx].ADBatVoltF = Msg->SensorResp.Val[2]; } // for } // if // Move all data up 1 position in queue for (Idx = (NO_OF_ELEM_IN_FILTERQUEU - 1); Idx > 0; Idx--) { // printf("Idx: %d\r\n", Idx); FQueue[Idx].ADDiesel = FQueue[Idx - 1].ADDiesel; FQueue[Idx].ADWater = FQueue[Idx - 1].ADWater; FQueue[Idx].ADBatVoltF = FQueue[Idx - 1].ADBatVoltF; } // for FQueue[0].ADDiesel = Msg->SensorResp.Val[0]; FQueue[0].ADWater = Msg->SensorResp.Val[1]; FQueue[0].ADBatVoltF = Msg->SensorResp.Val[2]; Msg->SensorResp.Val[0] = 0; Msg->SensorResp.Val[1] = 0; Msg->SensorResp.Val[2] = 0; // Calculate mean value of all elem in filter queue for (Idx = 0; Idx < NO_OF_ELEM_IN_FILTERQUEU; Idx++) { //printf("ADD %d: %4f ", Idx, FQueue[Idx].ADDiesel); Msg->SensorResp.Val[0] += FQueue[Idx].ADDiesel; Msg->SensorResp.Val[1] += FQueue[Idx].ADWater; Msg->SensorResp.Val[2] += FQueue[Idx].ADBatVoltF; } // for //printf("\r\n"); Msg->SensorResp.Val[0] = Msg->SensorResp.Val[0]/(NO_OF_ELEM_IN_FILTERQUEU); Msg->SensorResp.Val[1] = Msg->SensorResp.Val[1]/(NO_OF_ELEM_IN_FILTERQUEU); Msg->SensorResp.Val[2] = Msg->SensorResp.Val[2]/(NO_OF_ELEM_IN_FILTERQUEU); //printf("Wavg: %4f WLatest: %4f \r\n", Msg->SensorResp.Val[1], FQueue[0].ADWater); ProcState.BatVoltF = (Msg->SensorResp.Val[2] + 0.5); // Need to 0.5V due to measurement errors..? ProcState.ADWaterLevel = Msg->SensorResp.Val[1]; ProcState.ADDieselLevel = Msg->SensorResp.Val[0]; if ((ProcState.BatVoltF < 10) || (ProcState.BatVoltF > 15)) // Check if reasonable Voltage ProcState.BatVoltF = 13; // Set default value // Compensate for battery voltage ProcState.ADWaterLevel = ProcState.ADWaterLevel * 13 / ProcState.BatVoltF; ProcState.ADDieselLevel = ProcState.ADDieselLevel * 13 / ProcState.BatVoltF; if (DebugOn) // Print adjusted AD reading printf(">>>>Converted AD reading[BF %4.2f DL: %4.2f WL: %4.2f BS: %4.2f]\r\n", ProcState.BatVoltF, Msg->SensorResp.Val[0], Msg->SensorResp.Val[1], Msg->SensorResp.Val[2]); // Calculate water and diesel levels ProcState.WaterLevel = GetWaterLevel(ProcState.ADWaterLevel); ProcState.DieselLevel = GetDieselLevel(ProcState.ADDieselLevel); } if ((ProcState.ModeState == Water) || (ProcState.ModeState == Diesel) ) { // Fast update. Always send to Byteport at same pace! Msg->SigNo = SIGByteportReport; sprintf(Msg->ByteportReport.Str, "WaterLevel=%-.1f", ProcState.WaterLevel); if (DebugOn == 1) { LOG_MSG(Msg->ByteportReport.Str); } SEND(fd_BytePRep, Msg, sizeof(union SIGNAL)); REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitADExtFst", SIGInitMeasADExt, 1 Sec); // if (DebugOn) printf("Fast update M:%d \r\n",ProcState.ModeState); } else { // Slow update REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitADExtSlw", SIGInitMeasADExt, 12 Sec); // if (DebugOn) printf("Slow update M:%d \r\n",ProcState.ModeState ); } //sprintf(InfoText, "BatF %7.3f AD: %7.3f \n", ProcState.BatVoltS, Msg->SensorResp.Val[3]); //LOG_MSG(InfoText); // Write to file for Byteport reporting. create file if not opened yet //if (ProcState.fd.WaterLevel == 0) // No file descriptor defined LCDDisplayUpdate(&ProcState); break; // ADExt default: CHECK(FALSE, "Undefined sensor...\n"); break; } LCDDisplayUpdate(&ProcState); /* // Removed 20161227. Now we use Byteport cmd reporting by Axel! // Write to file for Byteport reporting. Create file if not opened yet if (DbgTest == 1) {printf("Enter send to Byteport\r\n");usleep(200000);} sprintf(FilePath, "/tmp/ByteportReports/BatVoltF"); // Set filename if((ProcState.fd.BatVoltF = fopen(FilePath, "w+")) == NULL) { // Check that file exists sprintf(InfoText, "ERROR: %s %d Can not open file %s \n", strerror(errno), errno, FilePath); CHECK(FALSE, InfoText); } else { sprintf(ByteportText, "%-.1f", ProcState.BatVoltF); fprintf(ProcState.fd.BatVoltF, ByteportText); fclose(ProcState.fd.BatVoltF); } if (DbgTest == 1) {printf("BatVoltF written\r\n");usleep(200000);} sprintf(FilePath, "/tmp/ByteportReports/DieselLevel"); // Set filename if((ProcState.fd.DieselLevel = fopen(FilePath, "w+")) == NULL) { // Check that file exists sprintf(InfoText, "ERROR: %s %d Can not open file %s \n", strerror(errno), errno, FilePath); CHECK(FALSE, InfoText); } else { sprintf(ByteportText, "%-.1f", ProcState.DieselLevel); fprintf(ProcState.fd.DieselLevel, ByteportText); fclose(ProcState.fd.DieselLevel); } if (DbgTest == 1) {printf("DieselLevel written\r\n");usleep(200000);} sprintf(FilePath, "/tmp/ByteportReports/WaterLevel"); // Set filename if((ProcState.fd.WaterLevel = fopen(FilePath, "w+")) == NULL) { // Check that file exists sprintf(InfoText, "ERROR: %s %d Can not open file %s \n", strerror(errno), errno, FilePath); CHECK(FALSE, InfoText); } else { sprintf(ByteportText, "%-.1f", ProcState.WaterLevel); fprintf(ProcState.fd.WaterLevel, ByteportText); fclose(ProcState.fd.WaterLevel); } if (DbgTest == 1) {printf("Leaving send to Byteport\r\n");usleep(200000);} if (Msg->SensorResp.Sensor == WATER_TEMP) {// Just to secure only 1 line when no display present LCDDisplayUpdate(&ProcState); } */ break; // Turn on backlight on Display when a button is pushed. case SIGOpButOn: if (DbgTest == 1) {printf("3: %d\r\n", Msg->SigNo);usleep(200000);} if (!ProcState.fd.lcd) { // First check that we have a LCD attached if (ProcState.LCDBlkOnTimer <= 0) { // If Display OFF, Set timer and turn on Display-nothing else ProcState.LCDBlkOnTimer = LCDBlkOnTimerVal; // Time before turning backlight off Set1WLCDBlkOn(LCD1); // Turn on backlight on display } else { // Execute button pressed OpButPressed(&ProcState); LCDDisplayUpdate(&ProcState); } } break; case SIGLftButOn: //printf("Left button presssed Msg: %s\n"); ProcState.LCDBlkOnTimer = LCDBlkOnTimerVal; // Time before turning backlight off Set1WLCDBlkOn(LCD1); // Turn on backlight on display RghtButPressed(&ProcState); // LftButPressed(&ProcState); // Due to problems reading Left/Right. Step always Right!!! LCDDisplayUpdate(&ProcState); break; case SIGRghtButOn: //printf("Right button presssed \n"); ProcState.LCDBlkOnTimer = LCDBlkOnTimerVal; // Time before turning backlight off Set1WLCDBlkOn(LCD1); // Turn on backlight on display RghtButPressed(&ProcState); LCDDisplayUpdate(&ProcState); break; case SIGServCmdReq: switch (Msg->ServCmdReq.Cmd) { case Dwn: printf("Main: Anchor Down \r\n"); break; case SlwUp: printf("Main: Anchor Slow Up \r\n"); break; case Up: printf("Main: Anchor Up \r\n"); break; case AnchStop: printf("Main: Anchor STOP \r\n"); break; case SetTime: printf("Main: Set Time \r\n"); break; default: sprintf(InfoText, "Illegal server cmd received: %d\n", Msg->ServCmdReq.Cmd); CHECK(FALSE, InfoText); break; } // End switch break; default: sprintf(InfoText, "Illegal signal received: %d MsgLen: %d Data: %x %x %x %x\n", Msg->SigNo, sizeof(Msg), Msg->Data[0], Msg->Data[1],Msg->Data[2],Msg->Data[3]); CHECK(FALSE, InfoText); break; } // Switch } // While }