Ejemplo n.º 1
0
BOOL CMainFrame::CreateStatusBar()
{
    std::vector<UINT> indicators(1, ID_SEPARATOR);
    ConfigSection items(m_frameNode.GetSection(L"statusbar/indicators"));

    for (int i = 0; ; i++)
    {
        ConfigSection item(items.GetSectionByIndex(L"item", i));
        UINT id = GetNodeID(item, L"id");
        if (0 == id)
            break;
        indicators.push_back(id);
        if (ID_SEPARATOR == id && indicators.front() == id)
            indicators.erase(indicators.begin());
    }

    VERIFY(m_statusBar.Create(m_mainwnd)
        && m_statusBar.SetIndicators(&indicators[0], x3::GetSize(indicators)));

    m_statusBar.SetCommandBars(m_cmdbars);
    m_statusBar.SetDrawDisabledText(FALSE);
    m_statusBar.GetStatusBarCtrl().SetMinHeight(22);
    m_statusBar.GetPane(0)->SetMargins(8, 1, 2, 1);

    return TRUE;
}
const Error *Node::ResetNode( void )
{
   cml.Debug( "ResetNode %d.\n", GetNodeID() );

   // Send the node a reset message
   RefObjLocker<Network> net( GetNetworkRef() );
   if( !net ) return &NodeError::NetworkUnavailable;
   return net->ResetNode( this );
}
const Error *Amp::UpdateEvents( uint16 stat, uint32 events, uint16 inputs )
{
   cml.Debug( "Amp %d status 0x%08x 0x%04x 0x%04x\n", GetNodeID(), events, stat, inputs );
   uint32 mask = 0;

   if(  stat & DRIVESTAT_SPACK    ) mask |= AMPEVENT_SPACK;
   if(  stat & DRIVESTAT_MOVEDONE ) mask |= AMPEVENT_MOVEDONE;
   if( ~stat & DRIVESTAT_TRJ      ) mask |= AMPEVENT_TRJDONE;
   if( ~stat & DRIVESTAT_QSTOP    ) mask |= AMPEVENT_QUICKSTOP;
   if(  stat & DRIVESTAT_ABORT    ) mask |= AMPEVENT_ABORT;
   if(  stat & DRIVESTAT_HOMECAP  ) mask |= AMPEVENT_HOME_CAPTURE;

   if( events & ERROR_EVENTS      ) mask |= AMPEVENT_ERROR;
   if( events & ESTAT_FAULT       ) mask |= AMPEVENT_FAULT;
   if( events & ESTAT_TRK_WARN    ) mask |= AMPEVENT_POSWARN;
   if( events & ESTAT_TRK_WIN     ) mask |= AMPEVENT_POSWIN;
   if( events & ESTAT_VEL_WIN     ) mask |= AMPEVENT_VELWIN;
   if( events & ESTAT_PWM_DISABLE ) mask |= AMPEVENT_DISABLED;
   if( events & ESTAT_POSLIM      ) mask |= AMPEVENT_POSLIM;    
   if( events & ESTAT_NEGLIM      ) mask |= AMPEVENT_NEGLIM;
   if( events & ESTAT_SOFTLIM_POS ) mask |= AMPEVENT_SOFTLIM_POS;
   if( events & ESTAT_SOFTLIM_NEG ) mask |= AMPEVENT_SOFTLIM_NEG;
   if( events & ESTAT_SOFT_DISABLE) mask |= AMPEVENT_SOFTDISABLE;
   if( events & ESTAT_PHASE_INIT  ) mask |= AMPEVENT_PHASE_INIT;

   // On new move aborts, do some clean up.
   if( mask & AMPEVENT_ABORT )
   {
      uint32 old = eventMap.getMask();

      if( !(old & AMPEVENT_ABORT) )
         MoveAborted();
   }

   // Do the same thing if the amplifier is disabled while 
   // a trajectory was in progress
   if( mask & AMPEVENT_DISABLED )
   {
      uint32 old = eventMap.getMask();

      if( !(old & AMPEVENT_TRJDONE) )
         MoveAborted();
   }

   // Change the bits that this function is responsible for.
   // for now, that's everything but the node guarding 
   // and PVT buffer empty bits.
   eventMap.changeBits( ~(AMPEVENT_PVT_EMPTY|AMPEVENT_NODEGUARD), mask );

   // Update the input pins state
   inputStateMap.setMask( (uint32)inputs );

   return 0;
}
const Error *Amp::FormatPvtSeg( int32 pos, int32 vel, uint8 time, uint8 *buff )
{
   cml.Debug( "Amp %d PVT Segment: %-10ld %-10ld %3d\n", GetNodeID(), pos, vel, time );

   // Save the lowest 3 bits of the segment ID.  This allows the
   // amplifier to identify missing profile segments.
   buff[0] = 7 & pvtSegID;

   // If position is more then 24 bits then we will have to send a 
   // relative move segment.  I'll just find the difference between 
   // this position and the last one sent.
   if( pos > 0x007FFFFF || -pos > 0x007FFFFF )
   {
      pos -= pvtLastPos;

      // if the result is still more then 24 bits, return an error
      if( pos > 0x007FFFFF || -pos > 0x007FFFFF )
         return &AmpError::pvtSegPos;

      // mark the segment as relative
      buff[0] |= 0x10;
   }

   // If velocity is more then 24-bits, send it in lower resolution
   if( vel > 0x007FFFFF )
   {
      vel = (vel+50)/100;
      buff[0] |= 0x08;

      if( vel > 0x007FFFFF )
         return &AmpError::pvtSegVel;
   }
   else if( -vel > 0x007FFFFF )
   {
      vel = (vel-50)/100;
      buff[0] |= 0x08;

      if( -vel > 0x007FFFFF )
         return &AmpError::pvtSegVel;
   }

   // Format the message and return     
   buff[1] = time;
   buff[2] = pos;
   buff[3] = pos>>8;
   buff[4] = pos>>16;
   buff[5] = vel;
   buff[6] = vel>>8;
   buff[7] = vel>>16;

   return 0;
}
Ejemplo n.º 5
0
BOOL CMainFrame::BeforeLoadFrame(CFrameWnd* pMainWnd)
{
    m_mainwnd = pMainWnd;
    m_frameNode = g_factoryRoot.GetSection(L"mainframe");
    m_appid = g_factoryRoot->GetString(L"_appid");
    m_appname = g_factoryRoot->GetString(L"appname");
    m_id = GetNodeID(m_frameNode, L"id");
    ASSERT(!m_appname.empty());

    m_barsfile = getConfigPath() + g_factoryRoot->GetString(L"cmdbarsFile", L"cmdbars.xml");

    return TRUE;
}
const Error *Amp::FormatPtSeg( int32 pos, uint8 time, uint8 *buff )
{
   cml.Debug( "Amp %d PT Segment: %-10ld %3d\n", GetNodeID(), pos, time );

   // Save the lowest 3 bits of the segment ID.  This allows the
   // amplifier to identify missing profile segments.
   buff[0] = 7 & pvtSegID;

   // PT points are always passed using buffer format code 5
   buff[0] |= (5<<3);

   // Format the message and return     
   buff[1] = time;
   buff[2] = ByteCast(pos);
   buff[3] = ByteCast(pos>>8);
   buff[4] = ByteCast(pos>>16);
   buff[5] = ByteCast(pos>>24);

   return 0;
}
Ejemplo n.º 7
0
PySubStruct *PyServiceMgr::BindObject(Client *c, PyBoundObject *cb, PyDict **dict) {
	if(cb == NULL)
    {
        sLog.Error("Service Mgr", "Tried to bind a NULL object!");
		return new PySubStruct(new PyNone());
	}

	cb->_SetNodeBindID(GetNodeID(), _GetBindID());	//tell the object what its bind ID is.

	BoundObject obj;
	obj.client = c;
	obj.destination = cb;

	m_boundObjects[cb->bindID()] = obj;

    //sLog.Debug("Service Mgr", "Binding %s to service %s", bind_str, cb->GetName());

	std::string bind_str = cb->GetBindStr();
	//not sure what this really is...
	uint64 expiration = Win32TimeNow() + Win32Time_Hour;

	PyTuple *objt;
	if(dict == NULL || *dict == NULL)
	{
		objt = new PyTuple(2);

		objt->items[0] = new PyString(bind_str);
		objt->items[1] = new PyLong(expiration);	//expiration?
	}
	else
	{
		objt = new PyTuple(3);

		objt->items[0] = new PyString(bind_str);
		objt->items[1] = *dict; *dict = NULL;			//consumed
		objt->items[2] = new PyLong(expiration);	//expiration?
	}

	return new PySubStruct(new PySubStream(objt));
}
// Uninitialize the PDOs used to get status from the drive. 
const Error *Amp::UninitPDOs( void )
{
   const Error *err = 0;

   // If this is a secondary axis, we shouldn't have to uninit the PDOs
   if( primaryAmpRef )
   {
      return err;
   }

   // Disable all the default PDOs 
   cml.Debug( "Amp %d, Uninitting PDOs\n", GetNodeID() );
   // See if I need to uninit for multiple axes
   int16 numAxes = 1;

   if( GetNetworkType() == NET_TYPE_ETHERCAT )
   {
      err = Upld16( OBJID_AMP_INFO, 25, numAxes );
      if( err ) return err;
   }

   if (statPDO)
   {
      err = statPDO->Uninit( *this, 0, numAxes );
      if( err )
      {
         delete statPDO;
         statPDO = 0;
         return err;
      }
   }
   
   if (pvtStatPDO)
   {
      err = pvtStatPDO->Uninit( *this, 1, numAxes );
      if( err )
      {
         delete pvtStatPDO;
         pvtStatPDO = 0;
         return err;
      }
   }

   if( GetNetworkType() == NET_TYPE_ETHERCAT )
   {
      if (ctrlPDO)
      {
         err = ctrlPDO->Uninit( *this, 0, numAxes );
         if( err )
         {
            delete ctrlPDO;
            ctrlPDO = 0;
            return err;
         }
      }
   }
   else
   {
      if (pvtCtrlPDO)
      {
         err = pvtCtrlPDO->Uninit( *this, 0, numAxes );
         if( err )
         {
            delete pvtCtrlPDO;
            pvtCtrlPDO = 0;
            return err;
         }
      }
   }

   return 0;
}
// Initialize the PDOs used to get status from the drive and send control info to it.
const Error *Amp::InitPDOs( void )
{
   const Error *err = 0;

   // If this is a secondary axis, just attach to the primary axis status PDO
   if( primaryAmpRef )
   {
      RefObjLocker<Amp> pri( primaryAmpRef );
      if( !pri ) return &AmpError::NotInit;
      if( !err ) err = pri->statPDO->ConnectSubAxis( axisNum, this );
      if( !err ) err = pri->pvtStatPDO->ConnectSubAxis( axisNum, this );
      return err;
   }

   // Disable all the default PDOs 
   cml.Debug( "Amp %d, Initting PDOs\n", GetNodeID() );
   for( int i=0; i<8; i++ )
   {
      if( !err ) err = TpdoDisable( i );
      if( !err ) err = RpdoDisable( i );
   }

   // See if I need to init for multiple axes
   int16 numAxes = 1;
   if( GetNetworkType() == NET_TYPE_ETHERCAT )
   {
      err = Upld16( OBJID_AMP_INFO, 25, numAxes );
      if( err ) return err;
   }

   // Release any PDOs that were previously allocated
   FreePDOs();

   statPDO = new TPDO_Status();
   err = statPDO->Init( *this, 0, numAxes );
   if( err )
   {
      delete statPDO;
      statPDO = 0;
      return err;
   }

   pvtStatPDO = new TPDO_PvtStat();
   err = pvtStatPDO->Init( *this, 1, numAxes );
   if( err )
   {
      delete pvtStatPDO;
      pvtStatPDO = 0;
      return err;
   }

   if( GetNetworkType() == NET_TYPE_ETHERCAT )
   {
      ctrlPDO = new RPDO_Ctrl();
      err = ctrlPDO->Init( *this, 0, numAxes );
      if( err )
      {
         delete ctrlPDO;
         ctrlPDO = 0;
         return err;
      }
   }
   else
   {
      pvtCtrlPDO = new RPDO_PvtCtrl();
      err = pvtCtrlPDO->Init( *this, 0, numAxes );
      if( err )
      {
         delete pvtCtrlPDO;
         pvtCtrlPDO = 0;
         return err;
      }
   }

   return 0;
}