void par_setbin(unsigned char param, void *source, size_t length)
{
  // write source to param slots:
  while (param < PARAM_MAX) {
    if (length > PARAM_MAX_LENGTH) {
      memcpy(par_value, source, PARAM_MAX_LENGTH);
      par_write(param);
      length -= PARAM_MAX_LENGTH;
      source += PARAM_MAX_LENGTH;
      param += 1;
    } else {
      // last chunk:
      memset(par_value, 0, PARAM_MAX_LENGTH);
      memcpy(par_value, source, length);
      par_write(param);
      break;
    }
  }
}
void par_set(unsigned char param, char* value)
  {
  if (param >= PARAM_MAX) return;

  if (value)
    {
    strncpy(par_value,value,PARAM_MAX_LENGTH);
    par_value[PARAM_MAX_LENGTH-1]='\0';
    }
  else
      par_value[0] = 0;

  par_write(param);
  }
void par_set(unsigned char param, char* value)
  {
  if (param >= PARAM_MAX) return;

#ifdef OVMS_TWIZY_CFG
  // exclude binary params for CFG profiles:
  if (param >= 16 && param <= 21) return;
#endif //OVMS_TWIZY_CFG

  if (value)
    {
    strncpy(par_value,value,PARAM_MAX_LENGTH);
    par_value[PARAM_MAX_LENGTH-1]='\0';
    }
  else
      par_value[0] = 0;

  par_write(param);
  }
Esempio n. 4
0
/*
 * par_main()
 *	Endless loop to receive and serve requests
 */
static void
par_main()
{
	struct msg msg;
	int x;
	struct file *f;
loop:
	/*
	 * Receive a message, log an error and then keep going
	 */
	x = msg_receive(lp_port, &msg);
	if (x < 0) {
		syslog(LOG_ERR, "msg_receive");
		goto loop;
	}

	/*
	 * All incoming data should fit in one buffer
	 */
	if (msg.m_nseg > 1) {
		msg_err(msg.m_sender, EINVAL);
		goto loop;
	}

	/*
	 * Categorize by basic message operation
	 */
	f = hash_lookup(filehash, msg.m_sender);
	switch (msg.m_op & MSG_MASK) {
	case M_CONNECT:		/* New client */
		new_client(&msg);
		break;
	case M_DISCONNECT:	/* Client done */
		dead_client(&msg, f);
		break;
	case M_DUP:		/* File handle dup during exec() */
		dup_client(&msg, f);
		break;
	case M_ABORT:		/* Aborted operation */
		/*
		 * We are synchronous. At the time we handle this
		 * message, any I/O is completed. Just answer
		 * with an abort message.
		 */
		msg_reply(msg.m_sender, &msg);
		break;
	case FS_WRITE:		/* Write */
		if (check_gen(&msg, f)) {
			break;
		}
		par_write(&msg, f);
		break;
	case FS_STAT:		/* Get stat of file */
		if (check_gen(&msg, f)) {
			break;
		}
		par_stat(&msg, f);
		break;
	case FS_WSTAT:		/* Writes stats */
		if (check_gen(&msg, f)) {
			break;
		}
		par_wstat(&msg, f);
		break;
	default:		/* Unknown */
		msg_err(msg.m_sender, EINVAL);
		break;
	}
	goto loop;
}
void par_setbase64(unsigned char param, void* source, size_t length)
  {
  base64encode(source, length, par_value);
  par_write(param);
  }