-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlugin_Test.m
More file actions
78 lines (60 loc) · 1.82 KB
/
Plugin_Test.m
File metadata and controls
78 lines (60 loc) · 1.82 KB
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
77
78
#include <stdio.h>
#include <assert.h>
#ifdef __APPLE__
#import <Foundation/Foundation.h> // Needed for CBPeripheral
static void BLENativeLinuxHelper(void *this) {
SInt32 result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, YES);
switch (result) {
case kCFRunLoopRunStopped:
case kCFRunLoopRunFinished:
fprintf(stderr, "Stopping run loop\n");
exit(0);
}
}
const char serviceUUID[] = "";
#undef __APPLE__
#undef __linux__
#else
#undef __linux__
const char serviceUUID[] = "B131ABDC-7195-142B-E012-0808817F198D";
#endif
#define __TEST__
#include "Unity3D_BLENativeManager.h"
#include "Unity3D_BLENativePeripheral.h"
const char deviceAddr[] = "00:7E:6B:5F:95:30";
const char charactUUID[] = "B131BBD0-7195-142B-E012-0808817F198D";
NativeConnection *connection = NULL;
void notifyCallback(const char *uuid, const void *dp)
{
int v = *(unsigned char *)dp;
fprintf(stderr, "%s: %s, %d (%p)\n", __func__, uuid, v, dp);
}
void scanCallback(
void *cs_context,
NativePeripheral *cbp,
NativeAdvertisementData *add/*XXX*/,
long int RSSI)
{
BLENativeManager *this = cs_context;
char id[32] = { '\0' };
BLENativePeripheral *p = BLENativeCreatePeripheral(cbp);
BLENativePeripheralGetIdentifier(p, id, sizeof(id));
fprintf(stderr, "device: %s\n", id);
if (strncmp(deviceAddr, id, sizeof(id))) {
BLENativePeripheralRelease(p);
return;
}
BLENativePeripheralSetService(p, serviceUUID);
BLENativePeripheralAddCharacteristic(p, charactUUID, notifyCallback);
connection = BLENativeConnect(this, p);
}
int main(int ac, const char **av)
{
BLENativeManager *this = BLENativeCreateManager();
BLENativeInitialise(this, this);
BLENativeScanStart(this, serviceUUID, scanCallback);
for (;;) {
BLENativeLinuxHelper(this);
}
/* NOTREACHED */
}