Ejemplo n.º 1
0
static void sendMsgBurst (int burstNr, int handle1, int handle2)
{
  canStatus stat;
  int i;
  
  // Send a burst of messages on both channels
  for (i=0; i<BURST_SIZE; i++) {
    stat = canWrite(handle1, 
                    msgs1[i].id,
                    msgs1[i].data, 
                    msgs1[i].dlc, 
                    msgs1[i].flags);
    if (stat != canOK) {
      printSomeStuff();
      printf("line %d, burst %d, msg %d\n", __LINE__, burstNr, i);
      Check("canWrite() failed", stat);
    }
    
    stat = canWrite(handle2, 
                    msgs2[i].id,
                    msgs2[i].data, 
                    msgs2[i].dlc, 
                    msgs2[i].flags);
    if (stat != canOK) {
      printSomeStuff();
      printf("line %d, burst %d, msg %d\n", __LINE__, burstNr, i);
      Check("canWrite() failed", stat);
    }
  }
}
Ejemplo n.º 2
0
void incBusLoad (int channel, int flags, int load)
{
  canHandle handle;
  unsigned char msg[8] = "Kvaser!";
  int i, id = 100, dlc = sizeof(msg);
  canStatus stat = canERR_PARAM;
  handle  = canOpenChannel(channel, flags);
  if (handle < 0) {
    check("canOpenChannel", handle);
    return;
  }
  stat = canBusOff(handle);
  check("canBusOff", stat);
  stat = canSetBusParams(handle, bitrate, 0, 0, 0, 0, 0);
  check("canSetBusParams", stat);
  canBusOn(handle);
  for (i = 0; i < load; i++) {
    stat = canWrite(handle, id, &msg, dlc, 0);
    check("canWrite", stat);
  }
  stat = canWriteWait(handle, id, &msg, dlc, 0, -1);
  check("canWriteWait", stat);
  canBusOff(handle);
  canClose(handle);
}
int CESDDevice::writeDevice(CProtocolMessage& rclProtocolMessage)
{
	int iRetVal = 0;
	long iNumberOfMessages = 1;
	CMSG clESDProtocolMessage;
	m_iErrorState = 0;

        //debug output

        printMessage(rclProtocolMessage,WRITE);
	clESDProtocolMessage.id = rclProtocolMessage.m_uiMessageId;
	clESDProtocolMessage.len = rclProtocolMessage.m_ucMessageLength;
	if(rclProtocolMessage.m_bRTRFlag)
		clESDProtocolMessage.len |= 0x10;
	memcpy(clESDProtocolMessage.data, rclProtocolMessage.m_aucMessageData, rclProtocolMessage.m_ucMessageLength);
	iRetVal = canWrite(m_hDevice, &clESDProtocolMessage, &iNumberOfMessages, NULL);
//	iRetVal = canSend(m_hDevice, &clESDProtocolMessage, &iNumberOfMessages);
	if(iRetVal != NTCAN_SUCCESS)
	{
		warning("can send failed Errorcode: %d", iRetVal);
		m_iErrorState = getDeviceError(iRetVal);
		return m_iErrorState;
	}

	return m_iErrorState;
}
/**
 * Sets a send parameters (fmtp) for the PayloadType.
 * This method is provided for applications using RTP with SDP, but
 * actually the ftmp information is not used for RTP processing.
**/
void payload_type_set_send_fmtp(PayloadType *pt, const char *fmtp){
	if (canWrite(pt)){
		if (pt->send_fmtp!=NULL) ortp_free(pt->send_fmtp);
		if (fmtp!=NULL) pt->send_fmtp=ortp_strdup(fmtp);
		else pt->send_fmtp=NULL;
	}
}
Ejemplo n.º 5
0
afs_int32
writeTape(int fid, struct tape *tapePtr, afs_int32 dumpid)
{
    struct budb_tapeEntry tapeEntry;
    afs_int32 code = 0, tcode;

    tcode = writeStructHeader(fid, SD_TAPE);
    if (tcode)
	ERROR(tcode);

    tapeToBudbTape(tapePtr, &tapeEntry);

    tapeEntry.dump = htonl(dumpid);

    if (canWrite(fid) <= 0)
	ERROR(BUDB_DUMPFAILED);

    if (write(fid, &tapeEntry, sizeof(tapeEntry)) != sizeof(tapeEntry))
	ERROR(BUDB_DUMPFAILED);

    haveWritten(sizeof(tapeEntry));

  error_exit:
    return (code);
}
void ossimGdalImageWriterFactory::getImageFileWritersByMimeType(ossimImageWriterFactoryBase::ImageFileWriterList& result,
                                                                const ossimString& mimeType)const
{
   int c = GDALGetDriverCount();
   int idx = 0;
   for(idx = 0; idx < c; ++idx)
   {
      
      GDALDriverH h = GDALGetDriver(idx);
      if(canWrite(h))
      {
         ossimString  driverName = GDALGetDriverShortName(h);
         driverName = "gdal_" + driverName.upcase();
         ossimString metaData(GDALGetMetadataItem(h, GDAL_DMD_MIMETYPE, 0));
         if(!metaData.empty())
         {
            if(metaData == mimeType)
            {
               ossimGdalWriter* writer = new ossimGdalWriter;
               writer->setOutputImageType(driverName);
               result.push_back(writer);
               if ( driverName == "gdal_JP2KAK" )
               {
                  // Make it lossless for starters.  User can still override.
                  ossimKeywordlist kwl;
                  kwl.add("property0.name", "QUALITY");
                  kwl.add("property0.value", "100");
                  writer->loadState(kwl, NULL);
               }
               return;
            }
         }
      }
   }
}
Ejemplo n.º 7
0
afs_int32
writeVolume(struct ubik_trans *ut, int fid, struct volFragment *volFragmentPtr,
	    struct volInfo *volInfoPtr, afs_int32 dumpid, char *tapeName)
{
    struct budb_volumeEntry budbVolume;
    afs_int32 code = 0;

    volsToBudbVol(volFragmentPtr, volInfoPtr, &budbVolume);

    budbVolume.dump = htonl(dumpid);
    strcpy(budbVolume.tape, tapeName);

    writeStructHeader(fid, SD_VOLUME);

    if (canWrite(fid) <= 0)
	ERROR(BUDB_DUMPFAILED);

    if (write(fid, &budbVolume, sizeof(budbVolume)) != sizeof(budbVolume))
	ERROR(BUDB_DUMPFAILED);

    haveWritten(sizeof(budbVolume));

  error_exit:
    return (code);
}
Ejemplo n.º 8
0
bool BackgroundTexturesIOPC::write(const BackgroundTexturesPC *textures)
{
	if(!canWrite()) {
		return false;
	}

	for(quint8 texID=0 ; texID<BACKGROUND_TEXTURE_PC_MAX_COUNT ; ++texID) {

		quint16 exists = textures->hasTex(texID);

		if(device()->write((char *)&exists, 2) != 2) {
			return false;
		}

		if(bool(exists)) {
			BackgroundTexturesPCInfos infos = textures->texInfos(texID);

			quint16 size = infos.size, depth = infos.depth;

			if(device()->write((char *)&size, 2) != 2 ||
					device()->write((char *)&depth, 2) != 2) {
				return false;
			}

			if(device()->write(textures->data().mid(infos.pos, infos.depth * 65536))
					!= infos.depth * 65536) {
				return false;
			}
		}
	}

	return true;
}
Ejemplo n.º 9
0
bool Fifo::tryConnect() noexcept {
  if (isConnected()) {
    return true;
  }

  if (!exists(path_.c_str())) {
    if (!create(path_.c_str())) {
      static bool logged{false};
      if (!logged) {
        VLOG(1) << "Error creating debug fifo at \"" << path_ << "\": "
                << strerror(errno) << " [" << errno << "]";
        logged = true;
      }
      return false;
    }
  }

  if (!isFifo(path_.c_str()) || !canWrite(path_.c_str())) {
    if (!removeFile(path_.c_str()) ||
        !create(path_.c_str())) {
      return false;
    }
  }

  int fd = folly::openNoInt(path_.c_str(), O_WRONLY | O_NONBLOCK);
  if (fd >= 0) {
    fd_.store(fd);
    return true;
  }

  return false;
}
Ejemplo n.º 10
0
bool BackgroundTilesIO::write(const BackgroundTiles &tiles) const
{
	if(!canWrite()) {
		return false;
	}

	return writeData(tiles);
}
Ejemplo n.º 11
0
PrefsFile::PrefsFile(const QString& pFilePath, bool write)
{
	m_prefsFilePath = pFilePath;
	m_ioEnabled = write;
	if (m_ioEnabled)
		canWrite();
	load();
}
Ejemplo n.º 12
0
int writeByte_nonblocking(char byte, uint8_t usartn)
{
   if (canWrite(usartn)) {
      __writeByte(byte, usartn);
      return 0;
   }

   return -1;
}
Ejemplo n.º 13
0
uint8_t circularBuffer_write(CircularBuffer * buffer, char * data, uint8_t size){
	uint8_t amount = 0;
	while (size-amount>0 && canWrite(buffer)){
		if(circularBuffer_writeByte(buffer, data[amount]) == -1)
			return amount;
		amount++;
	}
	return amount;
}
Ejemplo n.º 14
0
void StatisticsWindow::updateProtocol(AbstractProtocol* p)
{
    if(p != nullptr)
        _activeProtocol = p;
    if(_window == nullptr)
    {
        return;
    }
    werase(_window);
    wborder(_window, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE, ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER);

    std::string tmp("  ");
    for_each(_allProtocols.begin(), _allProtocols.end(), [&](std::string& s) {
        if(!s.compare(_activeProtocol->getProtocolName()))
        {
            tmp += std::string(" < ") + s + std::string(" > ");
        }
        else
        {
            tmp += std::string("   ") + s + std::string("   ");
        }

    });
    mvwprintw(_window, STATISTICS::PROTOCOLS_LINE, FIRST_CHAR_POS, "%s", tmp.c_str());

    unsigned int line = STATISTICS::FIRST_OPERATION_LINE;
    for(unsigned int i = STATISTICS::DEFAULT_GROUP; i <= _activeProtocol->getGroups(); i++)
    {
        if(canWrite(line))
        {
            mvwprintw(_window, line - (_scrollOffset.at(p)), FIRST_CHAR_POS, "%s", "Total:");
        }
        line++;
        for(unsigned int j = _activeProtocol->getGroupBegin(i); j < _activeProtocol->getGroupBegin(i + 1); j++)
        {
            if(canWrite(line))
            {
                mvwprintw(_window, line - (_scrollOffset.at(p)), FIRST_CHAR_POS, "%s", p->printProcedure(j));
            }
            line++;
        }
        line++;
    }
}
Ejemplo n.º 15
0
bool MemBuffer::write(const Byte* array, size_t size)
{
    bool bOk = false;
    if(canWrite(g_sizeBYTE*size))
    {
        memcpy(getBuffer(), array, size);
        bOk = shiftBuffer(g_sizeBYTE*size);
    }
    return bOk;
}
Ejemplo n.º 16
0
void NetworkMessage::addU32(uint32_t value)
{
    ECORR32(value);
	if(canWrite(4)){
		m_buffer[m_writePos++] = (uint8_t)(value);
		m_buffer[m_writePos++] = (uint8_t)(value >>  8);
		m_buffer[m_writePos++] = (uint8_t)(value >> 16);
		m_buffer[m_writePos++] = (uint8_t)(value >> 24);
		m_size += 4;
	}
Ejemplo n.º 17
0
void enable_torque_assist() {
  // Unit responds to input torque, provides output torque according to
  // programmed assist curve.
  char msg_buf[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  
  msg_buf[0]=0x02;
  
  check("canWrite", canWrite(h, CAN_ID, (void*)msg_buf, 8, canMSG_EXT));       
  check("canWriteSync", canWriteSync(h, 1000));
}
Ejemplo n.º 18
0
bool MemBuffer::writeByte(const Byte b)
{
    bool bOk = false;
    if(canWrite(g_sizeBYTE))
    {
        memcpy(getBuffer(), &b, g_sizeBYTE);
        bOk = shiftBuffer(g_sizeBYTE);
    }
    return bOk;
}
Ejemplo n.º 19
0
afs_int32
writeText(struct ubik_trans *ut, int fid, int textType)
{
    struct textBlock *tbPtr;
    afs_int32 textSize, writeSize;
    dbadr dbAddr;
    struct block block;
    afs_int32 code = 0;

    /* check lock is free */
    code = checkLock(textType);
    if (code)
	ERROR(code);

    /* ensure that this block has the correct type */
    code = checkText(ut, textType);
    if (code) {
	LogError(0, "writeText: text type %d damaged\n", textType);
	ERROR(code);
    }

    tbPtr = &db.h.textBlock[textType];
    textSize = ntohl(tbPtr->size);
    dbAddr = ntohl(tbPtr->textAddr);

    if (!dbAddr)
	goto error_exit;	/* Don't save anything if no blocks */

    writeTextHeader(fid, textType);

    while (dbAddr) {
	code = cdbread(ut, text_BLOCK, dbAddr, (char *)&block, sizeof(block));
	if (code)
	    ERROR(code);

	writeSize = MIN(textSize, BLOCK_DATA_SIZE);
	if (!writeSize)
	    break;

	if (canWrite(fid) <= 0)
	    ERROR(BUDB_DUMPFAILED);

	if (write(fid, &block.a[0], writeSize) != writeSize)
	    ERROR(BUDB_IO);

	haveWritten(writeSize);
	textSize -= writeSize;

	dbAddr = ntohl(block.h.next);
    }

  error_exit:
    return (code);
}
Ejemplo n.º 20
0
/* Can Send Function
 * A function for the sending of can messages on the bus.
 */
static void canSend(uint32_t id) {
  canMessage_t msg = {0, 0, 0, 0};   
  bool txOk = false;        
  
  msg.id = id;  // arbitrary CAN message id   
  msg.len = 4;    // data length 4   
  msg.dataA = 0;   
  msg.dataB = 0;        
  // Transmit message on CAN 1     
  txOk = canWrite(CAN_PORT_1, &msg);  
}
Ejemplo n.º 21
0
/**
 * @brief MainWindow::on_pushButton_CanSend_clicked
 */
void MainWindow::on_pushButton_CanSend_clicked()
{
    //    CanMsg m;
    //    m.dlc = ui->spinBoxDLC->value();
    //    m.extmsg = ui->checkBox_CanExtended->isChecked();
    //    if(m.extmsg)
    //        m.extid = ui->spinBoxCanIDHex->value();
    //    else
    //        m.stdid = ui->spinBoxCanIDHex->value();
    //    m.rtr = ui->checkBox_RTR->isChecked();

    //    if(m.dlc > 0 && ui->lineEdit_CanByte0->text() == QString("")) ui->lineEdit_CanByte0->setText("00");
    //    if(m.dlc > 1 && ui->lineEdit_CanByte1->text() == QString("")) ui->lineEdit_CanByte1->setText("00");
    //    if(m.dlc > 2 && ui->lineEdit_CanByte2->text() == QString("")) ui->lineEdit_CanByte2->setText("00");
    //    if(m.dlc > 3 && ui->lineEdit_CanByte3->text() == QString("")) ui->lineEdit_CanByte3->setText("00");
    //    if(m.dlc > 4 && ui->lineEdit_CanByte4->text() == QString("")) ui->lineEdit_CanByte4->setText("00");
    //    if(m.dlc > 5 && ui->lineEdit_CanByte5->text() == QString("")) ui->lineEdit_CanByte5->setText("00");
    //    if(m.dlc > 6 && ui->lineEdit_CanByte6->text() == QString("")) ui->lineEdit_CanByte6->setText("00");
    //    if(m.dlc > 7 && ui->lineEdit_CanByte7->text() == QString("")) ui->lineEdit_CanByte7->setText("00");

    //    bool c;
    //    if(m.dlc > 0) m.data.append(ui->lineEdit_CanByte0->text().toUInt(&c,16));
    //    if(m.dlc > 1) m.data.append(ui->lineEdit_CanByte1->text().toUInt(&c,16));
    //    if(m.dlc > 2) m.data.append(ui->lineEdit_CanByte2->text().toUInt(&c,16));
    //    if(m.dlc > 3) m.data.append(ui->lineEdit_CanByte3->text().toUInt(&c,16));
    //    if(m.dlc > 4) m.data.append(ui->lineEdit_CanByte4->text().toUInt(&c,16));
    //    if(m.dlc > 5) m.data.append(ui->lineEdit_CanByte5->text().toUInt(&c,16));
    //    if(m.dlc > 6) m.data.append(ui->lineEdit_CanByte6->text().toUInt(&c,16));
    //    if(m.dlc > 7) m.data.append(ui->lineEdit_CanByte7->text().toUInt(&c,16));

    if(connected && busOn && !ui->checkBox_Silent->isChecked()){
        char data[8];
        int flags = 0;
        data[0] = ui->lineEdit_CanByte0->text().toUInt(NULL,16);
        data[1] = ui->lineEdit_CanByte1->text().toUInt(NULL,16);
        data[2] = ui->lineEdit_CanByte2->text().toUInt(NULL,16);
        data[3] = ui->lineEdit_CanByte3->text().toUInt(NULL,16);
        data[4] = ui->lineEdit_CanByte4->text().toUInt(NULL,16);
        data[5] = ui->lineEdit_CanByte5->text().toUInt(NULL,16);
        data[6] = ui->lineEdit_CanByte6->text().toUInt(NULL,16);
        data[7] = ui->lineEdit_CanByte7->text().toUInt(NULL,16);
        if( ui->checkBox_CanExtended->isChecked() ){
            flags += canMSG_EXT;
        }
        if(ui->checkBox_RTR->isChecked()){
            flags += canMSG_RTR;
        }
        canWrite(canHandle, ui->spinBoxCanIDHex->value(), data, ui->spinBoxDLC->value(), flags );
    }else{
        QMessageBox msgBox;
        msgBox.setText("Current interface status does not allow transmitting can frames.\n\n- Connected?\n- Bus On?\n- Silent?");
        msgBox.exec();
    }
}
Ejemplo n.º 22
0
qint64 QLocalSocket::writeData(const char *data, qint64 maxSize)
{
    Q_D(QLocalSocket);
    if (!d->pipeWriter) {
        d->pipeWriter = new QWindowsPipeWriter(d->handle, this);
        connect(d->pipeWriter, SIGNAL(canWrite()), this, SLOT(_q_canWrite()));
        connect(d->pipeWriter, SIGNAL(bytesWritten(qint64)), this, SIGNAL(bytesWritten(qint64)));
        d->pipeWriter->start();
    }
    return d->pipeWriter->write(data, maxSize);
}
Ejemplo n.º 23
0
void LeaseHolderBase::acquireBlocking() {
  assertx(!canWrite());

  if (m_lease.amOwner()) {
    m_state = LockLevel::Write;
    return;
  }

  m_acquired = m_lease.acquire(true);
  m_state = LockLevel::Write;
}
void payload_type_append_recv_fmtp(PayloadType *pt, const char *fmtp){
	if (canWrite(pt)){
		if (pt->recv_fmtp==NULL)
			pt->recv_fmtp=ortp_strdup(fmtp);
		else{
			char *tmp=ortp_strdup_printf("%s;%s",pt->recv_fmtp,fmtp);
			ortp_free(pt->recv_fmtp);
			pt->recv_fmtp=tmp;
		}
	}
}
Ejemplo n.º 25
0
bool MemBuffer::write(uint32_t uint32)
{
    bool bOk = false;
    if(canWrite(g_sizeUINT32))
    {
        uint32 = htonl(uint32);
        memcpy(getBuffer(), &uint32, g_sizeUINT32);
        bOk =  shiftBuffer(g_sizeUINT32);
    }
    return bOk;
}
Ejemplo n.º 26
0
int32_t writeNTCAN(NTCAN_HANDLE handle, int32_t len, CMSG *msg) 
{
   NTCAN_RESULT	result;
/* Writes to NTCAN device */
   len |= len + (RTR_ENABLE<<4);
   result = canWrite(handle, msg, &len, NULL); 
   if(errorCheck(CAN_WRITE,result) != 0)
      { return 1; }
   printf("Message sent %d successful frames\n",len);
   return 0;
}
Ejemplo n.º 27
0
int8_t circularBuffer_writeByte(CircularBuffer * buffer, char data){
	if(canWrite(buffer) == 0)
		return -1;
	buffer->data[buffer->head-1] = data;
	if (buffer->head == buffer->size) {
		buffer->head = 1;
		} else {
		buffer->head++;
	}
	return 1;
}
Ejemplo n.º 28
0
//
//called when the Send button is pressed.
//
void CCanTestMFCDlg::OnSend()
{
    char	data[8];
    int		stat;

    //send a can message on channel 0
    stat = canWrite(m_handle, 1234, data, 8, canMSG_EXT);
    if (stat < 0) {
        AfxMessageBox("ERROR: canWrite().");
    }
}
Ejemplo n.º 29
0
bool BackgroundTexturesIOPS::write(const BackgroundTexturesPS *textures)
{
	if(!canWrite()) {
		return false;
	}

	if(device()->write(textures->data()) != textures->data().size()) {
		return false;
	}

	return true;
}
Ejemplo n.º 30
0
/*
 * A can send function for the sending of can messages
 * on the can bus.
 */
static void canSend(uint32_t id) {
    canMessage_t msg = {0, 0, 0, 0};

    /* Initialise the CAN message structure */
    msg.id = id;  // arbitrary CAN message id
    msg.len = 4;    // data length 4
    msg.dataA = 0;
    msg.dataB = 0;

    // Transmit message on CAN 1
    canWrite(CAN_PORT_1, &msg);
}