Commit 16f583cb authored by Mall, Anon's avatar Mall, Anon
Browse files

notify added for check and min height max height resources added

parent 589e5558
......@@ -285,11 +285,104 @@ void CoapFrontend::hnd_put_offset(coap_context_t *ctx UNUSED_PARAM,
}
}
void CoapFrontend::s_get_max_height(coap_context_t *ctx UNUSED_PARAM,
struct coap_resource_t *resource UNUSED_PARAM,
const coap_endpoint_t *local_interface UNUSED_PARAM,
coap_address_t *peer UNUSED_PARAM,
coap_pdu_t *request UNUSED_PARAM,
str *token UNUSED_PARAM,
coap_pdu_t *response)
{
CoapFrontend *cf = s_callbackMap.at(resource);
cf->hnd_get_max_height(ctx, resource, local_interface, peer, request, token, response);
}
void CoapFrontend::hnd_get_max_height(coap_context_t *ctx,
struct coap_resource_t *resource,
const coap_endpoint_t *local_interface UNUSED_PARAM,
coap_address_t *peer,
coap_pdu_t *request,
str *token,
coap_pdu_t *response)
{
coap_opt_iterator_t opt_iter;
coap_opt_t *option;
unsigned char buf[40];
size_t len;
time_t now;
coap_tick_t t;
response->hdr->code = COAP_RESPONSE_CODE(205);
if (coap_find_observer(resource, peer, token))
{
coap_add_option(response,
COAP_OPTION_OBSERVE,
coap_encode_var_bytes(buf, ctx->observe), buf);
}
coap_add_option(response,
COAP_OPTION_CONTENT_FORMAT,
coap_encode_var_bytes(buf, COAP_MEDIATYPE_TEXT_PLAIN), buf);
len = snprintf((char*)buf, sizeof(buf), "%d", m_controller.getMaxHeight());
cout << "max Height: " << m_controller.getMaxHeight() << endl;
coap_add_data(response, len, buf);
}
void CoapFrontend::s_get_min_height(coap_context_t *ctx UNUSED_PARAM,
struct coap_resource_t *resource UNUSED_PARAM,
const coap_endpoint_t *local_interface UNUSED_PARAM,
coap_address_t *peer UNUSED_PARAM,
coap_pdu_t *request UNUSED_PARAM,
str *token UNUSED_PARAM,
coap_pdu_t *response)
{
CoapFrontend *cf = s_callbackMap.at(resource);
cf->hnd_get_min_height(ctx, resource, local_interface, peer, request, token, response);
}
void CoapFrontend::hnd_get_min_height(coap_context_t *ctx,
struct coap_resource_t *resource,
const coap_endpoint_t *local_interface UNUSED_PARAM,
coap_address_t *peer,
coap_pdu_t *request,
str *token,
coap_pdu_t *response)
{
coap_opt_iterator_t opt_iter;
coap_opt_t *option;
unsigned char buf[40];
size_t len;
time_t now;
coap_tick_t t;
response->hdr->code = COAP_RESPONSE_CODE(205);
if (coap_find_observer(resource, peer, token))
{
coap_add_option(response,
COAP_OPTION_OBSERVE,
coap_encode_var_bytes(buf, ctx->observe), buf);
}
coap_add_option(response,
COAP_OPTION_CONTENT_FORMAT,
coap_encode_var_bytes(buf, COAP_MEDIATYPE_TEXT_PLAIN), buf);
len = snprintf((char*)buf, sizeof(buf), "%d", m_controller.getMinHeight());
cout << "min Height: " << m_controller.getMinHeight() << endl;
coap_add_data(response, len, buf);
}
void CoapFrontend::init_resources(coap_context_t *ctx)
{
coap_resource_t *root;
coap_resource_t *height;
coap_resource_t *offset;
coap_resource_t *max_height;
coap_resource_t *min_height;
// root
root = coap_resource_init(NULL, 0, 0);
......@@ -318,6 +411,20 @@ void CoapFrontend::init_resources(coap_context_t *ctx)
offset->observable = 1;
coap_add_resource(ctx, offset);
m_res_offset = offset;
//max_height
max_height = coap_resource_init((unsigned char *)"max height", 10, COAP_RESOURCE_FLAGS_NOTIFY_CON);
s_callbackMap.emplace(max_height, this);
coap_register_handler(max_height, COAP_REQUEST_GET, s_get_max_height);
coap_add_resource(ctx, max_height);
m_res_max_height = max_height;
//min_height
min_height = coap_resource_init((unsigned char *)"min height", 10, COAP_RESOURCE_FLAGS_NOTIFY_CON);
s_callbackMap.emplace(min_height, this);
coap_register_handler(min_height, COAP_REQUEST_GET, s_get_min_height);
coap_add_resource(ctx, min_height);
m_res_min_height = min_height;
}
coap_context_t *
......@@ -384,14 +491,17 @@ void CoapFrontend::notify(DeskNotification &notification)
{
case DeskNotification::Type::current_height:
cout << __PRETTY_FUNCTION__ << ": height=" << notification.value << endl;
m_res_height->dirty = 1;
break;
case DeskNotification::Type::target_height:
cout << __PRETTY_FUNCTION__ << ": target_height=" << notification.value << endl;
break;
case DeskNotification::Type::offset:
cout << __PRETTY_FUNCTION__ << ": offset=" << notification.value << endl;
m_res_offset->dirty = 1;
break;
}
coap_check_notify(m_ccontext);
}
void CoapFrontend::check_async(coap_context_t *ctx,
......
......@@ -88,6 +88,22 @@ protected:
coap_pdu_t *request,
str *token,
coap_pdu_t *response);
static void s_get_min_height(coap_context_t *ctx,
struct coap_resource_t *resource,
const coap_endpoint_t *local_interface,
coap_address_t *peer,
coap_pdu_t *request,
str *token,
coap_pdu_t *response);
static void s_get_max_height(coap_context_t *ctx,
struct coap_resource_t *resource,
const coap_endpoint_t *local_interface,
coap_address_t *peer,
coap_pdu_t *request,
str *token,
coap_pdu_t *response);
coap_context_t* get_context(const char *node, int port);
......@@ -133,6 +149,22 @@ protected:
str *token,
coap_pdu_t *response);
static void hnd_get_max_height(coap_context_t *ctx,
struct coap_resource_t *resource,
const coap_endpoint_t *local_interface,
coap_address_t *peer,
coap_pdu_t *request,
str *token,
coap_pdu_t *response);
static void hnd_get_min_height(coap_context_t *ctx,
struct coap_resource_t *resource,
const coap_endpoint_t *local_interface,
coap_address_t *peer,
coap_pdu_t *request,
str *token,
coap_pdu_t *response);
virtual void notify(DeskNotification& height);
void check_async(coap_context_t *ctx,
......@@ -148,6 +180,8 @@ protected:
coap_async_state_t* m_async;
coap_resource_t* m_res_height;
coap_resource_t* m_res_offset;
coap_resource_t* m_res_min_height;
coap_resource_t* m_res_max_height;
std::condition_variable m_ctxWait;
std::mutex m_ctxMutex;
bool m_constructFinished;
......
......@@ -131,7 +131,11 @@ DummyDesk::doDeskControl()
}
LinakDesk::LinakDesk(std::string offset_file):
m_stopDelay(STOP_DELAY),
m_smallStepTime(SMALL_STEP_TIME),
Controller(offset_file),
m_minHeight(MIN_HEIGHT+m_offset),
m_maxHeight(MAX_HEIGHT+m_offset),
m_smallStep(false),
m_finished(true)
{
......
......@@ -96,11 +96,17 @@ class LinakDesk : public Controller
virtual void doDeskControl(void);
virtual void setHeight(int height);
virtual int getHeight();
int getMaxHeight(void){return m_maxHeight};
int getMinHeight(void){return m_minHeight};
uint16_t move(Command cmd);
virtual ~LinakDesk();
protected:
int getInternalHeight();
int m_minHeight;
int m_maxHeight;
int m_stopDelay;
int m_smallStepTime;
std::mutex m_cmdMutex;
std::mutex m_busMutex;
libusb_device_handle *m_udev;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment