Beispiel #1
0
int main(int argc, char* argv[]) {
  struct stat st;
  char* output_dir;

  if (argc != 2) {
    fprintf(stderr, "usage: %s outdir\n", argv[0]);
    return kErrArgc;
  }
  output_dir = argv[1];
  if (stat(output_dir, &st) == -1) {
    fprintf(stderr, "error: could not stat %s\n", output_dir);
    return kErrCannotStat;
  }
  if (!S_ISDIR(st.st_mode)) {
    fprintf(stderr, "error: not a directory: %s\n", output_dir);
    return kErrNotADir;
  }

  InitStates();
  InitTransitions();
  OutputInit(&g_output, output_dir);
  TraverseStates(start_state, false);
  OutputCloseCurrent(&g_output);
  return 0;
}
Beispiel #2
0
void main()
{
   union {
      unsigned int32 hours;
      unsigned int8 minutes;
      unsigned int8 seconds;} upTime;
   
   
   TICK_TYPE CurrentTick,PreviousUDPTick,PreviousSATick;
   resetStatus = (RCON & 0b00111111) | !(STKPTR & 0b11000000); // Get the Reset Status
   RCON = RCON | 0b00111111; //Reset RCON Reset flags... (Reset Register)
   STKPTR = STKPTR & 0b00111111; // Clear Stack Overflow/Underflow flags
   PortInit(); 
   OutputInit();  
   restart_wdt();
   romEZHRInit();    //set up default ezhr settings
   eeROMinit();      //set up default eprom settings
   IPAddressInit();  //set up MAC and default IP addresses
   delay_ms(500); 
   ADCInit();        //set up ADC ports
   iniADCParams();    
   SerialInit();     //set up serial ports
   TickInit();       //set up tick timer
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   StackInit();   
   WritePHYReg(ERXFCON,EthernetRXfilterSetting); // Allow only uni & multi
   SetLEDConfig(E_LED_CONFIG);   // swap LED's 
   output_high(E_SW_PWR_DN);     // Power Ethernet Switch
   output_high(E_SW_RST);
   output_low(RS485_TXEN);
   output_high(RS485_RXDIS);
   output_high(RS232_F_OFF);
   output_high(RS232_F_ON);
   CurrentTick = PreviousUDPTick = get_ticks();
   UDPSampleRate = eeReadUDPRate() * TICKS_PER_MILLISECOND;
   portControlInit();
   while(TRUE)
   {
      CurrentTick = get_ticks();
      restart_wdt();
      StackTask();
      restart_wdt();
      MyTCPTask();//handles TCP connections
      restart_wdt();
      setIO();// checks voltage status and sets ports accordingly
//!      if(CurrentTick-PreviousUDPTick >= UDPSampleRate)
//!      {
//!         currentRoutine=UDPTASK;
//!         BOOL UDPDone = MyUDPTask();
//!         if(UDPDone) 
//!         {
//!            PreviousUDPTick=CurrentTick;
//!         }
//!      }
      StackApplications();
   }
}
Beispiel #3
0
int main(void) {
    uint16_t i = 0;

    OscInit();
    AnalogInit();
    OutputInit();
    PPSInit();

    Timing_Init();
    UART_DMA_Init();

    UI_LED_Initialize();
    for (i=0; i<UI_LED_Count; i++) {
        UI_LED_SetState(UI_LED_List[i], LED_On);
    }
    UI_LED_Update();

    DBG_printf("\r\n");
    DBG_printf("\2330;36mCalsol Datalogger v%u.%u (alpha)\23337m", VERSION_MAJ, VERSION_MIN);
    DBG_printf("\23336m  Built %s %s with C30 ver %i\23337m", __DATE__, __TIME__, __C30_VERSION__);

    DBG_DATA_printf("\23336mDevice reset:%s%s%s%s%s%s%s%s\23337m",
                    (RCONbits.TRAPR? " Trap" : ""),
                    (RCONbits.IOPUWR? " IllegalOpcode/UninitializedW" : ""),
                    (RCONbits.CM? " ConfigMismatch" : ""),
                    (RCONbits.EXTR? " ExternalReset" : ""),
                    (RCONbits.SWR? " SoftwareReset" : ""),
                    (RCONbits.WDTO? " WatchdogTimeout" : ""),
                    (RCONbits.BOR? " BrownOutReset" : ""),
                    (RCONbits.POR? " PowerOnReset" : "")
                   );

    ECAN_Init();
    ECAN_Config();
    C1FCTRLbits.FSA = 4;	// FIFO starts
    C1FEN1 = 0;
    ECAN_SetStandardFilter(0, 0x00, 0, 15);
    ECAN_SetStandardMask(0, 0x00);
    ECAN_SetMode(ECAN_MODE_OPERATE);
    ECAN_SetupDMA();

    UI_Switch_Update();
    if (UI_Switch_GetTest()) {
        DBG_printf("Entering test mode");
        UI_LED_SetState(&UI_LED_Fault, LED_Blink);
        while (UI_Switch_GetTest()) {
            UI_LED_Update();
            UI_Switch_Update();
        }
        UI_LED_SetState(&UI_LED_Fault, LED_Off);
        UI_LED_Update();
    }

    for (i=0; i<UI_LED_Count; i++) {
        UI_LED_SetState(UI_LED_List[i], LED_Off);
    }

    DBG_printf("Initialization complete");


    Datalogger_Init();

    while(1) {
        Datalogger_Loop();
    }
}
Beispiel #4
0
int main (void)
{
//	_DOZE = 0;
   	_RCDIV = 0;
   	//pin mapping
    PinMapping();
    //Initialize the outputs
	OutputInit();
	// Set up the timer
	TimerInit();
	_system_flags.uart_hi_speed = 1;
	if (_system_flags.uart_hi_speed) {
		// divisor=8 for 460800bps
		initUART(8);
	} else {
    	initUART(34);
    }
	//Initialize the system
	SYSTEMInit();	
	ADCinit();	
	//Initialize the button processes	
	BtnInit();
	//Initialize the system flags
	FLAGInit();
	// variable to hold number of times we've passed the 50 msec counter without completing a UART receive
	char receivedCtr=0;

	while (1)
	{
		// check continuity to PIC
		if(uartDataAvailable_receive )
		{
			// set a flag if we're inside a receive packet
			// then, in 50msec timer, if we've not received anything after ~150-200msec, 
			// clear it and tell uart_getPacket to reset state
			_system_flags.PacketisBeingReceived=1;
	        uart_getPacket(0);
            uartDataAvailable_receive = 0;
		}
		if(_system_flags.TwelveBitflag)
		{
			if(_system_flags.EndofFrameflag)
			{
				// if stopped, and all data already pushed out, turn off HTPA
				if(_system_flags.Stopflag)
				{
					while (TX_Sent_Counter!=TX_ToSend_Counter);
					TurnOffHTPA();
					IEC0bits.U1TXIE = 1; // re-enable UART TX ISR
					_system_flags.Standbyflag=1;
					_system_flags.RefreshStatusflag = 1;
					_system_flags.Stopflag = 0;
				}
				_system_flags.EndofFrameflag = 0;
			}
		}
		if (ms_flag)// 1ms loop
		{	
			BtnProcessEvents();  	// Button debounce processing
			StateMachine();	
			if((_button_press.SW1DBB)&&(!_system_flags.SW1released))
			{
				SleepCounter = SLEEPTIME;
				LaserOutlat = ~LaserOutlat;
				LaserCounter=10;
				ButtonTimer = 3;
				_system_flags.SW1released = 1;
			}
			if( _system_flags.PacketisReadyforParse)
			{
				_system_flags.PacketisBeingReceived=0;
				receivedCtr=0;
				_system_flags.PacketisReadyforParse = 0;
				ParsingRXMsg();	
			}    
			if (TimeBase50ms())   //increment and check for 50ms software timer
			{
				if (_system_flags.PacketisBeingReceived)
				{
					// increment counter
					receivedCtr++;
					if (receivedCtr>2)
					{
						receivedCtr=0;
						// reset uart_getPacket
						_system_flags.PacketisBeingReceived=0;
						uart_getPacket(1);
					}
				}
			}//end of 50ms interval
    		if (TimeBase100ms())   //increment and check for 100ms software timer
    		{
    			// if we're in standby, and the change UART flag has been set, change it
    			if (state==STATE_STANDBY)
    			{
	    			if (_system_flags.ChangeUARTSpeed)
	          		{
		          		if (_system_flags.PacketisBeingReceived)
				    	{
				    		uart_getPacket(1);
				    	}
						_system_flags.ChangeUARTSpeed=0;
						// simply toggle UART speed if we get this command
						if (_system_flags.uart_hi_speed==1) {
            				_system_flags.uart_hi_speed=0;
            				initUART(34);
        				} else {
            				_system_flags.uart_hi_speed=1;
            				initUART(8);
        				}
        				FLAGInit();
        				SYSTEMInit();
        			}
       			}
			}//end of 100ms
			if (TimeBase250ms())   //increment and check for 250ms software timer   
			{
				LED1BlinkingCounter++;
				if(LED1BlinkingCounter == 1)
				{
					LED2lat = 1;//green off
					LED1lat = 1; // red is off
				}
				// blink at double speed if in high speed mode
				if(LED1BlinkingCounter > (10-(5*_system_flags.uart_hi_speed))) {
					if(state ==STATE_STREAM )
					{
						LED2lat = 0; // green flashing during streaming
						LED1lat = 1; // red is off
					}
					if(state ==STATE_STANDBY )
					{
						LED1lat = 0; // red flashing during standby
						LED2lat = 1; // green is off	
					}
					LED1BlinkingCounter = 0;
				}
				if((!_button_press.SW1DBB)&&(_system_flags.SW1released))
				{
					_system_flags.SW1released = 0;
					SleepCounter = SLEEPTIME;
				}
				if((ButtonTimer==0)&&(_system_flags.SW1released)&&(!_system_flags.InSleepWake))
				{
					if((_button_press.SW1DBB))
					{
						if(state==STATE_STREAM)
						{
							TurnOffHTPA();
						}	
						// nuclear option, reset firmware and start over with clean plate. 
						asm ("reset");
					}
				}
			}
			if (TimeBase1s())   //increment and check for 1000ms software timer
			{
				if (LaserCounter!=0) LaserCounter--;
				if (LaserCounter==0)
				{
					LaserOutlat = 0;
    			}    
				if(ButtonTimer>0) 
				{
					ButtonTimer=ButtonTimer-1;
				}
				_system_flags.InSleepWake=0;
				if(state == STATE_STANDBY)
				{
					if(SleepCounter>0) 
					{
						SleepCounter=SleepCounter-1;
					}
					if((SleepCounter==0))
					{
						// sleep flag will call state=SLEEP above
						_system_flags.Sleepflag = 1;
						_system_flags.RefreshStatusflag=1;
					}
				}//stand by mode
			}//End of TimeBase1s
			if (TimeBase1h())
			{				
			}//end of 1 hour base	
			ms_flag = 0;
		}// End of msflag 1 ms
	}// End of while (1)
} //End of main()
int main()
{

  int i;

  printf("hello world\n");

  printf("start of out_test\n");
  Wait(SEC_1);

  // initialize
  if (!OutputInit())
    printf("output init returned false\n");

  ResetAllTachoCounts(OUT_ABCD);

//  OutputSetType(OUT_A, DEVICE_TYPE_TACHO);
//  OutputSetType(OUT_B, DEVICE_TYPE_TACHO);
//  OutputSetType(OUT_C, DEVICE_TYPE_MINITACHO);
//  OutputSetTypes(DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO);

  SetPower(OUT_A, 90);
  SetSpeed(OUT_B, 40);
  SetPower(OUT_C, 60);
  SetPower(OUT_D, -60);
  On(OUT_ALL);

  bool isBusy = false;
  for(i=0; i < 10; i++)
  {
    printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
    printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));
    printf("OUT_C: %d %d %d\n", MotorRotationCount(OUT_C), MotorTachoCount(OUT_C), MotorActualSpeed(OUT_C));
    printf("OUT_D: %d %d %d\n", MotorRotationCount(OUT_D), MotorTachoCount(OUT_D), MotorActualSpeed(OUT_D));
    Wait(SEC_1);

    isBusy = MotorBusy(OUT_ALL);
    printf("Any output isBusy = %d\n", (byte)isBusy);
  }
//  Wait(SEC_5);

  printf("Float(OUT_ALL)\n");
  Float(OUT_ALL);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("ResetAllTachoCounts(OUT_ALL)\n");
  ResetAllTachoCounts(OUT_ALL);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));
  printf("OUT_C: %d %d %d\n", MotorRotationCount(OUT_C), MotorTachoCount(OUT_C), MotorActualSpeed(OUT_C));
  printf("OUT_D: %d %d %d\n", MotorRotationCount(OUT_D), MotorTachoCount(OUT_D), MotorActualSpeed(OUT_D));

  printf("Wait(SEC_1)\n");
  Wait(SEC_1);

  printf("RotateMotorNoWait(OUT_AB, 75, 7200)\n");
  RotateMotorNoWait(OUT_AB, 75, 7200);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  isBusy = MotorBusy(OUT_AB);
  printf("A or B isBusy = %d\n", (byte)isBusy);

  printf("Wait(SEC_20)\n");
  Wait(SEC_20);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("resetting all tacho counters\n");
  ResetAllTachoCounts(OUT_ALL);

  printf("Wait(SEC_1)\n");
  Wait(SEC_1);

  printf("OnForSync(OUT_AB, SEC_10, 75)\n");
  OnForSync(OUT_AB, SEC_10, 75);

  for(i=0; i < 10; i++)
  {
    printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
    printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

    isBusy = MotorBusy(OUT_AB);
    printf("A or B isBusy = %d\n", (byte)isBusy);

    isBusy = MotorBusy(OUT_CD);
    printf("C or D isBusy = %d\n", (byte)isBusy);

    Wait(SEC_1);
  }

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  // synchronized motor movement without tacho or time limitation
  printf("OnFwdSync(OUT_AB, 75)\n");
  OnFwdSync(OUT_AB, 75);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("Off(OUT_AB)\n");
  Off(OUT_AB); // stop with braking

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("Wait(SEC_1)\n");
  Wait(SEC_1);

/*
 *  Turn ratio is how tight you turn and to what direction you turn
 *   - 0 value is moving straight forward
 *   - Negative values turns to the left
 *   - Positive values turns to the right
 *   - Value -100 stops the left motor
 *   - Value +100 stops the right motor
 *   - Values less than -100 makes the left motor run the opposite
 *     direction of the right motor (Spin)
 *   - Values greater than +100 makes the right motor run the opposite
 *     direction of the left motor (Spin)
 */

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("OnFwdSyncEx(OUT_AB, 75, -20, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 75, -20, RESET_NONE);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("OnFwdSync(OUT_AB, 50, -50, RESET_NONE)");
  OnFwdSyncEx(OUT_AB, 50, -50, RESET_NONE);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("OnFwdSync(OUT_AB, 20, -100, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 20, -100, RESET_NONE);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("OnFwdSync(OUT_AB, 80, -150, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 80, -150, RESET_NONE);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("OnFwdSync(OUT_AB, 30, -200, RESET_NONE)\n");
  OnFwdSyncEx(OUT_AB, 30, -200, RESET_NONE);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("Off(OUT_AB)\n");
  Off(OUT_AB);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  printf("ResetAllTachoCounts(OUT_AB)\n");
  ResetAllTachoCounts(OUT_AB);

  printf("Wait(SEC_2)\n");
  Wait(SEC_2);

  printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A));
  printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B));

  // a blocking version of RotateMotor (function call does not return
  // until the motor rotation is complete)
  printf("RotateMotor(OUT_AB, 75, 1800)");
  RotateMotor(OUT_AB, 75, 1800); // 5 rotations

  // by the time the function above returns the motors are no longer busy
  isBusy = MotorBusy(OUT_AB);
  printf("A or B isBusy = %d\n", isBusy);

  // this call starts the motors running Forward without regulation or
  // synchronization and the function call does not return until the
  // specified amount of time has elapsed.
  // at the end of the elapsed time the motors are stopped with braking.
  printf("OnFor(OUT_AB, SEC_3)\n");
  OnFor(OUT_AB, SEC_3);

  printf("Off(OUT_AB)\n");
  Off(OUT_AB);

  printf("Wait(SEC_5)\n");
  Wait(SEC_5);

  OutputClose();
  OutputExit();
  printf("end of out_test\n");

  return 0;
}
Beispiel #6
0
int main( int argc, char **argv )
/*******************************/
{
    FILE        *fp;
    char        drive[ _MAX_DRIVE ];
    char        dir[ _MAX_DIR ];
    char        fname[ _MAX_FNAME ];
    char        ext[ _MAX_EXT ];
    char        file[ _MAX_PATH ];
    char        *fn;
    int         i;
    bool        list_file;
    FILE        *fh;
    bool        is_intel;

    OutputInit();
    OutputSetFH( stdout );

    Descriptions = FALSE;
    InterpretComent = TRUE;
    TranslateIndex = FALSE;
    list_file = FALSE;
    is_intel = FALSE;
    quiet = FALSE;
    for( i = 1; i < argc; ++i ) {
        if( argv[i][0] == '-' ) {
            switch( tolower( argv[i][1] ) ) {
            case 'l':
                list_file = TRUE;
                break;
            case 'd':
                Descriptions = TRUE;
                break;
            case 'c':
                InterpretComent = FALSE;
                break;
            case 'r':
                if( strnicmp( argv[i] + 1, "rec=", 4 ) == 0 ) {
                    if( rec_count < 10 ) {
                        if( isdigit( argv[i][5] ) ) {
                            rec_type[ rec_count++ ] = atoi( argv[i] + 5 );
                        } else {
                            rec_type[ rec_count++ ] = RecNameToNumber( argv[i] + 5 );
                        }
                    } else {
                        Output( "Maximum 10 record type allowed." CRLF );
                        OutputFini();
                    }
                } else {
                    DumpRaw = TRUE;
                }
                break;
            case 'i':
                is_intel = FALSE;
                break;
            case 'q':
                quiet = TRUE;
                break;
            case 't':
                TranslateIndex = TRUE;
                break;
            default:
                usage();
            }
        } else {
            break;
        }
    }
    if( i == argc ) {
        usage();
    }

    ShowProductInfo();
    for( ; i < argc; ++i ) {
        _splitpath( argv[i], drive, dir, fname, ext );
        if( ext[0] == 0 ) {
            _makepath( file, drive, dir, fname, OBJSUFFIX );
            fn = file;
        } else {
            fn = argv[i];
        }
        fp = fopen( fn, "rb" );
        if( fp == NULL ) {
            Output( "Cannot open '%s' for reading" CRLF, fn );
            leave( 20 );
        }
        if( list_file ) {
            _makepath( file, drive, dir, fname, LSTSUFFIX );
            fh = fopen( file, "w" );
            if( fh == NULL ) {
                Output( "Cannot open '%s' for writing" CRLF, file );
                leave( 20 );
            }
            OutputSetFH( fh );
        }
        ProcFile( fp, is_intel );
        fclose( fp );
        OutputSetFH( stdout );  /* does fclose() if necessary */
    }
    leave( 0 );
    return( 0 );  // for the less intelligent compilers
}
Beispiel #7
0
int main()
{
  RCC_ClocksTypeDef RCC_Clocks;
  GPIO_InitTypeDef GPIO_InitStructure;
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  
	int rf_len = 0;
  int rs485_len = 0;
#if DEBUG
//  int usart_len = 0;
//	char buff_usart[BUFFER_SIZE];
#endif
	char buff_rf[BUFFER_SIZE];
	char buff_rs485[BUFFER_SIZE];
  
  unsigned int sensors_time_poll = 0;
//  int temp_time_poll = 0;
//  int sms_test_time = 0;
  
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  GPIO_WriteBit(GPIOB, GPIO_Pin_9, Bit_SET); // off
  
	Delay_Init();
  
  Enrf24_init(CE_PIN, CSN_PIN, IRQ_PIN);
	Enrf24_begin(1000000, 0);  // Defaults 1Mbps, channel 0, max TX power
  
  Enrf24_setTXaddress((void*)enrf24_addr);
  Enrf24_setRXaddress((void*)enrf24_addr);
  
  Enrf24_enableRX();  // Start listening
	
#if DEBUG
	USART1_Init(115200);
#endif
	DS1307_Init();
  Sensors_Init();
  RS485_Init(115200);
	sim_hal_init(115200);
  OutputInit();
  
  if (ThesisInit() == THESIS_FLASH_ERROR)
	{
#if DEBUG
		USART1_SendStr("\nFlash write error.\n");
#endif
		TurnBuzzerOn();
		Delay(1000);
	}
  
#if DEBUG
	RCC_GetClocksFreq(&RCC_Clocks);
  USART1_SendStr("System Clock: ");
  USART1_SendNum(RCC_Clocks.SYSCLK_Frequency);
  USART1_SendStr("\r\n");
  
  
  USART1_SendStr("Device ID: ");
  USART1_SendByte(__flash_data.id, HEX);
  USART1_SendStr("\r\n");
  USART1_SendStr("Device Unique Number: ");
  USART1_SendByte(__flash_data.unique_number[0], HEX);
  USART1_SendByte(__flash_data.unique_number[1], HEX);
  USART1_SendByte(__flash_data.unique_number[2], HEX);
  USART1_SendByte(__flash_data.unique_number[3], HEX);
  USART1_SendStr("\r\n");
#endif
  
  
	OneWire_Init();
	for EVER
	{
    if (millis() - sensors_time_poll > 100)
    {
      led_toggle();
      Sensors_Poll();
      sensors_time_poll = millis();
      //      buzzer_toggle();
      //      output_toggle();
      if (millis() > 10000)
      {
        if (sensors.Gas >= GAS_LIMIT)
        {
#if DEBUG
          USART1_SendStr("Gas detected.\r\n");
          USART1_SendStr("Current Gas: ");
          USART1_SendFloat(sensors.Gas);
          USART1_SendStr("Limited Gas: ");
          USART1_SendFloat(GAS_LIMIT);
          USART1_SendStr("\r\n");
#endif
          TurnBuzzerOn();
          TurnSpeakerOn();
          TurnRelayOn();
        }
        else if (sensors.Lighting >= LIGHT_LIMIT)
        {
#if DEBUG
          USART1_SendStr("Light detected.\r\n");
          USART1_SendStr("Current Light: ");
          USART1_SendFloat(sensors.Lighting);
          USART1_SendStr("Limited Light: ");
          USART1_SendFloat(LIGHT_LIMIT);
          USART1_SendStr("\r\n");
#endif
          TurnBuzzerOn();
          TurnSpeakerOn();
          TurnRelayOn();
        }
        else if (sensors.TempC >= TEMPC_LIMIT)
        {
#if DEBUG
          USART1_SendStr("Tempc detected.\r\n");
          USART1_SendStr("Current Tempc: ");
          USART1_SendFloat(sensors.TempC);
          USART1_SendStr("Limited Tempc: ");
          USART1_SendFloat(TEMPC_LIMIT);
          USART1_SendStr("\r\n");
#endif
          TurnBuzzerOn();
          TurnSpeakerOn();
          TurnRelayOn();
        }
        else
        {
          TurnBuzzerOff();
          TurnSpeakerOff();
          TurnRelayOff();
        }
      }
      
      //      Sim900_Process();
    }
    
    //    if (millis() - sms_test_time > 10000)
    //    {
    //      Sim900_SendSMS("Hi kieu", "01677880531");
    //      sms_test_time = millis();
    //    }
    
    //		usart_len = USART1_Available();
    //		
    //		// usart: for test
    //		if (usart_len > 4)
    //		{
    //			int i;
    //			USART1_SendStr("\nUSART1 received packet: \n");
    //			USART1_GetData(buff_usart, usart_len);
    //			for (i = 0; i < usart_len; i++)
    //				USART1_SendByte(buff_usart[i], HEX);
    //			USART1_SendChar('\n');
    //			if (ThesisProcess(buff_usart, usart_len) == THESIS_OK)
    //			{
    //				memset(buff_usart, 0, usart_len);
    //				USART1_Flush();
    //				if (thesis_need_to_send)
    //				{
    //					int i;
    //					USART1_SendStr("\nNeed to send packet: ");
    //					for (i = 0; i < thesis_msg_len; i++)
    //					{
    //						USART1_SendByte(thesis_sent_msg[i], HEX);
    //					}
    //					USART1_SendStr("\nNeed to send packet length: ");
    //					USART1_SendNum(thesis_msg_len);
    //					USART1_SendStr("\n");
    //					thesis_msg_len = 0;
    //					thesis_need_to_send = 0;
    //				}
    //				USART1_SendStr("\nPacket processed.\n"); 
    //			}
    //			else if (thesis_errn == THESIS_FLASH_ERROR)
    //			{
    //				USART1_SendStr("\n");
    //				USART1_SendStr(thesis_err_msg);
    //				USART1_SendStr("\n");
    //				led_toggle();
    //				for(;;);
    //			}
    //			else if (thesis_errn != THESIS_PACKET_NOT_ENOUGH_LENGTH)
    //			{
    //				memset(buff_usart, 0, usart_len);
    //				USART1_Flush();
    //				USART1_SendStr("Packet processing fail.\n");
    //			}
    //			
    //			USART1_SendStr("\n");
    //			USART1_SendStr(thesis_err_msg);
    //			USART1_SendStr("\n");
    //		}
		
    // rf
		if (Enrf24_available(1))
		{
			int i;
			rf_len = Enrf24_read(buff_rf + rf_len, BUFFER_SIZE - 1 - rf_len);
#if DEBUG
			USART1_SendStr("\nRF received packet.\n");
			for (i = 0; i < rf_len; i++)
				USART1_SendByte(buff_rf[i], HEX);
			USART1_SendChar('\n');
#endif
			
			if (ThesisProcess(buff_rf, rf_len) == THESIS_OK)
			{
				memset(buff_rf, 0, rf_len);
        rf_len = 0;
				if (thesis_need_to_send)
				{
					int i;
#if DEBUG
					USART1_SendStr("\nNeed to send packet: ");
					for (i = 0; i < thesis_msg_len; i++)
					{
            //						Enrf24_write(thesis_sent_msg[i]);
						USART1_SendByte(thesis_sent_msg[i], HEX);
					}
#endif
          Enrf24_write_buff(thesis_sent_msg, thesis_msg_len);
          Enrf24_flush();
#if DEBUG
					USART1_SendStr("\nNeed to send packet length: ");
					USART1_SendNum(thesis_msg_len);
					USART1_SendStr("\n");
#endif
					thesis_msg_len = 0;
					thesis_need_to_send = 0;
				}
#if DEBUG
				USART1_SendStr("\nPacket processed.\n");
#endif
			}
			else if (thesis_errn == THESIS_FLASH_ERROR)
			{
#if DEBUG
				USART1_SendStr("\n");
				USART1_SendStr(thesis_err_msg);
				USART1_SendStr("\n");
#endif
				led_toggle();
				for(;;);
			}
			else if (thesis_errn != THESIS_PACKET_NOT_ENOUGH_LENGTH)
			{
				memset(buff_rf, 0, rf_len);
        //				RF_Flush();
        rf_len = 0;
#if DEBUG
				USART1_SendStr("Packet processing fail.\n");
#endif
			}
			
#if DEBUG
			USART1_SendStr("\n");
			USART1_SendStr(thesis_err_msg);
			USART1_SendStr("\n");
#endif
		}
    
    // rs485
		rs485_len = RS485_Available();
		if (rs485_len > 4)
		{
			int i;
			RS485_GetData(buff_rs485, rs485_len);
#if DEBUG
			USART1_SendStr("\nUSART1 received packet: \n");
			for (i = 0; i < rs485_len; i++)
				USART1_SendByte(buff_rs485[i], HEX);
			USART1_SendChar('\n');
#endif
			if (ThesisProcess(buff_rs485, rs485_len) == THESIS_OK)
			{
				memset(buff_rs485, 0, rs485_len);
				RS485_Flush();
				if (thesis_need_to_send)
				{
					int i;
#if DEBUG
					USART1_SendStr("\nNeed to send packet: ");
#endif
          RS485_DIR_Output();
					for (i = 0; i < thesis_msg_len; i++)
					{
						RS485_SendChar(thesis_sent_msg[i]);
#if DEBUG
						USART1_SendByte(thesis_sent_msg[i], HEX);
#endif
					}
          RS485_DIR_Input();
#if DEBUG
					USART1_SendStr("\nNeed to send packet length: ");
					USART1_SendNum(thesis_msg_len);
					USART1_SendStr("\n");
#endif
					thesis_msg_len = 0;
					thesis_need_to_send = 0;
				}
#if DEBUG
				USART1_SendStr("\nPacket processed.\n"); 
#endif
			}
			else if (thesis_errn == THESIS_FLASH_ERROR)
			{
#if DEBUG
				USART1_SendStr("\n");
				USART1_SendStr(thesis_err_msg);
				USART1_SendStr("\n");
#endif
				led_toggle();
				for(;;);
			}
			else if (thesis_errn != THESIS_PACKET_NOT_ENOUGH_LENGTH)
			{
				memset(buff_rs485, 0, rs485_len);
				RS485_Flush();
#if DEBUG
				USART1_SendStr("Packet processing fail.\n");
#endif
			}
			
#if DEBUG
			USART1_SendStr("\n");
			USART1_SendStr(thesis_err_msg);
			USART1_SendStr("\n");
#endif
		}
    
	}
	
}
Beispiel #8
0
static int playFile(const char * file)
{
	int status = -1;
	media_desc_t mdesc;
	
	
	//DBGLOG("playing file: [%s]", file);
	memset(&mdesc, 0, sizeof(media_desc_t));
	mdesc.ftype = NMS_WP_INVALID;
	
	if (!InputIsOurFile(file)) return -1;
	
	status = InputInit(file, &mdesc); 
	
	switch (status) 
	{
	case 0: //everything is fine
		break; 
	case 1:
		WPRINT("InputInit: DM320 is locked by something else. Please try again later.");
		LOCK_PLAYMUTEX();
		errorStatus = NMS_STATUS_OUTPUT_LOCKED;
		UNLOCK_PLAYMUTEX();
		goto bail_clean_input;
	default:
		WPRINT("InputInit: Unable to init device!");
		LOCK_PLAYMUTEX();
		errorStatus = NMS_STATUS_NOT_PLAYABLE;
		UNLOCK_PLAYMUTEX();
		goto bail_clean_input;
	}

	LOCK_PLAYMUTEX();
	InputGetInfo(file, &info);
	UNLOCK_PLAYMUTEX();


	if (InputStart(file)) 
	{
		status = -1;
		goto bail_clean_input;
	}

	status = OutputInit(&mdesc,OutputGetMode(),curProportions); 
	switch (status)
	{
	case 0: //everything is fine
		break;
	case 1:
		WPRINT("OutputInit: DM320 is locked by something else. Please try again later.");
		LOCK_PLAYMUTEX();
		errorStatus = NMS_STATUS_OUTPUT_LOCKED;
		UNLOCK_PLAYMUTEX();
		goto bail_clean_input;
	default:
		WPRINT("OutputInit: Unable to init output !");
		LOCK_PLAYMUTEX();
		if ((playtype == NPT_FILE) || (totalFiles <= 1) || (repeat == 1))
			errorStatus = NMS_STATUS_NOT_PLAYABLE;
		UNLOCK_PLAYMUTEX();
		goto bail_clean_input;
	} 

	OutputActivateMode(0);

	LOCK_PLAYMUTEX();
	playtime = 0;
	ffrwLevel = 0;
	sfrwLevel = 0;
	sfrwLevelFinal = 0;
	muted = 0;
	playing  = 1;
	trackChange = TC_DISABLE;
	UNLOCK_PLAYMUTEX();
	
	if (newThread(&avThread, NULL, avLoop, NULL)) 
	{
		status = -1;
		goto bail_clean_input;
	}
	
	return 0;
	
bail_clean_input:
	LOCK_PLAYMUTEX();
	InputFinish();
	UNLOCK_PLAYMUTEX();
	return status;
}