From 23808f05fc5b2a92f1c5418b0623a9971fb27866 Mon Sep 17 00:00:00 2001 From: Ake Hedman Date: Thu, 21 Mar 2024 08:57:53 +0100 Subject: [PATCH] Fixed bug in page register separation --- src/vscp/common/mdf.cpp | 2 +- src/vscp/common/register.cpp | 45 ++++++++++++++--------- src/vscp/common/vscp_client_socketcan.cpp | 13 +++---- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/vscp/common/mdf.cpp b/src/vscp/common/mdf.cpp index 1da8f6696..24973376f 100644 --- a/src/vscp/common/mdf.cpp +++ b/src/vscp/common/mdf.cpp @@ -9653,7 +9653,7 @@ CMDF::getRegisterMap(uint16_t page, std::map &mapRegs } for (auto reg : regset) { - std::map mapRegs; + //std::map mapRegs; mapRegs[reg] = getRegister(reg, page); } diff --git a/src/vscp/common/register.cpp b/src/vscp/common/register.cpp index e4f527cfd..ebdf27226 100644 --- a/src/vscp/common/register.cpp +++ b/src/vscp/common/register.cpp @@ -265,8 +265,9 @@ vscp_readLevel1RegisterBlock(CVscpClient &client, ex.vscp_class = VSCP_CLASS1_PROTOCOL + (guidInterface.isNULL() ? 0 : 512); ex.vscp_type = VSCP_TYPE_PROTOCOL_EXTENDED_PAGE_READ; ex.sizeData = ifoffset + 5; - if (ifoffset) + if (ifoffset) { memcpy(ex.data, guidInterface.getGUID(), 16); + } ex.data[0 + ifoffset] = nickname; ex.data[1 + ifoffset] = (page >> 8) & 0x0ff; ex.data[2 + ifoffset] = page & 0x0ff; @@ -290,14 +291,16 @@ vscp_readLevel1RegisterBlock(CVscpClient &client, do { // Get response uint16_t cntRead; + printf("1\n"); rv = client.getcount(&cntRead); - if (cntRead && VSCP_ERROR_SUCCESS == rv) { + printf("2\n"); + if (cntRead && (VSCP_ERROR_SUCCESS == rv)) { if (VSCP_ERROR_SUCCESS != (rv = client.receive(ex))) { return rv; } - // std::cout << "class=" << (int)ex.vscp_class << " type = " << (int)ex.vscp_type << std::endl << std::flush; + std::cout << "class=" << (int)ex.vscp_class << " type=" << (int)ex.vscp_type << std::endl << std::flush; if (VSCP_CLASS1_PROTOCOL == ex.vscp_class) { if (VSCP_TYPE_PROTOCOL_EXTENDED_PAGE_RESPONSE == ex.vscp_type) { @@ -308,22 +311,27 @@ vscp_readLevel1RegisterBlock(CVscpClient &client, // Another frame received frameset.erase(ex.data[0]); - // std::cout << "idx=" << (int)ex.data[0] << " left = " << (int)frameset.size() << std::endl << std::flush; + std::cout << "idx=" << (int)ex.data[0] << " left = " << (int)frameset.size() << std::endl << std::flush; // Get read data + printf("size=%d\n",ex.sizeData ); for (int i = 0; i < ex.sizeData - 4; i++) { // values[offset + rcvcnt] = ex.data[4 + i]; + printf("A\n"); values[ex.data[3] + i] = ex.data[4 + i]; + printf("B\n"); rcvcnt++; + printf("C\n"); } - + printf("D\n"); // Check if we are ready - if (rcvcnt == count && frameset.empty()) { + if ((rcvcnt == count) && frameset.empty()) { return VSCP_ERROR_SUCCESS; } - } - } - } + printf("E\n"); + } // if is equal + } // Extended response + } // Protocol } if (timeout && ((vscp_getMsTimeStamp() - startTime) > timeout)) { @@ -336,7 +344,7 @@ vscp_readLevel1RegisterBlock(CVscpClient &client, #else usleep(2000); #endif - + printf("l2\n"); } while (true); return rv; @@ -489,10 +497,12 @@ vscp_scanForDevices(CVscpClient &client, cguid &guid, std::set &found, memset(&ex, 0, sizeof(vscpEventEx)); ex.vscp_class = VSCP_CLASS1_PROTOCOL + (guid.isNULL() ? 0 : 512); ex.vscp_type = VSCP_TYPE_PROTOCOL_WHO_IS_THERE; - memcpy(ex.data + offset, guid.getGUID(), 16); // Use GUID of interface - memset(ex.GUID, 0, 16); // Use GUID of interface - ex.sizeData = 17; - ex.data[16] = 0xff; // all devices + if (guid.isNULL()) { + memcpy(ex.data + offset, guid.getGUID(), 16); // Use GUID of interface + } + memset(ex.GUID, 0, 16); // Use GUID of interface + ex.sizeData = 1 + offset; + ex.data[0 + offset] = 0xff; // all devices // Clear input queue if (VSCP_ERROR_SUCCESS != (rv = client.clear())) { @@ -518,7 +528,7 @@ vscp_scanForDevices(CVscpClient &client, cguid &guid, std::set &found, } // Check timeout - if ((vscp_getMsTimeStamp() - startTime) > 500) { + if ((vscp_getMsTimeStamp() - startTime) > timeout) { rv = VSCP_ERROR_TIMEOUT; break; } @@ -577,7 +587,6 @@ vscp_scanSlowForDevices(CVscpClient &client, #else usleep(delay); #endif - } uint32_t startTime = vscp_getMsTimeStamp(); @@ -591,7 +600,7 @@ vscp_scanSlowForDevices(CVscpClient &client, } if (cnt) { - printf("cnt %d\n", (int)cnt); + printf("cnt %d\n", (int) cnt); rv = client.receive(ex); if (VSCP_ERROR_SUCCESS == rv) { std::cout << "Class: " << ex.vscp_class << " Type: " << ex.vscp_type << std::endl; @@ -1371,7 +1380,7 @@ CUserRegisters::init(CVscpClient &client, m_registerPageMap[page]->putLevel1Registers(registers); m_registerPageMap[page]->clearChanges(); m_pages.insert(page); - // std::cout << "Page " << std::hex << page << " size " << registers.size() << std::endl; + std::cout << "Page " << std::hex << page << " size " << registers.size() << std::endl; } return rv; } diff --git a/src/vscp/common/vscp_client_socketcan.cpp b/src/vscp/common/vscp_client_socketcan.cpp index 923c5160b..2cb06ca04 100644 --- a/src/vscp/common/vscp_client_socketcan.cpp +++ b/src/vscp/common/vscp_client_socketcan.cpp @@ -740,7 +740,7 @@ vscpClientSocketCan::send(vscpEvent &ev) memcpy(frame.data, canalMsg.data, canalMsg.sizeData); if (m_flags & FLAG_FD_MODE) { - // ensure discrete CAN FD length values 0..8, 12, 16, 20, 24, 32, 64 + // Ensure discrete CAN FD length values 0..8, 12, 16, 20, 24, 32, 64 frame.len = canal_dlc2len(canal_tbllen2dlc[frame.len]); } @@ -810,15 +810,15 @@ vscpClientSocketCan::receive(vscpEvent &ev) if (!m_receiveList.size()) { return VSCP_ERROR_FIFO_EMPTY; } - printf("receive\n"); - const vscpEvent *pev = m_receiveList.front(); + + const vscpEvent *pev = m_receiveList.front(); if (nullptr == pev) { return VSCP_ERROR_INVALID_POINTER; } - vscp_copyEvent(&ev, pev); + vscp_copyEvent(&ev, pev); m_receiveList.pop_front(); delete pev; - printf("RRRRR receive\n"); + return VSCP_ERROR_SUCCESS; } @@ -1162,7 +1162,7 @@ workerThread(void *pData) vscpEvent *pEvent = new vscpEvent(); if (nullptr != pEvent) { - + // This can lead to level I frames having to // much data. Later code will handel this case. pEvent->pdata = new uint8_t[frame.len]; @@ -1211,7 +1211,6 @@ workerThread(void *pData) sem_post(&pObj->m_semReceiveQueue); pthread_mutex_unlock(&pObj->m_mutexReceiveQueue); } - } else { vscp_deleteEvent(pEvent);