Skip to content

Commit

Permalink
Merge pull request #107 from matrix-io/kp/handle_errors
Browse files Browse the repository at this point in the history
Kp/handle errors
  • Loading branch information
kdpatino authored May 30, 2018
2 parents 34291f0 + acfe98e commit 11ff257
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 37 deletions.
8 changes: 8 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
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
* Bug Fix: Handle Bus init error.

-- MATRIX Labs <info@matrix.one> Wed, 30 Apr 2018 15:02:53 +0000

matrixio-malos (0.3.3) unstable; urgency=medium

* Support changes in libmatrixio-creator-hal.
Expand Down
22 changes: 12 additions & 10 deletions src/driver_everloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() != matrix_hal::kMatrixCreatorNLeds) {
std::string error_msg("35, Invalid number of leds for ");
error_msg += kEverloopDriverName;
error_msg += ". MATRIX Creator has " +
std::to_string(matrix_hal::kMatrixCreatorNLeds) + " 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();
Expand All @@ -55,4 +46,15 @@ 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;
everloop_pb.SerializeToString(&buffer);
zqm_push_update_->Send(buffer);
return true;
}
} // namespace matrix_malos
12 changes: 9 additions & 3 deletions src/driver_everloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
}

int32_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<matrix_hal::Everloop> writer_;
int32_t matrix_leds_;
};

} // namespace matrix_malos
Expand Down
2 changes: 1 addition & 1 deletion src/js_test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
69 changes: 47 additions & 22 deletions src/js_test/test_everloop.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,67 @@ 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')
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.
})

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
})
}, 50);
intensity_value -= 1
if (intensity_value < 0)
intensity_value = max_intensity
setEverloop({
red: 0,
green: intensity_value,
blue: 0,
white: 0
})
}, 50);
3 changes: 2 additions & 1 deletion src/malos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 " +
Expand Down

0 comments on commit 11ff257

Please sign in to comment.