More work on CW VM code ..

FossilOrigin-Name: 3b0cb324535527b32d0e938b03151c75f6100ca2059fc121e2c4d350a8caf8a4
This commit is contained in:
7u83@mail.ru
2015-04-10 15:14:55 +00:00
parent e148b7c9f6
commit c43f85b2a6
59 changed files with 1188 additions and 459 deletions

View File

@ -7,54 +7,52 @@
#include "cw_log.h"
int cw_put_item(uint8_t *dst,struct cw_item*item)
int cw_put_item(uint8_t * dst, struct cw_item *item)
{
switch (item->type){
switch (item->type) {
case CW_ITEMTYPE_STR:
return cw_put_data(dst,item->data,strlen( (char*)item->data));
return cw_put_data(dst, item->data, strlen((char *) item->data));
case CW_ITEMTYPE_BYTE:
return cw_put_byte(dst,item->byte);
return cw_put_byte(dst, item->byte);
case CW_ITEMTYPE_WORD:
return cw_put_word(dst,item->word);
return cw_put_word(dst, item->word);
case CW_ITEMTYPE_DWORD:
return cw_put_dword(dst,item->dword);
return cw_put_dword(dst, item->dword);
}
return 0;
}
int cw_out_generic(struct conn *conn,struct cw_action_out *a,uint8_t *dst) // ,struct cw_item * item)
int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst) // ,struct cw_item * item)
{
/* Get the item to put */
struct cw_item *item=NULL;
if (a->get){
item = a->get (conn,a);
struct cw_item *item = NULL;
if (a->get) {
item = a->get(conn, a);
}
/* Size for msg elem header depends on
vendor specific payload */
int start = a->vendor_id ? 10:4;
int start = a->vendor_id ? 10 : 4;
int len;
if ( !item ){
if (a->mand){
cw_log(LOG_ERR,"Cannot send mandatory message element %d",a->elem_id);
if (!item) {
if (a->mand) {
cw_log(LOG_ERR, "Error: Cannot send mandatory message element %d - (%s)",
a->elem_id, cw_strelemp(conn->actions, a->elem_id));
}
return 0;
}
else{
len = cw_put_item(dst+start,item);
} else {
len = cw_put_item(dst + start, item);
}
if (a->vendor_id)
return len + cw_put_elem_vendor_hdr(dst,a->vendor_id,a->elem_id,len);
if (a->vendor_id)
return len + cw_put_elem_vendor_hdr(dst, a->vendor_id, a->elem_id, len);
return len + cw_put_elem_hdr(dst,a->elem_id,len);
return len + cw_put_elem_hdr(dst, a->elem_id, len);
}