Skip to content
This repository was archived by the owner on Dec 22, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion KaiSDK/Kai.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@


class Kai:
def __init__(self, id = None, capabilities = 0, hand = None):
def __init__(self, id = None, name = None, capabilities = 0, hand = None):
self.id = id
self.name = name
self.capabilities = capabilities
self.hand = hand
self.eventManager = EventManager()
Expand Down
2 changes: 2 additions & 0 deletions KaiSDK/WebSocketModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ def close(self):
# Trigger a recv() for the listener so it closes (seems kind of hacky)
self.getSDKVersion()
self.webSocket.close()
print('Websocket intentionally closed.')

def create_connection(self):
self.webSocket = websocket.create_connection(Constants.WebSockerURL)
print(f'Websocket has been successfully hosted at {Constants.WebSockerURL}')

def close_connection(self):
self.webSocket.close()
Expand Down
22 changes: 16 additions & 6 deletions KaiSDK/kai_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
import json
import traceback
import threading
nomenclature = ['alpha', 'beta', 'gamma','delta','epsilon','zeta', 'eta','theta']


class KaiSDK:
ConnectedKais = [Kai() for i in range(8)]
ConnectedKais = [Kai(name=x) for x in nomenclature]
ForegroundProcess = ""

DefaultKai = Kai()
DefaultLeftKai = Kai()
DefaultRightKai = Kai()
AnyKai = Kai()
myKai = ConnectedKais[0]
DefaultKai = myKai
DefaultLeftKai = myKai
DefaultRightKai = myKai
AnyKai = myKai

def __init__(self):
self.initialized = False
Expand All @@ -38,13 +40,15 @@ def connect(self, moduleID, moduleSecret):
:rtype: bool
"""
self.initialize(moduleID, moduleSecret)
self.create_connection()
self.create_connection() #redundant
self.sendAuth()
self.handle(self.receive_data())
if self.authenticated:
print("KaiSDK successfully connected")
self.running = True
self.dataListener = threading.Thread(target=self.listener_thread)
self.dataListener.start()
print("started event listening")
return True
return False

Expand Down Expand Up @@ -83,9 +87,13 @@ def listener_thread(self):
self.close()

def sendAuth(self):
print("Authentication in progress")
obj = dict()
obj[Constants.Type] = Constants.Authentication
print(Constants.Authentication)
obj[Constants.ModuleId] = self.moduleID
print(self.moduleID)
print("Authentication successful")
obj[Constants.ModuleSecret] = self.moduleSecret

self.send(json.dumps(obj))
Expand All @@ -94,11 +102,13 @@ def getConnectedKais(self):
obj = dict()
obj[Constants.Type] = Constants.ListConnectedKais
self.send(json.dumps(obj))
return Constants.ListConnectedKais

def getSDKVersion(self):
obj = dict()
obj[Constants.Type] = Constants.GetSDKVersion
self.send(json.dumps(obj))
return Constants.GetSDKVersion

def setCapabilities(self, kai, capabilities):
kai.set_capabilities(capabilities)
Expand Down