[chirp_devel] def convert_freq_to_bytes(real_freq):

IZ3GME Marco
Tue Jan 22 00:32:20 PST 2013


The answer is:

def convert_freq_to_bytes(freq):
     bytes = [ 0 for x in range(0,8) ]   # init list with 8 times 0
     real_freq = int(freq * 100000)      # it has to be integer
     for i in range(7, -1, -1):          # go from 7 to 0
         bytes[i] = real_freq%10         # extract last digit
         real_freq /= 10                 # throw away last digit
     return bytes

I'm not a python guru, may be this can be done better with some python 
magics but this function just works :)

73 de IZ3GME


On 22/01/2013 04:08, Jim Unroe wrote:
> Hi group,
>
> I'm trying to create a helper function to convert a floating point
> number to a group of bytes
>
> For example I have this value: 146.52000
> I think I need it change to something like
> 0x01,0x04,0x06,0x05,0x02,0x00,0x00,0x00
>
> The first thing I beieve I need to do is shift the decimal point to the
> right 5 places. So I did this
>
>      real_freq *= 100000.0
>
> I believe this gets me 14652000
>
> Now I think I need to do something like this to separate the individual
> digits
>
>      digits =[int(i) for i in str(real_freq)]
>
> I'm not positive, but I think this makes an array something like
>
> digits[0] = 1
> digits[1] = 4
> digits[2] = 6
> digits[3] = 5
> digits[4] = 2
> digits[5] = 0
> digits[6] = 0
> digits[7] = 0
>
> Here is where I'm stuck. I've tried a few think but so far no luck. I've
> searched the other drivers to see if I could locate something similar.
> If there is, I missed it.
>
> Then ultimately, I think I need to end with
>
>      return bytes
>
> So am I on the right track? Any advice on what I need to do next.
>
> Thanks,
> Jim
>
>
>
>
> _______________________________________________
> chirp_devel mailing list
> chirp_devel at intrepid.danplanet.com
> http://intrepid.danplanet.com/mailman/listinfo/chirp_devel
> Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
>




More information about the chirp_devel mailing list