actube/src/cw/cw_out_radio_generic_struct.c

148 lines
2.8 KiB
C
Raw Normal View History

#include "cw.h"
#include "dbg.h"
int cw_ktv_idx_get_next(mavl_t ktv, const char *key, int n);
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
/*
int i,l, offset;
uint8_t * cdst;
cdst = dst;
offset = params->msgset->header_len(handler);
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;
2022-08-13 09:47:12 +02:00
i = cw_ktv_idx_get_next(params->cfg,"radio",i+1);
if (i==-1)
break;
sprintf(basekey,"radio.%d/%s",i,handler->key);
2022-08-13 09:47:12 +02:00
result = cw_ktv_base_exists(params->cfg,basekey);
if (result == NULL){
continue;
}
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);
cdst+=params->msgset->write_header(handler,cdst,l);
}
return cdst-dst;
}
int cw_out_traverse0(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
, uint8_t * dst, int i, const char *current, const char * next,
int * stack)
{
char *sl;
int l;
2022-08-14 12:26:34 +02:00
char key[CW_CFG_MAX_KEY_LEN];
int len;
len = 0;
printf("Next: %s\n", next);
sl = strchr(next,'/');
if (sl==NULL){
2022-07-31 17:15:32 +02:00
cw_Val_t * result;
sprintf(key,"%s/%s",current,next);
2022-08-13 09:47:12 +02:00
result = cw_ktv_base_exists(params->cfg,key);
if (result != NULL){
int offset;
int i,l;
offset = params->msgset->header_len(handler);
printf("Yea! We can do it: %s\n",result->key);
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,
handler->type,key,dst+offset);
printf("Write struct len %i\n",l);
l=params->msgset->write_header(handler,dst,l);
printf("header wr len %d\n",l);
if (handler->patch){
handler->patch(dst+offset,stack);
}
return l;
}
return 0;
}
strcpy(key,current);
printf("current is %s\n", current);
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" );
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;
2022-08-13 09:47:12 +02:00
i = cw_ktv_idx_get_next(params->cfg,key,i+1);
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);
if (result == NULL){
continue;
}
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);
}
return len;
2022-08-14 13:31:58 +02:00
*/
return 0;
}
int cw_out_traverse(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
, uint8_t * dst)
{
2022-08-14 12:26:34 +02:00
char current[CW_CFG_MAX_KEY_LEN];
int stack[10];
stack[0]=0;
current[0]=0;
2022-08-14 13:31:58 +02:00
stop();
return 0;
2022-08-14 13:31:58 +02:00
// return cw_out_traverse0(handler,params,dst,-1,current,handler->key, stack);
}