Mercurial > louis > mq > lightsd
changeset 268:4e2109e85e7b
getting this queue ready
author | Louis Opter <kalessin@kalessin.fr> |
---|---|
date | Sat, 22 Aug 2015 18:06:08 -0700 |
parents | a9d19885ec51 |
children | 11177907cbe4 |
files | add_missing_tagging_tests.patch add_set_bulb_label.patch add_start_stop_timer.patch expose_a_bunch_of_metadata_in_get_light_state.patch fix_addrtoa_mess.patch fix_label_printing_in_get_light_state.patch ignore_sigpipe.patch lookup_for_the_compilation_db.patch make_device_timeout_2_5x_force_refresh.patch rename_pulse_to_square_and_document_skew_ratio.patch router_label_no_break.patch series use_timer_interface_for_the_gateway_refresh_loop.patch |
diffstat | 13 files changed, 293 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/add_missing_tagging_tests.patch Sat Aug 22 16:29:00 2015 -0700 +++ b/add_missing_tagging_tests.patch Sat Aug 22 18:06:08 2015 -0700 @@ -1,5 +1,5 @@ # HG changeset patch -# Parent 5326bf973f36f82a7f4a81075d0965facf554291 +# Parent 51af413a23c49e38ef5d347d1721ef0807a072dc Add missing unit-tests on tag/untag diff --git a/tests/core/jsonrpc/test_jsonrpc_check_and_call_tag_missing_params.c b/tests/core/jsonrpc/test_jsonrpc_check_and_call_tag_missing_params.c
--- a/add_set_bulb_label.patch Sat Aug 22 16:29:00 2015 -0700 +++ b/add_set_bulb_label.patch Sat Aug 22 18:06:08 2015 -0700 @@ -1,5 +1,5 @@ # HG changeset patch -# Parent c370e07108dde8c8497f963f2a5c6d0f276f9dbe +# Parent 7ba29801abfbef0d915a9e22eb9b5dca931a02e3 Add the set_label command diff --git a/core/jsonrpc.c b/core/jsonrpc.c @@ -151,7 +151,7 @@ Available methods ----------------- -@@ -66,14 +70,22 @@ +@@ -83,14 +87,22 @@ .. function:: get_light_state(target)
--- a/add_start_stop_timer.patch Sat Aug 22 16:29:00 2015 -0700 +++ b/add_start_stop_timer.patch Sat Aug 22 18:06:08 2015 -0700 @@ -1,7 +1,9 @@ # HG changeset patch -# Parent 2ae11e7bd9c743fdded7c92649789475c6462922 +# Parent 758ed6ce112a02ab9af61eef14af36cfe4f60f3e Add an interface to start and stop standalone timers +And rename lifx/timer to lifx/watchdog. + diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt
--- a/expose_a_bunch_of_metadata_in_get_light_state.patch Sat Aug 22 16:29:00 2015 -0700 +++ b/expose_a_bunch_of_metadata_in_get_light_state.patch Sat Aug 22 18:06:08 2015 -0700 @@ -1,5 +1,10 @@ # HG changeset patch -# Parent 7e84e52589db3b0f651cc28ba2021d7034b9c13d +# Parent ad04f1a18f508f585ffd59826ceaae9445cfbc69 +Expose the bulb address, model and firmware version in get_light_state + +The bulb's gateway is also exposed. + +Even more will be returned if you run lightsd with -v debug. diff --git a/core/daemon.c b/core/daemon.c --- a/core/daemon.c
--- a/fix_addrtoa_mess.patch Sat Aug 22 16:29:00 2015 -0700 +++ b/fix_addrtoa_mess.patch Sat Aug 22 18:06:08 2015 -0700 @@ -1,5 +1,9 @@ # HG changeset patch # Parent 13b24c5af219c96e98584529bf917d7cef143ab2 +Correctly convert LIFX addresses to ASCII + +Rename the conversion function to something more explicit and make it +re-entrant so you can print more than one address per printf call... diff --git a/core/lightsd.h b/core/lightsd.h --- a/core/lightsd.h
--- a/fix_label_printing_in_get_light_state.patch Sat Aug 22 16:29:00 2015 -0700 +++ b/fix_label_printing_in_get_light_state.patch Sat Aug 22 18:06:08 2015 -0700 @@ -1,8 +1,8 @@ # HG changeset patch -# Parent 0fb1a86260b94867a0b603c4812a3773e2aae024 -Properly handle LIFX labels in get_light_state +# Parent 1337d53e1622ec04035bd250b1fc26ed225dae9b +Properly handle 32 chars long LIFX labels in get_light_state -They may not be null terminated. +Not be nul terminated. diff --git a/core/proto.c b/core/proto.c --- a/core/proto.c @@ -35,3 +35,129 @@ ); if (i >= (int)sizeof(buf)) { +diff --git a/tests/core/proto/test_proto_get_light_state_label_overflow.c b/tests/core/proto/test_proto_get_light_state_label_overflow.c +new file mode 100644 +--- /dev/null ++++ b/tests/core/proto/test_proto_get_light_state_label_overflow.c +@@ -0,0 +1,121 @@ ++#include "proto.c" ++ ++#include "mock_client_buf.h" ++#include "mock_daemon.h" ++#include "mock_gateway.h" ++#include "mock_event2.h" ++#include "mock_timer.h" ++#include "tests_utils.h" ++ ++#define MOCKED_ROUTER_TARGETS_TO_DEVICES ++#define MOCKED_ROUTER_DEVICE_LIST_FREE ++#include "tests_proto_utils.h" ++ ++static bool device_list_free_called = false; ++ ++void ++lgtd_router_device_list_free(struct lgtd_router_device_list *devices) ++{ ++ if (!devices) { ++ lgtd_errx(1, "the device list must be passed"); ++ } ++ ++ device_list_free_called = true; ++} ++ ++struct lgtd_router_device_list * ++lgtd_router_targets_to_devices(const struct lgtd_proto_target_list *targets) ++{ ++ if (targets != (void *)0x2a) { ++ lgtd_errx(1, "unexpected targets list"); ++ } ++ ++ static struct lgtd_router_device_list devices = ++ SLIST_HEAD_INITIALIZER(&devices); ++ if (SLIST_FIRST(&devices)) { ++ return &devices; ++ } ++ ++ static struct lgtd_lifx_gateway gw_bulb_1 = { ++ .bulbs = LIST_HEAD_INITIALIZER(&gw_bulb_1.bulbs) ++ }; ++ static struct lgtd_lifx_bulb bulb_1 = { ++ .addr = { 1, 2, 3, 4, 5 }, ++ .state = { ++ .hue = 0xaaaa, ++ .saturation = 0xffff, ++ .brightness = 0xbbbb, ++ .kelvin = 3600, ++ .power = LGTD_LIFX_POWER_ON, ++ .tags = 0 ++ }, ++ .ips[LGTD_LIFX_BULB_WIFI_IP] = { ++ .fw_info.version = 0x10001 ++ }, ++ .model = "testbulb", ++ .product_info = { ++ .vendor_id = 1, ++ .product_id = 0xa, ++ .version = 9 ++ }, ++ .gw = &gw_bulb_1 ++ }; ++ memset(&bulb_1.state.label, 'a', sizeof(bulb_1.state.label)); ++ static struct lgtd_router_device device_1 = { .device = &bulb_1 }; ++ SLIST_INSERT_HEAD(&devices, &device_1, link); ++ ++ return &devices; ++} ++ ++int ++main(void) ++{ ++ struct lgtd_client client = { .io = FAKE_BUFFEREVENT }; ++ struct lgtd_proto_target_list *targets = (void *)0x2a; ++ ++ lgtd_opts.verbosity = LGTD_INFO; ++ ++ char expected_info[] = ("[" ++ "{" ++ "\"_lifx\":{" ++ "\"addr\":\"01:02:03:04:05:00\"," ++ "\"gateway\":{" ++ "\"site\":\"00:00:00:00:00:00\"," ++ "\"url\":\"tcp://[]:0\"," ++ "\"latency\":0" ++ "}," ++ "\"mcu\":{\"firmware_version\":\"0.0\"}," ++ "\"wifi\":{\"firmware_version\":\"1.1\"}" ++ "}," ++ "\"_model\":\"testbulb\"," ++ "\"_vendor\":null," ++ "\"hsbk\":[240,1,0.733333,3600]," ++ "\"power\":true," ++ "\"label\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"," ++ "\"tags\":[]" ++ "}" ++ "]"); ++ ++ reset_client_write_buf(); ++ ++ lgtd_proto_get_light_state(&client, targets); ++ ++ if (client_write_buf_idx != sizeof(expected_info) - 1) { ++ lgtd_errx( ++ 1, ++ "%d bytes written, expected_info %lu " ++ "(got %.*s instead of %s)", ++ client_write_buf_idx, sizeof(expected_info) - 1UL, ++ client_write_buf_idx, client_write_buf, expected_info ++ ); ++ } ++ ++ if (memcmp(expected_info, client_write_buf, sizeof(expected_info) - 1)) { ++ lgtd_errx( ++ 1, "got %.*s instead of %s", ++ client_write_buf_idx, client_write_buf, expected_info ++ ); ++ } ++ ++ return 0; ++}
--- a/ignore_sigpipe.patch Sat Aug 22 16:29:00 2015 -0700 +++ b/ignore_sigpipe.patch Sat Aug 22 18:06:08 2015 -0700 @@ -1,8 +1,8 @@ # HG changeset patch -# Parent f2f2853633d97350ae110af1464739d0238d5530 +# Parent c6a99cf30f8e3fcbc29067463b06d8b2b4ea97f2 Ignore SIGPIPE -It would be sad to die on this one, because a client decided to leave at +It would be sad to die on this one because a client decided to leave at the wrong moment. diff --git a/core/lightsd.c b/core/lightsd.c
--- a/lookup_for_the_compilation_db.patch Sat Aug 22 16:29:00 2015 -0700 +++ b/lookup_for_the_compilation_db.patch Sat Aug 22 18:06:08 2015 -0700 @@ -1,5 +1,10 @@ # HG changeset patch -# Parent 2a978903d10cb85fe980821f64401cb569aa74ee +# Parent 1a54138f66e0f8cd4e94d215d7321a95269267e1 +Feed the clang compilation database to YouCompleteMe + +Works with my setup and it should also work if you build directory is at +the root of the repo. It's still doesn't cover headers but that's a nice +improvement. diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py --- a/.ycm_extra_conf.py
--- a/make_device_timeout_2_5x_force_refresh.patch Sat Aug 22 16:29:00 2015 -0700 +++ b/make_device_timeout_2_5x_force_refresh.patch Sat Aug 22 18:06:08 2015 -0700 @@ -1,5 +1,5 @@ # HG changeset patch -# Parent 81c70d56434dba896d023f0f182d81de64b00a4e +# Parent 7aaac1367125b1c2e5467dc949eea88e8164387a Bump the device timeout to 2.5x device force refresh This will let us do more retries before we drop devices.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rename_pulse_to_square_and_document_skew_ratio.patch Sat Aug 22 18:06:08 2015 -0700 @@ -0,0 +1,111 @@ +# HG changeset patch +# Parent b711c3a217123f374b86a328d7e297290a726aab +Rename PULSE to SQUARE and document set_waveform's skew_ratio argument + +I think SQUARE is the convention in this context. + +diff --git a/core/proto.c b/core/proto.c +--- a/core/proto.c ++++ b/core/proto.c +@@ -156,7 +156,7 @@ + assert(saturation >= 0 && saturation <= UINT16_MAX); + assert(brightness >= 0 && brightness <= UINT16_MAX); + assert(kelvin >= 2500 && kelvin <= 9000); +- assert(waveform <= LGTD_LIFX_WAVEFORM_PULSE); ++ assert(waveform <= LGTD_LIFX_WAVEFORM_SQUARE); + assert(skew_ratio >= -32767 && skew_ratio <= 32768); + assert(period >= 0); + assert(cycles >= 0); +diff --git a/docs/protocol.rst b/docs/protocol.rst +--- a/docs/protocol.rst ++++ b/docs/protocol.rst +@@ -52,7 +52,7 @@ + .. function:: set_waveform(target, waveform, h, s, b, k, period, cycles, skew_ratio, transient) + + :param string waveform: One of ``SAW``, ``SINE``, ``HALF_SINE``, +- ``TRIANGLE``, ``PULSE``. ++ ``TRIANGLE``, ``SQUARE``. + :param float h: Hue from 0 to 360. + :param float s: Saturation from 0 to 1. + :param float b: Brightness from 0 to 1. +@@ -64,6 +64,23 @@ + end of the waveform, otherwise it will revert back to + its original state. + ++ The meaning of the ``skew_ratio`` argument depends on the type of waveform: ++ ++ +---------------+-----------------------------------------------------------+ ++ | ``SAW`` | Should be 0.5. | ++ +---------------+-----------------------------------------------------------+ ++ | ``SINE`` | Defines the peak point of the function, 0.5 gives you a | ++ | | sine and 1 or 0 will give you cosine. Ignored by firmware | ++ | | 1.1. | ++ +---------------+-----------------------------------------------------------+ ++ | ``HALF_SINE`` | Should be 0.5. | ++ +---------------+-----------------------------------------------------------+ ++ | ``TRIANGLE`` | Defines the peak point of the function like ``SINE``. | ++ | | Ignored by firmware 1.1. | ++ +---------------+-----------------------------------------------------------+ ++ | ``SQUARE`` | Ratio of a cycle the targets are set to the given color. | ++ +---------------+-----------------------------------------------------------+ ++ + .. function:: get_light_state(target) + + Return a list of dictionnaries, each dict representing the state of one +diff --git a/examples/lightsc.py b/examples/lightsc.py +--- a/examples/lightsc.py ++++ b/examples/lightsc.py +@@ -81,10 +81,10 @@ + ) + + +-def pulse(socket, target, h, s, b, k, period, cycles, +- duty_cycle=0.5, transient=True): ++def square(socket, target, h, s, b, k, period, cycles, ++ duty_cycle=0.5, transient=True): + return set_waveform( +- socket, target, "PULSE", h, s, b, k, ++ socket, target, "SQUARE", h, s, b, k, + cycles=cycles, + period=period, + skew_ratio=duty_cycle, +diff --git a/lifx/wire_proto.c b/lifx/wire_proto.c +--- a/lifx/wire_proto.c ++++ b/lifx/wire_proto.c +@@ -444,7 +444,7 @@ + WAVEFORM_ENTRY("SINE"), + WAVEFORM_ENTRY("HALF_SINE"), + WAVEFORM_ENTRY("TRIANGLE"), +- WAVEFORM_ENTRY("PULSE"), ++ WAVEFORM_ENTRY("SQUARE"), + WAVEFORM_ENTRY("INVALID") + }; + +diff --git a/lifx/wire_proto.h b/lifx/wire_proto.h +--- a/lifx/wire_proto.h ++++ b/lifx/wire_proto.h +@@ -223,7 +223,7 @@ + LGTD_LIFX_WAVEFORM_SINE = 1, + LGTD_LIFX_WAVEFORM_HALF_SINE = 2, + LGTD_LIFX_WAVEFORM_TRIANGLE = 3, +- LGTD_LIFX_WAVEFORM_PULSE = 4, ++ LGTD_LIFX_WAVEFORM_SQUARE = 4, + LGTD_LIFX_WAVEFORM_INVALID = 5, + }; + +diff --git a/tests/lifx/wire_proto/test_wire_proto_waveform_table.c b/tests/lifx/wire_proto/test_wire_proto_waveform_table.c +--- a/tests/lifx/wire_proto/test_wire_proto_waveform_table.c ++++ b/tests/lifx/wire_proto/test_wire_proto_waveform_table.c +@@ -27,9 +27,9 @@ + errx(1, "Expected WAVEFORM_TRIANGLE"); + } + +- rv = lgtd_lifx_wire_waveform_string_id_to_type("PULSE", 5); +- if (rv != LGTD_LIFX_WAVEFORM_PULSE) { +- errx(1, "Expected WAVEFORM_PULSE"); ++ rv = lgtd_lifx_wire_waveform_string_id_to_type("SQUARE", 6); ++ if (rv != LGTD_LIFX_WAVEFORM_SQUARE) { ++ errx(1, "Expected WAVEFORM_SQUARE"); + } + + rv = lgtd_lifx_wire_waveform_string_id_to_type("TEST", 4);
--- a/router_label_no_break.patch Sat Aug 22 16:29:00 2015 -0700 +++ b/router_label_no_break.patch Sat Aug 22 18:06:08 2015 -0700 @@ -1,6 +1,6 @@ # HG changeset patch -# Parent 91a1889c4959a3359361159b8ab5dc97f29336c0 -Do not stop at the first match when targeting to a label +# Parent f0fbe12d52770de54bbd6279519462e0e43cf5d7 +Do not stop at the first match when targeting a label People should use tags, but that seems like the correct behavior to have. @@ -45,3 +45,27 @@ } } +diff --git a/tests/core/router/test_router_targets_to_devices.c b/tests/core/router/test_router_targets_to_devices.c +--- a/tests/core/router/test_router_targets_to_devices.c ++++ b/tests/core/router/test_router_targets_to_devices.c +@@ -169,5 +169,20 @@ + lgtd_errx(1, "expected 4 device but got %d", count); + } + ++ // targeting a label shouldn't break at the first match: ++ struct lgtd_lifx_bulb *bulb_3_gw_2 = lgtd_tests_insert_mock_bulb(gw_2, 7); ++ strcpy(bulb_3_gw_2->state.label, "desk"); ++ targets = lgtd_tests_build_target_list("desk", NULL); ++ devices = lgtd_router_targets_to_devices(targets); ++ if ((count = count_device(devices, bulb_1_gw_2)) != 1) { ++ lgtd_errx(1, "bulb bulb_1_gw_2 found %d times, expected 1", count); ++ } ++ if ((count = count_device(devices, bulb_3_gw_2)) != 1) { ++ lgtd_errx(1, "bulb bulb_3_gw_2 found %d times, expected 1", count); ++ } ++ if ((count = len(devices)) != 2) { ++ lgtd_errx(1, "expected 2 device but got %d", count); ++ } ++ + return 0; + }
--- a/series Sat Aug 22 16:29:00 2015 -0700 +++ b/series Sat Aug 22 18:06:08 2015 -0700 @@ -5,6 +5,7 @@ use_timer_interface_for_the_gateway_refresh_loop.patch expose_a_bunch_of_metadata_in_get_light_state.patch add_all_waveform_types_in_lightsc_py.patch +rename_pulse_to_square_and_document_skew_ratio.patch lookup_for_the_compilation_db.patch add_set_bulb_label.patch fix_label_printing_in_get_light_state.patch
--- a/use_timer_interface_for_the_gateway_refresh_loop.patch Sat Aug 22 16:29:00 2015 -0700 +++ b/use_timer_interface_for_the_gateway_refresh_loop.patch Sat Aug 22 18:06:08 2015 -0700 @@ -1,5 +1,5 @@ # HG changeset patch -# Parent b3b32b1d984b304cb8da0fe6b984068a5c01c327 +# Parent 558b65cfbfb0aaf6ed65d5abbfd060d456f84db8 Speed-up bulbs discovery By querying a gateway's bulbs as soon as it's discovered.