A metronome using the FRDM K64F board

Committer:
ram54288
Date:
Sun May 14 18:40:18 2017 +0000
Revision:
0:a7a43371b306
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:a7a43371b306 1 #include "frdm_client.hpp"
ram54288 0:a7a43371b306 2
ram54288 0:a7a43371b306 3 #include "mbed-client/m2mdevice.h"
ram54288 0:a7a43371b306 4 #include "security.h"
ram54288 0:a7a43371b306 5
ram54288 0:a7a43371b306 6 M2MDevice* frdm_client::make_device()
ram54288 0:a7a43371b306 7 {
ram54288 0:a7a43371b306 8 M2MDevice* device = M2MInterfaceFactory::create_device();
ram54288 0:a7a43371b306 9 if (!device)
ram54288 0:a7a43371b306 10 return NULL;
ram54288 0:a7a43371b306 11
ram54288 0:a7a43371b306 12 device->create_resource(M2MDevice::Manufacturer, "Freescale");
ram54288 0:a7a43371b306 13 device->create_resource(M2MDevice::DeviceType, "FRDM");
ram54288 0:a7a43371b306 14 device->create_resource(M2MDevice::ModelNumber, "K64F");
ram54288 0:a7a43371b306 15
ram54288 0:a7a43371b306 16 return device;
ram54288 0:a7a43371b306 17 }
ram54288 0:a7a43371b306 18
ram54288 0:a7a43371b306 19 frdm_client::frdm_client(const String& server_address, void* handler)
ram54288 0:a7a43371b306 20 : m_address(server_address), m_state(state::initialized)
ram54288 0:a7a43371b306 21 {
ram54288 0:a7a43371b306 22 String endpoint_type = "";
ram54288 0:a7a43371b306 23 String context_addr = "";
ram54288 0:a7a43371b306 24
ram54288 0:a7a43371b306 25 int32_t lifetime = 100;
ram54288 0:a7a43371b306 26 uint16_t port = 0;
ram54288 0:a7a43371b306 27
ram54288 0:a7a43371b306 28 m_interface = M2MInterfaceFactory::create_interface
ram54288 0:a7a43371b306 29 (
ram54288 0:a7a43371b306 30 *this,
ram54288 0:a7a43371b306 31 MBED_ENDPOINT_NAME, endpoint_type,
ram54288 0:a7a43371b306 32 lifetime,
ram54288 0:a7a43371b306 33 port, MBED_DOMAIN, socket_mode, stack_type, context_addr
ram54288 0:a7a43371b306 34 );
ram54288 0:a7a43371b306 35
ram54288 0:a7a43371b306 36 if (!m_interface)
ram54288 0:a7a43371b306 37 {
ram54288 0:a7a43371b306 38 m_state = state::error;
ram54288 0:a7a43371b306 39 return;
ram54288 0:a7a43371b306 40 }
ram54288 0:a7a43371b306 41
ram54288 0:a7a43371b306 42 m_security = M2MInterfaceFactory::create_security(M2MSecurity::M2MServer);
ram54288 0:a7a43371b306 43 if (!m_security)
ram54288 0:a7a43371b306 44 {
ram54288 0:a7a43371b306 45 m_state = state::error;
ram54288 0:a7a43371b306 46 return;
ram54288 0:a7a43371b306 47 }
ram54288 0:a7a43371b306 48
ram54288 0:a7a43371b306 49 m_security->set_resource_value(M2MSecurity::M2MServerUri, m_address);
ram54288 0:a7a43371b306 50 m_security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Certificate);
ram54288 0:a7a43371b306 51 m_security->set_resource_value(M2MSecurity::ServerPublicKey, SERVER_CERT, sizeof(SERVER_CERT)-1);
ram54288 0:a7a43371b306 52 m_security->set_resource_value(M2MSecurity::PublicKey, CERT, sizeof(CERT)-1);
ram54288 0:a7a43371b306 53 m_security->set_resource_value(M2MSecurity::Secretkey, KEY, sizeof(KEY)-1);
ram54288 0:a7a43371b306 54
ram54288 0:a7a43371b306 55 m_interface->set_platform_network_handler(handler);
ram54288 0:a7a43371b306 56 }
ram54288 0:a7a43371b306 57
ram54288 0:a7a43371b306 58 frdm_client::~frdm_client()
ram54288 0:a7a43371b306 59 {
ram54288 0:a7a43371b306 60 delete m_interface;
ram54288 0:a7a43371b306 61 delete m_security;
ram54288 0:a7a43371b306 62 }
ram54288 0:a7a43371b306 63
ram54288 0:a7a43371b306 64 void frdm_client::connect(const M2MObjectList& objects)
ram54288 0:a7a43371b306 65 {
ram54288 0:a7a43371b306 66 m_interface->register_object(m_security, objects);
ram54288 0:a7a43371b306 67 }
ram54288 0:a7a43371b306 68
ram54288 0:a7a43371b306 69 void frdm_client::disconnect()
ram54288 0:a7a43371b306 70 {
ram54288 0:a7a43371b306 71 m_interface->unregister_object(NULL);
ram54288 0:a7a43371b306 72 }
ram54288 0:a7a43371b306 73