int main(void) { uint8_t cmdBuf[128]; uint8_t i; // Init peripherals. // Clock is set to 32MHz. clockInit(); // This UART is connected to the UC3 device and provides connectivity // via USB. uartInit(&UARTC0, 8); // 115,200 BAUD // This UART will be connected to the RadioBlocks device. uartInit(&UARTF0, 8); // 115,200 BAUD // Init the globals. isrLen = 0; cmdLen = 0; cmdFlag = 0; testCmd = 0; wakeCmd = 0; isrCmd = 0; ackStatus = 0; // Fun! ledFlag = 0; // These are used to help in debug. Used to print strings // to USARTC0 which is connected to the xplained-a1 usb // port through the on-board UC3. userEnd = 0; userStart = 0; // DEBUG - Create delay timer. //startTimer(1000); // One millisecond test. // Configure PORTA as output to measure delay timer... // These pins are on Xplained header J2 PORT_SetPinsAsOutput( &PORTA, 0xFF ); // Use one of the Xplained-A1 pins. SW4 - PD4 PORT_SetPinsAsInput( &PORTD, 0x10 ); // Check UART operation //testUartTx(); // Enable global interrupts. sei(); // Create a function pointer to use with the user uart (UARTC0). void (*puartBuf)(uint8_t* , uint8_t); // Assign that function pointer to the send data to RadioBlocks. puartBuf = &sendUARTF0; /////////////////////// TEST CODE ////////////////// #if 0 for(uint16_t i=0; i<CIRCSIZE; i++) sniffBuff[i] = 255; toggleLed(puartBuf, LED_TOGGLE, uartBuf); testRequest(puartBuf, uartBuf); setAddress(puartBuf, 0x1234, uartBuf); getAddress(puartBuf, uartBuf); sleepRequest(puartBuf, 1000, uartBuf); settingsRequest(puartBuf, uartBuf, RESTORE_CURRENT_SETTINGS); configureUART(puartBuf, DATA_BITS_8, PARITY_NONE, STOP_BITS_1, BAUD_115200, uartBuf); setPanid(puartBuf, 0x5678, uartBuf); getPanid(puartBuf, uartBuf); setChannel(puartBuf, CHANNEL_16, uartBuf); getChannel(puartBuf,uartBuf); setTRXState(puartBuf, TX_ON, uartBuf); getTRXState(puartBuf, uartBuf); dataRequest(puartBuf, 0x0001, DATA_OPTION_NONE, 0x42, 6, testBuf, uartBuf); setTxPower(puartBuf, TX_POWER_2_8_DBM, uartBuf); getTxPower(puartBuf, uartBuf); //setSecurityKey(puartBuf, uint8_t* key, uartBuf); // max 16 bytes. #endif toggleLed(puartBuf, LED_TOGGLE, uartBuf); processResponse(); usartUartPrint(); testRequest(puartBuf, uartBuf); processResponse(); usartUartPrint(); processResponse(); usartUartPrint(); setAddress(puartBuf, 0x1234, uartBuf); processResponse(); usartUartPrint(); getAddress(puartBuf, uartBuf); processResponse(); usartUartPrint(); processResponse(); usartUartPrint(); setPanid(puartBuf, 0x5678, uartBuf); processResponse(); usartUartPrint(); getPanid(puartBuf, uartBuf); processResponse(); usartUartPrint(); processResponse(); usartUartPrint(); setChannel(puartBuf, CHANNEL_16, uartBuf); processResponse(); usartUartPrint(); getChannel(puartBuf,uartBuf); processResponse(); usartUartPrint(); processResponse(); usartUartPrint(); // setTRXState(puartBuf, TX_ON, uartBuf); // processResponse(); // getTRXState(puartBuf, uartBuf); // processResponse(); // processResponse(); setTxPower(puartBuf, TX_POWER_2_8_DBM, uartBuf); processResponse(); usartUartPrint(); getTxPower(puartBuf, uartBuf); processResponse(); usartUartPrint(); processResponse(); usartUartPrint(); dataRequest(puartBuf, 0x0001, DATA_OPTION_NONE, 0x42, 6, testBuf, uartBuf); processResponse(); usartUartPrint(); setTRXState(puartBuf, RX_ON, uartBuf); processResponse(); usartUartPrint(); getTRXState(puartBuf, uartBuf); processResponse(); usartUartPrint(); processResponse(); usartUartPrint(); while(1) { processResponse(); usartUartPrint(); // Fun. // toggleLed(puartBuf, LED_TOGGLE, uartBuf); // timerLoop(100); // WARNING, can BLOCK a loooong time. // processResponse(); // testBuf[5]++; // setTRXState(puartBuf, TX_ON, uartBuf); // processResponse(); // dataRequest(puartBuf, 0x0001, DATA_OPTION_NONE, 0x42, 6, testBuf, uartBuf); // processResponse(); // setTRXState(puartBuf, RX_ON, uartBuf); // processResponse(); /* USER CODE HERE! */ } }
QVariant QgsAggregateCalculator::calculate( QgsAggregateCalculator::Aggregate aggregate, const QString& fieldOrExpression, QgsExpressionContext* context, bool* ok ) const { if ( ok ) *ok = false; if ( !mLayer ) return QVariant(); QScopedPointer<QgsExpression> expression; QScopedPointer<QgsExpressionContext> defaultContext; if ( !context ) { defaultContext.reset( createContext() ); context = defaultContext.data(); } int attrNum = mLayer->fieldNameIndex( fieldOrExpression ); if ( attrNum == -1 ) { Q_ASSERT( context ); context->setFields( mLayer->fields() ); // try to use expression expression.reset( new QgsExpression( fieldOrExpression ) ); if ( expression->hasParserError() || !expression->prepare( context ) ) { return QVariant(); } } QStringList lst; if ( expression.isNull() ) lst.append( fieldOrExpression ); else lst = expression->referencedColumns(); QgsFeatureRequest request = QgsFeatureRequest() .setFlags(( expression.data() && expression->needsGeometry() ) ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) .setSubsetOfAttributes( lst, mLayer->fields() ); if ( !mFilterExpression.isEmpty() ) request.setFilterExpression( mFilterExpression ); if ( context ) request.setExpressionContext( *context ); //determine result type QVariant::Type resultType = QVariant::Double; if ( attrNum == -1 ) { // evaluate first feature, check result type QgsFeatureRequest testRequest( request ); testRequest.setLimit( 1 ); QgsFeature f; QgsFeatureIterator fit = mLayer->getFeatures( testRequest ); if ( !fit.nextFeature( f ) ) { //no matching features if ( ok ) *ok = true; return QVariant(); } if ( context ) context->setFeature( f ); QVariant v = expression->evaluate( context ); resultType = v.type(); } else { resultType = mLayer->fields().at( attrNum ).type(); } QgsFeatureIterator fit = mLayer->getFeatures( request ); return calculate( aggregate, fit, resultType, attrNum, expression.data(), mDelimiter, context, ok ); }