Example #1
0
void printTsStats(void) {
#if EFI_PROD_CODE
	if (!isSerialOverUart()) {
		scheduleMsg(&tsLogger, "TS RX on %s%d/TX on %s%d @%d", portname(TS_SERIAL_RX_PORT), TS_SERIAL_RX_PIN,
				portname(TS_SERIAL_TX_PORT), TS_SERIAL_TX_PIN, boardConfiguration->tunerStudioSerialSpeed);
	}
#endif /* EFI_PROD_CODE */
	scheduleMsg(&tsLogger, "TunerStudio size=%d / total=%d / errors=%d / H=%d / O=%d / P=%d / B=%d",
			sizeof(tsOutputChannels), tsState.tsCounter, tsState.errorCounter, tsState.queryCommandCounter,
			tsState.outputChannelsCommandCounter, tsState.readPageCommandsCounter, tsState.burnCommandCounter);
	scheduleMsg(&tsLogger, "TunerStudio W=%d / C=%d / P=%d / page=%d", tsState.writeValueCommandCounter,
			tsState.writeChunkCommandCounter, tsState.pageCommandCounter, currentPageId);
	scheduleMsg(&tsLogger, "page size=%d", getTunerStudioPageSize(currentPageId));

//	scheduleMsg(logger, "analogChartFrequency %d",
//			(int) (&engineConfiguration->analogChartFrequency) - (int) engineConfiguration);
//
//	int fuelMapOffset = (int) (&engineConfiguration->fuelTable) - (int) engineConfiguration;
//	scheduleMsg(logger, "fuelTable %d", fuelMapOffset);
//
//	int offset = (int) (&boardConfiguration->hip9011Gain) - (int) engineConfiguration;
//	scheduleMsg(&tsLogger, "hip9011Gain %d", offset);
//
//	offset = (int) (&engineConfiguration->crankingCycleBins) - (int) engineConfiguration;
//	scheduleMsg(&tsLogger, "crankingCycleBins %d", offset);
//
//	offset = (int) (&engineConfiguration->engineCycle) - (int) engineConfiguration;
//	scheduleMsg(&tsLogger, "engineCycle %d", offset);
}
Example #2
0
static void *
writer(void *aport)
{
	Port *port = (Port *)aport;
	Buffer *bp;
	int nwr, nref;

	for(;;){
		bp = qget(&port->xmitq);
		if(bp == NULL)
			break;
		if(bp->len > 0){
			*(uint32_t *)bp->buf = 0;
			nwr = write(port->fd, bp->buf, bp->len);
			if(nwr != bp->len){
				fprintf(stderr, "%s: short write, got %d wanted %d\n", portname(port), nwr, bp->len);
				break;
			}
		}
		nref = bdecref(bp);
		if(nref == 0)
			qput(bp->freeq, bp);
	}
	fprintf(stderr, "%s: writer exiting\n", portname(port));
	return port;
}
Example #3
0
static void printStats(void) {
#if EFI_PROD_CODE
	if (!isSerialOverUart()) {
		scheduleMsg(&logger, "TS RX on %s%d/TX on %s%d", portname(TS_SERIAL_RX_PORT), TS_SERIAL_RX_PIN,
				portname(TS_SERIAL_TX_PORT), TS_SERIAL_TX_PIN);
	}
#endif /* EFI_PROD_CODE */
	scheduleMsg(&logger, "TunerStudio total/error counter=%d/%d H=%d / O counter=%d size=%d / P=%d / B=%d", tsCounter, tsState.errorCounter, tsState.queryCommandCounter, tsState.outputChannelsCommandCounter,
			sizeof(tsOutputChannels), tsState.readPageCommandsCounter, tsState.burnCommandCounter);
	scheduleMsg(&logger, "TunerStudio W counter=%d / C = %d / P = %d / current page %d", tsState.writeValueCommandCounter, tsState.writeChunkCommandCounter,
			tsState.pageCommandCounter, tsState.currentPageId);
	scheduleMsg(&logger, "page size=%d", sizeof(engine_configuration_s));

//	scheduleMsg(&logger, "analogChartFrequency %d",
//			(int) (&engineConfiguration->analogChartFrequency) - (int) engineConfiguration);
//
//	int fuelMapOffset = (int) (&engineConfiguration->fuelTable) - (int) engineConfiguration;
//	scheduleMsg(&logger, "fuelTable %d", fuelMapOffset);
//
//	int offset = (int) (&boardConfiguration->o2heaterPin) - (int) engineConfiguration;
//	scheduleMsg(&logger, "o2heaterPin %d", offset);
//
//	offset = (int) (&boardConfiguration->idleSolenoidFrequency) - (int) engineConfiguration;
//	scheduleMsg(&logger, "idleSolenoidFrequency %d", offset);
}
Example #4
0
    void open_client(std::string const & server_name, std::string const & name, uint32_t input_port_count,
                     uint32_t output_port_count, uint32_t blocksize)
    {
        blocksize_ = blocksize;

        /* open client */
        client = server_name.empty() ? jack_client_open(name.c_str(), JackNoStartServer, &status)
                                     : jack_client_open(name.c_str(), jack_options_t(JackNoStartServer | JackServerName),
                                                        &status, server_name.c_str());
        boost::atomic_thread_fence(boost::memory_order_release); // ensure visibility on other threads

        if (status & JackServerFailed)
            throw std::runtime_error("Unable to connect to JACK server");

        if (status & JackNameNotUnique) {
            const char * client_name = jack_get_client_name(client);
            std::cout << "unique client name: " << client_name << std::endl;
        }

        /* initialize callbacks */
        jack_set_thread_init_callback (client, jack_thread_init_callback, this);
        jack_set_process_callback (client, jack_process_callback, this);
        jack_set_xrun_callback(client, jack_xrun_callback, this);
        jack_on_info_shutdown(client, (JackInfoShutdownCallback)jack_on_info_shutdown_callback, NULL);

        /* register ports */
        input_ports.clear();
        for (uint32_t i = 0; i != input_port_count; ++i) {
            std::string portname ("input_");
            portname += std::to_string(i+1);
            jack_port_t * port =
                jack_port_register(client, portname.c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
            input_ports.push_back(port);
        }
        input_channels = input_port_count;
        super::input_samples.resize(input_port_count);

        output_ports.clear();
        for (uint32_t i = 0; i != output_port_count; ++i) {
            std::string portname ("output_");
            portname += std::to_string(i+1);
            jack_port_t * port =
                jack_port_register(client, portname.c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
            output_ports.push_back(port);
        }
        output_channels = output_port_count;
        super::output_samples.resize(output_port_count);

        samplerate_ = jack_get_sample_rate(client);
        jack_frames = jack_get_buffer_size(client);

        if (jack_frames % blocksize_)
            throw std::runtime_error("Jack buffer size is not a multiple of blocksize");
    }
Example #5
0
static void *
reader(void *aport)
{
	Buffer *bp;
	Port *port;
	Cam *cam;
	uint8_t *dstmac, *srcmac;
	int i, nrd, nref;

	port = (Port *)aport;
	for(;;){
		bp = qget(&port->freeq);

		nrd = read(port->fd, bp->buf, bp->cap);
		if(port->state != PortOpen){
			qput(bp->freeq, bp);
			break;
		}
		bp->len = nrd;

		dstmac = (uint8_t *)bp->buf + 4;
		srcmac = (uint8_t *)bp->buf + 10;

		nref = 0;
		cam = camlook(g_cams, dstmac);
		if(cam != NULL && cam->port != NULL){
			// port found in cam, forward only there...
			nref = bincref(bp);
			if(qput(&cam->port->xmitq, bp) == -1)
				nref = bdecref(bp);
		} else {
			// broadcast..
			for(i = 0; i < nports; i++){
				if(port == (ports+i))
					continue;
				nref = bincref(bp);
				if(qput(&ports[i].xmitq, bp) == -1)
					nref = bdecref(bp);
			}
		}

		// teach the switch about the source address we just saw
		cam = camlook(g_cams, srcmac);
		if(cam != NULL){
			// always update the port, so if an address moves to a different port
			// the cam will point to that port right away.
			copymac(cam->mac, srcmac);
			cam->age = 0;
			cam->port = port;
		} else {
			fprintf(stderr, "cam presumably full..\n");
		}

		// ref is zero after the forward loop. it didn't go anywhere, so drop it.
		if(nref == 0)
			qput(bp->freeq, bp);
	}
	fprintf(stderr, "%s: reader exiting..\n", portname(port));
	return port;
}
Example #6
0
static void initWave(const char *name, int index) {
	brain_pin_e brainPin = boardConfiguration->logicAnalyzerPins[index];

	ioportid_t port = getHwPort(brainPin);
	ioportmask_t pin = getHwPin(brainPin);
	ICUDriver *driver = getInputCaptureDriver(brainPin);

	bool mode = boardConfiguration->logicAnalyzerMode[index];

	waveReaderCount++;
	efiAssertVoid(index < MAX_ICU_COUNT, "too many ICUs");
	WaveReader *reader = &readers[index];
	WaveReaderHw *hw = &reader->hw;

	reader->name = name;

	registerCallback(&hw->widthListeners, (IntListener) waAnaWidthCallback, (void*) reader);

	registerCallback(&hw->periodListeners, (IntListener) waIcuPeriodCallback, (void*) reader);

	initWaveAnalyzerDriver(hw, driver, port, pin);

	print("wave%d input on %s%d\r\n", index, portname(reader->hw.port), reader->hw.pin);
	setWaveReaderMode(hw, mode);
}
Example #7
0
static void *
agecam(void *aux)
{
	Cam *cam;
	int i;
	uint16_t age;
	uint8_t zeromac[6] = {0};

	for(;;){

		for(i = 0; i < Camsize; i++){
			cam = g_cams + i;
			age = __sync_fetch_and_add(&cam->age, 1) + 1;
			if(cam->port != NULL && (age >= MaxAge || cam->port->state != PortOpen)){
				fprintf(stderr, "%s: aged cam entry\n", portname(cam->port));
				cam->port = NULL;
				copymac(cam->mac, zeromac);
			}
		}
		for(i = 0; i < nports; i++){
			Port *port;
			port = ports + i;
			if(__sync_bool_compare_and_swap(&port->state, PortClosing, PortCloseWait)){
				// this close takes a long time because it tears down a network namespace.
				if(port->fd >= 0)
					close(port->fd);
				port->fd = -1;
				pthread_kill(port->xmitthr, SIGHUP);
				pthread_kill(port->recvthr, SIGHUP);
				pthread_join(port->xmitthr, NULL);
				pthread_join(port->recvthr, NULL);
				fprintf(stderr, "%s: closed fd\n", portname(ports+i));
				__sync_bool_compare_and_swap(&port->state, PortCloseWait, PortClosed);
			}
		}
		sleep(AgeInterval);
	}

	return aux;
}
Example #8
0
char * getPinNameByAdcChannel(const char *msg, adc_channel_e hwChannel, char *buffer) {
#if HAL_USE_ADC || defined(__DOXYGEN__)
	if (hwChannel == EFI_ADC_NONE) {
		strcpy(buffer, "NONE");
	} else {
		strcpy((char*) buffer, portname(getAdcChannelPort(msg, hwChannel)));
		itoa10(&buffer[2], getAdcChannelPin(hwChannel));
	}
#else
	strcpy(buffer, "NONE");
#endif
	return (char*) buffer;
}
Example #9
0
static void printTPSInfo(void) {
#if (EFI_PROD_CODE && HAL_USE_ADC) || defined(__DOXYGEN__)
	if (!engineConfiguration->hasTpsSensor) {
		scheduleMsg(&logger, "NO TPS SENSOR");
		return;
	}

	GPIO_TypeDef* port = getAdcChannelPort(engineConfiguration->tpsAdcChannel);
	int pin = getAdcChannelPin(engineConfiguration->tpsAdcChannel);

	scheduleMsg(&logger, "tps min %d/max %d v=%f @%s%d", engineConfiguration->tpsMin, engineConfiguration->tpsMax,
			getTPSVoltage(PASS_ENGINE_PARAMETER_F), portname(port), pin);
#endif
	scheduleMsg(&logger, "current 10bit=%d value=%f rate=%f", getTPS10bitAdc(), getTPS(PASS_ENGINE_PARAMETER_F),
			getTpsRateOfChange());
}
Example #10
0
static void printFullAdcReport(void) {

	for (int index = 0; index < EFI_ADC_SLOW_CHANNELS_COUNT; index++) {
		appendMsgPrefix(&logger);

		int hwIndex = getAdcHardwareIndexByInternalIndex(index);
		GPIO_TypeDef* port = getAdcChannelPort(hwIndex);
		int pin = getAdcChannelPin(hwIndex);

		int adcValue = getAdcValueByIndex(index);
		appendPrintf(&logger, " ch%d %s%d", index, portname(port), pin);
		appendPrintf(&logger, " ADC%d 12bit=%d", hwIndex, adcValue);
		float volts = adcToVolts(adcValue);
		appendPrintf(&logger, " v=%f", volts);

		appendMsgPostfix(&logger);
		scheduleLogging(&logger);
	}
}
Example #11
0
static void printFullAdcReport(void) {
	scheduleMsg(&logger, "fast %d slow %d", fastAdc.conversionCount, slowAdc.conversionCount);

	for (int index = 0; index < slowAdc.size(); index++) {
		appendMsgPrefix(&logger);

		adc_channel_e hwIndex = slowAdc.getAdcHardwareIndexByInternalIndex(index);
		GPIO_TypeDef* port = getAdcChannelPort(hwIndex);
		int pin = getAdcChannelPin(hwIndex);

		int adcValue = slowAdc.getAdcValueByIndex(index);
		appendPrintf(&logger, " ch%d %s%d", index, portname(port), pin);
		appendPrintf(&logger, " ADC%d 12bit=%d", hwIndex, adcValue);
		float volts = adcToVolts(adcValue);
		appendPrintf(&logger, " v=%f", volts);

		appendMsgPostfix(&logger);
		scheduleLogging(&logger);
	}
}
Example #12
0
static void processAdcPin(AdcConfiguration *adc, int index, const char *prefix) {
	adc_channel_e hwIndex = adc->getAdcHardwareIndexByInternalIndex(index);
	GPIO_TypeDef* port = getAdcChannelPort(hwIndex);
	int pin = getAdcChannelPin(hwIndex);

	int copy = stepCoutner;

	int c = 0;

	while (!isTimeForNextStep(copy)) {
		print("%s ch%d hwIndex=%d %s%d\r\n", prefix, index, hwIndex, portname(port), pin);
		int adcValue = adc->getAdcValueByIndex(index);

//		print("ADC%d val= %d%s", hwIndex, value, DELIMETER);
		float volts = adcToVolts(adcValue) * 2;
		print("v=%f  adc=%d  c=%d (hit 'n'<ENTER> for next step\r\n", volts, adcValue, c++);

		chThdSleepMilliseconds(300);

	}
}
Example #13
0
static void printFullAdcReport(Logging *logger) {
	scheduleMsg(logger, "fast %d slow %d", fastAdc.conversionCount, slowAdc.conversionCount);

	for (int index = 0; index < slowAdc.size(); index++) {
		appendMsgPrefix(logger);

		adc_channel_e hwIndex = slowAdc.getAdcHardwareIndexByInternalIndex(index);

		if(hwIndex != EFI_ADC_NONE && hwIndex != EFI_ADC_ERROR)
		{
			ioportid_t port = getAdcChannelPort("print", hwIndex);
			int pin = getAdcChannelPin(hwIndex);

			int adcValue = slowAdc.getAdcValueByIndex(index);
			appendPrintf(logger, " ch%d %s%d", index, portname(port), pin);
			appendPrintf(logger, " ADC%d 12bit=%d", hwIndex, adcValue);
			float volts = adcToVolts(adcValue);
			appendPrintf(logger, " v=%.2f", volts);

			appendMsgPostfix(logger);
			scheduleLogging(logger);
		}
	}
}
Example #14
0
void Bluetooth::onSwitchClicked()
{
    QString portname("/dev/ttySAC1");
    //QString portname("/dev/ttyUSB0");
    if(ui->switchBtn->text() == "启动")
    {
        if(myCom->connectToHard(portname))
        {
            if(myCom->startBluetooth() == RETURN_OK)
            {
                ui->switchBtn->setText("关闭");
                ui->scanBtn->setEnabled(true);
                QMessageBox::information(this, "提示", "蓝牙启动成功!");
            }
            else
            {
                myCom->disconnectToHard();
                QMessageBox::warning(this, "出错", "蓝牙启动失败,请检查蓝牙节点是否能正常工作!");
            }
        }
        else
        {
            QMessageBox::warning(this, "出错", "串口打开失败!");
        }
    }
    else
    {
        myCom->disconnectToHard();
        ui->switchBtn->setText("启动");
        ui->scanBtn->setEnabled(false);
        ui->connectBtn->setEnabled(false);
        ui->groupBox->setEnabled(false);
        ui->groupBox_2->setEnabled(false);
        ui->groupBox_3->setEnabled(false);
    }
}
Example #15
0
static void lcdInfo(void) {
	scheduleMsg(&logger, "HD44780 RS=%s%d E=%s%d", portname(HD44780_PORT_RS), HD44780_PIN_RS, portname(HD44780_PORT_E), HD44780_PIN_E);
	scheduleMsg(&logger, "HD44780 D4=%s%d D5=%s%d", portname(HD44780_PORT_DB4), HD44780_PIN_DB4, portname(HD44780_PORT_DB5), HD44780_PIN_DB5);
	scheduleMsg(&logger, "HD44780 D6=%s%d D7=%s%d", portname(HD44780_PORT_DB6), HD44780_PIN_DB6, portname(HD44780_PORT_DB7), HD44780_PIN_DB7);
}
Example #16
0
static void printTPSInfo(void) {
#if EFI_PROD_CODE
	GPIO_TypeDef* port = getAdcChannelPort(engineConfiguration->tpsAdcChannel);
	int pin = getAdcChannelPin(engineConfiguration->tpsAdcChannel);

	scheduleMsg(&logger, "tps min %d/max %d v=%f @%s%d", engineConfiguration->tpsMin, engineConfiguration->tpsMax, getTPSVoltage(), portname(port), pin);
#endif
	scheduleMsg(&logger, "current 10bit=%d value=%f rate=%f", getTPS10bitAdc(), getTPS(), getTpsRateOfChange());
}