2015-04-05 02:10:37 +02:00
|
|
|
|
2016-03-11 22:23:00 +01:00
|
|
|
#include "cw.h"
|
2018-03-17 17:29:09 +01:00
|
|
|
|
2015-04-05 02:10:37 +02:00
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
#include "dbg.h"
|
2015-04-10 17:52:01 +02:00
|
|
|
#include "log.h"
|
2018-03-12 18:01:40 +01:00
|
|
|
#include "msgset.h"
|
2022-07-31 17:15:32 +02:00
|
|
|
#include "val.h"
|
2015-04-07 07:42:36 +02:00
|
|
|
|
2015-04-05 02:10:37 +02:00
|
|
|
|
2018-03-12 18:01:40 +01:00
|
|
|
int cw_out_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
|
|
|
, uint8_t * dst)
|
2015-04-05 02:10:37 +02:00
|
|
|
{
|
2018-05-07 10:57:12 +02:00
|
|
|
|
2022-07-31 17:15:32 +02:00
|
|
|
struct cw_Val * elem;
|
2018-03-24 07:56:05 +01:00
|
|
|
int start, len, l;
|
2018-03-15 20:07:17 +01:00
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
/* Get the element */
|
2018-05-14 23:30:48 +02:00
|
|
|
/* search.key=(char*)handler->key;
|
2018-03-15 20:07:17 +01:00
|
|
|
elem = mavl_get(params->conn->local_cfg, &search);
|
2018-05-14 23:30:48 +02:00
|
|
|
*/
|
2022-07-28 01:36:16 +02:00
|
|
|
elem = cw_ktv_get(params->local_cfg,handler->key,NULL);
|
2018-05-14 23:30:48 +02:00
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
/* if (elem == NULL && params->conn->default_cfg !=NULL)
|
|
|
|
elem = mavl_get(params->conn->default_cfg, &search);
|
|
|
|
*/
|
2018-03-12 18:01:40 +01:00
|
|
|
if (elem == NULL) {
|
2015-04-19 16:44:20 +02:00
|
|
|
const char *vendor="";
|
2018-03-12 18:01:40 +01:00
|
|
|
if ( handler->vendor ) {
|
|
|
|
vendor=cw_strvendor(handler->vendor);
|
2015-04-19 16:44:20 +02:00
|
|
|
}
|
2018-03-15 20:07:17 +01:00
|
|
|
if ( params->elemdata->mand) {
|
|
|
|
cw_log(LOG_ERR,
|
2018-03-20 18:47:06 +01:00
|
|
|
"Can't put mandatory element %s %d-(%s) into %s. No value for '%s' found.",
|
|
|
|
vendor, handler->id, handler->name, params->msgdata->name
|
2018-03-15 20:07:17 +01:00
|
|
|
, handler->key
|
2015-04-11 19:00:51 +02:00
|
|
|
);
|
2018-03-15 20:07:17 +01:00
|
|
|
}
|
2015-04-11 19:00:51 +02:00
|
|
|
else{
|
2018-02-26 18:28:12 +01:00
|
|
|
/* cw_dbg(DBG_WARN,"No output for element %s%d -(%s) in %s. Item %s not found.",
|
2015-04-19 16:44:20 +02:00
|
|
|
vendor,
|
2015-04-11 19:00:51 +02:00
|
|
|
a->elem_id, cw_strelemp(conn->actions, a->elem_id)
|
|
|
|
, cw_strmsg(a->msg_id),a->item_id);
|
2018-02-26 18:28:12 +01:00
|
|
|
*/
|
2015-04-07 07:42:36 +02:00
|
|
|
}
|
|
|
|
return 0;
|
2018-03-12 18:01:40 +01:00
|
|
|
}
|
2018-03-27 07:07:14 +02:00
|
|
|
|
|
|
|
/* Size for msg elem header depends on
|
|
|
|
vendor specific payload */
|
2018-04-09 09:27:38 +02:00
|
|
|
/* start = handler->vendor ? 10 : 4; */
|
2022-07-29 12:11:19 +02:00
|
|
|
start = params->msgset->header_len(handler);
|
2018-04-09 09:27:38 +02:00
|
|
|
|
2018-05-14 23:30:48 +02:00
|
|
|
if (cw_ktv_cast(elem,handler->type)==NULL){
|
|
|
|
cw_log(LOG_ERR,"Can't put element '%s'- can't cast from %s to %s for key: %s", handler->name,
|
|
|
|
elem->type->name, ((const cw_Type_t*)handler->type)->name, handler->key);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-25 22:38:07 +02:00
|
|
|
len = ((const cw_Type_t*)(handler->type))->put(elem,dst+start);
|
2018-03-27 07:07:14 +02:00
|
|
|
|
|
|
|
/* ((const cw_Type_t*)(handler->type))->to_str(elem,detail,120);
|
2018-03-20 18:47:06 +01:00
|
|
|
sprintf(params->debug_details, " Value = %s", detail);
|
2018-03-27 07:07:14 +02:00
|
|
|
params->elem = elem;*/
|
2015-04-05 20:27:17 +02:00
|
|
|
|
2018-04-09 09:27:38 +02:00
|
|
|
/* if (handler->vendor)
|
2018-03-12 18:01:40 +01:00
|
|
|
return len + cw_put_elem_vendor_hdr(dst, handler->vendor, handler->id, len);
|
2015-04-05 20:27:17 +02:00
|
|
|
|
2018-04-09 09:27:38 +02:00
|
|
|
l = len + cw_put_elem_hdr(dst, handler->id, len); */
|
2022-07-29 12:11:19 +02:00
|
|
|
l = params->msgset->write_header(handler,dst,len);
|
2018-04-09 09:27:38 +02:00
|
|
|
|
2022-07-28 01:36:16 +02:00
|
|
|
cw_dbg_elem(DBG_ELEM_OUT,NULL,params->msgdata->type,handler,dst,l);
|
|
|
|
/* cw_dbg_elem(DBG_ELEM_OUT,params->conn,params->msgdata->type,handler,dst,l);*/
|
|
|
|
|
2018-03-24 07:56:05 +01:00
|
|
|
return l;
|
2015-04-05 02:10:37 +02:00
|
|
|
}
|
2015-04-28 10:23:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|