SEPIA
Software documentation for the APEX SEPIA receivers
mcunit.h
Go to the documentation of this file.
1 /* Copyright 2017 Michael Olberg <michael.olberg@chalmers.se> */
2 #ifndef MCUNIT_H
3 #define MCUNIT_H
4 
5 #include <QObject>
6 #include <QByteArray>
7 
8 #ifdef FAKE
9 #include <QHash>
10 #endif
11 
12 #include <asm/types.h>
13 
14 typedef __u32 DWORD;
15 
16 #define WORD unsigned short
17 #define BYTE unsigned char
18 #define LPSTR char*
19 
20 #include "PCANBasic.h"
21 
22 #include "../constants.h"
23 
34 class MCunit : public QObject {
35  Q_OBJECT
36 
37  public:
38  static const DWORD MCUNIT;
39  static const DWORD CONTROL;
40  static const DWORD MONITOR;
41  static const DWORD SPECIAL;
42 
43  static const DWORD MODULE5;
44  static const DWORD MODULE7;
45  static const DWORD MODULE9;
46 
50  static MCunit *instance()
51  {
52  if (m_instance == 0) m_instance = new MCunit();
53  return m_instance;
54  }
55 
56  bool startup();
57  bool enable(bool on);
58  void testCommunication();
59  void switchOff();
60  float getRealValue(DWORD id);
61  void setRealValue(DWORD id, float v);
62  void setWord(DWORD id, unsigned short w);
63  unsigned short getWord(DWORD id);
64  bool getFlag(DWORD id);
65  void setFlag(DWORD id, bool flag);
66 
67  public slots:
68  void disable() { enable(false); }
69  void addChannel(Sepia::Channel channel);
70  void removeChannel(Sepia::Channel channel);
71 
72  signals:
73  void error(DWORD addr);
74  void connected(bool flag);
75  void enabled(bool flag);
76 
77  private slots:
78  void canbusError(DWORD canStatus);
79 
80  private:
81  static MCunit *m_instance;
82  MCunit();
83 
84  DWORD m_id;
85 
86  const static float invalid;
87 
88  DWORD powerDistributionModule(Sepia::Channel channel);
89  void canDebug(bool read) const;
90  void send(quint32 id, const int size, QByteArray ba = QByteArray());
91  QByteArray receive(quint32 id, const int size);
92  bool m_perr;
93 
94  bool m_enabled;
95  bool m_connected;
96  QList<Sepia::Channel> m_bands;
98 #ifdef FAKE
99  QHash<DWORD, float> mcValues;
100  QHash<DWORD, unsigned short> mcWords;
101  QHash<DWORD, bool> mcFlags;
102 #endif
103 
104  TPCANMsg canMessage;
105  TPCANStatus canStatus;
106  TPCANParameter canParameter;
107 };
108 
109 #endif // MCUNIT_H
A class to handle all communication with the M&C unit via CANbus.
Definition: mcunit.h:34
Channel
An enumeration for the three SEPIA channels (cartridges).
Definition: constants.h:66
static MCunit * instance()
Get a pointer to a class MCunit instance.
Definition: mcunit.h:50