FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:dbad57390bd1 1 #pragma once
ram54288 0:dbad57390bd1 2
ram54288 0:dbad57390bd1 3 #include "mbed-client/m2mdevice.h"
ram54288 0:dbad57390bd1 4 #include "mbed-client/m2minterfacefactory.h"
ram54288 0:dbad57390bd1 5 #include "mbed-client/m2minterface.h"
ram54288 0:dbad57390bd1 6
ram54288 0:dbad57390bd1 7 class frdm_client : public M2MInterfaceObserver
ram54288 0:dbad57390bd1 8 {
ram54288 0:dbad57390bd1 9 public:
ram54288 0:dbad57390bd1 10 struct state
ram54288 0:dbad57390bd1 11 {
ram54288 0:dbad57390bd1 12 enum
ram54288 0:dbad57390bd1 13 {
ram54288 0:dbad57390bd1 14 initialized,
ram54288 0:dbad57390bd1 15 boostrapped,
ram54288 0:dbad57390bd1 16 registered,
ram54288 0:dbad57390bd1 17 unregistered,
ram54288 0:dbad57390bd1 18 error
ram54288 0:dbad57390bd1 19 };
ram54288 0:dbad57390bd1 20 };
ram54288 0:dbad57390bd1 21
ram54288 0:dbad57390bd1 22 public:
ram54288 0:dbad57390bd1 23 static M2MDevice* make_device();
ram54288 0:dbad57390bd1 24
ram54288 0:dbad57390bd1 25 public:
ram54288 0:dbad57390bd1 26 static const M2MInterface::NetworkStack stack_type = M2MInterface::LwIP_IPv4;
ram54288 0:dbad57390bd1 27 static const M2MInterface::BindingMode socket_mode = M2MInterface::TCP;
ram54288 0:dbad57390bd1 28
ram54288 0:dbad57390bd1 29 public:
ram54288 0:dbad57390bd1 30 frdm_client(const String& server_address, void* handler = NULL);
ram54288 0:dbad57390bd1 31 ~frdm_client();
ram54288 0:dbad57390bd1 32
ram54288 0:dbad57390bd1 33 public:
ram54288 0:dbad57390bd1 34 void connect(const M2MObjectList& objects);
ram54288 0:dbad57390bd1 35 void disconnect();
ram54288 0:dbad57390bd1 36
ram54288 0:dbad57390bd1 37 virtual void bootstrap_done(M2MSecurity* security) { if (security) m_state = state::boostrapped; }
ram54288 0:dbad57390bd1 38 virtual void object_registered(M2MSecurity*, const M2MServer&) { m_state = state::registered; }
ram54288 0:dbad57390bd1 39 virtual void object_unregistered(M2MSecurity*) { m_state = state::unregistered; }
ram54288 0:dbad57390bd1 40 virtual void registration_updated(M2MSecurity*, const M2MServer&) {}
ram54288 0:dbad57390bd1 41 virtual void value_updated(M2MBase*, M2MBase::BaseType) {}
ram54288 0:dbad57390bd1 42 virtual void error(M2MInterface::Error error) { m_state = state::error; }
ram54288 0:dbad57390bd1 43
ram54288 0:dbad57390bd1 44 int get_state() const { return m_state; }
ram54288 0:dbad57390bd1 45 M2MSecurity* get_security() const { return m_security; }
ram54288 0:dbad57390bd1 46
ram54288 0:dbad57390bd1 47 private:
ram54288 0:dbad57390bd1 48 String m_address;
ram54288 0:dbad57390bd1 49 volatile int m_state;
ram54288 0:dbad57390bd1 50
ram54288 0:dbad57390bd1 51 M2MInterface* m_interface;
ram54288 0:dbad57390bd1 52 M2MSecurity* m_security;
ram54288 0:dbad57390bd1 53 };
ram54288 0:dbad57390bd1 54