Logger now fully binary

This commit is contained in:
2017-06-19 23:39:40 +02:00
parent 16ea155d0d
commit b42787cc1b
7 changed files with 290 additions and 85 deletions
+40 -66
View File
@@ -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<String,AnyObject> {
// Grab channel
let channel: Dictionary<String,AnyObject> = channels as! Dictionary<String,AnyObject>
@@ -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<String,AnyObject> {
// Grab channel
let channel: Dictionary<String,AnyObject> = channels as! Dictionary<String,AnyObject>
@@ -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)
}
}
}
+2 -2
View File
@@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>4.0</string>
<string>4.1</string>
<key>CFBundleVersion</key>
<string>39</string>
<string>47</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
+2 -2
View File
@@ -1,2 +1,2 @@
version 4.0
build 39
version 4.1
build 47