5 #include "../hubolib.h"
24 void ReceiveToFile (
unsigned short pin,
string sFilename,
unsigned long long breakTime);
25 void TransmitFromFile (
unsigned short pin,
string sFilename,
int repeatCount);
28 int main(
int argc,
char *argv[])
30 if (argc!=3 || !(argv[1][0]==
'r'||argv[1][0]==
'w'))
34 "receive <r|w> <filename>\n"
35 "r: read radio signals into filename\n"
36 "w: write content of filename to transmitter\n"
41 unsigned char command = argv[1][0];
42 string sFilename = argv[2];
46 printf (
"GPIO not properly initialized. Are you running the program as sudoer?\n");
51 unsigned short transmit_pin = 17;
52 unsigned short receive_pin = 22;
67 void ReceiveToFile(
unsigned short pin,
string sFilename,
unsigned long long breakTime)
73 unsigned long long now, last_time, delay;
75 unsigned short last_value, value;
76 last_value = value = 0;
84 if (value != last_value)
87 delay = now - last_time;
89 if (delay >= breakTime)
94 printf (
"Writing done...\n");
102 sprintf (buffer,
"%ld %d\n", (
long) delay, value);
115 std::list<unsigned long long> m_DelayList;
116 std::list<int> m_ValueList;
119 FILE* pFile = fopen (sFilename.c_str(),
"r");
122 printf (
"Error opening file!\n");
126 while (fgets(buffer, 128, pFile))
128 unsigned long long delay;
130 if (sscanf(buffer,
"%llu %d", &delay, &value) != 2)
131 printf (
"Error in format reading\n");
134 m_DelayList.push_back(delay);
135 m_ValueList.push_back(value);
141 if (m_DelayList.empty() || m_ValueList.empty())
143 printf (
"Files seem to be empty.\n");
151 for (
int i=0; i<repeatCount; i++)
153 std::list<unsigned long long>::iterator iterator_delay = m_DelayList.begin();
154 std::list<int>::iterator iterator_value = m_ValueList.begin();
156 while (iterator_delay != m_DelayList.end() && iterator_value != m_ValueList.end())
159 WritePin (pin, (
unsigned char) *iterator_value);
void ReceiveToFile(unsigned short pin, string sFilename, unsigned long long breakTime)
unsigned short ReadPin(unsigned short pin)
Reads the value of an (input) pin.
void Delay_MicroSeconds(unsigned long delay_micros)
delays the execution of the calling thread for the given number of micro seconds. ...
int main(int argc, char *argv[])
bool IsGPIOInitialized()
Returns the status of the initialisation of the GPIO part of the library.
void Add(std::string sLine)
void FunctionSelectPin(unsigned char pin, FunctionSelectType mode)
Use FunctionSelect() to configure the mode of a BCM2835 pin.
void TransmitFromFile(unsigned short pin, string sFilename, int repeatCount)
void WritePin(unsigned char pin, unsigned char value)
Sets or clears a pin configured to be an output.
unsigned long long GetTime_MicroSeconds()
Returns the number of micro seconds.
void SetPullUpDown(unsigned char pin, PullUpDownType pud)
Enables or disables the BCM2835 internal pull -up or -down resistors for a pin configured as an input...