1
0
mirror of https://github.com/Oleg-Stepanenko-owo/IEBUS synced 2025-06-21 06:46:20 +00:00

update loger code style

This commit is contained in:
Oleg Stepanenko 2016-03-15 17:36:46 +02:00
parent d9e0f0bd9d
commit 264dc36198

View File

@ -2,12 +2,16 @@
BuffSerial.cpp v.01 - serial with transmit buffer library for Wiring BuffSerial.cpp v.01 - serial with transmit buffer library for Wiring
Created by Kochetkov Aleksey, 03.07.2009 Created by Kochetkov Aleksey, 03.07.2009
*/ */
//--------------------------------------------------------------------------------
#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
@ -22,6 +26,7 @@ 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)
@ -36,7 +41,9 @@ 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)
@ -56,9 +63,13 @@ 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 {
@ -85,43 +96,66 @@ 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);
} }
//--------------------------------------------------------------------------------
void BuffSerial::println(const char *pBuf) { 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::printHex4(uint8_t data) { //--------------------------------------------------------------------------------
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) {
@ -138,11 +172,17 @@ 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