Beispiel #1
0
static void hottSendTelemetryData(void) {
    if (!hottIsSending) {
        hottIsSending = true;
        // FIXME temorary workaround for HoTT not working on Hardware serial ports due to hardware/softserial serial port initialisation differences
        //serialSetMode(hottPort, MODE_TX);
        closeSerialPort(hottPort);
        hottPort = openSerialPort(portConfig->identifier, FUNCTION_TELEMETRY_HOTT, NULL, HOTT_BAUDRATE, MODE_TX, SERIAL_NOT_INVERTED);
        hottMsgCrc = 0;
        return;
    }

    if (hottMsgRemainingBytesToSendCount == 0) {
        hottMsg = NULL;
        hottIsSending = false;

        // FIXME temorary workaround for HoTT not working on Hardware serial ports due to hardware/softserial serial port initialisation differences
        //serialSetMode(hottPort, MODE_RX);
        closeSerialPort(hottPort);
        hottPort = openSerialPort(portConfig->identifier, FUNCTION_TELEMETRY_HOTT, NULL, HOTT_BAUDRATE, MODE_RX, SERIAL_NOT_INVERTED);
        flushHottRxBuffer();
        return;
    }

    --hottMsgRemainingBytesToSendCount;
    if(hottMsgRemainingBytesToSendCount == 0) {
        hottSerialWrite(hottMsgCrc++);
        return;
    }

    hottMsgCrc += *hottMsg;
    hottSerialWrite(*hottMsg++);
}
void ConsoleWindow::openSerialPort(const QString portName)
{
    if (portName.isEmpty()) return;

    settings->selectPortName(portName);
    if (serial->isOpen()) {
        if (serial->portName().compare(portName) != 0) {
            closeSerialPort();
            openSerialPort();
        }
    } else {
        openSerialPort();
    }
}
Beispiel #3
0
void TMainForm::openMyCom()
{
    m_fd = openSerialPort();
    if (m_fd < 0) {
    QMessageBox::warning(this, tr("Error"), tr("Fail to open serial port!"));
    return ;
    }

    ::write(m_fd,"AT+CNMI=2,1,0,0,0\r",strlen("AT+CNMI=2,1,0,0,0\r"));
    sleep(1);
    speedComboBox->setEnabled(false);
    dataBitsComboBox->setEnabled(false);
    parityComboBox->setEnabled(false);
    stopBitsComboBox->setEnabled(false);
    portNameComboBox->setEnabled(false);
    ok_Btn->setEnabled(false);
    
    call_Btn->setEnabled(true);
    mess_Btn->setEnabled(true);
    allmess_Btn->setEnabled(true);

    m_notifier = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); 
    connect (m_notifier, SIGNAL(activated(int)), this, SLOT(remoteDataIncoming())); 
    
 }
//Move X - Move X axis motor variable steps
//Input: Number of Steps
//Output: 0 for failure, 1 for success
//	2010/06/30:	Added backlash compensation when stepper turns around -ADE
int stepperDriver::MoveX(int steps)
{
	int temp;		//Added to handle backlash compensation when stepper changes direciton
	steps = -steps; //Axis is inverted with hardware setup
	temp = steps;

	//Check if stepper is changing directions.  If so compensate for backlash in motors.
	if ((iLastMoveX * steps)<0)
	{
		
		if (steps < 0)
			temp = steps - BACKLASH_COMPENSATION_X;
		else
			temp = steps + BACKLASH_COMPENSATION_X;
	}
	iLastMoveX = steps;
		
	//Build command string
	char command[25] = "F,C,I1M";
	
	char buf[10];
	itoa(temp,buf,10);		//convert steps to buffer string
	strcat(command,buf);	//append amount of steps to string
	strcat(command,",R");	//append run component of command
	
	//Output to Port
	
	openSerialPort();
	PortSendCommands(command);
	WaitForVXM();
	closeSerialPort();

	yCo+=steps;
	return 0;
}
Beispiel #5
0
bool sumhInit(rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig, rcReadRawDataPtr *callback)
{
    UNUSED(rxConfig);

    if (callback)
        *callback = sumhReadRawRC;

    rxRuntimeConfig->channelCount = SUMH_MAX_CHANNEL_COUNT;

    serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_RX_SERIAL);
    if (!portConfig) {
        return false;
    }

#ifdef TELEMETRY
    bool portShared = telemetryCheckRxPortShared(portConfig);
#else
    bool portShared = false;
#endif

    sumhPort = openSerialPort(portConfig->identifier, FUNCTION_RX_SERIAL, sumhDataReceive, SUMH_BAUDRATE, portShared ? MODE_RXTX : MODE_RX, SERIAL_NOT_INVERTED);

#ifdef TELEMETRY
    if (portShared) {
        telemetrySharedPort = sumhPort;
    }
#endif

    return sumhPort != NULL;
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    monitor = new PortMonitor(this);
    //przyciski
    connect(ui->pushButtonConnect,SIGNAL(clicked()),monitor,SLOT(openSerialPort()));
    connect(ui->pushButtonPreferences,SIGNAL(clicked()),monitor->settings,SLOT(show()));
    connect(ui->pushButtonDisconnect,SIGNAL(clicked()),monitor,SLOT(closeSerialPort()));
    //sygnały wysyłane, przez monitor portu
    connect(monitor,SIGNAL(newDataArrived(QByteArray)),this,SLOT(showData(QByteArray)));
    connect(monitor,SIGNAL(newLeftVerticaTriggerValue(int)),ui->verticalSliderLeftVerticalTrigger,SLOT(setValue(int)));
    connect(monitor,SIGNAL(newLeftHorizontalTriggerValue(int)),ui->horizontalSliderLeftHorizontalTrigger,SLOT(setValue(int)));
    connect(monitor,SIGNAL(newRightVerticaTriggerValue(int)),ui->verticalSliderRightVerticalTrigger,SLOT(setValue(int)));
    connect(monitor,SIGNAL(newRightHorizontalTriggerValue(int)),ui->horizontalSliderRightHorizontalTrigger,SLOT(setValue(int)));
    connect(monitor,SIGNAL(newLeftTriggerString(QString)),ui->labelLeftTrigger,SLOT(setText(QString)));
    connect(monitor,SIGNAL(newRightTriggerString(QString)),ui->labelRightTrigger,SLOT(setText(QString)));
    //dostosowanie kontrolek
    ui->verticalSliderLeftVerticalTrigger->setMinimum(-100);
    ui->verticalSliderLeftVerticalTrigger->setMaximum(100);
    ui->verticalSliderRightVerticalTrigger->setMinimum(-100);
    ui->verticalSliderRightVerticalTrigger->setMaximum(100);
    ui->horizontalSliderLeftHorizontalTrigger->setMinimum(-100);
    ui->horizontalSliderLeftHorizontalTrigger->setMaximum(100);
    ui->horizontalSliderRightHorizontalTrigger->setMinimum(-100);
    ui->horizontalSliderRightHorizontalTrigger->setMaximum(100);
}
Beispiel #7
0
/**
 * @brief Widget::Widget
 * @param parent
 */
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    ,serialPort(new QSerialPort(this))
    ,serialPortStatusBar(new QStatusBar())
    ,serialPortLabel(new QLabel(tr("Serial port:")))
    ,serialPortComboBox(new QComboBox())
    ,serialPortBaudRateLabel(new QLabel(tr("Baud Rate:")))
    ,serialPortBaudRateComboBox(new QComboBox())
    ,serialPortDataBitsLabel(new QLabel(tr("Data Bits:")))
    ,serialPortDataBisComboBox(new QComboBox())
    ,serialPortParityLabel(new QLabel(tr("Parity:")))
    ,serialPortParityComboBox(new QComboBox())
    ,serialPortStopBitsLabel(new QLabel(tr("Stop Bits:")))
    ,serialPortStopBitsComboBox(new QComboBox())
    ,serialPortFlowControlLabel(new QLabel(tr("Flow Control:")))
    ,serialPortFlowControlComboBox(new QComboBox())
    ,closeOrOpenSerialPortBtn(new QPushButton(tr("Open Serial Port")))
    ,senderBtn(new QPushButton(tr("Send")))
    ,serialPortTextBrowser(new QTextBrowser())
    ,serialPortLineEdit(new QLineEdit())
{
    setWindowIcon(QIcon(":/new/Icon/ICON"));
    setWindowTitle(tr("SerialCOM Assistant"));
    setUI();
    openSerialPort();
    activeSignalAndSlot();
}
Beispiel #8
0
gpsEnablePassthroughResult_e gpsEnablePassthrough(void)
{
    if (gpsData.state != GPS_RECEIVING_DATA)
        return GPS_PASSTHROUGH_NO_GPS;

    serialPort_t *gpsPassthroughPort = findOpenSerialPort(FUNCTION_GPS_PASSTHROUGH);
    if (gpsPassthroughPort) {

        waitForSerialPortToFinishTransmitting(gpsPassthroughPort);
        serialSetBaudRate(gpsPassthroughPort, serialConfig->gps_passthrough_baudrate);
    } else {
        gpsPassthroughPort = openSerialPort(FUNCTION_GPS_PASSTHROUGH, NULL, serialConfig->gps_passthrough_baudrate, MODE_RXTX, SERIAL_NOT_INVERTED);
        if (!gpsPassthroughPort) {
            return GPS_PASSTHROUGH_NO_SERIAL_PORT;
        }
    }

    LED0_OFF;
    LED1_OFF;

    while(1) {
        if (serialTotalBytesWaiting(gpsPort)) {
            LED0_ON;
            serialWrite(gpsPassthroughPort, serialRead(gpsPort));
            LED0_OFF;
        }
        if (serialTotalBytesWaiting(gpsPassthroughPort)) {
            LED1_ON;
            serialWrite(gpsPort, serialRead(gpsPassthroughPort));
            LED1_OFF;
        }
    }
    return GPS_PASSTHROUGH_ENABLED;
}
Beispiel #9
0
MainWindow::MainWindow()
{
    //QMainWindow(parent),

    messages = new char;
    //free(messages),messages = NULL;
    //messages[0] = '1';

    first = new bool;
    first = true;
    serial = new QSerialPort(this);

    settings = new SettingsDialog;

    // Création et disposition des widgets de la fenêtre
    etatServeur = new QLabel;
    boutonQuitter = new QPushButton(tr("Quitter"));
    buttonUartConnect = new QPushButton(tr("Open Uart"));
    buttonUartDisconnect = new QPushButton(tr("Close Uart"));
    buttonSettings = new QPushButton(tr("Uart Settings"));
    buttona = new QPushButton(tr("1"));


    connect(buttona, SIGNAL(clicked()), this, SLOT(open1()));


    connect(buttonUartConnect, SIGNAL(clicked()), this, SLOT(openSerialPort()));
    connect(buttonUartDisconnect, SIGNAL(clicked()), this, SLOT(closeSerialPort()));
    connect(boutonQuitter, SIGNAL(clicked()), qApp, SLOT(quit()));
    connect(buttonSettings, SIGNAL(clicked()), settings, SLOT(show()));

    connect(serial, SIGNAL(readyRead()), this, SLOT(readData()));

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(etatServeur);
    layout->addWidget(buttona);
    layout->addWidget(buttonSettings);
    layout->addWidget(buttonUartConnect);
    layout->addWidget(buttonUartDisconnect);
    layout->addWidget(boutonQuitter);
    setLayout(layout);

    setWindowTitle(tr("ZeroChat - Serveur"));

    // Gestion du serveur
    serveur = new QTcpServer(this);
    if (!serveur->listen(QHostAddress::Any, 50885)) // Démarrage du serveur sur toutes les IP disponibles et sur le port 50585
    {
        // Si le serveur n'a pas été démarré correctement
        etatServeur->setText(tr("Le serveur n'a pas pu être démarré. Raison :<br />") + serveur->errorString());
    }
    else
    {
        // Si le serveur a été démarré correctement
        etatServeur->setText(tr("Le serveur a été démarré sur le port <strong>") + QString::number(serveur->serverPort()) + tr("</strong>.<br />Des clients peuvent maintenant se connecter."));
        connect(serveur, SIGNAL(newConnection()), this, SLOT(nouvelleConnexion()));
    }
    tailleMessage = 0;
}
Beispiel #10
0
void cliInit(serialConfig_t *serialConfig)
{
    cliPort = findOpenSerialPort(FUNCTION_CLI);
    if (!cliPort) {
        cliPort = openSerialPort(FUNCTION_CLI, NULL, serialConfig->cli_baudrate, MODE_RXTX, SERIAL_NOT_INVERTED);
    }

}
Beispiel #11
0
void MainWindow::initSerialPort(){
    Terminal *serial1 = new Terminal;
    serial1->terminalInitialisation();

    QObject::connect(SerialConnectButton, SIGNAL(clicked()), serial1, SLOT(on_bouton_serial_connexion_clicked()));
    QObject::connect(serial1,SIGNAL(openSerialPortTerminal()),this,SLOT(openSerialPort()));
    QObject::connect(serial1,SIGNAL(closeSerialPortTerminal()),this,SLOT(closeSerialPort()));
}
//Move Up - Move Motor 2 +1000 steps
//Input: None
//Output: 0 for failure, 1 for success
int stepperDriver::MoveUp() 
{
	int temp = openSerialPort();		//add error code if needed
	temp = PortSendCommands("F,C,I2M1000,R"); //Move Motor 2 +5 steps
	temp = WaitForVXM();					//Wait for VMX program to finish
	temp = closeSerialPort();

	yCo+=1000;
	return temp;
}
Beispiel #13
0
int main(int argc, const char * argv[]) {
    
    int port;
    
    port = openSerialPort("/dev/tty....");
    initConnection(port);
    initListener();
    
    return 0;
}
void MainWindow::initActionsConnections()
{
    connect(ui->actionConnect, SIGNAL(triggered()), this, SLOT(openSerialPort()));
    connect(ui->actionDisconnect, SIGNAL(triggered()), this, SLOT(closeSerialPort()));
    connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close()));
    connect(ui->actionConfigure, SIGNAL(triggered()), settings, SLOT(show()));
    connect(ui->actionClear, SIGNAL(triggered()), console, SLOT(clear()));
    connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
    connect(ui->actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}
Beispiel #15
0
void HexySerial::onSettingsChanged()
{
	{
		QSignalBlocker(this);
		closeSerialPort();
		openSerialPort();
		settings->hide();
		//version();
		writeData("\n");
	}
	emit settingsChanged();
}
Beispiel #16
0
void MainWindow::on_pushButtonConnect_clicked()
{
    if (serialPort->isOpen())
    {
        closeSerialPort();
        ui->pushButtonConnect->setText(QStringLiteral("Connect"));
    }
    else if(openSerialPort())
    {
        ui->pushButtonConnect->setText(QStringLiteral("Disconnect"));
    }
}
Beispiel #17
0
void CheckOption::printInfo()
{
    update();
    emit shouldupdate();
    seriport_print=openSerialPort("/dev/ttySAC2");
    if (seriport_print < 0) {
        warning->setText("Fail to open serial port!");
        warning->move(200,200);
        warning->show();
    }

    QString Reallyserinumber;
    if(weatherSaved)//if saved;
        Reallyserinumber=serialNumber;
    else
        Reallyserinumber="";
    inputUserName=*MyInputUsername;
    char *print;
    print=(char *)malloc(500*sizeof(char));
    int printlength;
    int i;

    strcpy(print,"\nMagiCare RTR-FS100 打印报告");
    strcat(print,"\n");
    strcat(print,"\n");
    strcat(print,"\n签名:");
    strcat(print,"\n检测结果(a.u.):");
    strcat(print,data.toUtf8().data());
    strcat(print,"\n检测项目:");
    strcat(print,ui->comboBox->currentText().toUtf8().data());
    strcat(print,"\n年龄:");
    strcat(print,ui->lineEdit_Age->text().toUtf8().data());
    strcat(print,"\n性别:");
    strcat(print,ui->comboBox_gender->currentText().toUtf8().data());
    strcat(print,"\n姓名:");
    strcat(print,ui->lineEdit_Name->text().toUtf8().data());
    strcat(print,"\n检测编号:");
    strcat(print,ui->lineEdit_ID->text().toUtf8().data());
    strcat(print,"\n批次号:");
    strcat(print,ui->lineEdit_Bach->text().toUtf8().data());//no need to show Serialnumber
    strcat(print,"\n时间:");
    strcat(print,CurrentDate.time().toString().toUtf8().data());
    strcat(print,"\n日期:");
    strcat(print,YearDate.toUtf8().data());
    strcat(print,"\n");
    strcat(print,"\n");
    strcat(print,"\n");
    strcat(print,"\n");

    printlength=strlen(print);
    miniPrintWriteUnicode(seriport_print,print);
}
Beispiel #18
0
void configureFrSkyTelemetryPort(void)
{
    if (!portConfig) {
        return;
    }

    frskyPort = openSerialPort(portConfig->identifier, FUNCTION_TELEMETRY_FRSKY, NULL, FRSKY_BAUDRATE, FRSKY_INITIAL_PORT_MODE, telemetryConfig->telemetry_inversion ? SERIAL_INVERTED : SERIAL_NOT_INVERTED);
    if (!frskyPort) {
        return;
    }

    frskyTelemetryEnabled = true;
}
Beispiel #19
0
int main()
{
    int fd=openSerialPort();


    for(int i=0; i<100; i++) testLoopback(fd,i);


    close(fd);


    return 0;
}
Beispiel #20
0
void gpsInit(serialConfig_t *initialSerialConfig, gpsConfig_t *initialGpsConfig)
{
    gpsState.serialConfig = initialSerialConfig;
    gpsState.gpsConfig = initialGpsConfig;
    gpsState.baudrateIndex = 0;

    gpsStats.errors = 0;
    gpsStats.timeouts = 0;

    gpsResetSolution();

    // init gpsData structure. if we're not actually enabled, don't bother doing anything else
    gpsState.autoConfigStep = 0;
    gpsState.lastMessageMs = millis();
    gpsSetState(GPS_UNKNOWN);

    if (gpsProviders[gpsState.gpsConfig->provider].type == GPS_TYPE_BUS) {
        gpsSetState(GPS_INITIALIZING);
        return;
    }

    if (gpsProviders[gpsState.gpsConfig->provider].type == GPS_TYPE_SERIAL) {
        serialPortConfig_t * gpsPortConfig = findSerialPortConfig(FUNCTION_GPS);
        if (!gpsPortConfig) {
            featureClear(FEATURE_GPS);
        }
        else {
            while (gpsToSerialBaudRate[gpsState.baudrateIndex] != gpsPortConfig->gps_baudrateIndex) {
                gpsState.baudrateIndex++;
                if (gpsState.baudrateIndex >= GPS_BAUDRATE_COUNT) {
                    gpsState.baudrateIndex = 0;
                    break;
                }
            }

            portMode_t mode = gpsProviders[gpsState.gpsConfig->provider].portMode;

            // no callback - buffer will be consumed in gpsThread()
            gpsState.gpsPort = openSerialPort(gpsPortConfig->identifier, FUNCTION_GPS, NULL, baudRates[gpsToSerialBaudRate[gpsState.baudrateIndex]], mode, SERIAL_NOT_INVERTED);

            if (!gpsState.gpsPort) {
                featureClear(FEATURE_GPS);
            }
            else {
                gpsSetState(GPS_INITIALIZING);
                return;
            }
        }
    }
}
Beispiel #21
0
bool sbusInit(rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig, rcReadRawDataPtr *callback)
{
    int b;

    sBusPort = openSerialPort(FUNCTION_SERIAL_RX, sbusDataReceive, SBUS_BAUDRATE, (portMode_t)(MODE_RX | MODE_SBUS), SERIAL_INVERTED);

    for (b = 0; b < SBUS_MAX_CHANNEL; b++)
        sbusChannelData[b] = (1.6f * rxConfig->midrc) - 1408;
    if (callback)
        *callback = sbusReadRawRC;
    rxRuntimeConfig->channelCount = SBUS_MAX_CHANNEL;

    return sBusPort != NULL;
}
Beispiel #22
0
void configureLtmTelemetryPort(void)
{
    if (!portConfig) {
        return;
    }
    baudRate_e baudRateIndex = portConfig->telemetry_baudrateIndex;
    if (baudRateIndex == BAUD_AUTO) {
        baudRateIndex = BAUD_19200;
    }
    ltmPort = openSerialPort(portConfig->identifier, FUNCTION_TELEMETRY_LTM, NULL, baudRates[baudRateIndex], TELEMETRY_LTM_INITIAL_PORT_MODE, SERIAL_NOT_INVERTED);
    if (!ltmPort)
        return;
    ltmEnabled = true;
}
Beispiel #23
0
void configureHoTTTelemetryPort(void)
{
    if (!portConfig) {
        return;
    }

    hottPort = openSerialPort(portConfig->identifier, FUNCTION_TELEMETRY_HOTT, NULL, HOTT_BAUDRATE, HOTT_INITIAL_PORT_MODE, SERIAL_NOT_INVERTED);

    if (!hottPort) {
        return;
    }

    hottTelemetryEnabled = true;
}
void EasyTransferPi::begin(uint8_t *ptr, uint8_t lenght, qint32 baudRate)
{
    address=ptr;
    size=lenght;
    isDataRecieved=FALSE;
    baud=baudRate;
    rx_array_inx=0;
    rx_buffer=(uint8_t*)malloc(size+1);
    portManager=new SerialPortManager();
    connect(portManager, SIGNAL(eventDataRecieved(QByteArray&)), this, SLOT(onDataIncoming(QByteArray&)));
    connect(portManager,SIGNAL(eventConnectionEstablished()),this,SLOT(onConnected()));

    openSerialPort();
}
Beispiel #25
0
int main(int argc, char **argv)
{
    char	deviceFilePath[MAXPATHLEN];
    int		fileDescriptor;
    int		c;
    int		bCont;	// flag for continuous operation
    struct sigaction act;

    opterr = 0;
    while ((c=getopt(argc, argv, "cd:h")) != -1) {
	switch (c) {
	    case 'c': bCont = 1; break;
	    case 'd': strcpy(deviceFilePath, optarg); break;
	    case 'h': printHelp(); return 1;
	    case '?': if (optopt=='d')
			fprintf(stderr, "Option -%c requires an argument.\n", optopt);
		      else if (isprint (optopt))
			fprintf(stderr, "Unknown option '-%c'.\n", optopt);
		      else
			fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt);
		      return 1;
	    default: abort();
	}
    }

    act.sa_handler = intHandler;
    sigaction(SIGINT, &act, NULL);	// catch Ctrl-C

//printf ("dev: %s\n", deviceFilePath);

    if (!deviceFilePath[0])
    {
        printf("No serial device found. Did you specify the '-d /dev/device' option?\n");
        return EX_UNAVAILABLE;
    }

    fileDescriptor = openSerialPort(deviceFilePath);
    if (fileDescriptor == -1)
    {
        return EX_IOERR;
    }

    if (!(readSerialData(fileDescriptor, bCont))) {
        printf("Could not read data.\n");
    }

    closeSerialPort(fileDescriptor);
//    printf("Modem port closed.\n");
    return EX_OK;
}
Beispiel #26
0
void BuzzerControl::serialGo(bool state) {
    if (state) {
        QString serialPort = serialPortList->currentText();
        start->setText("Disconnect");
        emit openSerialPort(serialPort);
        serialPortList->setEnabled(false);
        refresh->setEnabled(false);
    } else {
        start->setText("Connect");
        emit closeSerialPort();
        serialPortList->setEnabled(true);
        refresh->setEnabled(true);
    }
}
Beispiel #27
0
void gpsInit(serialConfig_t *initialSerialConfig, gpsConfig_t *initialGpsConfig)
{
    serialConfig = initialSerialConfig;


    gpsData.baudrateIndex = 0;
    gpsData.errors = 0;
    gpsData.timeouts = 0;

    memset(gpsPacketLog, 0x00, sizeof(gpsPacketLog));

    gpsConfig = initialGpsConfig;

    // init gpsData structure. if we're not actually enabled, don't bother doing anything else
    gpsSetState(GPS_UNKNOWN);

    gpsData.lastMessage = millis();

    serialPortConfig_t *gpsPortConfig = findSerialPortConfig(FUNCTION_GPS);
    if (!gpsPortConfig) {
        featureClear(FEATURE_GPS);
        return;
    }

    while (gpsInitData[gpsData.baudrateIndex].baudrateIndex != gpsPortConfig->gps_baudrateIndex) {
        gpsData.baudrateIndex++;
        if (gpsData.baudrateIndex >= GPS_INIT_DATA_ENTRY_COUNT) {
            gpsData.baudrateIndex = DEFAULT_BAUD_RATE_INDEX;
            break;
        }
    }

    portMode_t mode = MODE_RXTX;
    // only RX is needed for NMEA-style GPS
#if !defined(COLIBRI_RACE) || !defined(LUX_RACE)
    if (gpsConfig->provider == GPS_NMEA)
        mode &= ~MODE_TX;
#endif

    // no callback - buffer will be consumed in gpsThread()
    gpsPort = openSerialPort(gpsPortConfig->identifier, FUNCTION_GPS, NULL, gpsInitData[gpsData.baudrateIndex].baudrateIndex, mode, SERIAL_NOT_INVERTED);
    if (!gpsPort) {
        featureClear(FEATURE_GPS);
        return;
    }

    // signal GPS "thread" to initialize when it gets to it
    gpsSetState(GPS_INITIALIZING);
}
/***********************************************************************************************************************
int main(int argc, char **argv)
program entry point, expects the serial port name as a command line argument
***********************************************************************************************************************/
int main(int argc, char **argv)
{
    // store the port parameters
    char* portName;
    int serialPort;

    // parse the command line arguments
    if(argc != 2)
    {
        printf("USAGE: %s <port_name> \n", argv[0]);
        return 0;
    }
    portName = argv[1];

    // attempt to open the serial port
    serialPort = openSerialPort(portName);

    // check to see if we connected successfully
    if(serialPort == -1)
    {
        printf("unable to open serial port %s \n", portName);
        return(0);
    }
    printf("%s opened successfully!\n", portName);

    // continuously check for received serial data
    int numBytes = 0;
    while(1)
    {
        // check for received serial data
        numBytes = numBytes + pollSerialPort(serialPort);

        // send a packet
        sendPacket(serialPort, 0x01, 0x02, 0x03);

        // stop listening for data once we receive 100 bytes
        if(numBytes >= 100)
        {
            break;
        }

        // sleep for 20ms (20*1000 microseconds)
        usleep(20*1000);
    }

    // close the serial port
    closeSerialPort(serialPort);
}
Beispiel #29
0
bool sumdInit(rxRuntimeConfig_t *rxRuntimeConfig, rcReadRawDataPtr *callback)
{
    if (callback)
        *callback = sumdReadRawRC;

    rxRuntimeConfig->channelCount = SUMD_MAX_CHANNEL;

    serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_RX_SERIAL);
    if (!portConfig) {
        return false;
    }

    serialPort_t *sumdPort = openSerialPort(portConfig->identifier, FUNCTION_RX_SERIAL, sumdDataReceive, SUMD_BAUDRATE, MODE_RX, SERIAL_NOT_INVERTED);

    return sumdPort != NULL;
}
Beispiel #30
0
bool sbusInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
{
    static uint16_t sbusChannelData[SBUS_MAX_CHANNEL];
    static sbusFrameData_t sbusFrameData;

    rxRuntimeConfig->channelData = sbusChannelData;
    rxRuntimeConfig->frameData = &sbusFrameData;
    sbusChannelsInit(rxConfig, rxRuntimeConfig);

    rxRuntimeConfig->channelCount = SBUS_MAX_CHANNEL;
    rxRuntimeConfig->rxRefreshRate = 11000;

    rxRuntimeConfig->rcFrameStatusFn = sbusFrameStatus;

    const serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_RX_SERIAL);
    if (!portConfig) {
        return false;
    }

#ifdef USE_TELEMETRY
    bool portShared = telemetryCheckRxPortShared(portConfig);
#else
    bool portShared = false;
#endif

    serialPort_t *sBusPort = openSerialPort(portConfig->identifier,
        FUNCTION_RX_SERIAL,
        sbusDataReceive,
        &sbusFrameData,
        SBUS_BAUDRATE,
        portShared ? MODE_RXTX : MODE_RX,
        SBUS_PORT_OPTIONS | (rxConfig->serialrx_inverted ? 0 : SERIAL_INVERTED) | (rxConfig->halfDuplex ? SERIAL_BIDIR : 0)
        );

    if (rxConfig->rssi_src_frame_errors) {
        rssiSource = RSSI_SOURCE_FRAME_ERRORS;
    }

#ifdef USE_TELEMETRY
    if (portShared) {
        telemetrySharedPort = sBusPort;
    }
#endif

    return sBusPort != NULL;
}