Merhaba,
Bir arduino kütüphanesini inceliyordum.C++ pek bilmediğinden bazı kısımlarda takıldım.Proje dosyaları: http://www.dosya.tc/server7/1b2l85/RF22Lib.zip.html (http://www.dosya.tc/server7/1b2l85/RF22Lib.zip.html)
Olayı açıklayarak gitmeye çalışacağım.Dosyaların arasında RHReliableDatagram.h ve .c dosyaları mevcut. Bu dosyada (RHReliableDatagram.h içinde) tanımlanan class ta RHDatagram dosyasını miras olarak almış;
class RHReliableDatagram : public RHDatagram
{
...
}
RHDatagram dosyası da
class RHDatagram
{
public:
...
protected:
/// The Driver we are to use
RHGenericDriver& _driver;
};
Şeklinde başka bir class ı kendi içinde tanımlıyor.Bu da demek oluyor ki ben RHReliableDatagram içinde RHGenericDriver'a ait herhangi bir şeyi kullanabilirim.Doğru mudur?
Devam ediyorum.
RHGenericDriver içerisinde virtual olarak tanımlanmış şeyler mevcut.Bu konuya biraz baktım.Base bir class'ın child class lara ait bazı ortak özelliklerini içermesi ve hangi child classın kullanıldığına bakılmaksızın doğrudan (base class-ilgili child class üzerinden) istenen child class özelliğinin kullanılması olayı imiş.Bu anlatımda yorumum da var sitede yazanların direk aktarımı da.Kısaca;
hayvan classı olsun.Bütün hayvanlar yer, içer. Kurt, köpek, inek, balık diye başka classlar (child) tanımlayalım.Bütün classların da yemek diye özellikleri olsun (yada nitelik mi deniyordu? -properties/attirubute-).Bu yemek özelliği de hayvan classı içinde virtual olarak tanımlanıyor.Neyse konu dağılıyor.Şurada anlatılanları aktarmaya çalıştım; http://cuneytcarikci.blogspot.com.tr/2012/04/c-virtualsanal-fonksiyonlar-ornegi.html (http://cuneytcarikci.blogspot.com.tr/2012/04/c-virtualsanal-fonksiyonlar-ornegi.html)
Sonraki adım olarak, bu kütüphanenin kullanımında şunu görüyorum.
main fonksiyon içinde RH_RF22 driver; RHReliableDatagram manager(driver, SERVER_ADDRESS);
şeklinde bir tanım var.Zaten dikkat edilirse RHReliableDatagram ın kurucu fonksiyonu GenericDriver olarak parametre alıyordu.Class ilişkilerine baktığımda RF22 ile GenericDriver arasındaki ilişki şöyle;
RF22 class içinde
class RH_RF22 : public RHSPIDriver
{
...
}
Şeklinde tanım var.RHSPIDriver classı ise;
class RHSPIDriver : public RHGenericDriver
{
...
protected:
RHGenericSPI& _spi;
};
Şeklinde tanımlanmış.Yani RF22 ile GenericDriver classları RHSPIDriver classı üzerinden kurulmuş.Benim buradan anladığım, RF22 classı üzerinden GenericDriver a ait özellikleri kullanabilirim.Ki burada bir enteresanlık var.Bu GenericDriver içinde herşey virtual tanımlanmış.Virtual tanımlanan şeyler de bu RF22 içerisinde.Şimdi ilişkisel olarak bakınca RHReliableDatagram ile RF22 arasında bir bağlantı yok.Yalnızca ikisi de ortak bir classı kendi içlerine mirasçı olarak almışlar.Yani ikisi de GenericDriver classında yer alanları miras almışlar.
Peki nasıl oluyor da RHReliableDatagram üzerinden RF22 üzerindeki özellikleri kullanabiliyor?
Diğer bir sorum da ben bu yapıyı derlediğimde bir sürü hata ve uyarı alıyorum.Bunlar neden oluşuyor?Acaba derleyip deneyebilir misiniz?
Alıntı yapılan: yldzelektronik - 11 Nisan 2016, 18:07:49
Bu da demek oluyor ki ben RHReliableDatagram içinde RHGenericDriver'a ait herhangi bir şeyi kullanabilirim.Doğru mudur?
_driver isimli değişken üzerinden çağrılma yapılabilir ama hem protected olarak tanımlanmasından, hem de adının _ ile başlamasından yola çıkarak, bu değişkenin dışarıdan kullanılmayan bir değişken olduğunu söyleyebiliriz.
Nesne yönelimli programlamada düşünme şeklini değiştirmen gerekiyor. Son kullanıcının RHGenericDriver türevlerini bir kez oluşturup bu nesneleri de RHDatagram ve türevlerinin oluşturulması haricinde kullanmaması amaçlanmış anladığım kadarıyla. Koda bakmadım ama RHGenericDriver içinde boş virtual fonksiyonlar haricinde bir şey yoksa, bu class'ı Java'cıların ifadesi ile bir
Interface olarak görmek gerekir (C++'ta sanırım
Pure Virtual Class deniyor). Yani bu class sadece kendinden türetilen diğer class'lar için bir sınır çiziyor ve içermeler gereken ortak özellikleri belirliyor.
RHDatagram büyük ihtimalle kendi içindeki _driver değişkeni üzerinden bazı işlemler yaparak RHGenericDriver'da tanımlı işlemlerin bir kısmını veya tamamını kullanıyordur. Bu işlemlerin ne şekilde çalışacakları da büyük ihtimalle RHSPIDriver ve RH_RF22 class'ları içinde tanımlıdır.
Bu arada, aldığın hata ve uyarılar nedir?
@Tagli kırk küsür hata kırk falan da uyarı vardı.Buraya nasıl taşıyabilirim bilmiyorum.Bir deneyeyim.
Düzeltme: Hata mesajlarını kopyalıyorum buraya:
Rebuild target 'SensorNetwork'
assembling startup_stm32f0xx.s...
compiling system_stm32f0xx.c...
compiling main.cpp...
..\User\src\RadioHead\RHHardwareSPI.h(35): warning: #1300-D: transfer inherits implicit virtual
uint8_t transfer(uint8_t data);
..\User\src\RadioHead\RHHardwareSPI.h(41): warning: #1300-D: attachInterrupt inherits implicit virtual
void attachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(45): warning: #1300-D: detachInterrupt inherits implicit virtual
void detachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(50): warning: #1300-D: begin inherits implicit virtual
void begin();
..\User\src\RadioHead\RHHardwareSPI.h(54): warning: #1300-D: end inherits implicit virtual
void end();
..\User\src\RadioHead\RHSPIDriver.h(50): warning: #1300-D: init inherits implicit virtual
bool init();
..\User\src\RadioHead\RH_RF22.h(943): warning: #1300-D: init inherits implicit virtual
bool init();
..\User\src\RadioHead\RH_RF22.h(1064): warning: #1300-D: available inherits implicit virtual
bool available();
..\User\src\RadioHead\RH_RF22.h(1075): warning: #1300-D: recv inherits implicit virtual
bool recv (uint8_t *buf, uint8_t *len);
..\User\src\RadioHead\RH_RF22.h(1083): warning: #1300-D: send inherits implicit virtual
bool send (const uint8_t *data, uint8_t len);
..\User\src\RadioHead\RH_RF22.h(1131): warning: #1300-D: maxMessageLength inherits implicit virtual
uint8_t maxMessageLength();
..\User\src\RadioHead\RH_RF22.h(1207): warning: #1300-D: setThisAddress inherits implicit virtual
void setThisAddress (uint8_t thisAddress);
..\User\src\main.cpp: 12 warnings, 0 errors
compiling stm32f0xx_it.c...
..\User\src\RadioHead\STM32ArduinoCompat\wirish.h(78): warning: #1295-D: Deprecated declaration millis - give arg types
extern uint32_t millis();
..\User\src\RadioHead\STM32ArduinoCompat\wirish.h(98): error: #20: identifier "class" is undefined
class SerialUSBClass
..\User\src\RadioHead\STM32ArduinoCompat\wirish.h(99): error: #65: expected a ";"
{
..\User\src\RadioHead\STM32ArduinoCompat\wirish.h(152): warning: #12-D: parsing restarts here after previous syntax error
};
..\User\src\RadioHead\STM32ArduinoCompat\wirish.h(155): error: #757: variable "SerialUSBClass" is not a type name
extern SerialUSBClass SerialUSB;
..\User\src\RadioHead\STM32ArduinoCompat\HardwareSPI.h(24): error: #20: identifier "class" is undefined
class HardwareSPI
..\User\src\RadioHead\STM32ArduinoCompat\HardwareSPI.h(25): error: #65: expected a ";"
{
..\User\src\RadioHead\STM32ArduinoCompat\HardwareSPI.h(34): warning: #12-D: parsing restarts here after previous syntax error
};
..\User\src\RadioHead\STM32ArduinoCompat\HardwareSPI.h(35): error: #757: variable "HardwareSPI" is not a type name
extern HardwareSPI SPI_HW;
..\User\src\RadioHead\RHGenericSPI.h(30): error: #20: identifier "class" is undefined
class RHGenericSPI
..\User\src\RadioHead\RHGenericSPI.h(31): error: #65: expected a ";"
{
..\User\src\RadioHead\RHGenericSPI.h(62): warning: #12-D: parsing restarts here after previous syntax error
} Frequency;
..\User\src\RadioHead\RHGenericSPI.h(85): error: #20: identifier "Frequency" is undefined
RHGenericSPI (Frequency frequency = Frequency1MHz, BitOrder bitOrder = BitOrderMSBFirst, DataMode dataMode = DataMode0);
..\User\src\RadioHead\RHGenericSPI.h(85): error: #18: expected a ")"
RHGenericSPI (Frequency frequency = Frequency1MHz, BitOrder bitOrder = BitOrderMSBFirst, DataMode dataMode = DataMode0);
..\User\src\RadioHead\RHGenericSPI.h(85): warning: #77-D: this declaration has no storage class or type specifier
RHGenericSPI (Frequency frequency = Frequency1MHz, BitOrder bitOrder = BitOrderMSBFirst, DataMode dataMode = DataMode0);
..\User\src\RadioHead\RHGenericSPI.h(85): error: #147: declaration is incompatible with "<error-type> RHGenericSPI" (declared at line 30)
RHGenericSPI (Frequency frequency = Frequency1MHz, BitOrder bitOrder = BitOrderMSBFirst, DataMode dataMode = DataMode0);
..\User\src\RadioHead\RHGenericSPI.h(90): error: #20: identifier "virtual" is undefined
virtual uint8_t transfer (uint8_t data) = 0;
..\User\src\RadioHead\RHGenericSPI.h(90): error: #101: "uint8_t" has already been declared in the current scope
virtual uint8_t transfer (uint8_t data) = 0;
..\User\src\RadioHead\RHGenericSPI.h(90): error: #65: expected a ";"
virtual uint8_t transfer (uint8_t data) = 0;
..\User\src\RadioHead\RHGenericSPI.h(95): error: #77-D: this declaration has no storage class or type specifier
virtual void attachInterrupt() {};
..\User\src\RadioHead\RHGenericSPI.h(95): error: #65: expected a ";"
virtual void attachInterrupt() {};
..\User\src\RadioHead\RHGenericSPI.h(99): error: #77-D: this declaration has no storage class or type specifier
virtual void detachInterrupt() {};
..\User\src\RadioHead\RHGenericSPI.h(99): error: #65: expected a ";"
virtual void detachInterrupt() {};
..\User\src\RadioHead\RHGenericSPI.h(103): error: #77-D: this declaration has no storage class or type specifier
virtual void begin() = 0;
..\User\src\RadioHead\RHGenericSPI.h(103): error: #65: expected a ";"
virtual void begin() = 0;
..\User\src\RadioHead\RHGenericSPI.h(107): error: #77-D: this declaration has no storage class or type specifier
virtual void end() = 0;
..\User\src\RadioHead\RHGenericSPI.h(107): error: #65: expected a ";"
virtual void end() = 0;
..\User\src\RadioHead\RHGenericSPI.h(113): error: #77-D: this declaration has no storage class or type specifier
virtual void setBitOrder (BitOrder bitOrder);
..\User\src\RadioHead\RHGenericSPI.h(113): error: #65: expected a ";"
virtual void setBitOrder (BitOrder bitOrder);
..\User\src\RadioHead\RHGenericSPI.h(118): error: #77-D: this declaration has no storage class or type specifier
virtual void setDataMode (DataMode dataMode);
..\User\src\RadioHead\RHGenericSPI.h(118): error: #65: expected a ";"
virtual void setDataMode (DataMode dataMode);
..\User\src\RadioHead\RHGenericSPI.h(125): error: #77-D: this declaration has no storage class or type specifier
virtual void setFrequency (Frequency frequency);
..\User\src\RadioHead\RHGenericSPI.h(125): error: #65: expected a ";"
virtual void setFrequency (Frequency frequency);
..\User\src\RadioHead\RHGenericSPI.h(127): error: #77-D: this declaration has no storage class or type specifier
protected:
..\User\src\RadioHead\RHGenericSPI.h(127): error: #65: expected a ";"
protected:
..\User\src\stm32f0xx_it.c: 5 warnings, 30 errors
compiling SensorNetwork.c...
compiling Delay.c...
compiling stm32f0xx_adc.c...
compiling stm32f0xx_exti.c...
compiling stm32f0xx_flash.c...
compiling stm32f0xx_gpio.c...
compiling stm32f0xx_i2c.c...
compiling stm32f0xx_misc.c...
compiling stm32f0xx_pwr.c...
compiling stm32f0xx_rcc.c...
compiling stm32f0xx_rtc.c...
compiling stm32f0xx_spi.c...
compiling stm32f0xx_syscfg.c...
compiling stm32f0xx_tim.c...
compiling RH_RF22.cpp...
..\User\src\RadioHead\RHHardwareSPI.h(35): warning: #1300-D: transfer inherits implicit virtual
uint8_t transfer(uint8_t data);
..\User\src\RadioHead\RHHardwareSPI.h(41): warning: #1300-D: attachInterrupt inherits implicit virtual
void attachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(45): warning: #1300-D: detachInterrupt inherits implicit virtual
void detachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(50): warning: #1300-D: begin inherits implicit virtual
void begin();
..\User\src\RadioHead\RHHardwareSPI.h(54): warning: #1300-D: end inherits implicit virtual
void end();
..\User\src\RadioHead\RHSPIDriver.h(50): warning: #1300-D: init inherits implicit virtual
bool init();
..\User\src\RadioHead\RH_RF22.h(943): warning: #1300-D: init inherits implicit virtual
bool init();
..\User\src\RadioHead\RH_RF22.h(1064): warning: #1300-D: available inherits implicit virtual
bool available();
..\User\src\RadioHead\RH_RF22.h(1075): warning: #1300-D: recv inherits implicit virtual
bool recv (uint8_t *buf, uint8_t *len);
..\User\src\RadioHead\RH_RF22.h(1083): warning: #1300-D: send inherits implicit virtual
bool send (const uint8_t *data, uint8_t len);
..\User\src\RadioHead\RH_RF22.h(1131): warning: #1300-D: maxMessageLength inherits implicit virtual
uint8_t maxMessageLength();
..\User\src\RadioHead\RH_RF22.h(1207): warning: #1300-D: setThisAddress inherits implicit virtual
void setThisAddress (uint8_t thisAddress);
..\User\src\RadioHead\RH_RF22.cpp(685): warning: #186-D: pointless comparison of unsigned integer with zero
if (polynomial >= CRC_CCITT &&
..\User\src\RadioHead\RH_RF22.cpp: 13 warnings, 0 errors
compiling RHDatagram.cpp...
compiling RHReliableDatagram.cpp...
compiling RHGenericDriver.cpp...
compiling HardwareSPI.cpp...
compiling RHHardwareSPI.cpp...
..\User\src\RadioHead\RHHardwareSPI.h(35): warning: #1300-D: transfer inherits implicit virtual
uint8_t transfer(uint8_t data);
..\User\src\RadioHead\RHHardwareSPI.h(41): warning: #1300-D: attachInterrupt inherits implicit virtual
void attachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(45): warning: #1300-D: detachInterrupt inherits implicit virtual
void detachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(50): warning: #1300-D: begin inherits implicit virtual
void begin();
..\User\src\RadioHead\RHHardwareSPI.h(54): warning: #1300-D: end inherits implicit virtual
void end();
..\User\src\RadioHead\RHHardwareSPI.cpp: 5 warnings, 0 errors
compiling RHSPIDriver.cpp...
..\User\src\RadioHead\RHHardwareSPI.h(35): warning: #1300-D: transfer inherits implicit virtual
uint8_t transfer(uint8_t data);
..\User\src\RadioHead\RHHardwareSPI.h(41): warning: #1300-D: attachInterrupt inherits implicit virtual
void attachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(45): warning: #1300-D: detachInterrupt inherits implicit virtual
void detachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(50): warning: #1300-D: begin inherits implicit virtual
void begin();
..\User\src\RadioHead\RHHardwareSPI.h(54): warning: #1300-D: end inherits implicit virtual
void end();
..\User\src\RadioHead\RHSPIDriver.h(50): warning: #1300-D: init inherits implicit virtual
bool init();
..\User\src\RadioHead\RHSPIDriver.cpp: 6 warnings, 0 errors
compiling RHGenericSPI.cpp...
".\Objects\SensorNetwork.axf" - 30 Error(s), 41 Warning(s).
Target not created
Alıntı yapılan: gerbay - 12 Nisan 2016, 00:36:05
hocam C dosyanızdan içerisinde C++ a özel tanımlar içeren header ları include etmemlisiniz..
stm32f0xx_it.c dosyasında "RH_RF22.h" dosyasını include ediyorsunuz, orada class tanımları var.
ilgili dosyadaki
//#include <RH_RF22.h>
satırını commentleyin..
Bunu yaptığımda ;
Rebuild target 'SensorNetwork'
assembling startup_stm32f0xx.s...
compiling system_stm32f0xx.c...
compiling main.cpp...
..\User\src\RadioHead\RHHardwareSPI.h(35): warning: #1300-D: transfer inherits implicit virtual
uint8_t transfer(uint8_t data);
..\User\src\RadioHead\RHHardwareSPI.h(41): warning: #1300-D: attachInterrupt inherits implicit virtual
void attachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(45): warning: #1300-D: detachInterrupt inherits implicit virtual
void detachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(50): warning: #1300-D: begin inherits implicit virtual
void begin();
..\User\src\RadioHead\RHHardwareSPI.h(54): warning: #1300-D: end inherits implicit virtual
void end();
..\User\src\RadioHead\RHSPIDriver.h(50): warning: #1300-D: init inherits implicit virtual
bool init();
..\User\src\RadioHead\RH_RF22.h(943): warning: #1300-D: init inherits implicit virtual
bool init();
..\User\src\RadioHead\RH_RF22.h(1064): warning: #1300-D: available inherits implicit virtual
bool available();
..\User\src\RadioHead\RH_RF22.h(1075): warning: #1300-D: recv inherits implicit virtual
bool recv (uint8_t *buf, uint8_t *len);
..\User\src\RadioHead\RH_RF22.h(1083): warning: #1300-D: send inherits implicit virtual
bool send (const uint8_t *data, uint8_t len);
..\User\src\RadioHead\RH_RF22.h(1131): warning: #1300-D: maxMessageLength inherits implicit virtual
uint8_t maxMessageLength();
..\User\src\RadioHead\RH_RF22.h(1207): warning: #1300-D: setThisAddress inherits implicit virtual
void setThisAddress (uint8_t thisAddress);
..\User\src\main.cpp: 12 warnings, 0 errors
compiling stm32f0xx_it.c...
compiling SensorNetwork.c...
compiling Delay.c...
compiling stm32f0xx_adc.c...
compiling stm32f0xx_exti.c...
compiling stm32f0xx_flash.c...
compiling stm32f0xx_gpio.c...
compiling stm32f0xx_i2c.c...
compiling stm32f0xx_misc.c...
compiling stm32f0xx_pwr.c...
compiling stm32f0xx_rcc.c...
compiling stm32f0xx_rtc.c...
compiling stm32f0xx_spi.c...
compiling stm32f0xx_syscfg.c...
compiling stm32f0xx_tim.c...
compiling RH_RF22.cpp...
..\User\src\RadioHead\RHHardwareSPI.h(35): warning: #1300-D: transfer inherits implicit virtual
uint8_t transfer(uint8_t data);
..\User\src\RadioHead\RHHardwareSPI.h(41): warning: #1300-D: attachInterrupt inherits implicit virtual
void attachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(45): warning: #1300-D: detachInterrupt inherits implicit virtual
void detachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(50): warning: #1300-D: begin inherits implicit virtual
void begin();
..\User\src\RadioHead\RHHardwareSPI.h(54): warning: #1300-D: end inherits implicit virtual
void end();
..\User\src\RadioHead\RHSPIDriver.h(50): warning: #1300-D: init inherits implicit virtual
bool init();
..\User\src\RadioHead\RH_RF22.h(943): warning: #1300-D: init inherits implicit virtual
bool init();
..\User\src\RadioHead\RH_RF22.h(1064): warning: #1300-D: available inherits implicit virtual
bool available();
..\User\src\RadioHead\RH_RF22.h(1075): warning: #1300-D: recv inherits implicit virtual
bool recv (uint8_t *buf, uint8_t *len);
..\User\src\RadioHead\RH_RF22.h(1083): warning: #1300-D: send inherits implicit virtual
bool send (const uint8_t *data, uint8_t len);
..\User\src\RadioHead\RH_RF22.h(1131): warning: #1300-D: maxMessageLength inherits implicit virtual
uint8_t maxMessageLength();
..\User\src\RadioHead\RH_RF22.h(1207): warning: #1300-D: setThisAddress inherits implicit virtual
void setThisAddress (uint8_t thisAddress);
..\User\src\RadioHead\RH_RF22.cpp(685): warning: #186-D: pointless comparison of unsigned integer with zero
if (polynomial >= CRC_CCITT &&
..\User\src\RadioHead\RH_RF22.cpp: 13 warnings, 0 errors
compiling RHDatagram.cpp...
compiling RHReliableDatagram.cpp...
compiling RHGenericDriver.cpp...
compiling HardwareSPI.cpp...
compiling RHHardwareSPI.cpp...
..\User\src\RadioHead\RHHardwareSPI.h(35): warning: #1300-D: transfer inherits implicit virtual
uint8_t transfer(uint8_t data);
..\User\src\RadioHead\RHHardwareSPI.h(41): warning: #1300-D: attachInterrupt inherits implicit virtual
void attachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(45): warning: #1300-D: detachInterrupt inherits implicit virtual
void detachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(50): warning: #1300-D: begin inherits implicit virtual
void begin();
..\User\src\RadioHead\RHHardwareSPI.h(54): warning: #1300-D: end inherits implicit virtual
void end();
..\User\src\RadioHead\RHHardwareSPI.cpp: 5 warnings, 0 errors
compiling RHSPIDriver.cpp...
..\User\src\RadioHead\RHHardwareSPI.h(35): warning: #1300-D: transfer inherits implicit virtual
uint8_t transfer(uint8_t data);
..\User\src\RadioHead\RHHardwareSPI.h(41): warning: #1300-D: attachInterrupt inherits implicit virtual
void attachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(45): warning: #1300-D: detachInterrupt inherits implicit virtual
void detachInterrupt();
..\User\src\RadioHead\RHHardwareSPI.h(50): warning: #1300-D: begin inherits implicit virtual
void begin();
..\User\src\RadioHead\RHHardwareSPI.h(54): warning: #1300-D: end inherits implicit virtual
void end();
..\User\src\RadioHead\RHSPIDriver.h(50): warning: #1300-D: init inherits implicit virtual
bool init();
..\User\src\RadioHead\RHSPIDriver.cpp: 6 warnings, 0 errors
compiling RHGenericSPI.cpp...
linking...
.\Objects\SensorNetwork.axf: Error: L6218E: Undefined symbol delay(unsigned) (referred from rh_rf22.o).
.\Objects\SensorNetwork.axf: Error: L6218E: Undefined symbol millis() (referred from rh_rf22.o).
.\Objects\SensorNetwork.axf: Error: L6218E: Undefined symbol SerialUSB (referred from rhgenericdriver.o).
.\Objects\SensorNetwork.axf: Error: L6218E: Undefined symbol digitalWrite(unsigned char, unsigned char) (referred from rhspidriver.o).
.\Objects\SensorNetwork.axf: Error: L6218E: Undefined symbol pinMode(unsigned char, WiringPinMode) (referred from rhspidriver.o).
Not enough information to list image symbols.
Finished: 1 information, 0 warning and 5 error messages.
".\Objects\SensorNetwork.axf" - 5 Error(s), 36 Warning(s).
Target not created
Mesajlarını alıyorum.
Alıntı yapılan: gerbay - 12 Nisan 2016, 00:36:05
o durumda 6 hata kalıyor;
bunlar linker ın link aşamasında bulamadığı fonksiyonlar. örneğin "handleInterrupt" metodu "C_RF22.c" dosyasında kodlanmış ama siz o dosyayı projeye dahil etmemişsiniz..
örneğin o dosyayı projeye ekleyip derlediğimizdeki durum;
görüldüğü gibi hata sayısı 5 e düştü. bu metodun kodu link aşamasında bulunamıyor. bu metodların olduğu dosyanın da projeye eklenip düzgünce derlenip link olayına katılması lazım..
ben baktığımda bu metodların arduino uyumlandırma katmanı olarak yazılmış kısımdaki "wirish.cpp" dosyasında olduğunu gördüm. onu projeye eklediğimde bu hatalar geçiyor ama başka hatalar geliyor; toplam 19 hata...
bunlar HAL library de olmalı diye hatırlıyorum ama sizin projede StdPerip.. kullanılmış.. bu tanımların olduğu dosyayı da ekleyip build ederseniz hata kalmaz sanırım..
"handleInterrupt" fonksiyonunu commentledikten sonra -ki zaten projeyi upload ettiğimde de commentlenmiş halde idi diye hatırlıyorum.Yanılıyor da olabilirim.- da yukarıdaki hata mesajlarının aynını alıyorum.Bu arada ben projeyi Keil 4.74.022 ile derliyorum.
En sonda çıkan hata mesajları çok önemli değil.Onları zaten biliyorum çözümü.Amadaha üstlerdeki warning ve errorlar canımı sıkıyor.Çözümü bilmiyorum ve sizin aldığınız sonuçları alamıyorum.
Ekleme: C_RF22.h dosyasını bütün dosyalardan silmiştim.Nasıl oluyor da derleyici ve/veya linker orada olduğunu biliyor?Acaba kütüphane dosyalarını aradığı yerde olduğu için biliyor olabilir mi?
@gerbay dediğinizi yaptım.Başarılı şekilde derleyebildim.Ancak ortalık warning kaynıyor.Bu konuyu nasıl çözebilirim?Bir de c++ da miras konusunu biraz izah edebilir misiniz?
herkese teşekkürler.Başarılı bir şekilde derleyebiliyorum.Sağolun.
Merhaba,
Aşağıdaki .h ve .cpp dosyaları ile ilgili sorun yaşıyorum.
.cpp
// RH_RF22.cpp
//
// Copyright (C) 2011 Mike McCauley
// $Id: RH_RF22.cpp,v 1.25 2015/12/11 01:10:24 mikem Exp $
#include <RH_RF22.h>
// Interrupt vectors for the 2 Arduino interrupt pins
// Each interrupt can be handled by a different instance of RH_RF22, allowing you to have
// 2 RH_RF22s per Arduino
RH_RF22 *RH_RF22::_deviceForInterrupt[RH_RF22_NUM_INTERRUPTS] = {0, 0, 0};
uint8_t RH_RF22::_interruptCount = 0; // Index into _deviceForInterrupt for next device
// These are indexed by the values of ModemConfigChoice
// Canned modem configurations generated with
// http://www.hoperf.com/upload/rf/RH_RF22B%2023B%2031B%2042B%2043B%20Register%20Settings_RevB1-v5.xls
// Stored in flash (program) memory to save SRAM
static const RH_RF22::ModemConfig MODEM_CONFIG_TABLE[] =
{
{ 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x00, 0x08 }, // Unmodulated carrier
{ 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x33, 0x08 }, // FSK, PN9 random modulation, 2, 5
// All the following enable FIFO with reg 71
// 1c, 1f, 20, 21, 22, 23, 24, 25, 2c, 2d, 2e, 58, 69, 6e, 6f, 70, 71, 72
// FSK, No Manchester, Max Rb err <1%, Xtal Tol 20ppm
{ 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x22, 0x08 }, // 2, 5
{ 0x1b, 0x03, 0x41, 0x60, 0x27, 0x52, 0x00, 0x07, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x22, 0x3a }, // 2.4, 36
{ 0x1d, 0x03, 0xa1, 0x20, 0x4e, 0xa5, 0x00, 0x13, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x27, 0x52, 0x2c, 0x22, 0x48 }, // 4.8, 45
{ 0x1e, 0x03, 0xd0, 0x00, 0x9d, 0x49, 0x00, 0x45, 0x40, 0x0a, 0x20, 0x80, 0x60, 0x4e, 0xa5, 0x2c, 0x22, 0x48 }, // 9.6, 45
{ 0x2b, 0x03, 0x34, 0x02, 0x75, 0x25, 0x07, 0xff, 0x40, 0x0a, 0x1b, 0x80, 0x60, 0x9d, 0x49, 0x2c, 0x22, 0x0f }, // 19.2, 9.6
{ 0x02, 0x03, 0x68, 0x01, 0x3a, 0x93, 0x04, 0xd5, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x09, 0xd5, 0x0c, 0x22, 0x1f }, // 38.4, 19.6
{ 0x06, 0x03, 0x45, 0x01, 0xd7, 0xdc, 0x07, 0x6e, 0x40, 0x0a, 0x2d, 0x80, 0x60, 0x0e, 0xbf, 0x0c, 0x22, 0x2e }, // 57.6. 28.8
{ 0x8a, 0x03, 0x60, 0x01, 0x55, 0x55, 0x02, 0xad, 0x40, 0x0a, 0x50, 0x80, 0x60, 0x20, 0x00, 0x0c, 0x22, 0xc8 }, // 125, 125
{ 0x2b, 0x03, 0xa1, 0xe0, 0x10, 0xc7, 0x00, 0x09, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x04, 0x32, 0x2c, 0x22, 0x04 }, // 512 baud, FSK, 2.5 Khz fd for POCSAG compatibility
{ 0x27, 0x03, 0xa1, 0xe0, 0x10, 0xc7, 0x00, 0x06, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x04, 0x32, 0x2c, 0x22, 0x07 }, // 512 baud, FSK, 4.5 Khz fd for POCSAG compatibility
// GFSK, No Manchester, Max Rb err <1%, Xtal Tol 20ppm
// These differ from FSK only in register 71, for the modulation type
{ 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x23, 0x08 }, // 2, 5
{ 0x1b, 0x03, 0x41, 0x60, 0x27, 0x52, 0x00, 0x07, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x23, 0x3a }, // 2.4, 36
{ 0x1d, 0x03, 0xa1, 0x20, 0x4e, 0xa5, 0x00, 0x13, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x27, 0x52, 0x2c, 0x23, 0x48 }, // 4.8, 45
{ 0x1e, 0x03, 0xd0, 0x00, 0x9d, 0x49, 0x00, 0x45, 0x40, 0x0a, 0x20, 0x80, 0x60, 0x4e, 0xa5, 0x2c, 0x23, 0x48 }, // 9.6, 45
{ 0x2b, 0x03, 0x34, 0x02, 0x75, 0x25, 0x07, 0xff, 0x40, 0x0a, 0x1b, 0x80, 0x60, 0x9d, 0x49, 0x2c, 0x23, 0x0f }, // 19.2, 9.6
{ 0x02, 0x03, 0x68, 0x01, 0x3a, 0x93, 0x04, 0xd5, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x09, 0xd5, 0x0c, 0x23, 0x1f }, // 38.4, 19.6
{ 0x06, 0x03, 0x45, 0x01, 0xd7, 0xdc, 0x07, 0x6e, 0x40, 0x0a, 0x2d, 0x80, 0x60, 0x0e, 0xbf, 0x0c, 0x23, 0x2e }, // 57.6. 28.8
{ 0x8a, 0x03, 0x60, 0x01, 0x55, 0x55, 0x02, 0xad, 0x40, 0x0a, 0x50, 0x80, 0x60, 0x20, 0x00, 0x0c, 0x23, 0xc8 }, // 125, 125
// OOK, No Manchester, Max Rb err <1%, Xtal Tol 20ppm
// { 0x51, 0x03, 0x68, 0x00, 0x3a, 0x93, 0x01, 0x3d, 0x2c, 0x11, 0x28, 0x80, 0x60, 0x09, 0xd5, 0x2c, 0x21, 0x08 }, // 1.2, 75
// { 0xc8, 0x03, 0x39, 0x20, 0x68, 0xdc, 0x00, 0x6b, 0x2a, 0x08, 0x2a, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x21, 0x08 }, // 2.4, 335
// { 0xc8, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x29, 0x04, 0x29, 0x80, 0x60, 0x27, 0x52, 0x2c, 0x21, 0x08 }, // 4.8, 335
// { 0xb8, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x28, 0x82, 0x29, 0x80, 0x60, 0x4e, 0xa5, 0x2c, 0x21, 0x08 }, // 9.6, 335
// { 0xa8, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x28, 0x41, 0x29, 0x80, 0x60, 0x9d, 0x49, 0x2c, 0x21, 0x08 }, // 19.2, 335
// { 0x98, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x28, 0x20, 0x29, 0x80, 0x60, 0x09, 0xd5, 0x0c, 0x21, 0x08 }, // 38.4, 335
// { 0x98, 0x03, 0x96, 0x00, 0xda, 0x74, 0x00, 0xdc, 0x28, 0x1f, 0x29, 0x80, 0x60, 0x0a, 0x3d, 0x0c, 0x21, 0x08 }, // 40, 335
};
RH_RF22::RH_RF22 (uint8_t slaveSelectPin, uint8_t interruptPin, RHGenericSPI &spi)
:
RHSPIDriver (slaveSelectPin, spi)
{
_interruptPin = interruptPin;
_idleMode = RH_RF22_XTON; // Default idle state is READY mode
_polynomial = CRC_16_IBM; // Historical
_myInterruptIndex = 0xff; // Not allocated yet
}
void RH_RF22::setIdleMode (uint8_t idleMode)
{
_idleMode = idleMode;
}
bool RH_RF22::init()
{
if (!RHSPIDriver::init())
return false;
// Determine the interrupt number that corresponds to the interruptPin
int interruptNumber = digitalPinToInterrupt (_interruptPin);
if (interruptNumber == NOT_AN_INTERRUPT)
return false;
#ifdef RH_ATTACHINTERRUPT_TAKES_PIN_NUMBER
interruptNumber = _interruptPin;
#endif
GPIO_WriteBit(GPIOC, GPIO_Pin_5, Bit_SET);
Delay(10);
GPIO_WriteBit(GPIOC, GPIO_Pin_5, Bit_RESET);
Delay(200);
// Software reset the device
reset();
// Get the device type and check it
// This also tests whether we are really connected to a device
_deviceType = spiRead (RH_RF22_REG_00_DEVICE_TYPE);
if ( _deviceType != RH_RF22_DEVICE_TYPE_RX_TRX
&& _deviceType != RH_RF22_DEVICE_TYPE_TX)
{
return false;
}
// Add by Adrien van den Bossche <vandenbo@univ-tlse2.fr> for Teensy
// ARM M4 requires the below. else pin interrupt doesn't work properly.
// On all other platforms, its innocuous, belt and braces
pinMode(_interruptPin, INPUT);
// Enable interrupt output on the radio. Interrupt line will now go high until
// an interrupt occurs
spiWrite (RH_RF22_REG_05_INTERRUPT_ENABLE1,
RH_RF22_ENTXFFAEM | RH_RF22_ENRXFFAFULL | RH_RF22_ENPKSENT | RH_RF22_ENPKVALID | RH_RF22_ENCRCERROR | RH_RF22_ENFFERR);
spiWrite (RH_RF22_REG_06_INTERRUPT_ENABLE2, RH_RF22_ENPREAVAL);
// Set up interrupt handler
// Since there are a limited number of interrupt glue functions isr*() available,
// we can only support a limited number of devices simultaneously
// On some devices, notably most Arduinos, the interrupt pin passed in is actually the
// interrupt number. You have to figure out the interruptnumber-to-interruptpin mapping
// yourself based on knowledge of what Arduino board you are running on.
if (_myInterruptIndex == 0xff){
// First run, no interrupt allocated yet
if (_interruptCount <= RH_RF22_NUM_INTERRUPTS)
_myInterruptIndex = _interruptCount++;
else
return false; // Too many devices, not enough interrupt vectors
}
_deviceForInterrupt[_myInterruptIndex] = this;
if (_myInterruptIndex == 0)
attachInterrupt(interruptNumber, isr0, FALLING);
else if (_myInterruptIndex == 1)
attachInterrupt(interruptNumber, isr1, FALLING);
else if (_myInterruptIndex == 2)
attachInterrupt(interruptNumber, isr2, FALLING);
else
return false; // Too many devices, not enough interrupt vectors
setModeIdle();
clearTxBuf();
clearRxBuf();
// Most of these are the POR default
spiWrite (RH_RF22_REG_7D_TX_FIFO_CONTROL2, RH_RF22_TXFFAEM_THRESHOLD);
spiWrite (RH_RF22_REG_7E_RX_FIFO_CONTROL, RH_RF22_RXFFAFULL_THRESHOLD);
spiWrite (RH_RF22_REG_30_DATA_ACCESS_CONTROL,
RH_RF22_ENPACRX | RH_RF22_ENPACTX | RH_RF22_ENCRC | (_polynomial & RH_RF22_CRC));
// Configure the message headers
// Here we set up the standard packet format for use by the RH_RF22 library
// 8 nibbles preamble
// 2 SYNC words 2d, d4
// Header length 4 (to, from, id, flags)
// 1 octet of data length (0 to 255)
// 0 to 255 octets data
// 2 CRC octets as CRC16(IBM), computed on the header, length and data
// On reception the to address is check for validity against RH_RF22_REG_3F_CHECK_HEADER3
// or the broadcast address of 0xff
// If no changes are made after this, the transmitted
// to address will be 0xff, the from address will be 0xff
// and all such messages will be accepted. This permits the out-of the box
// RH_RF22 config to act as an unaddresed, unreliable datagram service
spiWrite (RH_RF22_REG_32_HEADER_CONTROL1, RH_RF22_BCEN_HEADER3 | RH_RF22_HDCH_HEADER3);
spiWrite (RH_RF22_REG_33_HEADER_CONTROL2, RH_RF22_HDLEN_4 | RH_RF22_SYNCLEN_2);
setPreambleLength (8);
uint8_t syncwords[] = { 0x2d, 0xd4 };
setSyncWords (syncwords, sizeof (syncwords));
setPromiscuous (false);
// Set some defaults. An innocuous ISM frequency, and reasonable pull-in
setFrequency (434.0, 0.05);
// setFrequency(900.0);
// Some slow, reliable default speed and modulation
setModemConfig (GFSK_Rb2Fd5);
// Some fast, reliable default speed and modulation
// setModemConfig(GFSK_Rb125Fd125);
setGpioReversed (false);
// Lowish power
// setTxPower (RH_RF22_TXPOW_1DBM);
// Highish power
setTxPower (RH_RF22_TXPOW_20DBM);
return true;
}
// C++ level interrupt handler for this instance
void RH_RF22::handleInterrupt()
{
uint8_t _lastInterruptFlags[2];
// Read the interrupt flags which clears the interrupt
spiBurstRead (RH_RF22_REG_03_INTERRUPT_STATUS1, _lastInterruptFlags, 2);
//#if 0
// // DEVELOPER TESTING ONLY
// // Caution: Serial printing in this interrupt routine can cause mysterious crashes
// Serial.print("interrupt ");
// Serial.print(_lastInterruptFlags[0], HEX);
// Serial.print(" ");
// Serial.println(_lastInterruptFlags[1], HEX);
// if (_lastInterruptFlags[0] == 0 && _lastInterruptFlags[1] == 0)
// Serial.println("FUNNY: no interrupt!");
//#endif
if (_lastInterruptFlags[0] & RH_RF22_IFFERROR)
{
resetFifos(); // Clears the interrupt
if (_mode == RHModeTx)
restartTransmit();
else if (_mode == RHModeRx)
clearRxBuf();
// Serial.println("IFFERROR");
}
// Caution, any delay here may cause a FF underflow or overflow
if (_lastInterruptFlags[0] & RH_RF22_ITXFFAEM)
{
// See if more data has to be loaded into the Tx FIFO
sendNextFragment();
// Serial.println("ITXFFAEM");
}
if (_lastInterruptFlags[0] & RH_RF22_IRXFFAFULL)
{
// Caution, any delay here may cause a FF overflow
// Read some data from the Rx FIFO
readNextFragment();
// Serial.println("IRXFFAFULL");
}
if (_lastInterruptFlags[0] & RH_RF22_IEXT)
{
// This is not enabled by the base code, but users may want to enable it
handleExternalInterrupt();
// Serial.println("IEXT");
}
if (_lastInterruptFlags[1] & RH_RF22_IWUT)
{
// This is not enabled by the base code, but users may want to enable it
handleWakeupTimerInterrupt();
// Serial.println("IWUT");
}
if (_lastInterruptFlags[0] & RH_RF22_IPKSENT)
{
// Serial.println("IPKSENT");
_txGood++;
// Transmission does not automatically clear the tx buffer.
// Could retransmit if we wanted
// RH_RF22 transitions automatically to Idle
_mode = RHModeIdle;
}
if (_lastInterruptFlags[0] & RH_RF22_IPKVALID)
{
uint8_t len = spiRead (RH_RF22_REG_4B_RECEIVED_PACKET_LENGTH);
// Serial.println("IPKVALID");
// May have already read one or more fragments
// Get any remaining unread octets, based on the expected length
// First make sure we dont overflow the buffer in the case of a stupid length
// or partial bad receives
if ( len > RH_RF22_MAX_MESSAGE_LEN
|| len < _bufLen)
{
_rxBad++;
_mode = RHModeIdle;
clearRxBuf();
return; // Hmmm receiver buffer overflow.
}
spiBurstRead (RH_RF22_REG_7F_FIFO_ACCESS, _buf + _bufLen, len - _bufLen);
_rxHeaderTo = spiRead (RH_RF22_REG_47_RECEIVED_HEADER3);
_rxHeaderFrom = spiRead (RH_RF22_REG_48_RECEIVED_HEADER2);
_rxHeaderId = spiRead (RH_RF22_REG_49_RECEIVED_HEADER1);
_rxHeaderFlags = spiRead (RH_RF22_REG_4A_RECEIVED_HEADER0);
_rxGood++;
_bufLen = len;
_mode = RHModeIdle;
_rxBufValid = true;
}
if (_lastInterruptFlags[0] & RH_RF22_ICRCERROR)
{
// Serial.println("ICRCERR");
_rxBad++;
clearRxBuf();
resetRxFifo();
_mode = RHModeIdle;
setModeRx(); // Keep trying
}
if (_lastInterruptFlags[1] & RH_RF22_IPREAVAL)
{
// Serial.println("IPREAVAL");
_lastRssi = (int8_t) (-120 + ((spiRead (RH_RF22_REG_26_RSSI) / 2)));
_lastPreambleTime = millis();
resetRxFifo();
clearRxBuf();
}
}
// These are low level functions that call the interrupt handler for the correct
// instance of RH_RF22.
// 3 interrupts allows us to have 3 different devices
void RH_RF22::isr0()
{
if (_deviceForInterrupt[0])
_deviceForInterrupt[0]->handleInterrupt();
}
void RH_RF22::isr1()
{
if (_deviceForInterrupt[1])
_deviceForInterrupt[1]->handleInterrupt();
}
void RH_RF22::isr2()
{
if (_deviceForInterrupt[2])
_deviceForInterrupt[2]->handleInterrupt();
}
void RH_RF22::reset()
{
spiWrite (RH_RF22_REG_07_OPERATING_MODE1, RH_RF22_SWRES);
// Wait for it to settle
delay (1); // SWReset time is nominally 100usec
}
uint8_t RH_RF22::statusRead()
{
return spiRead (RH_RF22_REG_02_DEVICE_STATUS);
}
uint8_t RH_RF22::adcRead (uint8_t adcsel,
uint8_t adcref ,
uint8_t adcgain,
uint8_t adcoffs)
{
uint8_t configuration = adcsel | adcref | (adcgain & RH_RF22_ADCGAIN);
spiWrite (RH_RF22_REG_0F_ADC_CONFIGURATION, configuration | RH_RF22_ADCSTART);
spiWrite (RH_RF22_REG_10_ADC_SENSOR_AMP_OFFSET, adcoffs);
// Conversion time is nominally 305usec
// Wait for the DONE bit
while (! (spiRead (RH_RF22_REG_0F_ADC_CONFIGURATION) & RH_RF22_ADCDONE))
;
// Return the value
return spiRead (RH_RF22_REG_11_ADC_VALUE);
}
uint8_t RH_RF22::temperatureRead (uint8_t tsrange, uint8_t tvoffs)
{
spiWrite (RH_RF22_REG_12_TEMPERATURE_SENSOR_CALIBRATION, tsrange | RH_RF22_ENTSOFFS);
spiWrite (RH_RF22_REG_13_TEMPERATURE_VALUE_OFFSET, tvoffs);
return adcRead (RH_RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR | RH_RF22_ADCREF_BANDGAP_VOLTAGE);
}
uint16_t RH_RF22::wutRead()
{
uint8_t buf[2];
spiBurstRead (RH_RF22_REG_17_WAKEUP_TIMER_VALUE1, buf, 2);
return ((uint16_t)buf[0] << 8) | buf[1]; // Dont rely on byte order
}
// RFM-22 doc appears to be wrong: WUT for wtm = 10000, r, = 0, d = 0 is about 1 sec
void RH_RF22::setWutPeriod (uint16_t wtm, uint8_t wtr, uint8_t wtd)
{
uint8_t period[3];
period[0] = ((wtr & 0xf) << 2) | (wtd & 0x3);
period[1] = wtm >> 8;
period[2] = wtm & 0xff;
spiBurstWrite (RH_RF22_REG_14_WAKEUP_TIMER_PERIOD1, period, sizeof (period));
}
// Returns true if centre + (fhch * fhs) is within limits
// Caution, different versions of the RH_RF22 support different max freq
// so YMMV
bool RH_RF22::setFrequency (float centre, float afcPullInRange)
{
uint8_t fbsel = RH_RF22_SBSEL;
uint8_t afclimiter;
// if (centre < 240.0 || centre > 960.0) // 930.0 for early silicon
// return false;
// if (centre >= 480.0)
// {
// if (afcPullInRange < 0.0 || afcPullInRange > 0.318750)
// return false;
// centre /= 2;
// fbsel |= RH_RF22_HBSEL;
// afclimiter = afcPullInRange * 1000000.0 / 1250.0;
// }
// else
// {
// if (afcPullInRange < 0.0 || afcPullInRange > 0.159375)
// return false;
afclimiter = afcPullInRange * 1000000.0 / 625.0;
// }
centre /= 10.0;
float integerPart = floor (centre);
float fractionalPart = centre - integerPart;
uint8_t fb = (uint8_t)integerPart - 24; // Range 0 to 23
fbsel |= fb;
uint16_t fc = fractionalPart * 64000;
spiWrite (RH_RF22_REG_73_FREQUENCY_OFFSET1, 0); // REVISIT
spiWrite (RH_RF22_REG_74_FREQUENCY_OFFSET2, 0);
spiWrite (RH_RF22_REG_75_FREQUENCY_BAND_SELECT, fbsel);
spiWrite (RH_RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1, fc >> 8);
spiWrite (RH_RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0, fc & 0xff);
spiWrite (RH_RF22_REG_2A_AFC_LIMITER, afclimiter);
return ! (statusRead() & RH_RF22_FREQERR);
}
// Step size in 10kHz increments
// Returns true if centre + (fhch * fhs) is within limits
bool RH_RF22::setFHStepSize (uint8_t fhs)
{
spiWrite (RH_RF22_REG_7A_FREQUENCY_HOPPING_STEP_SIZE, fhs);
return ! (statusRead() & RH_RF22_FREQERR);
}
// Adds fhch * fhs to centre frequency
// Returns true if centre + (fhch * fhs) is within limits
bool RH_RF22::setFHChannel (uint8_t fhch)
{
spiWrite (RH_RF22_REG_79_FREQUENCY_HOPPING_CHANNEL_SELECT, fhch);
return ! (statusRead() & RH_RF22_FREQERR);
}
uint8_t RH_RF22::rssiRead()
{
return spiRead (RH_RF22_REG_26_RSSI);
}
uint8_t RH_RF22::ezmacStatusRead()
{
return spiRead (RH_RF22_REG_31_EZMAC_STATUS);
}
void RH_RF22::setOpMode (uint8_t mode)
{
spiWrite (RH_RF22_REG_07_OPERATING_MODE1, mode);
}
void RH_RF22::setModeIdle()
{
if (_mode != RHModeIdle)
{
setOpMode (_idleMode);
_mode = RHModeIdle;
}
}
bool RH_RF22::sleep()
{
if (_mode != RHModeSleep)
{
setOpMode (0);
_mode = RHModeSleep;
}
return true;
}
void RH_RF22::setModeRx()
{
if (_mode != RHModeRx)
{
setOpMode (_idleMode | RH_RF22_RXON);
_mode = RHModeRx;
}
}
void RH_RF22::setModeTx()
{
if (_mode != RHModeTx)
{
setOpMode (_idleMode | RH_RF22_TXON);
// Hmmm, if you dont clear the RX FIFO here, then it appears that going
// to transmit mode in the middle of a receive can corrupt the
// RX FIFO
resetRxFifo();
_mode = RHModeTx;
}
}
void RH_RF22::setTxPower (uint8_t power)
{
spiWrite (RH_RF22_REG_6D_TX_POWER, power | RH_RF22_LNA_SW); // On RF23, LNA_SW must be set.
}
// Sets registers from a canned modem configuration structure
void RH_RF22::setModemRegisters (const ModemConfig *config)
{
spiWrite (RH_RF22_REG_1C_IF_FILTER_BANDWIDTH, config->reg_1c);
spiWrite (RH_RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE, config->reg_1f);
spiBurstWrite (RH_RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE, &config->reg_20, 6);
spiBurstWrite (RH_RF22_REG_2C_OOK_COUNTER_VALUE_1, &config->reg_2c, 3);
spiWrite (RH_RF22_REG_58_CHARGE_PUMP_CURRENT_TRIMMING, config->reg_58);
spiWrite (RH_RF22_REG_69_AGC_OVERRIDE1, config->reg_69);
spiBurstWrite (RH_RF22_REG_6E_TX_DATA_RATE1, &config->reg_6e, 5);
}
// Set one of the canned FSK Modem configs
// Returns true if its a valid choice
bool RH_RF22::setModemConfig (ModemConfigChoice index)
{
if (index > (signed int) (sizeof (MODEM_CONFIG_TABLE) / sizeof (ModemConfig)))
return false;
RH_RF22::ModemConfig cfg;
memcpy_P (&cfg, &MODEM_CONFIG_TABLE[index], sizeof (RH_RF22::ModemConfig));
setModemRegisters (&cfg);
return true;
}
// REVISIT: top bit is in Header Control 2 0x33
void RH_RF22::setPreambleLength (uint8_t nibbles)
{
spiWrite (RH_RF22_REG_34_PREAMBLE_LENGTH, nibbles);
}
// Caution doesnt set sync word len in Header Control 2 0x33
void RH_RF22::setSyncWords (const uint8_t *syncWords, uint8_t len)
{
spiBurstWrite (RH_RF22_REG_36_SYNC_WORD3, syncWords, len);
}
void RH_RF22::clearRxBuf()
{
ATOMIC_BLOCK_START;
_bufLen = 0;
_rxBufValid = false;
ATOMIC_BLOCK_END;
}
bool RH_RF22::available()
{
if (!_rxBufValid)
{
if (_mode == RHModeTx)
return false;
setModeRx(); // Make sure we are receiving
}
return _rxBufValid;
}
bool RH_RF22::recv (uint8_t *buf, uint8_t *len)
{
if (!available())
return false;
if (buf && len)
{
ATOMIC_BLOCK_START;
if (*len > _bufLen)
*len = _bufLen;
memcpy (buf, _buf, *len);
ATOMIC_BLOCK_END;
}
clearRxBuf();
// printBuffer("recv:", buf, *len);
return true;
}
void RH_RF22::clearTxBuf()
{
ATOMIC_BLOCK_START;
_bufLen = 0;
_txBufSentIndex = 0;
ATOMIC_BLOCK_END;
}
void RH_RF22::startTransmit()
{
sendNextFragment(); // Actually the first fragment
spiWrite (RH_RF22_REG_3E_PACKET_LENGTH, _bufLen); // Total length that will be sent
setModeTx(); // Start the transmitter, turns off the receiver
}
// Restart the transmission of a packet that had a problem
void RH_RF22::restartTransmit()
{
_mode = RHModeIdle;
_txBufSentIndex = 0;
// Serial.println("Restart");
startTransmit();
}
bool RH_RF22::send (const uint8_t *data, uint8_t len)
{
bool ret = true;
waitPacketSent();
ATOMIC_BLOCK_START;
spiWrite (RH_RF22_REG_3A_TRANSMIT_HEADER3, _txHeaderTo);
spiWrite (RH_RF22_REG_3B_TRANSMIT_HEADER2, _txHeaderFrom);
spiWrite (RH_RF22_REG_3C_TRANSMIT_HEADER1, _txHeaderId);
spiWrite (RH_RF22_REG_3D_TRANSMIT_HEADER0, _txHeaderFlags);
if (!fillTxBuf (data, len))
ret = false;
else
startTransmit();
ATOMIC_BLOCK_END;
// printBuffer("send:", data, len);
return ret;
}
bool RH_RF22::fillTxBuf (const uint8_t *data, uint8_t len)
{
clearTxBuf();
if (!len)
return false;
return appendTxBuf (data, len);
}
bool RH_RF22::appendTxBuf (const uint8_t *data, uint8_t len)
{
if (((uint16_t)_bufLen + len) > RH_RF22_MAX_MESSAGE_LEN)
return false;
ATOMIC_BLOCK_START;
memcpy (_buf + _bufLen, data, len);
_bufLen += len;
ATOMIC_BLOCK_END;
// printBuffer("txbuf:", _buf, _bufLen);
return true;
}
// Assumption: there is currently <= RH_RF22_TXFFAEM_THRESHOLD bytes in the Tx FIFO
void RH_RF22::sendNextFragment()
{
if (_txBufSentIndex < _bufLen)
{
// Some left to send?
uint8_t len = _bufLen - _txBufSentIndex;
// But dont send too much
if (len > (RH_RF22_FIFO_SIZE - RH_RF22_TXFFAEM_THRESHOLD - 1))
len = (RH_RF22_FIFO_SIZE - RH_RF22_TXFFAEM_THRESHOLD - 1);
spiBurstWrite (RH_RF22_REG_7F_FIFO_ACCESS, _buf + _txBufSentIndex, len);
// printBuffer("frag:", _buf + _txBufSentIndex, len);
_txBufSentIndex += len;
}
}
// Assumption: there are at least RH_RF22_RXFFAFULL_THRESHOLD in the RX FIFO
// That means it should only be called after a RXFFAFULL interrupt
void RH_RF22::readNextFragment()
{
if (((uint16_t)_bufLen + RH_RF22_RXFFAFULL_THRESHOLD) > RH_RF22_MAX_MESSAGE_LEN)
return; // Hmmm receiver overflow. Should never occur
// Read the RH_RF22_RXFFAFULL_THRESHOLD octets that should be there
spiBurstRead (RH_RF22_REG_7F_FIFO_ACCESS, _buf + _bufLen, RH_RF22_RXFFAFULL_THRESHOLD);
_bufLen += RH_RF22_RXFFAFULL_THRESHOLD;
}
// Clear the FIFOs
void RH_RF22::resetFifos()
{
spiWrite (RH_RF22_REG_08_OPERATING_MODE2, RH_RF22_FFCLRRX | RH_RF22_FFCLRTX);
spiWrite (RH_RF22_REG_08_OPERATING_MODE2, 0);
}
// Clear the Rx FIFO
void RH_RF22::resetRxFifo()
{
spiWrite (RH_RF22_REG_08_OPERATING_MODE2, RH_RF22_FFCLRRX);
spiWrite (RH_RF22_REG_08_OPERATING_MODE2, 0);
_rxBufValid = false;
}
// CLear the TX FIFO
void RH_RF22::resetTxFifo()
{
spiWrite (RH_RF22_REG_08_OPERATING_MODE2, RH_RF22_FFCLRTX);
spiWrite (RH_RF22_REG_08_OPERATING_MODE2, 0);
}
// Default implmentation does nothing. Override if you wish
void RH_RF22::handleExternalInterrupt()
{
}
// Default implmentation does nothing. Override if you wish
void RH_RF22::handleWakeupTimerInterrupt()
{
}
void RH_RF22::setPromiscuous (bool promiscuous)
{
RHSPIDriver::setPromiscuous (promiscuous);
spiWrite (RH_RF22_REG_43_HEADER_ENABLE3, promiscuous ? 0x00 : 0xff);
}
bool RH_RF22::setCRCPolynomial (CRCPolynomial polynomial)
{
if (polynomial >= CRC_CCITT &&
polynomial <= CRC_Biacheva)
{
_polynomial = polynomial;
return true;
}
else
return false;
}
uint8_t RH_RF22::maxMessageLength()
{
return RH_RF22_MAX_MESSAGE_LEN;
}
void RH_RF22::setThisAddress (uint8_t thisAddress)
{
RHSPIDriver::setThisAddress (thisAddress);
spiWrite (RH_RF22_REG_3F_CHECK_HEADER3, thisAddress);
}
uint32_t RH_RF22::getLastPreambleTime()
{
return _lastPreambleTime;
}
void RH_RF22::setGpioReversed (bool gpioReversed)
{
// Ensure the antenna can be switched automatically according to transmit and receive
// This assumes GPIO0(out) is connected to TX_ANT(in) to enable tx antenna during transmit
// This assumes GPIO1(out) is connected to RX_ANT(in) to enable rx antenna during receive
if (gpioReversed)
{
// Reversed for HAB-RFM22B-BOA HAB-RFM22B-BO, also Si4432 sold by Dorji.com via Tindie.com.
spiWrite (RH_RF22_REG_0B_GPIO_CONFIGURATION0, 0x15) ; // RX state
spiWrite (RH_RF22_REG_0C_GPIO_CONFIGURATION1, 0x12) ; // TX state
}
else
{
spiWrite (RH_RF22_REG_0B_GPIO_CONFIGURATION0, 0x12) ; // TX state
spiWrite (RH_RF22_REG_0C_GPIO_CONFIGURATION1, 0x15) ; // RX state
}
}
.h dosyası
[code]
// RH_RF22.h
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2011 Mike McCauley
// $Id: RH_RF22.h,v 1.28 2015/12/11 01:10:24 mikem Exp $
//
#ifndef RH_RF22_h
#define RH_RF22_h
#include <RHGenericSPI.h>
#include <RHSPIDriver.h>
// This is the maximum number of interrupts the library can support
// Most Arduinos can handle 2, Megas can handle more
#define RH_RF22_NUM_INTERRUPTS 3
// This is the bit in the SPI address that marks it as a write
#define RH_RF22_SPI_WRITE_MASK 0x80
// This is the maximum message length that can be supported by this library. Limited by
// the single message length octet in the header.
// Yes, 255 is correct even though the FIFO size in the RF22 is only
// 64 octets. We use interrupts to refill the Tx FIFO during transmission and to empty the
// Rx FIFO during reception
// Can be pre-defined to a smaller size (to save SRAM) prior to including this header
#ifndef RH_RF22_MAX_MESSAGE_LEN
//#define RH_RF22_MAX_MESSAGE_LEN 255
#define RH_RF22_MAX_MESSAGE_LEN 50
#endif
// Max number of octets the RF22 Rx and Tx FIFOs can hold
#define RH_RF22_FIFO_SIZE 64
// These values we set for FIFO thresholds (4, 55) are actually the same as the POR values
#define RH_RF22_TXFFAEM_THRESHOLD 4
#define RH_RF22_RXFFAFULL_THRESHOLD 55
// Number of registers to be passed to setModemConfig(). Obsolete.
#define RH_RF22_NUM_MODEM_CONFIG_REGS 18
// Register names
#define RH_RF22_REG_00_DEVICE_TYPE 0x00
#define RH_RF22_REG_01_VERSION_CODE 0x01
#define RH_RF22_REG_02_DEVICE_STATUS 0x02
#define RH_RF22_REG_03_INTERRUPT_STATUS1 0x03
#define RH_RF22_REG_04_INTERRUPT_STATUS2 0x04
#define RH_RF22_REG_05_INTERRUPT_ENABLE1 0x05
#define RH_RF22_REG_06_INTERRUPT_ENABLE2 0x06
#define RH_RF22_REG_07_OPERATING_MODE1 0x07
#define RH_RF22_REG_08_OPERATING_MODE2 0x08
#define RH_RF22_REG_09_OSCILLATOR_LOAD_CAPACITANCE 0x09
#define RH_RF22_REG_0A_UC_OUTPUT_CLOCK 0x0a
#define RH_RF22_REG_0B_GPIO_CONFIGURATION0 0x0b
#define RH_RF22_REG_0C_GPIO_CONFIGURATION1 0x0c
#define RH_RF22_REG_0D_GPIO_CONFIGURATION2 0x0d
#define RH_RF22_REG_0E_IO_PORT_CONFIGURATION 0x0e
#define RH_RF22_REG_0F_ADC_CONFIGURATION 0x0f
#define RH_RF22_REG_10_ADC_SENSOR_AMP_OFFSET 0x10
#define RH_RF22_REG_11_ADC_VALUE 0x11
#define RH_RF22_REG_12_TEMPERATURE_SENSOR_CALIBRATION 0x12
#define RH_RF22_REG_13_TEMPERATURE_VALUE_OFFSET 0x13
#define RH_RF22_REG_14_WAKEUP_TIMER_PERIOD1 0x14
#define RH_RF22_REG_15_WAKEUP_TIMER_PERIOD2 0x15
#define RH_RF22_REG_16_WAKEUP_TIMER_PERIOD3 0x16
#define RH_RF22_REG_17_WAKEUP_TIMER_VALUE1 0x17
#define RH_RF22_REG_18_WAKEUP_TIMER_VALUE2 0x18
#define RH_RF22_REG_19_LDC_MODE_DURATION 0x19
#define RH_RF22_REG_1A_LOW_BATTERY_DETECTOR_THRESHOLD 0x1a
#define RH_RF22_REG_1B_BATTERY_VOLTAGE_LEVEL 0x1b
#define RH_RF22_REG_1C_IF_FILTER_BANDWIDTH 0x1c
#define RH_RF22_REG_1D_AFC_LOOP_GEARSHIFT_OVERRIDE 0x1d
#define RH_RF22_REG_1E_AFC_TIMING_CONTROL 0x1e
#define RH_RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE 0x1f
#define RH_RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE 0x20
#define RH_RF22_REG_21_CLOCK_RECOVERY_OFFSET2 0x21
#define RH_RF22_REG_22_CLOCK_RECOVERY_OFFSET1 0x22
#define RH_RF22_REG_23_CLOCK_RECOVERY_OFFSET0 0x23
#define RH_RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1 0x24
#define RH_RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0 0x25
#define RH_RF22_REG_26_RSSI 0x26
#define RH_RF22_REG_27_RSSI_THRESHOLD 0x27
#define RH_RF22_REG_28_ANTENNA_DIVERSITY1 0x28
#define RH_RF22_REG_29_ANTENNA_DIVERSITY2 0x29
#define RH_RF22_REG_2A_AFC_LIMITER 0x2a
#define RH_RF22_REG_2B_AFC_CORRECTION_READ 0x2b
#define RH_RF22_REG_2C_OOK_COUNTER_VALUE_1 0x2c
#define RH_RF22_REG_2D_OOK_COUNTER_VALUE_2 0x2d
#define RH_RF22_REG_2E_SLICER_PEAK_HOLD 0x2e
#define RH_RF22_REG_30_DATA_ACCESS_CONTROL 0x30
#define RH_RF22_REG_31_EZMAC_STATUS 0x31
#define RH_RF22_REG_32_HEADER_CONTROL1 0x32
#define RH_RF22_REG_33_HEADER_CONTROL2 0x33
#define RH_RF22_REG_34_PREAMBLE_LENGTH 0x34
#define RH_RF22_REG_35_PREAMBLE_DETECTION_CONTROL1 0x35
#define RH_RF22_REG_36_SYNC_WORD3 0x36
#define RH_RF22_REG_37_SYNC_WORD2 0x37
#define RH_RF22_REG_38_SYNC_WORD1 0x38
#define RH_RF22_REG_39_SYNC_WORD0 0x39
#define RH_RF22_REG_3A_TRANSMIT_HEADER3 0x3a
#define RH_RF22_REG_3B_TRANSMIT_HEADER2 0x3b
#define RH_RF22_REG_3C_TRANSMIT_HEADER1 0x3c
#define RH_RF22_REG_3D_TRANSMIT_HEADER0 0x3d
#define RH_RF22_REG_3E_PACKET_LENGTH 0x3e
#define RH_RF22_REG_3F_CHECK_HEADER3 0x3f
#define RH_RF22_REG_40_CHECK_HEADER2 0x40
#define RH_RF22_REG_41_CHECK_HEADER1 0x41
#define RH_RF22_REG_42_CHECK_HEADER0 0x42
#define RH_RF22_REG_43_HEADER_ENABLE3 0x43
#define RH_RF22_REG_44_HEADER_ENABLE2 0x44
#define RH_RF22_REG_45_HEADER_ENABLE1 0x45
#define RH_RF22_REG_46_HEADER_ENABLE0 0x46
#define RH_RF22_REG_47_RECEIVED_HEADER3 0x47
#define RH_RF22_REG_48_RECEIVED_HEADER2 0x48
#define RH_RF22_REG_49_RECEIVED_HEADER1 0x49
#define RH_RF22_REG_4A_RECEIVED_HEADER0 0x4a
#define RH_RF22_REG_4B_RECEIVED_PACKET_LENGTH 0x4b
#define RH_RF22_REG_50_ANALOG_TEST_BUS_SELECT 0x50
#define RH_RF22_REG_51_DIGITAL_TEST_BUS_SELECT 0x51
#define RH_RF22_REG_52_TX_RAMP_CONTROL 0x52
#define RH_RF22_REG_53_PLL_TUNE_TIME 0x53
#define RH_RF22_REG_55_CALIBRATION_CONTROL 0x55
#define RH_RF22_REG_56_MODEM_TEST 0x56
#define RH_RF22_REG_57_CHARGE_PUMP_TEST 0x57
#define RH_RF22_REG_58_CHARGE_PUMP_CURRENT_TRIMMING 0x58
#define RH_RF22_REG_59_DIVIDER_CURRENT_TRIMMING 0x59
#define RH_RF22_REG_5A_VCO_CURRENT_TRIMMING 0x5a
#define RH_RF22_REG_5B_VCO_CALIBRATION 0x5b
#define RH_RF22_REG_5C_SYNTHESIZER_TEST 0x5c
#define RH_RF22_REG_5D_BLOCK_ENABLE_OVERRIDE1 0x5d
#define RH_RF22_REG_5E_BLOCK_ENABLE_OVERRIDE2 0x5e
#define RH_RF22_REG_5F_BLOCK_ENABLE_OVERRIDE3 0x5f
#define RH_RF22_REG_60_CHANNEL_FILTER_COEFFICIENT_ADDRESS 0x60
#define RH_RF22_REG_61_CHANNEL_FILTER_COEFFICIENT_VALUE 0x61
#define RH_RF22_REG_62_CRYSTAL_OSCILLATOR_POR_CONTROL 0x62
#define RH_RF22_REG_63_RC_OSCILLATOR_COARSE_CALIBRATION 0x63
#define RH_RF22_REG_64_RC_OSCILLATOR_FINE_CALIBRATION 0x64
#define RH_RF22_REG_65_LDO_CONTROL_OVERRIDE 0x65
#define RH_RF22_REG_66_LDO_LEVEL_SETTINGS 0x66
#define RH_RF22_REG_67_DELTA_SIGMA_ADC_TUNING1 0x67
#define RH_RF22_REG_68_DELTA_SIGMA_ADC_TUNING2 0x68
#define RH_RF22_REG_69_AGC_OVERRIDE1 0x69
#define RH_RF22_REG_6A_AGC_OVERRIDE2 0x6a
#define RH_RF22_REG_6B_GFSK_FIR_FILTER_COEFFICIENT_ADDRESS 0x6b
#define RH_RF22_REG_6C_GFSK_FIR_FILTER_COEFFICIENT_VALUE 0x6c
#define RH_RF22_REG_6D_TX_POWER 0x6d
#define RH_RF22_REG_6E_TX_DATA_RATE1 0x6e
#define RH_RF22_REG_6F_TX_DATA_RATE0 0x6f
#define RH_RF22_REG_70_MODULATION_CONTROL1 0x70
#define RH_RF22_REG_71_MODULATION_CONTROL2 0x71
#define RH_RF22_REG_72_FREQUENCY_DEVIATION 0x72
#define RH_RF22_REG_73_FREQUENCY_OFFSET1 0x73
#define RH_RF22_REG_74_FREQUENCY_OFFSET2 0x74
#define RH_RF22_REG_75_FREQUENCY_BAND_SELECT 0x75
#define RH_RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1 0x76
#define RH_RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0 0x77
#define RH_RF22_REG_79_FREQUENCY_HOPPING_CHANNEL_SELECT 0x79
#define RH_RF22_REG_7A_FREQUENCY_HOPPING_STEP_SIZE 0x7a
#define RH_RF22_REG_7C_TX_FIFO_CONTROL1 0x7c
#define RH_RF22_REG_7D_TX_FIFO_CONTROL2 0x7d
#define RH_RF22_REG_7E_RX_FIFO_CONTROL 0x7e
#define RH_RF22_REG_7F_FIFO_ACCESS 0x7f
// These register masks etc are named wherever possible
// corresponding to the bit and field names in the RF-22 Manual
// RH_RF22_REG_00_DEVICE_TYPE 0x00
#define RH_RF22_DEVICE_TYPE_RX_TRX 0x08
#define RH_RF22_DEVICE_TYPE_TX 0x07
// RH_RF22_REG_02_DEVICE_STATUS 0x02
#define RH_RF22_FFOVL 0x80
#define RH_RF22_FFUNFL 0x40
#define RH_RF22_RXFFEM 0x20
#define RH_RF22_HEADERR 0x10
#define RH_RF22_FREQERR 0x08
#define RH_RF22_LOCKDET 0x04
#define RH_RF22_CPS 0x03
#define RH_RF22_CPS_IDLE 0x00
#define RH_RF22_CPS_RX 0x01
#define RH_RF22_CPS_TX 0x10
// RH_RF22_REG_03_INTERRUPT_STATUS1 0x03
#define RH_RF22_IFFERROR 0x80
#define RH_RF22_ITXFFAFULL 0x40
#define RH_RF22_ITXFFAEM 0x20
#define RH_RF22_IRXFFAFULL 0x10
#define RH_RF22_IEXT 0x08
#define RH_RF22_IPKSENT 0x04
#define RH_RF22_IPKVALID 0x02
#define RH_RF22_ICRCERROR 0x01
// RH_RF22_REG_04_INTERRUPT_STATUS2 0x04
#define RH_RF22_ISWDET 0x80
#define RH_RF22_IPREAVAL 0x40
#define RH_RF22_IPREAINVAL 0x20
#define RH_RF22_IRSSI 0x10
#define RH_RF22_IWUT 0x08
#define RH_RF22_ILBD 0x04
#define RH_RF22_ICHIPRDY 0x02
#define RH_RF22_IPOR 0x01
// RH_RF22_REG_05_INTERRUPT_ENABLE1 0x05
#define RH_RF22_ENFFERR 0x80
#define RH_RF22_ENTXFFAFULL 0x40
#define RH_RF22_ENTXFFAEM 0x20
#define RH_RF22_ENRXFFAFULL 0x10
#define RH_RF22_ENEXT 0x08
#define RH_RF22_ENPKSENT 0x04
#define RH_RF22_ENPKVALID 0x02
#define RH_RF22_ENCRCERROR 0x01
// RH_RF22_REG_06_INTERRUPT_ENABLE2 0x06
#define RH_RF22_ENSWDET 0x80
#define RH_RF22_ENPREAVAL 0x40
#define RH_RF22_ENPREAINVAL 0x20
#define RH_RF22_ENRSSI 0x10
#define RH_RF22_ENWUT 0x08
#define RH_RF22_ENLBDI 0x04
#define RH_RF22_ENCHIPRDY 0x02
#define RH_RF22_ENPOR 0x01
// RH_RF22_REG_07_OPERATING_MODE 0x07
#define RH_RF22_SWRES 0x80
#define RH_RF22_ENLBD 0x40
#define RH_RF22_ENWT 0x20
#define RH_RF22_X32KSEL 0x10
#define RH_RF22_TXON 0x08
#define RH_RF22_RXON 0x04
#define RH_RF22_PLLON 0x02
#define RH_RF22_XTON 0x01
// RH_RF22_REG_08_OPERATING_MODE2 0x08
#define RH_RF22_ANTDIV 0xc0
#define RH_RF22_RXMPK 0x10
#define RH_RF22_AUTOTX 0x08
#define RH_RF22_ENLDM 0x04
#define RH_RF22_FFCLRRX 0x02
#define RH_RF22_FFCLRTX 0x01
// RH_RF22_REG_0F_ADC_CONFIGURATION 0x0f
#define RH_RF22_ADCSTART 0x80
#define RH_RF22_ADCDONE 0x80
#define RH_RF22_ADCSEL 0x70
#define RH_RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR 0x00
#define RH_RF22_ADCSEL_GPIO0_SINGLE_ENDED 0x10
#define RH_RF22_ADCSEL_GPIO1_SINGLE_ENDED 0x20
#define RH_RF22_ADCSEL_GPIO2_SINGLE_ENDED 0x30
#define RH_RF22_ADCSEL_GPIO0_GPIO1_DIFFERENTIAL 0x40
#define RH_RF22_ADCSEL_GPIO1_GPIO2_DIFFERENTIAL 0x50
#define RH_RF22_ADCSEL_GPIO0_GPIO2_DIFFERENTIAL 0x60
#define RH_RF22_ADCSEL_GND 0x70
#define RH_RF22_ADCREF 0x0c
#define RH_RF22_ADCREF_BANDGAP_VOLTAGE 0x00
#define RH_RF22_ADCREF_VDD_ON_3 0x08
#define RH_RF22_ADCREF_VDD_ON_2 0x0c
#define RH_RF22_ADCGAIN 0x03
// RH_RF22_REG_10_ADC_SENSOR_AMP_OFFSET 0x10
#define RH_RF22_ADCOFFS 0x0f
// RH_RF22_REG_12_TEMPERATURE_SENSOR_CALIBRATION 0x12
#define RH_RF22_TSRANGE 0xc0
#define RH_RF22_TSRANGE_M64_64C 0x00
#define RH_RF22_TSRANGE_M64_192C 0x40
#define RH_RF22_TSRANGE_0_128C 0x80
#define RH_RF22_TSRANGE_M40_216F 0xc0
#define RH_RF22_ENTSOFFS 0x20
#define RH_RF22_ENTSTRIM 0x10
#define RH_RF22_TSTRIM 0x0f
// RH_RF22_REG_14_WAKEUP_TIMER_PERIOD1 0x14
#define RH_RF22_WTR 0x3c
#define RH_RF22_WTD 0x03
// RH_RF22_REG_1D_AFC_LOOP_GEARSHIFT_OVERRIDE 0x1d
#define RH_RF22_AFBCD 0x80
#define RH_RF22_ENAFC 0x40
#define RH_RF22_AFCGEARH 0x38
#define RH_RF22_AFCGEARL 0x07
// RH_RF22_REG_1E_AFC_TIMING_CONTROL 0x1e
#define RH_RF22_SWAIT_TIMER 0xc0
#define RH_RF22_SHWAIT 0x38
#define RH_RF22_ANWAIT 0x07
// RH_RF22_REG_30_DATA_ACCESS_CONTROL 0x30
#define RH_RF22_ENPACRX 0x80
#define RH_RF22_MSBFRST 0x00
#define RH_RF22_LSBFRST 0x40
#define RH_RF22_CRCHDRS 0x00
#define RH_RF22_CRCDONLY 0x20
#define RH_RF22_SKIP2PH 0x10
#define RH_RF22_ENPACTX 0x08
#define RH_RF22_ENCRC 0x04
#define RH_RF22_CRC 0x03
#define RH_RF22_CRC_CCITT 0x00
#define RH_RF22_CRC_CRC_16_IBM 0x01
#define RH_RF22_CRC_IEC_16 0x02
#define RH_RF22_CRC_BIACHEVA 0x03
// RH_RF22_REG_32_HEADER_CONTROL1 0x32
#define RH_RF22_BCEN 0xf0
#define RH_RF22_BCEN_NONE 0x00
#define RH_RF22_BCEN_HEADER0 0x10
#define RH_RF22_BCEN_HEADER1 0x20
#define RH_RF22_BCEN_HEADER2 0x40
#define RH_RF22_BCEN_HEADER3 0x80
#define RH_RF22_HDCH 0x0f
#define RH_RF22_HDCH_NONE 0x00
#define RH_RF22_HDCH_HEADER0 0x01
#define RH_RF22_HDCH_HEADER1 0x02
#define RH_RF22_HDCH_HEADER2 0x04
#define RH_RF22_HDCH_HEADER3 0x08
// RH_RF22_REG_33_HEADER_CONTROL2 0x33
#define RH_RF22_HDLEN 0x70
#define RH_RF22_HDLEN_0 0x00
#define RH_RF22_HDLEN_1 0x10
#define RH_RF22_HDLEN_2 0x20
#define RH_RF22_HDLEN_3 0x30
#define RH_RF22_HDLEN_4 0x40
#define RH_RF22_VARPKLEN 0x00
#define RH_RF22_FIXPKLEN 0x08
#define RH_RF22_SYNCLEN 0x06
#define RH_RF22_SYNCLEN_1 0x00
#define RH_RF22_SYNCLEN_2 0x02
#define RH_RF22_SYNCLEN_3
Alıntı yapılan: gerbay - 20 Haziran 2016, 13:43:37
hocam keşke ne sorun yaşadığınızı da belirtseydiniz
Halbuki ne kadar uzun metin yazmıştım.Neden böyle oluyor bende bu forum?
Header dosyasının sonuna
[/ccode] koymama rağmen siliniyor?
mesaj birleştirme:: 20 Haziran 2016, 14:02:40
Hocam konu özetle şu;
.cpp içinde tanımlanmış ve aynı zamanda .h içinde static olarak da tanımlanmış bir değişken var. _interruptCount Bu değişken benim için önemli. Bu lib Rfm22 rf modülün. 3 adet modülü tek mcu ile kontrol edebileceğini iddia ediyor. Benim yapmak istediğim iki tanesini bir mcu ile kontrol etmek.
Bahsettiğim değişkenin durumunun ne olacağını merak ediyorum.Ben bu class ile iki adet nesne oluştursam ve her ikisinde de init fonksiyonunu çağırsam, bahsettiğim değişken her yeni tür tanımlamam için yeniden mi oluşturulacak, yoksa 1 tane mi? 1 tane olunca türden bağımsız mı düşünmek gerekiyor?
RH_RF22 rf1, rf2; diye tanımladıktan sonra;
rf1.init(); çağrımından sonra _interruptCount değişkeni 1 olacak, rf2.init(); çağrımından sonra 0 mı olur, 2 mi?Neden ve nasıl?Gerçi ben pc üstünde c++ derleyici ile test yaptım ve her init fonksiyon çağırımında bir artıyor.
Bu işin izahı nedir?
Alıntı yapılan: gerbay - 20 Haziran 2016, 14:08:58
hocam o değişken derlenme sırasında oluşturuluyor ve yeri belli zaten. kullanılırken de nereden kullanılırsa kullanılsın o bir tane kopya kullanılıyor.
Ama header içinde protected olarak tanımlanmış.Nasıl olur da classın bir üyesi olmaz ki?