static void paramReadProcess(int ident)
{
  int id;

  id = variableGetIndex(ident);
  
  if (id<0) {
    p.data[0] = -1;
    p.data[1] = ident;
    p.data[2] = ENOENT;
    p.size = 3;
    
    crtpSendPacket(&p);
    return;
  }

  switch (params[id].type & PARAM_BYTES_MASK)
  {
 	case PARAM_1BYTE:
   		memcpy(&p.data[1], params[id].address, sizeof(uint8_t));
   		p.size = 1+sizeof(uint8_t);
   		break;
 		break;
    case PARAM_2BYTES:
   		memcpy(&p.data[1], params[id].address, sizeof(uint16_t));
   		p.size = 1+sizeof(uint16_t);
   		break;
    case PARAM_4BYTES:
      memcpy(&p.data[1], params[id].address, sizeof(uint32_t));
   		p.size = 1+sizeof(uint32_t);
   		break;
 	  case PARAM_8BYTES:
      memcpy(&p.data[1], params[id].address, sizeof(uint64_t));
   		p.size = 1+sizeof(uint64_t);
   		break;
  }
  
  crtpSendPacket(&p);
}
static void paramWriteProcess(int ident, void* valptr)
{
  int id;

  id = variableGetIndex(ident);
  
  if (id<0) {
    p.data[0] = -1;
    p.data[1] = ident;
    p.data[2] = ENOENT;
    p.size = 3;
    
    crtpSendPacket(&p);
    return;
  }

	if (params[id].type & PARAM_RONLY)
		return;

  switch (params[id].type & PARAM_BYTES_MASK)
  {
 	case PARAM_1BYTE:
 		*(uint8_t*)params[id].address = *(uint8_t*)valptr;
 		break;
    case PARAM_2BYTES:
  	  *(uint16_t*)params[id].address = *(uint16_t*)valptr;
      break;
 	case PARAM_4BYTES:
      *(uint32_t*)params[id].address = *(uint32_t*)valptr;
      break;
 	case PARAM_8BYTES:
      *(uint64_t*)params[id].address = *(uint64_t*)valptr;
      break;
  }
  
  crtpSendPacket(&p);
}
Beispiel #3
0
static int logAppendBlock(int id, struct ops_setting * settings, int len)
{
  int i;
  struct log_block * block;
  
  DEBUG("Appending %d variable to block %d\n", len, id);
  
  for (i=0; i<LOG_MAX_BLOCKS; i++)
    if (logBlocks[i].id == id) break;
  
  if (i >= LOG_MAX_BLOCKS) {
    ERROR("Trying to append block id %d that doesn't exist.", id);
    return ENOENT;
  }
  
  block = &logBlocks[i];
  
  for (i=0; i<len; i++)
  {
    int currentLength = blockCalcLength(block);
    struct log_ops * ops;
    int varId;
    
    if ((currentLength + typeLength[settings[i].logType&0x0F])>LOG_MAX_LEN) {
      ERROR("Trying to append a full block. Block id %d.\n", id);
      return E2BIG;
    }
    
    ops = opsMalloc();
    
    if(!ops) {
      ERROR("No more ops memory free!\n");
      return ENOMEM;
    }
    
    if (settings[i].id != 255)  //TOC variable
    {
      varId = variableGetIndex(settings[i].id);
      
      if (varId<0) {
        ERROR("Trying to add variable Id %d that does not exists.", settings[i].id);
        return ENOENT;
      }
      
      ops->variable    = logs[varId].address;
      ops->storageType = logs[varId].type;
      ops->logType     = settings[i].logType&0x0F;
      
      DEBUG("Appended variable %d to block %d\n", settings[i].id, id);
    } else {                     //Memory variable
      //TODO: Check that the address is in ram
      ops->variable    = (void*)(&settings[i]+1);
      ops->storageType = (settings[i].logType>>4)&0x0F;
      ops->logType     = settings[i].logType&0x0F;
      i += 2;
      
      DEBUG("Appended var addr 0x%x to block %d\n", (int)ops->variable, id);
    }
    blockAppendOps(block, ops);
    
    DEBUG("   Now lenght %d\n", blockCalcLength(block));
  }
  
  return 0;
}