Arduino USB Host Shield PL2302 Debug Message

问题:当我运行USB Host Shield Library 中关于 Pl2303 的例子(比如 pl2303_gprs_terminal)的时候,在串口会有下面的 Debug 信息:

Start
0000: 09 02 27 00 01 01 00 80 32 09 04 00 00 03 FF 00 
0010: 00 00 07 05 81 03 0A 00 01 07 05 02 02 40 00 00 
0020: 07 05 83 02 40 00 00

经过研究,产生的位置在  Usb.cpp 下面函数中

uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t* dataptr, USBReadParser *p) {

下面这个代码处:

// Invoke callback function if inTransfer completed successfully and callback function pointer is specified
   if(!rcode && p)
     ((USBReadParser*)p)->Parse(read, dataptr, total - left);

但是很明显,这里是调用设定的 callback 函数。

经过查找,最终确定实际生效的代码是hexdump.h 文件中下面的代码:

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 __attribute__((unused))) {
        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) {
                                PrintHex<OFFSET_TYPE > (byteTotal, 0x80);
                                E_Notify(PSTR(": "), 0x80);
                        }
                        PrintHex<uint8_t > (pbuf[j], 0x80);
                        E_Notify(PSTR(" "), 0x80);

                        if(byteCount == 15) {
                                E_Notify(PSTR("\r\n"), 0x80);
                                byteCount = 0xFF;
                        }
                }
        }
}

因为其他地方对 UsbDEBUGlvl 赋值为 0x80,所以会输出一下信息用于Debug。

最近阅读 USB Host Shield 感觉风格不是很统一,比如,用于 Debug 的定义开关有很多处,估计是因为后来的代码是很多人合作的结果。

参考:

1.https://www.lab-z.com/atu9/

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注