Jump to content

pdoria

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

pdoria's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thx ragax! Yea ... lots of fun.. C++/Qt4, PHP, SQL ... ... .... two open IDE's (eclipse/kdevelop) ... Have a gr8 weekend too!
  2. Thx Psycho! and sorry to have posted in the wrong forum earlier...
  3. Hi guys Since I'm not that good with regex I'm doing this quite the lame way ... <?php $string="[0:1]={1967,1968}"; $regex="#([[](.*)[]]=)#e"; $output=preg_replace($regex, '', $string); print ( $output . "<br/>" ); $search=array('{', '}'); $output=str_replace($search, "", $output); print ( $output ); ?> How can I do this in one pass using regex only? Thx in advance!
  4. Hi MadTechie Thanks for replying! Actually I've solved my problem of outputting the data with: for ($n=0; $n < strlen($buf); $n++) { printf("%02X\r\n", bin2hex($buf[$n])); } Now I'm having what seems to be an alignment problem... :-\ This code: $header ="\x01\x00\x00\x00"; // header $datalength ="\x00\x00\x00\x08"; // data length $codecid ="\x0A"; // codec ID $nrecs ="\x01"; // # of recs // garmin avl data $DLE ="\x10"; // DLE $packetid ="\xA1"; // packet id (161) $size_app_payload ="\x02"; // size_app_payload $fmi_packet_id = reverse_endianess_short (0x0001); // fmi packet id $checksum= $packetid+$size_app_payload+$fmi_packet_id; $checksum = -$checksum; $checksum &= 0xff; $ETX="\x03"; $buf=""; $buf=$header.$datalength.$codecid.$nrecs.$DLE.$packetid.$size_app_payload.$fmi_packet_id.$checksum.$DLE.$ETX.$nrecs; // crc16 $crc16=0; $garminAVLData=array(); $garminAVLData[]=$DLE; $garminAVLData[]=$packetid; $garminAVLData[]=$size_app_payload; $garminAVLData[]=$fmi_packet_id; $garminAVLData[]=$checksum; $garminAVLData[]=$DLE; $garminAVLData[]=$ETX; foreach ($garminAVLData as $val) { $crc=crc16($val, $crc16); } //$crc16 = pack("N", bin2hex($crc16)); $buf.=$crc16; printf("Len: %d - IP: %s\r\n", strlen($buf), $ip); for ($n=0; $n < strlen($buf); $n++) { printf("%02X\r\n", bin2hex($buf[$n])); } Outputs this: 01 00 00 00 00 00 00 08 00 01 0A 00 02 01 00 1E 0A 03 01 1E One thing that pops to view is the wrong order for $codecid and $nrecs ... The other is what I think are alignment issues... What can I do to have a byte be a byte in $buf (IOW serialize the data)? Already thankful for any help you can spare, Best regards, Pedro Doria Meunier
  5. Hi All, Coming from the C# world I'm in a bit of pickle here trying to handle binary data and sending it to a socket... Here's what I'm trying to do: $header ="\x01\x00\x00\x00"; // header $datalength ="\x08"; // data length $codecid ="\x0A"; // codec ID $nrecs ="\x01"; // # of recs // garmin avl data $DLE ="\x10"; // DLE $packetid ="\xA1"; // packet id (161) $size_app_payload ="\x02"; // size_app_payload $fmi_packet_id = reverse_endianess_short (0x0001); // fmi packet id $checksum= $packetid+$size_app_payload+$fmi_packet_id; $checksum = -$checksum; $checksum &= 0xff; $ETX="\x03"; $buf=""; $buf=$header.$datalength.$codecid.$nrecs.$DLE.$packetid.$size_app_payload.$fmi_packet_id.$checksum.$DLE.$ETX."\x01"; First question: Is this the right way to construct the buffer? First difficulty: print the $buf contents as to check it out... This for ($n=0; $n < strlen($buf); $n++) { printf("%02X\r\n", $buf[$n]); } Only outputs zeroes... Any pointers highly appreciated... BR, Pedro Doria Meunier
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.