/************************************************************************** Description : Ereignis: Der IORequest wird beendet Parameter : instance = Masterinstanz req = Referenz auf den entsprechenden IORequest Return-Value : --- Changes : Author, Date, Version, Reason ******************************************************** PRUESSING, 30.05.2001, 1.0, Created **************************************************************************/ void TStateDetect_OnIOReqEnd( TMasterCmdReq * mc, struct _TIORequest * req) { UNUSED_VAR ( mc ); UNUSED_VAR ( req ); YASDI_DEBUG(( VERBOSE_MASTER, "TStateDetect::OnIOReqEnd(): Currently detected devices in plant: %u; " "Searching for %u device(s)!\n", TDeviceList_GetCount( Plant.DevList ), mc->wDetectDevMax )); /* Wenn Geraete gefunden wurden, gehe in den Zustand "Konfiguration" */ if (!TDeviceList_IsEmpty( mc->NewFoundDevList ) ) { /* state "Configuration" */ TSMADataCmd_ChangeState( mc, TStateConfig_GetInstance() ); } else { /* stay in state "Detection" and check for retries */ TSMADataCmd_ChangeState( mc, TStateDetect_GetInstance() ); } }
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() ); } }