diff --git a/Docsis Toolkit.xcodeproj/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Docsis Toolkit.xcodeproj/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index fe2b454..fd70e2e 100644 --- a/Docsis Toolkit.xcodeproj/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/Docsis Toolkit.xcodeproj/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -2,4 +2,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FileOperations.swift b/FileOperations.swift index e7bd53d..56916cc 100644 --- a/FileOperations.swift +++ b/FileOperations.swift @@ -10,13 +10,33 @@ import Cocoa class FileOperations: NSObject { + // MARK: - Timestamp related + // 15 in threshold indicates some error + + static func encodeTimeStamp(stamp: String, threshold: String) -> UInt32 { + let mappingEncode: Dictionary = ["-" : 0, "62.81": 1, "58.21": 2, "57": 3, "59.81": 4, "55.21": 5, "54": 6, "56.81": 7, "52.21": 8, "51": 9] + let separated: Array = stamp.components(separatedBy: ":") + let hours: UInt32 = UInt32(separated[0])! << 16 + let minutes: UInt32 = UInt32(separated[1])! << 10 + let seconds: UInt32 = UInt32(separated[2])! << 4 + let thresholdI: UInt32 = mappingEncode[threshold] ?? 15 + return hours | seconds | minutes | thresholdI + } + + static func decodeTimestamp(stamp: UInt32) -> (String, String) { + let mappingDecode: Dictionary = [0: "-", 1: "62.81", 2: "58.21", 3: "57", 4: "59.81", 5: "55.21", 6: "54", 7: "56.81", 8: "52.21", 9: "51"] + let threshold: UInt32 = stamp & 0b1111 + let seconds: UInt32 = (stamp >> 4) & 0b111111 + let minutes: UInt32 = (stamp >> 10) & 0b111111 + let hours: UInt32 = (stamp >> 16) & 0b11111 + return ("\(hours):\(minutes):\(seconds)", mappingDecode[threshold] ?? "\(15)") + + } + + // MARK: - Loss log related + static func log(data: String, toLog path: String) { - let seperated: Array = data.components(separatedBy: ":") - let hours: UInt32 = UInt32(seperated[0])! - let minutes: UInt32 = UInt32(seperated[1])! - let seconds: UInt32 = UInt32(seperated[2])! - var dataToWrite: UInt32 = 0 - dataToWrite = ((((dataToWrite | hours) << 6) | minutes) << 8) | seconds + let dataToWrite = encodeTimeStamp(stamp: data, threshold: "") let file: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(bytes: 3, alignedTo: 1) file.storeBytes(of: dataToWrite, as: UInt32.self) do { @@ -36,11 +56,7 @@ class FileOperations: NSObject { while i < Data.length - 3 { let data: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(bytes: 3, alignedTo: 1) Data.getBytes(data, range: NSRange(location: i, length: 3)) - let compound: UInt32 = data.load(as: UInt32.self) - let seconds: UInt32 = (compound) & 0b111111 - let minutes: UInt32 = (compound >> 8) & 0b111111 - let hours: UInt32 = (compound >> 14) & 0b11111 - returnString?.append("\(hours):\(minutes):\(seconds)\n") + returnString?.append("\(decodeTimestamp(stamp: data.load(as: UInt32.self)).0)\n") i += 3 } if returnString != "" { @@ -48,4 +64,57 @@ class FileOperations: NSObject { } return nil } + + // MARK: - Frequency logging (encoding) + + static func logUpstream(data: String, toFrequencyLog path: String) { + let separated: Array = data.components(separatedBy: ";") + var encodedTime: UInt32 = encodeTimeStamp(stamp: separated[0], threshold: separated[2]) + // NaN Used for - + var encodedPower: Int32 = Int32.min + if (Double(separated[1]) != nil) { + encodedPower = Int32(Double(Double(separated[1])! * 100.0)) + } + var stringSize: UInt8 = UInt8(separated[3].lengthOfBytes(using: .ascii)) + + let fileContent: NSMutableData = NSMutableData() + fileContent.append(&stringSize, length: 1) + fileContent.append(&encodedTime, length: 3) + fileContent.append(&encodedPower, length: 4) + fileContent.append(separated[3].data(using: .ascii)!) + + do { + let fileData: NSMutableData = try NSMutableData(contentsOf: URL(fileURLWithPath: path)) + fileData.append(fileContent as Data) + fileData.write(to: URL(fileURLWithPath: path), atomically: true) + } catch _ { + fileContent.write(to: URL(fileURLWithPath: path), atomically: true) + } + } + + static func logDownstream(data: String, toFrequencyLog path: String) { + let separated: Array = data.components(separatedBy: ";") + var encodedTime: UInt32 = encodeTimeStamp(stamp: separated[0], threshold: "") + // NaN Used for - + var encodedPower: Int32 = Int32.min + if (Double(separated[1]) != nil) { + encodedPower = Int32(Double(Double(separated[1])! * 100.0)) + } + var encodedSNR = UInt8(separated[2]) ?? UInt8.max + + let fileContent: NSMutableData = NSMutableData() + fileContent.append(&encodedTime, length: 3) + fileContent.append(&encodedPower, length: 4) + fileContent.append(&encodedSNR, length: 1) + + do { + let fileData: NSMutableData = try NSMutableData(contentsOf: URL(fileURLWithPath: path)) + fileData.append(fileContent as Data) + fileData.write(to: URL(fileURLWithPath: path), atomically: true) + } catch _ { + fileContent.write(to: URL(fileURLWithPath: path), atomically: true) + } + } + + // MARK: - Frequency loading (decoding) } diff --git a/Graphic Analysis 2/Info.plist b/Graphic Analysis 2/Info.plist index c93a039..55189b7 100644 --- a/Graphic Analysis 2/Info.plist +++ b/Graphic Analysis 2/Info.plist @@ -42,9 +42,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.0 + 2.1 CFBundleVersion - 417 + 418 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/Graphic Analysis 2/buildnum.ver b/Graphic Analysis 2/buildnum.ver index 50d041b..2e22ddb 100644 --- a/Graphic Analysis 2/buildnum.ver +++ b/Graphic Analysis 2/buildnum.ver @@ -1,2 +1,2 @@ -version 2.0 -build 417 +version 2.1 +build 418 diff --git a/Logger4/FrequencyOperation.swift b/Logger4/FrequencyOperation.swift index 258a0c4..7c64401 100644 --- a/Logger4/FrequencyOperation.swift +++ b/Logger4/FrequencyOperation.swift @@ -125,18 +125,18 @@ class FrequencyOperation: Operation { entry += "NaN" } // Add ranging status - entry += ";\(channel["ranging_status"] as! String)\n" + entry += ";\(channel["ranging_status"] as! String)" // Add file name to path - file = dir.appending("Upstream \(channel["frequency"]!).csv") as NSString + file = dir.appending("Upstream \(channel["frequency"]!).hex") as NSString // Track modification - filesModified.append("Upstream \(channel["frequency"]!).csv") + filesModified.append("Upstream \(channel["frequency"]!).hex") // Write to file - logFreq(header: ";Power Level;Threshold;Ranging Status\n", file: file, entry: entry) + FileOperations.logUpstream(data: entry, toFrequencyLog: file.expandingTildeInPath) } } } } - // We have a single channel + // We have a single channel else if channels is Dictionary { // Grab channel let channel: Dictionary = channels as! Dictionary @@ -157,13 +157,13 @@ class FrequencyOperation: Operation { } let adjustInt: Double = Double(adjust)! // Add data to entry - entry = "\((NSApp.delegate as! AppDelegate).justTime.string(from: date));\(String(powerInt! + adjustInt));\(upstreamOne[modulationAdjust.allKeys(for: adjust)[0] as! String]!);\(channel["ranging_status"] as! String)\n" + entry = "\((NSApp.delegate as! AppDelegate).justTime.string(from: date));\(String(powerInt! + adjustInt));\(upstreamOne[modulationAdjust.allKeys(for: adjust)[0] as! String]!);\(channel["ranging_status"] as! String)" // Add file name to path - file = dir.appending("Upstream \(channel["frequency"]!).csv") as NSString + file = dir.appending("Upstream \(channel["frequency"]!).hex") as NSString // Track modifiction - filesModified.append("Upstream \(channel["frequency"]!).csv") + filesModified.append("Upstream \(channel["frequency"]!).hex") // Write to file - logFreq(header: ";Power Level;Threshold;Ranging Status\n", file: file, entry: entry) + FileOperations.logUpstream(data: entry, toFrequencyLog: file.expandingTildeInPath) } } } @@ -185,17 +185,17 @@ class FrequencyOperation: Operation { // We do not have an error if channel["frequency"] as! String != "status_error" { // Add data to entry - entry = "\((NSApp.delegate as! AppDelegate).justTime.string(from: date));\(channel["power_level"]!);\(channel["snr"]!)\n" + entry = "\((NSApp.delegate as! AppDelegate).justTime.string(from: date));\(channel["power_level"]!);\(channel["snr"]!)" // Add file name to path - file = dir.appending("Downstream \(channel["frequency"]!).csv") as NSString + file = dir.appending("Downstream \(channel["frequency"]!).hex") as NSString // Tracking modification - filesModified.append("Downstream \(channel["frequency"]!).csv") + filesModified.append("Downstream \(channel["frequency"]!).hex") // Write to file - logFreq(header: ";Power;SNR\n", file: file, entry: entry) + FileOperations.logDownstream(data: entry, toFrequencyLog: file.expandingTildeInPath) } } } - // We have a single channel + // We have a single channel else if channels is Dictionary { // Grab channel let channel: Dictionary = channels as! Dictionary @@ -204,72 +204,46 @@ class FrequencyOperation: Operation { // Add data to entry entry = "\((NSApp.delegate as! AppDelegate).justTime.string(from: date));\(channel["power_level"]!);\(channel["snr"]!)\n" // Add file name to path - file = dir.appending("Downstream \(channel["frequency"]!).csv") as NSString + file = dir.appending("Downstream \(channel["frequency"]!).hex") as NSString // Tracking modification - filesModified.append("Downstream \(channel["frequency"]!).csv") + filesModified.append("Downstream \(channel["frequency"]!).hex") // Write to file - logFreq(header: ";Power;SNR\n", file: file, entry: entry) - } - } - // Update if not modified - let fileManager = FileManager.default - // Get all filenames in directory - let enumerator:FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: dir.expandingTildeInPath)! - // Step through files - for element in enumerator { - // Check if modified - if !filesModified.contains(element as! String) && (element as! String).contains(".csv") { - logDummie(dir: dir, element: element as! String, date: date) + FileOperations.logDownstream(data: entry, toFrequencyLog: file.expandingTildeInPath) } } } - // Update if both nil (no connection to modem possible) - else if (upstreamBool && downstreamBool) { - upstreamBool = false - downstreamBool = false - let fileManager = FileManager.default - // Get all filenames in directory - let enumerator:FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: dir.expandingTildeInPath)! - // Step through files - for element in enumerator { + // Update if not modified + let fileManager = FileManager.default + // Get all filenames in directory + let enumerator:FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: dir.expandingTildeInPath)! + // Step through files + for element in enumerator { + // Check if modified + if !filesModified.contains(element as! String) && (element as! String).contains(".hex") { logDummie(dir: dir, element: element as! String, date: date) } } } - } - - func logFreq(header: String, file: NSString, entry: String) { - let fileManager = FileManager.default - if !fileManager.fileExists(atPath: file.expandingTildeInPath) { - do { - try header.write(toFile: file.expandingTildeInPath, atomically: true, encoding: .utf8) - } - catch { - NSLog("WRITE TO FILE \(file.expandingTildeInPath) FAILED\n"); - return + // Update if both nil (no connection to modem possible) + else if (upstreamBool && downstreamBool) { + upstreamBool = false + downstreamBool = false + let fileManager = FileManager.default + // Get all filenames in directory + let enumerator:FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: dir.expandingTildeInPath)! + // Step through files + for element in enumerator { + logDummie(dir: dir, element: element as! String, date: date) } } - let fileH: FileHandle? = FileHandle(forUpdatingAtPath: file.expandingTildeInPath) - fileH?.seekToEndOfFile() - let data: Data = (entry as NSString).data(using: String.Encoding.utf8.rawValue)! - fileH?.write(data) - fileH?.closeFile() } func logDummie(dir: NSString, element: String, date: Date) { - // Get file - let file: FileHandle? = FileHandle(forUpdatingAtPath: dir.expandingTildeInPath.appending(element)) - if file != nil { - // Write appropriate null entry to file - file?.seekToEndOfFile(); - var data: Data?; - if element.contains("Upstream") { - data = ("\((NSApp.delegate as! AppDelegate).justTime.string(from: date));-;-;-\n" as NSString).data(using: String.Encoding.utf8.rawValue) - } else { - data = ("\((NSApp.delegate as! AppDelegate).justTime.string(from: date));-;-\n" as NSString).data(using: String.Encoding.utf8.rawValue) - } - file?.write(data!) - file?.closeFile() + if element.contains("Upstream") { + FileOperations.logUpstream(data: "\((NSApp.delegate as! AppDelegate).justTime.string(from: date));-;-;-", toFrequencyLog: (dir.appending(element) as NSString).expandingTildeInPath) + } else { + FileOperations.logDownstream(data: "\((NSApp.delegate as! AppDelegate).justTime.string(from: date));-;-", + toFrequencyLog: (dir.appending(element) as NSString).expandingTildeInPath) } } } diff --git a/Logger4/Info.plist b/Logger4/Info.plist index 98cba17..f3be4d3 100644 --- a/Logger4/Info.plist +++ b/Logger4/Info.plist @@ -15,9 +15,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 4.0 + 4.1 CFBundleVersion - 39 + 47 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/Logger4/buildnum.ver b/Logger4/buildnum.ver index 628243c..a7d9510 100644 --- a/Logger4/buildnum.ver +++ b/Logger4/buildnum.ver @@ -1,2 +1,2 @@ -version 4.0 -build 39 +version 4.1 +build 47