Skip to content

Commit

Permalink
Add double[] support
Browse files Browse the repository at this point in the history
  • Loading branch information
nab138 committed May 8, 2024
1 parent 49a6a95 commit 78e3c06
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/NetworkTables/NT4Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ class NT4Client: WebSocketDelegate {
}
// If the topic is not found, return
guard let topic = topic else { return }
topic.latestValue = data
topic.latestTimestamp = timestamp
onNewTopicData?(topic, timestamp, data)
} else if topicID == -1 {
// Handle receive timestamp
Expand Down
15 changes: 15 additions & 0 deletions src/NetworkTables/NTStructures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class NTTopic {
var name: String = ""
var type: String = ""
var properties: [String: Any] = [:]
var latestValue: Any? = nil
var latestTimestamp: Int64 = -1

init(uid: Int, name: String, type: String, properties: [String: Any]) {
self.uid = uid
Expand Down Expand Up @@ -129,4 +131,17 @@ class NTTopic {
return 5 // Default to binary
}
}

func getDoubleArray() -> [Double]? {
if("double[]" != type) {
NSLog("Attempted to get double array from non-double[] topic")
return nil
}
if let val = latestValue as? [Double] {
return val
} else {
NSLog("Failed to cast latest value to double array")
return nil
}
}
}

0 comments on commit 78e3c06

Please sign in to comment.