mirror of
				https://github.com/Oleg-Stepanenko-owo/IEBUS
				synced 2025-10-31 02:17:12 +00:00 
			
		
		
		
	Added bluetooth module
This commit is contained in:
		
							parent
							
								
									033034df6b
								
							
						
					
					
						commit
						a4836d69b1
					
				
							
								
								
									
										33
									
								
								AVCLan_mini/AVCLan_BT.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								AVCLan_mini/AVCLan_BT.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | |||||||
|  | //--------------------------------------------------------------------------------
 | ||||||
|  | #include "AVCLan_BT.h" | ||||||
|  | #include <SoftwareSerial.h> | ||||||
|  | #include <avr/pgmspace.h> | ||||||
|  | //--------------------------------------------------------------------------------
 | ||||||
|  | SoftwareSerial mySerial(4, 3); // RX | TX
 | ||||||
|  | 
 | ||||||
|  | //--------------------------------------------------------------------------------
 | ||||||
|  | void AVCLanBT::begin() | ||||||
|  | //--------------------------------------------------------------------------------
 | ||||||
|  | { | ||||||
|  |   mySerial.begin(9600); | ||||||
|  |   mySerial.println("BlueTooth is ready"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | //--------------------------------------------------------------------------------
 | ||||||
|  | void AVCLanBT::println( char* val ) | ||||||
|  | //--------------------------------------------------------------------------------
 | ||||||
|  | { | ||||||
|  |   mySerial.println( val ); | ||||||
|  |   mySerial.println( "\n\r" ); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | //--------------------------------------------------------------------------------
 | ||||||
|  | void AVCLanBT::print( const char* val ) | ||||||
|  | //--------------------------------------------------------------------------------
 | ||||||
|  | { | ||||||
|  |   mySerial.print( val ); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | AVCLanBT avclanBT; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
							
								
								
									
										28
									
								
								AVCLan_mini/AVCLan_BT.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								AVCLan_mini/AVCLan_BT.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | |||||||
|  | /*
 | ||||||
|  | */ | ||||||
|  | #ifndef AVCLanBT_h | ||||||
|  | #define AVCLanBT_h | ||||||
|  | 
 | ||||||
|  | #include <avr/pgmspace.h> | ||||||
|  | #include "Arduino.h" | ||||||
|  | 
 | ||||||
|  | //--------------------------------------------------------------------------------
 | ||||||
|  | 
 | ||||||
|  | //--------------------------------------------------------------------------------
 | ||||||
|  | 
 | ||||||
|  | class AVCLanBT | ||||||
|  | { | ||||||
|  |   public: | ||||||
|  |     void begin ();                    // initialisation, obligatory method
 | ||||||
|  | 
 | ||||||
|  |     void println( char*); | ||||||
|  |     void print(const char*); | ||||||
|  | 
 | ||||||
|  |   private: | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | extern AVCLanBT avclanBT; | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| @ -1,6 +1,7 @@ | |||||||
| 
 | 
 | ||||||
| #include "AVCLanDrv.h" | #include "AVCLanDrv.h" | ||||||
| #include "AVCLanHonda.h" | #include "AVCLanHonda.h" | ||||||
|  | #include "AVCLan_BT.h" | ||||||
| #include "config.h" | #include "config.h" | ||||||
| //--------------------------------------------------------------------------------
 | //--------------------------------------------------------------------------------
 | ||||||
| 
 | 
 | ||||||
| @ -11,6 +12,9 @@ | |||||||
| #define HONDA_DIS_ON   sbi(LED_PORT, COMMUT_OUT); | #define HONDA_DIS_ON   sbi(LED_PORT, COMMUT_OUT); | ||||||
| #define HONDA_DIS_OFF  cbi(LED_PORT, COMMUT_OUT); | #define HONDA_DIS_OFF  cbi(LED_PORT, COMMUT_OUT); | ||||||
| 
 | 
 | ||||||
|  | static int MAX_ERROR_COUNT = 30; | ||||||
|  | byte errorID; | ||||||
|  | int  error_count; | ||||||
| //--------------------------------------------------------------------------------
 | //--------------------------------------------------------------------------------
 | ||||||
| void setup() | void setup() | ||||||
| //--------------------------------------------------------------------------------
 | //--------------------------------------------------------------------------------
 | ||||||
| @ -20,6 +24,11 @@ void setup() | |||||||
| 
 | 
 | ||||||
|   avclan.begin(); |   avclan.begin(); | ||||||
|   avclanHonda.begin(); |   avclanHonda.begin(); | ||||||
|  |   errorID = 0; | ||||||
|  |   error_count = 0; | ||||||
|  | 
 | ||||||
|  |   avclanBT.begin(); | ||||||
|  |   avclanBT.println("Start HONDA avclan."); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //--------------------------------------------------------------------------------
 | //--------------------------------------------------------------------------------
 | ||||||
| @ -43,10 +52,22 @@ void loop() | |||||||
|   if ( INPUT_IS_SET ) { |   if ( INPUT_IS_SET ) { | ||||||
|     byte res = avclan.readMessage(); |     byte res = avclan.readMessage(); | ||||||
|     if ( !res ) { |     if ( !res ) { | ||||||
|  |       error_count = 0; | ||||||
|  | 
 | ||||||
|       avclanHonda.getActionID(); |       avclanHonda.getActionID(); | ||||||
|       if ( avclan.actionID != ACT_NONE ) { |       if ( avclan.actionID != ACT_NONE ) { | ||||||
|         avclanHonda.processAction( (AvcActionID)avclan.actionID ); |         avclanHonda.processAction( (AvcActionID)avclan.actionID ); | ||||||
|       } |       } | ||||||
|  |     } else { | ||||||
|  |       if ( errorID == res ) error_count++; | ||||||
|  |       else error_count = 1; | ||||||
|  | 
 | ||||||
|  |       errorID = res; | ||||||
|  | 
 | ||||||
|  |       if ( error_count > MAX_ERROR_COUNT ) { | ||||||
|  |         error_count = 0; | ||||||
|  |         avclanHonda.setHondaDis(true); | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -60,6 +81,13 @@ void loop() | |||||||
|       HONDA_DIS_OFF; |       HONDA_DIS_OFF; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   if ( !error_count &&  errorID ) { | ||||||
|  |     char BUFFF[15]; | ||||||
|  |     sprintf(BUFFF, "Error: %d", errorID); | ||||||
|  |     avclanBT.println( BUFFF ); | ||||||
|  |     delay(2000); | ||||||
|  |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -29,10 +29,7 @@ | |||||||
| #define  LED_DDR     DDRC | #define  LED_DDR     DDRC | ||||||
| #define  LED_PORT    PORTC | #define  LED_PORT    PORTC | ||||||
| #define  LED_PIN     PINC | #define  LED_PIN     PINC | ||||||
| //#define  LED_OUT     5
 | #define COMMUT_OUT   0 | ||||||
| 
 |  | ||||||
| // Commutate pin 11
 |  | ||||||
| #define COMMUT_OUT   1 |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| // AZFM board activate
 | // AZFM board activate
 | ||||||
|  | |||||||
| @ -1,12 +1,14 @@ | |||||||
|  | /*
 | ||||||
|  |   AVCLanDrv.cpp - AVCLan Library for 'duino / Wiring | ||||||
|  |   Created by Kochetkov Aleksey, 04.08.2010 | ||||||
|  |   Version 0.3.1 | ||||||
|  | */ | ||||||
|  | 
 | ||||||
| #include "AVCLanDrv.h" | #include "AVCLanDrv.h" | ||||||
| #include "BuffSerial.h" | #include "BuffSerial.h" | ||||||
| 
 | 
 | ||||||
| // AVCLan driver & timer2 init, 
 | // AVCLan driver & timer2 init, 
 | ||||||
| // char buff[80] = {0};
 | void AVCLanDrv::begin (){ | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| void AVCLanDrv::begin () |  | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
| 	// AVCLan TX+/TX- 	read line INPUT
 | 	// AVCLan TX+/TX- 	read line INPUT
 | ||||||
| 	cbi(DATAIN_DDR,  DATAIN); | 	cbi(DATAIN_DDR,  DATAIN); | ||||||
| #ifdef AVCLAN_ST485 | #ifdef AVCLAN_ST485 | ||||||
| @ -30,48 +32,45 @@ void AVCLanDrv::begin () | |||||||
| 	AVC_OUT_DIS; | 	AVC_OUT_DIS; | ||||||
| 	OUTPUT_SET_0; | 	OUTPUT_SET_0; | ||||||
| #else  | #else  | ||||||
|   //avclan driver on PCA82C250 & LM239N
 | //avclan driver on PCA82C250 & LM239N
 | ||||||
| 	sbi(DATAOUT_DDR,  DATAOUT); | 	sbi(DATAOUT_DDR,  DATAOUT); | ||||||
| 	AVC_OUT_DIS; | 	AVC_OUT_DIS; | ||||||
| 	OUTPUT_SET_0; | 	OUTPUT_SET_0; | ||||||
| #endif | #endif | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|   // timer2 setup, prescaler factor - 8
 | // timer2 setup, prescaler factor - 8
 | ||||||
| #if defined(__AVR_ATmega8__) | #if defined(__AVR_ATmega8__) | ||||||
|   //  ASSR=0x00;
 | //	ASSR=0x00;
 | ||||||
|   TCCR2 = 0x02; | 	TCCR2=0x02; | ||||||
|   //  TCNT2=0x00;
 | //	TCNT2=0x00;
 | ||||||
|   //  OCR2=0x00;
 | //	OCR2=0x00;
 | ||||||
| #else   // ATMega168
 | #else   // ATMega168
 | ||||||
|   //  ASSR=0x00;
 | //	ASSR=0x00;
 | ||||||
|   //  TCCR2A=0x00;
 | //	TCCR2A=0x00;
 | ||||||
|   TCCR2B = 0x02; | 	TCCR2B=0x02; | ||||||
|   //  TCNT2=0x00;
 | //	TCNT2=0x00;
 | ||||||
|   //  OCR2A=0x00;
 | //	OCR2A=0x00;
 | ||||||
|   //  OCR2B=0x00;
 | //	OCR2B=0x00;
 | ||||||
| #endif | #endif | ||||||
| 	headAddress   = 0x0000; | 	headAddress   = 0x0000; | ||||||
| 	deviceAddress = 0x0000; | 	deviceAddress = 0x0000; | ||||||
|   //  event         = EV_NONE;
 | 	event         = EV_NONE; | ||||||
| 	actionID      = ACT_NONE; | 	actionID      = ACT_NONE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Reads specified number of bits from the AVCLan.
 | // Reads specified number of bits from the AVCLan.
 | ||||||
| // nbBits (byte) -> Number of bits to read.
 | // nbBits (byte) -> Number of bits to read.
 | ||||||
| // Return (word) -> Data value read.
 | // Return (word) -> Data value read.
 | ||||||
| //--------------------------------------------------------------------------------
 | word AVCLanDrv::readBits (byte nbBits){ | ||||||
| word AVCLanDrv::readBits (byte nbBits) |  | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
| 	word data  = 0; | 	word data  = 0; | ||||||
| 	_parityBit = 0; | 	_parityBit = 0; | ||||||
| 	 | 	 | ||||||
|   while (nbBits-- > 0) { | 	while (nbBits-- > 0){ | ||||||
| 		// Insert new bit
 | 		// Insert new bit
 | ||||||
| 		data <<= 1; | 		data <<= 1; | ||||||
| 		// Wait until rising edge of new bit.
 | 		// Wait until rising edge of new bit.
 | ||||||
|     while (INPUT_IS_CLEAR) { | 		while (INPUT_IS_CLEAR){ | ||||||
| 			// Reset watchdog.
 | 			// Reset watchdog.
 | ||||||
| 			//wdt_reset();
 | 			//wdt_reset();
 | ||||||
| 		} | 		} | ||||||
| @ -81,47 +80,40 @@ word AVCLanDrv::readBits (byte nbBits) | |||||||
| 		// Wait until falling edge.
 | 		// Wait until falling edge.
 | ||||||
| 		while (INPUT_IS_SET); | 		while (INPUT_IS_SET); | ||||||
| 		// Compare half way between a '1' (20 us) and a '0' (32 us ): 32 - (32 - 20) /2 = 26 us
 | 		// Compare half way between a '1' (20 us) and a '0' (32 us ): 32 - (32 - 20) /2 = 26 us
 | ||||||
|     if (TCNT2 < AVC_BIT_0_HOLD_ON_MIN_LENGTH) { | 		if (TCNT2 < AVC_BIT_0_HOLD_ON_MIN_LENGTH){ | ||||||
| 			// Set new bit.
 | 			// Set new bit.
 | ||||||
| 			data |= 0x0001; | 			data |= 0x0001; | ||||||
| 			// Adjust parity.
 | 			// Adjust parity.
 | ||||||
|       _parityBit = !_parityBit; | 			_parityBit = ! _parityBit; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	while (INPUT_IS_CLEAR && TCNT2 < AVC_NORMAL_BIT_LENGTH); | 	while (INPUT_IS_CLEAR && TCNT2 < AVC_NORMAL_BIT_LENGTH); | ||||||
| 
 |  | ||||||
|   //  char buff[10] = {0};
 |  | ||||||
|   //  sprintf(buff, "%x", data );
 |  | ||||||
|   //  // bSDLog.logs( buff );
 |  | ||||||
| 	return data; | 	return data; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Read incoming messages on the AVCLan.
 | // Read incoming messages on the AVCLan.
 | ||||||
| // Return 0 if success.
 | // Return true if success.
 | ||||||
| //--------------------------------------------------------------------------------
 | byte AVCLanDrv::_readMessage (){ | ||||||
| byte AVCLanDrv::_readMessage () |  | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
| 	uint8_t t = 0; | 	uint8_t t = 0; | ||||||
| 	uint8_t oldSREG = SREG; | 	uint8_t oldSREG = SREG; | ||||||
| 	cli();             // disable interrupts
 | 	cli();             // disable interrupts
 | ||||||
| 
 | 
 | ||||||
| 	// Start bit.
 | 	// Start bit.
 | ||||||
| 	while (INPUT_IS_CLEAR); | 	while (INPUT_IS_CLEAR); | ||||||
|   TCCR2B = 0x03;    // prescaler 32
 | 	TCCR2B=0x03;      // prescaler 32
 | ||||||
| 	TCNT2 = 0; | 	TCNT2 = 0; | ||||||
| 	// Wait until falling edge.
 | 	// Wait until falling edge.
 | ||||||
|   while (INPUT_IS_SET) { | 	while (INPUT_IS_SET){ | ||||||
| 		t = TCNT2; | 		t = TCNT2; | ||||||
| 		if (t > 0xFF) { | 		if (t > 0xFF) { | ||||||
|       TCCR2B = 0x02;    // prescaler 8
 | 			TCCR2B=0x02;      // prescaler 8
 | ||||||
| 			SREG = oldSREG; | 			SREG = oldSREG; | ||||||
| 			return 1; | 			return 1; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|   TCCR2B = 0x02;    // prescaler 8
 | 	TCCR2B=0x02;      // prescaler 8
 | ||||||
| 	 | 	 | ||||||
|   if (t < AVC_START_BIT_HOLD_ON_MIN_LENGTH) { | 	if (t < AVC_START_BIT_HOLD_ON_MIN_LENGTH){ | ||||||
| 	//if (t < 0x16){
 | 	//if (t < 0x16){
 | ||||||
| 			SREG = oldSREG; | 			SREG = oldSREG; | ||||||
| 			return 2; | 			return 2; | ||||||
| @ -131,80 +123,80 @@ byte AVCLanDrv::_readMessage () | |||||||
| 
 | 
 | ||||||
| 	masterAddress = readBits(12); | 	masterAddress = readBits(12); | ||||||
| 	bool p = _parityBit; | 	bool p = _parityBit; | ||||||
|   if (p != readBits(1)) { | 	if (p != readBits(1)){ | ||||||
| 		SREG = oldSREG; | 		SREG = oldSREG; | ||||||
| 		return 3; | 		return 3; | ||||||
| 	} | 	} | ||||||
|    |    | ||||||
| 	slaveAddress = readBits(12);        | 	slaveAddress = readBits(12);        | ||||||
| 	p = _parityBit; | 	p = _parityBit; | ||||||
|   if (p != readBits(1)) { | 	if (p != readBits(1)){ | ||||||
| 		SREG = oldSREG; | 		SREG = oldSREG; | ||||||
| 		return 4; | 		return 4; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	bool forMe = ( slaveAddress == deviceAddress ); | 	bool forMe = ( slaveAddress == deviceAddress ); | ||||||
| 
 | 
 | ||||||
|   if (forMe) { | 	if (forMe){ | ||||||
| 		// Send ACK.
 | 		// Send ACK.
 | ||||||
| 		AVC_OUT_EN; | 		AVC_OUT_EN; | ||||||
| 		send1BitWord(0); | 		send1BitWord(0); | ||||||
| 		AVC_OUT_DIS; | 		AVC_OUT_DIS; | ||||||
|   } else { | 	}else{   | ||||||
| 		readBits(1); | 		readBits(1); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Control 
 | 	// Control 
 | ||||||
| 	readBits(4); | 	readBits(4); | ||||||
| 	p = _parityBit; | 	p = _parityBit; | ||||||
|   if (p != readBits(1)) { | 	if (p != readBits(1)){ | ||||||
| 		SREG = oldSREG; | 		SREG = oldSREG; | ||||||
| 		return 5; | 		return 5; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|   if (forMe) { | 	if (forMe){ | ||||||
| 		// Send ACK.
 | 		// Send ACK.
 | ||||||
| 		AVC_OUT_EN; | 		AVC_OUT_EN; | ||||||
| 		send1BitWord(0); | 		send1BitWord(0); | ||||||
| 		AVC_OUT_DIS; | 		AVC_OUT_DIS; | ||||||
|   } else { | 	}else{   | ||||||
| 		readBits(1); | 		readBits(1); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	dataSize = readBits(8); | 	dataSize = readBits(8); | ||||||
| 	p = _parityBit; | 	p = _parityBit; | ||||||
|   if (p != readBits(1)) { | 	if (p != readBits(1)){ | ||||||
| 		SREG = oldSREG; | 		SREG = oldSREG; | ||||||
| 		return 6; | 		return 6; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|   if (forMe) { | 	if (forMe){ | ||||||
| 		// Send ACK.
 | 		// Send ACK.
 | ||||||
| 		AVC_OUT_EN; | 		AVC_OUT_EN; | ||||||
| 		send1BitWord(0); | 		send1BitWord(0); | ||||||
| 		AVC_OUT_DIS; | 		AVC_OUT_DIS; | ||||||
|   } else { | 	}else{   | ||||||
| 		readBits(1); | 		readBits(1); | ||||||
| 	} | 	} | ||||||
|   if (dataSize > AVC_MAXMSGLEN) { | 	if (dataSize > AVC_MAXMSGLEN){ | ||||||
| 		SREG = oldSREG; | 		SREG = oldSREG; | ||||||
| 		return 7; | 		return 7; | ||||||
| 	} | 	} | ||||||
| 	byte i; | 	byte i; | ||||||
|   for (i = 0; i < dataSize; i++ ) { | 	for (i = 0; i < dataSize; i++ ){ | ||||||
| 		message[i] = readBits(8); | 		message[i] = readBits(8); | ||||||
| 		p = _parityBit; | 		p = _parityBit; | ||||||
|     if (p != readBits(1)) { | 		if (p != readBits(1)){ | ||||||
| 			SREG = oldSREG; | 			SREG = oldSREG; | ||||||
| 			return 8; | 			return 8; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|     if (forMe) { | 		if (forMe){ | ||||||
| 			// Send ACK.
 | 			// Send ACK.
 | ||||||
| 			AVC_OUT_EN; | 			AVC_OUT_EN; | ||||||
| 			send1BitWord(0); | 			send1BitWord(0); | ||||||
| 			AVC_OUT_DIS; | 			AVC_OUT_DIS; | ||||||
|     } else { | 		}else{   | ||||||
| 			readBits(1); | 			readBits(1); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @ -214,50 +206,45 @@ byte AVCLanDrv::_readMessage () | |||||||
| 
 | 
 | ||||||
| // Read incoming messages on the AVCLan, log message through serial port
 | // Read incoming messages on the AVCLan, log message through serial port
 | ||||||
| // Return true if success.
 | // Return true if success.
 | ||||||
| //--------------------------------------------------------------------------------
 | byte AVCLanDrv::readMessage (){ | ||||||
| byte AVCLanDrv::readMessage () |  | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
| 	byte res = avclan._readMessage(); | 	byte res = avclan._readMessage(); | ||||||
|   if (res) | 	if (!res){ | ||||||
|   { | 		avclan.printMessage(true); | ||||||
|  | 	}else{ | ||||||
|  | 		bSerial.print("R"); | ||||||
|  | 		bSerial.printHex4(res); | ||||||
|  | 		bSerial.println(); | ||||||
| 		while (!avclan.isAvcBusFree()); | 		while (!avclan.isAvcBusFree()); | ||||||
| 	} | 	} | ||||||
| 	return res; | 	return res; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Send a start bit to the AVCLan
 | // Send a start bit to the AVCLan
 | ||||||
| ////--------------------------------------------------------------------------------
 | void AVCLanDrv::sendStartBit (){ | ||||||
| //void AVCLanDrv::sendStartBit ()
 | 	// Reset timer to measure bit length.
 | ||||||
| ////--------------------------------------------------------------------------------
 | 	TCCR2B=0x03;      // prescaler 32
 | ||||||
| //{
 | 	TCNT2 = 0; | ||||||
| //  // Reset timer to measure bit length.
 | 	OUTPUT_SET_1; | ||||||
| //  TCCR2B = 0x03;    // prescaler 32
 | 
 | ||||||
| //  TCNT2 = 0;
 | 	// Pulse level high duration.
 | ||||||
| //  OUTPUT_SET_1;
 | 	while ( TCNT2 < AVC_START_BIT_HOLD_ON_LENGTH ); | ||||||
| //
 | 	OUTPUT_SET_0; | ||||||
| //  // Pulse level high duration.
 | 
 | ||||||
| //  while ( TCNT2 < AVC_START_BIT_HOLD_ON_LENGTH );
 | 	// Pulse level low duration until ~185 us.
 | ||||||
| //  OUTPUT_SET_0;
 | 	while ( TCNT2 < AVC_START_BIT_LENGTH ); | ||||||
| //
 | 	TCCR2B=0x02;      // prescaler 8
 | ||||||
| //  // Pulse level low duration until ~185 us.
 | 
 | ||||||
| //  while ( TCNT2 < AVC_START_BIT_LENGTH );
 | } | ||||||
| //  TCCR2B = 0x02;    // prescaler 8
 |  | ||||||
| //
 |  | ||||||
| //}
 |  | ||||||
| 
 | 
 | ||||||
| // Send a 1 bit word to the AVCLan
 | // Send a 1 bit word to the AVCLan
 | ||||||
| //--------------------------------------------------------------------------------
 | void AVCLanDrv::send1BitWord (bool data){ | ||||||
| void AVCLanDrv::send1BitWord (bool data) |  | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
| 	// Reset timer to measure bit length.
 | 	// Reset timer to measure bit length.
 | ||||||
| 	TCNT2 = 0; | 	TCNT2 = 0; | ||||||
| 	OUTPUT_SET_1; | 	OUTPUT_SET_1; | ||||||
| 
 | 
 | ||||||
|   if (data) { | 	if (data){ | ||||||
| 		while (TCNT2 < AVC_BIT_1_HOLD_ON_LENGTH); | 		while (TCNT2 < AVC_BIT_1_HOLD_ON_LENGTH); | ||||||
|   } else { | 	}else{ | ||||||
| 		while (TCNT2 < AVC_BIT_0_HOLD_ON_LENGTH); | 		while (TCNT2 < AVC_BIT_0_HOLD_ON_LENGTH); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -265,108 +252,96 @@ void AVCLanDrv::send1BitWord (bool data) | |||||||
| 	while (TCNT2 <  AVC_NORMAL_BIT_LENGTH); | 	while (TCNT2 <  AVC_NORMAL_BIT_LENGTH); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //// Send a 4 bit word to the AVCLan
 | // Send a 4 bit word to the AVCLan
 | ||||||
| ////--------------------------------------------------------------------------------
 | void AVCLanDrv::send4BitWord (byte data){ | ||||||
| //void AVCLanDrv::send4BitWord (byte data)
 | 	_parityBit = 0; | ||||||
| ////--------------------------------------------------------------------------------
 | 
 | ||||||
| //{
 | 	// Most significant bit out first.   
 | ||||||
| //  _parityBit = 0;
 | 	for ( char nbBits = 0; nbBits < 4; nbBits++ ){ | ||||||
| //
 | 		// Reset timer to measure bit length.
 | ||||||
| //  // Most significant bit out first.
 | 		TCNT2 = 2; | ||||||
| //  for ( char nbBits = 0; nbBits < 4; nbBits++ ) {
 | 		OUTPUT_SET_1; | ||||||
| //    // Reset timer to measure bit length.
 | 
 | ||||||
| //    TCNT2 = 2;
 | 		if (data & 0x8){ | ||||||
| //    OUTPUT_SET_1;
 | 			// Adjust parity.
 | ||||||
| //
 | 			_parityBit = ! _parityBit; | ||||||
| //    if (data & 0x8) {
 | 			while ( TCNT2 < AVC_BIT_1_HOLD_ON_LENGTH ); | ||||||
| //      // Adjust parity.
 | 		}else{ | ||||||
| //      _parityBit = ! _parityBit;
 | 			while ( TCNT2 < AVC_BIT_0_HOLD_ON_LENGTH ); | ||||||
| //      while ( TCNT2 < AVC_BIT_1_HOLD_ON_LENGTH );
 | 		} | ||||||
| //    } else {
 | 
 | ||||||
| //      while ( TCNT2 < AVC_BIT_0_HOLD_ON_LENGTH );
 | 		OUTPUT_SET_0; | ||||||
| //    }
 | 		// Hold output low until end of bit.
 | ||||||
| //
 | 		while ( TCNT2 < AVC_NORMAL_BIT_LENGTH ); | ||||||
| //    OUTPUT_SET_0;
 | 
 | ||||||
| //    // Hold output low until end of bit.
 | 		// Fetch next bit.
 | ||||||
| //    while ( TCNT2 < AVC_NORMAL_BIT_LENGTH );
 | 		data <<= 1; | ||||||
| //
 | 	} | ||||||
| //    // Fetch next bit.
 | } | ||||||
| //    data <<= 1;
 | 
 | ||||||
| //  }
 | // Send a 8 bit word to the AVCLan
 | ||||||
| //}
 | void AVCLanDrv::send8BitWord (byte data){ | ||||||
| //
 | 	_parityBit = 0; | ||||||
| //// Send a 8 bit word to the AVCLan
 | 
 | ||||||
| ////--------------------------------------------------------------------------------
 | 	// Most significant bit out first.   
 | ||||||
| //void AVCLanDrv::send8BitWord (byte data)
 | 	for ( char nbBits = 0; nbBits < 8; nbBits++ ){ | ||||||
| ////--------------------------------------------------------------------------------
 | 		// Reset timer to measure bit length.
 | ||||||
| //{
 | 		TCNT2 = 2; | ||||||
| //  _parityBit = 0;
 | 		OUTPUT_SET_1; | ||||||
| //
 | 
 | ||||||
| //  // Most significant bit out first.
 | 		if (data & 0x80){ | ||||||
| //  for ( char nbBits = 0; nbBits < 8; nbBits++ ) {
 | 			// Adjust parity.
 | ||||||
| //    // Reset timer to measure bit length.
 | 			_parityBit = ! _parityBit; | ||||||
| //    TCNT2 = 2;
 | 			while ( TCNT2 < AVC_BIT_1_HOLD_ON_LENGTH ); | ||||||
| //    OUTPUT_SET_1;
 | 		}else{ | ||||||
| //
 | 			while ( TCNT2 < AVC_BIT_0_HOLD_ON_LENGTH ); | ||||||
| //    if (data & 0x80) {
 | 		} | ||||||
| //      // Adjust parity.
 | 
 | ||||||
| //      _parityBit = ! _parityBit;
 | 		OUTPUT_SET_0; | ||||||
| //      while ( TCNT2 < AVC_BIT_1_HOLD_ON_LENGTH );
 | 		// Hold output low until end of bit.
 | ||||||
| //    } else {
 | 		while ( TCNT2 < AVC_NORMAL_BIT_LENGTH ); | ||||||
| //      while ( TCNT2 < AVC_BIT_0_HOLD_ON_LENGTH );
 | 
 | ||||||
| //    }
 | 		// Fetch next bit.
 | ||||||
| //
 | 		data <<= 1; | ||||||
| //    OUTPUT_SET_0;
 | 	} | ||||||
| //    // Hold output low until end of bit.
 | } | ||||||
| //    while ( TCNT2 < AVC_NORMAL_BIT_LENGTH );
 | 
 | ||||||
| //
 | // Send a 12 bit word to the AVCLan
 | ||||||
| //    // Fetch next bit.
 | void AVCLanDrv::send12BitWord (word data){ | ||||||
| //    data <<= 1;
 | 	_parityBit = 0; | ||||||
| //  }
 | 
 | ||||||
| //}
 | 	// Most significant bit out first.   
 | ||||||
| //
 | 	for ( char nbBits = 0; nbBits < 12; nbBits++ ){ | ||||||
| //// Send a 12 bit word to the AVCLan
 | 		// Reset timer to measure bit length.
 | ||||||
| ////--------------------------------------------------------------------------------
 | 		TCNT2 = 2; | ||||||
| //void AVCLanDrv::send12BitWord (word data)
 | 		OUTPUT_SET_1; | ||||||
| ////--------------------------------------------------------------------------------
 | 
 | ||||||
| //{
 | 		if (data & 0x0800){ | ||||||
| //  _parityBit = 0;
 | 			// Adjust parity.
 | ||||||
| //
 | 			_parityBit = ! _parityBit; | ||||||
| //  // Most significant bit out first.
 | 			while ( TCNT2 < AVC_BIT_1_HOLD_ON_LENGTH ); | ||||||
| //  for ( char nbBits = 0; nbBits < 12; nbBits++ ) {
 | 		}else{ | ||||||
| //    // Reset timer to measure bit length.
 | 			while ( TCNT2 < AVC_BIT_0_HOLD_ON_LENGTH ); | ||||||
| //    TCNT2 = 2;
 | 		} | ||||||
| //    OUTPUT_SET_1;
 | 
 | ||||||
| //
 | 		OUTPUT_SET_0; | ||||||
| //    if (data & 0x0800) {
 | 		// Hold output low until end of bit.
 | ||||||
| //      // Adjust parity.
 | 		while ( TCNT2 < AVC_NORMAL_BIT_LENGTH ); | ||||||
| //      _parityBit = ! _parityBit;
 | 
 | ||||||
| //      while ( TCNT2 < AVC_BIT_1_HOLD_ON_LENGTH );
 | 		// Fetch next bit.
 | ||||||
| //    } else {
 | 		data <<= 1; | ||||||
| //      while ( TCNT2 < AVC_BIT_0_HOLD_ON_LENGTH );
 | 	} | ||||||
| //    }
 | } | ||||||
| //
 |  | ||||||
| //    OUTPUT_SET_0;
 |  | ||||||
| //    // Hold output low until end of bit.
 |  | ||||||
| //    while ( TCNT2 < AVC_NORMAL_BIT_LENGTH );
 |  | ||||||
| //
 |  | ||||||
| //    // Fetch next bit.
 |  | ||||||
| //    data <<= 1;
 |  | ||||||
| //  }
 |  | ||||||
| //}
 |  | ||||||
| 
 | 
 | ||||||
| //  determine whether the bus is free (no tx/rx).
 | //  determine whether the bus is free (no tx/rx).
 | ||||||
| //  return TRUE is bus is free.
 | //  return TRUE is bus is free.
 | ||||||
| //--------------------------------------------------------------------------------
 | bool AVCLanDrv::isAvcBusFree (void){ | ||||||
| bool AVCLanDrv::isAvcBusFree (void) |  | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
| 	// Reset timer.
 | 	// Reset timer.
 | ||||||
| 	TCNT2 = 0; | 	TCNT2 = 0; | ||||||
| 
 | 
 | ||||||
|   while (INPUT_IS_CLEAR) { | 	while (INPUT_IS_CLEAR){ | ||||||
| 		// We assume the bus is free if anything happens for the length of 1 bit.
 | 		// We assume the bus is free if anything happens for the length of 1 bit.
 | ||||||
|     if (TCNT2 > AVC_NORMAL_BIT_LENGTH) { | 		if (TCNT2 > AVC_NORMAL_BIT_LENGTH){    | ||||||
| 			return true; | 			return true; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @ -374,167 +349,148 @@ bool AVCLanDrv::isAvcBusFree (void) | |||||||
| 	return false; | 	return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //// reads the acknowledge bit the AVCLan
 | // reads the acknowledge bit the AVCLan
 | ||||||
| //// return TRUE if ack detected else FALSE.
 | // return TRUE if ack detected else FALSE.
 | ||||||
| ////--------------------------------------------------------------------------------
 | bool AVCLanDrv::readAcknowledge (void){ | ||||||
| //bool AVCLanDrv::readAcknowledge (void)
 | 	// The acknowledge pattern is very tricky: the sender shall drive the bus for the equivalent
 | ||||||
| ////--------------------------------------------------------------------------------
 | 	// of a bit '1' (20 us) then release the bus and listen. At this point the target shall have
 | ||||||
| //{
 | 	// taken over the bus maintaining the pulse until the equivalent of a bit '0' (32 us) is formed.
 | ||||||
| //  // The acknowledge pattern is very tricky: the sender shall drive the bus for the equivalent
 | 
 | ||||||
| //  // of a bit '1' (20 us) then release the bus and listen. At this point the target shall have
 | 	// Reset timer to measure bit length.
 | ||||||
| //  // taken over the bus maintaining the pulse until the equivalent of a bit '0' (32 us) is formed.
 | 	TCNT2 = 0; | ||||||
| //
 | 	OUTPUT_SET_1; | ||||||
| //  // Reset timer to measure bit length.
 | 
 | ||||||
| //  TCNT2 = 0;
 | 	// Generate bit '0'.
 | ||||||
| //  OUTPUT_SET_1;
 | 	while (TCNT2 < AVC_BIT_1_HOLD_ON_LENGTH); | ||||||
| //
 | 	OUTPUT_SET_0; | ||||||
| //  // Generate bit '0'.
 | 	 | ||||||
| //  while (TCNT2 < AVC_BIT_1_HOLD_ON_LENGTH);
 | 	AVC_OUT_DIS; | ||||||
| //  OUTPUT_SET_0;
 | 	 | ||||||
| //
 | 	while (TCNT2 < AVC_BIT_1_HOLD_ON_LENGTH + AVC_1U_LENGTH); | ||||||
| //  AVC_OUT_DIS;
 | 	// Measure final resulting bit.
 | ||||||
| //
 | 	while ( INPUT_IS_SET ); | ||||||
| //  while (TCNT2 < AVC_BIT_1_HOLD_ON_LENGTH + AVC_1U_LENGTH);
 | 
 | ||||||
| //  // Measure final resulting bit.
 | 	// Sample half-way through bit '0' (26 us) to detect whether the target is acknowledging.
 | ||||||
| //  while ( INPUT_IS_SET );
 | 	if (TCNT2 > AVC_BIT_0_HOLD_ON_MIN_LENGTH){ | ||||||
| //
 | 		// Slave is acknowledging (ack = 0). Wait until end of ack bit.
 | ||||||
| //  // Sample half-way through bit '0' (26 us) to detect whether the target is acknowledging.
 | 		while (INPUT_IS_SET ); | ||||||
| //  if (TCNT2 > AVC_BIT_0_HOLD_ON_MIN_LENGTH) {
 | 		AVC_OUT_EN; | ||||||
| //    // Slave is acknowledging (ack = 0). Wait until end of ack bit.
 | 		return true; | ||||||
| //    while (INPUT_IS_SET );
 | 	} | ||||||
| //    AVC_OUT_EN;
 | 
 | ||||||
| //    return true;
 | 	// No sign of life on the bus.
 | ||||||
| //  }
 | 	return false;     | ||||||
| //
 | } | ||||||
| //  // No sign of life on the bus.
 | 
 | ||||||
| //  return false;
 | // sends ack bit if I am broadcasting otherwise wait and return received ack bit.
 | ||||||
| //}
 | // return FALSE if ack bit not detected.
 | ||||||
| //
 | bool AVCLanDrv::handleAcknowledge (void){ | ||||||
| //// sends ack bit if I am broadcasting otherwise wait and return received ack bit.
 | 	if (broadcast == AVC_MSG_BROADCAST){    | ||||||
| //// return FALSE if ack bit not detected.
 | 		// Acknowledge.    
 | ||||||
| ////--------------------------------------------------------------------------------
 | 		send1BitWord(0); | ||||||
| //bool AVCLanDrv::handleAcknowledge (void)
 | 		return true; | ||||||
| ////--------------------------------------------------------------------------------
 | 	} | ||||||
| //{
 | 
 | ||||||
| //  if (broadcast == AVC_MSG_BROADCAST) {
 | 	// Return acknowledge bit.
 | ||||||
| //    // Acknowledge.
 | 	return readAcknowledge(); | ||||||
| //    send1BitWord(0);
 | }  | ||||||
| //    return true;
 | 
 | ||||||
| //  }
 | // sends the message in global registers on the AVC LAN bus.
 | ||||||
| //
 | // return 0 if successful else error code
 | ||||||
| //  // Return acknowledge bit.
 | byte AVCLanDrv::_sendMessage (void){   | ||||||
| //  return readAcknowledge();
 | 	uint8_t oldSREG = SREG; | ||||||
| //}
 | 	cli();             // disable interrupts
 | ||||||
| //
 | 	while (!isAvcBusFree()); | ||||||
| //// sends the message in global registers on the AVC LAN bus.
 | 	 | ||||||
| //// return 0 if successful else error code
 | 	AVC_OUT_EN; | ||||||
| ////--------------------------------------------------------------------------------
 | 	 | ||||||
| //byte AVCLanDrv::_sendMessage (void)
 | 	// Send start bit.
 | ||||||
| ////--------------------------------------------------------------------------------
 | 	sendStartBit(); | ||||||
| //{
 | 
 | ||||||
| //  uint8_t oldSREG = SREG;
 | 	// Broadcast bit.
 | ||||||
| //  cli();             // disable interrupts
 | 	send1BitWord(broadcast); | ||||||
| //  while (!isAvcBusFree());
 | 
 | ||||||
| //
 | 	// Master address = me.
 | ||||||
| //  AVC_OUT_EN;
 | 	send12BitWord(masterAddress); | ||||||
| //
 | 	send1BitWord(_parityBit); | ||||||
| //  // Send start bit.
 | 
 | ||||||
| //  sendStartBit();
 | 	// Slave address = head unit (HU).
 | ||||||
| //
 | 	send12BitWord(slaveAddress); | ||||||
| //  // Broadcast bit.
 | 	send1BitWord(_parityBit); | ||||||
| //  send1BitWord(broadcast);
 | 	if (!handleAcknowledge()){ | ||||||
| //
 | 		AVC_OUT_DIS; | ||||||
| //  // Master address = me.
 | 		SREG = oldSREG; | ||||||
| //  send12BitWord(masterAddress);
 | 		return 1; | ||||||
| //  send1BitWord(_parityBit);
 | 	} | ||||||
| //
 | 
 | ||||||
| //  // Slave address = head unit (HU).
 | 	// Control flag + parity.
 | ||||||
| //  send12BitWord(slaveAddress);
 | 	send4BitWord(AVC_CONTROL_FLAGS); | ||||||
| //  send1BitWord(_parityBit);
 | 	send1BitWord(_parityBit); | ||||||
| //  if (!handleAcknowledge()) {
 | 	if (!handleAcknowledge()){ | ||||||
| //    AVC_OUT_DIS;
 | 		AVC_OUT_DIS; | ||||||
| //    SREG = oldSREG;
 | 		SREG = oldSREG; | ||||||
| //    return 1;
 | 		return 2; | ||||||
| //  }
 | 	} | ||||||
| //
 | 
 | ||||||
| //  // Control flag + parity.
 | 	// Data length + parity.
 | ||||||
| //  send4BitWord(AVC_CONTROL_FLAGS);
 | 	send8BitWord(dataSize); | ||||||
| //  send1BitWord(_parityBit);
 | 	send1BitWord(_parityBit); | ||||||
| //  if (!handleAcknowledge()) {
 | 	if (!handleAcknowledge()){ | ||||||
| //    AVC_OUT_DIS;
 | 		AVC_OUT_DIS; | ||||||
| //    SREG = oldSREG;
 | 		SREG = oldSREG; | ||||||
| //    return 2;
 | 		return 3; | ||||||
| //  }
 | 	} | ||||||
| //
 | 
 | ||||||
| //  // Data length + parity.
 | 	for (byte i = 0; i < dataSize; i++){ | ||||||
| //  send8BitWord(dataSize);
 | 		send8BitWord(message[i]); | ||||||
| //  send1BitWord(_parityBit);
 | 		send1BitWord(_parityBit); | ||||||
| //  if (!handleAcknowledge()) {
 | 		if (!handleAcknowledge()){ | ||||||
| //    AVC_OUT_DIS;
 | 			AVC_OUT_DIS; | ||||||
| //    SREG = oldSREG;
 | 			SREG = oldSREG; | ||||||
| //    return 3;
 | 			return false; | ||||||
| //  }
 | 		} | ||||||
| //
 | 	} | ||||||
| //  for (byte i = 0; i < dataSize; i++) {
 | 	AVC_OUT_DIS; | ||||||
| //    send8BitWord(message[i]);
 | 	SREG = oldSREG; | ||||||
| //    send1BitWord(_parityBit);
 | 	return 0; | ||||||
| //    if (!handleAcknowledge()) {
 | } | ||||||
| //      AVC_OUT_DIS;
 | 
 | ||||||
| //      SREG = oldSREG;
 |  | ||||||
| //      return false;
 |  | ||||||
| //    }
 |  | ||||||
| //  }
 |  | ||||||
| //  AVC_OUT_DIS;
 |  | ||||||
| //  SREG = oldSREG;
 |  | ||||||
| //  return 0;
 |  | ||||||
| //}
 |  | ||||||
| //
 |  | ||||||
| // sends the message in global registers on the AVC LAN bus, log message through serial port
 | // sends the message in global registers on the AVC LAN bus, log message through serial port
 | ||||||
| // return 0 if successful else error code
 | // return 0 if successful else error code
 | ||||||
| ////--------------------------------------------------------------------------------
 | byte AVCLanDrv::sendMessage (void){ | ||||||
| //byte AVCLanDrv::sendMessage (void)
 | 	byte sc = MAXSENDATTEMP; | ||||||
| ////--------------------------------------------------------------------------------
 | 	byte res; | ||||||
| //{
 | 	do{ | ||||||
| //  byte sc = MAXSENDATTEMP;
 | 		res = avclan._sendMessage(); | ||||||
| //  byte res;
 | 		if (!res){ | ||||||
| //  do {
 | 			avclan.printMessage(false); | ||||||
| //    res = avclan._sendMessage();
 | 		}else{ | ||||||
| //    if (!res) {
 | 			bSerial.print("W"); | ||||||
| //      avclan.printMessage(false);
 | 			bSerial.printHex4(res); | ||||||
| //    } else {
 | 			bSerial.println(); | ||||||
| //      //      bSerial.print("W");
 | 			while (!avclan.isAvcBusFree()); | ||||||
| //      //      bSerial.printHex4(res);
 | 		} | ||||||
| //      //      bSerial.println();
 | 		sc--; | ||||||
| //      while (!avclan.isAvcBusFree());
 | 	}while (sc && res); | ||||||
| //    }
 | 	return res; | ||||||
| //    sc--;
 | } | ||||||
| //  } while (sc && res);
 | 
 | ||||||
| //  return res;
 |  | ||||||
| //}
 |  | ||||||
| //
 |  | ||||||
| // sends the message for given mesage ID on the AVC LAN bus, log message through serial port
 | // sends the message for given mesage ID on the AVC LAN bus, log message through serial port
 | ||||||
| // return 0 if successful else error code
 | // return 0 if successful else error code
 | ||||||
| ////--------------------------------------------------------------------------------
 | byte AVCLanDrv::sendMessage (AvcOutMessage *msg){ | ||||||
| //byte AVCLanDrv::sendMessage (const AvcOutMessage *msg)
 | 	loadMessage(msg); | ||||||
| ////--------------------------------------------------------------------------------
 | 	return sendMessage(); | ||||||
| //{
 | } | ||||||
| //  loadMessage(msg);
 |  | ||||||
| //  return sendMessage();
 |  | ||||||
| //}
 |  | ||||||
| 
 |  | ||||||
| // print message to serial port
 | // print message to serial port
 | ||||||
| //--------------------------------------------------------------------------------
 | void AVCLanDrv::printMessage(bool incoming){ | ||||||
| void AVCLanDrv::printMessage(bool incoming) | 	if (incoming){ | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
|   if (incoming) { |  | ||||||
| 		bSerial.print("< "); | 		bSerial.print("< "); | ||||||
|   } else { | 	}else{ | ||||||
| 		bSerial.print("> "); | 		bSerial.print("> "); | ||||||
| 	}   | 	}   | ||||||
|   if (broadcast == AVC_MSG_BROADCAST) { | 	if (broadcast == AVC_MSG_BROADCAST){ | ||||||
| 		bSerial.print("b "); | 		bSerial.print("b "); | ||||||
|   } else { | 	}else{  | ||||||
| 		bSerial.print("d "); | 		bSerial.print("d "); | ||||||
| 	} | 	} | ||||||
| 	bSerial.printHex4(masterAddress >> 8); | 	bSerial.printHex4(masterAddress >> 8); | ||||||
| @ -546,33 +502,78 @@ void AVCLanDrv::printMessage(bool incoming) | |||||||
| 	bSerial.print(" "); | 	bSerial.print(" "); | ||||||
| 	bSerial.printHex8(dataSize); | 	bSerial.printHex8(dataSize); | ||||||
| 
 | 
 | ||||||
|   for (byte i = 0; i < dataSize; i++) { | 	for (byte i = 0; i < dataSize; i++){ | ||||||
| 		bSerial.printHex8(message[i]); | 		bSerial.printHex8(message[i]); | ||||||
| 	} | 	} | ||||||
| 	bSerial.println();  | 	bSerial.println();  | ||||||
|  | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Use the last received message to determine the corresponding action ID
 | ||||||
|  | byte AVCLanDrv::getActionID(AvcInMessageTable messageTable[], byte mtSize){ | ||||||
|  | 	if (slaveAddress != deviceAddress && slaveAddress != 0x0FFF) return ACT_NONE; | ||||||
|  | 	for (byte msg = 0; msg < mtSize; msg++){ | ||||||
|  | 		bool found = true; | ||||||
|  | 		 | ||||||
|  | 		if (dataSize != pgm_read_byte_near(&messageTable[msg].dataSize)){ | ||||||
|  | 			continue; | ||||||
|  | 		} | ||||||
|  | 		for (byte i = 0; i < dataSize; i++){ | ||||||
|  | 			if (message[i] != pgm_read_byte_near(&messageTable[msg].data[i])){ | ||||||
|  | 				found = false; | ||||||
|  | 				break; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if (found){ | ||||||
|  | 			return pgm_read_byte_near(&messageTable[msg].actionID); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return ACT_NONE; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // Use the last received message to determine the corresponding action ID, use masked message table
 | ||||||
|  | byte AVCLanDrv::getActionID(AvcInMaskedMessageTable messageTable[], byte mtSize){ | ||||||
|  | 	if (slaveAddress != deviceAddress && slaveAddress != 0x0FFF) return ACT_NONE; | ||||||
|  | 	for (byte msg = 0; msg < mtSize; msg++){ | ||||||
|  | 		bool found = true; | ||||||
|  | 		 | ||||||
|  | 		if (dataSize != pgm_read_byte_near(&messageTable[msg].dataSize)){ | ||||||
|  | 			continue; | ||||||
|  | 		} | ||||||
|  | 		word mask = pgm_read_byte_near(&messageTable[msg].mask); | ||||||
|  | 		for (byte i = 0; i < dataSize; i++){ | ||||||
|  | 			if (mask & _BV(i)) continue; | ||||||
|  | 			if (message[i] != pgm_read_byte_near(&messageTable[msg].data[i])){ | ||||||
|  | 				found = false; | ||||||
|  | 				break; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if (found){ | ||||||
|  | 			return pgm_read_byte_near(&messageTable[msg].actionID); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return ACT_NONE; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| // Loads message data for given mesage ID.
 | // Loads message data for given mesage ID.
 | ||||||
| ////--------------------------------------------------------------------------------
 | void AVCLanDrv::loadMessage(AvcOutMessage *msg){ | ||||||
| //void AVCLanDrv::loadMessage(const AvcOutMessage *msg)
 | 	broadcast = pgm_read_byte_near(&msg->broadcast); | ||||||
| ////--------------------------------------------------------------------------------
 | 	masterAddress = deviceAddress; | ||||||
| //{
 | 
 | ||||||
| //  broadcast = pgm_read_byte_near(&msg->broadcast);
 | 	if (broadcast == AVC_MSG_BROADCAST) | ||||||
| //  masterAddress = deviceAddress;
 | 		slaveAddress = 0x01FF; | ||||||
| //
 | 	else | ||||||
| //  if (broadcast == AVC_MSG_BROADCAST)
 | 		slaveAddress = headAddress; | ||||||
| //    slaveAddress = 0x01FF;
 | 
 | ||||||
| //  else
 | 	dataSize = pgm_read_byte_near( &msg->dataSize );  | ||||||
| //    slaveAddress = headAddress;
 | 
 | ||||||
| //
 | 	for (byte i = 0; i < dataSize; i++ ){ | ||||||
| //  dataSize = pgm_read_byte_near( &msg->dataSize );
 | 		message[i] = pgm_read_byte_near( &msg->data[i] ); | ||||||
| //
 | 	} | ||||||
| //  for (byte i = 0; i < dataSize; i++ ) {
 | }; | ||||||
| //    message[i] = pgm_read_byte_near( &msg->data[i] );
 |  | ||||||
| //  }
 |  | ||||||
| //}
 |  | ||||||
| 
 | 
 | ||||||
| AVCLanDrv avclan; | AVCLanDrv avclan; | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|  | |||||||
| @ -36,8 +36,8 @@ | |||||||
| #define INPUT_IS_CLEAR (bit_is_clear(DATAIN_PIN, DATAIN)) | #define INPUT_IS_CLEAR (bit_is_clear(DATAIN_PIN, DATAIN)) | ||||||
| #define OUTPUT_SET_1   (cbi(DATAOUT_PORT, DATAOUT)); | #define OUTPUT_SET_1   (cbi(DATAOUT_PORT, DATAOUT)); | ||||||
| #define OUTPUT_SET_0   (sbi(DATAOUT_PORT, DATAOUT)); | #define OUTPUT_SET_0   (sbi(DATAOUT_PORT, DATAOUT)); | ||||||
| #define AVC_OUT_EN; | #define AVC_OUT_EN     ;  | ||||||
| #define AVC_OUT_DIS; | #define AVC_OUT_DIS    ; | ||||||
| #endif | #endif | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| @ -61,39 +61,29 @@ typedef enum | |||||||
| } AvcTransmissionMode; | } AvcTransmissionMode; | ||||||
| 
 | 
 | ||||||
| #define ACT_NONE 0  // no action
 | #define ACT_NONE 0  // no action
 | ||||||
| //#define EV_NONE	 0	// no event
 | #define EV_NONE	 0	// no event
 | ||||||
| 
 |  | ||||||
| //typedef struct
 |  | ||||||
| //{
 |  | ||||||
| //  byte  actionID;           // Action id
 |  | ||||||
| //  byte  dataSize;           // message size (bytes)
 |  | ||||||
| //  byte  prefixSize;          // prefix size
 |  | ||||||
| //  byte  prefix[6];          // prefix command (const value)
 |  | ||||||
| //  byte  commandSize;         // prefix size
 |  | ||||||
| //  byte  command[4];            // message
 |  | ||||||
| //} AvcInMessageTable;
 |  | ||||||
| 
 | 
 | ||||||
| typedef struct | typedef struct | ||||||
| { | { | ||||||
| 	byte	actionID;           // Action id
 | 	byte	actionID;           // Action id
 | ||||||
| 	byte	dataSize;           // message size (bytes)
 | 	byte	dataSize;           // message size (bytes)
 | ||||||
|   byte  command;         // message
 | 	byte	data[12];           // message
 | ||||||
| } AvcInCmdTable; | } AvcInMessageTable; | ||||||
| 
 | 
 | ||||||
| //typedef struct
 | typedef struct | ||||||
| //{
 | { | ||||||
| //  byte	actionID;           // Action id
 | 	byte	actionID;           // Action id
 | ||||||
| //  byte	dataSize;           // message size (bytes)
 | 	byte	dataSize;           // message size (bytes)
 | ||||||
| //  byte	data[14];           // message
 | 	byte	data[14];           // message
 | ||||||
| //  word	mask;				// mask, set bit = 1 in not checked position (1<<5 or _BV(5) - datap[5] not checked)
 | 	word	mask;				// mask, set bit = 1 in not checked position (1<<5 or _BV(5) - datap[5] not checked)
 | ||||||
| //} AvcInMaskedMessageTable;
 | } AvcInMaskedMessageTable; | ||||||
| 
 | 
 | ||||||
| //typedef struct
 | typedef struct | ||||||
| //{
 | { | ||||||
| //  AvcTransmissionMode broadcast;          // Transmission mode: normal (1) or broadcast (0).
 | 	AvcTransmissionMode broadcast;          // Transmission mode: normal (1) or broadcast (0).
 | ||||||
| //  byte                dataSize;           // message size (bytes)
 |     byte                dataSize;           // message size (bytes)
 | ||||||
| //  byte                data[14];           // message
 |     byte                data[14];           // message
 | ||||||
| //} AvcOutMessage;
 | } AvcOutMessage; | ||||||
| 
 | 
 | ||||||
| #ifndef cbi | #ifndef cbi | ||||||
| #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) | #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) | ||||||
| @ -102,7 +92,7 @@ typedef struct | |||||||
| #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) | #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| class AVCLanDrv { | class AVCLanDrv{ | ||||||
| 	public: | 	public: | ||||||
| 		bool	broadcast; | 		bool	broadcast; | ||||||
| 		word	masterAddress; | 		word	masterAddress; | ||||||
| @ -111,33 +101,31 @@ class AVCLanDrv { | |||||||
| 		word	headAddress; | 		word	headAddress; | ||||||
| 		byte	dataSize; | 		byte	dataSize; | ||||||
| 		byte	message[AVC_MAXMSGLEN]; | 		byte	message[AVC_MAXMSGLEN]; | ||||||
|     //    byte  event;
 | 		byte	event; | ||||||
| 		byte	actionID; | 		byte	actionID; | ||||||
| 		bool	readonly; | 		bool	readonly; | ||||||
| 
 |  | ||||||
| 		void	begin (); | 		void	begin (); | ||||||
| 		byte	readMessage (void); | 		byte	readMessage (void); | ||||||
|     //    byte  sendMessage (void);
 | 		byte	sendMessage (void); | ||||||
|     //    byte  sendMessage (const AvcOutMessage*);
 | 		byte	sendMessage (AvcOutMessage*); | ||||||
| 		void 	printMessage (bool incoming); | 		void 	printMessage (bool incoming); | ||||||
| 		bool	isAvcBusFree (void); | 		bool	isAvcBusFree (void); | ||||||
|     //    byte	getActionID (const AvcInMaskedMessageTable messageTable[], byte mtSize);
 | 		byte	getActionID (AvcInMessageTable messageTable[], byte mtSize); | ||||||
|     //    void  loadMessage (const AvcOutMessage*);
 | 		byte	getActionID (AvcInMaskedMessageTable messageTable[], byte mtSize); | ||||||
|  | 		void	loadMessage (AvcOutMessage*); | ||||||
| 	private: | 	private: | ||||||
| 		bool	_parityBit; | 		bool	_parityBit; | ||||||
| 		word	readBits (byte nbBits); | 		word	readBits (byte nbBits); | ||||||
| 		byte	_readMessage (void); | 		byte	_readMessage (void); | ||||||
|     //    byte  _sendMessage (void);
 | 		byte	_sendMessage (void); | ||||||
|     //    void  sendStartBit (void);
 | 		void	sendStartBit (void); | ||||||
| 		void	send1BitWord (bool data); | 		void	send1BitWord (bool data); | ||||||
|     //    void  send4BitWord (byte data);
 | 		void	send4BitWord (byte data); | ||||||
|     //    void  send8BitWord (byte data);
 | 		void	send8BitWord (byte data); | ||||||
|     //    void  send12BitWord (word data);
 | 		void	send12BitWord (word data); | ||||||
|     //    bool  readAcknowledge (void);
 | 		bool	readAcknowledge (void); | ||||||
|     //    bool  handleAcknowledge (void);
 | 		bool	handleAcknowledge (void); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| extern AVCLanDrv avclan; | extern AVCLanDrv avclan; | ||||||
| #endif | #endif | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|  | |||||||
| @ -1,17 +1,14 @@ | |||||||
| /*
 | /*
 | ||||||
|   BuffSerial.cpp v.01 - serial with transmit buffer library for Wiring |   BuffSerial.cpp - serial with transmit buffer library for Wiring | ||||||
|   Created by Kochetkov Aleksey, 03.07.2009 |   Created by Kochetkov Aleksey, 28.11.2009 | ||||||
|  |   Version 0.1.2 | ||||||
| */ | */ | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
|  | 
 | ||||||
| #include "BuffSerial.h" | #include "BuffSerial.h" | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| 
 | 
 | ||||||
| // serial init
 | // serial init
 | ||||||
| //--------------------------------------------------------------------------------
 | void BuffSerial::begin(long speed){ | ||||||
| void BuffSerial::begin(long speed) |  | ||||||
| { |  | ||||||
|   //--------------------------------------------------------------------------------
 |  | ||||||
| #if defined(__AVR_ATmega8__) | #if defined(__AVR_ATmega8__) | ||||||
| 	UCSRB = _BV(RXCIE) | _BV(RXEN) | _BV(TXCIE) | _BV(TXEN);   // enable rx, tx inerrputs
 | 	UCSRB = _BV(RXCIE) | _BV(RXEN) | _BV(TXCIE) | _BV(TXEN);   // enable rx, tx inerrputs
 | ||||||
| 	UBRRH = ((F_CPU / 16 + speed / 2) / speed - 1) >> 8;       // usart speed
 | 	UBRRH = ((F_CPU / 16 + speed / 2) / speed - 1) >> 8;       // usart speed
 | ||||||
| @ -26,7 +23,6 @@ void BuffSerial::begin(long speed) | |||||||
| 	txFull  = 0; | 	txFull  = 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| //USART Rx Complete
 | //USART Rx Complete
 | ||||||
| #if defined(__AVR_ATmega8__) | #if defined(__AVR_ATmega8__) | ||||||
| SIGNAL(SIG_UART_RECV) | SIGNAL(SIG_UART_RECV) | ||||||
| @ -41,9 +37,7 @@ SIGNAL(USART_RX_vect) | |||||||
| #endif | #endif | ||||||
| 	if (bSerial.rxEnd < RX_BUFF_SIZE) bSerial.rxEnd++; | 	if (bSerial.rxEnd < RX_BUFF_SIZE) bSerial.rxEnd++; | ||||||
| } | } | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| 
 | 
 | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| //USART Tx Complete
 | //USART Tx Complete
 | ||||||
| #if defined(__AVR_ATmega8__) | #if defined(__AVR_ATmega8__) | ||||||
| SIGNAL(SIG_UART_TRANS) | SIGNAL(SIG_UART_TRANS) | ||||||
| @ -51,7 +45,7 @@ SIGNAL(SIG_UART_TRANS) | |||||||
| SIGNAL(USART_TX_vect) | SIGNAL(USART_TX_vect) | ||||||
| #endif | #endif | ||||||
| { | { | ||||||
|   if (bSerial.txEnd != bSerial.txBegin || bSerial.txFull != 0) { | 	if (bSerial.txEnd != bSerial.txBegin || bSerial.txFull != 0){ | ||||||
| #if defined(__AVR_ATmega8__) | #if defined(__AVR_ATmega8__) | ||||||
| 		UDR  = bSerial.txBuffer[bSerial.txBegin];  // Send buffer
 | 		UDR  = bSerial.txBuffer[bSerial.txBegin];  // Send buffer
 | ||||||
| #else | #else | ||||||
| @ -63,28 +57,24 @@ SIGNAL(USART_TX_vect) | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| 
 | 
 | ||||||
| // send byte to serial or buffer if bisy
 | // send byte to serial or buffer if bisy
 | ||||||
| //--------------------------------------------------------------------------------
 | void BuffSerial::sendByte(uint8_t data){ | ||||||
| void BuffSerial::sendByte(uint8_t data) | 	if (txFull){ | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
|   if (txFull) { |  | ||||||
| 		txOverflow++; | 		txOverflow++; | ||||||
|   } else { | 	}else{ | ||||||
| 		uint8_t oldSREG = SREG; | 		uint8_t oldSREG = SREG; | ||||||
| 		cli(); | 		cli(); | ||||||
| #if defined(__AVR_ATmega8__) | #if defined(__AVR_ATmega8__) | ||||||
|     if (txEnd != txBegin || (UCSRA & _BV(UDRE)) == 0) { | 		if (txEnd != txBegin || (UCSRA & _BV(UDRE)) == 0){ | ||||||
| #else | #else | ||||||
|     if (txEnd != txBegin || (UCSR0A & _BV(UDRE0)) == 0) { | 		if (txEnd != txBegin || (UCSR0A & _BV(UDRE0)) == 0){ | ||||||
| #endif | #endif | ||||||
| 			txBuffer[txEnd] = data; | 			txBuffer[txEnd] = data; | ||||||
| 			txEnd++; | 			txEnd++; | ||||||
| 			if (txEnd == TX_BUFF_SIZE) txEnd = 0; | 			if (txEnd == TX_BUFF_SIZE) txEnd = 0; | ||||||
| 			if (txEnd == txBegin) txFull = 1;          // buffer overflow
 | 			if (txEnd == txBegin) txFull = 1;          // buffer overflow
 | ||||||
|     } else { | 		}else{ | ||||||
| #if defined(__AVR_ATmega8__) | #if defined(__AVR_ATmega8__) | ||||||
| 			UDR  = data; | 			UDR  = data; | ||||||
| #else | #else | ||||||
| @ -96,74 +86,63 @@ void BuffSerial::sendByte(uint8_t data) | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // print string
 | // print string
 | ||||||
| //--------------------------------------------------------------------------------
 | void BuffSerial::print(const char *pBuf){ | ||||||
| void BuffSerial::print(const char *pBuf) |  | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
| 	while (*pBuf)	{ | 	while (*pBuf)	{ | ||||||
| 		sendByte(*pBuf++); | 		sendByte(*pBuf++); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //--------------------------------------------------------------------------------
 | void BuffSerial::print(const char pBuf){ | ||||||
| void BuffSerial::print(const char pBuf) |  | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
| 	sendByte(pBuf); | 	sendByte(pBuf); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //--------------------------------------------------------------------------------
 | // print string from flash
 | ||||||
| void BuffSerial::println(const char *pBuf) | void BuffSerial::print_p(const char *pBuf){ | ||||||
| //--------------------------------------------------------------------------------
 | 	char c; | ||||||
| { | 	while ((c = pgm_read_byte_near( pBuf++ )))	{ | ||||||
|  | 		sendByte(c); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void BuffSerial::println(const char *pBuf){ | ||||||
| 	print(pBuf); | 	print(pBuf); | ||||||
| 	println(); | 	println(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //--------------------------------------------------------------------------------
 | void BuffSerial::println(const char pBuf){ | ||||||
| void BuffSerial::println(const char pBuf) |  | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
| 	print(pBuf); | 	print(pBuf); | ||||||
| 	println(); | 	println(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //--------------------------------------------------------------------------------
 | void BuffSerial::println(void){ | ||||||
| void BuffSerial::println(void) |  | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
| 	print("\r\n"); | 	print("\r\n"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //--------------------------------------------------------------------------------
 | void BuffSerial::println_p(const char *pBuf){ | ||||||
| void BuffSerial::printHex4(uint8_t data) | 	print_p(pBuf); | ||||||
| //--------------------------------------------------------------------------------
 | 	println(); | ||||||
| { | } | ||||||
|  | 
 | ||||||
|  | void BuffSerial::printHex4(uint8_t data){ | ||||||
| 	uint8_t c = data & 0x0f; | 	uint8_t c = data & 0x0f; | ||||||
| 	c += c < 10 ? '0' : 'A' - 10 ; | 	c += c < 10 ? '0' : 'A' - 10 ; | ||||||
| 	sendByte(c); | 	sendByte(c); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //--------------------------------------------------------------------------------
 | void BuffSerial::printHex8(uint8_t data){ | ||||||
| void BuffSerial::printHex8(uint8_t data) |  | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
|     printHex4(data >> 4); |     printHex4(data >> 4); | ||||||
|     printHex4(data); |     printHex4(data); | ||||||
| }  | }  | ||||||
| 
 | 
 | ||||||
| //--------------------------------------------------------------------------------
 | void BuffSerial::printDec(uint8_t data){ | ||||||
| void BuffSerial::printDec(uint8_t data) |  | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
| 	uint8_t buf[3];  | 	uint8_t buf[3];  | ||||||
| 	uint8_t i = 0; | 	uint8_t i = 0; | ||||||
|   if (data == 0) { | 	if (data == 0){ | ||||||
| 		sendByte('0'); | 		sendByte('0'); | ||||||
| 		return; | 		return; | ||||||
| 	}  | 	}  | ||||||
| 
 | 
 | ||||||
|   while (data > 0) { | 	while (data > 0){ | ||||||
| 		buf[i++] = data % 10; | 		buf[i++] = data % 10; | ||||||
| 		data /= 10; | 		data /= 10; | ||||||
| 	} | 	} | ||||||
| @ -172,17 +151,11 @@ void BuffSerial::printDec(uint8_t data) | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // check rx buffer not empty
 | // check rx buffer not empty
 | ||||||
| //--------------------------------------------------------------------------------
 | bool BuffSerial::rxEnabled(void){   | ||||||
| bool BuffSerial::rxEnabled(void) |  | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
| 	return rxEnd; | 	return rxEnd; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //--------------------------------------------------------------------------------
 | uint8_t BuffSerial::rxRead(void){ | ||||||
| uint8_t BuffSerial::rxRead(void) |  | ||||||
| //--------------------------------------------------------------------------------
 |  | ||||||
| { |  | ||||||
| #if defined(__AVR_ATmega8__) | #if defined(__AVR_ATmega8__) | ||||||
| 	cbi(UCSRB, RXCIE);                           // disable RX complete interrupt
 | 	cbi(UCSRB, RXCIE);                           // disable RX complete interrupt
 | ||||||
| #else | #else | ||||||
|  | |||||||
| @ -1,7 +1,9 @@ | |||||||
| /*
 | /*
 | ||||||
|   BuffSerial.h v.01 - serial with transmit buffer library for Wiring |   BuffSerial.h - serial with transmit buffer library for Wiring | ||||||
|   Created by Kochetkov Aleksey, 03.07.2009 |   Created by Kochetkov Aleksey, 28.11.2009 | ||||||
|  |   Version 0.1.2 | ||||||
| */ | */ | ||||||
|  | #include <avr/pgmspace.h> | ||||||
| 
 | 
 | ||||||
| #ifndef BuffSerial_h | #ifndef BuffSerial_h | ||||||
| #define BuffSerial_h | #define BuffSerial_h | ||||||
| @ -11,6 +13,7 @@ | |||||||
| #define TX_BUFF_SIZE		240               // max 65535 
 | #define TX_BUFF_SIZE		240               // max 65535 
 | ||||||
| #define RX_BUFF_SIZE		25                // max 255
 | #define RX_BUFF_SIZE		25                // max 255
 | ||||||
| #define TX_BUFF_MAX_LEN		TX_BUFF_SIZE - 1 | #define TX_BUFF_MAX_LEN		TX_BUFF_SIZE - 1 | ||||||
|  | #define BUFFSERIAL_VERSION "0.1.2" | ||||||
| 
 | 
 | ||||||
| #ifndef cbi | #ifndef cbi | ||||||
| #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) | #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) | ||||||
| @ -19,7 +22,7 @@ | |||||||
| #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) | #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| class BuffSerial { | class BuffSerial{ | ||||||
| 	public: | 	public: | ||||||
| 		uint8_t		rxBuffer[RX_BUFF_SIZE]; | 		uint8_t		rxBuffer[RX_BUFF_SIZE]; | ||||||
| 		uint8_t		rxBegin; | 		uint8_t		rxBegin; | ||||||
| @ -33,9 +36,11 @@ class BuffSerial { | |||||||
| 		void 		sendByte(uint8_t); | 		void 		sendByte(uint8_t); | ||||||
| 		void		print(const char*); | 		void		print(const char*); | ||||||
| 		void		print(const char); | 		void		print(const char); | ||||||
|  | 		void		print_p(const char*); | ||||||
| 		void		println(const char*); | 		void		println(const char*); | ||||||
| 		void		println(const char); | 		void		println(const char); | ||||||
| 		void		println(void); | 		void		println(void); | ||||||
|  | 		void		println_p(const char*); | ||||||
| 		void		printHex4(uint8_t); | 		void		printHex4(uint8_t); | ||||||
| 		void		printHex8(uint8_t); | 		void		printHex8(uint8_t); | ||||||
| 		void		printDec(uint8_t); | 		void		printDec(uint8_t); | ||||||
|  | |||||||
							
								
								
									
										1711
									
								
								logs/teraterm_parse.log
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1711
									
								
								logs/teraterm_parse.log
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user