Example #1
0
int GSM3SoftSerial::begin(long speed)
{   
	_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
	
	setTX();
	setRX();
	
	for (unsigned i=0; i<sizeof(table)/sizeof(table[0]); ++i)
	{
		long baud = pgm_read_dword(&table[i].baud);
		if (baud == speed)
		{
			_rx_delay_centering = pgm_read_word(&table[i].rx_delay_centering);
			_rx_delay_intrabit = pgm_read_word(&table[i].rx_delay_intrabit);
			_rx_delay_stopbit = pgm_read_word(&table[i].rx_delay_stopbit);
			_tx_delay = pgm_read_word(&table[i].tx_delay);
			break;
		}
	}

	// Set up RX interrupts, but only if we have a valid RX baud rate
	/*
	if (_rx_delay_stopbit)
	{
		pinMode(__RXPIN__, INPUT_PULLUP);
		tunedDelay(_tx_delay); // if we were low this establishes the end
	}
    */
    io_DisableINT();
    io_outpb(CROSSBARBASE + 0x90 + PIN86[__RXPIN__].gpN, 0x08);
	_activeObject = this;
	io_RestoreINT();
}
Example #2
0
// try to read a Dynamixel packet
// return true if successful, false otherwise 
uint16_t axReadPacket(uint8_t length){
    setRX();
    usart_timer = 0;
	// wait until the expected number of byte has been read
	while( local_rx_buffer_count < length ){ 
		if(usart_timer > g_usbtoaxregs.s.bUSART_ReceiveTimeout){
		    break;
		}
	}
setTX();
	if (local_rx_buffer_count != length){
		return false;
	}
	
	// TODO check for error in the packet, so that we don't wait if the status packet says that something went wrong... ?
	
	// compute checksum
    uint8_t checksum = 0; // accumulator for checksum
    for(uint8_t i=2; i < length; i++){
        checksum += local_rx_buffer[i];
    }
    
    if((checksum%256) != 255){
        return false; // invalid checksum
    }else{
        return true;
    }
}
Example #3
0
void SONAR::init(unsigned char pinCtrl,unsigned int baudrate) {
	debug();
	Serial.begin(baudrate);
	setPinCtrl(pinCtrl);
	pinMode(getPinCtrl(),OUTPUT);
	setTX();
}
Example #4
0
unsigned char SONAR::recvDat(unsigned char desiredSize) {
	debug();
	clearBuf();
	init();	// 201209
	setRX();
	unsigned char datSize=0;
	
#if defined(BOARD_maple) || defined(BOARD_maple_native) || defined(BOARD_maple_mini)
	for(int j=0;datSize<desiredSize && j<15;++j) {
		delay(1);
		unsigned char ibyte=Serial.read();
		
		if(datSize==0 && ibyte!=0x55) continue;
		if(datSize==1 && ibyte!=0xaa) continue;
		_recvBuf[datSize++]=ibyte;
	}
#else//for arduino
	for(int j=0;datSize<desiredSize && j<5000;++j) {
		unsigned char ibyte=Serial.read();
		if(ibyte!=0xff) {
			_recvBuf[datSize++]=ibyte;
		}
	}
#endif

	//SonarPrint.println(Serial.read(), HEX);
	setTX();
	return datSize;
}
Example #5
0
unsigned char SONAR::showDat(unsigned char desiredSize) {
	debug();
	setTX();
	for(int i=0;i<desiredSize;++i) {
		SonarPrint.print(_recvBuf[i],HEX);
		SonarPrint.print(" ");
	}
	SonarPrint.println();
	return desiredSize; 
}
Example #6
0
unsigned char SONAR::sendCmd(unsigned char* cmd,unsigned char size) {
	debug();
	init();	// 201209
	setTX();
	for(int i=0;i<size;++i) {
		Serial.write(cmd[i]);	// 201204
	}
	Serial.flush(); // 201204
	return size;
}
Example #7
0
//
// Constructor
//
SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */) : 
	_rx_delay_centering(0),
	_rx_delay_intrabit(0),
	_rx_delay_stopbit(0),
	_tx_delay(0),
	_buffer_overflow(false),
	_inverse_logic(inverse_logic)
{
	setTX(transmitPin);
	setRX(receivePin);
}
Example #8
0
//
// Constructor
//
SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */) : 
  baud(0),
  _buffer_overflow(false),
  _inverse_logic(inverse_logic)
{
#ifdef DEBUG_SOFTWARESERIAL
    printf("SoftwareSerial rx: pin %d, tx: pin %d\n", receivePin, transmitPin);
#endif
  setTX(transmitPin);
  setRX(receivePin);
}
Example #9
0
/** send instruction packet */
void AX12::ax12SendPacket (byte _id, byte datalength, byte instruction, byte* data) {
    byte checksum = 0;
    setTX();
    ax12writeB(0xFF);
    ax12writeB(0xFF);
    checksum += ax12writeB(_id);
    checksum += ax12writeB(datalength + 2);
    checksum += ax12writeB(instruction);
    for (byte f=0; f<datalength; f++) {     // data = parĂ¡metros
      checksum += ax12writeB(data[f]);
    }
    // checksum =
    ax12writeB(~checksum);
    setRX();
}
Example #10
0
unsigned char SONAR::setAddr(unsigned char addr) {
	debug();
	if(addr==0) {
		unsigned startTime=millis();
		unsigned int delta=0;
		bool gotKey=false;

		pinMode(keyS7, INPUT);	// 201209
		while(digitalRead(keyS7)==KEYPRESSED) {
			gotKey=true;
			delay(100);			
			SonarPrint.println(delta=millis()-startTime,DEC);
		}
		if(gotKey) {
			setTX();
			SonarPrint.print("GOt KeyS7(ms): ");
			SonarPrint.println(delta,DEC);
		}
		
		delta/=1000;
		if(0x1<=delta && delta<=0x30) addr=0x10+delta;
	}

	unsigned char addrCmd[sizeof(addrCmdTemplate)];
	if(0x11<=addr && addr<=0x30) {
		generateAddrCmd(addrCmd,addr);
		sendCmd(addrCmd,sizeof(addrCmd));
		delay(1);
		recvDat(addrDatSize);
		#ifdef DEBUG
			showDat(addrDatSize);
		#endif
		if(checksum(addrDatSize)==0) {
			initAddr(addr);
			return addr;
		}
	}
	return 0;
}
Example #11
0
//
// Constructor
//
Timer2Serial::Timer2Serial(uint8_t receivePin, uint8_t transmitPin) {

  setTX(transmitPin);

}
//
// Constructor
//
SendOnlySoftwareSerial::SendOnlySoftwareSerial(uint8_t transmitPin, bool inverse_logic /* = false */) :
  _tx_delay(0),
  _inverse_logic(inverse_logic)
{
  setTX(transmitPin);
}