int main(int argc, char *argv[]) { CircularBuffer* que; KeyType a = 101; int isEmpty, i; CircularBufferInit(&que, BUFFER_SIZE); fprintf(stderr,"After Init\n"); CircularBufferPrint(que); for(i=1; i<=4; i++) { a=10*i; printf("\n\n===\nTest: Insert %d-%d\n", a, a+NUM_OF_ELEMS-1); while(! CircularBufferEnque(que, a++)); CircularBufferPrint(que); printf("\nRX%d:", i); a=0; isEmpty = CircularBufferDeque(que, &a); while (!isEmpty) { printf("%02d ", a); a=0; isEmpty = CircularBufferDeque(que, &a); } //CircularBufferPrint(que); } CircularBufferPrint(que); fprintf(stderr,"\n"); free(que); return 0; }
/** * Relays data from Bluetooth to Radio */ void relayFromBluetooth() { /* UART1 - FTDI USB * UART2 - Bluetooth * UART3 - Radio */ if(!UART2_ReceiveBufferIsEmpty()) //New data on UART2 InjectLoop(UART2_Read()); //Reads data from UART2 and sends to injector //Lets see if there is some data available to send to radio if(!CircularBufferIsEmpty(&(inject.outBuff))) UART3_Write(CircularBufferDeque(&(inject.outBuff))); }
/* * Calculates the standard deviation of the elements in the input vector */ void stdev(CircularBuffer* que) { KeyType Src; int isEmpty; sum=0.0f; sumOfSquares=0.0f; do { isEmpty = CircularBufferDeque(que, &Src); sumOfSquares += Src * Src; sum += Src; } while (!isEmpty); stddev = sqrt((sumOfSquares - sum*sum / BLOCKSIZE) / (BLOCKSIZE - 1)); average = sum / BLOCKSIZE; }
int main(int argc, char *argv[]) { CircularBuffer* que; KeyType a = 0; int isEmpty; CircularBufferInit(&que, BUFFER_SIZE); while(! CircularBufferEnque(que, a++)); do { isEmpty = CircularBufferDeque(que, &a); printf("%02d ", a); } while (!isEmpty); printf("\n"); free(que); return 0; }
/** * Relays data from USB to Radio */ void relayFromUSB() { /* UART1 - FTDI USB * UART2 - Bluetooth * UART3 - Radio */ if(!UART1_ReceiveBufferIsEmpty()) { unsigned char rx = UART1_Read(); //Reads data from UART1 and InjectLoop(rx); //sends to injector //check for BTB_LAND packet from Mission Planner CheckLandingDirection(rx); } //Lets see if there is some data available to send to radio if(!CircularBufferIsEmpty(&(inject.outBuff))) UART3_Write(CircularBufferDeque(&(inject.outBuff))); }
int main() { KeyType counter = 0; KeyType thisint = 0; CircularBuffer* que; CircularBufferInit(&que, 4); while(true) { // this is the third thread counter++; if (enqueue) { CircularBufferEnque(que, counter); } if (dequeue) { CircularBufferDeque(que, &thisint); } lcd.cls(); lcd.locate(0,0); lcd.printf("Count: %d Popped: %d",counter, thisint); lcd.locate(0,15); lcd.printf("%d %d %d %d", (que->keys)[0], (que->keys)[1], (que->keys)[2], (que->keys)[3]); wait(1.0); } }