Exemplo n.º 1
0
unsigned int strbase2uint(const char* str, unsigned int base)
{
    if (str && (str[0]) && (base < 36))
    {
        int len = ((base <= 10) ? 
          find_wrongint_pos(str, base) : find_wrongsymb_pos(str, base));

        if (len > 0)
        {
            unsigned int result = 0;
            unsigned int digit_multiplier = 1;
            int          i = len;

            while (--i >= 0)
            {
                result += char2uint(str[i])*digit_multiplier;
                digit_multiplier *= base;
            }
          
            if (result && (base <= 20))
            {
                if ((str[len] == 'M') || (str[len] == 'm'))
                    result *= (1024*1024);
                else if ((str[len] == 'k') || (str[len] == 'K'))
                    result *= 1024;
            }
            return result;
        }
    }
    return 0;
}
Exemplo n.º 2
0
/******************************************************************************
 * @fn      OTA_SplitFileName
 *
 * @brief   Get the file ID of an image from the filename text
 *
 * @param   pName - Buffer to hold the name
 *          pFileID - Pointer to File ID structure
 *
 * @return  none
 */
void OTA_SplitFileName(char *pName, zclOTA_FileID_t *pFileId)
{
  // The OTA Upgrade image file name should contain the following information
  // at the beginning of the name with each field separated by a dash ("-"): 
  // manufacturer code, image type and file version. The value of each field
  // stated should be in hexadecimal number and in capital letter. Each 
  // manufacturer may append more information to the name as seen fit to
  // make the name more specific. The OTA Upgrade file extension should be
  // ".zigbee". An example of OTA Upgrade image file name and extension is
  // "1001-00AB-10053519-upgradeMe.zigbee".
  if (pName && pFileId)
  {
    uint8 len = (uint8) osal_strlen(pName);

    if (len >= 19)
    {
      uint8 i;

      pFileId->manufacturer = 0;
      for (i=0; i<4; i++)
      {
        pFileId->manufacturer |= ((uint16) char2uint(*pName++)) << (12 - (4*i));
      }

      pName++;
      pFileId->type = 0;
      for (i=0; i<4; i++)
      {
        pFileId->type |= ((uint16) char2uint(*pName++)) << (12 - (4*i));
      }

      pName++;
      pFileId->version = 0;
      for (i=0; i<8; i++)
      {
        pFileId->version |= ((uint32) char2uint(*pName++)) << (28 - (4*i));
      }
    }
  }
}