コード例 #1
0
ファイル: archivebox.c プロジェクト: pmansvelder/Rocrail
static const char* _getCategories( obj inst, Boolean* readonly) {
    iOArchiveBoxData data = Data(inst);
    TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "get categories [%s]", wArchiveBox.getcategories(data->ini) );
    *readonly = data->readonly;
    return wArchiveBox.getcategories(data->ini);
}
コード例 #2
0
void test_sorting_elements_SoA()
{
	// Generating the test data
	std::random_device Rd;
	std::mt19937 Gen(Rd());
	std::uniform_int_distribution<std::uint32_t> PrimRand(1, 6);
	std::uniform_int_distribution<std::uint32_t> FirstRand(0, 1);
	std::uniform_int_distribution<std::uint32_t> OffsetRand(1, 6);

	std::vector<DrawElementsIndirectCommand> Data(COUNT);
	Data[0].primitiveCount = PrimRand(Gen) * 3;
	Data[0].instanceCount = 1;
	Data[0].firstIndex = FirstRand(Gen) == 0 ? 0 : PrimRand(Gen);
	Data[0].baseVertex = 0;
	Data[0].baseInstance = 0;
	for(std::size_t i = 1; i < Data.size(); ++i)
	{
		Data[i].primitiveCount = PrimRand(Gen) * 3;
		Data[i].instanceCount = 1;
		Data[i].firstIndex = Data[i - 1].firstIndex + Data[i - 1].primitiveCount + (std::rand() % 10 ? 0 : OffsetRand(Gen));
		Data[i].baseVertex = 0;
		Data[i].baseInstance = 0;
	}

	// Randomize the data
	std::uniform_int_distribution<std::uint32_t> DataRand(0, Data.size() - 1);
	for(std::size_t i = 0; i < Data.size(); ++i)
	{
		DrawElementsIndirectCommand Temp;
		Temp.primitiveCount = Data[i].primitiveCount;
		Temp.instanceCount = Data[i].instanceCount;
		Temp.firstIndex = Data[i].firstIndex;
		Temp.baseVertex = Data[i].baseVertex;
		Temp.baseInstance = Data[i].baseInstance;

		std::uint32_t SwapIndex = DataRand(Gen);

		Data[i].primitiveCount = Data[SwapIndex].primitiveCount;
		Data[i].instanceCount = Data[SwapIndex].instanceCount;
		Data[i].firstIndex = Data[SwapIndex].firstIndex;
		Data[i].baseVertex = Data[SwapIndex].baseVertex;
		Data[i].baseInstance = Data[SwapIndex].baseInstance;

		Data[SwapIndex].primitiveCount = Temp.primitiveCount;
		Data[SwapIndex].instanceCount = Temp.instanceCount;
		Data[SwapIndex].firstIndex = Temp.firstIndex;
		Data[SwapIndex].baseVertex = Temp.baseVertex;
		Data[SwapIndex].baseInstance = Temp.baseInstance;
	}

	{
		// Actual testing
		std::clock_t TimeStart = std::clock();
		
		// Reording the draws
		std::sort(Data.begin(), Data.end(), less);
		
		std::clock_t TimeEnd = std::clock();

		printf("Repack - sort: %lu ms\n", (TimeEnd - TimeStart) * 1000 /  CLOCKS_PER_SEC);
	}

	// Packing the draws
	std::clock_t TimeStart = std::clock();

	std::size_t j = 0;
	{
		for(std::size_t i = 1; i < Data.size(); ++i)
		{
			if(Data[j].firstIndex + Data[j].primitiveCount == Data[i].firstIndex)
			{
				Data[j].primitiveCount += Data[i].primitiveCount;
			}
			else
			{
				++j;
				Data[j].primitiveCount = Data[i].primitiveCount;
				Data[j].instanceCount = Data[i].instanceCount;
				Data[j].firstIndex = Data[i].firstIndex;
				Data[j].baseVertex = Data[i].baseVertex;
				Data[j].baseInstance = Data[i].baseInstance;
			}
		}

		std::clock_t TimeEnd = std::clock();

		printf("Repack - pack(%lu): %lu ms\n", j, (TimeEnd - TimeStart) * 1000 /  CLOCKS_PER_SEC);
	}

	{
		std::clock_t TimeStart = std::clock();

		//std::vector<DrawElementsIndirectCommand> Result(j + 1);
		//memcpy(&Result[0], &Data[0], Result.size() * sizeof(DrawElementsIndirectCommand));
		Data.resize(j + 1);
		Data.shrink_to_fit();

		std::clock_t TimeEnd = std::clock();

		printf("Repack - shrink: %lu ms\n", (TimeEnd - TimeStart) * 1000 /  CLOCKS_PER_SEC);
	}
}
コード例 #3
0
ファイル: userial.c プロジェクト: KlausMerkert/FreeRail
void rocs_serial_setSerialMode( iOSerial inst, serial_mode mode ) {
  iOSerialData o = Data(inst);
  int errno;
#if defined __APPLE__
#else
  struct termios tio;
  if (!o->directIO) {
    tcgetattr( o->sh, &tio );
    tio.c_cflag &= ~PARENB;
    tio.c_cflag &= ~CSTOPB;
    tio.c_cflag &= ~CSIZE;
  }
  switch (mode) {
  case mm:
  /* Set Uart register for 38400baud Marklin/Motorola*/
    if (o->currserialmode != mm) {
      o->currserialmode = mm;
      if (o->directIO) {
        SystemOp.writePort( o->portbase + 3, 0x80 );
        SystemOp.writePort( o->portbase + 0, 0x03 );
        SystemOp.writePort( o->portbase + 1, 0x00 );
        SystemOp.writePort( o->portbase + 3, 0x01 );
      } else {
        tio.c_cflag |= CS6;
        cfsetospeed( &tio, B38400 );
        cfsetispeed( &tio, B38400 );
      }
    }
    break;
  case dcc:
  /* Set Uart register for 19200baud NMRA DCC */
    if (o->currserialmode != dcc) {
      o->currserialmode = dcc;
      if (o->directIO) {
        SystemOp.writePort( o->portbase + 3, 0x80 );
        SystemOp.writePort( o->portbase + 0, 0x06 );
        SystemOp.writePort( o->portbase + 1, 0x00 );
        SystemOp.writePort( o->portbase + 3, 0x03 );
      } else {
        tio.c_cflag |= CS8;
        cfsetospeed( &tio, B19200 );
        cfsetispeed( &tio, B19200 );
      }
    }
    break;
  case mma:
    if (o->currserialmode != mma) {
      o->currserialmode = mma;
      if (o->directIO) {
        SystemOp.writePort( o->portbase + 3, 0x80 );
        SystemOp.writePort( o->portbase + 0, 0x01 );
        SystemOp.writePort( o->portbase + 1, 0x00 );
        SystemOp.writePort( o->portbase + 3, 0x1F );
      } else {
        tio.c_cflag |= CS8;
        tio.c_cflag |= PARENB;
        tio.c_cflag |= CSTOPB;
        cfsetospeed( &tio, B115200 );
        cfsetispeed( &tio, B115200 );
      }
      break;
    }
    default: TraceOp.trc( __FILE__, TRCLEVEL_ERROR, __LINE__, 9999, "Error setting Serial mode!");
  }
  /* set attribute now */
  if (!o->directIO && tcsetattr( o->sh, TCSAFLUSH, &tio ) != 0)
    TraceOp.terrno( name, TRCLEVEL_WARNING, __LINE__, 9999, errno, "tcsetattr failed!" );
  //        tcgetattr( o->sh, &tio );
  //    TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "Current output baud rate is %d\n", (int) cfgetospeed(&tio) );
#endif
}
コード例 #4
0
void
lcm_ILI9325_setup(
	void
)
{
	#define Command(gw_cmd) 		*pcmd = gw_cmd
	#define Data(gw_data)			*pdata = gw_data

	dispReg_t *pdispReg = (dispReg_t *)(LOGI_ADDR_DISP_REG);
	volatile unsigned short *pcmd = (volatile unsigned short *) &pdispReg->dispLcmPgmIo00;
	volatile unsigned short *pdata = (volatile unsigned short *) &pdispReg->dispLcmPgmIo10;//dispLcmPgmIo30;

	// Start Initial Sequence
	Command(0x00E3);	Data(0x3008); // Set internal timing
	Command(0x00E7);	Data(0x0012); // Set internal timing
	Command(0x00EF);	Data(0x1231); // Set internal timing
	Command(0x0001);	Data(0x0100); // set SS and SM bit
	Command(0x0002);	Data(0x0700); // set 1 line inversion
	Command(0x0003);	Data(0x1018); // set GRAM write direction and BGR=1.
	Command(0x0004);	Data(0x0000); // Resize register
	Command(0x0008);	Data(0x0207); // set the back porch and front porch
	Command(0x0009);	Data(0x0000); // set non-display area refresh cycle ISC[3:0]
	Command(0x000A);	Data(0x0000); // FMARK function
	Command(0x000C);	Data(0x0000); // RGB interface setting
	Command(0x000D);	Data(0x0000); // Frame marker Position
	Command(0x000F);	Data(0x0000); // RGB interface polarity
	// Power On sequence
	Command(0x0010);	Data(0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
	Command(0x0011);	Data(0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
	Command(0x0012);	Data(0x0000); // VREG1OUT voltage
	Command(0x0013);	Data(0x0000); // VDV[4:0] for VCOM amplitude
	mdelay(10); // Dis-charge capacitor power voltage
	Command(0x0010);	Data(0x1490); // SAP, BT[3:0], AP, DSTB, SLP, STB
	Command(0x0011);	Data(0x0227); // DC1[2:0], DC0[2:0], VC[2:0]
	mdelay(10); // Delay 50ms
	Command(0x0012);	Data(0x001D); // Internal reference voltage= Vci;
	mdelay(10); // Delay 50ms
	Command(0x0013);	Data(0x0800); // Set VDV[4:0] for VCOM amplitude
	Command(0x0029);	Data(0x0045); // Set VCM[5:0] for VCOMH
	Command(0x002B);	Data(0x000D); // Set Frame Rate
	mdelay(10); // Delay 50ms
	Command(0x0020);	Data(0x0000); // GRAM horizontal Address
	Command(0x0021);	Data(0x0000); // GRAM Vertical Address
	// Adjust the Gamma Curve
	Command(0x0030);	Data(0x0007);
	Command(0x0031);	Data(0x0707);
	Command(0x0032);	Data(0x0006);
	Command(0x0035);	Data(0x0704);
	Command(0x0036);	Data(0x1F04);
	Command(0x0037);	Data(0x0004);
	Command(0x0038);	Data(0x0000);
	Command(0x0039);	Data(0x0706);
	Command(0x003C);	Data(0x0701);
	Command(0x003D);	Data(0x000F);
	// Set GRAM area
	Command(0x0050);	Data(0x0000); // Horizontal GRAM Start Address
	Command(0x0051);	Data(0x00EF); // Horizontal GRAM End Address
	Command(0x0052);	Data(0x0000); // Vertical GRAM Start Address
	Command(0x0053);	Data(0x013F); // Vertical GRAM Start Address
	Command(0x0060);	Data(0xA700); // Gate Scan Line
	Command(0x0061);	Data(0x0001); // NDL,VLE, REV
	Command(0x006A);	Data(0x0000); // set scrolling line
	// Partial Display Control
	Command(0x0080);	Data(0x0000);
	Command(0x0081);	Data(0x0000);
	Command(0x0082);	Data(0x0000);
	Command(0x0083);	Data(0x0000);
	Command(0x0084);	Data(0x0000);
	Command(0x0085);	Data(0x0000);
	// Panel Control
	Command(0x0090);	Data(0x0010);
	Command(0x0092);	Data(0x0600);
	Command(0x0093);	Data(0x0003);
	Command(0x0095);	Data(0x0110);
	Command(0x0097);	Data(0x0000);
	Command(0x0098);	Data(0x0000);
	Command(0x0007);	Data(0x0133); // 262K color and display ON

	Command(0x0022);
}
コード例 #5
0
ファイル: zstring.cpp プロジェクト: WChrisK/Zandronum
FString::~FString ()
{
	Data()->Release();
}
コード例 #6
0
ファイル: blob.hpp プロジェクト: jemmyw/openttd
	/** Return pointer to the index-th data item - non-const version */
	FORCEINLINE T *Data(size_t index)
	{
		CheckIdx(index);
		return (Data() + index);
	}
コード例 #7
0
ファイル: gametask.hpp プロジェクト: 655473/fallout-equestria
 Data                  GetItemIndex(void)      { return (item_index ? Data(item_index) : Data()); }
コード例 #8
0
ファイル: sprog.c プロジェクト: TheMRod/Rocrail
static int __translate( iOSprog sprog, iONode node, char* outa, int* insize ) {
  iOSprogData data = Data(sprog);
  int repeat = 1;

  outa[0] = '\0';
  *insize = 0;


  /* System command. */
  if( StrOp.equals( NodeOp.getName( node ), wSysCmd.name() ) ) {
    const char* cmd = wSysCmd.getcmd( node );
    if( StrOp.equals( cmd, wSysCmd.stop ) || StrOp.equals( cmd, wSysCmd.ebreak ) ) {
      TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "Power OFF" );
      StrOp.fmtb( outa, "-\r" );
      data->power = False;
    }
    else if( StrOp.equals( cmd, wSysCmd.go ) ) {
      TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "Power ON" );
      StrOp.fmtb( outa, "+\r" );
      data->power = True;
    }
  }

  /* Switch command. */
  else if( StrOp.equals( NodeOp.getName( node ), wSwitch.name() ) ) {

    int addr = wSwitch.getaddr1( node );
    int port = wSwitch.getport1( node );
    int gate = wSwitch.getgate1( node );
    int fada = 0;
    int pada = 0;
    int dir  = 1;
    int action = 1;
    int cmdsize = 0;
    byte dcc[12];
    char cmd[32] = {0};

    if( port == 0 ) {
      fada = addr;
      AddrOp.fromFADA( addr, &addr, &port, &gate );
    }
    else if( addr == 0 && port > 0 ) {
      pada = port;
      AddrOp.fromPADA( port, &addr, &port );
    }

    if( fada == 0 )
      fada = AddrOp.toFADA( addr, port, gate );
    if( pada == 0 )
      pada = AddrOp.toPADA( addr, port );

    if( StrOp.equals( wSwitch.getcmd( node ), wSwitch.turnout ) )
      dir = 0; /* thrown */

    if( wSwitch.issinglegate( node ) ) {
      dir = gate;
      if( StrOp.equals( wSwitch.getcmd( node ), wSwitch.straight ) )
        action = 0;
    }

    TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999,
        "turnout %04d %d %-10.10s fada=%04d pada=%04d addr=%d port=%d gate=%d dir=%d action=%d",
        addr, port, wSwitch.getcmd( node ), fada, pada, addr, port, gate, dir, action );

    cmdsize = accDecoderPkt2(dcc, addr, 1, (port-1)*2+dir);
    __byteToStr( cmd, dcc, cmdsize );
    StrOp.fmtb( outa, "O %s\r", cmd );
    TraceOp.trc( name, TRCLEVEL_BYTE, __LINE__, 9999, "DCC out: %s", outa );
    *insize = 3;
    repeat = 2;
  }

  else if( StrOp.equals( NodeOp.getName( node ), wSignal.name() ) ) {
    int addr = wSignal.getaddr(node);
    int port = wSignal.getport1(node);
    int gate = wSignal.getgate1(node);
    int aspect = wSignal.getaspect(node);
    int fada = 0;
    int pada = 0;
    int cmdsize = 0;
    byte dcc[12];
    char cmd[32] = {0};

    if( port == 0 ) {
      fada = addr;
      AddrOp.fromFADA( addr, &addr, &port, &gate );
    }
    else if( addr == 0 && port > 0 ) {
      pada = port;
      AddrOp.fromPADA( port, &addr, &port );
    }

    if( fada == 0 )
      fada = AddrOp.toFADA( addr, port, gate );
    if( pada == 0 )
      pada = AddrOp.toPADA( addr, port );

    TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "signal %04d %d %d fada=%04d pada=%04d aspect=%d",
        addr, port, gate, fada, pada, aspect );


    cmdsize = accSignalDecoderPkt(dcc, addr, aspect);
    /*cmdsize = accDecoderPkt(dcc, fada, action);*/
    __byteToStr( cmd, dcc, cmdsize );
    StrOp.fmtb( outa, "O %s\r", cmd );
    TraceOp.trc( name, TRCLEVEL_BYTE, __LINE__, 9999, "DCC out: %s", outa );
    *insize = 3;
    repeat = 2;
  }

  /* Output command. */
  else if( StrOp.equals( NodeOp.getName( node ), wOutput.name() ) ) {

    int addr = wOutput.getaddr( node );
    int port = wOutput.getport( node );
    int gate = wOutput.getgate( node );
    int fada = 0;
    int pada = 0;
    int cmdsize = 0;
    byte dcc[12];
    char cmd[32] = {0};
    int action = StrOp.equals( wOutput.getcmd( node ), wOutput.on ) ? 0x01:0x00;

    if( port == 0 ) {
      fada = addr;
      AddrOp.fromFADA( addr, &addr, &port, &gate );
    }
    else if( addr == 0 && port > 0 ) {
      pada = port;
      AddrOp.fromPADA( port, &addr, &port );
    }

    if( fada == 0 )
      fada = AddrOp.toFADA( addr, port, gate );
    if( pada == 0 )
      pada = AddrOp.toPADA( addr, port );

    TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "output %04d %d %d fada=%04d pada=%04d",
        addr, port, gate, fada, pada );


    cmdsize = accDecoderPkt2(dcc, addr, action, (port-1)*2+gate);
    /*cmdsize = accDecoderPkt(dcc, fada, action);*/
    __byteToStr( cmd, dcc, cmdsize );
    StrOp.fmtb( outa, "O %s\r", cmd );
    TraceOp.trc( name, TRCLEVEL_BYTE, __LINE__, 9999, "DCC out: %s", outa );
    *insize = 3;
    repeat = 2;
  }

  /* Program command. */
  else if( StrOp.equals( NodeOp.getName( node ), wProgram.name() ) ) {
    Boolean pom = wProgram.ispom( node );

    if( !pom && !data->power ) {
      Boolean direct = wProgram.getmode(node) == wProgram.mode_direct;
      if( wProgram.getcmd( node ) == wProgram.get ) {
        TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "CV %d get", wProgram.getcv(node) );
        StrOp.fmtb( outa, "%c %d\r", direct?'C':'V', wProgram.getcv(node) );
        data->lastcmd = CV_READ;
        data->lastvalue = 0;
      }
      else if( wProgram.getcmd( node ) == wProgram.set ) {
        TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "CV %d set %d", wProgram.getcv(node), wProgram.getvalue(node) );
        StrOp.fmtb( outa, "%c %d %d\r", direct?'C':'V', wProgram.getcv(node), wProgram.getvalue(node) );
        data->lastcmd = CV_WRITE;
        data->lastvalue = wProgram.getvalue(node);
      }
    }
    else if( pom && data->power ) {
      if( wProgram.getcmd( node ) == wProgram.set ) {
        byte dcc[12];
        char cmd[32] = {0};
        int cmdsize = opsCvWriteByte(dcc, wProgram.getaddr(node), wProgram.islongaddr(node), wProgram.getcv(node), wProgram.getvalue(node) );
        __byteToStr( cmd, dcc, cmdsize );
        StrOp.fmtb( outa, "O %s\r", cmd );
        TraceOp.trc( name, TRCLEVEL_BYTE, __LINE__, 9999, "POM DCC out: %s", outa );
        *insize = 3;
      }
    }
    else {
      TraceOp.trc( name, TRCLEVEL_WARNING, __LINE__, 9999, "turn power %s before programming", pom?"ON (POM)":"OFF" );
    }
  }

  /* Loc command. */
  else if( StrOp.equals( NodeOp.getName( node ), wLoc.name() ) ) {
    int slot   = 0;
    int size   = 0;

    TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "Loco command for address %d", wLoc.getaddr( node ) );

    slot =  __getLocoSlot( sprog, node);

    if( slot >= 0 ) {
      int V = 0;
      int steps = wLoc.getspcnt( node );

      TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "Loco slot=%d", slot );

      if( wLoc.getV( node ) != -1 ) {
        if( StrOp.equals( wLoc.getV_mode( node ), wLoc.V_mode_percent ) )
          V = (wLoc.getV( node ) * steps) / 100;
        else if( wLoc.getV_max( node ) > 0 )
          V = (wLoc.getV( node ) * steps) / wLoc.getV_max( node );
      }

      /* keep this value for the ping thread */
      data->slots[slot].dir = wLoc.isdir( node );
      data->slots[slot].V = (V > 127 ? 127:V);
      data->slots[slot].steps = steps;
      data->slots[slot].addr = wLoc.getaddr( node );
      data->slots[slot].longaddr = (wLoc.getaddr( node ) > 127) ? True:False;
      data->slots[slot].lights = wLoc.isfn( node );
      data->slots[slot].fn[0]  = wLoc.isfn( node );
      data->slots[slot].changedfgrp = wLoc.isfn( node ) ? 1:-1;
      data->slots[slot].idle = SystemOp.getTick();

      TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999,
          "slot=%d addr=%d V=%d steps=%d dir=%d long=%d", slot,
          data->slots[slot].addr, data->slots[slot].V, data->slots[slot].steps, data->slots[slot].dir, data->slots[slot].longaddr );

      size = 0;
    }
  }

  /* Function */
  else if( StrOp.equals( NodeOp.getName( node ), wFunCmd.name() ) ) {
    int addr  = wFunCmd.getaddr( node );
    int group = wFunCmd.getgroup( node );

    int slot =  __getLocoSlot( sprog, node);

    if( slot >= 0 ) {
      if( data->slots[slot].addr == 0 ) {
        /* first use of this slot */
        data->slots[slot].addr = addr;
        data->slots[slot].longaddr = (addr > 127) ? True:False;
      }
      data->slots[slot].changedfgrp = group;
      data->slots[slot].lights = wFunCmd.isf0 ( node );
      data->slots[slot].fn[ 0] = wFunCmd.isf0 ( node );
      data->slots[slot].fn[ 1] = wFunCmd.isf1 ( node );
      data->slots[slot].fn[ 2] = wFunCmd.isf2 ( node );
      data->slots[slot].fn[ 3] = wFunCmd.isf3 ( node );
      data->slots[slot].fn[ 4] = wFunCmd.isf4 ( node );
      data->slots[slot].fn[ 5] = wFunCmd.isf5 ( node );
      data->slots[slot].fn[ 6] = wFunCmd.isf6 ( node );
      data->slots[slot].fn[ 7] = wFunCmd.isf7 ( node );
      data->slots[slot].fn[ 8] = wFunCmd.isf8 ( node );
      data->slots[slot].fn[ 9] = wFunCmd.isf9 ( node );
      data->slots[slot].fn[10] = wFunCmd.isf10( node );
      data->slots[slot].fn[11] = wFunCmd.isf11( node );
      data->slots[slot].fn[12] = wFunCmd.isf12( node );
      data->slots[slot].fn[13] = wFunCmd.isf13( node );
      data->slots[slot].fn[14] = wFunCmd.isf14( node );
      data->slots[slot].fn[15] = wFunCmd.isf15( node );
      data->slots[slot].fn[16] = wFunCmd.isf16( node );
      data->slots[slot].fn[17] = wFunCmd.isf17( node );
      data->slots[slot].fn[18] = wFunCmd.isf18( node );
      data->slots[slot].fn[19] = wFunCmd.isf19( node );
      data->slots[slot].fn[20] = wFunCmd.isf20( node );
      data->slots[slot].fn[21] = wFunCmd.isf21( node );
      data->slots[slot].fn[22] = wFunCmd.isf22( node );
      data->slots[slot].fn[23] = wFunCmd.isf23( node );
      data->slots[slot].fn[24] = wFunCmd.isf24( node );
      data->slots[slot].fn[25] = wFunCmd.isf25( node );
      data->slots[slot].fn[26] = wFunCmd.isf26( node );
      data->slots[slot].fn[27] = wFunCmd.isf27( node );
      data->slots[slot].fn[28] = wFunCmd.isf28( node );

      TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999,
          "slot=%d function group %d changed for loco %d", slot, group, addr );
    }
  }


  return repeat;

}
コード例 #9
0
ファイル: sprog.c プロジェクト: TheMRod/Rocrail
static Boolean _setListener( obj inst ,obj listenerObj ,const digint_listener listenerFun ) {
  iOSprogData data = Data(inst);
  data->listenerObj = listenerObj;
  data->listenerFun = listenerFun;
  return True;
}
コード例 #10
0
ファイル: sprog.c プロジェクト: TheMRod/Rocrail
static const char* __id( void* inst ) {
  iOSprogData data = Data(inst);
  return data->iid;
}
コード例 #11
0
ファイル: sprog.c プロジェクト: TheMRod/Rocrail
static void* __event( void* inst, const void* evt ) {
  iOSprogData data = Data(inst);
  return NULL;
}
コード例 #12
0
ファイル: sprog.c プロジェクト: TheMRod/Rocrail
static void* __properties( void* inst ) {
  iOSprogData data = Data(inst);
  return data->ini;
}
コード例 #13
0
ファイル: main.c プロジェクト: DusteDdk/eoEdit
int main(int argc, char *argv[])
{
	//All must bow for the migthy vector of DOOOOM!
  vec3 p;

  eoInitAll(argc, argv, DATADIR);
  
  //Enable mouse-selection
  eoGameEnableMouseSelection(0.2);

  eoExec("testbox 1");
  //Load the cursor
  sprite_base* dcur_sprb = eoSpriteBaseLoad(Data("/data/gfx/","cursor.spr"));
  dcur_spr = eoSpriteNew( dcur_sprb, 1, 1 );


  sprite_base* hcur_sprb = eoSpriteBaseLoad(Data("/data/gfx/","cursorH.spr"));
  hcur_spr = eoSpriteNew( hcur_sprb, 1, 1 );


  //Setup the 2D gui context
  ingameContext = eoGuiContextCreate();


  winHalp = eoGuiAddWindow(ingameContext, 10, 10, 200, 50, "Halp", NULL);

  int lblOffset=0, lblInc=13;
  eoGuiAddLabel(winHalp, 0, 0, "F1 = Console");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "h = Toggle Halp");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "click = Select Obj");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "u,o = obj move y");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "i,j,k,l  = obj move x/z");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "8,9= obj rot around y");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "space =free/lock camera");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "del = delete selected object");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "shift = move slower");
  lblOffset+=lblInc;

  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "Cmds:");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "-------------");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "quit 1");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "addat /dir/file.obj className");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "add /dir/file.obj className");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "rot x y z");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "pos x y z");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "class [newClassName]");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "save FILENAME.lvl");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "merge FILENAME.lvl");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "pinc [num]");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "rinc [num]");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "testbox [0 or 1]");
  eoGuiAddLabel(winHalp, 0, lblOffset+=lblInc, "hitbox [0 or 1]");

  winHalp->_size.y +=lblOffset;

  winObjInfo = eoGuiAddWindow(ingameContext, eoSetting()->res.x- 160, eoSetting()->res.y - 110, 150,100, "Object Info", NULL );
  lblInfoClassName = eoGuiAddLabel( winObjInfo, 0,0, "Class: No Object                                                ");
  lblInfoId = eoGuiAddLabel( winObjInfo, 0,10, "Id: No Object                                                         ");
  lblInfoPos = eoGuiAddLabel( winObjInfo, 0,20, "Pos: No Object                                                       ");
  lblInfoRot = eoGuiAddLabel( winObjInfo, 0,30, "Rot: No Object                                                       ");




  hackyPos.x = 0;
  hackyPos.y = 2.5;
  hackyPos.z = 0;
  eoCamPosSet( hackyPos );
  hackyPos.x = 0;
  hackyPos.y = 0;
  hackyPos.z = -10;
  eoCamTargetSet( hackyPos );

  eoExec( "camfree 1" );

  eoFuncAdd( conLoadObj, NULL, "add");
  eoFuncAdd( conLoadObjP, NULL, "addat");
  eoFuncAdd( conRotObj, NULL, "rot");
  eoFuncAdd( conPosObj, NULL, "pos");
  eoFuncAdd( conClassObj, NULL, "class");

  eoFuncAdd( conMergeLevel, NULL, "merge");
  eoFuncAdd( conSaveLevel, NULL, "save");

  eoVarAdd(CON_TYPE_VEC3,0, &hackyPos, "_selectedPos");
  eoVarAdd(CON_TYPE_VEC3,0, &hackyRot, "_selectedRot");


  eoVarAdd(CON_TYPE_FLOAT,0, &rinc, "rinc");
  eoVarAdd(CON_TYPE_FLOAT,0, &pinc, "pinc");

  //Set active context
  eoGuiContextSet(ingameContext);


  eoGuiWarpMouse( eoSetting()->res.x/2, eoSetting()->res.y/2 );

  //Set camera to somewhere
  p.x=14;
  p.y=2;
  p.z=-2.5;
  eoCamPosSet(p);

  p.x=-8.52066;
  p.y=2.107272;
  p.z=7.96192;
  //and at something
  eoCamTargetSet( p );

  //Enable 2Dinterface
  eoGuiShow();
  eoGuiShowCursor(1);
  
  //Pause simulation
  eoPauseSet(FALSE);

  //Register callback function
  eoRegisterStartFrameFunc( frameStart );

  //Set some GL light stuffs
  GLfloat global_ambient[] = { 0.2f, 0.2f, 0.2f, 2.0f };
  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);

  GLfloat pos[] = { 10,10,10,0 }; //Last pos: 0 = dir, 1=omni
  glLightfv( GL_LIGHT0, GL_POSITION, pos );

  GLfloat specular[] = {0.0, 0.0, 0.0, 1.0};
  glLightfv(GL_LIGHT0, GL_SPECULAR, specular);


  eoInpAddFunc( "exit", "Exit the game.", inpQuitFunc, INPUT_FLAG_DOWN);

  eoInpAddFunc( "halp", "Toggle the halp window.", inpToggleHalp, INPUT_FLAG_DOWN);
  eoExec("bind h halp");

  eoInpAddFunc( "camtoggle", "Toggle the camfree.", inpToggleCam, INPUT_FLAG_DOWN);
  eoExec("bind space camtoggle");

  eoInpAddFunc( "objMoveUp", "Move currently selected object up along Y.", inpMoveObjUp, INPUT_FLAG_HOLD);
  eoInpAddFunc( "objMoveDn", "Move currently selected object down along Y.", inpMoveObjDn, INPUT_FLAG_HOLD);
  eoInpAddFunc( "objMoveLeft", "Move currently selected object down along X.", inpMoveObjLeft, INPUT_FLAG_HOLD);
  eoInpAddFunc( "objMoveRight", "Move currently selected object up along X.", inpMoveObjRight, INPUT_FLAG_HOLD);
  eoInpAddFunc( "objMoveForward", "Move currently selected object down along Z.", inpMoveObjForward, INPUT_FLAG_HOLD);
  eoInpAddFunc( "objMoveBackward", "Move currently selected object up along Z.", inpMoveObjBackward, INPUT_FLAG_HOLD);
  eoInpAddFunc( "objRotYCW", "Rotate around Y clockwise.", inpRotYPlus, INPUT_FLAG_HOLD);
  eoInpAddFunc( "objRotYCCW", "Rotate around Y counter-clockwise.", inpRotYMinus, INPUT_FLAG_HOLD);
  eoInpAddFunc( "objSlow", "Make movement and rotation slow.", inpSlowObj, INPUT_FLAG_UP|INPUT_FLAG_DOWN);
  eoInpAddFunc( "objRm", "Remove object", inpObjRm, INPUT_FLAG_DOWN);

  eoExec("bind u objMoveUp");
  eoExec("bind o objMoveDn");
  eoExec("bind i objMoveForward");
  eoExec("bind k objMoveBackward");
  eoExec("bind j objMoveLeft");
  eoExec("bind l objMoveRight");
  eoExec("bind 8 objRotYCW");
  eoExec("bind 9 objRotYCCW");
  eoExec("bind shiftl objSlow");
  eoExec("bind delete objRm");

  eoMainLoop();

  return 0;
}
コード例 #14
0
ファイル: archivebox.c プロジェクト: pmansvelder/Rocrail
static iONode _getCategory( obj inst ,const char* category ) {
    iOArchiveBoxData data = Data(inst);
    TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "get category [%s]", category );
    return NULL;
}
コード例 #15
0
ファイル: Boundary_Data.hpp プロジェクト: kravitz/transims4
	void Speed (int period, int value)      { Data (period, 1, value); }
コード例 #16
0
ファイル: sprog.c プロジェクト: TheMRod/Rocrail
/** bit0=power, bit1=programming, bit2=connection */
static int _state( obj inst ) {
  iOSprogData data = Data(inst);
  return 0;
}
コード例 #17
0
double
get_slack_estimate(const ParticlesTemp& ps,
                   double upper_bound,
                   double step,
                   const RestraintsTemp &restraints,
                   bool derivatives,
                   Optimizer *opt,
                   ClosePairContainer *cpc) {
  std::vector<Data> datas;
  for (double slack=0; slack< upper_bound; slack+= step) {
    IMP_LOG(VERBOSE, "Computing for " << slack << std::endl);
    datas.push_back(Data());
    datas.back().slack=slack;
    {
      boost::timer imp_timer;
      int count=0;
      base::SetLogState sl(opt->get_model(), SILENT);
      do {
        cpc->set_slack(slack);
        cpc->update();
        ++count;
      } while (imp_timer.elapsed()==0);
      datas.back().ccost= imp_timer.elapsed()/count;
      IMP_LOG(VERBOSE, "Close pair finding cost "
              << datas.back().ccost << std::endl);
    }
    {
      boost::timer imp_timer;
      double score=0;
      int count=0;
      int iters=1;
      base::SetLogState sl(opt->get_model(), SILENT);
      do {
        for ( int j=0; j< iters; ++j) {
          for (unsigned int i=0; i< restraints.size(); ++i) {
            score+=restraints[i]->evaluate(derivatives);
            // should restore
          }
        }
        count += iters;
        iters*=2;
      } while (imp_timer.elapsed()==0);
      datas.back().rcost= imp_timer.elapsed()/count;
      IMP_LOG(VERBOSE, "Restraint evaluation cost "
              << datas.back().rcost << std::endl);
    }
  }
  int ns=100;
  int last_ns=1;
  int opt_i=-1;
  std::vector<Floats > dists(1, Floats(1,0.0));
  std::vector< std::vector<algebra::Vector3D> >
    pos(1, std::vector<algebra::Vector3D>(ps.size()));
  for (unsigned int j=0; j< ps.size(); ++j) {
    pos[0][j]=core::XYZ(ps[j]).get_coordinates();
  }
  do {
    IMP_LOG(VERBOSE, "Stepping from " << last_ns << " to " << ns << std::endl);
    dists.resize(ns, Floats(ns, 0.0));
    for ( int i=0; i< last_ns; ++i) {
      dists[i].resize(ns, 0.0);
    }
    pos.resize(ns,  std::vector<algebra::Vector3D>(ps.size()));
    base::SetLogState sl(opt->get_model(), SILENT);
    for ( int i=last_ns; i< ns; ++i) {
      opt->optimize(1);
      for (unsigned int j=0; j< ps.size(); ++j) {
        pos[i][j]=core::XYZ(ps[j]).get_coordinates();
      }
    }
    for ( int i=last_ns; i< ns; ++i) {
      for ( int j=0; j< i; ++j) {
        double md=0;
        for (unsigned int k=0; k< ps.size(); ++k) {
          md= std::max(md, algebra::get_distance(pos[i][k], pos[j][k]));
        }
        dists[i][j]=md;
        dists[j][i]=md;
      }
    }
    // estimate lifetimes from slack
    for (unsigned int i=0; i< datas.size(); ++i) {
      Ints deaths;
      for ( int j=0; j< ns; ++j) {
        for ( int k=j+1; k < ns; ++k) {
          if (dists[j][k]> datas[i].slack) {
            deaths.push_back(k-j);
            break;
          }
        }
      }
      std::sort(deaths.begin(), deaths.end());
      // kaplan meier estimator
      double ml=0;
      if (deaths.empty()) {
        ml= ns;
      } else {
        //double l=1;
        IMP_INTERNAL_CHECK(deaths.size() < static_cast<unsigned int>(ns),
                           "Too much death");
        double S=1;
        for (unsigned int j=0; j< deaths.size(); ++j) {
          double n= ns-j;
          double t=(n-1.0)/n;
          ml+=(S-t*S)*deaths[j];
          S*=t;
        }
      }
      datas[i].lifetime=ml;
      IMP_LOG(VERBOSE, "Expected life of " << datas[i].slack
              << " is " << datas[i].lifetime << std::endl);
    }

    /**
       C(s) is cost to compute
       R(s) is const to eval restraints
       L(s) is lifetime of slack
       minimize C(s)/L(s)+R(s)
    */
    // smooth
    for (unsigned int i=1; i< datas.size()-1; ++i) {
      datas[i].rcost=(datas[i].rcost+ datas[i-1].rcost+datas[i+1].rcost)/3.0;
      datas[i].ccost=(datas[i].ccost+ datas[i-1].ccost+datas[i+1].ccost)/3.0;
      datas[i].lifetime=(datas[i].lifetime
                      + datas[i-1].lifetime+datas[i+1].lifetime)/3.0;
    }
    double min= std::numeric_limits<double>::max();
    for (unsigned int i=0; i< datas.size(); ++i) {
      double v= datas[i].rcost+ datas[i].ccost/datas[i].lifetime;
      IMP_LOG(VERBOSE, "Cost of " << datas[i].slack << " is " << v
              << " from " << datas[i].rcost
              << " " << datas[i].ccost << " " << datas[i].lifetime
              << std::endl);
      if (v < min) {
        min=v;
        opt_i=i;
      }
    }
    last_ns=ns;
    ns*=2;
    IMP_LOG(VERBOSE, "Opt is " << datas[opt_i].slack << std::endl);
    // 2 for the value, 2 for the doubling
    // if it more than 1000, just decide that is enough
  } while (datas[opt_i].lifetime > ns/4.0 && ns <1000);
  return datas[opt_i].slack;
}
コード例 #18
0
ファイル: sprog.c プロジェクト: TheMRod/Rocrail
/* external shortcut event */
static void _shortcut(obj inst) {
  iOSprogData data = Data( inst );
}
コード例 #19
0
ファイル: blob.hpp プロジェクト: jemmyw/openttd
	/** Return pointer to the index-th data item - const version */
	FORCEINLINE const T *Data(size_t index) const
	{
		CheckIdx(index);
		return (Data() + index);
	}
コード例 #20
0
ファイル: sprog.c プロジェクト: TheMRod/Rocrail
static Boolean _supportPT( obj inst ) {
  iOSprogData data = Data(inst);
  return False;
}
コード例 #21
0
ファイル: Xcup.c プロジェクト: izaackgerard/Sintetizador_Voz
Status
XcupStoreColors(
    Display* dpy,
    Colormap colormap,
    XColor* colors_in_out,
    int ncolors)
{
    XExtDisplayInfo *info = find_display (dpy);
    xXcupStoreColorsReply rep;
    xXcupStoreColorsReq *req;
    xColorItem rbuf[256];
    xColorItem citem;
    int i;
    XColor* xcp;

    XextCheckExtension (dpy, info, xcup_extension_name, False);

    LockDisplay(dpy);
    GetReq(XcupStoreColors, req);
    req->reqType = info->codes->major_opcode;
    req->xcupReqType = X_XcupStoreColors;
    req->cmap = colormap;
    req->length += (ncolors * SIZEOF(xColorItem)) >> 2;

    for (i = 0, xcp = colors_in_out; i < ncolors; i++, xcp++) {
	citem.pixel = xcp->pixel;
	citem.red = xcp->red;
	citem.green = xcp->green;
	citem.blue = xcp->blue;

	/* note that xColorItem doesn't contain all 16-bit quantities, so
	   we can't use Data16 */
	Data(dpy, (char *)&citem, (long) SIZEOF(xColorItem));
    }

    if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
	long nbytes;
	xColorItem* rbufp;
	xColorItem* cs;
	int nentries = rep.length / 3;

	nbytes = nentries * SIZEOF (xColorItem);

	if (nentries != ncolors) {
	    _XEatData (dpy, (unsigned long) nbytes);
	    UnlockDisplay (dpy);
	    SyncHandle ();
	    return False;
	}

	if (ncolors > 256)
	    rbufp = (xColorItem*) Xmalloc (nbytes);
	else
	    rbufp = rbuf;

	if (rbufp == NULL) {
	    _XEatData (dpy, (unsigned long) nbytes);
	    UnlockDisplay (dpy);
	    SyncHandle ();
	    return False;

	}

	_XRead (dpy, (char*) rbufp, nbytes);

	for (i = 0, xcp = colors_in_out, cs = rbufp; i < ncolors; i++, xcp++, cs++) {
	    xcp->pixel = cs->pixel;
	    xcp->red = cs->red;
	    xcp->green = cs->green;
	    xcp->blue = cs->blue;
	    xcp->flags = cs->flags;
	}
	if (rbufp != rbuf) XFree ((char*)rbufp);

	UnlockDisplay(dpy);
	SyncHandle();
	return True;
    }
    UnlockDisplay(dpy);
    SyncHandle();
    return False;
}
コード例 #22
0
ファイル: sprog.c プロジェクト: TheMRod/Rocrail
static int _version( obj inst ) {
  iOSprogData data = Data(inst);
  return vmajor*10000 + vminor*100 + patch;
}
コード例 #23
0
ファイル: zstring.cpp プロジェクト: WChrisK/Zandronum
void FString::AllocBuffer (size_t len)
{
	Chars = (char *)(FStringData::Alloc(len) + 1);
	Data()->Len = (unsigned int)len;
}
コード例 #24
0
ファイル: sprog.c プロジェクト: TheMRod/Rocrail
static void __sprogWriter( void* threadinst ) {
  iOThread th = (iOThread)threadinst;
  iOSprog sprog = (iOSprog)ThreadOp.getParm( th );
  iOSprogData data = Data(sprog);
  int slotidx = 0;

  TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "SPROG writer started." );

  while(data->run) {

    ThreadOp.sleep(25);

    if( data->power ) {
      if( data->slots[slotidx].addr > 0 ) {
        byte dcc[12];
        char cmd[32] = {0};
        char out[64] = {0};
        char in [64] = {0};
        TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "slot refresh for %d", data->slots[slotidx].addr );

        if( data->slots[slotidx].V == data->slots[slotidx].V_prev && data->slots[slotidx].changedfgrp == 0 ) {
          if( data->slots[slotidx].idle + 8000 < SystemOp.getTick() ) {
            TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999,
                "slot %d purged for loco address %d", slotidx, data->slots[slotidx].addr );
            data->slots[slotidx].addr = 0;
            data->slots[slotidx].idle = 0;
            data->slots[slotidx].fgrp = 0;
            data->slots[slotidx].changedfgrp = 0;
            data->slots[slotidx].V_prev = 0;
            data->slots[slotidx].V = 0;
            slotidx++;
            continue;
          }
        }
        else {
          data->slots[slotidx].V_prev = data->slots[slotidx].V;
          data->slots[slotidx].fgrp = data->slots[slotidx].changedfgrp;
          data->slots[slotidx].changedfgrp = 0;
          data->slots[slotidx].idle = SystemOp.getTick();
        }


        if( data->slots[slotidx].steps > 28 )  {
          int size = speedStep128Packet(dcc, data->slots[slotidx].addr,
              data->slots[slotidx].longaddr, data->slots[slotidx].V, data->slots[slotidx].dir );
          __byteToStr( cmd, dcc, size );
          StrOp.fmtb( out, "O %s\r", cmd );
          TraceOp.trc( name, TRCLEVEL_BYTE, __LINE__, 9999, "128 DCC out: %s", out );
          __transact( sprog, out, StrOp.len(out), in, 3, 1 );
        }
        else if( data->slots[slotidx].steps == 28 )  {
          int size = speedStep28Packet(dcc, data->slots[slotidx].addr,
              data->slots[slotidx].longaddr, data->slots[slotidx].V, data->slots[slotidx].dir );
          __byteToStr( cmd, dcc, size );
          StrOp.fmtb( out, "O %s\r", cmd );
          TraceOp.trc( name, TRCLEVEL_BYTE, __LINE__, 9999, "28 DCC out: %s", out );
          __transact( sprog, out, StrOp.len(out), in, 3, 1 );
        }
        else {
          int size = speedStep14Packet(dcc, data->slots[slotidx].addr,
              data->slots[slotidx].longaddr, data->slots[slotidx].V,
              data->slots[slotidx].dir, data->slots[slotidx].lights );
          __byteToStr( cmd, dcc, size );
          StrOp.fmtb( out, "O %s\r", cmd );
          TraceOp.trc( name, TRCLEVEL_BYTE, __LINE__, 9999, "14 DCC out: %s", out );
          __transact( sprog, out, StrOp.len(out), in, 3, 1 );
        }

        if( data->slots[slotidx].fgrp > 0 ) {
          int size = 0;

          ThreadOp.sleep(25);
          if( data->slots[slotidx].fgrp == 1 ) {
            size = function0Through4Packet(dcc, data->slots[slotidx].addr,
                data->slots[slotidx].longaddr,
                data->slots[slotidx].fn[0],
                data->slots[slotidx].fn[1],
                data->slots[slotidx].fn[2],
                data->slots[slotidx].fn[3],
                data->slots[slotidx].fn[4] );
          }
          else if( data->slots[slotidx].fgrp == 2 ) {
            size = function5Through8Packet(dcc, data->slots[slotidx].addr,
                data->slots[slotidx].longaddr,
                data->slots[slotidx].fn[5],
                data->slots[slotidx].fn[6],
                data->slots[slotidx].fn[7],
                data->slots[slotidx].fn[8] );
          }
          else if( data->slots[slotidx].fgrp == 3 ) {
            size = function9Through12Packet(dcc, data->slots[slotidx].addr,
                data->slots[slotidx].longaddr,
                data->slots[slotidx].fn[9],
                data->slots[slotidx].fn[10],
                data->slots[slotidx].fn[11],
                data->slots[slotidx].fn[12] );
          }
          else if( data->slots[slotidx].fgrp == 4 || data->slots[slotidx].fgrp == 5 ) {
            size = function13Through20Packet(dcc, data->slots[slotidx].addr,
                data->slots[slotidx].longaddr,
                data->slots[slotidx].fn[13],
                data->slots[slotidx].fn[14],
                data->slots[slotidx].fn[15],
                data->slots[slotidx].fn[16],
                data->slots[slotidx].fn[17],
                data->slots[slotidx].fn[18],
                data->slots[slotidx].fn[19],
                data->slots[slotidx].fn[20] );
          }
          else if( data->slots[slotidx].fgrp == 6 || data->slots[slotidx].fgrp == 7 ) {
            size = function21Through28Packet(dcc, data->slots[slotidx].addr,
                data->slots[slotidx].longaddr,
                data->slots[slotidx].fn[21],
                data->slots[slotidx].fn[22],
                data->slots[slotidx].fn[23],
                data->slots[slotidx].fn[24],
                data->slots[slotidx].fn[25],
                data->slots[slotidx].fn[26],
                data->slots[slotidx].fn[27],
                data->slots[slotidx].fn[28] );
          }

          __byteToStr( cmd, dcc, size );
          StrOp.fmtb( out, "O %s\r", cmd );
          TraceOp.trc( name, TRCLEVEL_BYTE, __LINE__, 9999, "function group %d DCC out: %s", data->slots[slotidx].changedfgrp, out );
          __transact( sprog, out, StrOp.len(out), in, 3, 1 );
        }

        slotidx++;
      }
      else {
        slotidx = 0;
      }
    }


  };

  TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "SPROG writer ended." );
  ThreadOp.base.del(th);
}
コード例 #25
0
ファイル: zstring.cpp プロジェクト: WChrisK/Zandronum
void FString::VFormat (const char *fmt, va_list arglist)
{
	Data()->Release();
	Chars = (char *)(FStringData::Alloc(128) + 1);
	StringFormat::VWorker (FormatHelper, this, fmt, arglist);
}
コード例 #26
0
ファイル: sprog.c プロジェクト: TheMRod/Rocrail
static void __sprogReader( void* threadinst ) {
  iOThread th = (iOThread)threadinst;
  iOSprog sprog = (iOSprog)ThreadOp.getParm( th );
  iOSprogData data = Data(sprog);

  char in[256] = {0};
  int idx = 0;
  int retry = 0;

  TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "SPROG reader started." );
  ThreadOp.sleep( 1000 );

  StrOp.fmtb( in, "?\r" );
  __transact( sprog, in, StrOp.len(in), NULL, 0, 1 );

  do {

    ThreadOp.sleep( 10 );

    if( data->run && data->commOK && MutexOp.wait( data->mux ) ) {
      int available = SerialOp.available(data->serial);
      if( available > 0 ) {
        if( SerialOp.read(data->serial, &in[idx], 1) ) {
          TraceOp.dump( NULL, TRCLEVEL_DEBUG, (char*)in, StrOp.len(in) );
          if( idx > 254 ) {
            in[idx] = 0;
            TraceOp.trc( name, TRCLEVEL_WARNING, __LINE__, 9999, "reader overflow [%d]\n%s", idx, in );
            idx = 0;
          }
          else if( in[idx] == '\r' || in[idx] == '\n' ) {
            in[idx+1] = '\0';
            StrOp.replaceAll( in, '\n', '\0' );
            StrOp.replaceAll( in, '\r', '\0' );
            if( StrOp.len(in) > 0 ) {
              TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "SPROG read: [%s]", in );
              __handleResponse(sprog, in);
            }
            idx = 0;
            in[idx] = '\0';
          }
          else if( StrOp.equals( in, "P> ") || StrOp.equals( in, " P>") || StrOp.equals( in, " P> ") ) {
            idx = 0;
            in[idx] = '\0'; /* ignore prompt */
          }
          else {
            idx++;
          }
        }
      }
      else if( available == -1 || SerialOp.getRc(data->serial) > 0 ) {
        /* device error */
        data->commOK = False;
        SerialOp.close(data->serial);
        TraceOp.trc( name, TRCLEVEL_EXCEPTION, __LINE__, 9999, "device error" );
      }

      /* Release the mutex. */
      MutexOp.post( data->mux );
    }
    else if(!data->commOK) {
      retry++;
      if( retry >= 500 ) {
        retry = 0;
        data->commOK = SerialOp.open( data->serial );
        if(data->commOK) {
          SerialOp.setDTR(data->serial, True);
          SerialOp.setRTS(data->serial, True);
        }
      }
    }

  } while(data->run);

  TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "SPROG reader ended." );
  ThreadOp.base.del(th);
}
コード例 #27
0
ファイル: userial.c プロジェクト: KlausMerkert/FreeRail
/**
 * /dev/ttyS0 == com1
 * /dev/ttyS1 == com2
 */
Boolean rocs_serial_open( iOSerial inst ) {
#ifdef __ROCS_SERIAL__
  iOSerialData o = Data(inst);
  char* device = o->device;
  int r,w;
  int symbps, actbps;

  /* open read/write, no controlling terminal */
  if( StrOp.equalsi( "com1", o->device ) )
    device = "/dev/ttyS0";
  else if( StrOp.equalsi( "com2", o->device ) )
    device = "/dev/ttyS1";
  else if( StrOp.equalsi( "com3", o->device ) )
    device = "/dev/ttyS2";
  else if( StrOp.equalsi( "com4", o->device ) )
    device = "/dev/ttyS3";

  /*
  ttyS0 3F8
  ttyS1 2F8
  ttyS2 3E8
  ttyS3 2E8
  */
  if( o->portbase == 0 ) {
    if( StrOp.equals( "/dev/ttyS0", device ) )
      o->portbase = 0x3F8;
    else if( StrOp.equals( "/dev/ttyS1", device ) )
      o->portbase = 0x2F8;
    else if( StrOp.equals( "/dev/ttyS2", device ) )
      o->portbase = 0x3E8;
    else if( StrOp.equals( "/dev/ttyS3", device ) )
      o->portbase = 0x2E8;
  }

#if defined __APPLE__ || defined __OpenBSD__
    o->directIO=False;
#else
  if( o->portbase > 0 && ioperm(o->portbase, 8, 1) == 0 ) {
    /* Simple test for 16550 compatible Uart by writing to and read back from scratch register */
    SystemOp.writePort( o->portbase + 7, 0x55 );
    if (SystemOp.readPort( o->portbase + 7 )==0x55)
      o->directIO= True;
    else
      o->directIO= False;
  } else {
    o->directIO=False;
  }
#endif

  //    o->directIO=False; //Test, remove
  errno = 0;
  o->sh = open( device, O_RDWR | O_TRUNC | O_NONBLOCK | O_NOCTTY  );

  r = access( device, R_OK );
  w = access( device, W_OK );

  TraceOp.terrno( name, TRCLEVEL_INFO, __LINE__, 9999, errno, "open rc=%d read=%d write=%d", errno, r, w );

  if( o->sh > 0 ) {
    struct termios tio;

    TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "blocking[%d] directIO[%d]", o->blocking, o->directIO);
#if defined __APPLE__ || defined __OpenBSD__
#else
    if( o->divisor > 0 ) {
      struct serial_struct serial;
      ioctl(o->sh, TIOCGSERIAL, &serial);
      serial.custom_divisor = o->divisor;
      serial.flags &= ~ASYNC_USR_MASK;
      serial.flags |= ASYNC_SPD_CUST | ASYNC_LOW_LATENCY;
      ioctl(o->sh, TIOCSSERIAL, &serial);
    } else {
      struct serial_struct serial;
      ioctl(o->sh, TIOCGSERIAL, &serial);
      serial.custom_divisor = 0;
      serial.flags = 0;
      ioctl(o->sh, TIOCSSERIAL, &serial);
    }
#endif

    tcgetattr( o->sh, &tio );

    /***** CONTROL FLAGS: reset */
    tio.c_cflag = 0;
    /* hardwareflow */
#ifdef CRTSCTS

    if( o->line.flow == cts )
      TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "set CRTSCTS" );
    tio.c_cflag |= o->line.flow == cts ? CRTSCTS:0;
#endif
    /* ignore modem, enable receiver */
    tio.c_cflag |= CLOCAL | CREAD;

    /* set data bits */
    tio.c_cflag |= __symbolicBits( o->line.bits );

    /* set parity */
    tio.c_cflag |= o->line.parity != none ? PARENB:0;
    tio.c_cflag |= o->line.parity == odd  ? PARODD:0;

    /* set stop bits */
    tio.c_cflag |= o->line.stopbits == twostopbits ? CSTOPB:0;

    /***** INPUT FLAGS: reset all input control processing */
    /*tio.c_iflag = (IGNBRK | IGNCR);*/
    tio.c_iflag = o->line.parity != none ? INPCK:0;

    /***** OUTPUT FLAGS: reset all output control processing */
    tio.c_oflag = 0;

    /***** LOCAL FLAGS: raw mode */
    tio.c_lflag = NOFLSH;

    /* minimal receive count */
    tio.c_cc[VMIN]  = 0;
    /* set timeout int 1/10 seconds */
    tio.c_cc[VTIME] = (o->timeout.read / 100) ? (o->timeout.read / 100):0;

    /* insert speed */
    symbps = __symbolicSpeed(o->line.bps, &actbps);
    TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "set bps to %d (requested=%d)", actbps, o->line.bps );
    cfsetospeed( &tio, symbps );
    cfsetispeed( &tio, symbps );
    errno = 0;
    tcsetattr( o->sh, TCSANOW, &tio );

#if defined __APPLE__
    if( actbps !=  o->line.bps ) {
      TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "trying IOSSIOSPEED for set bps to %d", o->line.bps );
      if( ioctl(o->sh, IOSSIOSPEED, &o->line.bps) == -1 )
        TraceOp.trc( name, TRCLEVEL_EXCEPTION, __LINE__, 9999, "unable to set bps to %d", o->line.bps );
    }
#endif


    //    TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "rocs_serial_open:tcsetattr rc=%d", errno );
  }

  //  TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "rocs_serial_open rc=%d", errno );
  return o->sh < 0 ? False:True;
#else

  return False;
#endif
}
コード例 #28
0
ファイル: Boundary_Data.hpp プロジェクト: kravitz/transims4
	int  Speed (int period)                 { return (Data (period, 1)); }
コード例 #29
0
void NamedParameterCheck::check(const MatchFinder::MatchResult &Result) {
  const SourceManager &SM = *Result.SourceManager;
  const auto *Function = Result.Nodes.getNodeAs<FunctionDecl>("decl");
  SmallVector<std::pair<const FunctionDecl *, unsigned>, 4> UnnamedParams;

  // Ignore implicitly generated members.
  if (Function->isImplicit())
    return;

  // Ignore declarations without a definition if we're not dealing with an
  // overriden method.
  const FunctionDecl *Definition = nullptr;
  if ((!Function->isDefined(Definition) || Function->isDefaulted() ||
       Function->isDeleted()) &&
      (!isa<CXXMethodDecl>(Function) ||
       cast<CXXMethodDecl>(Function)->size_overridden_methods() == 0))
    return;

  // TODO: Handle overloads.
  // TODO: We could check that all redeclarations use the same name for
  //       arguments in the same position.
  for (unsigned I = 0, E = Function->getNumParams(); I != E; ++I) {
    const ParmVarDecl *Parm = Function->getParamDecl(I);
    if (Parm->isImplicit())
      continue;
    // Look for unnamed parameters.
    if (!Parm->getName().empty())
      continue;

    // Don't warn on the dummy argument on post-inc and post-dec operators.
    if ((Function->getOverloadedOperator() == OO_PlusPlus ||
         Function->getOverloadedOperator() == OO_MinusMinus) &&
        Parm->getType()->isSpecificBuiltinType(BuiltinType::Int))
      continue;

    // Sanity check the source locations.
    if (!Parm->getLocation().isValid() || Parm->getLocation().isMacroID() ||
        !SM.isWrittenInSameFile(Parm->getBeginLoc(), Parm->getLocation()))
      continue;

    // Skip gmock testing::Unused parameters.
    if (auto Typedef = Parm->getType()->getAs<clang::TypedefType>())
      if (Typedef->getDecl()->getQualifiedNameAsString() == "testing::Unused")
        continue;

    // Skip std::nullptr_t.
    if (Parm->getType().getCanonicalType()->isNullPtrType())
      continue;

    // Look for comments. We explicitly want to allow idioms like
    // void foo(int /*unused*/)
    const char *Begin = SM.getCharacterData(Parm->getBeginLoc());
    const char *End = SM.getCharacterData(Parm->getLocation());
    StringRef Data(Begin, End - Begin);
    if (Data.find("/*") != StringRef::npos)
      continue;

    UnnamedParams.push_back(std::make_pair(Function, I));
  }

  // Emit only one warning per function but fixits for all unnamed parameters.
  if (!UnnamedParams.empty()) {
    const ParmVarDecl *FirstParm =
        UnnamedParams.front().first->getParamDecl(UnnamedParams.front().second);
    auto D = diag(FirstParm->getLocation(),
                  "all parameters should be named in a function");

    for (auto P : UnnamedParams) {
      // Fallback to an unused marker.
      StringRef NewName = "unused";

      // If the method is overridden, try to copy the name from the base method
      // into the overrider.
      const auto *M = dyn_cast<CXXMethodDecl>(P.first);
      if (M && M->size_overridden_methods() > 0) {
        const ParmVarDecl *OtherParm =
            (*M->begin_overridden_methods())->getParamDecl(P.second);
        StringRef Name = OtherParm->getName();
        if (!Name.empty())
          NewName = Name;
      }

      // If the definition has a named parameter use that name.
      if (Definition) {
        const ParmVarDecl *DefParm = Definition->getParamDecl(P.second);
        StringRef Name = DefParm->getName();
        if (!Name.empty())
          NewName = Name;
      }

      // Now insert the comment. Note that getLocation() points to the place
      // where the name would be, this allows us to also get complex cases like
      // function pointers right.
      const ParmVarDecl *Parm = P.first->getParamDecl(P.second);
      D << FixItHint::CreateInsertion(Parm->getLocation(),
                                      " /*" + NewName.str() + "*/");
    }
  }
}
コード例 #30
0
ファイル: archivebox.c プロジェクト: pmansvelder/Rocrail
static iOList _find( obj inst ,const char* text, Boolean intext, Boolean incategory, Boolean infilename, Boolean indate, const char* fromdate, const char* todate ) {
    iOArchiveBoxData data = Data(inst);
    TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "find [%s] in [%s] [%d%d%d%d] [%s]-[%s]", text, data->home, intext, incategory, infilename, indate, fromdate, todate );
    return __find(data->home, text, intext, incategory, infilename, indate, fromdate, todate);
}