void TStateConfig_CheckNextDevice( TMasterCmdReq * mc ) { TNetDevice * dev; assert(mc->NewFoundDevList); dev = GET_NEXT_DEVICE(mc->NewFoundDevListIter, mc->NewFoundDevList->DevList); if (dev) { BOOL bAddressMustChanged = false; WORD OrigNetAddr, NewNetAddr; OrigNetAddr = TNetDevice_GetNetAddr( dev ); /* collision of network address? => changing... */ if (TPlant_CheckNetAddrCollision( &Plant, dev )) { YASDI_DEBUG((VERBOSE_MASTER, "TStateConfig::CheckNextDevice(): " "Net address collision of Device '%s'! Changing...\n", TNetDevice_GetName(dev) )); bAddressMustChanged = true; } /* Device has the same adress of the master? => Changing */ if (TNetDevice_GetNetAddr(dev) == 0) { YASDI_DEBUG((VERBOSE_MASTER, "TStateConfig::CheckNextDevice(): " "Device '%s' has the same address of " "the master! => Changing...\n", TNetDevice_GetName(dev) )); bAddressMustChanged = true; } /* Check the address range of the device */ if (((TNetDevice_GetNetAddr(dev) & 0x00ff) < (int)Master.DeviceAddrRangeLow) || ((TNetDevice_GetNetAddr(dev) & 0x00ff) > (int)Master.DeviceAddrRangeHigh) ) { YASDI_DEBUG((VERBOSE_MASTER, "TStateConfig::CheckNextDevice(): " "Net address of Device '%s' is out of the allowed range!" " Allowed:[0x%x..0x%x] => Changing...\n", TNetDevice_GetName(dev), (int)Master.DeviceAddrRangeLow, (int)Master.DeviceAddrRangeHigh )); bAddressMustChanged = true; } /* Need to change the device address? => Changing... */ if (bAddressMustChanged) TNetDevice_SetNetAddr(dev, TPlant_GetUniqueNetAddr( &Plant, dev, Master.DeviceAddrRangeLow, Master.DeviceAddrRangeHigh ) ); /* BUS-ID ok? */ if ((TNetDevice_GetNetAddrBus(dev) < (int)Master.DeviceAddrBusRangeLow) || (TNetDevice_GetNetAddrBus(dev) > (int)Master.DeviceAddrBusRangeHigh)) { TNetDevice_SetNetAddrBus(dev, Master.DeviceAddrBusRangeLow); } /* String-ID ok?*/ if ((TNetDevice_GetNetAddrString(dev) < (int)Master.DeviceAddrBusRangeLow) || (TNetDevice_GetNetAddrString(dev) > (int)Master.DeviceAddrBusRangeHigh)) { TNetDevice_SetNetAddrString(dev, Master.DeviceAddrBusRangeLow); } /*restore original net address and get the new one */ NewNetAddr = TNetDevice_GetNetAddr(dev); TNetDevice_SetNetAddr( dev, OrigNetAddr ); /* Erzeuge IORequest fuer die Konfiguration */ /* CMD_GET_CFG_NETADR */ TSMAData_InitReqCfgNetAddr( mc->IOReq, Master.SrcAddr, /* eigene Netzadresse */ TNetDevice_GetSerNr( dev ), /* das angeprochene Geraet */ NewNetAddr, /* die neue Netzadresse des Geraetes */ 4, /* Timeout */ 5, /* Repeat */ dev->prodID //the transportprotocol.... ); YASDI_DEBUG(( VERBOSE_MASTER, "TStateConfig::CheckNextDevice(): Configure Device " "'%s' to address 0x%x...\n", TNetDevice_GetName( dev ), NewNetAddr )); TSMAData_AddIORequest( mc->IOReq ); } else { /* alle erfassten Geraete konfiguriert => In den Status "Detection" zurueckkehren */ //TDevListIter_Destructor( Master.DevIter ); TSMADataCmd_ChangeState( mc, TStateDetect_GetInstance() ); } }
/************************************************************************** Description : Add a async IO Request Parameter : req = IORequest to add Return-Value : --- Changes : Author, Date, Version, Reason ******************************************************** PRUESSING, 28.04.2002, 1.0, Created **************************************************************************/ void yasdiAddIORequest( TIORequest * req ) { assert( req ); //Only wrapp it to the SMA-Data-Layer TSMAData_AddIORequest( req ); }
/************************************************************************** Description : Ereignis: Der Status "Detection" ist aktiviert worden... Parameter : Referenz auf die Master - Instanz Return-Value : --- Changes : Author, Date, Version, Reason ******************************************************** PRUESSING, 30.05.2001, 1.0, Created PRUESSING, 18.08.2001, 1.1, Maximalanzahl der Erfassungversuche eingefuehrt PRUESSING, 05.10.2001, 1.2, Bearbeitung von Masterkommandos druchfuehren.... **************************************************************************/ void TStateDetect_OnEnter( TMasterCmdReq * mc ) { WORD useTransportProt = 0; BOOL broadbandDetection; YASDI_DEBUG(( VERBOSE_MASTER, "TStateDetect::OnEnter\n" )); /* Masterkommando jetzt in Bearbeitung...*/ mc->Result = MCS_WORKING; /* calculate the device count when searching for only one device more */ if(mc->wDetectDevMax == (WORD)DETECT_ONE_MORE_DEV) mc->wDetectDevMax = (WORD)(TPlant_GetCount() + 1); /* Schon alle Geraet erfasst? (unendliches Suchen=="-1"?) */ if ((TPlant_GetCount() < (DWORD)mc->wDetectDevMax) && (mc->iDetectMaxTrys != 0) ) { /* no, search ahead... */ //broadband (normal) or directed detection? //directed detection only when from event "peer added" initiated with //an valid "Driver Device Handle"... broadbandDetection = ( mc->Param.DriverDeviceHandle == INVALID_DRIVER_DEVICE_HANDLE ); /* Wenn NICHT unendliches Suchen (!= -1), dann ein Versuch weniger */ if (mc->iDetectMaxTrys > 0) mc->iDetectMaxTrys--; /* calculate the next transport protocol which should be used ** toggle also the "Master.bDetectionStart" flag */ useTransportProt = TSMADataMaster_CalcNextTransportProt( mc ); //init get net request TSMAData_InitReqGetNet( mc->IOReq, Master.SrcAddr, // eigene Netzadresse Master.Timeouts.iWaitAfterDetection, // Timeout in Sekunden useTransportProt, // transport prot. mc->bDetectionStart, // CMD_GET_NET or ..START ? broadbandDetection // broadband (normal) or directed detection? ); /* Die evtl. schon erfasst wurden, aus der Liste nehmen bei GET_NET */ if ( !mc->bDetectionStart ) TDeviceList_Clear( mc->NewFoundDevList ); YASDI_DEBUG((VERBOSE_MASTER, "TStateDetect:: Sende %s\n", mc->bDetectionStart ? "CMD_GET_NET_START" : "CMD_GET_NET")); /* Request absetzen */ TSMAData_AddIORequest( mc->IOReq ); } else { //stop seaching devices...(all found or not) YASDI_DEBUG(( VERBOSE_MASTER, "TStateDetect::OnEnter(): Device detection finished....\n" )); YASDI_DEBUG(( VERBOSE_MASTER, "TStateDetect ==> %ld Device(s) in plant," " searching %d device(s)!\n", TPlant_GetCount(), mc->wDetectDevMax )); //calculate the result of the detection: if (TPlant_GetCount() >= (DWORD)mc->wDetectDevMax) mc->Result = MCS_SUCCESS; //ok (all found) else mc->Result = MCS_TIMEOUT; //nok (not all found, signaled with "timeout" /* step into state identification and get all channel lists if needed... */ // The state "identification" end the master command... TSMADataCmd_ChangeState(mc, TStateIdent_GetInstance() ); } YASDI_DEBUG(( VERBOSE_MASTER, "TStateDetect::OnEnter() end....\n" )); }