diff --git a/RootViewController.swift b/RootViewController.swift index fb77f4d..47d50fc 100644 --- a/RootViewController.swift +++ b/RootViewController.swift @@ -43,7 +43,7 @@ class RootViewController: UIViewController, UIGestureRecognizerDelegate { robotNode = robot // Create a dummy node so that I can offset the position of the robot let dummyNode = SCNNode() - dummyNode.position = SCNVector3(0.35, -0.35, -0.35) + dummyNode.position = SCNVector3(0.35, -0.35, -0.8) dummyNode.addChildNode(robotNode) fieldNode.addChildNode(dummyNode) @@ -70,7 +70,7 @@ class RootViewController: UIViewController, UIGestureRecognizerDelegate { // [x, y, rot (degrees)] let newPos = topic.getDoubleArray(); // The data is in meters relative to the field center (in the field model scale) so we need to scale it to the ARKit scale - self.robotNode.position = SCNVector3(newPos![0] - 8.25, 0, newPos![1] - 4) + self.robotNode.position = SCNVector3(-newPos![0] + 8.25, 0, newPos![1] - 4) self.robotNode.eulerAngles.y = Float(newPos![2] * .pi / 180) } }, onConnect: { @@ -80,7 +80,7 @@ class RootViewController: UIViewController, UIGestureRecognizerDelegate { }) NTClient.connect() - NTClient.subscribe(key: "/SmartDashboard/Field/Robot") + NTClient.subscribe(key: "/SmartDashboard/Field/Robot", periodic: 0.001) } func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { diff --git a/deploy.sh b/deploy.sh index e052e95..b80794e 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,6 +1,6 @@ #!/bin/bash mv packages/*.ipa packages_archive/ -make package +make clean package package_name=$(ls packages/*.ipa | awk -F'/' '{print $2}') $THEOS/bin/sideloader-cli-linux-x86_64 install packages/$package_name -i \ No newline at end of file diff --git a/src/NetworkTables/NT4Client.swift b/src/NetworkTables/NT4Client.swift index 6cbcca9..fdce552 100644 --- a/src/NetworkTables/NT4Client.swift +++ b/src/NetworkTables/NT4Client.swift @@ -114,18 +114,12 @@ class NT4Client: WebSocketDelegate { serverConnectionActive = false onDisconnect?(reason, code) case .text(let string): - NSLog("Recieved text: \(string)") if let data = string.data(using: .utf8) { if let msg = try? JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]] { - NSLog("Received JSON: \(msg)") // Iterate through the messages for obj in msg { - let objStr = String(describing: obj) - // Attempt to decode the message as a JSON object - if let msgObj = try? JSONSerialization.jsonObject(with: objStr.data(using: .utf8)!, options: []) as? [String: Any] { - // Handle the message - handleJsonMessage(msg: msgObj) - } + // Handle the message + handleJsonMessage(msg: obj) } } } @@ -160,7 +154,6 @@ class NT4Client: WebSocketDelegate { } private func handleJsonMessage(msg: [String: Any]) { - NSLog("Recieved Parsed JSON: \(msg)") if let method = msg["method"] as? String { if let params = msg["params"] as? [String: Any] { switch method { @@ -168,7 +161,6 @@ class NT4Client: WebSocketDelegate { let newTopic = NTTopic(data: params) serverTopics[newTopic.name] = newTopic onTopicAnnounce?(newTopic) - NSLog("Announce: \(params)") default: NSLog("Unknown method: \(method)") } @@ -176,22 +168,27 @@ class NT4Client: WebSocketDelegate { } } - private func handleMsgPackMessage(msg: [Optional]){ - NSLog("Received binary: \(msg)") - NSLog("attempting to decode topic id: \(msg[0]!)") - guard let unwrappedMsg = msg[0], let topicID = unwrappedMsg as? Int else { - NSLog("Failed to decode topicID") - return - } - guard let timestamp = msg[1]! as? Int64 else { + private func handleMsgPackMessage(msg: [Any?]){ + NSLog("Type of msg[3]: \(type(of: msg[3]!))") + + guard let unsignedTimestamp = msg[1]! as? UInt32 else { NSLog("Failed to decode timestamp") return } - let data = msg[2] - NSLog("topicID: \(topicID), timestamp: \(timestamp), data: \(data!)") - - - if topicID >= 0 { + let timestamp = Int64(unsignedTimestamp) + let data = msg[3]! + + if let topicID = msg[0]! as? Int8 { + if topicID == -1 { + guard let clientTimestamp = data as? Int64 else { + NSLog("Failed to decode clientTimestamp") + return + } + NSLog("Received timestamp: \(clientTimestamp)") + // Handle receive timestamp + wsHandleReceiveTimestamp(serverTimestamp: timestamp, clientTimestamp: clientTimestamp) + } + } else if let topicID = msg[0]! as? UInt16 { var topic: NTTopic? = nil // Check to see if the topic ID matches any of the server topics for serverTopic in serverTopics.values { @@ -205,15 +202,11 @@ class NT4Client: WebSocketDelegate { topic.latestValue = data topic.latestTimestamp = timestamp onNewTopicData?(topic, timestamp, data) - } else if topicID == -1 { - guard let clientTimestamp = data as? Int64 else { - NSLog("Failed to decode clientTimestamp") - return - } - NSLog("Received timestamp: \(clientTimestamp)") - // Handle receive timestamp - wsHandleReceiveTimestamp(serverTimestamp: timestamp, clientTimestamp: clientTimestamp) + } else { + NSLog("Failed to decode topicID") + return } + } private func wsHandleReceiveTimestamp(serverTimestamp: Int64, clientTimestamp: Int64) {