bool RepeatedTimeData::insertSignalValue(quint64 index, qreal value) { bool retval=false; const qreal * envelopData; qreal *_s=signalData(); RepeatedTimeDataParams* _params=dynamic_cast<RepeatedTimeDataParams*>(getDataParameters()); Q_ASSERT(_params); quint64 _sampleSingleShotDuration=qFloor((_params->duration()+_params->blankTime())*_params->sampleRate()); quint64 lowestIndex=lowestSampleIndexForModification(); bool _envEnable=getEnvelopeParameters()->isEnabledEnvelope(); if (_envEnable) { envelopData=getEnvelope()->getEnvelope(); } qreal _tVal; if ((lowestIndex<=index) && (index<=highestSampleIndexForModification()) ) { _tVal=(_envEnable ? value*envelopData[index-lowestIndex] : value); quint64 i; for (unsigned int _rep=0; _rep < m_repetitions; _rep++) { i=_rep*_sampleSingleShotDuration+index; // Q_ASSERT(i<=getSampleNumber()); if (i<=getSampleNumber()) _s[i]= _tVal; else break; } retval=true; } return retval; }
void Widget::on_pushButton_test_clicked() { if(!m_thread->isRunning()) { m_thread->start(); } int a = 1; unsigned int add = (unsigned int)&a; ui->textBrowser->append("start emit local signal"); emit signalData(a,add); ui->textBrowser->append("after emit local signal"); }
void TestThread::run() { while(!m_abort) { if(1) { int a = 1; unsigned int add = (unsigned int)&a; emit signalData(a,add); } sleep(1); m_abort = true; } }
jint shmemBase_sendByte(SharedMemoryConnection *connection, jbyte data) { Stream *stream = &connection->outgoing; SharedStream *shared = stream->shared; int offset; CHECK_ERROR(enterMutex(stream, connection->shutdown)); CHECK_ERROR(waitForSpace(connection, stream)); SHMEM_ASSERT(!FULL(stream)); offset = shared->writeOffset; shared->buffer[offset] = data; shared->writeOffset = ADD_OFFSET(offset, 1); shared->isFull = (shared->readOffset == shared->writeOffset); STREAM_INVARIANT(stream); CHECK_ERROR(leaveMutex(stream)); CHECK_ERROR(signalData(stream)); return SYS_OK; }
static jint sendBytes(SharedMemoryConnection *connection, const void *bytes, jint length) { Stream *stream = &connection->outgoing; SharedStream *shared = stream->shared; jint fragmentStart; jint fragmentLength; jint index = 0; jint maxLength; clearLastError(); CHECK_ERROR(enterMutex(stream, connection->shutdown)); while (index < length) { CHECK_ERROR(waitForSpace(connection, stream)); SHMEM_ASSERT(!FULL(stream)); fragmentStart = shared->writeOffset; if (fragmentStart < shared->readOffset) { maxLength = shared->readOffset - fragmentStart; } else { maxLength = SHARED_BUFFER_SIZE - fragmentStart; } fragmentLength = MIN(maxLength, length - index); memcpy(shared->buffer + fragmentStart, (jbyte *)bytes + index, fragmentLength); shared->writeOffset = ADD_OFFSET(fragmentStart, fragmentLength); index += fragmentLength; shared->isFull = (shared->readOffset == shared->writeOffset); STREAM_INVARIANT(stream); CHECK_ERROR(signalData(stream)); } CHECK_ERROR(leaveMutex(stream)); return SYS_OK; }
int main() { if (true) { test3bitsEncoding(); return 0; } _running = true; signal(SIGTERM, &signal_handler); //------------------------- //----- SETUP USART 0 ----- //------------------------- //At bootup, pins 8 and 10 are already set to UART0_TXD, UART0_RXD (ie the alt0 function) respectively int uart0_filestream = -1; //OPEN THE UART //The flags (defined in fcntl.h): // Access modes (use 1 of these): // O_RDONLY - Open for reading only. // O_RDWR - Open for reading and writing. // O_WRONLY - Open for writing only. // // O_NDELAY / O_NONBLOCK (same function) - Enables nonblocking mode. When set read requests on the file can return immediately with a failure status // if there is no input immediately available (instead of blocking). Likewise, write requests can also return // immediately with a failure status if the output can't be written immediately. // // O_NOCTTY - When set and path identifies a terminal device, open() shall not cause the terminal device to become the controlling terminal for the process. uart0_filestream = open("/dev/ttyAMA0", O_WRONLY | O_NOCTTY | O_NDELAY); //Open in non blocking read/write mode if (uart0_filestream == -1) { //ERROR - CAN'T OPEN SERIAL PORT printf("Error - Unable to open UART. Ensure it is not in use by another application\n"); } // if (0) { //CONFIGURE THE UART //The flags (defined in /usr/include/termios.h - see http://pubs.opengroup.org/onlinepubs/007908799/xsh/termios.h.html): // Baud rate:- B1200, B2400, B4800, B9600, B19200, B38400, B57600, B115200, B230400, B460800, B500000, B576000, B921600, B1000000, B1152000, B1500000, B2000000, B2500000, B3000000, B3500000, B4000000 // CSIZE:- CS5, CS6, CS7, CS8 // CLOCAL - Ignore modem status lines // CREAD - Enable receiver // IGNPAR = Ignore characters with parity errors // ICRNL - Map CR to NL on input (Use for ASCII comms where you want to auto correct end of line characters - don't use for bianry comms!) // PARENB - Parity enable // PARODD - Odd parity (else even) struct termios options; tcgetattr(uart0_filestream, &options); options.c_cflag = B4000000 | CS8 | CLOCAL; //<Set baud rate options.c_iflag = IGNPAR; options.c_oflag = 0; options.c_lflag = 0; cfmakeraw(&options); std::cout << "options.c_cflag = " << options.c_cflag << std::endl; std::cout << "options.c_iflag = " << options.c_iflag << std::endl; std::cout << "options.c_oflag = " << options.c_oflag << std::endl; std::cout << "options.c_lflag = " << options.c_lflag << std::endl; tcflush(uart0_filestream, TCIFLUSH); tcsetattr(uart0_filestream, TCSANOW, &options); // Let's verify configured options tcgetattr(uart0_filestream, &options); std::cout << "options.c_cflag = " << options.c_cflag << std::endl; std::cout << "options.c_iflag = " << options.c_iflag << std::endl; std::cout << "options.c_oflag = " << options.c_oflag << std::endl; std::cout << "options.c_lflag = " << options.c_lflag << std::endl; } { struct serial_struct ser; if (-1 == ioctl(uart0_filestream, TIOCGSERIAL, &ser)) { std::cerr << "Failed to obtian 'serial_struct' for setting custom baudrate" << std::endl; } std::cout << "Current divisor: " << ser.custom_divisor << " ( = " << ser.baud_base << " / 4000000" << std::endl; // set custom divisor ser.custom_divisor = ser.baud_base / 8000000; // update flags ser.flags &= ~ASYNC_SPD_MASK; ser.flags |= ASYNC_SPD_CUST; std::cout << "Current divisor: " << ser.custom_divisor << " ( = " << ser.baud_base << " / 8000000" << std::endl; if (-1 == ioctl(uart0_filestream, TIOCSSERIAL, &ser)) { std::cerr << "Failed to configure 'serial_struct' for setting custom baudrate" << std::endl; } // Check result if (-1 == ioctl(uart0_filestream, TIOCGSERIAL, &ser)) { std::cerr << "Failed to obtian 'serial_struct' for setting custom baudrate" << std::endl; } std::cout << "Current divisor: " << ser.custom_divisor << " ( = " << ser.baud_base << " / 4000000" << std::endl; } if (uart0_filestream < 0) { std::cerr << "Opening the device has failed" << std::endl; return -1; } //----- TX BYTES ----- std::vector<ColorSignal> signalData(10, RED_Signal); int loopCnt = 0; std::cout << "Type 'c' to continue, 'q' or 'x' to quit: "; while (_running) { char c = getchar(); if (c == 'q' || c == 'x') { break; } if (c != 'c') { continue; } set_realtime_priority(); for (int iRun=0; iRun<10; ++iRun) { // tcflush(uart0_filestream, TCOFLUSH); write(uart0_filestream, signalData.data(), signalData.size()*sizeof(ColorSignal)); tcdrain(uart0_filestream); usleep(100000); ++loopCnt; if (loopCnt%3 == 2) signalData = std::vector<ColorSignal>(10, GREEN_Signal); else if(loopCnt%3 == 1) signalData = std::vector<ColorSignal>(10, BLUE_Signal); else if(loopCnt%3 == 0) signalData = std::vector<ColorSignal>(10, RED_Signal); } } signalData = std::vector<ColorSignal>(50, BLACK_Signal); write(uart0_filestream, signalData.data(), signalData.size()*sizeof(ColorSignal)); //----- CLOSE THE UART ----- close(uart0_filestream); std::cout << "Program finished" << std::endl; return 0; }