我正在嘗試Arduino最終GPS突破,我想從GPS獲取經度和緯度。然後我想通過射頻發送這兩個變量。像下面的圖像中: C中的數據類型的問題
我使用名爲panstamp所述RF模塊庫,以便能夠從阿爾杜伊諾1發送的經度和緯度,以及接收它們的Arduino 2.像在下面的代碼:
發射:
void send_data() {
CCPACKET data;
data.length=2;
float lon=26.533255;
float lat=27.533463;
data.data[0]=lon;
data.data[1]=lat;
if(cc1101.sendData(data)){
Serial.println(data.data[0]);
Serial.println(data.data[1]);
Serial.println(" sent ok ");
return true;
}else{
Serial.println("sent failed ");
return false;
}
}
接收:
void loop(){
float j = 0;
lon = packet.data[j];
Serial.print(lon);
Serial.print(" ");
float k = 1;
lat = packet.data[k];
Serial.print(lat);
Serial.println(".");
}
發射時它完美和REC eiving :)
問題是,當我收到這兩個變量我剛剛收到LON 26.00和LAT 27.00但不經度緯度26.533255 27.533463如我所料。
我假設的數據類型有一些錯誤。我調查了panstamp庫以找到改變類型但沒有成功的東西。
這裏是CCPACKET頭文件:
#ifndef _CCPACKET_H
#define _CCPACKET_H
#include "Arduino.h"
/**
* Buffer and data lengths
*/
#define CC1101_BUFFER_LEN 64
#define CC1101_DATA_LEN CC1101_BUFFER_LEN - 3
/**
* Class: CCPACKET
*
* Description:
* CC1101 data packet class
*/
class CCPACKET
{
public:
/**
* Data length
*/
byte length;
/**
* Data buffer
*/
byte data[CC1101_DATA_LEN];
/**
* CRC OK flag
*/
boolean crc_ok;
/**
* Received Strength Signal Indication
*/
byte rssi;
/**
* Link Quality Index
*/
byte lqi;
};
#endif
和發送數據的源代碼/接收數據:
boolean CC1101::sendData(CCPACKET packet)
{
byte marcState;
bool res = false;
// Declare to be in Tx state. This will avoid receiving packets whilst
// transmitting
rfState = RFSTATE_TX;
// Enter RX state
setRxState();
// Check that the RX state has been entered
while (((marcState = readStatusReg(CC1101_MARCSTATE)) & 0x1F) != 0x0D)
{
if (marcState == 0x11) // RX_OVERFLOW
flushRxFifo(); // flush receive queue
}
delayMicroseconds(500);
// Set data length at the first position of the TX FIFO
writeReg(CC1101_TXFIFO, packet.length);
// Write data into the TX FIFO
writeBurstReg(CC1101_TXFIFO, packet.data, packet.length);
// CCA enabled: will enter TX state only if the channel is clear
setTxState();
// Check that TX state is being entered (state = RXTX_SETTLING)
marcState = readStatusReg(CC1101_MARCSTATE) & 0x1F;
if((marcState != 0x13) && (marcState != 0x14) && (marcState != 0x15))
{
setIdleState(); // Enter IDLE state
flushTxFifo(); // Flush Tx FIFO
setRxState(); // Back to RX state
// Declare to be in Rx state
rfState = RFSTATE_RX;
return false;
}
// Wait for the sync word to be transmitted
wait_GDO0_high();
// Wait until the end of the packet transmission
wait_GDO0_low();
// Check that the TX FIFO is empty
if((readStatusReg(CC1101_TXBYTES) & 0x7F) == 0)
res = true;
setIdleState(); // Enter IDLE state
flushTxFifo(); // Flush Tx FIFO
// Enter back into RX state
setRxState();
// Declare to be in Rx state
rfState = RFSTATE_RX;
return res;
}
byte CC1101::receiveData(CCPACKET * packet)
{
byte val;
byte rxBytes = readStatusReg(CC1101_RXBYTES);
// Any byte waiting to be read and no overflow?
if (rxBytes & 0x7F && !(rxBytes & 0x80))
{
// Read data length
packet->length = readConfigReg(CC1101_RXFIFO);
// If packet is too long
if (packet->length > CC1101_DATA_LEN)
packet->length = 0; // Discard packet
else
{
// Read data packet
readBurstReg(packet->data, CC1101_RXFIFO, packet->length);
// Read RSSI
packet->rssi = readConfigReg(CC1101_RXFIFO);
// Read LQI and CRC_OK
val = readConfigReg(CC1101_RXFIFO);
packet->lqi = val & 0x7F;
packet->crc_ok = bitRead(val, 7);
}
}
else
packet->length = 0;
setIdleState(); // Enter IDLE state
flushRxFifo(); // Flush Rx FIFO
//cmdStrobe(CC1101_SCAL);
// Back to RX state
setRxState();
return packet->length;
}
請幫助我的人:)
的鏈接在Panstamp庫:PanStamp Library
爲什麼你不能收到雙打?你正在失去精確度,這就是問題所在?此外,你已經指出,庫代碼可能有錯誤 – ha9u63ar 2014-10-28 11:12:41
這是我失去了精度的問題。但我能做些什麼來接收雙打或浮標?這是我的問題。 – AdiT 2014-10-28 11:17:35
可能是這個賦值工作不正常,data.data [0] = lon; data.data [1] = lat,在這裏您將float轉換爲字節類型 – 2014-10-28 11:30:09