void CDepartmentEstimationDialog::HandlePositioningMessage(SDialogPositioingMessage *Message) { Assert(Message->m_MessageType == DialogPositioningMessage); int ListEntryIndex = GetListEntryIndex(Message); if (ListEntryIndex == -1) AddNewEntry(Message); else UpdateEntry(ListEntryIndex, Message); UpdateUserLocation(Message->m_BDADDRESS, Message->m_EstimatedPosition, Message->m_DepartmentNamesUserCurrentlyIn); }
/* ============================================================================ Loads the log data from a file. ============================================================================ */ int VTTpddServerLog::LoadFile(MString filename) { FILE* fd; int c, lineNo, rxTx; //VTTpddLogEntry* pEntry; //MString fmt, hexFmt; char line[256]; char *ptr; // Test if we are loading from the root window if (this == gpLog) { // Don't load files from the root window. Create a new window VTTpddServerLog* pLog = new VTTpddServerLog(w(), h(), "TPDD Log Viewer"); // Validate the window was created if (pLog == NULL) return FALSE; // Let the new window open the log if (!pLog->LoadFile(filename)) { // Load was not successful. Destroy the window delete pLog; return FALSE; } // Now show the new window pLog->show(); pLog->resize(x()+MENU_HEIGHT, y()+MENU_HEIGHT, w(), h()); return TRUE; } // Try to open the file if ((fd = fopen(filename, "r")) == NULL) { fl_message("Unable to open file %s", fl_filename_name((const char *) filename)); return FALSE; } // Loop for all data in the file lineNo = 0; while (fgets(line, sizeof(line), fd) != NULL) { // Start at beginning of line ptr = line; c = 0; lineNo++; // Search for a reference. This means we log the existing entry and start a new one while (*ptr == ' ') { // Increment ptr and c ptr++; c++; } // Test if a reference found if (c < 4) { // Validate the file format if (*ptr < '0' || *ptr > '9') { // Not a trace file!! fl_message("This does not appear to be a valid file on line %d", lineNo); return FALSE; } // Reference found. This entry and start a new one if (m_rxCount > 0) AddNewEntry(TPDD_LOG_RX, m_rxCount, m_rxBuffer); if (m_txCount > 0) AddNewEntry(TPDD_LOG_TX, m_txCount, m_txBuffer); m_txCount = 0; m_rxCount = 0; // Skip past the reference and find the ':' while (*ptr != ':' && c < sizeof(line)) { // Increment pointer and index ptr++; c++; } // Test if ':' found if (c >= sizeof(line) || *ptr != ':') { // Not a trace file!! fl_message("This does not appear to be a valid file on line %d", lineNo); return FALSE; } // Skip the ':' and spaces after it ptr += 2; c += 2; // Now get RX/TX marker if (*ptr == 'T') rxTx = 1; else if (*ptr == 'R') rxTx = 0; else { // Not a trace file!! fl_message("This does not appear to be a valid file on line %d", lineNo); return FALSE; } // Skip past "RX: " or "TX: " ptr += 4; c += 4; } // Now we are pointing at the HEX data. Read all data from this line into // either the m_rxBuffer or m_txBuffer while (*ptr != ' ' && *ptr != '\0' && c < sizeof(line)) { unsigned char val; val = (*ptr > '9' ? *ptr = 'A' + 10 : *ptr - '0') << 4; ptr++; val += *ptr > '9' ? *ptr = 'A' + 10 : *ptr - '0'; ptr += 2; c += 3; // Now save val in either rx or tx buffer if (rxTx) { m_txBuffer[m_txCount++] = val; if (m_txCount >= sizeof(m_txBuffer)) { AddNewEntry(TPDD_LOG_TX, m_txCount, m_txBuffer); m_txCount = 0; } } else { m_rxBuffer[m_rxCount++] = val; if (m_rxCount >= sizeof(m_rxBuffer)) { AddNewEntry(TPDD_LOG_RX, m_rxCount, m_rxBuffer); m_rxCount = 0; } } } } // Log any remaining data if (m_rxCount > 0) AddNewEntry(TPDD_LOG_RX, m_rxCount, m_rxBuffer); if (m_txCount > 0) AddNewEntry(TPDD_LOG_TX, m_txCount, m_txBuffer); m_txCount = 0; m_rxCount = 0; // Close the file fclose(fd); return TRUE; }
/* ============================================================================ Saves the log data to a file using the current window width ============================================================================ */ void VTTpddServerLog::SaveFile(MString filename) { FILE* fd; int count, c, i, dataIdx; VTTpddLogEntry* pEntry; MString fmt, hexFmt; // Validate we have data if (m_log.GetSize() == 0) return; // Test if the file exists if ((fd = fopen((const char *) filename, "r")) != NULL) { // Close the file fclose(fd); int ans = fl_choice("Overwrite existing file %s?", "Ok", "Cancel", NULL, fl_filename_name((const char *) filename)); if (ans == 1) return; } // Try to open the file if ((fd = fopen((const char *) filename, "w")) == NULL) { MString err; err.Format("Unable to create file %s\n", (const char *) filename); fl_message("%s", (const char *) err); return; } // Test if any leftover RX or TX data not logged to an entry yet if (m_rxCount > 0) AddNewEntry(TPDD_LOG_RX, m_rxCount, m_rxBuffer); if (m_txCount > 0) AddNewEntry(TPDD_LOG_TX, m_txCount, m_txBuffer); m_txCount = 0; m_rxCount = 0; // Now loop for all entries count = m_log.GetSize(); for (c = 0; c < count; c++) { // Get the next entry pEntry = (VTTpddLogEntry *) m_log[c]; fmt.Format("%4d: %s: ", pEntry->m_ref, pEntry->m_rxTx ? "TX" : "RX"); i = 0; dataIdx = 0; while (dataIdx < pEntry->m_count) { if (dataIdx != 0) fmt = " "; // "Print" the HEX data to the line for (i = 0; i < m_bytesPerLine && dataIdx + i < pEntry->m_count; i++) { hexFmt.Format("%02X ", (unsigned char) pEntry->m_pData[dataIdx + i]); fmt += hexFmt; } // Pad with spaces if less then m_bytesPerLine for ( ; i < m_bytesPerLine; i++) fmt += (char *) " "; // "Print" the ASCII data to the line fmt += (char *) " "; for (i = 0; i < m_bytesPerLine && dataIdx + i < pEntry->m_count; i++) { // Test if it's actual ASCII data or not if (pEntry->m_pData[dataIdx + i] >= ' ' && pEntry->m_pData[dataIdx + i] <= '~') hexFmt.Format("%c", (unsigned char) pEntry->m_pData[dataIdx + i]); else hexFmt = '.'; fmt += hexFmt; } // Save to the file fprintf(fd, "%s\n", (const char *) fmt); dataIdx += i; } } // Close the file fclose(fd); }
/* ============================================================================ Log data to the TPPD Server Log ============================================================================ */ void VTTpddServerLog::LogData(char data, int rxTx) { // Test if logging is enabled if (m_enabled) { int cmdlineState = m_pServer->IsCmdlineState(); // Test if logging RX data if (rxTx == TPDD_LOG_RX) { // Test if last logged data was RX or not if (!m_lastWasRx && !cmdlineState) { // We are starting a new RX entry. Save the existing TX entry // And start a new RX entry if (m_rxCount > 0) AddNewEntry(TPDD_LOG_RX, m_rxCount, m_rxBuffer); if (m_txCount > 0) AddNewEntry(TPDD_LOG_TX, m_txCount, m_txBuffer); m_txCount = 0; m_rxCount = 0; //printf("\nRX: "); } m_lastWasRx = TRUE; m_rxBuffer[m_rxCount++] = data; // Test if the rxBuffer is full if (m_rxCount == sizeof(m_rxBuffer)) { // Need to dump this packet and start a new one AddNewEntry(TPDD_LOG_RX, m_rxCount, m_rxBuffer); m_rxCount = 0; } //printf("%02X ", (unsigned char) data); } else { // Logging TX data test if starting a new TX packet if (m_lastWasRx && !cmdlineState) { // We are starting a new RX entry. Save the existing TX entry // And start a new RX entry if (m_rxCount > 0) AddNewEntry(TPDD_LOG_RX, m_rxCount, m_rxBuffer); if (m_txCount > 0) AddNewEntry(TPDD_LOG_TX, m_txCount, m_txBuffer); m_txCount = m_rxCount = 0; //printf("\nTX: "); } m_lastWasRx = FALSE; // Add data to the tx buffer m_txBuffer[m_txCount++] = data; // Test if the TX buffer is full if (m_txCount == sizeof(m_txBuffer)) { // Need to dump this packet and start a new one AddNewEntry(TPDD_LOG_TX, m_txCount, m_txBuffer); m_txCount = 0; } //printf("%02X ", (unsigned char) data); } } // TODO: Make redrawing smarter and add auto-scroll if (!m_callbackActive) { Fl::add_timeout(0.1, cb_redraw, this); m_callbackActive = TRUE; } }