boolean PutBowlerPacket(BowlerPacket * Packet){
	Packet->use.head.ResponseFlag=1;
	FixPacket(Packet);
//	if(Packet->use.head.Method ==BOWLER_ASYN)
//		printPacket(Packet,WARN_PRINT);
	return putStream(Packet->stream,GetPacketLegnth(Packet));
}
boolean _getBowlerPacket(BowlerPacket * Packet,BYTE_FIFO_STORAGE * fifo, boolean debug){
	boolean PacketCheck=false; 
	//uint16_t PacketLegnth=0;
        Packet->stream[0]=0;
	if (getNumBytes(fifo) == 0 ) {
		return false; //Not enough bytes to even be a header, try back later
	}

	allign(Packet,fifo);

	if (getNumBytes(fifo) < ((_BowlerHeaderSize)+4)) {
		if(debug){
			//b_println("Current num bytes: ",ERROR_PRINT);p_int(getNumBytes(fifo),ERROR_PRINT);
		}
		return false; //Not enough bytes to even be a header, try back later
	}
	FifoReadByteStream(Packet->stream,_BowlerHeaderSize,fifo);
	PacketCheck=false; 
	while(PacketCheck==false) {
		if( (Packet->use.head.ProtocolRevision != BOWLER_VERSION)
				|| (CheckCRC(Packet)==false) 

		  ){
			if(Packet->use.head.ProtocolRevision != BOWLER_VERSION){
				b_println("first",ERROR_PRINT);
			}else if(CheckCRC(Packet)==false) {
				b_println("crc",ERROR_PRINT);
			}
			//prHEX8(Packet->use.head.ProtocolRevision,ERROR_PRINT);print_nnl(" Fifo Size=",ERROR_PRINT);p_int(calcByteCount(fifo),ERROR_PRINT);
			uint8_t b;
			if(getNumBytes(fifo)==0)
				return false; 
			//StartCritical();
			getStream(& b,1,fifo);//junk out one
			//EndCritical();
			FifoReadByteStream(Packet->stream,_BowlerHeaderSize,fifo);
		}else{
			if(debug){
				//b_println("Got header");
			}
			PacketCheck=true; 
		}
		if (getNumBytes(fifo) < minSize) {
			b_println("allign packet",ERROR_PRINT);
			allign(Packet,fifo);
			return false; //Not enough bytes to even be a header, try back later
		}
	}
	//PacketLegnth  = Packet->use.head.DataLegnth;

	uint16_t totalLen = GetPacketLegnth(Packet);
	// See if all the data has arived for this packet
	int32_t num = getNumBytes(fifo);
	if (num >=(totalLen) ){
		if(debug){
			//b_println("**Found packet, ");p_int(totalLen);//print_nnl(" Bytes, pulling out of buffer");
		}
		//StartCritical();
		getStream(Packet->stream,totalLen,fifo);
		//EndCritical();
		if(CheckDataCRC(Packet)){
			return  true;
		}else{
			println_E("Data CRC Failed ");printBowlerPacketDEBUG(Packet,ERROR_PRINT);
		}
	}
	if(debug){
		//b_println("Header ready, but data is not. Need: ",INFO_PRINT);p_int(totalLen,INFO_PRINT);print_nnl(" have: ",INFO_PRINT);p_int(num ,INFO_PRINT);
	}
	return false; 
}
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");
    }
}