Mr IPC
Hauptseite
Datenstrukturen
Dateien
Auflistung der Dateien
Datei-Elemente
Alle
Datenstrukturen
Dateien
Funktionen
Variablen
Aufzählungen
Aufzählungswerte
Makrodefinitionen
Seiten
mr_ipc.h
gehe zur Dokumentation dieser Datei
1
#ifndef MR_IPC_H
2
#define MR_IPC_H
3
25
#include <unistd.h>
26
#include <sys/socket.h>
27
#include <cs2.h>
28
#include <mr_cs2ms2.h>
29
32
/*
33
* @brief Konstanten für den Returncode der Funktion MrIpcSend()
34
*/
35
#define MR_IPC_RCV_ERROR -1
36
#define MR_IPC_RCV_CLOSED 0
37
#define MR_IPC_RCV_OK 1
38
40
#define MR_IPC_SOCKET_ALL -1
41
42
typedef
enum
{
Off
,
On
}
SwitchType
;
43
typedef
enum
{
Forward
,
Backward
}
DirectionType
;
44
typedef
enum
{
Left
,
Right
}
PositionType
;
45
49
typedef
enum
{
50
MrIpcCmdNull
,
/* 0 empty command */
51
MrIpcCmdRun
,
/* 1 system start/stop command */
52
MrIpcCmdTrackProto
,
/* 2 system Gleis Protokoll */
53
MrIpcCmdLocomotiveSpeed
,
/* 3 command to set speed of a locomotive */
54
MrIpcCmdLocomotiveDirection
,
/* 4 command to set direction of a locomotive */
55
MrIpcCmdLocomotiveFunction
,
/* 5 command to set function of a locomotive */
56
MrIpcCmdAccSwitch
,
/* 6 command to switch accesoires */
57
MrIpcCmdRequestMember
,
/* 7 command to request CAN member */
58
MrIpcCmdMember
,
/* 8 command to announce member */
59
MrIpcCmdRequestLocName
,
/* 9 command to request loc name from MS2 */
60
MrIpcCmdRequestLocInfo
,
/* 10 command to request loc info from MS2 */
61
MrIpcCmdRequestFile
,
/* 11 command to request a .cs2 file from CS2 */
62
MrIpcCmdCfgHeader
,
/* 12 command with header of cfg data */
63
MrIpcCmdCfgZHeader
,
/* 13 command with header of z-packed cfg data */
64
MrIpcCmdCfgData
,
/* 14 command with data of cfg data */
65
MrIpcCmdCanBootldrGeb
,
/* 15 command can bootloader gebunden */
66
MrIpcCmdStatusRequest
,
/* 16 command request status */
67
MrIpcCmdStatusSize
,
/* 17 command with number of packets in status */
68
MrIpcCmdStatusData
,
/* 18 command with status data */
69
MrIpcCmdStatusResponse
,
/* 19 command response status */
70
MrIpcCmdRequestMesswert
,
/* 20 command request system status */
71
MrIpcCmdSetConfig
,
/* 21 command set config system status */
72
MrIpcCmdConfigResponse
,
/* 22 command response set config system status */
73
MrIpcCmdMesswertResponse
,
/* 23 command response request system status */
74
MrIpcCmdRequestLokListe
,
/* 24 command to request lokliste from MS2 */
75
MrIpcCmdIntern
,
/* 25 internal command */
76
}
MrIpcCommandValue
;
77
81
typedef
struct
{
82
unsigned
long
Lp1
;
83
unsigned
int
Ip1
;
84
unsigned
int
Ip2
;
85
}
IntDatas
;
86
90
typedef
struct
{
91
unsigned
char
Dlc
;
92
unsigned
char
Data[2 * MR_CS2_NUM_CAN_BYTES + 1];
93
}
RawDatas
;
94
98
typedef
struct
{
99
MrIpcCommandValue
Command
;
100
int
SenderSocket
;
101
int
ReceiverSocket
;
102
unsigned
int
CanResponse
;
103
unsigned
int
CanHash
;
104
unsigned
int
CanCommand
;
105
unsigned
int
CanPrio
;
106
union
{
107
IntDatas
Ints
;
108
RawDatas
Raws
;
109
} Parms;
110
}
MrIpcCmdType
;
111
115
#define MrIpcSetCommand(Dat,c) (Dat)->Command=htons(c)
116
#define MrIpcSetSenderSocket(Dat,v) (Dat)->SenderSocket=v
117
#define MrIpcSetReceiverSocket(Dat,v) (Dat)->ReceiverSocket=v
118
#define MrIpcSetCanResponse(Dat,v) (Dat)->CanResponse=htons(v)
119
#define MrIpcSetCanHash(Dat,v) (Dat)->CanHash=htons(v)
120
#define MrIpcSetCanCommand(Dat,v) (Dat)->CanCommand=htons(v)
121
#define MrIpcSetCanPrio(Dat,v) (Dat)->CanPrio=htons(v)
122
#define MrIpcSetIntLp1(Dat,v) (Dat)->Parms.Ints.Lp1=(unsigned long)htonl(v)
123
#define MrIpcSetIntIp1(Dat,v) (Dat)->Parms.Ints.Ip1=htons(v)
124
#define MrIpcSetIntIp2(Dat,v) (Dat)->Parms.Ints.Ip2=htons(v)
125
#define MrIpcSetRawDlc(Dat,v) (Dat)->Parms.Raws.Dlc=v
126
#define MrIpcSetRawDataI(Dat,i,v) (Dat)->Parms.Raws.Data[i]=v
127
131
#define MrIpcGetCommand(Dat) ntohs((Dat)->Command)
132
#define MrIpcGetSenderSocket(Dat) (Dat)->SenderSocket
133
#define MrIpcGetReceiverSocket(Dat) (Dat)->ReceiverSocket
134
#define MrIpcGetCanResponse(Dat) ntohs((Dat)->CanResponse)
135
#define MrIpcGetCanHash(Dat) ntohs((Dat)->CanHash)
136
#define MrIpcGetCanCommand(Dat) ntohs((Dat)->CanCommand)
137
#define MrIpcGetCanPrio(Dat) ntohs((Dat)->CanPrio)
138
#define MrIpcGetIntLp1(Dat) (unsigned long)ntohl((Dat)->Parms.Ints.Lp1)
139
#define MrIpcGetIntIp1(Dat) ntohs((Dat)->Parms.Ints.Ip1)
140
#define MrIpcGetIntIp2(Dat) ntohs((Dat)->Parms.Ints.Ip2)
141
#define MrIpcGetRawDlc(Dat) (Dat)->Parms.Raws.Dlc
142
#define MrIpcGetRawData(Dat) (Dat)->Parms.Raws.Data
143
#define MrIpcGetRawDataI(Dat,i) (Dat)->Parms.Raws.Data[i]
144
145
#define MrIpcInternalPollMs2 0x0001
146
150
#define MrIpcClose(socket) close(socket)
151
#define MrIpcCalcHash(Data,Uid) MrIpcSetCanHash(Data,Cs2CalcHash(Uid))
152
153
MrIpcCmdType
*
MrIpcCreate
(
void
);
154
void
MrIpcDestroy
(
MrIpcCmdType
*Data);
155
void
MrIpcInit
(
MrIpcCmdType
*Data);
156
void
MrIpcExit
(
MrIpcCmdType
*Data);
157
int
MrIpcConnect
(
char
*Address,
int
Port);
158
int
MrIpcConnectIf
(
char
*Interface,
int
Port);
159
int
MrIpcStartServer
(
char
*Adress,
int
Port);
160
int
MrIpcStartServerIf
(
char
*Interface,
int
Port);
161
int
MrIpcAccept
(
int
ServerSock);
162
int
MrIpcSend
(
int
socket,
MrIpcCmdType
*Data);
163
int
MrIpcRecv
(
int
socket,
MrIpcCmdType
*Data);
164
165
void
MrIpcEncodeFromCan
(
MrIpcCmdType
*Data, MrCs2CanDataType *CanMsg);
166
void
MrIpcDecodeToCan
(
MrIpcCmdType
*Data, MrCs2CanDataType *CanMsg);
167
168
void
MrIpcCmdSetNull
(
MrIpcCmdType
*Data,
unsigned
char
Dlc,
169
unsigned
char
*CanData);
170
void
MrIpcCmdSetRun
(
MrIpcCmdType
*Data,
SwitchType
Switch);
171
void
MrIpcCmdSetTrackProto
(
MrIpcCmdType
*Data,
unsigned
Protokoll);
172
void
MrIpcCmdSetLocomotiveSpeed
(
MrIpcCmdType
*Data,
unsigned
long
Addr,
173
unsigned
Speed);
174
void
MrIpcCmdSetLocomotiveDir
(
MrIpcCmdType
*Data,
unsigned
long
Addr,
DirectionType
Direction);
175
void
MrIpcCmdSetLocomotiveFkt
(
MrIpcCmdType
*Data,
unsigned
long
Addr,
176
unsigned
Function,
SwitchType
Switch);
177
void
MrIpcCmdSetAccPos
(
MrIpcCmdType
*Data,
unsigned
long
Addr,
178
PositionType
Position,
unsigned
int
Current);
179
void
MrIpcCmdSetRequest
(
MrIpcCmdType
*Data);
180
void
MrIpcCmdSetRequestMember
(
MrIpcCmdType
*Data);
181
void
MrIpcCmdSetMember
(
MrIpcCmdType
*Data,
unsigned
long
Addr,
182
unsigned
Version,
unsigned
Type);
183
void
MrIpcCmdSetReqestLocname
(
MrIpcCmdType
*Data,
unsigned
StartIdx,
184
unsigned
EndIdx);
185
void
MrIpcCmdSetReqestLocinfo
(
MrIpcCmdType
*Data,
char
*Locname);
186
void
MrIpcCmdSetReqestLoclist
(
MrIpcCmdType
*Data);
187
void
MrIpcCmdSetQuery
(
MrIpcCmdType
*Data,
unsigned
char
Dlc,
char
*Name);
188
void
MrIpcCmdSetCfgHeader
(
MrIpcCmdType
*Data,
unsigned
long
Length,
189
unsigned
Crc);
190
void
MrIpcCmdSetCfgZHeader
(
MrIpcCmdType
*Data,
unsigned
long
Length,
191
unsigned
Crc);
192
void
MrIpcCmdSetCfgData
(
MrIpcCmdType
*Data,
char
*Buf);
193
void
MrIpcCmdSetCanBootldr
(
MrIpcCmdType
*Data,
unsigned
Dlc,
194
unsigned
char
*CanData);
195
void
MrIpcCmdSetStatusRequest
(
MrIpcCmdType
*Data,
unsigned
long
Addr,
196
unsigned
int
Index);
197
void
MrIpcCmdSetStatusPos
(
MrIpcCmdType
*Data,
unsigned
long
Addr,
198
unsigned
int
Index,
unsigned
int
NumPackets);
199
void
MrIpcCmdSetStatusData
(
MrIpcCmdType
*Data,
unsigned
char
*Buf);
200
void
MrIpcCmdSetStatusResponse
(
MrIpcCmdType
*Data,
unsigned
long
Addr,
201
unsigned
int
Index);
202
void
MrIpcCmdSetMesswertRequest
(
MrIpcCmdType
*Data,
unsigned
long
Addr,
203
unsigned
int
Kanalnummer);
204
void
MrIpcCmdSetSetConfig
(
MrIpcCmdType
*Data,
unsigned
long
Addr,
205
unsigned
int
Kanalnummer,
unsigned
int
Value);
206
void
MrIpcCmdSetConfigResponse
(
MrIpcCmdType
*Data,
unsigned
long
Addr,
207
unsigned
int
Kanalnummer,
unsigned
int
Response);
208
209
void
MrIpcCmdGetNull
(
MrIpcCmdType
*Data,
unsigned
char
*Dlc,
char
*CanData);
210
void
MrIpcCmdGetRun
(
MrIpcCmdType
*Data,
SwitchType
*Switch);
211
void
MrIpcCmdGetTrackProto
(
MrIpcCmdType
*Data,
unsigned
*Protokoll);
212
void
MrIpcCmdGetLocomotiveDir
(
MrIpcCmdType
*Data,
unsigned
long
*Addr,
213
DirectionType
*Direction);
214
void
MrIpcCmdGetLocomotiveSpeed
(
MrIpcCmdType
*Data,
unsigned
long
*Addr,
215
unsigned
*Speed);
216
void
MrIpcCmdGetLocomotiveFkt
(
MrIpcCmdType
*Data,
unsigned
long
*Addr,
217
unsigned
*Function,
SwitchType
*Switch);
218
void
MrIpcCmdGetAccPos
(
MrIpcCmdType
*Data,
unsigned
long
*Addr,
219
PositionType
*Position,
unsigned
int
*Current);
220
#define MrIpcCmdGetRequestMember(Data)
221
void
MrIpcCmdGetMember
(
MrIpcCmdType
*Data,
unsigned
long
*Addr,
222
unsigned
*Version,
unsigned
*Type);
223
void
MrIpcCmdGetReqestLocname
(
MrIpcCmdType
*Data,
unsigned
*StartIdx,
224
unsigned
*EndIdx);
225
void
MrIpcCmdGetReqestLocinfo
(
MrIpcCmdType
*Data,
char
*Locinfo);
226
#define MrIpcCmdGetReqestLoclist(Data)
227
void
MrIpcCmdGetQuery
(
MrIpcCmdType
*Data,
char
*Name);
228
void
MrIpcCmdGetCfgHeader
(
MrIpcCmdType
*Data,
unsigned
long
*Length,
229
unsigned
*Crc);
230
void
MrIpcCmdGetCfgZHeader
(
MrIpcCmdType
*Data,
unsigned
long
*Length,
231
unsigned
*Crc);
232
void
MrIpcCmdGetCfgData
(
MrIpcCmdType
*Data,
char
*Buf);
233
void
MrIpcCmdGetCanBootldr
(
MrIpcCmdType
*Data,
unsigned
*Dlc,
234
char
*CanData);
235
void
MrIpcCmdGetStatusRequest
(
MrIpcCmdType
*Data,
unsigned
long
*Addr,
236
unsigned
int
*Index);
237
void
MrIpcCmdGetStatusPos
(
MrIpcCmdType
*Data,
unsigned
long
*Addr,
238
unsigned
int
*Index,
unsigned
int
*NumPackets);
239
void
MrIpcCmdGetStatusData
(
MrIpcCmdType
*Data,
unsigned
char
*Buf);
240
#define MrIpcCmdGetStatusResponse(Data, Addr, Index) MrIpcCmdGetStatusRequest(Data, Addr, Index)
241
void
MrIpcCmdGetMesswertRequest
(
MrIpcCmdType
*Data,
unsigned
long
*Addr,
242
unsigned
int
*Kanalnummer);
243
void
MrIpcCmdGetSetConfig
(
MrIpcCmdType
*Data,
unsigned
long
*Addr,
244
unsigned
int
*Kanalnummer,
unsigned
int
*Value);
245
void
MrIpcCmdGetConfigResponse
(
MrIpcCmdType
*Data,
unsigned
long
*Addr,
246
unsigned
int
*Kanalnummer,
unsigned
int
*Response);
247
#define MrIpcCmdGetMesswertResponse(Data, Addr, Kanalnummer, Value) MrIpcCmdGetConfigResponse(Data, Addr, Kanalnummer, Value)
248
void
MrIpcCmdSetMesswertResponse
(
MrIpcCmdType
*Data,
unsigned
long
Addr,
249
unsigned
int
Kanalnummer,
unsigned
int
Response);
250
251
#endif
Erzeugt am Fre Apr 10 2020 23:37:23 für Mr IPC von
1.8.1.2