Beispiel #1
0
void
dumpmem(uint8_t *addr, uint16_t len)
{
  for(uint16_t i = 0; i < len; i += 16) {
    uint8_t l = len;
    if(l > 16)
      l = 16;
    DH(i,4);
    DC(':'); DC(' ');
    for(uint8_t j = 0; j < l; j++) {
      DH2(addr[j]);
      if(j&1)
        DC(' ');
    }
    DC(' ');
    for(uint8_t j = 0; j < l; j++) {
      if(addr[j] >= ' ' && addr[j] <= '~')
        DC(addr[j]);
      else
        DC('.');
    }
    addr += 16;
    DNL();
  }
  DNL();
}
Beispiel #2
0
/* evolve hk values from Nics to Nshss */
double DDhk(double k, double N, double hk, double Dhk, double Ni, double step, double ai, double *H_array, double *DH_array)
{
	double DDhk_val;
	DDhk_val = -(3 +(DH(N, Ni, step, DH_array)/H(N, Ni, step, H_array)))*(Dhk)
			-pow(k/(A(N, ai)*H(N, Ni, step, H_array)),2)*hk;
	return DDhk_val;
}
Beispiel #3
0
void
kopp_fc_func(char *in)

{ 
int SingleBlkOnly=0;											// Default:  we will send key off if Keycode >= 0x80
uint32_t LastWatchdog;

uint8_t blkTXcode=0x00; 
uint8_t inhex_dec[kopp_fc_Command_char];						// in_decbin: decimal value of hex commandline
uint8_t hblen = fromhex(in+2, inhex_dec, strlen(in));	
strcpy(ErrorMSG,"ok");		


// If parameter 2 = "t" then  "Transmitt Free Control Telegram" 
SingleBlkOnly=0;												// Default:  we will send key off if Keycode >= 0x80

if((in[1] == 't') || (in[1] == 's')) 


// Transmitt Command
// =================
{
kopp_fc_tx_on = 1;												// Transmitt activated

if (in[15]=='J') printon[0]='Y'; else printon[0]='N'; 		// Sollen wir Daten ausgeben (Zeitstempel etc)

if(in[1] == 's') SingleBlkOnly=1;								// Command = "s", -> If KeyCode > 0x80 we will send no !! Key Off Code

LastWatchdog=ticks;												// I guess, Watchdog reset was done shortly before 
BlockStartTime=ticks;

// print some status Information
if (printon[0]=='Y')
 {
 DS_P(PSTR("Transmitt\r\n"));
													
 DS_P(PSTR("commandlineparameter: "));
 DS(in);

 DS_P(PSTR("\r\nStringlength:     "));
 DU(strlen(in),0);
 DS_P(PSTR("\r\nNext Character (int) after parameter (should be line end character): "));
 DU((int)in[strlen(in)],0);
 DS_P(PSTR("\r\nAmount of Bytes (Hex) found inside command line parameter:           "));
 DU(hblen,0);
 DS_P(PSTR("\r\n"));
 
   
// following code to check whether ticks uses full 32 bits or will be reset afer 125 ticks
 DS_P(PSTR("Tick Timer:           "));
 DH((uint16_t)(( BlockStartTime>>16) & 0xffff),4);
 DH((uint16_t)(BlockStartTime & 0xffff),4);
 DS_P(PSTR("\r\n"));
 }
int main()
{
  DeltaHeap<unsigned int> DH(100, &hashfun);

  for (unsigned int i = 10; i > 0; i--) {
    cout << "Adding item " << i << " with priority " << (float) i << endl;
    DH.add(i, (float) i);
  }

  cout << "Promote 9 to have value 3.0" << endl;
  DH.add(9, 3.0);

  cout << "Demote 6 to have value 8.0" << endl;
  DH.add(6, 8.0);

  unsigned int u = DH.min();
  float p = DH.minPriority();
  cout << "The minimum element is " << u << " with priority " << p << endl;

  p = DH.minPriority();
  u = DH.popMin();
  cout << "Popped the minimum element " << u << " with priority " << p << endl;
  p = DH.minPriority();
  u = DH.popMin();
  cout << "Popped the minimum element " << u << " with priority " << p << endl;
  p = DH.minPriority();
  u = DH.popMin();
  cout << "Popped the minimum element " << u << " with priority " << p << endl;

  cout << "Adding element " << u << " with priority 0.0" << endl;
  DH.add(u, 0.0);

  DH.deleteAllValues();
  cout << "DH size is " << DH.size() << endl;

  clrandom rng;
  DH.add(10, -1E16);
  cout << "top priority = " << -DH.minPriority() << endl;


  return 0;
}
Beispiel #5
0
/**
 * FSAL_closedir :
 * Free the resources allocated for reading directory entries.
 *
 * \param dir_descriptor (input):
 *        Pointer to a directory descriptor filled by FSAL_opendir.
 *
 * \return Major error codes :
 *        - ERR_FSAL_NO_ERROR     (no error)
 *        - ERR_FSAL_FAULT        (a NULL pointer was passed as mandatory argument)
 *        - Other error codes can be returned :
 *          ERR_FSAL_IO, ...
 */
fsal_status_t CEPHFSAL_closedir(fsal_dir_t * extdescriptor,
                                fsal_op_context_t * p_context  /* IN */ )
{
  cephfsal_dir_t* descriptor = (cephfsal_dir_t*) extdescriptor;
  struct ceph_mount_info *cmount = descriptor->ctx.export_context->cmount;
  int rc = 0;

  /* sanity checks */
  if(!descriptor)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_closedir);

  TakeTokenFSCall();
  rc = ceph_ll_releasedir(cmount, DH(descriptor));
  ReleaseTokenFSCall();

  if (rc < 0)
    Return(posix2fsal_error(rc), 0, INDEX_FSAL_closedir);

  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_closedir);
}
Beispiel #6
0
void
read_eeprom(char *in)
{
  uint8_t hb[2], d;
  uint16_t addr;

#ifdef HAS_ETHERNET
  if(in[1] == 'i') {
           if(in[2] == 'm') { display_ee_mac(EE_MAC_ADDR);
    } else if(in[2] == 'd') { DH2(erb(EE_USE_DHCP));
    } else if(in[2] == 'a') { display_ee_ip4(EE_IP4_ADDR);
    } else if(in[2] == 'n') { display_ee_ip4(EE_IP4_NETMASK);
    } else if(in[2] == 'g') { display_ee_ip4(EE_IP4_GATEWAY);
    } else if(in[2] == 'N') { display_ee_ip4(EE_IP4_NTPSERVER);
    } else if(in[2] == 'o') { DH2(erb(EE_IP4_NTPOFFSET));
    } else if(in[2] == 'p') {
      DU(eeprom_read_word((uint16_t *)EE_IP4_TCPLINK_PORT), 0);
    }
  } else 
#endif
  if(in[1] == 'M') { display_ee_mac(EE_DUDETTE_MAC); }  
  else if(in[1] == 'P') { display_ee_bytes(EE_DUDETTE_PUBL, 16); }  
  else {
    hb[0] = hb[1] = 0;
    d = fromhex(in+1, hb, 2);
    if(d == 2)
      addr = (hb[0] << 8) | hb[1];
    else
      addr = hb[0];

    d = erb((uint8_t *)addr);
    DC('R');                    // prefix
    DH(addr,4);                 // register number
    DS_P( PSTR(" = ") );
    DH2(d);                    // result, hex
    DS_P( PSTR(" / ") );
    DU(d,2);                    // result, decimal
  }
  DNL();
}
Beispiel #7
0
void
rf_router_func(char *in)
{
  if(in[1] == 0) {               // u: display id and router
    DH2(rf_router_myid);
    DH2(rf_router_target);
    DNL();
#ifdef RFR_DEBUG 
  } else if(in[1] == 'd') {     // ud: Debug
    DH((uint16_t)ticks, 4); DC('.');
    DH2(rf_router_sendtime);
    DNL();
  } else if(in[1] == 's') {     // us: Statistics
    DH(nr_t,1); DC('.');
    DH(nr_f,1); DC('.');
    DH(nr_e,1); DC('.');
    DH(nr_k,1); DC('.');
    DH(nr_h,1); DC('.');
    DH(nr_r,1); DC('.');
    DH(nr_plus,1);
    DNL();
#endif

  } else if(in[1] == 'i') {      // uiXXYY: set own id to XX and router id to YY
    fromhex(in+2, &rf_router_myid, 1);
    ewb(EE_RF_ROUTER_ID, rf_router_myid);
    fromhex(in+4, &rf_router_target, 1);
    ewb(EE_RF_ROUTER_ROUTER, rf_router_target);

  } else {                      // uYYDATA: send data to node with id YY
    rb_reset(&RFR_Buffer);
    while(*++in)
      rb_put(&RFR_Buffer, *in);
    rf_router_send(0);

  }
}
Beispiel #8
0
void
fhtsend(char *in)
{
  uint8_t hb[6], l;                    // Last byte needed for 8v checksum
  l = fromhex(in+1, hb, 5);

  if(l < 4) {

    if(hb[0] == 1) {                   // Set housecode, clear buffers
      if(l == 3) {
        ewb(EE_FHTID  , hb[1]);        // 1.st byte: 80b relevant
        ewb(EE_FHTID+1, hb[2]);        // 1.st+2.nd byte: 8v relevant
        fht_init();
        return;

      } else {
        DH2(fht_hc0);
        DH2(fht_hc1);
      }

#ifdef HAS_FHT_80b
    } else if(hb[0] == 2) {            // Return the 80b buffer
      fht80b_print(l==1 || hb[1]==1);

    } else if(hb[0] == 3) {            // Return the remaining fht buffer
#if FHTBUF_SIZE > 255
      DH(fht_bufspace(),4);
#else
      DH2(fht_bufspace());
#endif
#endif

#ifdef HAS_FHT_8v
    } else if(hb[0] == 0x10) {         // Return the 8v buffer

      uint8_t na=0;
      for(int i = 0; i < FHT_8V_NUM; i++) {
        if(fht8v_buf[2*i] == FHT_8V_DISABLED)
          continue;
        if(na)
          DC(' ');
        DH2(i);
        DC(':');
        DH2(fht8v_buf[2*i]);
        DH2(fht8v_buf[2*i+1]);
        na++;
      }

      if(na==0)
        DS_P( PSTR("N/A") );

    } else if(hb[0] == 0x11) {         // Return the next 8v timeout
      DH2(fht8v_timeout/125);
#endif

    }
    DNL();

  } else {

#ifdef HAS_FHT_8v
    if(hb[0]>=fht_hc0 &&
       hb[0]< fht_hc0+FHT_8V_NUM &&
       hb[1]==fht_hc1) {                 // FHT8v mode commands

      if(hb[3] == FHT8V_CMD_PAIR) {
        addParityAndSend(in, FHT_CSUM_START, 2);

      } else if(hb[3] == FHT8V_CMD_SYNC){// start syncprocess for _all_ 8v's
        fht8v_ctsync = hb[4];            // use it to shorten the sync-time
        fht8v_timeout=1;

        // Cheating on the 1%
        uint8_t cnt = 0;
        for(uint8_t i = 0 ; i < FHT_8V_NUM; i++ )
          if(fht8v_buf[2*i] != FHT_8V_DISABLED )
            cnt++;
        credit_10ms += (4*fht8v_ctsync);   // should be 3.75 = 75ms / 2 / 10
        
      } else {                           // Valve position
        uint8_t idx = (hb[0]-fht_hc0)*2;
        fht8v_buf[idx  ] = hb[3];        // Command or 0xff for disable this
        fht8v_buf[idx+1] = hb[4];        // slot (valve)

      }
      return;
    }
#endif

#ifdef HAS_FHT_80b
    if(!fht_addbuf(in))                  // FHT80b mode: Queue everything
      DS_P( PSTR("EOB\r\n") );
#endif

  }
}
Beispiel #9
0
/**
 * FSAL_readdir :
 *     Read the entries of an opened directory.
 *
 * \param descriptor (input):
 *        Pointer to the directory descriptor filled by FSAL_opendir.
 * \param start_position (input):
 *        Cookie that indicates the first object to be read during
 *        this readdir operation.
 *        This should be :
 *        - FSAL_READDIR_FROM_BEGINNING for reading the content
 *          of the directory from the beginning.
 *        - The end_position parameter returned by the previous
 *          call to FSAL_readdir.
 * \param get_attr_mask (input)
 *        Specify the set of attributes to be retrieved for directory entries.
 * \param buffersize (input)
 *        The size (in bytes) of the buffer where
 *        the direntries are to be stored.
 * \param dirents (output)
 *        Adress of the buffer where the direntries are to be stored.
 * \param end_position (output)
 *        Cookie that indicates the current position in the directory.
 * \param count (output)
 *        Pointer to the number of entries read during the call.
 * \param end_of_dir (output)
 *        Pointer to a boolean that indicates if the end of dir
 *        has been reached during the call.
 *
 * \return Major error codes :
 *        - ERR_FSAL_NO_ERROR     (no error)
 *        - ERR_FSAL_FAULT        (a NULL pointer was passed as mandatory argument) 
 *        - Other error codes can be returned :
 *          ERR_FSAL_IO, ...
 */
fsal_status_t CEPHFSAL_readdir(fsal_dir_t *extdescriptor,
                               fsal_op_context_t * p_context,       /* IN */
                               fsal_cookie_t extstart,
                               fsal_attrib_mask_t attrmask,
                               fsal_mdsize_t buffersize,
                               fsal_dirent_t *dirents,
                               fsal_cookie_t *extend,
                               fsal_count_t *count,
                               fsal_boolean_t *end_of_dir)
{
  int rc = 0;
  fsal_status_t status;
  struct dirent de;
  cephfsal_dir_t* descriptor = (cephfsal_dir_t*) extdescriptor;
  struct ceph_mount_info *cmount = descriptor->ctx.export_context->cmount;

  loff_t start = ((cephfsal_cookie_t*) extstart.data)->cookie;
  loff_t* end = &((cephfsal_cookie_t*) extend->data)->cookie;
  unsigned int max_entries = buffersize / sizeof(fsal_dirent_t);

  /* sanity checks */

  if(!descriptor || !dirents || !end || !count || !end_of_dir)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_readdir);

  *end_of_dir = FALSE;
  *count = 0;

  TakeTokenFSCall();

  (void) ceph_seekdir(cmount, DH(descriptor), start);

  while ((*count <= max_entries) && !(*end_of_dir)) {
      struct stat st;

      memset(&dirents[*count], sizeof(fsal_dirent_t), 0);
      memset(&de, sizeof(struct dirent), 0);
      memset(&st, sizeof(struct stat), 0);
      int stmask = 0;

      TakeTokenFSCall();
      rc = ceph_readdirplus_r(cmount, DH(descriptor), &de, &st, &stmask);
      if (rc < 0) /* Error */
          Return(posix2fsal_error(rc), 0, INDEX_FSAL_readdir);
      else if (rc == 1) {
          /* Got a dirent */
          cephfsal_handle_t* entryhandle
            = (cephfsal_handle_t*) &(dirents[*count].handle.data);
          cephfsal_cookie_t* entrycookie
            = (cephfsal_cookie_t*) &(dirents[*count].cookie);
          /* skip . and .. */
          if(!strcmp(de.d_name, ".") || !strcmp(de.d_name, ".."))
            continue;

          entryhandle->data.vi.ino.val = st.st_ino;
          entryhandle->data.vi.snapid.val = st.st_dev;

          status = FSAL_str2name(de.d_name, FSAL_MAX_NAME_LEN,
                                 &(dirents[*count].name));
          if(FSAL_IS_ERROR(status))
            ReturnStatus(status, INDEX_FSAL_readdir);

          entrycookie->data.cookie = ceph_telldir(cmount, DH(descriptor));
          dirents[*count].attributes.asked_attributes = attrmask;

          status =
            posix2fsal_attributes(&st,
                                  &(dirents[*count].attributes));
          if(FSAL_IS_ERROR(status)) {
              FSAL_CLEAR_MASK(dirents[*count].attributes
                              .asked_attributes);
              FSAL_SET_MASK(dirents[*count].attributes.asked_attributes,
                            FSAL_ATTR_RDATTR_ERR);
            }
          if (*count != 0) {
              dirents[(*count)-1].nextentry = &(dirents[*count]);
          }
          (*count)++;
      } else if (rc == 0) /* EOF */
          *end_of_dir = TRUE;
      else{
          /* Can't happen */ 
          abort();
      }
  } /* while */

  (*end) = ceph_telldir(cmount, DH(descriptor));

  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_readdir);
}