- .NET Framework 4.5
- App created in VS2012, can be openned with VS2013
Getting the files:
- Create a new project in your IDE (such as Visual Studio).
- In your project folder, clone the repository recursively:
- git clone --recursive https://github.com/ase-lab/SoD_CS_Library.git SOD
- This will clone SOD library, as well as its dependency - socketIOclient
Setting up your solution and references:
- Right-click your solution in Solution Explorer, and choose Add... Existing Project.
- Add the SOD library and socketIOclient projects:
- Right-click your solution in Solution Explorer, and choose Manage NuGet Packages for Solution.
- Also suggest to Enable NuGet Package Restore
- Make sure Newtonsoft.JSON package (listed as Json.NET 6.0.3) is installed.
- Add both SOD_CS_Library and SocketIOClient to your project references.
- Right-click your project file, choose Add...Reference.
- On the left menu, choose Solution, and you should see the SOD library and socketIOclient projects you added in step 1. Select both of them.
- Check to see that SOD_CS_Library references include:
- SocketIOClient (if this is missing, do the same as step 3 to add it)
Your project should build at this point.
Using SoD in your project:
Prepare an instance of SoD:
- Add namespace to your application
- Create an instance of SoD:
- Connect to server when your app is ready (server must be running):
- SOD = new SOD_CS_Library.SOD(address, port);
- address is a string of format "192.168.1.69", port is an int (most likely 3000)
Subscribing to events:
Note: Event handlers should be set up before connecting to the server.
- Having prepared an instance of SOD, you can handle events with:
SOD.socket.On("eventNameToListenTo", (messageReceived) =>
//Parse received message
Dictionary<string, dynamic> parsedMessage = SOD.ParseMessageIntoDictionary(messageReceived);
//You can access the parsed information like this:
string eventName = parsedMessage["name"]; //name of event
object data = parsedMessage["data"]; //data sent by other device
int PID = parsedMessage["PID"]; //message ID, used for replying
//To send a reply/acknowledgement:
Dictionary<string, string> dictionaryToSendBack; //make some sample object to send back
Set up your own device:
SOD requires information about your device, such as the width and height.
The main properties can be set with:
- SOD.ownDevice.SetDeviceInformation(widthInMM, heightInMM, locationX, locationY, locationZ, deviceType, stationary);
Additional properties can be set individually:
- SOD.ownDevice.ID not used by server, but can help user identify device
- SOD.ownDevice.locationX X coordinate of location, set for stationary devices
- SOD.ownDevice.locationY Y coordinate of location, set for stationary devices
- SOD.ownDevice.locationZ Z coordinate of location, set for stationary devices
- SOD.ownDevice.deviceType what device it is, eg. "iPad" or "table"
- SOD.ownDevice.orientation no need to set this, might be useful for stationary devices though
- SOD.ownDevice.height device height in mm, used to calculate devices in view and intersection points
- SOD.ownDevice.width device width in mm, used to calculate devices in view and intersection points
- SOD.ownDevice.FOV how wide is the field of view of the device, to calculate devices in view
- SOD.ownDevice.ownerID usually should not be set by user, used by server to identify someone who is paired with the device
- SOD.ownDevice.pairingState pairing state, server will use this during pairing
- SOD.ownDevice.deviceIP IP address of the device, will be set by server upon connection
Connecting to server:
When the address and port are provided, the event handlers are setup, and the device information is set as well, SOD can connect to the server with:
Sending a request to server
There are four main types of requests sent to the server:
- Send information to server: These requests tell the server about the device.
- SendOrientation (angle the device is facing - use calibrateDeviceAngle to set current angle to 0)
- TryPairWithID (device wants to pair with a person)
- UnpairDevice (device wants to unpair)
- Get information from server: These requests get information stored on the server.
- GetDevicesWithSelection (get a list of all devices in the selection, eg. "inView","paired" or you can de a chain selection : ["all", "single101", "paired", "nearst"], the first selection in the arry gets filtered first, also "single101" means gets single device with ID=101)
- GetDeviceByID (get a single device by its ID)
- GetAllTrackedPeople (get a list of all people tracked by server)
- Send information to a device: These requests provide a selection for the server to determine which devices will receive the information ("all", "inView", etc.)
- SendStringToDevices (send a string to specified device or devices)
- SendDictionaryToDevices (send a dictionary to specified device or devices)
- Request information from a device
- RequestDataFromSelection (ask for some data with "requestName", from all devices in selection, eg. "all", inView", etc.)