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