[En-Nut-Discussion] Sending Numerical Data

MUHAMMAD AZEEM AZAM muhammadazeemazam786 at yahoo.com
Thu Feb 1 11:17:11 CET 2007


Hi     I am sending data from microcontroller in the form of 128 Bytes (i.e packet = 128 Bytes).  I want that the first 2 -Bytes should count from 1 to 65536 packets one after another.

I have to send whole array of 128 bytes but first 2 bytes shows the packet.    for   0 ->00000000Binary->'0'ASCII  but  what for  20->00100000Binary->'2''0' am i right  but how to convert to ascii    Please check code as well for improvement  -----------------------------   unsigned int packet_number = 0;    main()  {  if (strncmp(buff, "packetb\n", got_data) == 0) //If Match       {    int p_size = 128;      char p_array[p_size];      int index = 0;             p_array[0]= packet_number;     p_array[1]= packet_number;          for(index=2;index<p_size;index++)       {        p_array[index] = rand()%26+ 'a';        }          fwrite(p_array,sizeof(p_array),1,TCPStream);           packet_number ++;           continue;   }  }  


Ulrich Hertlein <ulrich.hertlein at artcom.de> wrote:  You mean how to encode/send a 16-bit int? Like that?

unsigned short packetNumber = 0xbeef;
fwrite(&packetNumber, sizeof(packetNumber), 1, TCPStream);

Cheers,
/ulrich

MUHAMMAD AZEEM AZAM wrote:
> I have to send more than 128 BYtes of Data but in the form of 128 Bytes chunk.
> The first 2 Bytes show the packet number.
> in the first 2 Bytes how can i reach upto from counting packets 0-65536. 
> 2power16 = 6536
> how is that possible
> 
> bye
> 
> "Thiago A. Corrêa" wrote:
> Muhammad,
> 
> Yeah, it appears that you are sending in ASCII. Althought I don't
> understand your code. To use the binary value just dont enclose it with ' or
> ". Sorry I can't be of further assistance but I can't make much sense of
> what the problem is.
> 
> Cheers.
> 
> 
> On 1/31/07, MUHAMMAD AZEEM AZAM wrote:
>> Hi
>>
>> I have to send now more than 128 Bytes of Data. (1 Packet = 128 BYtes)
>> The first two Bytes are numerical Numbers that shows tha packet.
>> The code below (Please if u can make it better then it would be helpful)
>> its working and showing numbers from 0 t0 99.
>> But i think its in ASCII Format.
>> 1) How can i send in Binary.
>> 2) Since 2-Bytes so i need nos from 0 to 65536.
>> hows that possible
>> ------------------------------------------------------
>> unsigned int packet_number_L = '0';
>> unsigned char packet_number_R = '0';
>> ---------------------------------------------------------
>> its the part of main()
>>
>> if (strncmp(buff, "packet\n", got_data) == 0) //If Match
>>
>> {
>> int p_size = 128;
>> char p_array[p_size];
>> int index = 0;
>>
>> p_array[0]= packet_number_L;
>> p_array[1]= packet_number_R;
>>
>> for(index=2;index
>> {
>> p_array[index] = rand()%26+'a';
>> }
>>
>> fwrite(p_array,sizeof(p_array),1,TCPStream);
>>
>>
>> if(packet_number_R == 57)
>> {
>> packet_number_R = '0';
>> packet_number_L++;
>> }
>> else
>> {
>> packet_number_R ++;
>> }
>>
>> if(packet_number_R == 57 && packet_number_L ==57)
>> {
>> packet_number_R = '0';
>> packet_number_L = '0';
>> }
>>
>> continue;
>> }

-- 
Ulrich Hertlein | Software Development

ART+COM AG
Kleiststr. 23-26 | 10787 Berlin | Germany

phone: +49.30.21001-433
fax: +49.30.21001-555
http://www.artcom.de
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion


 
---------------------------------
Never Miss an Email
Stay connected with Yahoo! Mail on your mobile. Get started!


More information about the En-Nut-Discussion mailing list