Example #1
0
void CheckSwitches(void){

	Print_Level l = getPrintLevel();
	setPrintLevelInfoPrint();
	switched=0;
	volt = GetRawVoltage();
	boolean up = false; 

	uint8_t reg = isRegulated_0();
	if (bankState[0] != reg ){
		bankState[0]=reg;
		up=true; 
	}


	reg = isRegulated_1();
	if (bankState[1] != reg){
		bankState[1] = reg;
		up=true; 
	}

	if ((lastVolt>RawVoltageMin) && (volt<RawVoltageMin)){
		up=true; 
		lastVolt = volt;
	}
	if ((lastVolt<RawVoltageMin) && (volt>RawVoltageMin)){
		up=true; 
		lastVolt = volt;
	}

	setPrintLevel(l);
}
void UserInit(void){
	StartCritical();

	//println_W(startmessage);// All printfDEBUG functions do not need to be removed from code if debug is disabled
//#if defined(DEBUG)
//	ConfigureUART(115200);
//	if(GetChannelMode(16)!=IS_UART_TX)
//		setMode(16,IS_UART_TX);
//#endif
	setPrintLevelInfoPrint();
	println_I(/*PSTR*/("\e[1;1H\e[2J ***Starting User initialization***"));
	InitFlagPins();
	InitBankLEDs();
	SetPowerState0(0,0);
	SetPowerState1(0,0);


	//_delay_ms(1);

#if defined(WPIRBE)
	SPISlaveInit();
#endif


	//_delay_ms(100);
	println_I(/*PSTR*/("Starting Pin Functions"));
	InitPinFunction();
	println_I(/*PSTR*/("Starting Pin Modes"));
	InitPinModes();
	int i=0;
	//println_I(/*PSTR*/("Starting hardware modes"));
	for(i=0;i<GetNumberOfIOChannels();i++){
		initPinState(i);
		configAdvancedAsyncNotEqual(i,10);
		setAsyncLocal(i,true) ;
	}
	//println_I(/*PSTR*/("DONE pin initialization"));

	//println_I(/*PSTR*/("Adding IO Initialization"));
	addNamespaceToList((NAMESPACE_LIST *)get_bcsIoNamespace());
	//println_I(/*PSTR*/("Adding IO.SETMODE Initialization"));
	addNamespaceToList((NAMESPACE_LIST *)get_bcsIoSetmodeNamespace());
	//println_I(/*PSTR*/("Adding Internal Initialization"));
	addNamespaceToList((NAMESPACE_LIST *)get_internalNamespace());
	setNoAsyncMode(true);
	setIgnoreAddressing(true);
	//SetPinTris(0,OUTPUT);
	//SetDIO(0,OFF);

#if defined(USE_AS_LIBRARY)
	InitializeUserCode();
#endif
	EndCritical();
	println_I(/*PSTR*/("Starting Core"));
//	setMode(22,IS_DO);
//	setMode(23,IS_DI);
//	println_I(/*PSTR*/("Pin done"));
}
Example #3
0
void RunPPMCheck(void){
	if(GetChannelMode(23) != IS_PPM_IN){
		//setMode(23,IS_PPM_IN);
		return;
	}
	if(startedLinks==false){
		startedLinks=true;
		readPPMLink(ppmLink);
	}
	if(writeLinks==true){
		writeLinks=false;
		writePPMLink(ppmLink);
	}
	int i;
	boolean up = false; 
	for(i=0;i<NUM_PPM_CHAN;i++){
		float fTime =MyTickConvertToMilliseconds(((float)ppmDataTmp[i])+(((float)TickGetUpper())*((float) 4294967295ul )));
		if(fTime>.9 && fTime<2.2){
			float fVal = (fTime-.99)*255;
			if(fVal>254)
				fVal=254;
			if(fVal<0)
				fVal=0;
			uint8_t time =((BYTE) fVal);

			if((time>(ppmData[i]+3)) || (time<(ppmData[i]-3))){
				ppmData[i]=time;
				//setHeartBeatState( FALSE, 0);
				up=true; 
			}
		}
	}
	if(up){
		//push upstream
		pushPPMPacket();
		//print_I("\nUpdating ppm chan ");printStream(ppmData,NUM_PPM_CHAN);
		//print_I(" PPM cross link ");printStream(ppmLink,NUM_PPM_CHAN);
		for(i=0;i<NUM_PPM_CHAN;i++){
			if(ppmLink[i] != INVALID_PPM_LINK){
				if(ppmLastSent[i] != ppmData[i]){
					ppmLastSent[i] = ppmData[i];
					Print_Level l = getPrintLevel();
					setPrintLevelInfoPrint();
					//println_I("PPM setting output");
					//SetChannelValueCoProc(ppmLink[i],ppmData[i]);
					getBcsIoDataTable(ppmLink[i])->PIN.currentValue=ppmData[i];
					//SetValFromAsync(ppmLink[i],ppmData[i]);
					setPrintLevel(l);
				}
			}
		}
	}
}
void UserInit(void){
	//setPrintStream(&USBPutArray);
	setPrintLevelInfoPrint();
	println_I("\n\nStarting PIC initialization");
	//DelayMs(1000);
	hardwareInit();
	println_I("Hardware Init done");

	ReleaseAVRReset();



	CheckRev();

	LoadEEstore();

	LoadDefaultValues();

	CartesianControllerInit();

	InitPID();

	UpdateAVRLED();


	lockServos();
	setPrintLevelInfoPrint();

	BOOL brown = getEEBrownOutDetect();
	setCoProcBrownOutMode(brown);
	setBrownOutDetect(brown);


	println_I("###Starting PIC In Debug Mode###\n");// All printfDEBUG functions do not need to be removed from code if debug is disabled
	DelayMs(1000);
	//setPrintLevelErrorPrint();
	println_E("Error level printing");
	println_W("Warning level printing");
	println_I("Info level printing");
}
void UserInit(void) {
    //setPrintStream(&USBPutArray);
    clearPrint();
    setPrintLevelInfoPrint();
    println_I("Start PIC");
    //DelayMs(1000);
    hardwareInit();
    //println_I("Hardware Init done");

    InitializeDyIODataTableManager();

    CheckRev();

    LoadEEstore();


    

    UpdateAVRLED();


    lockServos();
    setPrintLevelInfoPrint();

    boolean brown = getEEBrownOutDetect() ? true:false;
    setBrownOutDetect(brown);

    //Data table needs to be synced before the PID can init properly
    SyncDataTable();
    InitPID();

    
    //println_I("###Starting PIC In Debug Mode###\n"); // All printfDEBUG functions do not need to be removed from code if debug is disabled
    //DelayMs(1000);
    setPrintLevelWarningPrint();
    //println_E("Error level printing");
    //println_W("Warning level printing");
    //println_I("Info level printing");
}
void CheckSwitches(void){

	Print_Level l = getPrintLevel();
	setPrintLevelInfoPrint();
	switched=0;
	volt = GetRawVoltage();
	BOOL up = FALSE;

	BYTE reg = isRegulated_0();
	if (bankState[0] != reg ){
		bankState[0]=reg;
		up=TRUE;
	}


	reg = isRegulated_1();
	if (bankState[1] != reg){
		bankState[1] = reg;
		up=TRUE;
	}

	if ((lastVolt>RawVoltageMin) && (volt<RawVoltageMin)){
		up=TRUE;
		lastVolt = volt;
	}
	if ((lastVolt<RawVoltageMin) && (volt>RawVoltageMin)){
		up=TRUE;
		lastVolt = volt;
	}

	if(up){
		println_I("\nVoltage on raw:   \t");
		p_fl_I(volt);

		println_I("Voltage on bank0: \t");
		p_fl_I(GetRail0Voltage());

		println_I("Voltage on bank1:\t");
		p_fl_I(GetRail1Voltage());
		println_I("Pushing upstream Power Packet bank 0: ");p_int_I(bankState[0]);print_I(" bank 1: ");p_int_I(bankState[1]);
		println_I("Power Code 0: ");p_int_I(GetRawVoltageCode(0));
		println_I("Power Code 1 : ");p_int_I(GetRawVoltageCode(1));
		println_I("Raw: ");p_fl_I(GetRawVoltage());
		UpstreamPushPowerChange();
	}
	setPrintLevel(l);
}
void ProcessAsyncData(BowlerPacket * Packet){
	//println_I("**Got Async Packet**");
	//printPacket(Packet,INFO_PRINT);

	Print_Level l = getPrintLevel();
	setPrintLevelInfoPrint();

	if (Packet->use.head.RPC==GCHV){
		BYTE pin = Packet->use.data[0];
		BYTE mode = GetChannelMode(pin);
		if(mode == IS_ANALOG_IN ){
			UINT16_UNION ana;
			ana.byte.SB = Packet->use.data[1];
			ana.byte.LB = Packet->use.data[2];
			//ADC_val[pin-8]=ana.Val;
			if(ana.Val>=0 && ana.Val<1024)
				SetValFromAsync(pin,ana.Val);//asyncData[pin].currentVal=ana.Val;
			println_I("***Setting analog value: ");p_int_I(pin);print_I(", ");p_int_I(ana.Val);
		}
		else if((mode == IS_DI) || (mode == IS_COUNTER_INPUT_HOME)|| (mode == IS_COUNTER_OUTPUT_HOME) || mode == IS_SERVO){
			//DIG_val[pin]=Packet->use.data[1];
			SetValFromAsync(pin,Packet->use.data[1]);//asyncData[pin].currentVal=Packet->use.data[1];
			println_I("***Setting digital value: ");p_int_I(pin);print_I(", ");p_int_I(Packet->use.data[1]);//printStream(DIG_val,NUM_PINS);
		}else {
			if(IsAsync(pin)){
				println_I("Sending async packet, not digital or analog");
				PutBowlerPacket(Packet);
			}
		}
	}else if (Packet->use.head.RPC==AASN){
		int i;
		for(i=0;i<8;i++){
			BYTE pin = i+8;
			BYTE mode = GetChannelMode(pin);
			if(mode == IS_ANALOG_IN ){
				UINT16_UNION ana;
				ana.byte.SB = Packet->use.data[i*2];
				ana.byte.LB = Packet->use.data[(i*2)+1];
				//ADC_val[pin-8]=ana.Val
				if(ana.Val>=0 && ana.Val<1024);
					SetValFromAsync(pin,ana.Val);//asyncData[pin].currentVal=ana.Val;
			}
		}
	}else if (Packet->use.head.RPC==DASN){
		int i;
		for(i=0;i<GetNumberOfIOChannels();i++){
			BYTE mode = GetChannelMode(i);
			if((mode == IS_DI) || (mode == IS_COUNTER_INPUT_HOME)|| (mode == IS_COUNTER_OUTPUT_HOME)|| (mode == IS_SERVO)){
				SetValFromAsync(i,Packet->use.data[i]);//asyncData[i].currentVal=Packet->use.data[i];
			}

		}
		//println_I("***Setting All Digital value: ");
	}if (Packet->use.head.RPC==GetRPCValue("gacv")){
		int i;
		int val;
		for(i=0;i<GetNumberOfIOChannels();i++){
			val = get32bit(Packet, i*4);
			if(getBcsIoDataTable()[i].PIN.asyncDataCurrentVal!=val){
				println_I("Data on Pin ");p_int_I(i);print_I(" to val ");p_int_I(val);
				SetValFromAsync(i,val);//
			}
		}
	}else{
		println_W("***Async packet not UNKNOWN***");
		printPacket(Packet,WARN_PRINT);
	}
//	println_I("***Setting All value: [");
//	int i;
//	for(i=0;i<NUM_PINS;i++){
//		p_int_I(asyncData[i].currentVal);print_I(" ");
//	}
//	print_I("]");
	setPrintLevel(l);
}
void advancedBowlerExample() {
    /**
     * User code must implement a few functions needed by the stack internally
     * This Platform specific code can be stored in the Platform directory if it is universal for all
     * implementations on the given Platform.
     * float getMs(void) Returns the current milliseconds since the application started
     * StartCritical()   Starts a critical protected section of code
     * EndCritical()     Ends the critical section and returns to normal operation
     */
    setPrintLevelInfoPrint();// enable the stack specific printer. If you wish to use this feature putCharDebug(char c) needs to be defined
    printf("\r\nStarting Sample Program\r\n");
    int pngtmp = GetRPCValue("_png");
    if(pngtmp != _PNG) {
        printf("\r\nFAIL Expected: ");
        prHEX32(_PNG,INFO_PRINT);
        printf(" got: ");
        prHEX32(pngtmp,INFO_PRINT);
        return;
    }

    /**
     * First we are going to put together dummy array of packet data. These are examples of a _png receive and a custom response.
     * These would not exist in your implementation but would come in from the physical layer
     */
    BowlerPacket myPngPacket;
    myPngPacket.use.head.RPC = GetRPCValue("apid");
    myPngPacket.use.head.MessageID = 2;// Specify namespace 2 for the collision detect
    myPngPacket.use.head.Method = BOWLER_GET;
    myPngPacket.use.head.DataLegnth=4;
    FixPacket(&myPngPacket);// Set up the stack content

    BowlerPacket myNamespacTestPacket;
    myNamespacTestPacket.use.head.RPC = GetRPCValue("rtst");
    myNamespacTestPacket.use.head.Method = BOWLER_GET;
    myNamespacTestPacket.use.data[0] = 37;
    myNamespacTestPacket.use.head.DataLegnth=4+1;
    FixPacket(&myNamespacTestPacket);// Set up the stack content


    /**
     * Now we begin to set up the stack features. The first step is to set up the FIFO to receive the data coming in asynchronously
     *
     */
    BYTE privateRXCom[sizeof(BowlerPacket)];//make the buffer at least big enough to hold one full sized packet
    BYTE_FIFO_STORAGE store;//this is the FIFO data storage struct. All interactions with the circular buffer will go through this.
    /**
     * Next we initialize the buffer
     */
    InitByteFifo(&store,// the pointer to the storage struct
                 privateRXCom,//pointer the the buffer
                 sizeof(privateRXCom));//the size of the buffer

    Bowler_Init();// Start the Bowler stack

    /**
     * Now we are going to regester what namespaces we implement with the framework
     */
    NAMESPACE_LIST * tmp =getBcsPidNamespace();
    addNamespaceToList(tmp);
    tmp = getBcsTestNamespace();
    addNamespaceToList(tmp);


    printf("\r\n# of namespaces declared= %i",getNumberOfNamespaces());
    int i=0;
    for(i=0; i<getNumberOfNamespaces(); i++) {
        NAMESPACE_LIST * nsPtr = getNamespaceAtIndex(i);
        printf("\r\nNamespace %s at index %i",nsPtr->namespaceString,i);
    }

    /**
     * Now we load the buffer with the the packet that we "Received"
     * This step would come in from the physical layer, usually on
     * an interrupt on a mcu.
     */

    for (i=0; i<GetPacketLegnth(&myPngPacket); i++) {
        BYTE err;// this is a stack error storage byte. See Bowler/FIFO.h for response codes
        BYTE b= myPngPacket.stream[i];// This would be a new byte from the physical layer
        FifoAddByte(&store, b, &err);// This helper function adds the byte to the storage buffer and manages the read write pointers.
    }
    /**
     * Next we load the new namespace packet
     */
    i=0;
    for (i=0; i<GetPacketLegnth(&myNamespacTestPacket); i++) {
        BYTE err;// this is a stack error storage byte. See Bowler/FIFO.h for response codes
        BYTE b= myNamespacTestPacket.stream[i];// This would be a new byte from the physical layer
        FifoAddByte(&store, b, &err);// This helper function adds the byte to the storage buffer and manages the read write pointers.
    }

    printf("\r\nData loaded into packet\r\n");
    /**
     * We have now loaded a packet into the storage struct 'store'
     * All the while we can be polling the storage struct for a new packet
     */
    BowlerPacket myLocalPacket; // Declare a packet struct to catch the parsed packet from the asynchronous storage buffer
    while(getNumBytes(&store)>0) {
        while(Bowler_Server_Static(&myLocalPacket,// pointer to the local packet into which to store the parsed packet
                                   &store// storage struct from which the packet will be checked and parsed.
                                  ) == FALSE) { // Returns true when a packet is found and pulled out of the buffer
            // wait because there is no packet yet
        }

        /**
         * At this point the packet has been parsed and pulled out of the buffer
         * The Static server will have also called the call backs to pars the packet, so
         * the response should be loaded up to send back
         */

        int packetLength = GetPacketLegnth(&myLocalPacket); // helper function to get packet length

        printf("\r\nPreparing to send:\r\n");
        printPacket(&myLocalPacket, INFO_PRINT);

        printf("\r\nSending Packet Data back out: [ ");
        for(i=0; i< packetLength; i++) {
            //This would be sending to the physical layer. For this example we are just printing out the data
            printf(" %i ",myLocalPacket.stream[i]);
        }
        printf(" ] \r\n");
    }
}