forked from skumlos/ihcserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIHCInterface.h
50 lines (45 loc) · 1.57 KB
/
IHCInterface.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* This is the main interface to the IHC controller
* It works by waiting for the DATA_READY/GIVE command (0x30)
* addressed to the PC (ID_PC/0x1C). When such a packet is received
* it checks if any requests are in, if not it either updates inputs,
* or outputs, depending on what was updated upon last DATA_READY
* "event".
*
* December 2012, January 2013, Martin Hejnfelt (martin@hejnfelt.com)
*/
#ifndef IHCINTERFACE_H
#define IHCINTERFACE_H
#include <string>
#include <vector>
#include <list>
#include <map>
#include <pthread.h>
#include "utils/Thread.h"
#include "IHCDefs.h"
#include "IHCRS485Packet.h"
#include "IHCOutput.h"
#include "IHCInput.h"
class UART;
class IHCInterface : public Thread {
public:
IHCInterface(std::string rs485port);
~IHCInterface();
void thread();
IHCInput* getInput(int moduleNumber, int inputNumber);
IHCOutput* getOutput(int moduleNumber, int outputNumber);
std::list<IHCInput*> getAllInputs();
std::list<IHCOutput*> getAllOutputs();
void changeOutput(IHCOutput* output, bool newState);
void changeInput(IHCInput* input, bool shouldActivate);
private:
IHCRS485Packet getPacket(UART& uart, int ID = IHCDefs::ID_PC, int expectedPacketLength = 0, bool useTimeout = true) throw (bool);
void updateInputStates(const std::vector<unsigned char>& newStates);
void updateOutputStates(const std::vector<unsigned char>& newStates);
UART* m_port;
std::map<int,std::vector<IHCOutput*> > m_outputs;
std::map<int,std::vector<IHCInput*> > m_inputs;
pthread_mutex_t m_packetQueueMutex;
std::list<IHCRS485Packet> m_packetQueue;
};
#endif /* IHCINTERFACE_H */