Skip to content

Commit

Permalink
Merge pull request #611 from avr39-ripe/feature/wifi_events
Browse files Browse the repository at this point in the history
Add WifiEvents, add Basic_WebSkeletonApp, add  "save" argument to Wifi*.enable() method
  • Loading branch information
hreintke committed Mar 3, 2016
2 parents cb33f46 + 6efd262 commit c35c44b
Show file tree
Hide file tree
Showing 24 changed files with 901 additions and 6 deletions.
7 changes: 5 additions & 2 deletions Sming/SmingCore/Platform/AccessPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ AccessPointClass::AccessPointClass()
runConfig = NULL;
}

void AccessPointClass::enable(bool enabled)
void AccessPointClass::enable(bool enabled, bool save)
{
uint8 mode = wifi_get_opmode() & ~SOFTAP_MODE;
if (enabled) mode |= SOFTAP_MODE;
wifi_set_opmode(mode);
if (save)
wifi_set_opmode(mode);
else
wifi_set_opmode_current(mode);
}

bool AccessPointClass::isEnabled()
Expand Down
3 changes: 2 additions & 1 deletion Sming/SmingCore/Platform/AccessPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class AccessPointClass : protected ISystemReadyHandler

/** @brief Enable or disable WiFi AP
* @param enabled True to enable AP. False to disable.
* @param save True to save operational mode to flash, False to set current operational mode only
*/
void enable(bool enabled);
void enable(bool enabled, bool save = false);

/** @brief Get WiFi AP enable status
* @retval bool True if WiFi AP enabled.
Expand Down
12 changes: 10 additions & 2 deletions Sming/SmingCore/Platform/Station.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ StationClass::~StationClass()
connectionTimer = NULL;
}

void StationClass::enable(bool enabled)
void StationClass::enable(bool enabled, bool save)
{
uint8 mode = wifi_get_opmode() & ~STATION_MODE;
if (enabled) mode |= STATION_MODE;
wifi_set_opmode(mode);
if (save)
wifi_set_opmode(mode);
else
wifi_set_opmode_current(mode);
}

bool StationClass::isEnabled()
Expand Down Expand Up @@ -82,6 +85,11 @@ bool StationClass::config(String ssid, String password, bool autoConnectOnStartu
return true;
}

void StationClass::connect()
{
wifi_station_connect();
}

void StationClass::disconnect()
{
wifi_station_disconnect();
Expand Down
7 changes: 6 additions & 1 deletion Sming/SmingCore/Platform/Station.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ class StationClass : protected ISystemReadyHandler

/** @brief Enable / disable WiFi station
* @param enabled True to enable station. False to disable.
* @param save True to save operational mode to flash, False to set current operational mode only
*/
void enable(bool enabled);
void enable(bool enabled, bool save = false);

/** @brief Get WiFi station enable status
* @retval bool True if WiFi station enabled
Expand All @@ -100,6 +101,10 @@ class StationClass : protected ISystemReadyHandler
*/
bool config(String ssid, String password, bool autoConnectOnStartup = true);

/** @brief Connect WiFi station to network
*/
void connect();

/** @brief Disconnect WiFi station from network
*/
void disconnect();
Expand Down
138 changes: 138 additions & 0 deletions Sming/SmingCore/Platform/WifiEvents.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* WifiEvents.cpp
*
* Created on: 19 февр. 2016 г.
* Author: shurik
*/

#include <WifiEvents.h>

WifiEventsClass WifiEvents;

WifiEventsClass::WifiEventsClass()
{
wifi_set_event_handler_cb(staticWifiEventHandler);
}

void WifiEventsClass::onStationConnect(onStationConnectDelegate delegateFunction)
{
onSTAConnect = delegateFunction;
}

void WifiEventsClass::onStationDisconnect(onStationDisconnectDelegate delegateFunction)
{
onSTADisconnect = delegateFunction;
}

void WifiEventsClass::onStationAuthModeChange(onStationAuthModeChangeDelegate delegateFunction)
{
onSTAAuthModeChange = delegateFunction;
}

void WifiEventsClass::onStationGotIP(onStationGotIPDelegate delegateFunction)
{
onSTAGotIP = delegateFunction;
}

void WifiEventsClass::onAccessPointConnect(onAccessPointConnectDelegate delegateFunction)
{
onSOFTAPConnect = delegateFunction;
}

void WifiEventsClass::onAccessPointDisconnect(onAccessPointDisconnectDelegate delegateFunction)
{
onSOFTAPDisconnect = delegateFunction;
}

void WifiEventsClass::onAccessPointProbeReqRecved(onAccessPointProbeReqRecvedDelegate delegateFunction)
{
onSOFTAPProbeReqRecved = delegateFunction;
}

void WifiEventsClass::staticWifiEventHandler(System_Event_t *evt)
{
WifiEvents.WifiEventHandler(evt);
}

void WifiEventsClass::WifiEventHandler(System_Event_t *evt)
{
debugf("event %x\n", evt->event);

switch (evt->event)
{
case EVENT_STAMODE_CONNECTED:
debugf("connect to ssid %s, channel %d\n",
evt->event_info.connected.ssid,
evt->event_info.connected.channel);
if (onSTAConnect)
{
onSTAConnect((const char *)evt->event_info.connected.ssid,
evt->event_info.connected.ssid_len,
evt->event_info.connected.bssid,
evt->event_info.connected.channel);
}
break;
case EVENT_STAMODE_DISCONNECTED:
debugf("disconnect from ssid %s, reason %d\n",
evt->event_info.disconnected.ssid,
evt->event_info.disconnected.reason);
if (onSTADisconnect)
{
onSTADisconnect((const char *)evt->event_info.disconnected.ssid,
evt->event_info.disconnected.ssid_len,
evt->event_info.disconnected.bssid,
evt->event_info.disconnected.reason);
}
break;
case EVENT_STAMODE_AUTHMODE_CHANGE:
debugf("mode: %d -> %d\n",
evt->event_info.auth_change.old_mode,
evt->event_info.auth_change.new_mode);
if (onSTAAuthModeChange)
{
onSTAAuthModeChange(evt->event_info.auth_change.old_mode,
evt->event_info.auth_change.new_mode);
}
break;
case EVENT_STAMODE_GOT_IP:
debugf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR,
IP2STR(&evt->event_info.got_ip.ip),
IP2STR(&evt->event_info.got_ip.mask),
IP2STR(&evt->event_info.got_ip.gw));
debugf("\n");
if (onSTAGotIP)
{
onSTAGotIP(evt->event_info.got_ip.ip,
evt->event_info.got_ip.mask,
evt->event_info.got_ip.gw);
}
break;
case EVENT_SOFTAPMODE_STACONNECTED:
debugf("station: " MACSTR "join, AID = %d\n",
MAC2STR(evt->event_info.sta_connected.mac),
evt->event_info.sta_connected.aid);
if (onSOFTAPConnect)
{
onSOFTAPConnect(evt->event_info.sta_connected.mac, evt->event_info.sta_connected.aid);
}
break;
case EVENT_SOFTAPMODE_STADISCONNECTED:
debugf("station: " MACSTR "leave, AID = %d\n",
MAC2STR(evt->event_info.sta_disconnected.mac),
evt->event_info.sta_disconnected.aid);
if (onSOFTAPDisconnect)
{
onSOFTAPDisconnect(evt->event_info.sta_disconnected.mac, evt->event_info.sta_disconnected.aid);
}
break;
case EVENT_SOFTAPMODE_PROBEREQRECVED:
if (onSOFTAPDisconnect)
{
onSOFTAPProbeReqRecved(evt->event_info.ap_probereqrecved.rssi, evt->event_info.ap_probereqrecved.mac);
}
break;
default:
break;
}

}
52 changes: 52 additions & 0 deletions Sming/SmingCore/Platform/WifiEvents.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* WifiEvents.h
*
* Created on: 19 февр. 2016 г.
* Author: shurik
*/

#ifndef SMINGCORE_PLATFORM_WIFIEVENTS_H_
#define SMINGCORE_PLATFORM_WIFIEVENTS_H_

#include "../SmingCore/Delegate.h"
#include "../../Wiring/WString.h"
#include "../../Wiring/IPAddress.h"

//Define WifiEvents Delegates types
typedef Delegate<void(String, uint8_t, uint8_t[6], uint8_t)> onStationConnectDelegate;
typedef Delegate<void(String, uint8_t, uint8_t[6], uint8_t)> onStationDisconnectDelegate;
typedef Delegate<void(uint8_t, uint8_t)> onStationAuthModeChangeDelegate;
typedef Delegate<void(IPAddress, IPAddress, IPAddress)> onStationGotIPDelegate;
typedef Delegate<void(uint8_t[6], uint8_t)> onAccessPointConnectDelegate;
typedef Delegate<void(uint8_t[6], uint8_t)> onAccessPointDisconnectDelegate;
typedef Delegate<void(int16_t, uint8_t[6])> onAccessPointProbeReqRecvedDelegate;

class WifiEventsClass
{
public:
WifiEventsClass();

void onStationConnect(onStationConnectDelegate delegateFunction);
void onStationDisconnect(onStationDisconnectDelegate delegateFunction);
void onStationAuthModeChange(onStationAuthModeChangeDelegate delegateFunction);
void onStationGotIP(onStationGotIPDelegate delegateFunction);
void onAccessPointConnect(onAccessPointConnectDelegate delegateFunction);
void onAccessPointDisconnect(onAccessPointDisconnectDelegate delegateFunction);
void onAccessPointProbeReqRecved(onAccessPointProbeReqRecvedDelegate delegateFunction);

private:
static void staticWifiEventHandler(System_Event_t *evt);
void WifiEventHandler(System_Event_t *evt);

onStationConnectDelegate onSTAConnect = nullptr;
onStationDisconnectDelegate onSTADisconnect = nullptr;
onStationAuthModeChangeDelegate onSTAAuthModeChange = nullptr;
onStationGotIPDelegate onSTAGotIP = nullptr;
onAccessPointConnectDelegate onSOFTAPConnect = nullptr;
onAccessPointDisconnectDelegate onSOFTAPDisconnect = nullptr;
onAccessPointProbeReqRecvedDelegate onSOFTAPProbeReqRecved = nullptr;
};


extern WifiEventsClass WifiEvents;
#endif /* SMINGCORE_PLATFORM_WIFIEVENTS_H_ */
1 change: 1 addition & 0 deletions Sming/SmingCore/SmingCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "SPISoft.h"

#include "Platform/System.h"
#include "Platform/WifiEvents.h"
#include "Platform/Station.h"
#include "Platform/AccessPoint.h"
#include "Platform/WDT.h"
Expand Down
95 changes: 95 additions & 0 deletions samples/Basic_WebSkeletonApp/.cproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="0.131700304">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.131700304" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration buildProperties="" description="" id="0.131700304" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
<folderInfo id="0.131700304." name="/" resourcePath="">
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.481709424" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.481709424.1637922483" name=""/>
<builder id="org.eclipse.cdt.build.core.settings.default.builder.1861624051" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.927548352" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.1318259878" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.49095807" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.451866905" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.952230018" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.639761705" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.2127747414" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="Basic_WebSkeletonApp.null.1098635923" name="Basic_WebSkeletonApp"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="0.2058741737">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.c.compiler.mingw.base.2032390008;cdt.managedbuild.tool.gnu.c.compiler.input.1700912488">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="0.147001341">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="0.1962726862">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="0.358052692">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="0.131700304">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.454898447;cdt.managedbuild.tool.gnu.cpp.compiler.input.501261625">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="rebuild" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>rebuild</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="flash" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>flash</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
</cproject>
Loading

0 comments on commit c35c44b

Please sign in to comment.