Skip to content

Commit

Permalink
Fixed bug in page register separation
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Mar 21, 2024
1 parent 024fa7b commit 23808f0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/vscp/common/mdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9653,7 +9653,7 @@ CMDF::getRegisterMap(uint16_t page, std::map<uint32_t, CMDF_Register *> &mapRegs
}

for (auto reg : regset) {
std::map<uint32_t, CMDF_Register *> mapRegs;
//std::map<uint32_t, CMDF_Register *> mapRegs;
mapRegs[reg] = getRegister(reg, page);
}

Expand Down
45 changes: 27 additions & 18 deletions src/vscp/common/register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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)) {
Expand All @@ -336,7 +344,7 @@ vscp_readLevel1RegisterBlock(CVscpClient &client,
#else
usleep(2000);
#endif

printf("l2\n");
} while (true);

return rv;
Expand Down Expand Up @@ -489,10 +497,12 @@ vscp_scanForDevices(CVscpClient &client, cguid &guid, std::set<uint16_t> &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())) {
Expand All @@ -518,7 +528,7 @@ vscp_scanForDevices(CVscpClient &client, cguid &guid, std::set<uint16_t> &found,
}

// Check timeout
if ((vscp_getMsTimeStamp() - startTime) > 500) {
if ((vscp_getMsTimeStamp() - startTime) > timeout) {
rv = VSCP_ERROR_TIMEOUT;
break;
}
Expand Down Expand Up @@ -577,7 +587,6 @@ vscp_scanSlowForDevices(CVscpClient &client,
#else
usleep(delay);
#endif

}

uint32_t startTime = vscp_getMsTimeStamp();
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 6 additions & 7 deletions src/vscp/common/vscp_client_socketcan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -1211,7 +1211,6 @@ workerThread(void *pData)
sem_post(&pObj->m_semReceiveQueue);
pthread_mutex_unlock(&pObj->m_mutexReceiveQueue);
}

}
else {
vscp_deleteEvent(pEvent);
Expand Down

0 comments on commit 23808f0

Please sign in to comment.