BOOL GetChannelModeFromPacket(BowlerPacket * Packet){ Packet->use.data[1]=GetChannelMode(Packet->use.data[0]); Packet->use.head.DataLegnth=6; Packet->use.head.Method=BOWLER_POST; FixPacket(Packet); return TRUE; }
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 GetAllChanelValueFromPacket(BowlerPacket * Packet) { int32_t * data = (int32_t *) (&Packet->use.data[1]); if (getAllChanelValueHWPtr != NULL) { int i; int32_t tmp; getAllChanelValueHWPtr(data); for (i = 0; i < GetNumberOfIOChannels(); i++) { tmp = data[i]; if(isOutputMode(GetChannelMode(i))==false){ setDataTableCurrentValue(i,tmp); }else{ if(GetChannelMode(i) == IS_SERVO){ tmp = GetServoPos(i); }else if(GetChannelMode(i)== IS_UART_RX){ setDataTableCurrentValue(i,tmp); }else{ tmp = getBcsIoDataTable(i)->PIN.currentValue; } } set32bit(Packet, tmp, (i*4)+1); } Packet->use.data[0]=(GetNumberOfIOChannels()); Packet->use.head.RPC=GetRPCValue("gacv"); Packet->use.head.DataLegnth = 4+1+(GetNumberOfIOChannels()*4); } else return false; FixPacket(Packet); return true; }
boolean GetChanelValueFromPacket(BowlerPacket * Packet) { uint8_t pin = Packet->use.data[0]; uint8_t mode = GetChannelMode(pin); uint8_t numValues = 1; int32_t data; if (getChanelValueHWPtr != NULL) { getChanelValueHWPtr(pin, &numValues, &data); } else { return false; } if(isOutputMode(GetChannelMode(pin))==false ){ setDataTableCurrentValue(pin,data); }else{ if(mode== IS_UART_RX){ setDataTableCurrentValue(pin,data); }else{ data = getBcsIoDataTable(pin)->PIN.currentValue; } } set32bit(Packet, data, 1); numValues = 4; Packet->use.head.DataLegnth = 4 + 1 + numValues; FixPacket(Packet); return true; }
BOOL ConfigureChannelFromPacket(BowlerPacket * Packet){ BYTE pin = Packet->use.data[0]; BYTE mode = GetChannelMode(pin); INT32 * data = (INT32 *)(Packet->use.data+1); INT32 tmp; int i; if(configChannelHWPtr!=NULL){ if(Packet->use.head.DataLegnth>5 && mode != IS_SERVO){ int numVals = (Packet->use.head.DataLegnth-(4+1))/4; for(i=0;i<numVals;i++){ tmp = get32bit(Packet, (i*4)+1); getBcsIoDataTable()[i].PIN.currentValue = tmp; data[i]=tmp; } configChannelHWPtr(pin,numVals,(INT32 * )(Packet->use.data+1)); }else{ // Single Byte Servo, legacy HACK INT32 value = Packet->use.data[1]; configChannelHWPtr(pin,1,&value); } }else{ return FALSE; } FixPacket(Packet); return TRUE; }
boolean GetAsyncFromPacket(BowlerPacket * Packet) { Packet->use.head.Method = BOWLER_POST; Packet->use.data[1] = IsAsync(Packet->use.data[0]); Packet->use.head.DataLegnth = 4 + 2; FixPacket(Packet); return true; }
BOOL SetAsyncFromPacket(BowlerPacket * Packet){ Packet->use.head.Method=BOWLER_POST; setAsync(Packet->use.data[0],Packet->use.data[1]); Packet->use.head.DataLegnth=4; FixPacket(Packet); return TRUE; }
boolean GetChannelModeFromPacket(BowlerPacket * Packet) { Packet->use.data[1] = GetChannelMode(Packet->use.data[0]); Packet->use.head.DataLegnth = 6; Packet->use.head.Method = BOWLER_POST; FixPacket(Packet); //printBowlerPacketDEBUG(Packet,WARN_PRINT); return true; }
BOOL avrAsyncCallbackPtr(BowlerPacket *Packet){ FixPacket(Packet); //println_I("<<Async\n\r");printPacket(Packet,INFO_PRINT); int i; for(i=0;i<Packet->use.head.DataLegnth+BowlerHeaderSize;i++){ send(Packet->stream[i]); } return TRUE; }
BOOL GetAllChannelModeFromPacket(BowlerPacket * Packet){ int i; Packet->use.head.Method=BOWLER_POST; for (i=0;i<GetNumberOfIOChannels();i++){ Packet->use.data[i]=GetChannelMode(i); } Packet->use.head.DataLegnth=4+GetNumberOfIOChannels(); FixPacket(Packet); return TRUE; }
BOOL GetIOChannelCountFromPacket(BowlerPacket * Packet){ Packet->use.head.Method=BOWLER_POST; Packet->use.data[0]=0; Packet->use.data[1]=0; Packet->use.data[2]=0; Packet->use.data[3]=GetNumberOfIOChannels();; Packet->use.head.DataLegnth=4+4; FixPacket(Packet); return TRUE; }
boolean GetIOChannelCountFromPacket(BowlerPacket * Packet) { Packet->use.head.Method = BOWLER_POST; Packet->use.data[0] = 0; Packet->use.data[1] = 0; Packet->use.data[2] = 0; Packet->use.data[3] = GetNumberOfIOChannels(); Packet->use.head.RPC= GetRPCValue("gchc"); Packet->use.head.DataLegnth = 4 + 4; FixPacket(Packet); return true; }
boolean GetAllChannelModeFromPacket(BowlerPacket * Packet) { int i; Packet->use.head.Method = BOWLER_POST; Packet->use.head.RPC=GetRPCValue("gacm"); Packet->use.data[0] = GetNumberOfIOChannels(); for (i = 0; i < GetNumberOfIOChannels(); i++) { Packet->use.data[1 + i] = GetChannelMode(i); } Packet->use.head.DataLegnth = 4 + GetNumberOfIOChannels()+1; FixPacket(Packet); //printBowlerPacketDEBUG(Packet,WARN_PRINT); return true; }
BOOL getFunctionList(BowlerPacket * Packet){ int chan = Packet->use.data[0]; int index =0; int i=0; for(i=0;i<IO_MODE_MAX;i++){ if(pinHasFunction(chan,i)){ Packet->use.data[index++]=i; } } Packet->use.head.DataLegnth=4+index; FixPacket(Packet); return TRUE; }
BOOL GetAllChanelValueFromPacket(BowlerPacket * Packet){ INT32 * data = (INT32 *)(Packet->use.data); if(getAllChanelValueHWPtr!=NULL){ int i; INT32 tmp; getAllChanelValueHWPtr((INT32 * )Packet->use.data); for(i=0;i<GetNumberOfIOChannels();i++){ tmp = data[i]; getBcsIoDataTable()[i].PIN.currentValue = tmp; set32bit(Packet,tmp,i*4); } Packet->use.head.DataLegnth = 4+GetNumberOfIOChannels()*4; }else return FALSE; FixPacket(Packet); return TRUE; }
void checkPositionChange(){ int i; float tmp[4]; updateCurrentPositions(); tmp[0]=xCurrent; tmp[1]=yCurrent; tmp[2]=zCurrent; tmp[3] = getLinkAngle(3); if( tmp[0]!=lastXYZE[0]|| tmp[1]!=lastXYZE[1]|| tmp[2]!=lastXYZE[2]|| tmp[3]!=lastXYZE[3]){ for(i=0;i<4;i++){ lastXYZE[i] =tmp[i]; } // println_I("Current Voltage of sensor");p_fl_E(getAdcVoltage(mapHeaterIndex(HEATER0_INDEX),10)); // print_E(" Temp = ");p_fl_E(getHeaterTempreture(HEATER0_INDEX)); // print_E(" Raw ADC = ");p_int_E(getAdcRaw(mapHeaterIndex(HEATER0_INDEX),10)); // println_I("Current position X=");p_fl_E(lastXYZE[0]); // print_E(" Y=");p_fl_E(lastXYZE[1]); // print_E(" Z=");p_fl_E(lastXYZE[2]); // print_E(" extr=");p_fl_E(lastXYZE[3]); INT32_UNION PID_Temp; LoadCorePacket(& packetTemp); packetTemp.use.head.DataLegnth=4; packetTemp.use.head.RPC = GetRPCValue("cpos"); int i; for(i=0;i<4;i++){ PID_Temp.Val=lastXYZE[i]; packetTemp.use.data[0+(i*4)]=PID_Temp.byte.FB; packetTemp.use.data[1+(i*4)]=PID_Temp.byte.TB; packetTemp.use.data[2+(i*4)]=PID_Temp.byte.SB; packetTemp.use.data[3+(i*4)]=PID_Temp.byte.LB; packetTemp.use.head.DataLegnth+=4; } packetTemp.use.head.Method=BOWLER_ASYN; FixPacket(&packetTemp); asyncCallback(& packetTemp); } }
boolean ConfigureChannelFromPacket(BowlerPacket * Packet) { uint8_t pin = Packet->use.data[0]; boolean setValues = Packet->use.data[1]; uint8_t mode = GetChannelMode(pin); int32_t tmp; if(mode != 0xff && setValues){ if (configChannelHWPtr != NULL) { // println_E("Pushing configs from packet "); // p_int_E(pin); tmp = get32bit(Packet, 3); // print_E(" value = "); // p_int_E(tmp); //println_E(__FILE__);println_E("ConfigureChannelFromPacket"); setDataTableCurrentValue(pin,tmp); configChannelHWPtr(pin, 1, &tmp); } else { return false; } } //println_E("Loading configs into packet"); Packet->use.head.RPC= GetRPCValue("cchn"); Packet->use.head.Method = BOWLER_CRIT; Packet->use.head.DataLegnth = 4+1+(GetNumberOfIOChannels()*4); int32_t * data = (int32_t *) (Packet->use.data + 1); configChannelHWPtr(0xff, GetNumberOfIOChannels(), data); Packet->use.data[0] =GetNumberOfIOChannels(); int i; for (i = 0; i < GetNumberOfIOChannels(); i++) { tmp = data[i]; set32bit(Packet, tmp, (i*4)+1); } FixPacket(Packet); return true; }
BOOL GetChanelValueFromPacket(BowlerPacket * Packet){ BYTE pin = Packet->use.data[0]; BYTE mode = GetChannelMode(pin); BYTE numValues; if(isStremChannelMode(mode)){ if(getChanelValueHWPtr!=NULL){ // Load the data directly into the packet as the buffer //Data pointer is offset by one to start after the pin index getChanelValueHWPtr(pin, &numValues, (INT32 *)(Packet->use.data+1)); }else{ return FALSE; } }else{ INT32 data; if(getChanelValueHWPtr!=NULL){ getChanelValueHWPtr(pin, &numValues, &data); }else{ return FALSE; } if(isSingleByteMode(mode)){ set8bit(Packet,data, 1); numValues=1; }else if(isTwoByteMode(mode)){ set16bit(Packet,data, 1); numValues=2; }else{ set32bit(Packet,data, 1); numValues=4; } } Packet->use.head.DataLegnth = 4+1+numValues; FixPacket(Packet); return TRUE; }
BOOL bcsIoAsyncEventCallback(BowlerPacket *Packet,BOOL (*pidAsyncCallbackPtr)(BowlerPacket *)){ int i; BOOL update=FALSE; println_W("Async ");print_W(ioNSName); for(i=0;i<GetNumberOfIOChannels();i++){ //println_W("Checking ");p_int_W(i); if(pushAsyncReady(i)){ update=TRUE; } } if(update){ println_I(__FILE__);println_I("Async: "); populateGACV(Packet); Packet->use.head.Method=BOWLER_ASYN; FixPacket(Packet); printBowlerPacketDEBUG(Packet,INFO_PRINT); if(pidAsyncCallbackPtr!=NULL){ pidAsyncCallbackPtr(Packet); } } println_W("Done ");print_W(ioNSName); return FALSE; }
BOOL SetAllChannelValueFromPacket(BowlerPacket * Packet){ INT32 * data = (INT32 *)(Packet->use.data+4); UINT32 tmp; if(setAllChanelValueHWPtr!=NULL){ UINT32_UNION time; BYTE i; time.byte.FB=Packet->use.data[0]; time.byte.TB=Packet->use.data[1]; time.byte.SB=Packet->use.data[2]; time.byte.LB=Packet->use.data[3]; for(i=0;i<GetNumberOfIOChannels();i++){ tmp = get32bit(Packet, i*4); getBcsIoDataTable()[i].PIN.currentValue = tmp; data[i]=tmp; } setAllChanelValueHWPtr(data,time.Val); READY(Packet,3,3); FixPacket(Packet); }else{ return FALSE; } return TRUE; }
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"); } }