Пример #1
0
/**************************************************************************
Description   : Ereignis: Ein Antwort eines IORequest wurde empfangen.
Parameter     : instance   = Masterinstanz
req        = Referenz auf den entsprechenden IORequest
SourceAddr = Absender der Antwort
Buffer     = Referenz auf Datenpuffer
BufferSize = Groesse der Daten
RxFlags    = Empfangsflags
Return-Value  : ---
Changes       : Author, Date, Version, Reason
********************************************************
PRUESSING, 30.05.2001, 1.0, Created
**************************************************************************/
void TStateDetect_OnIOReqPktRcv(TMasterCmdReq * mc,
                                struct _TIORequest * req,
                                TOnReceiveInfo * rcvInfo)
{
   TNetDevice * NewDev;
   BOOL bIsDeviceNew = FALSE;
   
   UNUSED_VAR ( req     );
   
   /* Antwort interpretieren: Neues Geraet, falls noch nicht im Geraetebaum eingetragen,
      nun eintragen... */
   NewDev = TPlant_ScanGetNetBuf(   &Plant,
                                    rcvInfo->Buffer,
                                    rcvInfo->BufferSize,
                                    rcvInfo->SourceAddr,
                                    rcvInfo->RxFlags,
                                    &bIsDeviceNew,
                                    rcvInfo->BusDriverDevHandle);
   if (NewDev)
   {
      #ifdef DEBUG
      BOOL sunnyNet = rcvInfo->RxFlags & TS_PROT_SUNNYNET_ONLY;
      #endif
      
      YASDI_DEBUG(( VERBOSE_MASTER,
                    "TStateDetect::OnIOReqPktRcv() Device answer"
                    ": Device type='%8s' SN=%10ld NetAddr=[0x%04x], prot=%s\n",
                    TNetDevice_GetType( NewDev ),
                    TNetDevice_GetSerNr( NewDev ),
                    TNetDevice_GetNetAddr( NewDev ),
                    sunnyNet ? "SUNNYNET" : "SMANET")
                  );
      
      if (!TDeviceList_IsInList( mc->NewFoundDevList, NewDev ))
      {
         /* In die Liste der gerade gefunden Geraet aufnehmen */
         TDeviceList_Add( mc->NewFoundDevList, NewDev );
      }
      
      if (bIsDeviceNew)
      {
         //Callback Master API Event listener... 
         TSMADataMaster_FireAPIEventDeviceDetection( YASDI_EVENT_DEVICE_ADDED,
                                                     TNetDevice_GetHandle( NewDev ),
                                                     0 /*unused*/);
      }
   }
   else
   {
      YASDI_DEBUG(( VERBOSE_MASTER,
                    "TStateDetect::OnIOReqPktRcv() Netzerfassung-Geraetemeldung"
                    " ist ungueltig!"
                    " Paket wird ignoriert! SrcAddr=%d BufferSize=%ld\n",
                    rcvInfo->SourceAddr,
                    rcvInfo->BufferSize));
   }
}
Пример #2
0
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() );
 	}
}