コード例 #1
0
void Reg_InitNeural()
{
	unsigned char i;
	srand1();
	for (i=0;i<INPUT_NEURONS*HIDDEN_NEURONS;i++)
	{
		weightIH[i]=rand1(MAXWEIGHT);
	}
	for (i=0;i<HIDDEN_NEURONS*OUTPUT_NEURONS;i++)
	{
		weightHO[i]=rand1(MAXWEIGHT);
	}
	for (i=0;i<HIDDEN_NEURONS*HIDDEN_NEURONS;i++)
	{
		weightCH[i]=rand1(MAXWEIGHT);
	}
	for (i=0;i<OUTPUT_NEURONS*OUTPUT_NEURONS;i++)
	{
		weightCO[i]=rand1(MAXWEIGHT);
	}
    for(i=0;i<HIDDEN_NEURONS;i++)
    {
        CH_outputs[i]=0;
    }
    for(i=0;i<OUTPUT_NEURONS;i++)
    {
        CO_outputs[i]=0;
    }

	printf("Network Initialized\r\n");
}
コード例 #2
0
ファイル: r_drive1a.c プロジェクト: markf152/C_Saw
int main(void)
{
    int count;
    unsigned seed;
    int cont = 1;
    char redo = 'y';

    puts("\n");

//    printf("Please enter your choice for seed.\n");
    while (cont) {
        srand1((unsigned int)time(0));    /* reset seed */
        for (count = 0; count < 5; count++)
            printf("%d\n", rand1());
        printf("Hit <enter> to re-run with a new seed or q, then <enter> to quit):\n");
        scanf("%c", &redo);
        if (redo == 'q')
            cont = 0;
    }

    printf("Done.\n");

    puts("\n");

    return 0;
}
コード例 #3
0
ファイル: 5.c プロジェクト: Ricky-Hao/C-Primer-Plus-Demo
int main()
{
	int ar[100];
	for (int n = 0; n < 100; n++)
		ar[n] = rand1(srand1(n));
	sort(ar);
	for (int n = 0; n < 100; n++)
		printf("%d ", ar[n]);
	putchar('\n');
	return 0;
}
コード例 #4
0
int main(){
  int count;
  unsigned seed;
  printf("Please enter your choice for seed.\n");
  while(scanf("%u", &seed) == 1){
    srand1(seed);
    for(count = 0; count < 5; count++)
      printf("%hd\n", rand1());
    printf("Please enter next seed (q to quit):\n");
  }
  puts("Done.");
  return 0;
}
コード例 #5
0
//In-place Fischer-Yates shuffle
void shuffle(Card *deck, unsigned int seed) {
	int cards_left = DECK_SIZE;
	int next_index;
	int cur_index;
	Card temp;
	srand1(seed);
	while (cards_left != 0) {
		next_index = DECK_SIZE - rand1() % cards_left - 1;
		cur_index = DECK_SIZE - cards_left;
		temp = deck[cur_index];
		deck[cur_index] = deck[next_index];
		deck[next_index] = temp;
		cards_left--;
	}
}
コード例 #6
0
ファイル: P352E6.c プロジェクト: ssfdust/C
int main (void)
{
		int i,j;
		int ar[1000];
		int num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0,num6 = 0,num7 = 0,num8 = 0,num9 = 0, num10 = 0;
		srand1( (unsigned int) time(0));

		for ( i = 0;i < 1000;i++ )
				ar[i] = rand1() + 1;
		for ( i = 0;i < 1000;i++ )
		{
				switch (ar[i])
				{
						case 1:num1++;
							   break;
						case 2:num2++;
							   break;
						case 3:num3++;
							   break;
						case 4:num4++;
							   break;
						case 5:num5++;
							   break;
						case 6:num6++;
							   break;
						case 7:num7++;
							   break;
						case 8:num8++;
							   break;
						case 9:num9++;
							   break;
						case 10:num10++;
								break;
				}
		}
		printf ( "1:%d\n",num1 );
		printf ( "2:%d\n",num2 );
		printf ( "3:%d\n",num3 );
		printf ( "4:%d\n",num4 );
		printf ( "5:%d\n",num5 );
		printf ( "6:%d\n",num6 );
		printf ( "7:%d\n",num7 );
		printf ( "8:%d\n",num8 );
		printf ( "9:%d\n",num9 );
		printf ( "10:%d\n",num10 );
		return 0;
}
コード例 #7
0
ファイル: randomTestmain.c プロジェクト: Mo2meN-Ali/x86
int main(void)
{
      int count;
      unsigned seed;
 
      printf("Please enter your choice for seed.\n");
      while (scanf("%u", &seed) == 1)
      {
          srand1(seed);    /* reset seed */
          for (count = 0; count < 5; count++)
              printf("%d\n", rand1());
          printf("Please enter next seed (q to quit):\n");
      }
      printf("Done\n");
 
	  system("pause");
      return 0;
 }   
コード例 #8
0
/*!
 * Physical layer state machine implementation
 */
static void HandleStateMachine()
{
    uint8_t result;

    for ( ;; ) {
        switch ( phyStatus ) {
            case PHY_INITIAL_STATE:
                LOG_TRACE("Radio reset.");
                Radio.Reset();
                /* Random seed initialization */
                srand1(Radio.Random());
                if ( pLoRaDevice->devClass != CLASS_C ) {
                    LOG_TRACE("Radio idle.");
                    phyStatus = PHY_IDLE;
                } else {
                    LOG_TRACE("Radio receiving.");
                    phyStatus = PHY_RECEIVING;
                }
                break;
            case PHY_POWER_DOWN:
                Radio.Sleep();
                LOG_TRACE("Radio idle.");
                phyStatus = PHY_IDLE;
                return;
            case PHY_IDLE:
            {
                result = CheckTx();
                if ( result == ERR_OK ) { /* there was data and it has been sent */
                    phyStatus = PHY_WAIT_FOR_TXDONE;
                    LOG_TRACE("Radio wait tx done.");
                    break; /* process switch again */
                }
                return;
            }
            case PHY_WAIT_FOR_TXDONE:
                if ( phyFlags.Bits.TxDone == 1 ) {
                    phyFlags.Bits.TxDone = 0;
                    if ( pLoRaDevice->devClass != CLASS_C ) {
                        LOG_TRACE("Tx done. Radio power down.");
                        phyStatus = PHY_POWER_DOWN;
                    } else {
                        LOG_TRACE("Radio receiving.");
                        phyStatus = PHY_RECEIVING;
                    }
                    break;
                }
                return;
            case PHY_RECEIVING:
                if ( phyFlags.Bits.RxDone == 1 ) {
                    phyFlags.Bits.RxDone = 0;
                    LOG_TRACE("Rx done. Radio power down.");
                    phyStatus = PHY_POWER_DOWN;
                    break;
                }
                /* Reception window open */
                return;
            case PHY_ADVERTISING:
                return;
            case PHY_TIMEOUT:
                phyStatus = PHY_POWER_DOWN;
                LOG_TRACE("Radio timeout. Radio power down.");
                break;
            case PHY_ERROR:
                phyStatus = PHY_POWER_DOWN;
                LOG_TRACE("Radio error. Radio power down.");
                break;
            default:
                return;
        }
    }
}
コード例 #9
0
ファイル: main.c プロジェクト: Lora-net/LoRaMac-node
/**
 * Main application entry point.
 */
int main( void )
{
    LoRaMacPrimitives_t LoRaMacPrimitives;
    LoRaMacCallback_t LoRaMacCallbacks;
    MibRequestConfirm_t mibReq;

    BoardInitMcu( );
    BoardInitPeriph( );

    DeviceState = DEVICE_STATE_INIT;

    while( 1 )
    {
        switch( DeviceState )
        {
            case DEVICE_STATE_INIT:
            {
                LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm;
                LoRaMacPrimitives.MacMcpsIndication = McpsIndication;
                LoRaMacPrimitives.MacMlmeConfirm = MlmeConfirm;
                LoRaMacPrimitives.MacMlmeIndication = MlmeIndication;
                LoRaMacCallbacks.GetBatteryLevel = BoardGetBatteryLevel;
                LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallbacks, ACTIVE_REGION );

                TimerInit( &TxNextPacketTimer, OnTxNextPacketTimerEvent );

                TimerInit( &Led1Timer, OnLed1TimerEvent );
                TimerSetValue( &Led1Timer, 25 );

                TimerInit( &Led2Timer, OnLed2TimerEvent );
                TimerSetValue( &Led2Timer, 25 );

                mibReq.Type = MIB_ADR;
                mibReq.Param.AdrEnable = LORAWAN_ADR_ON;
                LoRaMacMibSetRequestConfirm( &mibReq );

                mibReq.Type = MIB_PUBLIC_NETWORK;
                mibReq.Param.EnablePublicNetwork = LORAWAN_PUBLIC_NETWORK;
                LoRaMacMibSetRequestConfirm( &mibReq );

#if defined( REGION_EU868 )
                LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON );
#endif
                mibReq.Type = MIB_DEVICE_CLASS;
                mibReq.Param.Class = CLASS_C;
                LoRaMacMibSetRequestConfirm( &mibReq );

                DeviceState = DEVICE_STATE_JOIN;
                break;
            }
            case DEVICE_STATE_JOIN:
            {
#if( OVER_THE_AIR_ACTIVATION != 0 )
                MlmeReq_t mlmeReq;

                // Initialize LoRaMac device unique ID
                BoardGetUniqueId( DevEui );

                mlmeReq.Type = MLME_JOIN;

                mlmeReq.Req.Join.DevEui = DevEui;
                mlmeReq.Req.Join.AppEui = AppEui;
                mlmeReq.Req.Join.AppKey = AppKey;
                mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;

                if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
                {
                    DeviceState = DEVICE_STATE_SLEEP;
                }
                else
                {
                    DeviceState = DEVICE_STATE_CYCLE;
                }
#else
                // Choose a random device address if not already defined in Commissioning.h
                if( DevAddr == 0 )
                {
                    // Random seed initialization
                    srand1( BoardGetRandomSeed( ) );

                    // Choose a random device address
                    DevAddr = randr( 0, 0x01FFFFFF );
                }

                mibReq.Type = MIB_NET_ID;
                mibReq.Param.NetID = LORAWAN_NETWORK_ID;
                LoRaMacMibSetRequestConfirm( &mibReq );

                mibReq.Type = MIB_DEV_ADDR;
                mibReq.Param.DevAddr = DevAddr;
                LoRaMacMibSetRequestConfirm( &mibReq );

                mibReq.Type = MIB_NWK_SKEY;
                mibReq.Param.NwkSKey = NwkSKey;
                LoRaMacMibSetRequestConfirm( &mibReq );

                mibReq.Type = MIB_APP_SKEY;
                mibReq.Param.AppSKey = AppSKey;
                LoRaMacMibSetRequestConfirm( &mibReq );

                mibReq.Type = MIB_NETWORK_JOINED;
                mibReq.Param.IsNetworkJoined = true;
                LoRaMacMibSetRequestConfirm( &mibReq );

                DeviceState = DEVICE_STATE_SEND;
#endif
                break;
            }
            case DEVICE_STATE_SEND:
            {
                if( NextTx == true )
                {
                    PrepareTxFrame( AppPort );

                    NextTx = SendFrame( );
                }
                if( ComplianceTest.Running == true )
                {
                    // Schedule next packet transmission
                    TxDutyCycleTime = 5000; // 5000 ms
                }
                else
                {
                    // Schedule next packet transmission
                    TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND );
                }
                DeviceState = DEVICE_STATE_CYCLE;
                break;
            }
            case DEVICE_STATE_CYCLE:
            {
                DeviceState = DEVICE_STATE_SLEEP;

                // Schedule next packet transmission
                TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime );
                TimerStart( &TxNextPacketTimer );
                break;
            }
            case DEVICE_STATE_SLEEP:
            {
                // Wake up through events
                TimerLowPowerHandler( );
                // Process Radio IRQ
                Radio.IrqProcess( );
                break;
            }
            default:
            {
                DeviceState = DEVICE_STATE_INIT;
                break;
            }
        }
    }
}
コード例 #10
0
ファイル: main.c プロジェクト: AlexanderWiniger/LoRaMac-node
/**
 * Main application entry point.
 */
int main(void)
{
    static uint32_t cnt[] = { 0, 0, 0 };
// Target board initialisation
    BoardInitMcu();
    PRINTF("\r\n\r\nTRACE: Mcu initialized.\r\n");
    BoardInitPeriph();
    PRINTF("TRACE: Peripherals initialized.\r\n");

// Radio initialization
    RadioEvents.TxDone = OnTxDone;
    RadioEvents.RxDone = OnRxDone;
    RadioEvents.TxTimeout = OnTxTimeout;
    RadioEvents.RxTimeout = OnRxTimeout;
    RadioEvents.RxError = OnRxError;
    RadioEvents.CadDone = OnCadDone;

    txDone = false;
	cadDone = false;
	channelActivityDetected = false;
	rxDone = false;
	sendPacket = false;

	SelectedChannel = 1;

    Radio.Init(&RadioEvents);
    PRINTF("TRACE: Radio initialized.\r\n");

    Radio.SetChannel(Channels[SelectedChannel]);

#if defined( USE_MODEM_LORA )

    Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
            LORA_SPREADING_FACTOR, LORA_CODINGRATE,
            LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
            true, 0, 0, LORA_IQ_INVERSION_ON, 3000000 );

    Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
            LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
            LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
            0, true, 0, 0, LORA_IQ_INVERSION_ON, true );

#elif defined( USE_MODEM_FSK )

    Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0,
            FSK_DATARATE, 0,
            FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON,
            true, 0, 0, 0, 3000000 );

    Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE,
            0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH,
            0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true,
            0, 0,false, true );

#else
#error "Please define a frequency band in the compiler options."
#endif

    srand1 (BoardGetRandomSeed() );
#if 0
    PRINTF("Start channel activity detection...\r\n");
    Radio.StartCad();

    while (1) {
        if (cadDone) {
            cadDone = false;
            if (channelActivityDetected) {
                PRINTF("Channel activity detected (%u. on channel %u).\r\n", ++cnt[SelectedChannel],
                        Channels[SelectedChannel]);
                DelayMs(100); /* Wait for Rx1 to open */
                Radio.SetChannel(Channels[0]); /* Set to default channel */
                Radio.Send(TxBuffer, TxBufferSize);
                while (!txDone) {
                };
                txDone = false;
                SelectedChannel = randr(0, 2);
                PRINTF("Channel activity detection on channel %u activated.\r\n",
                        Channels[SelectedChannel]);
                Radio.SetChannel(Channels[SelectedChannel]);
            }
            DelayMs(50);
            Radio.StartCad();
        }
    }
#else
    PRINTF("Start package receiving...\r\n");
	Radio.Rx(0);

	while(1){
		if(rxDone) {
			rxDone = false;
//			TimerSetValue(&TxPacketTimer, RECEIVE_DELAY1);
//			TimerStart(&TxPacketTimer);
			PRINTF("TRACE: %s - Incoming message. %u bytes. (%d/%d)\r\n", __FUNCTION__, RxBufferSize, Rssi, Snr);
			for(uint8_t i = 0; i < RxBufferSize; i++) {
				PRINTF("%02x", RxBuffer[i]);
			}
			PRINTF("\r\n");
			Radio.Rx(0);
		}
	}
#endif
}