2018-04-17 07:46:09 +02:00
|
|
|
|
|
|
|
#include "cw.h"
|
|
|
|
#include "dbg.h"
|
|
|
|
|
2018-05-07 23:29:35 +02:00
|
|
|
int cw_ktv_idx_get_next(mavl_t ktv, const char *key, int n);
|
|
|
|
|
2018-04-17 07:46:09 +02:00
|
|
|
int cw_out_radio_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
|
|
|
, uint8_t * dst)
|
|
|
|
{
|
2022-08-14 12:26:34 +02:00
|
|
|
cw_dbg(DBG_X,"KEY: %s",handler->key);
|
2022-08-13 09:47:12 +02:00
|
|
|
stop();
|
2022-08-14 13:31:58 +02:00
|
|
|
/*
|
2018-04-17 07:46:09 +02:00
|
|
|
int i,l, offset;
|
2018-05-20 20:29:40 +02:00
|
|
|
|
2018-04-17 07:46:09 +02:00
|
|
|
uint8_t * cdst;
|
|
|
|
|
|
|
|
cdst = dst;
|
|
|
|
|
|
|
|
|
2022-07-29 12:11:19 +02:00
|
|
|
offset = params->msgset->header_len(handler);
|
2018-05-20 20:29:40 +02:00
|
|
|
|
2018-05-07 23:29:35 +02:00
|
|
|
i=-1;
|
|
|
|
while(1){
|
2022-08-14 12:26:34 +02:00
|
|
|
char basekey[CW_CFG_MAX_KEY_LEN];
|
2022-07-31 17:15:32 +02:00
|
|
|
cw_Val_t * result;
|
2018-05-07 23:29:35 +02:00
|
|
|
|
2022-08-13 09:47:12 +02:00
|
|
|
i = cw_ktv_idx_get_next(params->cfg,"radio",i+1);
|
2018-05-07 23:29:35 +02:00
|
|
|
if (i==-1)
|
|
|
|
break;
|
2018-04-17 07:46:09 +02:00
|
|
|
sprintf(basekey,"radio.%d/%s",i,handler->key);
|
|
|
|
|
2022-08-13 09:47:12 +02:00
|
|
|
result = cw_ktv_base_exists(params->cfg,basekey);
|
2018-05-07 23:29:35 +02:00
|
|
|
if (result == NULL){
|
2018-04-17 07:46:09 +02:00
|
|
|
continue;
|
2018-05-07 23:29:35 +02:00
|
|
|
}
|
2018-04-17 07:46:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
l=0;
|
|
|
|
l+=cw_put_byte(cdst+offset+l,i);
|
2022-08-13 09:47:12 +02:00
|
|
|
l+= cw_ktv_write_struct(params->cfg,NULL, handler->type,basekey,cdst+offset+l);
|
2018-04-17 07:46:09 +02:00
|
|
|
|
|
|
|
|
2022-07-29 12:11:19 +02:00
|
|
|
cdst+=params->msgset->write_header(handler,cdst,l);
|
2018-05-20 20:29:40 +02:00
|
|
|
}
|
|
|
|
return cdst-dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int cw_out_traverse0(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
2018-05-22 07:15:52 +02:00
|
|
|
, uint8_t * dst, int i, const char *current, const char * next,
|
|
|
|
int * stack)
|
2018-05-20 20:29:40 +02:00
|
|
|
{
|
|
|
|
char *sl;
|
|
|
|
int l;
|
2022-08-14 12:26:34 +02:00
|
|
|
char key[CW_CFG_MAX_KEY_LEN];
|
2018-05-22 07:15:52 +02:00
|
|
|
int len;
|
|
|
|
len = 0;
|
2022-07-30 19:44:57 +02:00
|
|
|
|
|
|
|
printf("Next: %s\n", next);
|
|
|
|
|
2018-05-20 20:29:40 +02:00
|
|
|
sl = strchr(next,'/');
|
|
|
|
if (sl==NULL){
|
2022-07-31 17:15:32 +02:00
|
|
|
cw_Val_t * result;
|
2018-05-20 20:29:40 +02:00
|
|
|
sprintf(key,"%s/%s",current,next);
|
2022-08-13 09:47:12 +02:00
|
|
|
result = cw_ktv_base_exists(params->cfg,key);
|
2018-05-20 20:29:40 +02:00
|
|
|
if (result != NULL){
|
2018-05-22 07:15:52 +02:00
|
|
|
int offset;
|
|
|
|
int i,l;
|
2022-07-29 12:11:19 +02:00
|
|
|
offset = params->msgset->header_len(handler);
|
2018-05-20 20:29:40 +02:00
|
|
|
printf("Yea! We can do it: %s\n",result->key);
|
2018-05-22 07:15:52 +02:00
|
|
|
for (i=0;i<stack[0];i++){
|
|
|
|
printf("I=%i\n",stack[i+1]);
|
|
|
|
}
|
2022-08-14 12:26:34 +02:00
|
|
|
l= cw_ktv_write_struct(params->cfg,params->cfg,
|
2018-05-22 07:15:52 +02:00
|
|
|
handler->type,key,dst+offset);
|
|
|
|
|
|
|
|
printf("Write struct len %i\n",l);
|
|
|
|
|
2022-07-29 12:11:19 +02:00
|
|
|
l=params->msgset->write_header(handler,dst,l);
|
2018-05-22 07:15:52 +02:00
|
|
|
printf("header wr len %d\n",l);
|
|
|
|
if (handler->patch){
|
|
|
|
handler->patch(dst+offset,stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
return l;
|
2018-05-20 20:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(key,current);
|
2022-07-30 19:44:57 +02:00
|
|
|
|
|
|
|
printf("current is %s\n", current);
|
|
|
|
|
2018-05-20 20:29:40 +02:00
|
|
|
if (key[0!=0])
|
|
|
|
strcat(key,"/");
|
|
|
|
l = sl - next;
|
|
|
|
strncat(key,next,l);
|
|
|
|
|
|
|
|
|
|
|
|
printf("Here we are %s\n",key);
|
2022-08-13 09:47:12 +02:00
|
|
|
cw_dbg_ktv_dump(params->cfg,DBG_INFO,"start"," ", "end" );
|
2018-05-20 20:29:40 +02:00
|
|
|
i=-1;
|
|
|
|
while(1){
|
2022-08-14 12:26:34 +02:00
|
|
|
char basekey[CW_CFG_MAX_KEY_LEN];
|
2022-07-31 17:15:32 +02:00
|
|
|
cw_Val_t * result;
|
2018-04-17 07:46:09 +02:00
|
|
|
|
2022-08-13 09:47:12 +02:00
|
|
|
i = cw_ktv_idx_get_next(params->cfg,key,i+1);
|
2022-07-30 19:44:57 +02:00
|
|
|
|
2018-05-20 20:29:40 +02:00
|
|
|
if (i==-1)
|
|
|
|
break;
|
|
|
|
sprintf(basekey,"%s.%d",key,i);
|
|
|
|
printf("Our basekey is %s\n",basekey);
|
2022-08-13 09:47:12 +02:00
|
|
|
result = cw_ktv_base_exists(params->cfg,basekey);
|
2018-05-20 20:29:40 +02:00
|
|
|
if (result == NULL){
|
|
|
|
continue;
|
|
|
|
}
|
2018-05-07 23:29:35 +02:00
|
|
|
|
2018-05-22 07:15:52 +02:00
|
|
|
stack[0]++;
|
|
|
|
stack[stack[0]]=i;
|
|
|
|
len += cw_out_traverse0(handler,params,dst+len,-1,basekey,next+l+1, stack);
|
|
|
|
printf("Len is now %d\n", len);
|
2018-04-17 07:46:09 +02:00
|
|
|
}
|
2018-05-20 20:29:40 +02:00
|
|
|
|
|
|
|
|
2018-05-22 07:15:52 +02:00
|
|
|
return len;
|
2022-08-14 13:31:58 +02:00
|
|
|
*/
|
|
|
|
return 0;
|
2018-04-17 07:46:09 +02:00
|
|
|
}
|
2018-05-20 20:29:40 +02:00
|
|
|
|
|
|
|
int cw_out_traverse(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
|
|
|
, uint8_t * dst)
|
|
|
|
|
|
|
|
{
|
2018-05-22 07:15:52 +02:00
|
|
|
|
2022-08-14 12:26:34 +02:00
|
|
|
char current[CW_CFG_MAX_KEY_LEN];
|
2018-05-22 07:15:52 +02:00
|
|
|
int stack[10];
|
|
|
|
stack[0]=0;
|
2018-05-20 20:29:40 +02:00
|
|
|
|
|
|
|
current[0]=0;
|
2022-07-30 19:44:57 +02:00
|
|
|
|
2022-08-14 13:31:58 +02:00
|
|
|
stop();
|
|
|
|
return 0;
|
2018-05-20 20:29:40 +02:00
|
|
|
|
2022-08-14 13:31:58 +02:00
|
|
|
// return cw_out_traverse0(handler,params,dst,-1,current,handler->key, stack);
|
2018-05-20 20:29:40 +02:00
|
|
|
}
|
|
|
|
|