Skip to content

Commit

Permalink
Added Wifi output to Particle platform.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtuchkin committed Mar 20, 2017
1 parent d586c72 commit 8536d80
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 3 deletions.
8 changes: 8 additions & 0 deletions platform-particle/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
#include "settings.h"
#include "application.h"

SYSTEM_MODE(MANUAL);
//SerialLogHandler logHandler; // Uncomment to pipe system logging to Serial.

// This will be either configuration pipeline, or production pipeline.
std::unique_ptr<Pipeline> pipeline;

void setup() {
WiFi.connect();
waitUntil(WiFi.ready);
}

void loop() {
try {
if (!pipeline || pipeline->is_stop_requested()) {
Expand Down
8 changes: 7 additions & 1 deletion platform-particle/notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ sensor0 pin 3 negative tim
base0 origin -1.528180 2.433750 -1.969390 matrix -0.841840 0.332160 -0.425400 -0.046900 0.740190 0.670760 0.537680 0.584630 -0.607540
base1 origin 1.718700 2.543170 0.725060 matrix 0.458350 -0.649590 0.606590 0.028970 0.693060 0.720300 -0.888300 -0.312580 0.336480
object0 sensor0 0.0000 0.0000 0.0000
stream0 position object0 > usb_serial
serial2 9600 # Wifi
stream0 position object0 > serial2


To get the outputs via wifi, use socat:
```
socat - udp4-recv:3300,reuseaddr
```

## Build sequence for 'main' project.
dependent modules: user wiring hal system services communication platform wiring_globals

Expand Down
2 changes: 1 addition & 1 deletion platform-particle/output_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void HardwareSerialOutputNode::start() {
}

OutputNode::CreatorRegistrar HardwareSerialOutputNode::creator_([](uint32_t idx, const OutputDef& def) -> std::unique_ptr<OutputNode> {
if (idx > 0 && idx < num_outputs)
if (idx < num_outputs && hardware_serials[idx])
return std::make_unique<HardwareSerialOutputNode>(idx, def);
return nullptr;
});
36 changes: 36 additions & 0 deletions platform-particle/output_wifi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "output_wifi.h"

OutputNodeWifi::OutputNodeWifi(uint32_t idx, const OutputDef& def)
: OutputNode(idx, def)
, udp_stream_{} {
local_port_ = 33000;
remote_port_ = 3300;
}

void OutputNodeWifi::start() {
OutputNode::start();
udp_stream_.begin(local_port_);
uint32_t local_ip = WiFi.localIP().raw().ipv4;
uint32_t subnet_mask = WiFi.subnetMask().raw().ipv4;
uint32_t broadcast_ip = local_ip | ~subnet_mask;
remote_ip_ = broadcast_ip;
}

size_t OutputNodeWifi::write(const uint8_t *buffer, size_t size) {
size_t ret = udp_stream_.sendPacket(buffer, size, remote_ip_, remote_port_);
if (ret < 0)
Serial.printf("Error sending UDP packet: %d\n", ret);
return ret;
}

int OutputNodeWifi::read() {
if (!udp_stream_.available())
udp_stream_.parsePacket();
return udp_stream_.read();
}

OutputNode::CreatorRegistrar OutputNodeWifi::creator_([](uint32_t idx, const OutputDef& def) -> std::unique_ptr<OutputNode> {
if (idx == 2)
return std::make_unique<OutputNodeWifi>(idx, def);
return nullptr;
});
18 changes: 18 additions & 0 deletions platform-particle/output_wifi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include "output_serial.h"
#include <application.h>

class OutputNodeWifi : public OutputNode {
public:
OutputNodeWifi(uint32_t idx, const OutputDef& def);

protected:
virtual void start();
virtual size_t write(const uint8_t *buffer, size_t size);
virtual int read();
static CreatorRegistrar creator_;

uint16_t local_port_, remote_port_;
IPAddress remote_ip_;
UDP udp_stream_;
};
2 changes: 1 addition & 1 deletion platform-particle/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ uint32_t Timestamp::cur_time_millis() {
LedState cur_led_state = LedState::kNotInitialized;
LEDStatus led_statuses[] = {
[(int)LedState::kNotInitialized] = LEDStatus(RGB_COLOR_ORANGE, LED_PATTERN_SOLID),
[(int)LedState::kConfigMode] = LEDStatus(RGB_COLOR_GREEN, LED_PATTERN_BLINK, LED_SPEED_SLOW),
[(int)LedState::kConfigMode] = LEDStatus(RGB_COLOR_ORANGE, LED_PATTERN_BLINK, LED_SPEED_SLOW),
[(int)LedState::kNoFix] = LEDStatus(RGB_COLOR_BLUE, LED_PATTERN_BLINK, LED_SPEED_SLOW),
[(int)LedState::kFixFound] = LEDStatus(RGB_COLOR_BLUE, LED_PATTERN_BLINK, LED_SPEED_FAST),
};
Expand Down
1 change: 1 addition & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ bool PersistentSettings::process_command(char *input_cmd, PrintStream &stream) {

case "continue"_hash:
if (!validate_setup(stream)) break;
is_configured_ = true;
return false;

default:
Expand Down

0 comments on commit 8536d80

Please sign in to comment.