Skip to content

Commit

Permalink
Initial support for Uno WiFi rev2
Browse files Browse the repository at this point in the history
Need to add a patch to Arduino_ConnectionHandler:

diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h
index 195ab13..8d80f2e 100644
--- a/src/Arduino_ConnectionHandler.h
+++ b/src/Arduino_ConnectionHandler.h
@@ -29,7 +29,8 @@
   #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED
 #endif

-#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT)
+#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \
+  defined(ARDUINO_AVR_UNO_WIFI_REV2)
   #include <WiFiNINA.h>
   #include <WiFiUdp.h>
  • Loading branch information
facchinm authored and aentinger committed Jan 26, 2021
1 parent 3a665ae commit 8482a1a
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/AIoTC_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
#define HAS_TCP
#endif

#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT)
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \
defined(ARDUINO_AVR_UNO_WIFI_REV2)
#define BOARD_HAS_OFFLOADED_ECCX08
#define HAS_TCP
#undef OTA_ENABLED
Expand Down
4 changes: 4 additions & 0 deletions src/cbor/CBORDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
/******************************************************************************
INCLUDE
******************************************************************************/
#ifdef __AVR__
#include <Arduino.h>
#include <ArduinoSTL.h>
#endif

#undef max
#undef min
Expand Down
5 changes: 5 additions & 0 deletions src/cbor/CBOREncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
* INCLUDE
******************************************************************************/

#ifdef __AVR__
#include <Arduino.h>
#include <ArduinoSTL.h>
#endif

#include "../property/PropertyContainer.h"

/******************************************************************************
Expand Down
5 changes: 5 additions & 0 deletions src/cbor/lib/tinycbor/src/cbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#ifndef CBOR_H
#define CBOR_H

#ifdef __AVR__
#define FP_NAN NAN
#define FP_INFINITE INFINITY
#endif

#ifndef assert
#include <assert.h>
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/cbor/lib/tinycbor/src/cborpretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
# define __STDC_LIMIT_MACROS 1
#endif

#ifndef __AVR__

#include "cbor.h"
#include "cborinternal_p.h"
#include "compilersupport_p.h"
Expand Down Expand Up @@ -580,4 +582,6 @@ CborError cbor_value_to_pretty_stream(CborStreamFunction streamFunction, void *t

#pragma GCC diagnostic pop

#endif // __AVR__

/** @} */
4 changes: 4 additions & 0 deletions src/cbor/lib/tinycbor/src/cbortojson.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
# define __STDC_LIMIT_MACROS 1
#endif

#ifndef __AVR__

#include "cbor.h"
#include "cborjson.h"
#include "cborinternal_p.h"
Expand Down Expand Up @@ -701,4 +703,6 @@ CborError cbor_value_to_json_advance(FILE *out, CborValue *value, int flags)

#pragma GCC diagnostic pop

#endif // __AVR__

/** @} */
4 changes: 4 additions & 0 deletions src/cbor/lib/tinycbor/src/open_memstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

#include <unistd.h>

#ifdef __AVR__
typedef size_t ssize_t;
#endif

typedef ssize_t RetType;
typedef size_t LenType;

Expand Down
235 changes: 235 additions & 0 deletions src/nonstd/nonstd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
#pragma once
#ifdef __AVR__
#include <Arduino.h>
extern void * operator new(size_t size, void * ptr);
namespace nonstd{

template<class T>struct tag{using type=T;};
template<class Tag>using type_t=typename Tag::type;

using size_t=decltype(sizeof(int));

//move

template<class T>
T&& move(T&t){return static_cast<T&&>(t);}

//forward

template<class T>
struct remove_reference:tag<T>{};
template<class T>
struct remove_reference<T&>:tag<T>{};
template<class T>using remove_reference_t=type_t<remove_reference<T>>;

template<class T>
T&& forward( remove_reference_t<T>& t ) {
return static_cast<T&&>(t);
}
template<class T>
T&& forward( remove_reference_t<T>&& t ) {
return static_cast<T&&>(t);
}

//decay

template<class T>
struct remove_const:tag<T>{};
template<class T>
struct remove_const<T const>:tag<T>{};

template<class T>
struct remove_volatile:tag<T>{};
template<class T>
struct remove_volatile<T volatile>:tag<T>{};

template<class T>
struct remove_cv:remove_const<type_t<remove_volatile<T>>>{};


template<class T>
struct decay3:remove_cv<T>{};
template<class R, class...Args>
struct decay3<R(Args...)>:tag<R(*)(Args...)>{};
template<class T>
struct decay2:decay3<T>{};
template<class T, size_t N>
struct decay2<T[N]>:tag<T*>{};

template<class T>
struct decay:decay2<remove_reference_t<T>>{};

template<class T>
using decay_t=type_t<decay<T>>;

//is_convertible

template<class T>
T declval(); // no implementation

template<class T, T t>
struct integral_constant{
static constexpr T value=t;
constexpr integral_constant() {};
constexpr operator T()const{ return value; }
constexpr T operator()()const{ return value; }
};
template<bool b>
using bool_t=integral_constant<bool, b>;
using true_type=bool_t<true>;
using false_type=bool_t<false>;

template<class...>struct voider:tag<void>{};
template<class...Ts>using void_t=type_t<voider<Ts...>>;

namespace details {
template<template<class...>class Z, class, class...Ts>
struct can_apply:false_type{};
template<template<class...>class Z, class...Ts>
struct can_apply<Z, void_t<Z<Ts...>>, Ts...>:true_type{};
}
template<template<class...>class Z, class...Ts>
using can_apply = details::can_apply<Z, void, Ts...>;

namespace details {
template<class From, class To>
using try_convert = decltype( To{declval<From>()} );
}
template<class From, class To>
struct is_convertible : can_apply< details::try_convert, From, To > {};
template<>
struct is_convertible<void,void>:true_type{};

//enable_if

template<bool, class=void>
struct enable_if {};
template<class T>
struct enable_if<true, T>:tag<T>{};
template<bool b, class T=void>
using enable_if_t=type_t<enable_if<b,T>>;

//res_of

namespace details {
template<class G, class...Args>
using invoke_t = decltype( declval<G>()(declval<Args>()...) );

template<class Sig,class=void>
struct res_of {};
template<class G, class...Args>
struct res_of<G(Args...), void_t<invoke_t<G, Args...>>>:
tag<invoke_t<G, Args...>>
{};
}
template<class Sig>
using res_of = details::res_of<Sig>;
template<class Sig>
using res_of_t=type_t<res_of<Sig>>;

//aligned_storage

template<size_t size, size_t align>
struct alignas(align) aligned_storage_t {
char buff[size];
};

//is_same

template<class A, class B>
struct is_same:false_type{};
template<class A>
struct is_same<A,A>:true_type{};

template<class Sig, size_t sz, size_t algn>
struct small_task;

template<class R, class...Args, size_t sz, size_t algn>
struct small_task<R(Args...), sz, algn>{
struct vtable_t {
void(*mover)(void* src, void* dest);
void(*destroyer)(void*);
R(*invoke)(void const* t, Args&&...args);
template<class T>
static vtable_t const* get() {
static const vtable_t table = {
[](void* src, void*dest) {
new(dest) T(move(*static_cast<T*>(src)));
},
[](void* t){ static_cast<T*>(t)->~T(); },
[](void const* t, Args&&...args)->R {
return (*static_cast<T const*>(t))(forward<Args>(args)...);
}
};
return &table;
}
};
vtable_t const* table = nullptr;
aligned_storage_t<sz, algn> data;
template<class F,
class dF=decay_t<F>,
enable_if_t<!is_same<dF, small_task>{}>* = nullptr,
enable_if_t<is_convertible< res_of_t<dF&(Args...)>, R >{}>* = nullptr
>
small_task( F&& f ):
table( vtable_t::template get<dF>() )
{
static_assert( sizeof(dF) <= sz, "object too large" );
static_assert( alignof(dF) <= algn, "object too aligned" );
new(&data) dF(forward<F>(f));
}
~small_task() {
if (table)
table->destroyer(&data);
}
small_task(const small_task& o):
table(o.table)
{
data = o.data;
}
small_task(small_task&& o):
table(o.table)
{
if (table)
table->mover(&o.data, &data);
}
small_task(){}
small_task& operator=(const small_task& o){
this->~small_task();
new(this) small_task( move(o) );
return *this;
}
small_task& operator=(small_task&& o){
this->~small_task();
new(this) small_task( move(o) );
return *this;
}
explicit operator bool()const{return table;}
R operator()(Args...args)const{
return table->invoke(&data, forward<Args>(args)...);
}
};

template<class R, class...Args, size_t sz, size_t algn>
inline bool operator==(const small_task<R(Args...), sz, algn>& __f, nullptr_t)
{ return !static_cast<bool>(__f); }

/// @overload
template<class R, class...Args, size_t sz, size_t algn>
inline bool operator==(nullptr_t, const small_task<R(Args...), sz, algn>& __f)
{ return !static_cast<bool>(__f); }

template<class R, class...Args, size_t sz, size_t algn>
inline bool operator!=(const small_task<R(Args...), sz, algn>& __f, nullptr_t)
{ return static_cast<bool>(__f); }

/// @overload
template<class R, class...Args, size_t sz, size_t algn>
inline bool operator!=(nullptr_t, const small_task<R(Args...), sz, algn>& __f)
{ return static_cast<bool>(__f); }

template<class Sig>
using function = small_task<Sig, sizeof(void*)*4, alignof(void*) >;
}

#endif
11 changes: 10 additions & 1 deletion src/property/Property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ CborError Property::appendAttributeReal(String value, String attributeName, Cbor
}, encoder);
}

CborError Property::appendAttributeName(String attributeName, std::function<CborError (CborEncoder& mapEncoder)>appendValue, CborEncoder *encoder) {
#ifdef __AVR__
CborError Property::appendAttributeName(String attributeName, nonstd::function<CborError (CborEncoder& mapEncoder)>appendValue, CborEncoder *encoder)
#else
CborError Property::appendAttributeName(String attributeName, std::function<CborError (CborEncoder& mapEncoder)>appendValue, CborEncoder *encoder)
#endif
{
if (attributeName != "") {
// when the attribute name string is not empty, the attribute identifier is incremented in order to be encoded in the message if the _lightPayload flag is set
_attributeIdentifier++;
Expand Down Expand Up @@ -271,7 +276,11 @@ void Property::setAttributeReal(String& value, String attributeName) {
});
}

#ifdef __AVR__
void Property::setAttributeReal(String attributeName, nonstd::function<void (CborMapData & md)>setValue)
#else
void Property::setAttributeReal(String attributeName, std::function<void (CborMapData & md)>setValue)
#endif
{
if (attributeName != "") {
_attributeIdentifier++;
Expand Down
11 changes: 10 additions & 1 deletion src/property/Property.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ typedef void(*OnSyncCallbackFunc)(Property &);
CLASS DECLARATION
******************************************************************************/

#ifdef __AVR__
#include "nonstd/nonstd.h"
#endif

class Property
{
public:
Expand Down Expand Up @@ -177,13 +181,18 @@ class Property
CborError appendAttributeReal(int value, String attributeName = "", CborEncoder *encoder = nullptr);
CborError appendAttributeReal(float value, String attributeName = "", CborEncoder *encoder = nullptr);
CborError appendAttributeReal(String value, String attributeName = "", CborEncoder *encoder = nullptr);
#ifndef __AVR__
CborError appendAttributeName(String attributeName, std::function<CborError (CborEncoder& mapEncoder)>f, CborEncoder *encoder);
void setAttributeReal(String attributeName, std::function<void (CborMapData & md)>setValue);
#else
CborError appendAttributeName(String attributeName, nonstd::function<CborError (CborEncoder& mapEncoder)>f, CborEncoder *encoder);
void setAttributeReal(String attributeName, nonstd::function<void (CborMapData & md)>setValue);
#endif
void setAttributesFromCloud(std::list<CborMapData> * map_data_list);
void setAttributeReal(bool& value, String attributeName = "");
void setAttributeReal(int& value, String attributeName = "");
void setAttributeReal(float& value, String attributeName = "");
void setAttributeReal(String& value, String attributeName = "");
void setAttributeReal(String attributeName, std::function<void (CborMapData & md)>setValue);
String getAttributeName(String propertyName, char separator);

virtual bool isDifferentFromCloud() = 0;
Expand Down

0 comments on commit 8482a1a

Please sign in to comment.