void amf_encode_msg(lua_State *L, amf_buf *buf) { luaL_checktype(L, -1, LUA_TTABLE); int i = 0, ver; while(i++ < 3) { lua_rawgeti(L, -1, i); switch (i) { case 1: { ver = lua_tonumber(L, -1); amf_buf_append_u16(buf, ver); break; } case 2: { /* headers */ if (lua_isnil(L, -1)) { amf_buf_append_u16(buf, 0); } else if (lua_istable(L, -1)) { int hc = lua_objlen(L, -1); amf_buf_append_u16(buf, hc); int j; for (j = 1; j <= hc; j++) { lua_rawgeti(L, -1, j); encode_hdr(L, buf, ver); lua_pop(L, 1); } } else { luaL_error(L, "invalid amf msg header container structure, must be a table or nil"); } break; } case 3: { if (lua_isnil(L, -1)) { amf_buf_append_u16(buf, 0); } else if (lua_istable(L, -1)) { int bc = lua_objlen(L, -1); amf_buf_append_u16(buf, bc); int j; for (j = 1; j <= bc; j++) { lua_rawgeti(L, -1, j); encode_body(L, buf, ver); lua_pop(L, 1); } } else { luaL_error(L, "invalid amf msg body container structure, must be a table or nil"); } break; } } lua_pop(L, 1); } }
void bt_monitor_send(uint16_t opcode, const void *data, size_t len) { struct bt_monitor_hdr hdr; int key; encode_hdr(&hdr, opcode, len); key = irq_lock(); monitor_send(&hdr, sizeof(hdr)); monitor_send(data, len); irq_unlock(key); }
void bt_monitor_send(u16_t opcode, const void *data, size_t len) { struct bt_monitor_hdr hdr; if (atomic_test_and_set_bit(&flags, BT_LOG_BUSY)) { drop_add(opcode); return; } encode_hdr(&hdr, opcode, len); monitor_send(&hdr, BT_MONITOR_BASE_HDR_LEN + hdr.hdr_len); monitor_send(data, len); atomic_clear_bit(&flags, BT_LOG_BUSY); }
void bt_log(int prio, const char *fmt, ...) { struct bt_monitor_user_logging log; struct bt_monitor_hdr hdr; const char id[] = "bt"; va_list ap; int len; va_start(ap, fmt); len = vsnprintk(NULL, 0, fmt, ap); va_end(ap); if (len < 0) { return; } log.priority = prio; log.ident_len = sizeof(id); if (atomic_test_and_set_bit(&flags, BT_LOG_BUSY)) { drop_add(BT_MONITOR_USER_LOGGING); return; } encode_hdr(&hdr, BT_MONITOR_USER_LOGGING, sizeof(log) + sizeof(id) + len + 1); monitor_send(&hdr, BT_MONITOR_BASE_HDR_LEN + hdr.hdr_len); monitor_send(&log, sizeof(log)); monitor_send(id, sizeof(id)); va_start(ap, fmt); _vprintk(log_out, NULL, fmt, ap); va_end(ap); /* Terminate the string with null */ uart_poll_out(monitor_dev, '\0'); atomic_clear_bit(&flags, BT_LOG_BUSY); }
void bt_log(int prio, const char *fmt, ...) { struct bt_monitor_user_logging log; struct bt_monitor_hdr hdr; const char id[] = "bt"; va_list ap; int len, key; va_start(ap, fmt); len = vsnprintk(NULL, 0, fmt, ap); va_end(ap); if (len < 0) { return; } log.priority = prio; log.ident_len = sizeof(id); encode_hdr(&hdr, BT_MONITOR_USER_LOGGING, sizeof(log) + sizeof(id) + len + 1); key = irq_lock(); monitor_send(&hdr, sizeof(hdr)); monitor_send(&log, sizeof(log)); monitor_send(id, sizeof(id)); va_start(ap, fmt); _vprintk(log_out, NULL, fmt, ap); va_end(ap); /* Terminate the string with null */ uart_poll_out(monitor_dev, '\0'); irq_unlock(key); }