From 2437e5028ae84fb3c33b695437701f8a8212154d Mon Sep 17 00:00:00 2001 From: Kevin Patino Date: Tue, 22 May 2018 14:54:13 -0500 Subject: [PATCH 1/8] Handle errors --- debian/changelog | 6 ++++++ src/malos.cpp | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index d0173be..8a4a026 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +matrixio-malos (0.3.4) unstable; urgency=medium + + * Bug Fix: Handle Bus init error. + + -- MATRIX Labs Tue, 10 Apr 2018 11:02:53 +0000 + matrixio-malos (0.3.3) unstable; urgency=medium * Support changes in libmatrixio-creator-hal. diff --git a/src/malos.cpp b/src/malos.cpp index 78b1e58..222dfcd 100644 --- a/src/malos.cpp +++ b/src/malos.cpp @@ -47,7 +47,8 @@ int RunServer() { std::cerr << std::endl; matrix_hal::MatrixIOBus* bus = new matrix_hal::MatrixIOBus(); - bus->Init(); + + if (!bus.Init()) return false; DriverManager driver_manager(kBasePort, kUnsecureBindScope); std::cerr << "You can query specific driver info using port " + From 26e128f7894b6133ff894785790e830a8ec39347 Mon Sep 17 00:00:00 2001 From: Kevin Patino Date: Tue, 22 May 2018 14:55:35 -0500 Subject: [PATCH 2/8] Set as a pointer --- src/malos.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/malos.cpp b/src/malos.cpp index 222dfcd..d560474 100644 --- a/src/malos.cpp +++ b/src/malos.cpp @@ -48,7 +48,7 @@ int RunServer() { matrix_hal::MatrixIOBus* bus = new matrix_hal::MatrixIOBus(); - if (!bus.Init()) return false; + if (!bus->Init()) return false; DriverManager driver_manager(kBasePort, kUnsecureBindScope); std::cerr << "You can query specific driver info using port " + From 3fa9e216391fa92ee28bb271ac34ae1c22a94e54 Mon Sep 17 00:00:00 2001 From: Kevin Patino Date: Tue, 22 May 2018 16:53:17 -0500 Subject: [PATCH 3/8] Add everloop_length proto update --- src/driver_everloop.cpp | 14 ++++++++++---- src/driver_everloop.h | 12 +++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/driver_everloop.cpp b/src/driver_everloop.cpp index 3bf85d4..6f47ad3 100644 --- a/src/driver_everloop.cpp +++ b/src/driver_everloop.cpp @@ -28,11 +28,11 @@ namespace matrix_malos { bool EverloopDriver::ProcessConfig(const pb::driver::DriverConfig& config) { pb::io::EverloopImage image(config.image()); - if (image.led_size() != matrix_hal::kMatrixCreatorNLeds) { - std::string error_msg("35, Invalid number of leds for "); + if (image.led_size() != MatrixLeds()) { + std::string error_msg("Invalid number of leds for "); error_msg += kEverloopDriverName; - error_msg += ". MATRIX Creator has " + - std::to_string(matrix_hal::kMatrixCreatorNLeds) + " leds."; + error_msg += ". MATRIX Device has " + + std::to_string(MatrixLeds()) + " leds."; zmq_push_error_->Send(error_msg); return false; } @@ -55,4 +55,10 @@ bool EverloopDriver::ProcessConfig(const pb::driver::DriverConfig& config) { return writer_->Write(&image_for_hal); } + +bool ImuDriver::SendUpdate() { + const pb::io::EverloopImage erverloop_pb; + everloop_pb.set_everloop_length(MatrixLeds()); + return true; +} } // namespace matrix_malos diff --git a/src/driver_everloop.h b/src/driver_everloop.h index b19ae68..099a6cd 100644 --- a/src/driver_everloop.h +++ b/src/driver_everloop.h @@ -31,26 +31,32 @@ namespace matrix_malos { class EverloopDriver : public MalosWishboneBase { public: + EverloopDriver() : MalosWishboneBase(kEverloopDriverName) { - SetProvidesUpdates(false); - SetNeedsKeepalives(false); SetNotesForHuman( - "Write-only. There are 35 leds. Values range from 0 to 255. Check " + "Write-only. There are N leds. Values range from 0 to 255. Check " "message EverloopImage (protocol buffer)"); } + uint32_t MatrixLeds(){return matrix_leds_;} + // Receive a copy of the shared wishbone bus. Not owned. void SetupMatrixIOBus(matrix_hal::MatrixIOBus* wishbone) override { writer_.reset(new matrix_hal::Everloop); writer_->Setup(wishbone); + matrix_leds_ = wishbone->MatrixLeds(); } // Read configuration of LEDs (from the outside world). bool ProcessConfig(const pb::driver::DriverConfig& config) override; + // Send update to 0MQ zqm_push_update_ queue when called. + bool SendUpdate() override; + private: // Everloop writer. std::unique_ptr writer_; + uint32_t matrix_leds_; }; } // namespace matrix_malos From 7d6951e95d9b7c7099c8a0a2378bfaa5d646e289 Mon Sep 17 00:00:00 2001 From: Kevin Patino Date: Tue, 22 May 2018 23:00:26 +0000 Subject: [PATCH 4/8] Add update function --- src/driver_everloop.cpp | 12 +++++++++--- src/driver_everloop.h | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/driver_everloop.cpp b/src/driver_everloop.cpp index 6f47ad3..3f7c565 100644 --- a/src/driver_everloop.cpp +++ b/src/driver_everloop.cpp @@ -56,9 +56,15 @@ bool EverloopDriver::ProcessConfig(const pb::driver::DriverConfig& config) { } -bool ImuDriver::SendUpdate() { - const pb::io::EverloopImage erverloop_pb; - everloop_pb.set_everloop_length(MatrixLeds()); +bool EverloopDriver::SendUpdate() { + pb::io::EverloopImage everloop_pb; + int32_t matrix_leds = MatrixLeds(); + std::cout << "NLEDs : " << matrix_leds<< std::endl; + everloop_pb.set_everloop_length(matrix_leds); + + std::string buffer; + everloop_pb.SerializeToString(&buffer); + zqm_push_update_->Send(buffer); return true; } } // namespace matrix_malos diff --git a/src/driver_everloop.h b/src/driver_everloop.h index 099a6cd..b4967bf 100644 --- a/src/driver_everloop.h +++ b/src/driver_everloop.h @@ -38,7 +38,7 @@ class EverloopDriver : public MalosWishboneBase { "message EverloopImage (protocol buffer)"); } - uint32_t MatrixLeds(){return matrix_leds_;} + int32_t MatrixLeds(){return matrix_leds_;} // Receive a copy of the shared wishbone bus. Not owned. void SetupMatrixIOBus(matrix_hal::MatrixIOBus* wishbone) override { @@ -56,7 +56,7 @@ class EverloopDriver : public MalosWishboneBase { private: // Everloop writer. std::unique_ptr writer_; - uint32_t matrix_leds_; + int32_t matrix_leds_; }; } // namespace matrix_malos From 5b9cf65e01e62fea5364e55c71b21f3dc7ec0df6 Mon Sep 17 00:00:00 2001 From: Kevin Patino Date: Wed, 30 May 2018 19:38:46 +0000 Subject: [PATCH 5/8] Fix everloop driver --- src/driver_everloop.cpp | 13 ++------ src/js_test/package.json | 2 +- src/js_test/test_everloop.js | 63 +++++++++++++++++++++++++----------- 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/src/driver_everloop.cpp b/src/driver_everloop.cpp index 3f7c565..a31cefd 100644 --- a/src/driver_everloop.cpp +++ b/src/driver_everloop.cpp @@ -28,16 +28,7 @@ namespace matrix_malos { bool EverloopDriver::ProcessConfig(const pb::driver::DriverConfig& config) { pb::io::EverloopImage image(config.image()); - if (image.led_size() != MatrixLeds()) { - std::string error_msg("Invalid number of leds for "); - error_msg += kEverloopDriverName; - error_msg += ". MATRIX Device has " + - std::to_string(MatrixLeds()) + " leds."; - zmq_push_error_->Send(error_msg); - return false; - } - - matrix_hal::EverloopImage image_for_hal; + matrix_hal::EverloopImage image_for_hal(MatrixLeds()); int idx = 0; for (const pb::io::LedValue& value : image.led()) { image_for_hal.leds[idx].red = value.red(); @@ -59,7 +50,7 @@ bool EverloopDriver::ProcessConfig(const pb::driver::DriverConfig& config) { bool EverloopDriver::SendUpdate() { pb::io::EverloopImage everloop_pb; int32_t matrix_leds = MatrixLeds(); - std::cout << "NLEDs : " << matrix_leds<< std::endl; + everloop_pb.set_everloop_length(matrix_leds); std::string buffer; diff --git a/src/js_test/package.json b/src/js_test/package.json index 6cc7f84..174d8eb 100644 --- a/src/js_test/package.json +++ b/src/js_test/package.json @@ -7,7 +7,7 @@ "repository": "https://github.com/matrix-io/matrix-creator-malos", "devDependencies": {}, "dependencies": { - "matrix-protos": "0.0.17", + "matrix-protos":"", "mic": "^2.1.1", "zmq": "^2.15.3" } diff --git a/src/js_test/test_everloop.js b/src/js_test/test_everloop.js index 0e44d1d..3369dac 100644 --- a/src/js_test/test_everloop.js +++ b/src/js_test/test_everloop.js @@ -17,7 +17,6 @@ var zmq = require('zmq') // Import MATRIX Proto messages var matrix_io = require('matrix-protos').matrix_io - // To trigger an error message you can send an invalid configuration to the driver. // For instance, set a number of leds != 35. var errorSocket = zmq.socket('sub') @@ -30,29 +29,55 @@ errorSocket.on('message', (error_message) => { var configSocket = zmq.socket('push') configSocket.connect('tcp://' + creator_ip + ':' + creator_everloop_base_port /* config */) +var config = matrix_io.malos.v1.driver.DriverConfig.create({ + delayBetweenUpdates: 2.0, // 2 seconds between updates + timeoutAfterLastPing: 6.0, // Stop sending updates 6 seconds after pings. +}) + +configSocket.send(matrix_io.malos.v1.driver.DriverConfig.encode(config).finish()) + var max_intensity = 50 var intensity_value = max_intensity +var matrix_device_leds = 0 + +var updateSocket = zmq.socket('sub') +updateSocket.connect('tcp://' + creator_ip + ':' + (creator_everloop_base_port + 3)) +updateSocket.subscribe('') +updateSocket.on('message', (buffer) => { + var data = matrix_io.malos.v1.io.EverloopImage.decode(buffer) + matrix_device_leds = data.everloopLength +}); + +var pingSocket = zmq.socket('push') +pingSocket.connect('tcp://' + creator_ip + ':' + (creator_everloop_base_port + 1)) +console.log('Sending pings every 5 seconds'); +pingSocket.send(''); // Ping the first time. +setInterval(() => { + pingSocket.send(''); +}, 5000); + function setEverloop(led_values) { - var image = matrix_io.malos.v1.io.EverloopImage.create() - for (var j = 0; j < 35; ++j) { - var led_conf = matrix_io.malos.v1.io.LedValue.create(led_values); - image.led.push(led_conf) - } - var config = matrix_io.malos.v1.driver.DriverConfig.create({ - image: image - }) - configSocket.send(matrix_io.malos.v1.driver.DriverConfig.encode(config).finish()); + +var image = matrix_io.malos.v1.io.EverloopImage.create() + for (var j = 0; j < matrix_device_leds; ++j) { + var led_conf = matrix_io.malos.v1.io.LedValue.create(led_values); + image.led.push(led_conf) + } + var config = matrix_io.malos.v1.driver.DriverConfig.create({ + image: image + }) + configSocket.send(matrix_io.malos.v1.driver.DriverConfig.encode(config).finish()); } setInterval(() => { - intensity_value -= 1 - if (intensity_value < 0) - intensity_value = max_intensity - setEverloop({ - red: 0, - green: intensity_value, - blue: 0, - white: 0 - }) + intensity_value -= 1 + if (intensity_value < 0) + intensity_value = max_intensity + setEverloop({ + red: 0, + green: intensity_value, + blue: 0, + white: 0 + }) }, 50); From 03f50e264091a2a2d932db290a5bff5afad354b7 Mon Sep 17 00:00:00 2001 From: Kevin Patino Date: Wed, 30 May 2018 14:43:16 -0500 Subject: [PATCH 6/8] Fix style --- src/driver_everloop.cpp | 3 +-- src/js_test/test_everloop.js | 52 ++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/driver_everloop.cpp b/src/driver_everloop.cpp index a31cefd..00c41ee 100644 --- a/src/driver_everloop.cpp +++ b/src/driver_everloop.cpp @@ -46,11 +46,10 @@ bool EverloopDriver::ProcessConfig(const pb::driver::DriverConfig& config) { return writer_->Write(&image_for_hal); } - bool EverloopDriver::SendUpdate() { pb::io::EverloopImage everloop_pb; int32_t matrix_leds = MatrixLeds(); - + everloop_pb.set_everloop_length(matrix_leds); std::string buffer; diff --git a/src/js_test/test_everloop.js b/src/js_test/test_everloop.js index 3369dac..5d6044a 100644 --- a/src/js_test/test_everloop.js +++ b/src/js_test/test_everloop.js @@ -23,15 +23,15 @@ var errorSocket = zmq.socket('sub') errorSocket.connect('tcp://' + creator_ip + ':' + (creator_everloop_base_port + 2)) errorSocket.subscribe('') errorSocket.on('message', (error_message) => { - console.log('Message received: Pressure error: ' + error_message.toString('utf8')) + console.log('Message received: Pressure error: ' + error_message.toString('utf8')) }); var configSocket = zmq.socket('push') -configSocket.connect('tcp://' + creator_ip + ':' + creator_everloop_base_port /* config */) +configSocket.connect('tcp://' + creator_ip + ':' + creator_everloop_base_port /* config */ ) var config = matrix_io.malos.v1.driver.DriverConfig.create({ - delayBetweenUpdates: 2.0, // 2 seconds between updates - timeoutAfterLastPing: 6.0, // Stop sending updates 6 seconds after pings. + delayBetweenUpdates: 2.0, // 2 seconds between updates + timeoutAfterLastPing: 6.0, // Stop sending updates 6 seconds after pings. }) configSocket.send(matrix_io.malos.v1.driver.DriverConfig.encode(config).finish()) @@ -44,8 +44,8 @@ var updateSocket = zmq.socket('sub') updateSocket.connect('tcp://' + creator_ip + ':' + (creator_everloop_base_port + 3)) updateSocket.subscribe('') updateSocket.on('message', (buffer) => { - var data = matrix_io.malos.v1.io.EverloopImage.decode(buffer) - matrix_device_leds = data.everloopLength + var data = matrix_io.malos.v1.io.EverloopImage.decode(buffer) + matrix_device_leds = data.everloopLength }); var pingSocket = zmq.socket('push') @@ -53,31 +53,31 @@ pingSocket.connect('tcp://' + creator_ip + ':' + (creator_everloop_base_port + 1 console.log('Sending pings every 5 seconds'); pingSocket.send(''); // Ping the first time. setInterval(() => { - pingSocket.send(''); + pingSocket.send(''); }, 5000); function setEverloop(led_values) { - -var image = matrix_io.malos.v1.io.EverloopImage.create() + + var image = matrix_io.malos.v1.io.EverloopImage.create() for (var j = 0; j < matrix_device_leds; ++j) { - var led_conf = matrix_io.malos.v1.io.LedValue.create(led_values); - image.led.push(led_conf) - } - var config = matrix_io.malos.v1.driver.DriverConfig.create({ - image: image - }) - configSocket.send(matrix_io.malos.v1.driver.DriverConfig.encode(config).finish()); + var led_conf = matrix_io.malos.v1.io.LedValue.create(led_values); + image.led.push(led_conf) + } + var config = matrix_io.malos.v1.driver.DriverConfig.create({ + image: image + }) + configSocket.send(matrix_io.malos.v1.driver.DriverConfig.encode(config).finish()); } setInterval(() => { - intensity_value -= 1 - if (intensity_value < 0) - intensity_value = max_intensity - setEverloop({ - red: 0, - green: intensity_value, - blue: 0, - white: 0 - }) -}, 50); + intensity_value -= 1 + if (intensity_value < 0) + intensity_value = max_intensity + setEverloop({ + red: 0, + green: intensity_value, + blue: 0, + white: 0 + }) +}, 50); \ No newline at end of file From 8f2862820541428dc13c30e16224d21cb554f35a Mon Sep 17 00:00:00 2001 From: Kevin Patino Date: Wed, 30 May 2018 14:47:42 -0500 Subject: [PATCH 7/8] update changlelog --- debian/changelog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index 8a4a026..5ac416b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +matrixio-malos (0.3.5) unstable; urgency=medium + + * Bug Fix: Handle Everloop in MATRIX Voice and MATRIX Creator. + * Info: Comptible with protoc >= 0.3.5 + + -- MATRIX Labs Wed, 30 Apr 2018 15:02:53 +0000 + matrixio-malos (0.3.4) unstable; urgency=medium * Bug Fix: Handle Bus init error. From acfe98e754b39198d2eabfbb8c411be48dcb5b5f Mon Sep 17 00:00:00 2001 From: Kevin Patino Date: Wed, 30 May 2018 14:58:18 -0500 Subject: [PATCH 8/8] update changlelog --- debian/changelog | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/debian/changelog b/debian/changelog index 5ac416b..4cc7a9b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,15 +1,10 @@ -matrixio-malos (0.3.5) unstable; urgency=medium +matrixio-malos (0.3.4) unstable; urgency=medium * Bug Fix: Handle Everloop in MATRIX Voice and MATRIX Creator. * Info: Comptible with protoc >= 0.3.5 - - -- MATRIX Labs Wed, 30 Apr 2018 15:02:53 +0000 - -matrixio-malos (0.3.4) unstable; urgency=medium - * Bug Fix: Handle Bus init error. - -- MATRIX Labs Tue, 10 Apr 2018 11:02:53 +0000 + -- MATRIX Labs Wed, 30 Apr 2018 15:02:53 +0000 matrixio-malos (0.3.3) unstable; urgency=medium