-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbeacon.go
76 lines (59 loc) · 2.01 KB
/
beacon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package carrot
/*
This file describes the construction and types of messages sent during the Picnic Protocol handshake
between the server and primary and secondary devices.
Example initial message to devices. Since the session_token and uuid are the same,
this is a primary device message. The two fields would be different for secondary devices.
{
session_token: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F";
endpoint: "carrot_beacon";
payload: {
params: {
identifier = "com.Carrot.PrimaryBeacon";
uuid = "E621E1F8-C36C-495A-93FC-0C247A3E6E5F";
};
};
}
*/
// createInitialDeviceInfo creates initial message to be sent to a newly connected device.
// It establishes a device's primary or secondary role in order to send and recieve further information.
func createInitialDeviceInfo(uuid string, token string) ([]byte, error) {
params := ResponseParams{"identifier": "com.Carrot.Beacon", "uuid": uuid}
payload, err := newPayloadNoTransform(nil, params)
res, err := NewResponse(token, "carrot_beacon", payload)
info, err := res.Build()
return info, err
}
/*
Example request to obtain T_P from the primary device.
Since params (and offsets) are unnecessary for this case, the payload is empty.
{
session_token: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F";
endpoint: "carrot_transform";
payload: {
};
}
*/
// getT_PFromPrimaryDeviceRes requests information to determine a secondary device's
// position relative to the primary device.
func getT_PFromPrimaryDeviceRes(token string) ([]byte, error) {
payload, err := newPayloadNoTransform(nil, nil)
res, err := NewResponse(token, "carrot_transform", payload)
ask, err := res.Build()
return ask, err
}
/*
Example response from a primary device sending its T_P or a secondary device sending its T_L.
These messages look identical so the context in transform.go determines where and what the offset is stored as.
{
"session_token": "E621E1F8-C36C-495A-93FC-0C247A3E6E5F",
"endpoint": "carrot_transform",
"payload": {
"offset": {
"x": 1,
"y": 1,
"z": 1
}
}
}
*/