-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar_rf.cpp
37 lines (33 loc) · 933 Bytes
/
car_rf.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "rc522.h"
#include "car_rf.h"
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <wiringPiSPI.h>
#include <unistd.h>
CarRF::CarRF(CarState *state) {
this->state = state;
}
CarRF::~CarRF() {
thread_on=0;
rf_thread->join();
std::cout<<"CLOSING RF!"<<std::endl;
}
void CarRF::Start() {
wiringPiSPISetup(0, 10000000);
InitRc522();
rf_thread = std::unique_ptr<std::thread>(new std::thread(&CarRF::SyncronizeState, this));
}
void CarRF::SyncronizeState() {
while(thread_on){
if (state->get_car_state() != CarState::WAITING) {
unsigned char status = PcdRequest(PICC_REQIDL, buffer_tag);
if(status == TAG_OK){
PcdAnticoll(0, buffer_uid);
unsigned int uid = (buffer_uid[0]<<24)|(buffer_uid[1]<<16)|(buffer_uid[2]<<8)|buffer_uid[3];
//std::cout << std::hex << "UIDul este " << uid << std::endl;
state->update_rf_tag(uid);
}
}
}
}