Linux のポートからデータを読み込もうとしているのですが、このデータを使用したいのですが、次のコードを記述すると、データの各バイトが配列内の 1 つのセルに格納されると思いましたが、テストしようとするとそれを印刷すると、常に最初のバイトがデータ全体を印刷し、他のすべてのバイトは空になります。読み取った各バイトを1つのセルに格納する方法を知っている人はいますか? コードは書き留められています。不足しているものを教えてください。
int decode_gps() {
while(1){
unsinged int UBX_buffer[40];
if (read(fd,&UBX_buffer,1)>0) {
// cout<<UBX_buffer[0]<<endl;
switch(UBX_step) //we start from zero and increment as we go through the cases
{
case 0:
if(UBX_buffer[0]==0xB5) UBX_step++; break; // UBX sync char 1 //check for the first data packet and go to next byte
case 1: if(UBX_buffer[1]==0x62) UBX_step++;// UBX sync char 2 //check for the second data packet and go to the next byte
else UBX_step=0; break; //if first and second packets are not correct then go back and check again
case 2: UBX_class=UBX_buffer[2]; checksum(UBX_class); UBX_step++; break;
case 3: UBX_id=UBX_buffer[3]; checksum(UBX_id); UBX_step++; break;
case 4: UBX_payload_length_hi=UBX_buffer[4]; checksum(UBX_payload_length_hi); UBX_step++; break;
case 5: UBX_payload_length_lo=UBX_buffer[5]; checksum(UBX_payload_length_lo); UBX_step++; break;
case 6: // Payload data read...
if (UBX_payload_counter < UBX_payload_length_hi) // We stay in this state until we reach the payload_length
{
UBX_buffer[UBX_payload_counter] = data;
checksum(data);
UBX_payload_counter++;
}
else
UBX_step++;
break;
case 7: ck_a=data; UBX_step++; break; // First checksum byte
case 8: ck_b=data; // Second checksum byte
// We end the GPS read...
if((ck_a= ck_a)&&(ck_b= ck_a)) // Verify the received checksum with the generated checksum..
parse_ubx_gps(); // Parse new GPS packet...
UBX_step=0;
UBX_payload_counter=0;
ck_a=0;
ck_b=0;
GPS_timer=0; //Restarting timer...
break;
} // End Switch
} //end if
} //end while loop
close(fd);
return(0);
}