mirror of
https://github.com/Oleg-Stepanenko-owo/IEBUS
synced 2025-06-28 10:16:13 +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
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,7 @@
|
|||||||
#define INPUT_IS_CLEAR (!(ACSR & _BV(ACO)))
|
#define INPUT_IS_CLEAR (!(ACSR & _BV(ACO)))
|
||||||
#define OUTPUT_SET_1 sbi(PORTD, DATAOUT);
|
#define OUTPUT_SET_1 sbi(PORTD, DATAOUT);
|
||||||
#define OUTPUT_SET_0 cbi(PORTD, DATAOUT);
|
#define OUTPUT_SET_0 cbi(PORTD, DATAOUT);
|
||||||
#define AVC_OUT_EN sbi(PORTD, DATAOUT); sbi(DDRD, DATAOUT); sbi(DDRD, DATAIN); sbi(ACSR, ACD);
|
#define AVC_OUT_EN sbi(PORTD, DATAOUT); sbi(DDRD, DATAOUT); sbi(DDRD, DATAIN); sbi(ACSR, ACD);
|
||||||
#define AVC_OUT_DIS cbi(PORTD, DATAOUT); cbi(DDRD, DATAOUT); cbi(DDRD, DATAIN); cbi(ACSR, ACD);
|
#define AVC_OUT_DIS cbi(PORTD, DATAOUT); cbi(DDRD, DATAOUT); cbi(DDRD, DATAIN); cbi(ACSR, ACD);
|
||||||
#else
|
#else
|
||||||
#ifdef AVCLAN_ST485
|
#ifdef AVCLAN_ST485
|
||||||
@ -28,7 +28,7 @@
|
|||||||
#define INPUT_IS_CLEAR (bit_is_set(DATAIN_PIN, DATAIN))
|
#define INPUT_IS_CLEAR (bit_is_set(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 (sbi(OUTEN_PORT, OUTEN));;
|
#define AVC_OUT_EN (sbi(OUTEN_PORT, OUTEN));;
|
||||||
#define AVC_OUT_DIS (cbi(OUTEN_PORT, OUTEN));;
|
#define AVC_OUT_DIS (cbi(OUTEN_PORT, OUTEN));;
|
||||||
#else
|
#else
|
||||||
//avclan driver on PCA82C250 & LM239N
|
//avclan driver on PCA82C250 & LM239N
|
||||||
@ -36,64 +36,54 @@
|
|||||||
#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
|
||||||
|
|
||||||
#define AVC_NORMAL_BIT_LENGTH 0x4A // 37 * (F_CPU / 1000000L / 8)
|
#define AVC_NORMAL_BIT_LENGTH 0x4A // 37 * (F_CPU / 1000000L / 8)
|
||||||
#define AVC_BIT_1_HOLD_ON_LENGTH 0x28 // 20 uS * (F_CPU / 1000000L / 8)
|
#define AVC_BIT_1_HOLD_ON_LENGTH 0x28 // 20 uS * (F_CPU / 1000000L / 8)
|
||||||
#define AVC_BIT_0_HOLD_ON_LENGTH 0x40 // 32 uS * (F_CPU / 1000000L / 8)
|
#define AVC_BIT_0_HOLD_ON_LENGTH 0x40 // 32 uS * (F_CPU / 1000000L / 8)
|
||||||
//#define AVC_BIT_0_HOLD_ON_MIN_LENGTH 0x34 // 26 uS * (F_CPU / 1000000L / 8) Compare half way between a '1' (20 us) and a '0' (32 us ): 32 - (32 - 20) /2 = 26 us
|
//#define AVC_BIT_0_HOLD_ON_MIN_LENGTH 0x34 // 26 uS * (F_CPU / 1000000L / 8) Compare half way between a '1' (20 us) and a '0' (32 us ): 32 - (32 - 20) /2 = 26 us
|
||||||
#define AVC_BIT_0_HOLD_ON_MIN_LENGTH 0x3C // 30 uS * (F_CPU / 1000000L / 8) Compare half way between a '1' (20 us) and a '0' (32 us ): 32 - (32 - 20) /2 = 26 us
|
#define AVC_BIT_0_HOLD_ON_MIN_LENGTH 0x3C // 30 uS * (F_CPU / 1000000L / 8) Compare half way between a '1' (20 us) and a '0' (32 us ): 32 - (32 - 20) /2 = 26 us
|
||||||
#define AVC_START_BIT_LENGTH 0x5D // 186 uS * (F_CPU / 1000000L / 32) , prescaler 32
|
#define AVC_START_BIT_LENGTH 0x5D // 186 uS * (F_CPU / 1000000L / 32) , prescaler 32
|
||||||
#define AVC_START_BIT_HOLD_ON_LENGTH 0x54 // 168 uS * (F_CPU / 1000000L / 32) prescaler 32
|
#define AVC_START_BIT_HOLD_ON_LENGTH 0x54 // 168 uS * (F_CPU / 1000000L / 32) prescaler 32
|
||||||
#define AVC_START_BIT_HOLD_ON_MIN_LENGTH 0x16 // 44 uS * (F_CPU / 1000000L / 32) grater that AVC_NORMAL_BIT_LENGTH, prescaler 32
|
#define AVC_START_BIT_HOLD_ON_MIN_LENGTH 0x16 // 44 uS * (F_CPU / 1000000L / 32) grater that AVC_NORMAL_BIT_LENGTH, prescaler 32
|
||||||
#define AVC_1U_LENGTH 0x02 // 1 uS * (F_CPU / 1000000L / 8)
|
#define AVC_1U_LENGTH 0x02 // 1 uS * (F_CPU / 1000000L / 8)
|
||||||
|
|
||||||
#define AVC_MAXMSGLEN 32
|
#define AVC_MAXMSGLEN 32
|
||||||
#define AVC_CONTROL_FLAGS 0xF
|
#define AVC_CONTROL_FLAGS 0xF
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{ // No this is not a mistake, broadcast = 0!
|
{ // No this is not a mistake, broadcast = 0!
|
||||||
AVC_MSG_DIRECT = 1,
|
AVC_MSG_DIRECT = 1,
|
||||||
AVC_MSG_BROADCAST = 0
|
AVC_MSG_BROADCAST = 0
|
||||||
} 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,42 +92,40 @@ 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;
|
||||||
word slaveAddress;
|
word slaveAddress;
|
||||||
word deviceAddress;
|
word deviceAddress;
|
||||||
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 (AvcOutMessage*);
|
||||||
// byte sendMessage (const AvcOutMessage*);
|
void printMessage (bool incoming);
|
||||||
void printMessage (bool incoming);
|
bool isAvcBusFree (void);
|
||||||
bool isAvcBusFree (void);
|
byte getActionID (AvcInMessageTable messageTable[], byte mtSize);
|
||||||
// byte getActionID (const AvcInMaskedMessageTable messageTable[], byte mtSize);
|
byte getActionID (AvcInMaskedMessageTable messageTable[], byte mtSize);
|
||||||
// void loadMessage (const AvcOutMessage*);
|
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,32 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
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
|
||||||
UBRRL = ((F_CPU / 16 + speed / 2) / speed - 1);
|
UBRRL = ((F_CPU / 16 + speed / 2) / speed - 1);
|
||||||
#else
|
#else
|
||||||
UCSR0B = (_BV(RXCIE0) | _BV(RXEN0) | _BV(TXCIE0) | _BV(TXEN0)); // enable rx, tx inerrputs
|
UCSR0B = (_BV(RXCIE0) | _BV(RXEN0) | _BV(TXCIE0) | _BV(TXEN0)); // enable rx, tx inerrputs
|
||||||
UBRR0H = ((F_CPU / 16 + speed / 2) / speed - 1) >> 8; // usart speed
|
UBRR0H = ((F_CPU / 16 + speed / 2) / speed - 1) >> 8; // usart speed
|
||||||
UBRR0L = ((F_CPU / 16 + speed / 2) / speed - 1);
|
UBRR0L = ((F_CPU / 16 + speed / 2) / speed - 1);
|
||||||
#endif
|
#endif
|
||||||
rxBegin = rxEnd = 0;
|
rxBegin = rxEnd = 0;
|
||||||
txBegin = txEnd = txOverflow = 0;
|
txBegin = txEnd = txOverflow = 0;
|
||||||
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)
|
||||||
@ -35,15 +31,13 @@ SIGNAL(USART_RX_vect)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if defined(__AVR_ATmega8__)
|
#if defined(__AVR_ATmega8__)
|
||||||
bSerial.rxBuffer[bSerial.rxEnd] = UDR;
|
bSerial.rxBuffer[bSerial.rxEnd] = UDR;
|
||||||
#else
|
#else
|
||||||
bSerial.rxBuffer[bSerial.rxEnd] = UDR0;
|
bSerial.rxBuffer[bSerial.rxEnd] = UDR0;
|
||||||
#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,153 +45,132 @@ 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
|
||||||
UDR0 = bSerial.txBuffer[bSerial.txBegin]; // Send buffer
|
UDR0 = bSerial.txBuffer[bSerial.txBegin]; // Send buffer
|
||||||
#endif
|
#endif
|
||||||
bSerial.txFull = 0;
|
bSerial.txFull = 0;
|
||||||
bSerial.txBegin++;
|
bSerial.txBegin++;
|
||||||
if (bSerial.txBegin == TX_BUFF_SIZE) bSerial.txBegin = 0;
|
if (bSerial.txBegin == TX_BUFF_SIZE) bSerial.txBegin = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// 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){
|
||||||
//--------------------------------------------------------------------------------
|
txOverflow++;
|
||||||
{
|
}else{
|
||||||
if (txFull) {
|
uint8_t oldSREG = SREG;
|
||||||
txOverflow++;
|
cli();
|
||||||
} else {
|
|
||||||
uint8_t oldSREG = SREG;
|
|
||||||
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
|
||||||
UDR0 = data;
|
UDR0 = data;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
SREG = oldSREG;
|
SREG = oldSREG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// print string
|
// print string
|
||||||
//--------------------------------------------------------------------------------
|
void BuffSerial::print(const char *pBuf){
|
||||||
void BuffSerial::print(const char *pBuf)
|
while (*pBuf) {
|
||||||
//--------------------------------------------------------------------------------
|
sendByte(*pBuf++);
|
||||||
{
|
}
|
||||||
while (*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++ ))) {
|
||||||
print(pBuf);
|
sendByte(c);
|
||||||
println();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
void BuffSerial::println(const char *pBuf){
|
||||||
void BuffSerial::println(const char pBuf)
|
print(pBuf);
|
||||||
//--------------------------------------------------------------------------------
|
println();
|
||||||
{
|
|
||||||
print(pBuf);
|
|
||||||
println();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
void BuffSerial::println(const char pBuf){
|
||||||
void BuffSerial::println(void)
|
print(pBuf);
|
||||||
//--------------------------------------------------------------------------------
|
println();
|
||||||
{
|
|
||||||
print("\r\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
void BuffSerial::println(void){
|
||||||
void BuffSerial::printHex4(uint8_t data)
|
print("\r\n");
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
{
|
|
||||||
uint8_t c = data & 0x0f;
|
|
||||||
c += c < 10 ? '0' : 'A' - 10 ;
|
|
||||||
sendByte(c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
void BuffSerial::println_p(const char *pBuf){
|
||||||
void BuffSerial::printHex8(uint8_t data)
|
print_p(pBuf);
|
||||||
//--------------------------------------------------------------------------------
|
println();
|
||||||
{
|
|
||||||
printHex4(data >> 4);
|
|
||||||
printHex4(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
void BuffSerial::printHex4(uint8_t data){
|
||||||
void BuffSerial::printDec(uint8_t data)
|
uint8_t c = data & 0x0f;
|
||||||
//--------------------------------------------------------------------------------
|
c += c < 10 ? '0' : 'A' - 10 ;
|
||||||
{
|
sendByte(c);
|
||||||
uint8_t buf[3];
|
}
|
||||||
uint8_t i = 0;
|
|
||||||
if (data == 0) {
|
|
||||||
sendByte('0');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (data > 0) {
|
void BuffSerial::printHex8(uint8_t data){
|
||||||
buf[i++] = data % 10;
|
printHex4(data >> 4);
|
||||||
data /= 10;
|
printHex4(data);
|
||||||
}
|
}
|
||||||
for (; i > 0; i--)
|
|
||||||
sendByte((buf[i - 1] < 10 ? '0' + buf[i - 1] : 'A' + buf[i - 1] - 10));
|
void BuffSerial::printDec(uint8_t data){
|
||||||
|
uint8_t buf[3];
|
||||||
|
uint8_t i = 0;
|
||||||
|
if (data == 0){
|
||||||
|
sendByte('0');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (data > 0){
|
||||||
|
buf[i++] = data % 10;
|
||||||
|
data /= 10;
|
||||||
|
}
|
||||||
|
for (; i > 0; i--)
|
||||||
|
sendByte((buf[i - 1] < 10 ? '0' + buf[i - 1] : 'A' + buf[i - 1] - 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
cbi(UCSR0B, RXCIE0); // disable RX complete interrupt
|
cbi(UCSR0B, RXCIE0); // disable RX complete interrupt
|
||||||
#endif
|
#endif
|
||||||
uint8_t readkey = rxBuffer[rxBegin]; // read begin of received Buffer
|
uint8_t readkey = rxBuffer[rxBegin]; // read begin of received Buffer
|
||||||
rxBegin++;
|
rxBegin++;
|
||||||
if (rxBegin == rxEnd) rxBegin = rxEnd = 0; // if Buffer is empty reset Buffer
|
if (rxBegin == rxEnd) rxBegin = rxEnd = 0; // if Buffer is empty reset Buffer
|
||||||
#if defined(__AVR_ATmega8__)
|
#if defined(__AVR_ATmega8__)
|
||||||
sbi(UCSRB, RXCIE); // enable RX complete interrupt
|
sbi(UCSRB, RXCIE); // enable RX complete interrupt
|
||||||
#else
|
#else
|
||||||
sbi(UCSR0B, RXCIE0); // enable RX complete interrupt
|
sbi(UCSR0B, RXCIE0); // enable RX complete interrupt
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return readkey;
|
return readkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
BuffSerial bSerial;
|
BuffSerial bSerial;
|
||||||
|
@ -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,28 +22,30 @@
|
|||||||
#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;
|
||||||
uint8_t rxEnd;
|
uint8_t rxEnd;
|
||||||
uint8_t txBuffer[TX_BUFF_SIZE];
|
uint8_t txBuffer[TX_BUFF_SIZE];
|
||||||
uint16_t txBegin;
|
uint16_t txBegin;
|
||||||
uint16_t txEnd;
|
uint16_t txEnd;
|
||||||
uint8_t txFull;
|
uint8_t txFull;
|
||||||
uint16_t txOverflow;
|
uint16_t txOverflow;
|
||||||
void begin(long);
|
void begin(long);
|
||||||
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 println(const char*);
|
void print_p(const char*);
|
||||||
void println(const char);
|
void println(const char*);
|
||||||
void println(void);
|
void println(const char);
|
||||||
void printHex4(uint8_t);
|
void println(void);
|
||||||
void printHex8(uint8_t);
|
void println_p(const char*);
|
||||||
void printDec(uint8_t);
|
void printHex4(uint8_t);
|
||||||
bool rxEnabled(void);
|
void printHex8(uint8_t);
|
||||||
uint8_t rxRead(void);
|
void printDec(uint8_t);
|
||||||
|
bool rxEnabled(void);
|
||||||
|
uint8_t rxRead(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern BuffSerial bSerial;
|
extern BuffSerial bSerial;
|
||||||
|
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