debugging macro fixes

This commit is contained in:
Andrew J. Kroll 2013-05-16 16:43:51 -04:00
parent 387a4ab5f4
commit 814c2baf55
17 changed files with 208 additions and 64 deletions

29
BTD.cpp
View file

@ -16,7 +16,7 @@
*/
#include "BTD.h"
#define DEBUG // Uncomment to print data for debugging
// #define DEBUG // Uncomment to print data for debugging -- NO! see message.h
//#define EXTRADEBUG // Uncomment to get even more debugging data
const uint8_t BTD::BTD_CONTROL_PIPE = 0;
@ -217,30 +217,40 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
/* diagnostic messages */
FailGetDevDescr:
#ifdef DEBUG
NotifyFailGetDevDescr();
goto Fail;
#endif
FailSetDevTblEntry:
#ifdef DEBUG
NotifyFailSetDevTblEntry();
goto Fail;
#endif
FailGetConfDescr:
#ifdef DEBUG
NotifyFailGetConfDescr();
goto Fail;
#endif
FailSetConfDescr:
#ifdef DEBUG
NotifyFailSetConfDescr();
#endif
goto Fail;
FailUnknownDevice:
NotifyFailUnknownDevice(VID,PID);
#ifdef DEBUG
NotifyFailUnknownDevice(VID, PID);
#endif
pUsb->setAddr(bAddress, 0, 0); // Reset address
rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
Fail:
#ifdef DEBUG
Notify(PSTR("\r\nBTD Init Failed, error code: "), 0x80);
#endif
NotifyFail(rcode);
#endif
Release();
return rcode;
}
@ -302,7 +312,7 @@ uint8_t BTD::Release() {
if (btService[i])
btService[i]->Reset(); // Reset all Bluetooth services
}
pUsb->GetAddressPool().FreeAddress(bAddress);
bAddress = 0;
bPollEnable = false;
@ -427,7 +437,7 @@ void BTD::HCI_event_task() {
case EV_REMOTE_NAME_COMPLETE:
if (!hcibuf[2]) { // check if reading is OK
for (uint8_t i = 0; i < min(sizeof(remote_name),sizeof(hcibuf)-9); i++)
for (uint8_t i = 0; i < min(sizeof (remote_name), sizeof (hcibuf) - 9); i++)
remote_name[i] = hcibuf[9 + i];
hci_event_flag |= HCI_FLAG_REMOTE_NAME_COMPLETE;
}
@ -941,15 +951,14 @@ void BTD::hci_pin_code_request_reply() {
hcibuf[8] = disc_bdaddr[5];
if (pairWithWii) {
hcibuf[9] = 6; // Pin length is the length of the Bluetooth address
if(wiiUProController) {
if (wiiUProController) {
#ifdef DEBUG
Notify(PSTR("\r\nParing with Wii U Pro Controller"), 0x80);
#endif
for(uint8_t i = 0; i < 6; i++)
for (uint8_t i = 0; i < 6; i++)
hcibuf[10 + i] = my_bdaddr[i]; // The pin is the Bluetooth dongles Bluetooth address backwards
}
else {
for(uint8_t i = 0; i < 6; i++)
} else {
for (uint8_t i = 0; i < 6; i++)
hcibuf[10 + i] = disc_bdaddr[i]; // The pin is the Wiimote's Bluetooth address backwards
}
for (uint8_t i = 16; i < 26; i++)

View file

@ -16,7 +16,7 @@
*/
#include "PS3USB.h"
#define DEBUG // Uncomment to print data for debugging
//#define DEBUG // Uncomment to print data for debugging -- NO! see message.h
//#define EXTRADEBUG // Uncomment to get even more debugging data
//#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers
@ -221,25 +221,32 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
/* diagnostic messages */
FailGetDevDescr:
#ifdef DEBUG
NotifyFailGetDevDescr();
goto Fail;
#endif
FailSetDevTblEntry:
#ifdef DEBUG
NotifyFailSetDevTblEntry();
goto Fail;
#endif
FailSetConfDescr:
#ifdef DEBUG
NotifyFailSetConfDescr();
#endif
goto Fail;
FailUnknownDevice:
NotifyFailUnknownDevice(VID,PID);
#ifdef DEBUG
NotifyFailUnknownDevice(VID, PID);
#endif
rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
Fail:
Fail:
#ifdef DEBUG
Notify(PSTR("\r\nPS3 Init Failed, error code: "), 0x80);
#endif
NotifyFail(rcode);
#endif
Release();
return rcode;
}
@ -427,7 +434,7 @@ void PS3USB::setRumbleOff() {
void PS3USB::setRumbleOn(Rumble mode) {
if ((mode & 0x30) > 0x00) {
uint8_t power[2] = { 0xff, 0x00 }; // Defaults to RumbleLow
uint8_t power[2] = {0xff, 0x00}; // Defaults to RumbleLow
if (mode == RumbleHigh) {
power[0] = 0x00;
power[1] = 0xff;
@ -448,14 +455,17 @@ void PS3USB::setLedRaw(uint8_t value) {
writeBuf[9] = value;
PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
}
void PS3USB::setLedOff(LED a) {
writeBuf[9] &= ~((uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1));
PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
}
void PS3USB::setLedOn(LED a) {
writeBuf[9] |= (uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1);
PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
}
void PS3USB::setLedToggle(LED a) {
writeBuf[9] ^= (uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1);
PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);

View file

@ -18,7 +18,7 @@
*/
#include "XBOXRECV.h"
#define DEBUG // Uncomment to print data for debugging
//#define DEBUG // Uncomment to print data for debugging -- NO! see message.h
//#define EXTRADEBUG // Uncomment to get even more debugging data
//#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller
@ -120,8 +120,8 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) {
bAddress = 0;
#ifdef DEBUG
Notify(PSTR("\r\nsetAddr: "), 0x80);
#endif
PrintHex<uint8_t > (rcode, 0x80);
#endif
return rcode;
}
#ifdef EXTRADEBUG
@ -218,26 +218,34 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) {
/* diagnostic messages */
FailGetDevDescr:
#ifdef DEBUG
NotifyFailGetDevDescr();
goto Fail;
#endif
FailSetDevTblEntry:
#ifdef DEBUG
NotifyFailSetDevTblEntry();
goto Fail;
#endif
FailSetConfDescr:
#ifdef DEBUG
NotifyFailSetConfDescr();
#endif
goto Fail;
FailUnknownDevice:
#ifdef DEBUG
NotifyFailUnknownDevice(VID,PID);
#endif
rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
Fail:
#ifdef DEBUG
Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80);
#endif
NotifyFail(rcode);
#endif
Release();
return rcode;
}

View file

@ -16,7 +16,7 @@
*/
#include "XBOXUSB.h"
#define DEBUG // Uncomment to print data for debugging
//#define DEBUG // Uncomment to print data for debugging -- NO! see message.h
//#define EXTRADEBUG // Uncomment to get even more debugging data
//#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller
@ -183,25 +183,33 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
/* diagnostic messages */
FailGetDevDescr:
#ifdef DEBUG
NotifyFailGetDevDescr();
goto Fail;
#endif
FailSetDevTblEntry:
#ifdef DEBUG
NotifyFailSetDevTblEntry();
goto Fail;
#endif
FailSetConfDescr:
#ifdef DEBUG
NotifyFailSetConfDescr();
goto Fail;
#endif
FailUnknownDevice:
NotifyFailUnknownDevice(VID,PID);
#ifdef DEBUG
NotifyFailUnknownDevice(VID, PID);
#endif
rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
Fail:
#ifdef DEBUG
Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80);
#endif
NotifyFail(rcode);
#endif
Release();
return rcode;
}

16
adk.cpp
View file

@ -227,33 +227,45 @@ uint8_t ADK::Init(uint8_t parent, uint8_t port, bool lowspeed) {
/* diagnostic messages */
FailGetDevDescr:
#ifdef DEBUG
NotifyFailGetDevDescr();
goto Fail;
#endif
FailSetDevTblEntry:
#ifdef DEBUG
NotifyFailSetDevTblEntry();
goto Fail;
#endif
FailGetConfDescr:
#ifdef DEBUG
NotifyFailGetConfDescr();
goto Fail;
#endif
FailSetConfDescr:
#ifdef DEBUG
NotifyFailSetConfDescr();
goto Fail;
#endif
FailGetProto:
#ifdef DEBUG
USBTRACE("\r\ngetProto:");
goto Fail;
#endif
FailSwAcc:
#ifdef DEBUG
USBTRACE("\r\nswAcc:");
goto Fail;
#endif
SwAttempt:
#ifdef DEBUG
USBTRACE("\r\nAccessory mode switch attempt");
// goto Fail;
#endif
//FailOnInit:
// USBTRACE("OnInit:");
// goto Fail;

View file

@ -174,7 +174,7 @@ uint8_t ACM::Init(uint8_t parent, uint8_t port, bool lowspeed) {
goto FailOnInit;
USBTRACE("ACM configured\r\n");
ready = true;
//bPollEnable = true;
@ -183,26 +183,38 @@ uint8_t ACM::Init(uint8_t parent, uint8_t port, bool lowspeed) {
return 0;
FailGetDevDescr:
#ifdef DEBUG
NotifyFailGetDevDescr();
goto Fail;
#endif
FailSetDevTblEntry:
#ifdef DEBUG
NotifyFailSetDevTblEntry();
goto Fail;
#endif
FailGetConfDescr:
#ifdef DEBUG
NotifyFailGetConfDescr();
goto Fail;
#endif
FailSetConfDescr:
#ifdef DEBUG
NotifyFailSetConfDescr();
goto Fail;
#endif
FailOnInit:
#ifdef DEBUG
USBTRACE("OnInit:");
#endif
Fail:
#ifdef DEBUG
NotifyFail(rcode);
#endif
Release();
return rcode;
}

View file

@ -178,26 +178,38 @@ uint8_t FTDI::Init(uint8_t parent, uint8_t port, bool lowspeed) {
return 0;
FailGetDevDescr:
#ifdef DEBUG
NotifyFailGetDevDescr();
goto Fail;
#endif
FailSetDevTblEntry:
#ifdef DEBUG
NotifyFailSetDevTblEntry();
goto Fail;
#endif
FailGetConfDescr:
#ifdef DEBUG
NotifyFailGetConfDescr();
goto Fail;
#endif
FailSetConfDescr:
#ifdef DEBUG
NotifyFailSetConfDescr();
goto Fail;
#endif
FailOnInit:
#ifdef DEBUG
USBTRACE("OnInit:");
#endif
Fail:
#ifdef DEBUG
NotifyFail(rcode);
#endif
Release();
return rcode;
}

View file

@ -155,26 +155,38 @@ uint8_t PL2303::Init(uint8_t parent, uint8_t port, bool lowspeed) {
return 0;
FailGetDevDescr:
#ifdef DEBUG
NotifyFailGetDevDescr();
goto Fail;
#endif
FailSetDevTblEntry:
#ifdef DEBUG
NotifyFailSetDevTblEntry();
goto Fail;
#endif
FailGetConfDescr:
#ifdef DEBUG
NotifyFailGetConfDescr();
goto Fail;
#endif
FailSetConfDescr:
#ifdef DEBUG
NotifyFailSetConfDescr();
goto Fail;
#endif
FailOnInit:
#ifdef DEBUG
USBTRACE("OnInit:");
#endif
Fail:
#ifdef DEBUG
NotifyFail(rcode);
#endif
Release();
return rcode;
}

View file

@ -40,7 +40,6 @@ public:
template <class BASE_CLASS, class LEN_TYPE, class OFFSET_TYPE>
void HexDumper<BASE_CLASS, LEN_TYPE, OFFSET_TYPE>::Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset) {
#ifdef DEBUG
if(UsbDEBUGlvl >= 0x80) { // Fully bypass this block of code if we do not debug.
for(LEN_TYPE j = 0; j < len; j++, byteCount++, byteTotal++) {
if(!byteCount) {
@ -56,7 +55,6 @@ void HexDumper<BASE_CLASS, LEN_TYPE, OFFSET_TYPE>::Parse(const LEN_TYPE len, con
}
}
}
#endif
}
#endif // __HEXDUMP_H__

View file

@ -390,32 +390,44 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
return 0;
FailGetDevDescr:
#ifdef DEBUG
NotifyFailGetDevDescr();
goto Fail;
#endif
FailSetDevTblEntry:
#ifdef DEBUG
NotifyFailSetDevTblEntry();
goto Fail;
#endif
FailGetConfDescr:
#ifdef DEBUG
NotifyFailGetConfDescr();
goto Fail;
#endif
FailSetConfDescr:
#ifdef DEBUG
NotifyFailSetConfDescr();
goto Fail;
#endif
FailSetProtocol:
#ifdef DEBUG
USBTRACE("SetProto:");
goto Fail;
#endif
FailSetIdle:
#ifdef DEBUG
USBTRACE("SetIdle:");
goto Fail;
#endif
Fail:
#ifdef DEBUG
NotifyFail(rcode);
#endif
Release();
return rcode;
}

View file

@ -221,27 +221,39 @@ uint8_t HIDUniversal::Init(uint8_t parent, uint8_t port, bool lowspeed) {
return 0;
FailGetDevDescr:
#ifdef DEBUG
NotifyFailGetDevDescr();
goto Fail;
#endif
FailSetDevTblEntry:
#ifdef DEBUG
NotifyFailSetDevTblEntry();
goto Fail;
#endif
FailGetConfDescr:
#ifdef DEBUG
NotifyFailGetConfDescr();
goto Fail;
#endif
FailSetConfDescr:
#ifdef DEBUG
NotifyFailSetConfDescr();
goto Fail;
#endif
FailSetIdle:
#ifdef DEBUG
USBTRACE("SetIdle:");
#endif
Fail:
#ifdef DEBUG
NotifyFail(rcode);
#endif
Release();
return rcode;
}

View file

@ -174,9 +174,10 @@ uint8_t BulkOnly::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) {
return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET;
FailGetDevDescr:
#ifdef DEBUG
NotifyFailGetDevDescr(rcode);
#endif
rcode = USB_ERROR_FailGetDevDescr;
goto Fail;
Fail:
Release();
@ -188,6 +189,7 @@ boolean BulkOnly::WriteProtected(uint8_t lun) {
}
// Check for write protect.
uint8_t BulkOnly::Page3F(uint8_t lun) {
uint8_t buf[192];
for (int i = 0; i < 192; i++) {
@ -205,7 +207,7 @@ uint8_t BulkOnly::Page3F(uint8_t lun) {
Notify(PSTR(" "), 0x80);
}
#if 0
if(WriteOk[lun]) {
if (WriteOk[lun]) {
Notify(PSTR(" Writes Allowed"), 0x80);
} else {
Notify(PSTR(" Writes Denied"), 0x80);
@ -226,7 +228,7 @@ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) {
AddressPool &addrPool = pUsb->GetAddressPool();
UsbDevice *p = addrPool.GetUsbDevicePtr(bAddress);
if (!p)
if (!p)
return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
// Assign new address to the device
@ -358,30 +360,44 @@ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) {
return 0;
FailSetConfDescr:
#ifdef DEBUG
NotifyFailSetConfDescr();
goto Fail;
#endif
FailOnInit:
#ifdef DEBUG
USBTRACE("OnInit:");
goto Fail;
#endif
FailGetMaxLUN:
#ifdef DEBUG
USBTRACE("GetMaxLUN:");
goto Fail;
#endif
FailInvalidSectorSize:
#ifdef DEBUG
USBTRACE("Sector Size is NOT VALID: ");
goto Fail;
#endif
FailSetDevTblEntry:
#ifdef DEBUG
NotifyFailSetDevTblEntry();
goto Fail;
#endif
FailGetConfDescr:
FailGetConfDescr:
#ifdef DEBUG
NotifyFailGetConfDescr();
#endif
Fail:
#ifdef DEBUG
NotifyFail(rcode);
#endif
Release();
return rcode;
}
@ -449,7 +465,6 @@ uint8_t BulkOnly::Poll() {
return rcode;
}
uint8_t BulkOnly::GetMaxLUN(uint8_t *plun) {
uint8_t ret = pUsb->ctrlReq(bAddress, 0, bmREQ_MASSIN, MASS_REQ_GET_MAX_LUN, 0, 0, bIface, 1, 1, plun, NULL);
@ -465,7 +480,7 @@ uint8_t BulkOnly::ClearEpHalt(uint8_t index) {
uint8_t ret = 0;
while(ret = (pUsb->ctrlReq(bAddress, 0, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_STANDARD | USB_SETUP_RECIPIENT_ENDPOINT,
while (ret = (pUsb->ctrlReq(bAddress, 0, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_STANDARD | USB_SETUP_RECIPIENT_ENDPOINT,
USB_REQUEST_CLEAR_FEATURE, USB_FEATURE_ENDPOINT_HALT, 0, ((index == epDataInIndex) ? (0x80 | epInfo[index].epAddr) : epInfo[index].epAddr), 0, 0, NULL, NULL))
== 0x01) delay(6);
@ -476,7 +491,7 @@ uint8_t BulkOnly::ClearEpHalt(uint8_t index) {
}
epInfo[index].bmSndToggle = 0;
epInfo[index].bmRcvToggle = 0;
// epAttribs = 0;
// epAttribs = 0;
return 0;
}
@ -490,6 +505,7 @@ uint8_t BulkOnly::Reset() {
#endif
return r;
}
uint8_t BulkOnly::ResetRecovery() {
Notify(PSTR("\r\nResetRecovery\r\n"), 0x80);
Notify(PSTR("-----------------\r\n"), 0x80);
@ -821,7 +837,7 @@ uint8_t BulkOnly::Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t block
uint8_t BulkOnly::Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, const uint8_t * buf) {
if (!LUNOk[lun]) return MASS_ERR_NO_MEDIA;
if(!WriteOk[lun]) return MASS_ERR_WRITE_PROTECTED;
if (!WriteOk[lun]) return MASS_ERR_WRITE_PROTECTED;
Notify(PSTR("\r\nWrite LUN:\t"), 0x80);
PrintHex<uint8_t > (lun, 0x90);
//printf("LUN=%i LBA=%8.8X BLOCKS=%i SIZE=%i\r\n", lun, addr, blocks, bsize);
@ -917,7 +933,7 @@ uint8_t BulkOnly::Transaction(CommandBlockWrapper *pcbw, uint16_t buf_size, void
pcbw->bmReserved2 = 0;
ErrorMessage<uint32_t > (PSTR("CBW.dCBWTag"), pcbw->dCBWTag);
while((usberr = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, sizeof (CommandBlockWrapper), (uint8_t*)pcbw)) == hrBUSY) delay(1);
while ((usberr = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, sizeof (CommandBlockWrapper), (uint8_t*)pcbw)) == hrBUSY) delay(1);
ret = HandleUsbError(usberr, epDataOutIndex);
//ret = HandleUsbError(pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, sizeof (CommandBlockWrapper), (uint8_t*)pcbw), epDataOutIndex);
@ -928,14 +944,14 @@ uint8_t BulkOnly::Transaction(CommandBlockWrapper *pcbw, uint16_t buf_size, void
if (!write) {
if (callback) {
uint8_t rbuf[bytes];
while((usberr = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, &bytes, rbuf)) == hrBUSY) delay(1);
while ((usberr = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, &bytes, rbuf)) == hrBUSY) delay(1);
if (usberr == hrSUCCESS) ((USBReadParser*)buf)->Parse(bytes, rbuf, 0);
} else {
while((usberr = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, &bytes, (uint8_t*)buf)) == hrBUSY) delay(1);
while ((usberr = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, &bytes, (uint8_t*)buf)) == hrBUSY) delay(1);
}
ret = HandleUsbError(usberr, epDataInIndex);
} else {
while((usberr = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, bytes, (uint8_t*)buf)) == hrBUSY) delay(1);
while ((usberr = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, bytes, (uint8_t*)buf)) == hrBUSY) delay(1);
ret = HandleUsbError(usberr, epDataOutIndex);
}
if (ret) {
@ -949,7 +965,7 @@ uint8_t BulkOnly::Transaction(CommandBlockWrapper *pcbw, uint16_t buf_size, void
bytes = sizeof (CommandStatusWrapper);
int tries = 2;
while (tries--) {
while((usberr = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, &bytes, (uint8_t*) & csw)) == hrBUSY) delay(1);
while ((usberr = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, &bytes, (uint8_t*) & csw)) == hrBUSY) delay(1);
if (!usberr) break;
ClearEpHalt(epDataInIndex);
//HandleUsbError(usberr, epDataInIndex);

View file

@ -1,7 +1,6 @@
#if !defined(__MASSTORAGE_H__)
#define __MASSTORAGE_H__
#define DEBUG
//<RANT>
// @Oleg -- Perhaps we need a central 'config.h', many of these includes and
@ -19,6 +18,7 @@
#include "usbhost.h"
#include "usb_ch9.h"
#include "Usb.h"
#include <message.h>
#if defined(ARDUINO) && ARDUINO >=100
#include "Arduino.h"

View file

@ -15,14 +15,13 @@ Web : http://www.circuitsathome.com
e-mail : support@circuitsathome.com
*/
#define DEBUG
#include "message.h"
// 0x80 is the default (i.e. trace) to turn off set this global to something lower.
// this allows for 126 other debugging levels.
// TO-DO: Allow assignment to a different serial port
int UsbDEBUGlvl = 0x80;
void Notifyc(char c, int lvl) {
void E_Notifyc(char c, int lvl) {
if (UsbDEBUGlvl < lvl) return;
#if defined(ARDUINO) && ARDUINO >=100
Serial.print(c);
@ -32,22 +31,23 @@ void Notifyc(char c, int lvl) {
Serial.flush();
}
void Notify(char const * msg, int lvl) {
void E_Notify(char const * msg, int lvl) {
if (UsbDEBUGlvl < lvl) return;
if (!msg) return;
char c;
while ((c = pgm_read_byte(msg++))) Notifyc(c, lvl);
while ((c = pgm_read_byte(msg++))) E_Notifyc(c, lvl);
}
void NotifyStr(char const * msg, int lvl) {
void E_NotifyStr(char const * msg, int lvl) {
if (UsbDEBUGlvl < lvl) return;
if (!msg) return;
char c;
while (c = *msg++) Notifyc(c, lvl);
while (c = *msg++) E_Notifyc(c, lvl);
}
#ifdef DEBUG
void NotifyFailGetDevDescr(void) {
Notify(PSTR("\r\ngetDevDescr"), 0x80);
}
@ -96,3 +96,4 @@ void NotifyFail(uint8_t rcode) {
PrintHex<uint8_t > (rcode, 0x80);
Notify(PSTR("\r\n"), 0x80);
}
#endif

View file

@ -17,20 +17,24 @@ e-mail : support@circuitsathome.com
#if !defined(__MESSAGE_H__)
#define __MESSAGE_H__
// uncomment to activate
#define DEBUG
#include <inttypes.h>
#include <avr/pgmspace.h>
extern int UsbDEBUGlvl;
#include "printhex.h"
void E_Notify(char const * msg, int lvl);
void E_NotifyStr(char const * msg, int lvl);
void Notify(char const * msg, int lvl);
void NotifyStr(char const * msg, int lvl);
#ifdef DEBUG
#define Notify E_Notify
#define NotifyStr E_NotifyStr
void NotifyFailGetDevDescr(uint8_t reason);
void NotifyFailSetDevTblEntry(uint8_t reason);
void NotifyFailGetConfDescr(uint8_t reason);
void NotifyFailGetDevDescr(void);
void NotifyFailSetDevTblEntry(void);
void NotifyFailGetConfDescr(void);
@ -38,28 +42,37 @@ void NotifyFailSetConfDescr(void);
void NotifyFailUnknownDevice(uint16_t VID, uint16_t PID);
void NotifyFail(uint8_t rcode);
#else
#define NotifyFailGetDevDescr()
#define NotifyFailSetDevTblEntry()
#define NotifyFailGetConfDescr()
#define NotifyFailSetConfDescr()
#define NotifyFailUnknownDevice(VID, PID)
#define NotifyFail(rcode)
#define Notify(...) ((void)0)
#define NotifyStr(...) ((void)0)
#define NotifyFailGetDevDescr(...) ((void)0)
#define NotifyFailSetDevTblEntry(...) ((void)0)
#define NotifyFailGetConfDescr(...) ((void)0)
#define NotifyFailGetDevDescr(...) ((void)0)
#define NotifyFailSetDevTblEntry(...) ((void)0)
#define NotifyFailGetConfDescr(...) ((void)0)
#define NotifyFailSetConfDescr(...) ((void)0)
#define NotifyFailUnknownDevice(...) ((void)0)
#define NotifyFail(...) ((void)0)
#endif
template <class ERROR_TYPE>
void ErrorMessage(uint8_t level, char const * msg, ERROR_TYPE rcode = 0) {
#ifdef DEBUG
Notify(msg, level);
Notify(PSTR(": "), level);
PrintHex<ERROR_TYPE > (rcode, level);
Notify(PSTR("\r\n"), level);
#endif
}
template <class ERROR_TYPE>
void ErrorMessage(char const * msg, ERROR_TYPE rcode = 0) {
#ifdef DEBUG
Notify(msg, 0x80);
Notify(PSTR(": "), 0x80);
PrintHex<ERROR_TYPE > (rcode, 0x80);
Notify(PSTR("\r\n"), 0x80);
#endif
}
#include "hexdump.h"

View file

@ -19,9 +19,9 @@ e-mail : support@circuitsathome.com
#include <inttypes.h>
#include <avr/pgmspace.h>
#include "printhex.h"
#include "hexdump.h"
#include "message.h"
//#include "printhex.h"
//#include "hexdump.h"
#if defined(ARDUINO) && ARDUINO >=100
#include "Arduino.h"

View file

@ -22,30 +22,36 @@ e-mail : support@circuitsathome.com
#else
#include <WProgram.h>
#endif
void Notifyc(char c, int lvl);
void E_Notifyc(char c, int lvl);
template <class T>
void PrintHex(T val, int lvl) {
#ifdef DEBUG
int num_nibbles = sizeof(T) * 2;
do {
char v = 48 + (((val >> (num_nibbles - 1) * 4)) & 0x0f);
if(v > 57) v += 7;
Notifyc(v, lvl);
E_Notifyc(v, lvl);
} while(--num_nibbles);
#endif
}
template <class T>
void PrintBin(T val, int lvl) {
#ifdef DEBUG
for(T mask = (((T) 1) << ((sizeof(T) << 3) - 1)); mask; mask >>= 1)
if(val & mask)
Notifyc('1', lvl);
E_Notifyc('1', lvl);
else
Notifyc('0', lvl);
E_Notifyc('0', lvl);
#endif
}
template <class T>
void SerialPrintHex(T val) {
#ifdef DEBUG
int num_nibbles = sizeof(T) * 2;
do {
@ -53,10 +59,12 @@ void SerialPrintHex(T val) {
if(v > 57) v += 7;
Serial.print(v);
} while(--num_nibbles);
#endif
}
template <class T>
void PrintHex2(Print *prn, T val) {
#ifdef DEBUG
T mask = (((T) 1) << (((sizeof(T) << 1) - 1) << 2));
while(mask > 1) {
@ -66,6 +74,7 @@ void PrintHex2(Print *prn, T val) {
mask >>= 4;
}
prn->print((T) val, HEX);
#endif
}
#endif // __PRINTHEX_H__