]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/tests/mbed/rpc/main.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / tests / mbed / rpc / main.cpp
1 #include "mbed.h"
2 #include "test_env.h"
3 #include "mbed_rpc.h"
4
5 void foo(Arguments *args, Reply *reply) {
6 reply->putData<float>(args->getArg<float>() * 3.3);
7 }
8
9 bool rpc_test(const char *input, const char *expected) {
10 char outbuf[RPC_MAX_STRING] = {0};
11 bool result = RPC::call(input, outbuf);
12 printf("RPC: %s -> ", input);
13
14 if (result == false) {
15 printf("Procedure call ... [FAIL]\r\n");
16 } else if (strncmp(outbuf, expected, RPC_MAX_STRING) != 0) {
17 printf("'%s' != '%s' ... [FAIL]\r\n", outbuf, expected);
18 result = false;
19 } else {
20 printf("'%s' ... [OK]\r\n", outbuf);
21 }
22 return result;
23 }
24
25 #define RPC_TEST(INPUT,EXPECTED) result = result && rpc_test(INPUT,EXPECTED); if (result == false) { notify_completion(result); exit(1); }
26
27 int main() {
28 float f = 0;
29 bool result = true;
30 // Variable
31 RPCVariable<float> rpc_f(&f, "f");
32 RPC_TEST("/f/write 1", "");
33 RPC_TEST("/f/read", "1");
34
35 // Function
36 RPCFunction rpc_foo(&foo, "foo");
37 #if defined(TOOLCHAIN_ARM_MICRO)
38 RPC_TEST("/foo/run 1", "3.299999952316284");
39 #else
40 RPC_TEST("/foo/run 1", "3.2999999523162842");
41 #endif
42
43 // Class
44 RPC::add_rpc_class<RpcDigitalOut>();
45 RPC_TEST("/DigitalOut/new LED2 led2", "led2");
46 RPC_TEST("/led2/write 1", "");
47 RPC_TEST("/led2/read", "1");
48
49 // Instance
50 RpcDigitalOut rpc_led(LED1, "led1");
51 RPC_TEST("/led1/write 1", "");
52 RPC_TEST("/led1/read", "1");
53
54 // Introspection
55 RPC_TEST("/", "led1 led2 foo f DigitalOut RPC");
56 RPC_TEST("/f", "read write delete");
57 RPC_TEST("/foo", "run delete");
58 RPC_TEST("/DigitalOut", "new");
59 RPC_TEST("/led1", "write read delete");
60
61 // Delete instance
62 RPC_TEST("/led2/delete", "");
63 RPC_TEST("/", "led1 foo f DigitalOut RPC");
64
65 notify_completion(result);
66 return 0;
67 }
Imprint / Impressum