示例#1
0
/* rank the nodes */
static error patricia__node_show_viz_rank(patricia__node_t *n, int level, void *opaque)
{
  patricia__show_viz_args_t *args = opaque;

  NOT_USED(level);

  if (n->bit == args->rank)
    (void) fprintf(args->f, "\t\t\"%p\"\n", (void *) n);

  return error_OK;
}
示例#2
0
/**
 * parse each widget
 *
 * @param w: pointer to widget
 * @param m: no use
 * @return: NULL
 **/
static struct widget* do_parse_widget(struct widget* w, union message* m)
{
    NOT_USED(m);
    /**
     * record focusable widget
     **/
    if(w->input_enable == 1)
    {
        list_push_back(&global_application.focus_list, &w, sizeof(w));
    }

    /**
     * register window and update active window
     **/
    if(w->is_window)
    {
        struct window* parent = (struct window*)object_parent(OBJECT_POINTER(w));
		struct window* window_ptr = WINDOW_POINTER(w);
		si_t parent_descriptor = (parent == NULL ? 0 : parent->descriptor);
		si_t window_descriptor = register_window(parent_descriptor, window_ptr->title, 
				window_ptr->area.x, window_ptr->area.y, window_ptr->area.width, window_ptr->area.height, 
				window_ptr->minimize_enable, window_ptr->maximize_enable, window_ptr->modal);
		if(0 == window_descriptor)
		{
			EGUI_PRINT_ERROR("failed to register window %s", window_ptr->title);
			return NULL;
		}
		window_ptr->descriptor = window_descriptor;
        global_application.focus = window_ptr;

        /**
         * find icon for the application
         **/
        if((window_ptr->icon_path = (char*)malloc(256)) == NULL)
        {
			EGUI_PRINT_ERROR("failed to register window");
			return NULL;
        }
        else
        {
            /**
             * in C89 standard, snprintf() is NOT included in <stdio.h>
             * so you have to use sprintf, which may be dangerous. be careful
             **/
            sprintf(window_ptr->icon_path, "%s/icons/%s.bmp", global_application.icon_root_path, global_application.name);
            if(access(window_ptr->icon_path, R_OK) == -1)
            {
                sprintf(window_ptr->icon_path, "%s/icons/default.bmp", global_application.icon_root_path);
            }
        }
    }

    return NULL;
}
/*JSON{  "type":"method", "class": "Serial", "name" : "println",
         "description" : "Print a line to the serial port (newline character sent are '\r\n')",
         "generate" : "jswrap_serial_println",
         "params" : [ [ "string", "JsVar", "A String to print"] ]
}*/
void _jswrap_serial_print(JsVar *parent, JsVar *str, bool newLine) {
  NOT_USED(parent);
  IOEventFlags device = jsiGetDeviceFromClass(parent);
  str = jsvAsString(str, false);
  jsiTransmitStringVar(device,str);
  jsvUnLock(str);
  if (newLine) {
    jshTransmit(device, (unsigned char)'\r');
    jshTransmit(device, (unsigned char)'\n');
  }
}
示例#4
0
static
LONG
CDECL
comm_ioctl(FILEPTR * f,
           WORD      mode,
           void *    buf)
{
  NOT_USED(f);
  
  TRACE("srv_comm_device: ioctl");
  return 0;
}
示例#5
0
direntry_t *direntry_copy (CALLER_DECL direntry_t *de)
{
    unsigned refc = ref_count_inc( BASE_CLASS(de)->ref_count );


    NOT_USED(refc);
    direntry_trace("[direntry %p inode %lu] copy (" CALLER_FORMAT ") ref %u\n",
                   de, de->inode, CALLER_PASS refc);


    return de;
}
示例#6
0
static
LONG
CDECL
comm_unselect(FILEPTR * f,
              LONG      p,
              WORD      mode)
{
  NOT_USED(f);
  TRACE("srv_comm_device: unselect");

  return 0;
}
示例#7
0
/*JSON{
  "type" : "method",
  "class" : "ESPWifi",
  "name" : "setIP",
  "generate" : "jswrap_esp8266_setIP",
  "params" : [
    ["options","JsVar","Object containing IP address options `{ ip : '1,2,3,4', subnet, gateway, dns  }`, or do not supply an object in otder to force DHCP."]
  ],
  "return" : ["bool","True on success"]
}
Set the current IP address for get an IP from DHCP (if no options object is specified)
*/
bool jswrap_esp8266_setIP(JsVar *wlanObj, JsVar *options) {
  NOT_USED(wlanObj);

  if (networkState != NETWORKSTATE_ONLINE) {
    jsError("Not connected to the internet");
    return false;
  }

  bool success = false;

  return success;
}
示例#8
0
文件: filerwin.c 项目: dpt/PrivateEye
static error adjust_bobs(filerwin    *fw,
                         int          x,
                         int          y,
                         int          c,
                         unsigned int flags,
                         void        *opaque)
{
  os_box b;

  NOT_USED(x);
  NOT_USED(y);
  NOT_USED(flags);
  NOT_USED(opaque);

  bitvec_toggle(fw->selection, c);

  index_to_area(fw, c, &b);
  wimp_force_redraw(fw->w, b.x0, b.y0, b.x1, b.y1);

  return error_OK;
}
示例#9
0
文件: treeview.c 项目: dpt/PrivateEye
static error get_dimensions_walk(treeview_t     *tr,
                                 int             depth,
                                 int             x,
                                 int             y,
                                 ntree_t        *t,
                                 connector_flags flags,
                                 int             index,
                                 txtfmt_t       *tx,
                                 int             height,
                                 void           *opaque)
{
  treeview_get_dimensions_data *data = opaque;
  int                           width;

  NOT_USED(tr);
  NOT_USED(y);
  NOT_USED(t);
  NOT_USED(flags);
  NOT_USED(index);
  NOT_USED(height);

  width = x;
  width += (depth + 1) * tr->line_height;
  width += 16 * txtfmt_get_wrapped_width(tx);
  width += 16; /* add another character's worth of space to allow for Wimp
                  text padding */
  if (width > data->width)
    data->width = width;

  return error_OK;
}
示例#10
0
文件: treeview.c 项目: dpt/PrivateEye
static error click_walk(treeview_t    *tr,
                       int             depth,
                       int             x,
                       int             y,
                       ntree_t        *t,
                       connector_flags flags,
                       int             index,
                       txtfmt_t       *tx,
                       int             height,
                       void           *opaque)
{
  treeview_click_data *data = opaque;
  os_box               box;

  NOT_USED(tr);
  NOT_USED(t);
  NOT_USED(flags);
  NOT_USED(index);
  NOT_USED(tx);
  NOT_USED(height);

  /* hit detect */

  box.x0 = x + depth * tr->line_height;
  box.y0 = y;
  box.x1 = box.x0 + tr->line_height;
  box.y1 = box.y0 + tr->line_height;

  if (box_contains_point(&box, data->x, data->y))
    /* exiting here means that tr->walk.x and y are valid */
    return error_TREEVIEW_FOUND;
  else
    return error_OK;
}
示例#11
0
/**
  * @brief  USBD_CDC_HID_Init
  *         Initialize the CDC interface
  * @param  pdev: device instance
  * @param  cfgidx: Configuration index
  * @retval status
  */
static uint8_t  USBD_CDC_HID_Init (USBD_HandleTypeDef *pdev,
                               uint8_t cfgidx)
{

  pdev->pClassData = &cdc_hid;
  USBD_CDC_HID_HandleTypeDef   *handle = (USBD_CDC_HID_HandleTypeDef*) pdev->pClassData;

  NOT_USED(cfgidx);
  uint8_t ret = 0;
  
  /* Open EP IN */
  USBD_LL_OpenEP(pdev,
                 CDC_IN_EP,
                 USBD_EP_TYPE_BULK,
                 CDC_DATA_FS_IN_PACKET_SIZE);

  /* Open EP OUT */
  USBD_LL_OpenEP(pdev,
                 CDC_OUT_EP,
                 USBD_EP_TYPE_BULK,
                 CDC_DATA_FS_OUT_PACKET_SIZE);
  /* Open Command IN EP */
  USBD_LL_OpenEP(pdev,
                 CDC_CMD_EP,
                 USBD_EP_TYPE_INTR,
                 CDC_CMD_PACKET_SIZE);
  
  /* Init Xfer states */
  handle->cdcState = CDC_IDLE;

  /* Prepare Out endpoint to receive next packet */
  USBD_LL_PrepareReceive(pdev,
                         CDC_OUT_EP,
                         handle->cdcRX,
                         CDC_DATA_FS_OUT_PACKET_SIZE);

#ifdef USE_USB_HID
  unsigned int reportSize = 0;
  handle->hidReportDesc = USB_GetHIDReportDesc(&reportSize);
  handle->hidReportDescSize = (uint16_t)reportSize;

  /* Open HID EP IN - even if we're not using it */
  USBD_LL_OpenEP(pdev,
                 HID_IN_EP,
                 USBD_EP_TYPE_INTR,
                 HID_DATA_IN_PACKET_SIZE);

  handle->hidState = HID_IDLE;
#endif

  return ret;
}
示例#12
0
/*JSON{
  "type" : "method",
  "class" : "SPI",
  "name" : "send4bit",
  "generate" : "jswrap_spi_send4bit",
  "params" : [
    ["data","JsVar","The data to send - either an integer, array, or string"],
    ["bit0","int32","The 4 bits to send for a 0 (MSB first)"],
    ["bit1","int32","The 4 bits to send for a 1 (MSB first)"],
    ["nss_pin","pin","An nSS pin - this will be lowered before SPI output and raised afterwards (optional). There will be a small delay between when this is lowered and when sending starts, and also between sending finishing and it being raised."]
  ]
}
Send data down SPI, using 4 bits for each 'real' bit (MSB first). This can be useful for faking one-wire style protocols

Sending multiple bytes in one call to send is preferable as they can then be transmitted end to end. Using multiple calls to send() will result in significantly slower transmission speeds.
 */
void jswrap_spi_send4bit(JsVar *parent, JsVar *srcdata, int bit0, int bit1, Pin nss_pin) {
  NOT_USED(parent);
  IOEventFlags device = jsiGetDeviceFromClass(parent);
  if (!DEVICE_IS_SPI(device)) {
    jsExceptionHere(JSET_ERROR, "SPI.send4bit only works on hardware SPI");
    return;
  }

  jshSPISet16(device, true); // 16 bit output

  if (bit0==0 && bit1==0) {
    bit0 = 0x01;
    bit1 = 0x03;
  }
  bit0 = bit0 & 0x0F;
  bit1 = bit1 & 0x0F;

  if (!jshIsDeviceInitialised(device)) {
    JshSPIInfo inf;
    jshSPIInitInfo(&inf);
    jshSPISetup(device, &inf);
  }

  // we're just sending (no receive)
  jshSPISetReceive(device, false);
  // assert NSS
  if (nss_pin!=PIN_UNDEFINED) jshPinOutput(nss_pin, false);

  // send data
  if (jsvIsNumeric(srcdata)) {
    jsspiSend4bit(device, (unsigned char)jsvGetInteger(srcdata), bit0, bit1);
  } else if (jsvIsIterable(srcdata)) {
    jshInterruptOff();
    JsvIterator it;
    jsvIteratorNew(&it, srcdata);
    while (jsvIteratorHasElement(&it)) {
      unsigned char in = (unsigned char)jsvIteratorGetIntegerValue(&it);
      jsspiSend4bit(device, in, bit0, bit1);
      jsvIteratorNext(&it);
    }
    jsvIteratorFree(&it);
    jshInterruptOn();
  } else {
    jsExceptionHere(JSET_ERROR, "Variable type %t not suited to transmit operation", srcdata);
  }

  jshSPIWait(device); // wait until SPI send finished and clear the RX buffer

  // de-assert NSS
  if (nss_pin!=PIN_UNDEFINED) jshPinOutput(nss_pin, true);
  jshSPISet16(device, false); // back to 8 bit
}
示例#13
0
void _jswrap_serial_print(JsVar *parent, JsVar *arg, bool isPrint, bool newLine) {
  NOT_USED(parent);
  IOEventFlags device = jsiGetDeviceFromClass(parent);
  if (!DEVICE_IS_USART(device)) return;

  if (isPrint) arg = jsvAsString(arg, false);
  jsvIterateCallback(arg, _jswrap_serial_print_cb, (void*)&device);
  if (isPrint) jsvUnLock(arg);
  if (newLine) {
    _jswrap_serial_print_cb((unsigned char)'\r', (void*)&device);
    _jswrap_serial_print_cb((unsigned char)'\n', (void*)&device);
  }
}
示例#14
0
static struct widget* do_dispatch_repaint_event_to_all(struct widget* w, union message* msg)
{
    NOT_USED(msg);
    if(w->callback != NULL)
    {
        union message msg;
        msg.widget_repaint.type = MESSAGE_TYPE_WIDGET_REPAINT;
        msg.widget_repaint.area = w->area;

        w->callback(w, &msg);
    }
    return NULL;
}
示例#15
0
int    b_let(int argc,char *argv[],void *extra)
{
	register int r;
	register char *arg;
	NOT_USED(argc);
	NOT_USED(extra);
	while (r = optget(argv,sh_optlet)) switch (r)
	{
	    case ':':
		errormsg(SH_DICT,2, "%s", opt_info.arg);
		break;
	    case '?':
		errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
		break;
	}
	argv += opt_info.index;
	if(error_info.errors || !*argv)
		errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
	while(arg= *argv++)
		r = !sh_arith(arg);
	return(r);
}
示例#16
0
/**
 * 对标准输入的写操作将触发的回调函数
 * 即event_listener_add_write_handler()中标准输入的通信句柄所对应的处理函数
 *
 * 读取命令,调用对应函数发送请求
 * 1. $0 draw_line x1 y1 x2 y2
 * 2. $0 register_window fd title
 * 3. $0 window_manager_exit
 **/
si_t command_handler(struct egui_uds* uds_ptr, addr_t arg)
{
	char command_buf[1024];
	struct egui_uds* server_uds_ptr = (struct egui_uds*)arg;
	const char draw_line_command[] = "draw_line";
	const char register_window_command[] = "register_window";
	const char window_manager_exit_command[] = "window_manager_exit";
	NOT_USED(uds_ptr);

	EGUI_PRINT_INFO("callback command_handler() is called");

	scanf("%s", command_buf);

	if(0 == strncmp(command_buf, draw_line_command, sizeof(draw_line_command)))
	{
		si_t x1 = 0, y1 = 0, x2 = 0, y2 = 0;
		EGUI_PRINT_INFO("get draw_line_command");
		scanf("%d%d%d%d", (int*)&x1, (int*)&y1, (int*)&x2, (int*)&y2);
		if(0 != fake_draw_line(server_uds_ptr, x1, y1, x2, y2))
		{
			EGUI_PRINT_ERROR("failed to execute draw line command");
		}
	}
	else if(0 == strncmp(command_buf, register_window_command, sizeof(register_window_command)))
	{
		si_t fd = 0;
		char title_buf[1024] = {0};
		EGUI_PRINT_INFO("get register_window_command");
		scanf("%d%s", (int*)&fd, title_buf);
		if(0 != fake_register_window(server_uds_ptr, fd, title_buf))
		{
			EGUI_PRINT_ERROR("failed to execute register window command");
		}
	}
	else if(0 == strncmp(command_buf, window_manager_exit_command, sizeof(window_manager_exit_command)))
	{
		EGUI_PRINT_INFO("get window_manager_exit_command");
		if(0 != fake_window_manager_exit(server_uds_ptr))
		{
			EGUI_PRINT_ERROR("failed to execute window manager exit command");
		}
		/** 如果用户输入退出窗口管理器的命令,那么客户端的程序也应当退出 **/
		return SELECTER_RETURN_TYPE_END;
	}
	else
	{
		EGUI_PRINT_ERROR("unknow command %s", command_buf);
		EGUI_PRINT_INFO(help_str);
	}
	return SELECTER_RETURN_TYPE_CONTINUE;
}
void *vpu_clock_init(struct vpu_platform_resources *res)
{
	int i;
	struct vpu_clock *cl;
	struct vpu_clk_control *clk_ctrl;

	if (!res)
		return NULL;

	clk_ctrl = (struct vpu_clk_control *)
			kzalloc(sizeof(struct vpu_clk_control), GFP_KERNEL);
	if (!clk_ctrl) {
		pr_err("failed to allocate clock ctrl block\n");
		return NULL;
	}

	for (i = 0; i < VPU_MAX_CLKS; i++)
		clk_ctrl->clock[i] = &res->clock[i];

	/* mask allowing to only enable clocks from certain groups of clocks */
	clk_ctrl->mask = CLOCK_CORE;

	/* setup the clock handles */
	for (i = 0; i < VPU_MAX_CLKS; i++) {
		if (NOT_USED(clk_ctrl, i))
			continue;

		cl = clk_ctrl->clock[i];

		if (CLOCK_IS_SCALABLE(clk_ctrl, i) && !cl->pwr_frequencies) {
			pr_err("%s pwr frequencies unknown\n", cl->name);
			goto fail_init_clocks;
		}

		cl->clk = devm_clk_get(&res->pdev->dev, cl->name);
		if (IS_ERR_OR_NULL(cl->clk)) {
			pr_err("Failed to get clock: %s\n", cl->name);
			cl->clk = NULL;
			goto fail_init_clocks;
		}
		cl->status = 0;
	}

	return clk_ctrl;

fail_init_clocks:
	vpu_clock_deinit((void *)clk_ctrl);
	kfree(clk_ctrl);
	return NULL;
}
示例#18
0
文件: pickle-test.c 项目: dpt/DPTLib
static int my_walk_fn(const void *key, const void *value, void *opaque)
{
  char kbuf[256];
  char vbuf[256];

  NOT_USED(opaque);

  cheese_format_key(key, kbuf, sizeof(kbuf), NULL);
  cheese_format_value(value, vbuf, sizeof(vbuf), NULL);

  printf("walk '%s':'%s'...\n", kbuf, vbuf);

  return 0;
}
示例#19
0
static int tags_search_event_mouse_click(wimp_event_no event_no,
                                         wimp_block   *block,
                                         void         *handle)
{
  wimp_pointer *pointer;

  NOT_USED(event_no);
  NOT_USED(handle);

  pointer = &block->pointer;

  if (pointer->buttons & (wimp_CLICK_SELECT | wimp_CLICK_ADJUST))
  {
    switch (pointer->i)
    {
      case TAGS_SEARCH_B_SEARCH:
        tags_search_search();
        break;

      case TAGS_SEARCH_B_CANCEL:
        break;
    }

    if (pointer->i == TAGS_SEARCH_B_SEARCH ||
        pointer->i == TAGS_SEARCH_B_CANCEL)
    {
#if 0
      if (pointer->buttons & wimp_CLICK_SELECT)
        tags_search_close_dialogue();
      else
        tags_search_update_dialogue();
#endif
    }
  }

  return event_HANDLED;
}
示例#20
0
static int sse50etf_exec(void *data, void *data2) {
	RAII_VAR(struct msg *, msg, (struct msg *)data, msg_decr);
	Quote *quote = (Quote *)msg->data;
	struct wp *wp;
	NOT_USED(data2);

	if (isnan(cru) || isnan(ecc)) {
		xcb_log(XCB_LOG_WARNING, "No valid value for CRU or ECC");
		goto end;
	}
	table_lock(contracts);
	if ((wp = table_get_value(contracts, quote->thyquote.m_cHYDM)) &&
		(isnan(wp->price) || fabs(wp->price - quote->thyquote.m_dZXJ) > 0.000001)) {
		table_iter_t iter;
		table_node_t node;
		double sum = 0.0;
		time_t t = (time_t)quote->thyquote.m_nTime;
		struct tm lt;
		char datestr[64], res[512];

		if (wp->type == 2) {
			table_unlock(contracts);
			goto end;
		}
		wp->price = quote->thyquote.m_dZXJ;
		iter = table_iter_new(contracts);
		while ((node = table_next(iter))) {
			wp = table_node_value(node);
			if (isnan(wp->price)) {
				xcb_log(XCB_LOG_WARNING, "No price info for '%s'", table_node_key(node));
				table_iter_free(&iter);
				table_unlock(contracts);
				goto end;
			}
			sum += wp->weight * wp->price;
		}
		table_iter_free(&iter);
		strftime(datestr, sizeof datestr, "%F %T", localtime_r(&t, &lt));
		snprintf(res, sizeof res, "SSE50ETF,%s.%03d|%f",
			datestr,
			quote->m_nMSec,
			(sum + ecc) / cru);
		out2rmp(res);
	}
	table_unlock(contracts);

end:
	return 0;
}
示例#21
0
文件: filerwin.c 项目: dpt/PrivateEye
static int filerwin_event_user_drag_box(wimp_event_no event_no,
                                        wimp_block   *block,
                                        void         *handle)
{
  wimp_dragged *dragged;
  filerwin     *fw;

  NOT_USED(event_no);

  dragged = &block->dragged;
  fw      = handle;

  if (fw->drag_type == drag_type_SELECTION_SELECT ||
      fw->drag_type == drag_type_SELECTION_ADJUST)
  {
    wimp_version_no    version;
    mapfn             *selector;
    wimp_window_state  wstate;

    xwimpreadsysinfo_version(&version);

    if (version >= wimp_VERSION_RO40)
      wimp_auto_scroll(0, NULL);

    // convert dragged.final to workarea relative
    // (note fiddling with dragged->final in place)

    wstate.w = fw->w;
    wimp_get_window_state(&wstate);

    screen_box_to_workarea(&dragged->final, &wstate);

    // for each icon: do we hit it?

    if (fw->drag_type == drag_type_SELECTION_SELECT)
    {
      bitvec_clear_all(fw->selection);
      selector = select_bobs;
    }
    else
    {
      selector = adjust_bobs;
    }

    map(fw, selector, 0,0, &dragged->final, NULL);


    fw->drag_type = -1;
  }
示例#22
0
/// Receive data if possible. returns nBytes on success, 0 on no data, or -1 on failure
int net_wiznet_recv(JsNetwork *net, int sckt, void *buf, size_t len) {
  NOT_USED(net);
  int num = 0;
  if (getSn_SR((uint8_t)sckt) == SOCK_LISTEN) {
    // socket is operating as a TCP server - something has gone wrong.
    // just return -1 to close this connection immediately
    return -1;
  } else {
    // receive data - if none available it'll just return SOCK_BUSY
    num = (int)recv((uint8_t)sckt,buf,(uint16_t)len,0);
    if (num==SOCK_BUSY) num=0;
  }
  if (jspIsInterrupted()) return -1;
  return num;
}
示例#23
0
static error format_key(const void *vkey,
                        char       *buf,
                        size_t      len,
                        void       *opaque)
{
  NOT_USED(opaque);

  if (len < digestdb_DIGESTSZ * 2 + 1)
    return error_FILENAMEDB_BUFF_OVERFLOW;

  digestdb_encode(buf, vkey);
  buf[digestdb_DIGESTSZ * 2] = '\0';

  return error_OK;
}
示例#24
0
si_t shortcut_default_widget_repaint(struct shortcut* sh , union message * msg)
{
	NOT_USED(msg);
	shortcut_update_all_areas( sh );

	shortcut_draw_img( sh );

	if(shortcut_get_is_text_visiable(sh) == 1)
	{
		shortcut_show_text(sh);
	}

    return 0;

}
示例#25
0
static error dstree__select_node(dstree__node_t *n,
                                 int             level,
                                 void           *opaque)
{
  dstree__select_args_t *args = opaque;

  NOT_USED(level);

  if (args->k-- == 0)
  {
    args->item = &n->item;
    return error_STOP_WALK;
  }

  return error_OK;
}
示例#26
0
/** gets data from callback, writes it into array if nonzero. Returns total length */
uint32_t heatshrink_decode(int (*callback)(uint32_t *cbdata), uint32_t *cbdata, unsigned char *data) {
  heatshrink_decoder hsd;
  uint8_t inBuf[BUFFERSIZE];
  uint8_t outBuf[BUFFERSIZE];
  heatshrink_decoder_reset(&hsd);

  size_t count = 0;
  size_t sunk = 0;
  size_t polled = 0;
  int lastByte = 0;
  size_t inBufCount = 0;
  while (lastByte >= 0 || inBufCount>0) {
    // Read data from flash
    while (inBufCount<BUFFERSIZE && lastByte>=0) {
      lastByte = callback(cbdata);
      if (lastByte >= 0)
        inBuf[inBufCount++] = (uint8_t)lastByte;
    }
    // decode
    bool ok = heatshrink_decoder_sink(&hsd, inBuf, inBufCount, &count) >= 0;
    // if not all the data was read, shift what's left to the start of our buffer
    if (count < inBufCount) {
      size_t i;
      for (i=count;i<inBufCount;i++)
        inBuf[i-count] = inBuf[i];
    }
    inBufCount -= count;
    assert(ok);NOT_USED(ok);
    sunk += count;
    if (lastByte < 0) {
      heatshrink_decoder_finish(&hsd);
    }

    HSE_poll_res pres;
    do {
      pres = heatshrink_decoder_poll(&hsd, outBuf, sizeof(outBuf), &count);
      assert(pres >= 0);
      if (data) memcpy(&data[polled], outBuf, count);
      polled += count;
    } while (pres == HSER_POLL_MORE);
    assert(pres == HSER_POLL_EMPTY);
    if (lastByte < 0) {
      heatshrink_decoder_finish(&hsd);
    }
  }
  return (uint32_t)polled;
}
/*JSON{ "type":"method", "class": "Serial", "name" : "write",
         "description" : "Write a character or array of characters to the serial port - without a line feed",
         "generate" : "jswrap_serial_write",
         "params" : [ [ "data", "JsVar", "A byte, a string, or an array of bytes to write"] ]
}*/
void jswrap_serial_write(JsVar *parent, JsVar *data) {
  NOT_USED(parent);
  IOEventFlags device = jsiGetDeviceFromClass(parent);
  if (jsvIsNumeric(data)) {
    jshTransmit(device, (unsigned char)jsvGetInteger(data));
  } else if (jsvIsIterable(data)) {
    JsvIterator it;
    jsvIteratorNew(&it, data);
    while (jsvIteratorHasElement(&it)) {
      jshTransmit(device, (unsigned char)jsvIteratorGetIntegerValue(&it));
      jsvIteratorNext(&it);
    }
    jsvIteratorFree(&it);
  } else {
    jsWarn("Data supplied was not an integer - or iterable");
  }
}
示例#28
0
//rewrite metachanges_log func
void masterconn_metachanges_log(serventry *eptr,const uint8_t *data,uint32_t length) {
	char log_data[1000];
	char log_str[1000];                                                                                                                                        
	uint64_t version;
	uint32_t size;
	//FILE *new_fd;
	uint8_t log_count = 0;
	uint8_t log_limit;
	int ret = 0;

    NOT_USED(length);
	log_limit = get8bit(&data);
	if (eptr->logfd == NULL) {
		eptr->logfd = fopen("changelog.0.mfs","a");
	}
	while(log_count < log_limit) {
		version = get64bit(&data);
		size = get32bit(&data);
		memcpy(log_str,data,size);
		data = data + size;
		if (log_str[size - 1] != '\0') {
			MFSLOG(LOG_NOTICE,"MATOSLA_CHANGELOG - invalide string the last is %c",log_str[size - 1]);
		}
		snprintf(log_data,sizeof(log_data),"%"PRIu64": %s\n",version,log_str);
	        if (eptr->logfd) {
                	ret = replay(log_data);
         	      	if (ret != 0) {
				MFSLOG(LOG_ERR,"changelog replay failed");
				break;
                  	      //more complicated method to ensure consistency
                	}
                	fprintf(eptr->logfd,"%"PRIu64": %s",version,log_str);
                	fflush(eptr->logfd);
			log_count++;
        	} else {
                	MFSLOG(LOG_NOTICE,"lost MFS change %"PRIu64": %s",version,log_str);
			ret = -1;
			break;
        	}
	}
	if (ret == 0) {
		masterconn_ack_changelog(eptr,0);
	} else {
		masterconn_ack_changelog(eptr,1);
	}
}
示例#29
0
文件: app_pd.c 项目: ArkShen/xcb
static int pd_exec(void *data, void *data2) {
	RAII_VAR(struct msg *, msg, (struct msg *)data, msg_decr);
	Quote *quote = (Quote *)msg->data;
	dlist_t dlist;
	NOT_USED(data2);

	if ((dlist = table_get_value(contracts, quote->thyquote.m_cHYDM))) {
		dlist_iter_t iter = dlist_iter_new(dlist, DLIST_START_HEAD);
		dlist_node_t node;

		while ((node = dlist_next(iter))) {
			struct cpl *cpl = (struct cpl *)dlist_node_value(node);

			pthread_spin_lock(&cpl->lock);
			if (!strcasecmp(cpl->contract1, quote->thyquote.m_cHYDM))
				cpl->price1 = quote->thyquote.m_dZXJ;
			else
				cpl->price2 = quote->thyquote.m_dZXJ;
			if (cpl->price1 > 0.0 && cpl->price2 > 0.0) {
				float pd = fabs(cpl->price1 - cpl->price2);

				/* If the price diff changes, we output it. */
				if (fabs(pd - cpl->prevpd) > 0.000001) {
					time_t t = (time_t)quote->thyquote.m_nTime;
					struct tm lt;
					char datestr[64], res[512];

					strftime(datestr, sizeof datestr, "%F %T", localtime_r(&t, &lt));
					snprintf(res, sizeof res, "PD,%s.%03d,%s,%s|%.2f,%.2f,%.2f",
						datestr,
						quote->m_nMSec,
						cpl->contract1,
						cpl->contract2,
						cpl->price1,
						cpl->price2,
						pd);
					out2rmp(res);
					cpl->prevpd = pd;
				}
			}
			pthread_spin_unlock(&cpl->lock);
		}
	}
	return 0;
}
示例#30
0
/*JSON{
  "type" : "method",
  "class" : "ESPWifi",
  "name" : "getIP",
  "generate" : "jswrap_esp8266_getIP",
  "return" : ["JsVar",""]
}
Get the current IP address
*/
JsVar *jswrap_esp8266_getIP(JsVar *wlanObj) {
  NOT_USED(wlanObj);

  if (networkState != NETWORKSTATE_ONLINE) {
    jsError("Not connected to the internet");
    return 0;
  }


  /* If byte 1 is 0 we don't have a valid address */
  JsVar *data = jsvNewWithFlags(JSV_OBJECT);
/*  networkPutAddressAsString(data, "ip", &gWIZNETINFO.ip[0], 4, 10, '.');
  networkPutAddressAsString(data, "subnet", &gWIZNETINFO.sn[0], 4, 10, '.');
  networkPutAddressAsString(data, "gateway", &gWIZNETINFO.gw[0], 4, 10, '.');
  networkPutAddressAsString(data, "dns", &gWIZNETINFO.dns[0], 4, 10, '.');
  networkPutAddressAsString(data, "mac", &gWIZNETINFO.mac[0], 6, 16, 0);*/
  return data;
}