2022-07-31 17:15:32 +02:00
|
|
|
#include "val.h"
|
2018-04-07 19:28:00 +02:00
|
|
|
#include "dbg.h"
|
|
|
|
#include "log.h"
|
2022-08-14 12:26:34 +02:00
|
|
|
#include "cfg.h"
|
2018-04-07 19:28:00 +02:00
|
|
|
|
2022-07-31 17:15:32 +02:00
|
|
|
int cw_ktv_write_struct(mavl_t ktv, mavl_t def, const cw_ValStruct_t * stru, const char *pkey,
|
2018-04-07 19:28:00 +02:00
|
|
|
uint8_t * dst)
|
|
|
|
{
|
2022-08-14 12:26:34 +02:00
|
|
|
char key[CW_CFG_MAX_KEY_LEN];
|
2018-04-07 19:28:00 +02:00
|
|
|
int pos, i;
|
2022-07-31 17:15:32 +02:00
|
|
|
cw_Val_t * result;
|
2018-04-07 19:28:00 +02:00
|
|
|
|
|
|
|
pos=0; i=0;
|
|
|
|
for(i=0; stru[i].type != NULL;i++){
|
|
|
|
|
|
|
|
if (stru[i].position!=-1){
|
|
|
|
pos=stru[i].position;
|
|
|
|
}
|
2018-04-22 09:00:55 +02:00
|
|
|
if (stru[i].len!=-1)
|
|
|
|
memset(dst+pos,0,stru[i].len);
|
2018-04-07 19:28:00 +02:00
|
|
|
|
2018-04-27 14:04:03 +02:00
|
|
|
|
|
|
|
if (stru[i].key!=NULL)
|
|
|
|
sprintf(key,"%s/%s",pkey,stru[i].key);
|
|
|
|
else
|
|
|
|
sprintf(key,"%s",pkey);
|
|
|
|
|
2022-07-30 19:44:57 +02:00
|
|
|
printf("Get Key: %s\n",key);
|
2018-04-26 06:50:32 +02:00
|
|
|
result = cw_ktv_get(ktv,key,NULL);
|
2022-07-30 19:44:57 +02:00
|
|
|
|
|
|
|
if(result)
|
|
|
|
{
|
|
|
|
char s[129];
|
|
|
|
result->type->to_str(result,s,128);
|
|
|
|
printf("Content: '%s'\n",s);
|
|
|
|
}
|
2018-04-26 06:50:32 +02:00
|
|
|
|
2018-05-14 23:30:48 +02:00
|
|
|
if (result == NULL && def != NULL){
|
|
|
|
result = cw_ktv_get(def,key,NULL);
|
|
|
|
}
|
|
|
|
|
2018-04-07 19:28:00 +02:00
|
|
|
|
|
|
|
if (result == NULL){
|
2018-04-09 09:27:38 +02:00
|
|
|
cw_log(LOG_ERR,"Can't put %s, no value found, filling zero.",key);
|
|
|
|
memset(dst+pos,0,stru[i].len);
|
|
|
|
}
|
|
|
|
else{
|
2018-04-26 06:50:32 +02:00
|
|
|
result->valguard=stru[i].valguard;
|
2018-05-14 23:30:48 +02:00
|
|
|
if (cw_ktv_cast(result,stru[i].type)==NULL){
|
|
|
|
cw_log(LOG_ERR,"Can't cast key '%s' from %s to %s",key,result->type->name,stru[i].type->name);
|
|
|
|
}
|
|
|
|
/* if (strcmp(stru[i].type->name,result->type->name)){
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-26 06:50:32 +02:00
|
|
|
printf("Type mismatch: %s != %s\n",stru[i].type->name,result->type->name);
|
|
|
|
if (stru[i].type->cast != NULL){
|
|
|
|
if (!stru[i].type->cast(result)){
|
2018-05-07 23:29:35 +02:00
|
|
|
cw_log(LOG_ERR,"Can't cast '%s' from %s to %s",key,result->type->name,stru[i].type->name);
|
2018-04-26 06:50:32 +02:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-05-14 23:30:48 +02:00
|
|
|
*/
|
2018-04-09 09:27:38 +02:00
|
|
|
result->type->put(result,dst+pos);
|
2018-04-07 19:28:00 +02:00
|
|
|
}
|
2018-04-22 09:00:55 +02:00
|
|
|
if (stru[i].len!=-1)
|
|
|
|
pos+=stru[i].len;
|
|
|
|
else
|
|
|
|
pos+=result->type->len(result);
|
2018-04-07 19:28:00 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|