bool ReadPortSettings(int idx, LPTSTR szPort, DWORD *SpeedIndex, DWORD *Bit1Index) { switch (idx) { case 0: ReadPort1Settings(szPort, SpeedIndex, Bit1Index); return true; case 1: ReadPort2Settings(szPort, SpeedIndex, Bit1Index); return true; default: return false; } }
static BOOL devInit(LPCTSTR CommandLine) { int i; PDeviceDescriptor_t pDevNmeaOut = NULL; for (i=0; i<NUMDEV; i++){ DeviceList[i].Port = -1; DeviceList[i].fhLogFile = NULL; DeviceList[i].Name[0] = '\0'; DeviceList[i].Driver = NULL; DeviceList[i].pDevPipeTo = NULL; } pDevPrimaryBaroSource = NULL; pDevSecondaryBaroSource=NULL; DWORD PortIndex1, PortIndex2, SpeedIndex1, SpeedIndex2; #ifdef GNAV PortIndex1 = 2; SpeedIndex1 = 5; PortIndex2 = 0; SpeedIndex2 = 5; #else PortIndex1 = 0; SpeedIndex1 = 2; PortIndex2 = 0; SpeedIndex2 = 2; #endif ReadPort1Settings(&PortIndex1,&SpeedIndex1); ReadPort2Settings(&PortIndex2,&SpeedIndex2); devInitOne(devA(), 0, COMMPort[PortIndex1], dwSpeed[SpeedIndex1], pDevNmeaOut); if (PortIndex1 != PortIndex2) devInitOne(devB(), 1, COMMPort[PortIndex2], dwSpeed[SpeedIndex2], pDevNmeaOut); CommandLine = LOGGDEVCOMMANDLINE; if (CommandLine != NULL){ TCHAR *pC, *pCe; TCHAR wcLogFileName[MAX_PATH]; TCHAR sTmp[128]; pC = _tcsstr(CommandLine, TEXT("-logA=")); if (pC != NULL){ pC += strlen("-logA="); if (*pC == '"'){ pC++; pCe = pC; while (*pCe != '"' && *pCe != '\0') pCe++; } else{ pCe = pC; while (*pCe != ' ' && *pCe != '\0') pCe++; } if (pCe != NULL && pCe-1 > pC){ _tcsncpy(wcLogFileName, pC, pCe-pC); wcLogFileName[pCe-pC] = '\0'; if (devOpenLog(devA(), wcLogFileName)){ _stprintf(sTmp, TEXT("Device A logs to\r\n%s"), wcLogFileName); MessageBoxX (sTmp, gettext(TEXT("Information")), MB_OK|MB_ICONINFORMATION); } else { _stprintf(sTmp, TEXT("Unable to open log\r\non device A\r\n%s"), wcLogFileName); MessageBoxX (sTmp, gettext(TEXT("Error")), MB_OK|MB_ICONWARNING); } } } pC = _tcsstr(CommandLine, TEXT("-logB=")); if (pC != NULL){ pC += strlen("-logA="); if (*pC == '"'){ pC++; pCe = pC; while (*pCe != '"' && *pCe != '\0') pCe++; } else{ pCe = pC; while (*pCe != ' ' && *pCe != '\0') pCe++; } if (pCe != NULL && pCe > pC){ _tcsncpy(wcLogFileName, pC, pCe-pC); wcLogFileName[pCe-pC] = '\0'; if (devOpenLog(devB(), wcLogFileName)){ _stprintf(sTmp, TEXT("Device B logs to\r\n%s"), wcLogFileName); MessageBoxX (sTmp, gettext(TEXT("Information")), MB_OK|MB_ICONINFORMATION); } else { _stprintf(sTmp, TEXT("Unable to open log\r\non device B\r\n%s"), wcLogFileName); MessageBoxX (sTmp, gettext(TEXT("Error")), MB_OK|MB_ICONWARNING); } } } } if (pDevNmeaOut != NULL){ if (pDevNmeaOut == devA()){ devB()->pDevPipeTo = devA(); } if (pDevNmeaOut == devB()){ devA()->pDevPipeTo = devB(); } } return(TRUE); }
BOOL devInit(LPTSTR CommandLine){ int i; TCHAR DeviceName[DEVNAMESIZE+1]; PDeviceDescriptor_t pDevNmeaOut = NULL; static bool doinit=true; for (i=0; i<NUMDEV; i++){ DeviceList[i].Port = -1; DeviceList[i].fhLogFile = NULL; DeviceList[i].Name[0] = '\0'; DeviceList[i].ParseNMEA = NULL; DeviceList[i].PutMacCready = NULL; DeviceList[i].DirectLink = NULL; DeviceList[i].PutBugs = NULL; DeviceList[i].PutBallast = NULL; DeviceList[i].Open = NULL; DeviceList[i].Close = NULL; DeviceList[i].Init = NULL; DeviceList[i].LinkTimeout = NULL; DeviceList[i].Declare = NULL; DeviceList[i].IsLogger = devIsFalseReturn; DeviceList[i].IsGPSSource = devIsFalseReturn; DeviceList[i].IsBaroSource = devIsFalseReturn; DeviceList[i].IsRadio = devIsFalseReturn; DeviceList[i].PutVoice = (int (*)(struct DeviceDescriptor_t *,TCHAR *))devIsFalseReturn; DeviceList[i].PortNumber = i; DeviceList[i].PutQNH = NULL; DeviceList[i].OnSysTicker = NULL; DeviceList[i].pDevPipeTo = NULL; DeviceList[i].PutVolume = NULL; DeviceList[i].PutFreqActive = NULL; DeviceList[i].PutFreqStandby = NULL; DeviceList[i].IsCondor = devIsFalseReturn; DeviceList[i].Disabled = true; ComPortStatus[i]=CPS_UNUSED; // 100210 ComPortHB[i]=0; // counter if (doinit) { ComPortRx[i]=0; ComPortTx[i]=0; ComPortErrTx[i]=0; ComPortErrRx[i]=0; ComPortErrors[i]=0; doinit=false; } } pDevPrimaryBaroSource = NULL; pDevSecondaryBaroSource=NULL; ReadDeviceSettings(0, DeviceName); #ifdef DEBUG_DEVSETTING StartupStore(_T(".......... ReadDeviceSetting 0, DeviceName=<%s>\n"),DeviceName); #endif PortIndex1 = 0; SpeedIndex1 = 2; Bit1Index=(BitIndex_t)bit8N1; ReadPort1Settings(&PortIndex1,&SpeedIndex1,&Bit1Index); //if (_tcslen(DeviceName)>0) // removed 110530 if (wcscmp(DeviceName,_T(DEV_DISABLED_NAME))!=0) { DeviceList[0].Disabled=false; StartupStore(_T(". Device A is <%s> Port=%s%s"),DeviceName,COMMPort[PortIndex1],NEWLINE); } else { DeviceList[0].Disabled=true; StartupStore(_T(". Device A is DISABLED.%s"),NEWLINE); } for (i=DeviceRegisterCount-1; i>=0; i--) { if (DeviceList[0].Disabled) break; if ((_tcscmp(DeviceRegister[i].Name, DeviceName) == 0)) { ComPort *Com = new ComPort(0); // remember: Port1 is the port used by device A, port1 may be Com3 or Com1 etc // this is port 1, so index 0 for us. if (!Com->Initialize(COMMPort[PortIndex1], dwSpeed[SpeedIndex1],Bit1Index,0)) { delete Com; ComPortStatus[0]=CPS_OPENKO; break; } ComPortStatus[0]=CPS_OPENOK; DeviceRegister[i].Installer(devA()); if ((pDevNmeaOut == NULL) && (DeviceRegister[i].Flags & (1l << dfNmeaOut))){ pDevNmeaOut = devA(); } devA()->Com = Com; devInit(devA()); devOpen(devA(), 0); if (devIsBaroSource(devA())) { if (pDevPrimaryBaroSource == NULL){ pDevPrimaryBaroSource = devA(); } else if (pDevSecondaryBaroSource == NULL){ pDevSecondaryBaroSource = devA(); } } break; } } ReadDeviceSettings(1, DeviceName); #ifdef DEBUG_DEVSETTING StartupStore(_T(".......... ReadDeviceSetting 1, DeviceName=<%s>\n"),DeviceName); #endif PortIndex2 = 0; SpeedIndex2 = 2, Bit2Index=(BitIndex_t)bit8N1; ReadPort2Settings(&PortIndex2,&SpeedIndex2, &Bit2Index); //if (_tcslen(DeviceName)>0) // removed 110530 if (wcscmp(DeviceName,_T(DEV_DISABLED_NAME))!=0) { DeviceList[1].Disabled=false; StartupStore(_T(". Device B is <%s> Port=%s%s"),DeviceName,COMMPort[PortIndex2],NEWLINE); } else { DeviceList[1].Disabled=true; StartupStore(_T(". Device B is DISABLED.%s"),NEWLINE); } for (i=DeviceRegisterCount-1; i>=0; i--) { if (PortIndex1 == PortIndex2) break; if (DeviceList[1].Disabled) break; if ((_tcscmp(DeviceRegister[i].Name, DeviceName) == 0)) { ComPort *Com = new ComPort(1); // this is port 2, so index 1 for us if (!Com->Initialize(COMMPort[PortIndex2], dwSpeed[SpeedIndex2],Bit2Index,1)) { // 100210 delete Com; ComPortStatus[1]=CPS_OPENKO; break; } ComPortStatus[1]=CPS_OPENOK; DeviceRegister[i].Installer(devB()); if ((pDevNmeaOut == NULL) && (DeviceRegister[i].Flags & (1l << dfNmeaOut))){ pDevNmeaOut = devB(); } devB()->Com = Com; devInit(devB()); devOpen(devB(), 1); if (devIsBaroSource(devB())) { if (pDevPrimaryBaroSource == NULL){ pDevPrimaryBaroSource = devB(); } else if (pDevSecondaryBaroSource == NULL){ pDevSecondaryBaroSource = devB(); } } break; } } if (pDevNmeaOut != NULL){ if (pDevNmeaOut == devA()){ devB()->pDevPipeTo = devA(); } if (pDevNmeaOut == devB()){ devA()->pDevPipeTo = devB(); } } return(TRUE); }