コード例 #1
0
ファイル: DMCC.c プロジェクト: windbender/DMCC_Library
int getQEIDir(int fd, unsigned int motor)
{
    // Send status update command
    putByte(fd, 0xff, 0x00);
    
    if (motor == 1) {
        return ((getByte(fd, 0x01) >> 2) & 1);
    } else if (motor == 2) {
コード例 #2
0
ファイル: uart.c プロジェクト: suryasundarraj/avr-programming
/*! \brief Writes an ASCII string to the TX buffer */
void writeString(char *str)
{
  while (*str != '\0')
  {
    putByte(*str);
    ++str;
  }
}
コード例 #3
0
ファイル: pp3.c プロジェクト: jaromir-sukuba/a-p-prog
int p18a_read_page (unsigned char * data, int address, unsigned char num)
    {
    unsigned char i;
    if (verbose>2) flsprintf(stdout,"Reading page of %d bytes at 0x%6.6x\n", num, address);
    putByte(0x11);
    putByte(0x04);
    putByte(num/2);
    putByte((address>>16)&0xFF);
    putByte((address>>8)&0xFF);
    putByte((address>>0)&0xFF);
    getByte();
    for (i=0; i<num; i++)
        {
        *data++ = getByte();
        }
    return 0;
    }
コード例 #4
0
ファイル: loader.c プロジェクト: 8l/YESS
/* Function Name: load
 * Purpose:       Driver function. Opens an input file, loads the machine code,
 *                performs a memory dump, then exits.
 *
 * Parameters:    argc - amount of arguments passed
 *                args[] - input file name
 * Returns:       TRUE if program loaded successfully
 *                FALSE if program failed to load
 */
bool load(int argc, char * args[])
{
    if((argc > 1) && (validFileName(args[1]))){ //check for valid file name and # of arguments

        FILE* f = fopen(args[1], "r"); //open the file
        
        unsigned char addrCounter = 0; //counter used to check for overlapping addresses
        char line[80];
        unsigned int addr;
        int i;              //Address parser count
        unsigned int lineCount = 0;
        int len;            //Length of instruction
        unsigned char dataByte;      //Temporary storage of info
        bool loadErr = FALSE;
        int check;
        while(fgets(line,80,f))     //While we haven't reached the end of the file...
        {           
            lineCount++;
            check = checkLine(line);                    //Check the line

            if(check == 1)                              //If the line is valid...
            {                                           
                addr = grabAddress(line);               //Grab the address
                if(addr < addrCounter){                 //Check for errors with the address
                    printError(lineCount, line);
                    loadErr = TRUE;
                    break;
                }
                len = lenInst(line);                    //Find the length of the instruction
                int i = 0;
                unsigned int byteNo = 0;
                while(byteNo < len)                          //And load the data byte by byte
                {
                    dataByte = grabDataByte(line, 9+i);
                    putByte(addr, dataByte, &loadErr);
                    addr++;
                    byteNo++;
                    addrCounter = addr;
                    i += 2;
                }
              
            }                 
            else if(check == 0)                         //If the line is invalid...
            {                                           //Halt loading and give an error message
                printError(lineCount, line);
                loadErr = TRUE;
                break;
            }    
            discardRest(line, f);                                 //If the line or instructions are just spaces, do nothing
        }

        return loadErr;                                 //return TRUE if program was successfully loaded
    }
    printf("file opening failed\n usage: yess <filename>.yo\n"); //error message

    return TRUE; //return if invalid filename
}
コード例 #5
0
ファイル: net_buffer.c プロジェクト: cathyyul/cs219_bfr
int net_buffer_putByte(struct net_buffer * buf, uint8_t byte)
{
    if (!buf) return -1;
    if ((buf->buf_ptr + sizeof(uint8_t)) > buf->buf+buf->size) return -1;

    putByte(buf->buf_ptr, byte);
    buf->buf_ptr += sizeof(uint8_t);
    return 0;
}
コード例 #6
0
ファイル: loader.c プロジェクト: leec1/yess
/* storeData
 *      From the specified line, get the data portion and stores it in memory.
 * Params:   char *line - a pointer to the line we want the data from
 * Returns:  bool - true if the read/store was successful
 * Modifies: none
 */
void storeData(char *line) {
    bool memError;
    char byte[2];
    int i;
    for (i=0; i<numBytes*2; i+=2) {
        strncpy(byte, &line[i+9], 2);
        putByte(addr+(i/2), (unsigned char)strtol(byte,NULL,16), &memError);
    }
}
コード例 #7
0
ファイル: compresser.c プロジェクト: Heloise-fernandes/PLS
void lancementSimple(char* chemin, char* name)
{
	int T[N];
	int nb_occurence[N];
	int i;
	int f,d;
	
	extentionDossierCalcul(chemin,&f,&d);
	
	char* format = malloc(sizeof(char)*(f+1));
	char* dossier = malloc(sizeof(char)*(d+1));
	
	extentionDossierCreation(chemin,format,dossier,&f,&d);	
	
	char fichierCode[strlen(dossier)+strlen(name)+4];
	char fichierRetour[strlen(dossier)+strlen(name)+1+strlen(format)];
	
	strcpy(fichierCode,dossier);
	strcat(fichierCode,name);
	strcat(fichierCode,".txt");
	
	strcpy(fichierRetour,dossier);
	strcat(fichierRetour,name);
	strcat(fichierRetour,".");
	strcat(fichierRetour,format);

	pArbre res = huffman(chemin,nb_occurence);
	for (i=0;i<N;i++){
		T[i]=0;
	}
	
	profondeur(res,T,0);

	unsigned char nb_symbole=255;
	for (i=0;i<N;i++){ if (T[i]!=0){ nb_symbole++;}}
	
	
	//calcul de la taille
	int taille=0;
	for (i=0;i<N;i++){
		taille= taille + nb_occurence[i]*T[i];
	}
	
	pArbre A=construction_arbre_canonique(T);
	
	FILE *F1= ouvertureFichierLecture(chemin);
	FILE *F2 = ouvertureFichierEcriture (fichierCode);
	
	//ecriture du nombre de symbole 
	putByte(F2,nb_symbole);
	
	codage(F1,F2,A,taille);
	
	fermetureFichier(F1);
	fermetureFichier(F2);
}
コード例 #8
0
    encode()
    {
        Packet::encode();
        buffer+=ID;
        putInt(seed);
        putByte(dimension);
        putInt(generator);
        putInt(gamemode);
        putLong(eid);
        putInt(spawnX);
        putInt(spawnY);
        putInt(spawnZ);
        putFloat(x);
        putFloat(y);
        putFloat(z);
        putByte('\0');


    }
コード例 #9
0
 encode()
 {
     Packet::encode();
     buffer+=ID;
     putMagic();
     putLong(serverId);
     putAddress(clientAddress,clientPort);
     putShort(mtuSize);
     putByte('\0');//server security
 }
コード例 #10
0
ファイル: rewrite.c プロジェクト: ABratovic/open-watcom-v2
static void putSrcFile( REWRITE *r, TOKEN_LOCN *locn )
{
    uint_32 srcfile_index;

    srcfile_index = newSrcFileHandle( r, locn->src_file );
    putToken( r, T_REWRITE_MODS );
    putByte( r, CODE_FILE );
    putBinary( r, (uint_8*)&srcfile_index, sizeof( srcfile_index ) );
    locn->line = 0;
    locn->column = 0;
}
コード例 #11
0
ファイル: CRC8.hpp プロジェクト: posilva/dune
    //! Compute the CRC8 of an array of bytes.
    //! @param[in] data array of bytes.
    //! @param[in] data_size size of array.
    //! @return current CRC8 value.
    uint8_t
    putArray(const uint8_t* data, unsigned int data_size)
    {
        while (data_size > 0)
        {
            putByte(*data++);
            --data_size;
        }

        return m_value;
    }
コード例 #12
0
void max7221::noOp( byte count )
{
	/*
	 * sends count no-op codes to select a chip in daisy-chain mode. 0: first, 1: second, ...
	 * These codes must be sent after the 2 data bytes and before load goes high again.
	 */
	for( int i = 0; i < count; i++ )
	{
		putByte(0x00);
	}
}
コード例 #13
0
ファイル: bl08.c プロジェクト: Noah1989/bl08
void sendByte(int byte) {
	byte &=  0xFF;
	putByte(byte);
	char buf;
	if (read(com, &buf, 1)!=1)
		comErr("Loopback failed, nothing was received\n");
	int rx=buf &0xFF;
	if (byte !=  rx)
		comErr("Loopback failed, sent 0x%02X, got 0x%02X\n", byte,  rx);
	rx = getByte();
	if (byte !=  rx)
		comErr("Target echo failed, sent 0x%02X, got 0x%02X\n", byte, rx);
	}
コード例 #14
0
ファイル: rewrite.c プロジェクト: ABratovic/open-watcom-v2
static void putSrcLocn( REWRITE *r, TOKEN_LOCN *locn )
{
    SRCFILE currfile;
    uint_32 absolute;
    uint_8 code_byte;

    currfile = SrcFileCurrent();
    if( currfile != locn->src_file ) {
        locn->src_file = currfile;
        putSrcFile( r, locn );
    }
    putToken( r, T_REWRITE_MODS );
    if( ( TokenLine - locn->line ) > 127 ) {
        putByte( r, CODE_ABS );
        absolute = TokenLine | MASK_ABS_LINE;
        putBinary( r, (uint_8*)&absolute, sizeof( absolute ) );
        locn->line = TokenLine;
    } else if( ( TokenLine - locn->line ) > 0 ) {
        code_byte = ( TokenLine - locn->line ) | MASK_DELTA_LINE;
        putByte( r, code_byte );
        locn->line = TokenLine;
    }
    if( ( TokenColumn - locn->column ) > 127 ) {
        putByte( r, CODE_ABS );
        absolute = TokenColumn;
        putBinary( r, (uint_8*)&absolute, sizeof( absolute ) );
        locn->column = TokenColumn;
    } else if( ( TokenColumn - locn->column ) > 0 ) {
        code_byte = TokenColumn - locn->column;
        putByte( r, code_byte );
        locn->column = TokenColumn;
    } else {                        // this guards against token at same col.
        putByte( r, CODE_ABS );
        absolute = TokenColumn;
        putBinary( r, (uint_8*)&absolute, sizeof( absolute ) );
        locn->column = TokenColumn;
    }
}
コード例 #15
0
ファイル: tedstd.cpp プロジェクト: BackupTheBerlios/toped-svn
void laydata::TEDfile::putTime() 
{
   time_t ctime = _design->created();
   tm* broken_time = localtime(&ctime);
   putByte(tedf_TIMECREATED);
   put4b(broken_time->tm_mday);
   put4b(broken_time->tm_mon);
   put4b(broken_time->tm_year);
   put4b(broken_time->tm_hour);
   put4b(broken_time->tm_min);
   put4b(broken_time->tm_sec);
   //
   _lastUpdated = time(NULL);
   _design->_lastUpdated = _lastUpdated;
   broken_time = localtime(&_lastUpdated);
   putByte(tedf_TIMEUPDATED);
   put4b(broken_time->tm_mday);
   put4b(broken_time->tm_mon);
   put4b(broken_time->tm_year);
   put4b(broken_time->tm_hour);
   put4b(broken_time->tm_min);
   put4b(broken_time->tm_sec);
}
コード例 #16
0
ファイル: DMCC.c プロジェクト: S1Lightcycle/Lightcycle_DMCC
unsigned int getQEI(int fd, unsigned int motor)
{
    // Send status update command (required call before reading)
    putByte(fd, 0xff, 0x00);

    if (motor == 1) {
        return getDWord(fd, 0x10);
    } else if (motor == 2) {
        return getDWord(fd, 0x14);
    } else {
        printf("Error: invalid motor number\n");
        return 0;
    }
}
コード例 #17
0
ファイル: pp3.c プロジェクト: jaromir-sukuba/a-p-prog
void putBytes (unsigned char * data, int len)
    {

    int i;
    for (i=0; i<len; i++)
        putByte(data[i]);
    /*
    	if (verbose>3)
    		flsprintf(stdout,"TXP: %d B\n", len);
    int n = write(com, data, len);
    	if (n != len)
    		comErr("Serial port failed to send %d bytes, write returned %d\n", len,n);
    */
    }
コード例 #18
0
ファイル: putChunk.cpp プロジェクト: MP2E/GDCC
         //
         // Info::putChunkFUNC
         //
         void Info::putChunkFUNC()
         {
            if(!numChunkFUNC) return;

            Core::Array<IR::Function const *> funcs{numChunkFUNC};

            for(auto &f : funcs) f = nullptr;

            for(auto const &itr : prog->rangeFunction())
            {
               if(itr.ctype != IR::CallType::LangACS)
                  continue;

               funcs[itr.valueInt] = &itr;
            }

            putData("FUNC", 4);
            putWord(numChunkFUNC * 8);

            for(auto f : funcs)
            {
               if(f)
               {
                  putByte(f->param);
                  putByte(std::max(f->localReg, f->param));
                  putByte(!!f->retrn);
                  putByte(0);

                  if(f->defin)
                     putExpWord(resolveGlyph(f->label));
                  else
                     putWord(0);
               }
               else
                  putData("\0\0\0\0\0\0\0\0", 8);
            }
         }
コード例 #19
0
ファイル: pp3.c プロジェクト: jaromir-sukuba/a-p-prog
int prog_enter_progmode (void)
    {
    if (verbose>2) flsprintf(stdout,"Entering programming mode\n");
    if (chip_family==CF_P16F_A) putByte(0x01);
    else 	if (chip_family==CF_P16F_B) putByte(0x01);
    else 	if (chip_family==CF_P18F_A) putByte(0x10);
    else 	if (chip_family==CF_P18F_B) putByte(0x10);
    else 	if (chip_family==CF_P18F_D) putByte(0x10);
    else 	if (chip_family==CF_P18F_E) putByte(0x10);
    putByte(0x00);
    getByte();
    return 0;
    }
コード例 #20
0
/**
 * @brief Read 1 or more bytes from the I2C slave
 * @param device_address The address of the device to read from
 * @param data An allocated array to read the data into
 * @param data_bytes Number of bytes to read (must be equal to or less then the allocated memory in data)
 */
void SoftwareI2C::read(char device_address, char* data, char data_bytes) {
	if (data == 0 || data_bytes == 0) return;

	device_address = device_address | 0x01;
	start();
	putByte(device_address);
	getAck();
	for (int x = 0; x < data_bytes; ++x) {
		data[x] = getByte();
		if ( x < (data_bytes -1)) { //ack all but the final byte
			giveAck();
		}
	}
	stop();
}
コード例 #21
0
ファイル: Sensirion.cpp プロジェクト: shday/myarduino
Sensirion::Sensirion(uint8_t dataPin, uint8_t clockPin) {
  // Initialize private storage for library functions
  _pinData = dataPin;
  _pinClock = clockPin;
  _presult = NULL;                  // No pending measurement
  _stat_reg = 0x00;                 // Sensor status register default state

  // Initialize CLK signal direction
  // Note: All functions exit with CLK low and DAT in input mode
  pinMode(_pinClock, OUTPUT);

  // Return sensor to default state
  resetConnection();                // Reset communication link with sensor
  putByte(SOFT_RESET);              // Send soft reset command
}
コード例 #22
0
ファイル: decompressor.cpp プロジェクト: pdpdds/sglt
//-------------------------------
//  Huffman decompressor
//-------------------------------
int DecompressorHuffman::unpack(Common::ReadStream *src, byte *dest, uint32 nPacked,
								uint32 nUnpacked) {
	init(src, dest, nPacked, nUnpacked);
	byte numnodes;
	int16 c;
	uint16 terminator;

	numnodes = _src->readByte();
	terminator = _src->readByte() | 0x100;
	_nodes = new byte [numnodes << 1];
	_src->read(_nodes, numnodes << 1);

	while ((c = getc2()) != terminator && (c >= 0) && !isFinished())
		putByte(c);

	delete[] _nodes;
	return _dwWrote == _szUnpacked ? 0 : 1;
}
コード例 #23
0
status_t i2c_HMC_read(uint8_t* data)
{
//	int i;
	start();
	
	//address device
    if (putByte(0x3D) == STATUS_NO_ACK) 
	{
		stop();
		return STATUS_ACK;
    }
	
	// read data now
	*data = getByte(STATUS_NO_ACK);
	
	stop();
	
	return STATUS_OK;
}
コード例 #24
0
ファイル: i2cSwBus.c プロジェクト: kenzanin/webbotavrclib-1x
// Send the start and address
// return TRUE if acknowledged
static boolean start(const I2C_DEVICE* device, boolean writeMode){
	boolean rtn = FALSE;

	const I2C_SOFTWARE_BUS* i2c = (const I2C_SOFTWARE_BUS*)(device->bus);
	if(i2c){
		sda_high(i2c);
		halfDelay();
		scl_high(i2c);
		halfDelay();

		sda_low(i2c);
		halfDelay();
		scl_low(i2c);
		halfDelay();

		// Send the device addr and direction
		uint8_t addr = device->addr & 0xfe;
		if(writeMode==FALSE){
			addr |= 1;
		}
		rtn = putByte(device->bus, addr);
	}
	return rtn;
}
コード例 #25
0
static void maxOne(byte maxNr, byte reg, byte col)
{
	digitalWrite(IO_OUT_SPI_LOAD, LOW);  // begin

	for (U8 c = maxInUse; c > maxNr; c--)
	{
		putByte(0);    // means no operation
		putByte(0);    // means no operation
	}

	putByte(reg);  // specify register
	putByte(col);//((data & 0x01) * 256) + data >> 1); // put data

	for (U8 c = maxNr-1; c >= 1; c--)
	{
		putByte(0);    // means no operation
		putByte(0);    // means no operation
	}

	digitalWrite(IO_OUT_SPI_LOAD, LOW); // and load da shit
	digitalWrite(IO_OUT_SPI_LOAD, HIGH);
}
コード例 #26
0
void Max7219::maxOne(byte maxNr, byte reg, byte col) const
{
	// maxOne is for adressing different MAX7219's,
	// while having a couple of them cascaded

	digitalWrite(m_loadPin, LOW);  // begin

	for(char c = m_numMax; c > maxNr; --c) {
		putByte(0);    // means no operation
		putByte(0);    // means no operation
	}

	putByte(reg);		// specify register
	putByte(col);		//((data & 0x01) * 256) + data >> 1); // put data

	for(char c = maxNr - 1; c >= 1; --c) {
		putByte(0);    // means no operation
		putByte(0);    // means no operation
	}

	digitalWrite(m_loadPin, LOW); // and load da shit
	digitalWrite(m_loadPin, HIGH);
} // maxOne
コード例 #27
0
ファイル: max72.c プロジェクト: ECE1T6/game-o-matic
void maxOne(byte maxNr, byte reg, byte col) {    
//maxOne is for adressing different MAX7219's, 
//whilele having a couple of them cascaded

  int c = 0;
  digitalWrite(load, LOW);  // begin     

  for ( c = maxInUse; c > maxNr; c--) {
    putByte(0);    // means no operation
    putByte(0);    // means no operation
  }

  putByte(reg);  // specify register
  putByte(col);//((data & 0x01) * 256) + data >> 1); // put data 

  for ( c =maxNr-1; c >= 1; c--) {
    putByte(0);    // means no operation
    putByte(0);    // means no operation
  }

  digitalWrite(load, LOW); // and load da shit
  digitalWrite(load,HIGH); 
}
コード例 #28
0
void Serial::putBuffer( u8 *buf, int len )
{
	int i;
	for(i=0;i<len;i++)
		putByte(buf[i]);
}
コード例 #29
0
ファイル: Sensirion.cpp プロジェクト: shday/myarduino
// Public reset function
// Note: Soft reset returns sensor status register to default values
uint8_t Sensirion::reset(void) {
  _stat_reg = 0x00;                 // Sensor status register default state
  resetConnection();                // Reset communication link with sensor
  return putByte(SOFT_RESET);       // Send soft reset command & return status
}
コード例 #30
0
ファイル: tedstd.cpp プロジェクト: BackupTheBerlios/toped-svn
void laydata::TEDfile::putString(std::string str) {
//   byte len = str.length();
//   fwrite(&len, 1,1, _file);
   putByte(str.length());
   fputs(str.c_str(), _file);
}