Commit c8aa2affae4a854d42a4852e2fe0c059ffbc719c

modified payload to use a generic dS485Container

removed all references to raw data packets
core/ds485-socket/dS485Const.h
(3 / 73)
  
1717
1818#define dSMAPI_CALL_TIMEOUT_SEKUNDEN 5
1919
20
21#if defined(__GNUC__)
22#pragma pack(1)
23#endif
24
2520#include "core/ds485-socket/ds485c.h"
2621
2722extern dsidType dSIDBroadcast;
2823
29/*
30 * dS485 Frame for transporting through socket
31 */
32typedef struct _dS485TransportFrame {
33 unsigned char start;
3424
35 unsigned char typeflag : 1;
36 unsigned char broadcastflag : 1;
37 unsigned char destination : 6;
38
39 unsigned char msgid : 2;
40 unsigned char source : 6;
41
42 unsigned char length : 4;
43 unsigned char command : 4;
44
45 unsigned char data[15]; /* 15 data bytes max on the wire */
46 unsigned char _pad0; /* some systems require word alignment ... */
47
48 unsigned short crc16;
49} dS485TransportFrame;
50
51/*
52 * dS485 Container for internal
53 */
54/*
55typedef struct _dS485Container {
56 unsigned char broadcastflag;
57 dsidType destination;
58
59 unsigned char msgid;
60
61 unsigned char length;
62 unsigned char command;
63 union _data {
64 struct _parameter{
65 unsigned char msgID;
66 unsigned short parameter1;
67 unsigned short parameter2;
68 unsigned short parameter3;
69 unsigned short parameter4;
70 unsigned short parameter5;
71 unsigned short parameter6;
72 unsigned short parameter7;
73 } parameter;
74 unsigned char plaindata[15];
75 } data;
76} dS485Container;
77*/
78/*
79 * dS485 Datagramm
80 */
81typedef struct _dS485Packet {
82 dS485TransportFrame frame;
83 time_t tstamp;
84 unsigned short length;
85 unsigned short flags;
86 unsigned short valid;
87 struct _dS485Packet* next;
88} dS485Packet;
89
90
91#if defined(__GNUC__)
92#pragma pack()
93#endif
94
9525typedef enum {
96 notWaiting,
97 Waiting,
98 Received
26 notWaiting,
27 Waiting,
28 Received
9929} answerState;
10030
10131typedef struct {
core/ds485-socket/ds485-socket.cpp
(12 / 12)
  
104104 {
105105 int messageID=pFrage.data[0];
106106
107 dsid_t dSMID=getdsid_tFromdsidType(pFrage.destination);
107 dsid_t dSMID=getdsid_tFromdsidType(pFrage.deviceId);
108108
109109 int zoneID,devID,groupID,sceneID;
110110 int FID;
230230 }
231231 case MAPI_GET_POWER_CONSUMPTION:
232232 {
233 if (pFrage.containerType==DSTELEGRAM_RESPONSE)
233 if (pFrage.containerType==DS485_CONTAINER_RESPONSE)
234234 {
235235 ModelEvent* pEvent = new ModelEvent(ModelEvent::etPowerConsumption);
236236 pEvent->setMeter(dSMID);
241241 }
242242 case MAPI_GET_POWER_METERVALUE:
243243 {
244 if (pFrage.containerType==DSTELEGRAM_RESPONSE)
244 if (pFrage.containerType==DS485_CONTAINER_RESPONSE)
245245 {
246246 ModelEvent* pEvent = new ModelEvent(ModelEvent::etEnergyMeterValue);
247247 pEvent->setMeter(dSMID);
252252 }
253253 case MAPI_GET_DSID:
254254 {
255 if (pFrage.containerType==DSTELEGRAM_RESPONSE)
255 if (pFrage.containerType==DS485_CONTAINER_RESPONSE)
256256 {
257257 ModelEvent* pEvent = new ModelEvent(ModelEvent::etDS485DeviceDiscovered);
258258 pEvent->setMeter(dSMID);
267267 {
268268 int messageID=pFrage.data[0];
269269 int zoneID,devID,groupID,sceneID,sensorIndex,value;
270 dsid_t dSMID=getdsid_tFromdsidType(pFrage.destination);
270 dsid_t dSMID=getdsid_tFromdsidType(pFrage.deviceId);
271271
272272 switch (messageID){
273273 case DSMAPI_DEVICE_ADDED:
377377 }
378378 case DSMAPI_DSM_CIRCUIT_METERING_VALUE:
379379 {
380 if (pFrage.containerType==DSTELEGRAM_RESPONSE)
380 if (pFrage.containerType==DS485_CONTAINER_RESPONSE)
381381 {
382382 ModelEvent* pEvent = new ModelEvent(ModelEvent::etEnergyMeterValue);
383383
394394 }
395395 case DSMAPI_DSM_DSID:
396396 {
397 if (pFrage.containerType==DSTELEGRAM_RESPONSE)
397 if (pFrage.containerType==DS485_CONTAINER_RESPONSE)
398398 {
399399 ModelEvent* pEvent = new ModelEvent(ModelEvent::etDS485DeviceDiscovered);
400400 pEvent->setMeter(dSMID);
427427 formatContainer(oLogMSG,&pFrage);
428428 log("Callback:\n" + std::string(oLogMSG), lsInfo);
429429*/
430 if (ds485_get_dsid_state(pFrage.destination)==1)
430 if (ds485_get_dsid_state(pFrage.deviceId)==1)
431431 mycallBackOld(pFrage);
432432 else
433433 mycallBackNew(pFrage);
755755 dSMAPI_getEnergyMeterValue(dSIDBroadcast);
756756
757757 dS485Container pFrame;
758 pFrame.containerType=DSTELEGRAM_REQUEST;
759 pFrame.destination=dSIDBroadcast;
758 pFrame.containerType=DS485_CONTAINER_REQUEST;
759 pFrame.deviceId=dSIDBroadcast;
760760 pFrame.data[0]=DSMAPI_DSM_CIRCUIT_METERING_VALUE;
761761 setModifier(pFrame,DSMAPI_MODIFIER_GET);
762762 setParameterCount(pFrame,0);
769769 dSMAPI_getPowerConsumption(dSIDBroadcast);
770770
771771 dS485Container pFrame;
772 pFrame.containerType=DSTELEGRAM_REQUEST;
773 pFrame.destination=dSIDBroadcast;
772 pFrame.containerType=DS485_CONTAINER_REQUEST;
773 pFrame.deviceId=dSIDBroadcast;
774774 pFrame.data[0]=DSMAPI_DSM_CIRCUIT_METERING_VALUE;
775775 setModifier(pFrame,DSMAPI_MODIFIER_GET);
776776 setParameterCount(pFrame,0);
core/ds485-socket/ds485Connection.c
(198 / 316)
  
2828#include "ds485d-interface.h"
2929#include "ds485RawFunction-old.h"
3030#include "ds485Connection.h"
31
32
3133/******************************************************************************
3234 *
3335 */
3436
37typedef enum {
38 API_VERSION_1 = 1,
39 API_VERSION_2 = 2,
40} ApiVersion_t;
41
3542typedef struct
3643{
37 dsidType oDSID;
38 int state;
39}oDSIDItem;
44 dsidType oDSID;
45 ApiVersion_t state;
46} oDSIDItem;
4047
4148typedef struct
4249{
43 BusState_t sessionState;
44 oDSIDItem dSIDExisting[64];
45 char* dProtocol;
46 char* dHostname;
47 char* dPort;
48 int sockfd;
50 BusState_t sessionState;
51 oDSIDItem dSIDExisting[64];
52 char* dProtocol;
53 char* dHostname;
54 char* dPort;
55 int sockfd;
4956} connectionItem_t;
5057
5158connectionItem_t connectionItem[MAX_THREADS];
5259client_callback_state_t stateCallback;
5360client_callback_container_t responseCallback;
5461
55extern char *optarg;
56extern int optind;
62dsidType dSIDBroadcast = { 0xff, };
63dsidType dSIDNull = { 0, };
5764
58dsidType dSIDBroadcast;
59
6065typedef struct _dS485RXCommand {
61 uint8_t command;
62 uint8_t length;
63 dS485TransportFrame pFrame;
64} dS485RXCommand;
66 uint8_t command;
67 uint8_t length;
68 dS485Container apiData;
69} __attribute__ ((packed)) dS485RXCommand;
6570
6671
67static int verbose = 0;
72static int verbose = 1;
6873static pthread_t rxThread;
6974
7075/* server connection spec */
8181pthread_mutex_t answer_mutex;
8282pthread_cond_t answer_threshold_cv;
8383
84
85//void formatFrame(char *pTarget,dS485TransportFrame *pFrame);
86void formatContainer(char *pTarget, dS485Container *pMessage);
87void formatConnectionItem(char *p, connectionItem_t *pItem, unsigned char deviceAddress);
88
89
8490/************************ SOCKET CONNECTION *******************************/
8591
8692int connectsock(const char *host, const char *service, const char *protocol)
130130 if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
131131 close(s);
132132 return -5;
133 }
133 }
134134
135135 int opts = fcntl(s, F_GETFL);
136136 if (opts > 0) {
159159 int status = write(fd, data, dlen);
160160
161161 if (status == dlen ) {
162 //printf("wrote %d bytes to socket[%d].\n", status, fd);
162163 return status;
163164 }
164165 else if (status > -1) {
165 printf("short write disconnecting client [%d]\n", fd);
166 printf("short write disconnecting socket[%d]\n", fd);
166167 close(fd);
167168 return 0;
168 } else if (errno == EAGAIN || errno == EINTR) {
169 printf("client[%d] has not written data.\n", fd);
169 } else if (errno == EAGAIN || errno == EINTR) {
170 printf("socket[%d] write failed, no data sent.\n", fd);
170171 return 0;
171172 }
172173 else if (errno == EBADF) {
173 printf("client[%d] has vanished.\n", fd);
174 printf("socket[%d] has vanished.\n", fd);
174175 }
175176 else if (errno == EWOULDBLOCK /*&& (timestamp() - cl->active) > NOREAD_TIMEOUT*/) {
176 printf("client[%d] timed out.\n", fd);
177 printf("socket[%d] timed out.\n", fd);
177178 }
178179 else {
179 printf("client[%d] write: %s\n", fd, strerror(errno));
180 printf("socket[%d] write: %s\n", fd, strerror(errno));
180181 }
181 close(fd);
182 close(fd);
182183 return status;
183184}
184185
189189static uint32_t rxTotal[MAX_THREADS];
190190static uint64_t rxBytes[MAX_THREADS];
191191
192static int sysServiceDispatch(uint8_t* data, int dlen,int iSocketIndex)
192static int sysServiceDispatch(uint8_t* data, int dlen, int iSocketIndex)
193193{
194194 char oLGMSG[1000];
195195 dS485Container pContainer;
196196 dS485dCommand* cmd;
197197 uint8_t len;
198198
199 int iWork=1;
200
201199 cmd = (dS485dCommand *) data;
202200 len = cmd->length;
203201
213213
214214 case DS845D_CMD_RX_PACKET:
215215 {
216 dS485Packet* pPacket = (dS485Packet *) cmd->data;
216 dS485Container* pData = (dS485Container *) cmd->data;
217 uint8_t deviceAddress = pData->deviceAddress & 0x3f;
217218
218219 rxTotal[iSocketIndex] ++;
219 rxBytes[iSocketIndex] += pPacket->length;
220 rxBytes[iSocketIndex] += pData->length;
220221
222 if (1 || compareDSID(pData->deviceId, dSIDNull)) {
223 pData->deviceId = connectionItem[iSocketIndex].dSIDExisting[deviceAddress].oDSID;
224 }
225
226#if 0
227 if (verbose) {
228 printf("Empfanges Packet von socket %d, device %d:\n", iSocketIndex, deviceAddress);
229 formatContainer(oLGMSG, pData);
230 printf("%s",oLGMSG);
231 }
232#endif
233
221234 pthread_mutex_lock(&answer_mutex);
222235
223 /* Dump to ... to console */
224 //if (verbose) {
225 printf("Empfanges Packet von socket %d:\n",iSocketIndex);
226 formatFrame(oLGMSG,&(pPacket->frame));
227 printf("%s",oLGMSG);
228 //}
229236
230 if ((pPacket->frame.broadcastflag)||(pPacket->frame.data[0]==0x25)){
237#ifdef FEATURE_PACKET_FORWARDING_TO_ALL_SOCKETS
238 if ((pData->containerFlags & DS485_FLAG_BROADCAST) ||
239 (pData->data[0]==0x25))
240 {
231241 if ((pPacket->frame.command==0x09) || (pPacket->frame.command==0x0f))
232242 {
233243 if (verbose)
263263 sockwrite(connectionItem[jSocketIndex].sockfd, (uint8_t *) &cmdCall, sizeof(dS485RXCommand));
264264 }
265265 }
266 if (pPacket->frame.data[0]==0x90)
267 { // switching Version
268 // 5 = 2
269 // 6 >53
266#endif
267
268 if (pData->data[0]==0x90)
269 { // switching Version, old Api < 2.60, new Api >= 2.60
270 // Byte 5 Version Major
271 // Byte 6 Version Minor
270272 connectionItem[iSocketIndex].sessionState=DSBUS_ACTIVE;
271 int iVersionsID=(pPacket->frame.data[5])*100 + pPacket->frame.data[6];
272 if (iVersionsID<253) {
273 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].state=1;
273 int iVersionsID=(pData->data[5])*100 + pData->data[6];
274 if (iVersionsID < 260) {
275 connectionItem[iSocketIndex].dSIDExisting[deviceAddress].state = API_VERSION_1;
274276 } else {
275 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].state=2;
277 connectionItem[iSocketIndex].dSIDExisting[deviceAddress].state = API_VERSION_2;
276278 }
279 formatConnectionItem(oLGMSG, &connectionItem[iSocketIndex], deviceAddress);
280 printf("Received Type Response: %s", oLGMSG);
277281 }
278 if (pPacket->frame.data[0]==0x91)
282 if (pData->data[0]==0x91)
279283 {
280284 // update internal addressing
281 if (connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].state==1)
285 if (connectionItem[iSocketIndex].dSIDExisting[deviceAddress].state == API_VERSION_1)
282286 {
283287 // old API
284288 connectionItem[iSocketIndex].sessionState=DSBUS_ACTIVE;
285 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[0]=pPacket->frame.data[1]&0xff;
286 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[1]=pPacket->frame.data[2]&0xff;
287 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[2]=pPacket->frame.data[3]&0xff;
288 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[3]=pPacket->frame.data[4]&0xff;
289 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[4]=pPacket->frame.data[5]&0xff;
290 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[5]=pPacket->frame.data[6]&0xff;
291 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[6]=pPacket->frame.data[7]&0xff;
292 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[7]=pPacket->frame.data[8]&0xff;
293 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[8]=pPacket->frame.data[9]&0xff;
294 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[9]=pPacket->frame.data[10]&0xff;
295 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[10]=pPacket->frame.data[11]&0xff;
296 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[11]=pPacket->frame.data[12]&0xff;
289 memcpy(&connectionItem[iSocketIndex].dSIDExisting[deviceAddress].oDSID.value[0], &pData->data[1], 12);
297290 }
298 if (connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].state==2) {
291 else if (connectionItem[iSocketIndex].dSIDExisting[deviceAddress].state == API_VERSION_2)
292 {
299293 // new API
300 if (pPacket->frame.data[3]!=0x35)
294 if (pData->data[3]!=0x35)
301295 {
302296 printf ("-----------------------\nWrong Answer\n--------------------------\n");
303297 pthread_cond_signal(&answer_threshold_cv);
304298 pthread_mutex_unlock(&answer_mutex);
305299 return len;
306300 }
307
308301 connectionItem[iSocketIndex].sessionState=DSBUS_ACTIVE;
309 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[0]=pPacket->frame.data[3]&0xff;
310 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[1]=pPacket->frame.data[4]&0xff;
311 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[2]=pPacket->frame.data[5]&0xff;
312 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[3]=pPacket->frame.data[6]&0xff;
313 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[4]=pPacket->frame.data[7]&0xff;
314 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[5]=pPacket->frame.data[8]&0xff;
315 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[6]=pPacket->frame.data[9]&0xff;
316 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[7]=pPacket->frame.data[10]&0xff;
317 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[8]=pPacket->frame.data[11]&0xff;
318 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[9]=pPacket->frame.data[12]&0xff;
319 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[10]=pPacket->frame.data[13]&0xff;
320 connectionItem[iSocketIndex].dSIDExisting[(pPacket->frame.destination)].oDSID.value[11]=pPacket->frame.data[14]&0xff;
302 memcpy(&connectionItem[iSocketIndex].dSIDExisting[deviceAddress].oDSID.value[0], &pData->data[3], 12);
321303 }
304 formatConnectionItem(oLGMSG, &connectionItem[iSocketIndex], deviceAddress);
305 printf("Received DSID Response: %s", oLGMSG);
322306 }
323 switch(pPacket->frame.command) {
324 case 0x09:
325 pContainer.containerType=DSTELEGRAM_REQUEST;
326 break;
327 case 0x0a:
328 pContainer.containerType=DSTELEGRAM_RESPONSE;
329 break;
330 case 0x0e:
331 pContainer.containerType=DSTELEGRAM_EVENT;
332 break;
333 }
334 pContainer.length=pPacket->frame.length;
335 int i;
336 for (i=0;i<15;i++)
337 pContainer.data[i]=pPacket->frame.data[i];
338307
339 pContainer.destination=connectionItem[iSocketIndex].dSIDExisting[pPacket->frame.destination].oDSID;
308 pContainer = *pData;
309 pContainer.deviceId = connectionItem[iSocketIndex].dSIDExisting[deviceAddress].oDSID;
340310
341311 if (oAnswer.Status==Waiting)
342 if (compareDSID(pContainer.destination,oAnswer.request.destination))
343 if (pContainer.containerType==oAnswer.request.containerType)
344 if (pContainer.data[0]==oAnswer.request.data[0])
312 if (compareDSID(pContainer.deviceId, oAnswer.request.deviceId))
313 if (pContainer.containerType == oAnswer.request.containerType)
314 if (pContainer.data[0] == oAnswer.request.data[0])
345315 {
346 oAnswer.answer=pContainer;
347 oAnswer.Status=Received;
316 oAnswer.answer = pContainer;
317 oAnswer.Status = Received;
348318 pthread_cond_signal(&answer_threshold_cv);
349319 }
350320
351321
352322 /* Calling Callbacks */
353323 if (responseCallback) {
354 responseCallback(iSocketIndex,pContainer);
324 responseCallback(iSocketIndex, pContainer);
355325 }
356326
357327
360360 int rval;
361361 int rxLen = 0;
362362
363#define RXBUFLEN 300
363#define RXBUFLEN 1024
364364 uint8_t* rxBuffer = (uint8_t *) malloc(RXBUFLEN);
365365 uint8_t* p;
366366/*
370370 iSocketIndex=iIndex;
371371 }
372372*/
373 printf("Receive thread started.\n");
374373 while (mainActive) {
375374
376375 for (iSocketIndex=0;iSocketIndex<MAX_THREADS;iSocketIndex++)
399399 }
400400 else {
401401 if (FD_ISSET(connectionItem[iSocketIndex].sockfd, &rfds)) {
402 if (verbose) printf("Readausfuehren: %d ",connectionItem[iSocketIndex].sockfd);
403402 rval = read(connectionItem[iSocketIndex].sockfd, rxBuffer + rxLen, RXBUFLEN - rxLen);
404 if (verbose) printf("gelesen rxLen %d, rval %d \n",rxLen,rval);
405403 if (rval < 0) {
406404 if (verbose) printf("client socket read error %d [%d]\n", rval, connectionItem[iSocketIndex].sockfd);
407405 continue;
407407 else if (rval == 0) {
408408 if (verbose) printf("client socket closed by server [%d]\n", connectionItem[iSocketIndex].sockfd);
409409 shutdown(connectionItem[iSocketIndex].sockfd, 2);
410
411 // TODO: handle reconnect ...
412
410413 break;
411414 }
412415
413416 rxLen += rval;
414 if (verbose) printf("sockfd %d, rx %d bytes\n", connectionItem[iSocketIndex].sockfd, rval);
417 //if (verbose) printf("sockfd %d, rx %d bytes, total %d\n", connectionItem[iSocketIndex].sockfd, rval, rxLen);
415418
416419 p = rxBuffer;
417420 while (rxLen >= 2) {
450450 }
451451
452452 free(rxBuffer);
453 printf("Receive thread terminated.\n");
454
455 mainActive = 0;
456453 return NULL;
457454}
458455
459
460/*
461void sendMessageToSocket (dS485Container pFrame)
462{
463 dS485RXCommand cmdCall;
464 char oLGMSG[1000];
465 int iSocketIndex;
466 int i,j;
467
468 cmdCall.command = DS845D_CMD_TX_PACKET;
469 cmdCall.length = sizeof(dS485RXCommand);
470 cmdCall.pFrame.typeflag=0;
471 cmdCall.pFrame.command=pFrame.command;
472 cmdCall.pFrame.broadcastflag=0;
473 for (i=0;i<15;i++)
474 cmdCall.pFrame.data[i]=pFrame.data.plaindata[i];
475 cmdCall.pFrame.length=(pFrame.length*2)+1;
476
477 if (pFrame.broadcastflag)
478 {
479 for (iSocketIndex=0;iSocketIndex<MAX_THREADS;iSocketIndex++)
480 if (connectionItem[iSocketIndex].sockfd) {
481 cmdCall.pFrame.broadcastflag=1;
482 cmdCall.pFrame.destination=0;
483
484 if (verbose) {
485 printf("Sende Packet to socket %d(%x):\n",iSocketIndex, connectionItem[iSocketIndex].sockfd);
486 formatFrame(oLGMSG,&cmdCall.pFrame);
487 printf("%s",oLGMSG);
488 }
489 sockwrite(connectionItem[iSocketIndex].sockfd, (uint8_t *) &cmdCall, sizeof(dS485RXCommand));
490 }
491 return;
492 }
493
494 int iSearchIndex=-1;
495
496 for (j=0;j<MAX_THREADS;j++)
497 if (connectionItem[j].sessionState==DSBUS_ACTIVE)
498 for (i=0;i<64;i++)
499 if (connectionItem[j].dSIDExisting[i].state)
500 if (compareDSID(connectionItem[j].dSIDExisting[i].oDSID,pFrame.destination)) {
501 iSearchIndex=i;
502 iSocketIndex=j;
503 }
504
505 if (iSearchIndex!=-1) {
506 cmdCall.pFrame.destination=iSearchIndex;
507
508 if (verbose) {
509 printf("Sende Packet to socket %d(%x):\n",iSocketIndex, connectionItem[iSocketIndex].sockfd);
510 formatFrame(oLGMSG,&cmdCall.pFrame);
511 printf("%s",oLGMSG);
512 }
513 sockwrite(sockfd[iSocketIndex], (uint8_t *) &cmdCall, sizeof(dS485RXCommand));
514 }
515}
516*/
517456void setVerbose(int iVerbose)
518457{
519458 verbose=iVerbose;
503503 printf("use Socket #%d\n",iNewThread);
504504
505505 oAnswer.Status=notWaiting;
506 verbose=iVerbose;
507506
508
509507 connectionItem[iNewThread].dProtocol = strdup(pProtokol);
510508 connectionItem[iNewThread].dHostname = strdup(pHostname);
511509 connectionItem[iNewThread].dPort = strdup(pPort);
510 connectionItem[iNewThread].sessionState = DSBUS_ISOLATED;
512511
513 connectionItem[iNewThread].sessionState=DSBUS_ISOLATED;
514
515512 /*
516513 * Connect to server socket
517514 */
518515 connectionItem[iNewThread].sockfd = connectsock(connectionItem[iNewThread].dHostname, connectionItem[iNewThread].dPort, connectionItem[iNewThread].dProtocol);
519516 if (connectionItem[iNewThread].sockfd < 0) {
520517 connectionItem[iNewThread].sockfd=0;
521 connectionItem[iNewThread].sessionState=DSBUS_INACTIVE;
522
518 connectionItem[iNewThread].sessionState = DSBUS_INACTIVE;
523519 return &mainActive;
524 } else
525 if (verbose) {
520 } else if (verbose) {
526521 printf("get SocketNumber #%d(%x) \n",iNewThread,connectionItem[iNewThread].sockfd);
527522 }
528523
529524 rxTotal[iNewThread]=0;
530525 rxBytes[iNewThread]=0;
526
531527 /*
532528 * Set connection options
533529 */
534530 dS485dCommand cmd;
535
536 cmd.command = DS845D_CMD_RAWMODE;
537 cmd.length = 3;
538 cmd.data[0] = 1;
539 rval = sockwrite(connectionItem[iNewThread].sockfd, (uint8_t *) &cmd, sizeof(dS485dCommand));
540
541531 cmd.command = DS845D_CMD_PACKETFILTER;
542532 cmd.length = 3;
543533 cmd.data[0] = DS485_FILTER_STANDARD;
544534 rval = sockwrite(connectionItem[iNewThread].sockfd, (uint8_t *) &cmd, sizeof(dS485dCommand));
535
545536 /*
546537 * Start receiver thread
547538 */
548539 if (!preInitDone)
549 if (pthread_create(&rxThread, NULL, sysRxThread,NULL)) {
550 }
540 if (pthread_create(&rxThread, NULL, sysRxThread,NULL)) {
541 }
551542 preInitDone=1;
552543
553544 dS485Container pFrame;
554 pFrame.containerType=DSTELEGRAM_REQUEST;
545 pFrame.containerType=DS485_CONTAINER_REQUEST;
555546 pFrame.data[0]=0x90;
556547 pFrame.length=1;
557 pFrame.destination=dSIDBroadcast;
548 pFrame.deviceId=dSIDBroadcast;
558549 ds485_client_send_command(&pFrame);
559550
560551 dS485Container pFrame2;
561 pFrame2.containerType=DSTELEGRAM_REQUEST;
552 pFrame2.containerType=DS485_CONTAINER_REQUEST;
562553 pFrame2.data[0]=0x91;
563554 pFrame2.length=1;
564 pFrame2.destination=dSIDBroadcast;
555 pFrame2.deviceId=dSIDBroadcast;
565556 ds485_client_send_command(&pFrame2);
557
566558 return &mainActive;
567559}
568560
573573
574574 return;
575575}
576/*
577576
578dsidType DeviceForIndex(int iIndex)
579{
580 int i;
581 dsidType nulldSID;
582 nulldSID.value[0]=0;
583 nulldSID.value[1]=0;
584 nulldSID.value[2]=0;
585 nulldSID.value[3]=0;
586 nulldSID.value[4]=0;
587 nulldSID.value[5]=0;
588 nulldSID.value[6]=0;
589 nulldSID.value[7]=0;
590 nulldSID.value[8]=0;
591 nulldSID.value[9]=0;
592 nulldSID.value[10]=0;
593 nulldSID.value[11]=0;
594 for (j=0;j<MAX_THREADS;j++)
595 for (i=0;i<64;i++)
596 if (connectionItem[j].sessionState==DSBUS_ACTIVE)
597 if (connectionItem[j].dSIDExisting[i].state) {
598 if (iIndex==0)
599 return connectionItem[j].dSIDExisting[i].oDSID;
600 else
601 iIndex--;
602 }
603 return nulldSID;
604}
605*/
606/*dS485Container synchronizedCall(dS485Container pFrame){
607
608 dS485Container pFrameResult;
609
610 pthread_mutex_lock(&answer_mutex);
611
612 if (!pFrame.broadcastflag) {
613 oAnswer.Status=Waiting;
614 oAnswer.request=pFrame;
615 }
616 oAnswer.request.command=0x0a;
617 sendMessageToSocket(pFrame);
618
619 if (!pFrame.broadcastflag) {
620 struct timespec ts;
621 struct timeval now;
622 gettimeofday(&now,NULL);
623 ts.tv_sec = now.tv_sec +dSMAPI_CALL_TIMEOUT_SEKUNDEN;
624 ts.tv_nsec = now.tv_usec * 1000;
625
626 pthread_cond_timedwait(&answer_threshold_cv, &answer_mutex,&ts);
627 if (oAnswer.Status==Received)
628 {
629 pFrameResult=oAnswer.answer;
630 } else {
631 pFrameResult.msgid=0xff;
632 }
633 oAnswer.Status=notWaiting;
634 } else
635 pFrameResult.msgid=0xfe;
636
637 pthread_mutex_unlock(&answer_mutex);
638 return pFrameResult;
639}
640*/
577#if 0
641578void formatFrame(char *pTarget,dS485TransportFrame *pMessage)
642579{
643580 char *pChar=pTarget;
591591 pChar+=sprintf(pChar,"param7 : %.2x%.2x ",pMessage->data[14],pMessage->data[13]);
592592 pChar+=sprintf(pChar,"length : %.2d\r\n",(pMessage->length-1)/2);
593593}
594#endif
594595
595void formatContainer(char *pTarget,dS485Container *pMessage)
596void formatContainer(char *pTarget, dS485Container *pMessage)
596597{
597 char *pChar=pTarget;
598 pChar+=sprintf(pChar," Type : %.1x ",pMessage->containerType);
599 pChar+=sprintf(pChar," addr : %.2x%.2x ",pMessage->destination.value[10],pMessage->destination.value[11]);
600 pChar+=sprintf(pChar," msgId : %.2x\r\n",pMessage->data[0]);
601 pChar+=sprintf(pChar,"param1 : %.2x%.2x ",pMessage->data[2],pMessage->data[1]);
602 pChar+=sprintf(pChar,"param2 : %.2x%.2x ",pMessage->data[4],pMessage->data[3]);
603 pChar+=sprintf(pChar,"param3 : %.2x%.2x ",pMessage->data[6],pMessage->data[5]);
604 pChar+=sprintf(pChar,"param4 : %.2x%.2x\r\n" ,pMessage->data[8],pMessage->data[7]);
605 pChar+=sprintf(pChar,"param5 : %.2x%.2x ",pMessage->data[10],pMessage->data[9]);
606 pChar+=sprintf(pChar,"param6 : %.2x%.2x ",pMessage->data[12],pMessage->data[11]);
607 pChar+=sprintf(pChar,"param7 : %.2x%.2x ",pMessage->data[14],pMessage->data[13]);
608 pChar+=sprintf(pChar,"length : %.2d\r\n",(pMessage->length-1)/2);
598 char *pChar = pTarget;
599 unsigned char n;
600
601 pChar+=sprintf(pChar," Type : %.1x ", pMessage->containerType);
602 pChar+=sprintf(pChar," Flags : %.1x ", pMessage->containerFlags);
603 pChar+=sprintf(pChar," msgId : %.2x ", pMessage->data[0]);
604 pChar+=sprintf(pChar," addr : %d/", pMessage->deviceAddress);
605 for (n = 0; n < 12; n ++)
606 pChar += sprintf(pChar, "%02x", pMessage->deviceId.value[n]);
607 pChar+=sprintf(pChar,"\n");
608 pChar+=sprintf(pChar,"param1 : %.2x%.2x ", pMessage->data[2],pMessage->data[1]);
609 pChar+=sprintf(pChar,"param2 : %.2x%.2x ", pMessage->data[4],pMessage->data[3]);
610 pChar+=sprintf(pChar,"param3 : %.2x%.2x ", pMessage->data[6],pMessage->data[5]);
611 pChar+=sprintf(pChar,"param4 : %.2x%.2x\r\n", pMessage->data[8],pMessage->data[7]);
612 pChar+=sprintf(pChar,"param5 : %.2x%.2x ", pMessage->data[10],pMessage->data[9]);
613 pChar+=sprintf(pChar,"param6 : %.2x%.2x ", pMessage->data[12],pMessage->data[11]);
614 pChar+=sprintf(pChar,"param7 : %.2x%.2x ", pMessage->data[14],pMessage->data[13]);
615 pChar+=sprintf(pChar,"length : %d\r\n", pMessage->length);
609616}
610617
618void formatConnectionItem(char *p, connectionItem_t *pItem, unsigned char deviceAddress)
619{
620 unsigned char n;
621 p += sprintf(p, "Device: addr: %d/", deviceAddress);
622 for (n = 0; n < 12; n ++)
623 p += sprintf(p, "%02x", pItem->dSIDExisting[deviceAddress].oDSID.value[n]);
624 p += sprintf(p, ", state:%d\n", pItem->dSIDExisting[deviceAddress].state);
625}
611626
612627/////////////////////////////////////////////////////////////////////////////
613628
649649 token = strtok(NULL, ":");
650650 if (token) pTempPort = token;
651651
652 init(pTempPort,pTempHost,pTempPort,0);
652 init(pTempPort, pTempHost, pTempPort, 1);
653653}
654654
655655/**
735735int ds485_client_send_command(dS485Container *pCommand)
736736{
737737 dS485RXCommand cmdCall;
738 unsigned int cmdLength;
738739 char oLGMSG[1000];
739740 int iSocketIndex;
740741 int i,j;
741742
742 cmdCall.command = DS845D_CMD_TX_PACKET;
743 cmdCall.length = sizeof(dS485RXCommand);
744 cmdCall.pFrame.typeflag=0;
745 switch(pCommand->containerType)
746 {
747 case DSTELEGRAM_REQUEST:
748 cmdCall.pFrame.command=0x09;
749 break;
750 case DSTELEGRAM_RESPONSE:
751 cmdCall.pFrame.command=0x0a;
752 break;
753 case DSTELEGRAM_EVENT:
754 cmdCall.pFrame.command=0x0e;
755 break;
756 }
757 cmdCall.pFrame.broadcastflag=0;
758 for (i=0;i<15;i++)
759 cmdCall.pFrame.data[i]=pCommand->data[i];
760 cmdCall.pFrame.length=pCommand->length;
743 memset(&cmdCall, 0, sizeof(dS485RXCommand));
761744
762 if (compareDSID(pCommand->destination,dSIDBroadcast))
745 cmdCall.apiData.deviceAddress = pCommand->deviceAddress;
746 cmdCall.apiData.deviceId = pCommand->deviceId;
747 cmdCall.apiData.containerType = pCommand->containerType;
748 cmdCall.apiData.containerFlags = DS485_FLAG_NONE;
749 cmdCall.apiData.length = pCommand->length;
750 memcpy(&cmdCall.apiData.data, pCommand->data, cmdCall.apiData.length);
751
752 cmdLength = DS485_CONTAINER_SIZE + cmdCall.apiData.length + 2;
753
754 cmdCall.length = cmdLength;
755 cmdCall.command = DS845D_CMD_TX_PACKET;
756
757 if (compareDSID(pCommand->deviceId, dSIDBroadcast))
763758 {
764 for (iSocketIndex=0;iSocketIndex<MAX_THREADS;iSocketIndex++)
765 if (connectionItem[iSocketIndex].sockfd) {
766 cmdCall.pFrame.broadcastflag=1;
767 cmdCall.pFrame.destination=0;
759 cmdCall.apiData.deviceAddress = 0xff;
760 cmdCall.apiData.containerFlags |= DS485_FLAG_BROADCAST;
768761
769 if (verbose) {
770 printf("Sende Packet to socket %d(%x):\n",iSocketIndex, connectionItem[iSocketIndex].sockfd);
771 formatFrame(oLGMSG,&cmdCall.pFrame);
772 printf("%s",oLGMSG);
773 }
774 sockwrite(connectionItem[iSocketIndex].sockfd, (uint8_t *) &cmdCall, sizeof(dS485RXCommand));
762#if 0
763 if (verbose) {
764 printf("ds485_client_send_command:\n");
765 formatContainer(oLGMSG, &cmdCall.apiData);
766 printf("%s",oLGMSG);
767 }
768#endif
769
770 for (iSocketIndex=0;iSocketIndex<MAX_THREADS;iSocketIndex++)
771 if (connectionItem[iSocketIndex].sockfd) {
772 sockwrite(connectionItem[iSocketIndex].sockfd, (uint8_t *) &cmdCall, cmdLength);
775773 }
776774 return 0;
777775 }
778776
779777 int iSearchIndex=-1;
780
781778 for (j=0;j<MAX_THREADS;j++)
782779 if (connectionItem[j].sessionState==DSBUS_ACTIVE)
783780 for (i=0;i<64;i++)
784781 if (connectionItem[j].dSIDExisting[i].state) {
785 if (compareDSID(connectionItem[j].dSIDExisting[i].oDSID,pCommand->destination)) {
782 if (compareDSID(connectionItem[j].dSIDExisting[i].oDSID, pCommand->deviceId)) {
786783 iSearchIndex=i;
787784 iSocketIndex=j;
788
789785 }
790786 }
791787
792788 if (iSearchIndex!=-1) {
793 cmdCall.pFrame.destination=iSearchIndex;
789 cmdCall.apiData.deviceAddress = iSearchIndex;
790 cmdCall.apiData.deviceId = connectionItem[j].dSIDExisting[iSearchIndex].oDSID;
794791
795 if (verbose) {
796 printf("Sende Packet to socket %d(%x):\n",iSocketIndex, connectionItem[iSocketIndex].sockfd);
797 formatFrame(oLGMSG,&cmdCall.pFrame);
798 printf("%s",oLGMSG);
799 }
800 sockwrite(connectionItem[iSocketIndex].sockfd, (uint8_t *) &cmdCall, sizeof(dS485RXCommand));
792#if 0
793 if (verbose) {
794 printf("ds485_client_send_command:\n");
795 formatContainer(oLGMSG, &cmdCall.apiData);
796 printf("%s",oLGMSG);
797 }
798#endif
799
800 if (connectionItem[iSocketIndex].sockfd) {
801 sockwrite(connectionItem[iSocketIndex].sockfd, (uint8_t *) &cmdCall, cmdLength);
802 }
801803 return 0;
802804 }
803805
806 printf("ds485_client_send: id not found\n");
804807 return -1;
805808}
806809
812812 */
813813int ds485_client_send_sync_command(dS485Container *pCommand, dS485Container *pResponse)
814814{
815 int result;
815 int result, rval;
816816 pthread_mutex_lock(&answer_mutex);
817817
818818 pResponse->data[1]=0xff;
819819 pResponse->data[2]=0xff;
820820
821 if (!(compareDSID(pCommand->destination,dSIDBroadcast))) {
822 oAnswer.Status=Waiting;
823 oAnswer.request=*pCommand;
821 if (!(compareDSID(pCommand->deviceId,dSIDBroadcast))) {
822 oAnswer.Status = Waiting;
823 oAnswer.request = *pCommand;
824824 }
825 oAnswer.request.containerType=DSTELEGRAM_RESPONSE;
825 oAnswer.request.containerType = DS485_CONTAINER_RESPONSE;
826
826827 result=ds485_client_send_command(pCommand);
827 if (result==0)
828 if (!(compareDSID(pCommand->destination,dSIDBroadcast))) {
828 if (result==0) {
829 if (!(compareDSID(pCommand->deviceId,dSIDBroadcast))) {
829830 struct timespec ts;
830831 struct timeval now;
831832 gettimeofday(&now,NULL);
834834 ts.tv_nsec = now.tv_usec * 1000;
835835 result=0;
836836
837 pthread_cond_timedwait(&answer_threshold_cv, &answer_mutex,&ts);
838 if (oAnswer.Status==Received)
839 {
840 *pResponse=oAnswer.answer;
841 } else {
842 result=-1;
843 }
837 while (oAnswer.Status != Received) {
838 rval = pthread_cond_timedwait(&answer_threshold_cv, &answer_mutex,&ts);
839 if (oAnswer.Status == Received)
840 {
841 *pResponse=oAnswer.answer;
842 break;
843 } else {
844 result = -1;
845 }
846 }
844847 oAnswer.Status=notWaiting;
845 } else
848 } else {
846849 result=-2;
850 }
851 }
847852
848853 pthread_mutex_unlock(&answer_mutex);
849854 return result;
core/ds485-socket/ds485Connection.h
(0 / 3)
  
1414 void deinit() ;
1515 void setVerbose(int iVerbose);
1616
17 void formatFrame(char *pTarget,dS485TransportFrame *pFrame);
18 void formatContainer(char *pTarget,dS485Container *pMessage);
19
2017#ifdef __cplusplus
2118 }
2219#endif
core/ds485-socket/ds485RawFunction-old.c
(157 / 287)
  
2828extern pthread_cond_t answer_threshold_cv;
2929
3030
31#define setPara(dSFrame, ParameterNummer, Value) dSFrame.data[(((ParameterNummer)-1)*2)+1]=Value&0xff; dSFrame.data[(((ParameterNummer)-1)*2)+2]=(Value>>8)&0xff
32#define setParaCount(dSFrame, ParameterCount) dSFrame.length=1+(ParameterCount*2)
33#define getPara(dSFrame, ParameterNummer) (dSFrame.data[((ParameterNummer-1)*2)+1] | ((dSFrame.data[((ParameterNummer-1)*2)+2]<<8)&0xff00))
31//#define setPara(dSFrame, ParameterNummer, Value) dSFrame.data[(((ParameterNummer)-1)*2)+1]=Value&0xff; dSFrame.data[(((ParameterNummer)-1)*2)+2]=(Value>>8)&0xff
32//#define setParaCount(dSFrame, ParameterCount) dSFrame.length=1+(ParameterCount*2)
33//#define getPara(dSFrame, ParameterNummer) (dSFrame.data[((ParameterNummer-1)*2)+1] | ((dSFrame.data[((ParameterNummer-1)*2)+2]<<8)&0xff00))
3434
35#define setPara16(dSFrame, ParameterNummer, Value) { uint16_t *obj = (uint16_t *) & (dSFrame.data[1+((ParameterNummer)-1)*2]); *obj = (Value); }
36#define getPara16(dSFrame, ParameterNummer) ( *(uint16_t *) & (dSFrame.data[1+((ParameterNummer)-1)*2]))
3537
3638long dSMAPI_addRoom(dsidType dSMdSID, unsigned int roomId){
3739 long returnValue;
3840 dS485Container pFrame,pFrameAnswer;
3941
40 pFrame.destination=dSMdSID;
41
42 pFrame.containerType=DSTELEGRAM_REQUEST;
42 pFrame.deviceId=dSMdSID;
43 pFrame.containerType=DS485_CONTAINER_REQUEST;
4344 pFrame.data[0]=MAPI_ADD_ROOM;
44 setPara(pFrame,1,roomId);
45 setPara16(pFrame,1,roomId);
4546 setParaCount(pFrame,1);
46
4747 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
4848
49 returnValue=getPara(pFrameAnswer,1);
50
49 returnValue=getPara16(pFrameAnswer,1);
5150 return returnValue;
5251}
5352
5454 long returnValue;
5555 dS485Container pFrame,pFrameAnswer;
5656
57 pFrame.destination=dSMdSID;
58
59
60 pFrame.containerType=DSTELEGRAM_REQUEST;
57 pFrame.deviceId=dSMdSID;
58 pFrame.containerType=DS485_CONTAINER_REQUEST;
6159 pFrame.data[0]=MAPI_REM_ROOM;
62 setPara(pFrame,1,roomId);
60 setPara16(pFrame,1,roomId);
6361 setParaCount(pFrame,1);
6462 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
6563
66 returnValue=getPara(pFrameAnswer,1);
64 returnValue=getPara16(pFrameAnswer,1);
6765 return returnValue;
6866}
6967
6969 long returnValue;
7070 dS485Container pFrame,pFrameAnswer;
7171
72 pFrame.destination=dSMdSID;
73
74
75
76 pFrame.containerType=DSTELEGRAM_REQUEST;
72 pFrame.deviceId=dSMdSID;
73 pFrame.containerType=DS485_CONTAINER_REQUEST;
7774 pFrame.data[0]=MAPI_REM_ALL_ROOMS;
7875 setParaCount(pFrame,0);
7976 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
8077
81 returnValue=getPara(pFrameAnswer,1);
78 returnValue=getPara16(pFrameAnswer,1);
8279 return returnValue;
8380}
8481
8383 long returnValue;
8484 dS485Container pFrame,pFrameAnswer;
8585
86 pFrame.destination=dSMdSID;
87
88
89 pFrame.containerType=DSTELEGRAM_REQUEST;
86 pFrame.deviceId=dSMdSID;
87 pFrame.containerType=DS485_CONTAINER_REQUEST;
9088 pFrame.data[0]=MAPI_GET_GROUP_COUNT;
91 setPara(pFrame,1,roomId);
89 setPara16(pFrame,1,roomId);
9290 setParaCount(pFrame,1);
9391 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
9492
95 returnValue=getPara(pFrameAnswer,1);
93 returnValue=getPara16(pFrameAnswer,1);
9694 return returnValue;
9795}
9896
9898 long returnValue;
9999 dS485Container pFrame,pFrameAnswer;
100100
101 pFrame.destination=dSMdSID;
102
103
104 pFrame.containerType=DSTELEGRAM_REQUEST;
101 pFrame.deviceId=dSMdSID;
102 pFrame.containerType=DS485_CONTAINER_REQUEST;
105103 pFrame.data[0]=MAPI_GET_GROUP_ID_IN_ROOM;
106 setPara(pFrame,1,roomID);
107 setPara(pFrame,2,groupIndex);
104 setPara16(pFrame,1,roomID);
105 setPara16(pFrame,2,groupIndex);
108106 setParaCount(pFrame,2);
109107 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
110108
111 returnValue=getPara(pFrameAnswer,1);
112 *grType =getPara(pFrameAnswer,2);
109 returnValue = getPara16(pFrameAnswer,1);
110 *grType = getPara16(pFrameAnswer,2);
113111 return returnValue;
114112}
115113
115115 long returnValue;
116116 dS485Container pFrame,pFrameAnswer;
117117
118 pFrame.destination=dSMdSID;
119
120
121 pFrame.containerType=DSTELEGRAM_REQUEST;
118 pFrame.deviceId=dSMdSID;
119 pFrame.containerType=DS485_CONTAINER_REQUEST;
122120 pFrame.data[0]=MAPI_GET_DEVICE_COUNT;
123 setPara(pFrame,1,roomId);
121 setPara16(pFrame,1,roomId);
124122 setParaCount(pFrame,1);
125
126123 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
127124
128 returnValue=getPara(pFrameAnswer,1);
125 returnValue=getPara16(pFrameAnswer,1);
129126 return returnValue;
130127}
131128
130130 long returnValue;
131131 dS485Container pFrame,pFrameAnswer;
132132
133 pFrame.destination=dSMdSID;
134
135
136 pFrame.containerType=DSTELEGRAM_REQUEST;
133 pFrame.deviceId=dSMdSID;
134 pFrame.containerType=DS485_CONTAINER_REQUEST;
137135 pFrame.data[0]=MAPI_GET_DEVICE_ADDRESS;
138 setPara(pFrame,1,roomId);
139 setPara(pFrame,2,devIndex);
136 setPara16(pFrame,1,roomId);
137 setPara16(pFrame,2,devIndex);
140138 setParaCount(pFrame,2);
141
142139 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
143140
144 returnValue=getPara(pFrameAnswer,1);
141 returnValue=getPara16(pFrameAnswer,1);
145142 return returnValue;
146143}
147144
146146 long returnValue;
147147 dS485Container pFrame,pFrameAnswer;
148148
149 pFrame.destination=dSMdSID;
150
151
152 pFrame.containerType=DSTELEGRAM_REQUEST;
149 pFrame.deviceId=dSMdSID;
150 pFrame.containerType=DS485_CONTAINER_REQUEST;
153151 pFrame.data[0]=MAPI_GET_ROOM_COUNT;
154152 setParaCount(pFrame,0);
155
156153 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
157154
158 returnValue=getPara(pFrameAnswer,1);
155 returnValue = getPara16(pFrameAnswer,1);
156 printf("Device has %d rooms\n", returnValue);
159157 return returnValue;
160158}
161159
162162 long returnValue;
163163 dS485Container pFrame,pFrameAnswer;
164164
165 pFrame.destination=dSMdSID;
166
167
168 pFrame.containerType=DSTELEGRAM_REQUEST;
165 pFrame.deviceId=dSMdSID;
166 pFrame.containerType=DS485_CONTAINER_REQUEST;
169167 pFrame.data[0]=MAPI_GET_ROOM_ID;
170168 setParaCount(pFrame,1);
171 setPara(pFrame,1,index);
169 setPara16(pFrame,1,index);
172170 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
173171
174
175 returnValue=getPara(pFrameAnswer,1);
172 returnValue=getPara16(pFrameAnswer,1);
176173 return returnValue;
177174}
178175
177177 long returnValue;
178178 dS485Container pFrame,pFrameAnswer;
179179
180 pFrame.destination=dSMdSID;
181
182
183 pFrame.containerType=DSTELEGRAM_REQUEST;
180 pFrame.deviceId=dSMdSID;
181 pFrame.containerType=DS485_CONTAINER_REQUEST;
184182 pFrame.data[0]=MAPI_GET_GROUP_DEVICE_COUNT;
185183 setParaCount(pFrame,2);
186184 setPara(pFrame,1,roomId);
193193 long returnValue;
194194 dS485Container pFrame,pFrameAnswer;
195195
196 pFrame.destination=dSMdSID;
197
198
199 pFrame.containerType=DSTELEGRAM_REQUEST;
196 pFrame.deviceId=dSMdSID;
197 pFrame.containerType=DS485_CONTAINER_REQUEST;
200198 pFrame.data[0]=MAPI_GET_GROUP_DEVICE_ADDRESS;
201199 setParaCount(pFrame,3);
202200 setPara(pFrame,1,roomId);
210210 long returnValue;
211211 dS485Container pFrame,pFrameAnswer;
212212
213 pFrame.destination=dSMdSID;
214
215
216 pFrame.containerType=DSTELEGRAM_REQUEST;
213 pFrame.deviceId=dSMdSID;
214 pFrame.containerType=DS485_CONTAINER_REQUEST;
217215 pFrame.data[0]=MAPI_ADD_USER_GROUP;
218216 setParaCount(pFrame,2);
219217 setPara(pFrame,1,roomId);
228228 long returnValue;
229229 dS485Container pFrame,pFrameAnswer;
230230
231 pFrame.destination=dSMdSID;
232
233
234 pFrame.containerType=DSTELEGRAM_REQUEST;
231 pFrame.deviceId=dSMdSID;
232 pFrame.containerType=DS485_CONTAINER_REQUEST;
235233 pFrame.data[0]=MAPI_REM_USER_GROUP;
236234 setParaCount(pFrame,2);
237235 setPara(pFrame,1,roomId);
245245 long returnValue;
246246 dS485Container pFrame,pFrameAnswer;
247247
248 pFrame.destination=dSMdSID;
249
250
251 pFrame.containerType=DSTELEGRAM_REQUEST;
248 pFrame.deviceId=dSMdSID;
249 pFrame.containerType=DS485_CONTAINER_REQUEST;
252250 pFrame.data[0]=MAPI_REM_ALL_USER_GROUPS;
253251 setParaCount(pFrame,1);
254252 setPara(pFrame,1,roomId);
263263 long returnValue;
264264 dS485Container pFrame,pFrameAnswer;
265265
266 pFrame.destination=dSMdSID;
267
268
269 pFrame.containerType=DSTELEGRAM_REQUEST;
266 pFrame.deviceId=dSMdSID;
267 pFrame.containerType=DS485_CONTAINER_REQUEST;
270268 pFrame.data[0]=MAPI_GET_GROUP_LAST_SCENE;
271269 setParaCount(pFrame,2);
272270 setPara(pFrame,1,roomId);
280280 long returnValue;
281281 dS485Container pFrame,pFrameAnswer;
282282
283 pFrame.destination=dSMdSID;
284
285
286 pFrame.containerType=DSTELEGRAM_REQUEST;
283 pFrame.deviceId=dSMdSID;
284 pFrame.containerType=DS485_CONTAINER_REQUEST;
287285 pFrame.data[0]=MAPI_INC_GROUP_VALUE;
288286 setParaCount(pFrame,2);
289287 setPara(pFrame,1,roomId);
297297 long returnValue;
298298 dS485Container pFrame,pFrameAnswer;
299299
300 pFrame.destination=dSMdSID;
301
302
303 pFrame.containerType=DSTELEGRAM_REQUEST;
300 pFrame.deviceId=dSMdSID;
301 pFrame.containerType=DS485_CONTAINER_REQUEST;
304302 pFrame.data[0]=MAPI_DEC_GROUP_VALUE;
305303 setParaCount(pFrame,2);
306304 setPara(pFrame,1,roomId);
314314 long returnValue;
315315 dS485Container pFrame,pFrameAnswer;
316316
317 pFrame.destination=dSMdSID;
318
319
320 pFrame.containerType=DSTELEGRAM_REQUEST;
317 pFrame.deviceId=dSMdSID;
318 pFrame.containerType=DS485_CONTAINER_REQUEST;
321319 pFrame.data[0]=MAPI_INC_STARTDIM_GROUP;
322320 setParaCount(pFrame,2);
323321 setPara(pFrame,1,roomId);
331331 long returnValue;
332332 dS485Container pFrame,pFrameAnswer;
333333
334 pFrame.destination=dSMdSID;
335
336
337 pFrame.containerType=DSTELEGRAM_REQUEST;
334 pFrame.deviceId=dSMdSID;
335 pFrame.containerType=DS485_CONTAINER_REQUEST;
338336 pFrame.data[0]=MAPI_DEC_STARTDIM_GROUP;
339337 setParaCount(pFrame,2);
340338 setPara(pFrame,1,roomId);
348348 long returnValue;
349349 dS485Container pFrame,pFrameAnswer;
350350
351 pFrame.destination=dSMdSID;
352
353
354 pFrame.containerType=DSTELEGRAM_REQUEST;
351 pFrame.deviceId=dSMdSID;
352 pFrame.containerType=DS485_CONTAINER_REQUEST;
355353 pFrame.data[0]=MAPI_STOPDIM_GROUP;
356354 setParaCount(pFrame,2);
357355 setPara(pFrame,1,roomId);
365365 long returnValue;
366366 dS485Container pFrame,pFrameAnswer;
367367
368 pFrame.destination=dSMdSID;
369
370
371 pFrame.containerType=DSTELEGRAM_REQUEST;
368 pFrame.deviceId=dSMdSID;
369 pFrame.containerType=DS485_CONTAINER_REQUEST;
372370 pFrame.data[0]=MAPI_CALL_SCENE_GROUP;
373371 setParaCount(pFrame,3);
374372 setPara(pFrame,1,roomId);
384384 long returnValue;
385385 dS485Container pFrame,pFrameAnswer;
386386
387 pFrame.destination=dSMdSID;
388
389
390 pFrame.containerType=DSTELEGRAM_REQUEST;
387 pFrame.deviceId=dSMdSID;
388 pFrame.containerType=DS485_CONTAINER_REQUEST;
391389 pFrame.data[0]=MAPI_SAVE_SCENE_GROUP;
392390 setParaCount(pFrame,3);
393391 setPara(pFrame,1,roomId);
401401 long returnValue;
402402 dS485Container pFrame,pFrameAnswer;
403403
404 pFrame.destination=dSMdSID;
405
406
407 pFrame.containerType=DSTELEGRAM_REQUEST;
404 pFrame.deviceId=dSMdSID;
405 pFrame.containerType=DS485_CONTAINER_REQUEST;
408406 pFrame.data[0]=MAPI_UNDO_GROUP;
409407 setParaCount(pFrame,2);
410408 setPara(pFrame,1,roomId);
417417 long returnValue;
418418 dS485Container pFrame,pFrameAnswer;
419419
420 pFrame.destination=dSMdSID;
421
422
423 pFrame.containerType=DSTELEGRAM_REQUEST;
420 pFrame.deviceId=dSMdSID;
421 pFrame.containerType=DS485_CONTAINER_REQUEST;
424422 pFrame.data[0]=MAPI_SET_VALUE_GROUP;
425423 setParaCount(pFrame,3);
426424 setPara(pFrame,1,roomId);
435435 long returnValue;
436436 dS485Container pFrame,pFrameAnswer;
437437
438 pFrame.destination=dSMdSID;
439
440
441 pFrame.containerType=DSTELEGRAM_REQUEST;
438 pFrame.deviceId=dSMdSID;
439 pFrame.containerType=DS485_CONTAINER_REQUEST;
442440 pFrame.data[0]=MAPI_IDENTIFY_GROUP;
443441 setParaCount(pFrame,3);
444442 setPara(pFrame,1,addressSelection);
452452 long returnValue;
453453 dS485Container pFrame,pFrameAnswer;
454454
455 pFrame.destination=dSMdSID;
456
457
458 pFrame.containerType=DSTELEGRAM_REQUEST;
455 pFrame.deviceId=dSMdSID;
456 pFrame.containerType=DS485_CONTAINER_REQUEST;
459457 pFrame.data[0]=MAPI_REM_FROM_ALL_GROUPS;
460458 setParaCount(pFrame,1);
461459 setPara(pFrame,1,deviceAdr);
467467 long returnValue;
468468 dS485Container pFrame,pFrameAnswer;
469469
470 pFrame.destination=dSMdSID;
471
472
473 pFrame.containerType=DSTELEGRAM_REQUEST;
470 pFrame.deviceId=dSMdSID;
471 pFrame.containerType=DS485_CONTAINER_REQUEST;
474472 pFrame.data[0]=MAPI_ADD_TO_NEW_GROUP;
475473 setParaCount(pFrame,1);
476474 setPara(pFrame,1,deviceAdr);
482482 long returnValue;
483483 dS485Container pFrame,pFrameAnswer;
484484
485 pFrame.destination=dSMdSID;
486
487
488 pFrame.containerType=DSTELEGRAM_REQUEST;
485 pFrame.deviceId=dSMdSID;
486 pFrame.containerType=DS485_CONTAINER_REQUEST;
489487 pFrame.data[0]=MAPI_REM_ALL_DEVS_FR_ROOM;
490488 setParaCount(pFrame,1);
491489 setPara(pFrame,1,roomId);
497497 long returnValue;
498498 dS485Container pFrame,pFrameAnswer;
499499
500 pFrame.destination=dSMdSID;
501
502
503 pFrame.containerType=DSTELEGRAM_REQUEST;
500 pFrame.deviceId=dSMdSID;
501 pFrame.containerType=DS485_CONTAINER_REQUEST;
504502 pFrame.data[0]=MAPI_ADD_TO_GROUP;
505503 setParaCount(pFrame,2);
506504 setPara(pFrame,1,deviceAdr);
513513 long returnValue;
514514 dS485Container pFrame,pFrameAnswer;
515515
516 pFrame.destination=dSMdSID;
517
518
519 pFrame.containerType=DSTELEGRAM_REQUEST;
516 pFrame.deviceId=dSMdSID;
517 pFrame.containerType=DS485_CONTAINER_REQUEST;
520518 pFrame.data[0]=MAPI_REM_FROM_GROUP;
521519 setParaCount(pFrame,2);
522520 setPara(pFrame,1,deviceAdr);
529529 long returnValue;
530530 dS485Container pFrame,pFrameAnswer;
531531
532 pFrame.destination=dSMdSID;
533
534
535 pFrame.containerType=DSTELEGRAM_REQUEST;
532 pFrame.deviceId=dSMdSID;
533 pFrame.containerType=DS485_CONTAINER_REQUEST;
536534 pFrame.data[0]=MAPI_INC_VALUE_DEVICE;
537535 setParaCount(pFrame,1);
538536 setPara(pFrame,1,deviceAdr);
544544 long returnValue;
545545 dS485Container pFrame,pFrameAnswer;
546546
547 pFrame.destination=dSMdSID;
548
549
550 pFrame.containerType=DSTELEGRAM_REQUEST;
547 pFrame.deviceId=dSMdSID;
548 pFrame.containerType=DS485_CONTAINER_REQUEST;
551549 pFrame.data[0]=MAPI_DEC_VALUE_DEVICE;
552550 setParaCount(pFrame,1);
553551 setPara(pFrame,1,deviceAdr);
559559 long returnValue;
560560 dS485Container pFrame,pFrameAnswer;
561561
562 pFrame.destination=dSMdSID;
563
564
565 pFrame.containerType=DSTELEGRAM_REQUEST;
562 pFrame.deviceId=dSMdSID;
563 pFrame.containerType=DS485_CONTAINER_REQUEST;
566564 pFrame.data[0]=MAPI_CALL_SCENE_DEVICE;
567565 setParaCount(pFrame,2);
568566 setPara(pFrame,1,deviceAdr);
579579 long returnValue;
580580 dS485Container pFrame,pFrameAnswer;
581581
582 pFrame.destination=dSMdSID;
583
584
585 pFrame.containerType=DSTELEGRAM_REQUEST;
582 pFrame.deviceId=dSMdSID;
583 pFrame.containerType=DS485_CONTAINER_REQUEST;
586584 pFrame.data[0]=MAPI_SAVE_SCENE_DEVICE;
587585 setParaCount(pFrame,2);
588586 setPara(pFrame,1,deviceAdr);
595595 long returnValue;
596596 dS485Container pFrame,pFrameAnswer;
597597
598 pFrame.destination=dSMdSID;
599
600
601 pFrame.containerType=DSTELEGRAM_REQUEST;
598 pFrame.deviceId=dSMdSID;
599 pFrame.containerType=DS485_CONTAINER_REQUEST;
602600 pFrame.data[0]=MAPI_UNDO_DEVICE;
603601 setParaCount(pFrame,1);
604602 setPara(pFrame,1,deviceAdr);
610610 long returnValue;
611611 dS485Container pFrame,pFrameAnswer;
612612
613 pFrame.destination=dSMdSID;
614
615
616 pFrame.containerType=DSTELEGRAM_REQUEST;
613 pFrame.deviceId=dSMdSID;
614 pFrame.containerType=DS485_CONTAINER_REQUEST;
617615 pFrame.data[0]=MAPI_INC_STARTDIM_DEVICE;
618616 setParaCount(pFrame,1);
619617 setPara(pFrame,1,deviceAdr);
625625 long returnValue;
626626 dS485Container pFrame,pFrameAnswer;
627627
628 pFrame.destination=dSMdSID;
629
630
631 pFrame.containerType=DSTELEGRAM_REQUEST;
628 pFrame.deviceId=dSMdSID;
629 pFrame.containerType=DS485_CONTAINER_REQUEST;
632630 pFrame.data[0]=MAPI_DEC_STARTDIM_DEVICE;
633631 setParaCount(pFrame,1);
634632 setPara(pFrame,1,deviceAdr);
639639 long returnValue;
640640 dS485Container pFrame,pFrameAnswer;
641641
642 pFrame.destination=dSMdSID;
643
644
645 pFrame.containerType=DSTELEGRAM_REQUEST;
642 pFrame.deviceId=dSMdSID;
643 pFrame.containerType=DS485_CONTAINER_REQUEST;
646644 pFrame.data[0]=MAPI_STOPDIM_DEVICE;
647645 setParaCount(pFrame,1);
648646 setPara(pFrame,1,deviceAdr);
654654 long returnValue;
655655 dS485Container pFrame,pFrameAnswer;
656656
657 pFrame.destination=dSMdSID;
658
659
660 pFrame.containerType=DSTELEGRAM_REQUEST;
657 pFrame.deviceId=dSMdSID;
658 pFrame.containerType=DS485_CONTAINER_REQUEST;
661659 pFrame.data[0]=MAPI_SET_PARAMETER;
662660 setParaCount(pFrame,3);
663661 setPara(pFrame,1,devAdr);
671671 long returnValue;
672672 dS485Container pFrame,pFrameAnswer;
673673
674 pFrame.destination=dSMdSID;
675
676
677 pFrame.containerType=DSTELEGRAM_REQUEST;
674 pFrame.deviceId=dSMdSID;
675 pFrame.containerType=DS485_CONTAINER_REQUEST;
678676 pFrame.data[0]=MAPI_INC_PARAMETER_VALUE;
679677 setParaCount(pFrame,2);
680678 setPara(pFrame,1,devAdr);
687687 long returnValue;
688688 dS485Container pFrame,pFrameAnswer;
689689
690 pFrame.destination=dSMdSID;
691
692
693 pFrame.containerType=DSTELEGRAM_REQUEST;
690 pFrame.deviceId=dSMdSID;
691 pFrame.containerType=DS485_CONTAINER_REQUEST;
694692 pFrame.data[0]=MAPI_DEC_PARAMETER_VALUE;
695693 setParaCount(pFrame,2);
696694 setPara(pFrame,1,devAdr);
703703 long returnValue;
704704 dS485Container pFrame,pFrameAnswer;
705705
706 pFrame.destination=dSMdSID;
707
708
709 pFrame.containerType=DSTELEGRAM_REQUEST;
706 pFrame.deviceId=dSMdSID;
707 pFrame.containerType=DS485_CONTAINER_REQUEST;
710708 pFrame.data[0]=MAPI_DEVICE_SET_ROOM_ID;
711709 setParaCount(pFrame,2);
712710 setPara(pFrame,1,devAdr);
718718 long returnValue;
719719 dS485Container pFrame,pFrameAnswer;
720720
721 pFrame.destination=dSMdSID;
722
723
724 pFrame.containerType=DSTELEGRAM_REQUEST;
721 pFrame.deviceId=dSMdSID;
722 pFrame.containerType=DS485_CONTAINER_REQUEST;
725723 pFrame.data[0]=MAPI_DEVICE_SET_VALUE;
726724 setParaCount(pFrame,2);
727725 setPara(pFrame,1,devAdr);
734734 long returnValue;
735735 dS485Container pFrame,pFrameAnswer;
736736
737 pFrame.destination=dSMdSID;
738
739
740 pFrame.containerType=DSTELEGRAM_REQUEST;
737 pFrame.deviceId=dSMdSID;
738 pFrame.containerType=DS485_CONTAINER_REQUEST;
741739 pFrame.data[0]=MAPI_DEVICE_IDENTIFY;
742740 setParaCount(pFrame,2);
743741 setPara(pFrame,1,addressSelection);
750750 long returnValue;
751751 dS485Container pFrame;
752752
753 pFrame.destination=dSMdSID;
754
755
756 pFrame.containerType=DSTELEGRAM_REQUEST;
753 pFrame.deviceId=dSMdSID;
754 pFrame.containerType=DS485_CONTAINER_REQUEST;
757755 pFrame.data[0]=MAPI_GET_PARAMETER_VALUE;
758756 setParaCount(pFrame,2);
759757 setPara(pFrame,1,devAdr);
761761 oAnswer.request=pFrame;
762762 }
763763
764 oAnswer.request.containerType=DSTELEGRAM_RESPONSE;
764 oAnswer.request.containerType=DS485_CONTAINER_RESPONSE;
765765 ds485_client_send_command(&pFrame);
766766
767767 int iExpAnswers=3;
804804 long returnValue;
805805 dS485Container pFrame,pFrameAnswer;
806806
807 pFrame.destination=dSMdSID;
808
809
810 pFrame.containerType=DSTELEGRAM_REQUEST;
807 pFrame.deviceId=dSMdSID;
808 pFrame.containerType=DS485_CONTAINER_REQUEST;
811809 pFrame.data[0]=MAPI_GET_DEV_DSID;
812810 setParaCount(pFrame,1);
813811 setPara(pFrame,1,devAdr);
832832 long returnValue;
833833 dS485Container pFrame,pFrameAnswer;
834834
835 pFrame.destination=dSMdSID;
836
837
838 pFrame.containerType=DSTELEGRAM_REQUEST;
835 pFrame.deviceId=dSMdSID;
836 pFrame.containerType=DS485_CONTAINER_REQUEST;
839837 pFrame.data[0]=MAPI_GET_DEV_FID;
840838 setParaCount(pFrame,1);
841839 setPara(pFrame,1,devAdr);
847847 long returnValue;
848848 dS485Container pFrame,pFrameAnswer;
849849
850 pFrame.destination=dSMdSID;
851
852
853 pFrame.containerType=DSTELEGRAM_REQUEST;
850 pFrame.deviceId=dSMdSID;
851 pFrame.containerType=DS485_CONTAINER_REQUEST;
854852 pFrame.data[0]=MAPI_GET_DEV_GROUPFLAGS;
855853 setParaCount(pFrame,1);
856854 setPara(pFrame,1,devAdr);
869869 long returnValue;
870870 dS485Container pFrame,pFrameAnswer;
871871
872 pFrame.destination=dSMdSID;
873
874
875 pFrame.containerType=DSTELEGRAM_REQUEST;
872 pFrame.deviceId=dSMdSID;
873 pFrame.containerType=DS485_CONTAINER_REQUEST;
876874 pFrame.data[0]=MAPI_GET_DEV_VERSION;
877875 setParaCount(pFrame,1);
878876 setPara(pFrame,1,devAdr);
883883
884884long dSMAPI_getType(dsidType dSMdSID,unsigned short *deviceType, unsigned short *hwVersion, unsigned short *swVersion){
885885 dS485Container pFrame,pFrameAnswer;
886 pFrame.destination=dSMdSID;
887 pFrame.containerType=DSTELEGRAM_REQUEST;
886 pFrame.deviceId=dSMdSID;
887 pFrame.containerType=DS485_CONTAINER_REQUEST;
888888 pFrame.data[0]=MAPI_GET_TYPE;
889889 setParaCount(pFrame,0);
890890 if (ds485_client_send_sync_command(&pFrame,&pFrameAnswer)!=0)
900900 long returnValue;
901901 dS485Container pFrame,pFrameAnswer;
902902
903 pFrame.destination=dSMdSID;
904
905
906 pFrame.containerType=DSTELEGRAM_REQUEST;
903 pFrame.deviceId=dSMdSID;
904 pFrame.containerType=DS485_CONTAINER_REQUEST;
907905 pFrame.data[0]=MAPI_GET_DSID;
908906 setParaCount(pFrame,0);
909907 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
925925 long returnValue;
926926 dS485Container pFrame,pFrameAnswer;
927927
928 pFrame.destination=dSMdSID;
929
930
931 pFrame.containerType=DSTELEGRAM_REQUEST;
928 pFrame.deviceId=dSMdSID;
929 pFrame.containerType=DS485_CONTAINER_REQUEST;
932930 pFrame.data[0]=MAPI_GET_VERSION_HW;
933931 setParaCount(pFrame,0);
934932 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
938938 long returnValue;
939939 dS485Container pFrame,pFrameAnswer;
940940
941 pFrame.destination=dSMdSID;
942
943
944 pFrame.containerType=DSTELEGRAM_REQUEST;
941 pFrame.deviceId=dSMdSID;
942 pFrame.containerType=DS485_CONTAINER_REQUEST;
945943 pFrame.data[0]=MAPI_GET_VERSION_SW;
946944 setParaCount(pFrame,0);
947945 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
951951 long returnValue;
952952 dS485Container pFrame,pFrameAnswer;
953953
954 pFrame.destination=dSMdSID;
955
956
957 pFrame.containerType=DSTELEGRAM_REQUEST;
954 pFrame.deviceId=dSMdSID;
955 pFrame.containerType=DS485_CONTAINER_REQUEST;
958956 pFrame.data[0]=MAPI_GET_POWER_CONSUMPTION;
959957 setParaCount(pFrame,0);
960958 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
965965 long returnValue;
966966 dS485Container pFrame,pFrameAnswer;
967967
968 pFrame.destination=dSMdSID;
969
970
971 pFrame.containerType=DSTELEGRAM_REQUEST;
968 pFrame.deviceId=dSMdSID;
969 pFrame.containerType=DS485_CONTAINER_REQUEST;
972970 pFrame.data[0]=MAPI_GET_POWER_METERVALUE;
973971 setParaCount(pFrame,0);
974972 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
978978long dSMAPI_setEnergyBorder(dsidType dSMdSID,unsigned int Gelb, unsigned int Rot){
979979 dS485Container pFrame,pFrameAnswer;
980980
981 pFrame.destination=dSMdSID;
982
983
984 pFrame.containerType=DSTELEGRAM_REQUEST;
981 pFrame.deviceId=dSMdSID;
982 pFrame.containerType=DS485_CONTAINER_REQUEST;
985983 pFrame.data[0]=MAPI_SET_ENERGY_BORDER;
986984 setParaCount(pFrame,2);
987985 setPara(pFrame,1,Gelb);
991991long dSMAPI_getEnergyBorder(dsidType dSMdSID,unsigned int *Gelb, unsigned int *Rot){
992992 dS485Container pFrame,pFrameAnswer;
993993
994 pFrame.destination=dSMdSID;
995
996
997 pFrame.containerType=DSTELEGRAM_REQUEST;
994 pFrame.deviceId=dSMdSID;
995 pFrame.containerType=DS485_CONTAINER_REQUEST;
998996 pFrame.data[0]=MAPI_GET_ENERGY_BORDER;
999997 setParaCount(pFrame,0);
1000998 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
10051005 long returnValue;
10061006
10071007 dS485Container pFrameP1;
1008
10091008 dS485Container pFrameP2;
10101009
10111010 pthread_mutex_lock(&answer_mutex);
10121011
1013 pFrameP1.destination=dSMdSID;
1014 pFrameP2.destination=dSMdSID;
1015
1016 pFrameP1.containerType=DSTELEGRAM_REQUEST;
1017 pFrameP2.containerType=DSTELEGRAM_REQUEST;
1012 pFrameP1.deviceId=dSMdSID;
1013 pFrameP2.deviceId=dSMdSID;
1014 pFrameP1.containerType=DS485_CONTAINER_REQUEST;
1015 pFrameP2.containerType=DS485_CONTAINER_REQUEST;
10181016 pFrameP1.data[0]=0x9e;
10191017 pFrameP2.data[0]=0x9e;
10201018
10351035 oAnswer.Status=Waiting;
10361036 oAnswer.request=pFrameP2;
10371037
1038 oAnswer.request.containerType=DSTELEGRAM_RESPONSE;
1038 oAnswer.request.containerType=DS485_CONTAINER_RESPONSE;
10391039 ds485_client_send_command(&pFrameP1);
10401040 ds485_client_send_command(&pFrameP2);
10411041
10731073
10741074 pthread_mutex_lock(&answer_mutex);
10751075
1076
1077 pFrame.destination=dSMdSID;
1078
1079
1080 pFrame.containerType=DSTELEGRAM_REQUEST;
1081
1076 pFrame.deviceId=dSMdSID;
1077 pFrame.containerType=DS485_CONTAINER_REQUEST;
10821078 pFrame.data[0]=0x9e;
1083
10841079 pFrame.data[1]=0x00 | typeOfName;
10851080 pFrame.data[2]=0x00 | typeOfName;
10861081
10941094 oAnswer.Status=Waiting;
10951095 oAnswer.request=pFrame;
10961096
1097 oAnswer.request.containerType=DSTELEGRAM_RESPONSE;
1097 oAnswer.request.containerType=DS485_CONTAINER_RESPONSE;
10981098 ds485_client_send_command(&pFrame);
10991099
11001100 struct timespec ts;
11301130 long returnValue;
11311131 dS485Container pFrame,pFrameAnswer;
11321132
1133 pFrame.destination=dSMdSID;
1134
1135
1136 pFrame.containerType=DSTELEGRAM_REQUEST;
1133 pFrame.deviceId=dSMdSID;
1134 pFrame.containerType=DS485_CONTAINER_REQUEST;
11371135 pFrame.data[0]=0x9f;
11381136 setParaCount(pFrame,1);
11391137 setPara(pFrame,1,devAdr);
11411141 oAnswer.request=pFrame;
11421142 }
11431143
1144 oAnswer.request.containerType=DSTELEGRAM_EVENT;
1144 oAnswer.request.containerType=DS485_CONTAINER_EVENT;
11451145 ds485_client_send_command(&pFrame);
11461146
11471147 if (compareDSID(dSMdSID,dSIDBroadcast)) {
11721172 long returnValue;
11731173 dS485Container pFrame,pFrameAnswer;
11741174
1175 pFrame.destination=dSMdSID;
1176
1177
1178 pFrame.containerType=DSTELEGRAM_REQUEST;
1175 pFrame.deviceId=dSMdSID;
1176 pFrame.containerType=DS485_CONTAINER_REQUEST;
11791177 pFrame.data[0]=0x51;
11801178 setParaCount(pFrame,2);
11811179 setPara(pFrame,1,devAdr);
11881188 long returnValue;
11891189 dS485Container pFrame,pFrameAnswer;
11901190
1191 pFrame.destination=dSMdSID;
1192
1193
1194 pFrame.containerType=DSTELEGRAM_REQUEST;
1191 pFrame.deviceId=dSMdSID;
1192 pFrame.containerType=DS485_CONTAINER_REQUEST;
11951193 pFrame.data[0]=0xb0;
11961194 setParaCount(pFrame,3);
11971195 setPara(pFrame,1,Stunde);
12051205
12061206 dS485Container pFrame,pFrameAnswer;
12071207
1208 pFrame.destination=dSMdSID;
1209
1210
1211 pFrame.containerType=DSTELEGRAM_REQUEST;
1208 pFrame.deviceId=dSMdSID;
1209 pFrame.containerType=DS485_CONTAINER_REQUEST;
12121210 pFrame.data[0]=0xb1;
12131211 setParaCount(pFrame,0);
12141212 ds485_client_send_sync_command(&pFrame,&pFrameAnswer);
core/ds485-socket/ds485RawFunction-old.h
(10 / 3)
  
11#ifndef _ds485RawFunction_old_h
22#define _ds485RawFunction_old_h
33
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
4#ifdef __cplusplus
5extern "C" {
6#endif
77
8#include <arpa/inet.h>
9
810#define setPara(dSFrame, ParameterNummer, Value) dSFrame.data[(((ParameterNummer)-1)*2)+1]=Value&0xff; dSFrame.data[(((ParameterNummer)-1)*2)+2]=(Value>>8)&0xff
11//#define setPara(dSFrame, ParameterNummer, Value) { uint16_t *obj = (uint16_t *) & (dSFrame.data[(ParameterNummer)-1)*2]); *obj = htons(Value); }
12
913#define setParaCount(dSFrame, ParameterCount) dSFrame.length=1+(ParameterCount*2)
14
1015#define getPara(dSFrame, ParameterNummer) (dSFrame.data[((ParameterNummer-1)*2)+1] | ((dSFrame.data[((ParameterNummer-1)*2)+2]<<8)&0xff00))
16//#define getPara(dSFrame, ParameterNummer, Value) (ntohs( *(uint16_t *) & (dSFrame.data[((ParameterNummer)-1)*2])))
17
1118
1219
1320long dSMAPI_addRoom(dsidType dSMdSID, unsigned int roomId);
core/ds485-socket/ds485RawFunction.c
(112 / 112)
  
3838int ZoneModify_Add(dsidType dSMdSID, uint16_t ZoneId)
3939{
4040 dS485Container pFrame,pFrameAnswer;
41 pFrame.containerType=DSTELEGRAM_REQUEST;
42 pFrame.destination=dSMdSID;
41 pFrame.containerType=DS485_CONTAINER_REQUEST;
42 pFrame.deviceId=dSMdSID;
4343 pFrame.data[0]=DSMAPI_ZONE_MODIFY;
4444 setModifier(pFrame,DSMAPI_MODIFIER_ADD);
4545 setParameter(pFrame,1,ZoneId);
5454 uint16_t ZoneId)
5555{
5656 dS485Container pFrame,pFrameAnswer;
57 pFrame.containerType=DSTELEGRAM_REQUEST;
58 pFrame.destination=dSMdSID;
57 pFrame.containerType=DS485_CONTAINER_REQUEST;
58 pFrame.deviceId=dSMdSID;
5959 pFrame.data[0]=DSMAPI_ZONE_MODIFY;
6060 setModifier(pFrame,DSMAPI_MODIFIER_REMOVE);
6161 setParameter(pFrame,1,ZoneId);
7171 uint16_t *DeviceCount)
7272{
7373 dS485Container pFrame,pFrameAnswer;
74 pFrame.containerType=DSTELEGRAM_REQUEST;
75 pFrame.destination=dSMdSID;
74 pFrame.containerType=DS485_CONTAINER_REQUEST;
75 pFrame.deviceId=dSMdSID;
7676 pFrame.data[0]=DSMAPI_ZONE_DEVICE_COUNT;
7777 setModifier(pFrame,DSMAPI_MODIFIER_ONLY_ACTIVE);
7878 setParameter(pFrame,1,ZoneId);
8888 uint16_t *DeviceCount)
8989{
9090 dS485Container pFrame,pFrameAnswer;
91 pFrame.containerType=DSTELEGRAM_REQUEST;
92 pFrame.destination=dSMdSID;
91 pFrame.containerType=DS485_CONTAINER_REQUEST;
92 pFrame.deviceId=dSMdSID;
9393 pFrame.data[0]=DSMAPI_ZONE_DEVICE_COUNT;
9494 setModifier(pFrame,DSMAPI_MODIFIER_ONLY_INACTIVE);
9595 setParameter(pFrame,1,ZoneId);
105105 out uint16_t *deviceCount, uint16_t *lastScene)
106106{
107107 dS485Container pFrame,pFrameAnswer;
108 pFrame.containerType=DSTELEGRAM_REQUEST;
109 pFrame.destination=dSMdSID;
108 pFrame.containerType=DS485_CONTAINER_REQUEST;
109 pFrame.deviceId=dSMdSID;
110110 pFrame.data[0]=DSMAPI_ZONE_GROUP_INFO;
111111 setModifier(pFrame,DSMAPI_MODIFIER_GET);
112112 setParameter(pFrame,1,ZoneId);
123123 uint16_t *ZoneCount)
124124{
125125 dS485Container pFrame,pFrameAnswer;
126 pFrame.containerType=DSTELEGRAM_REQUEST;
127 pFrame.destination=dSMdSID;
126 pFrame.containerType=DS485_CONTAINER_REQUEST;
127 pFrame.deviceId=dSMdSID;
128128 pFrame.data[0]=DSMAPI_ZONE_COUNT;
129129 setModifier(pFrame,DSMAPI_MODIFIER_GET);
130130 setParameterCount(pFrame,0);
139139 uint16_t *ZoneID, uint16_t *FunctionID, uint16_t *MyClickNumber, uint16_t *TargetGroup, uint16_t *PingCounter, uint16_t *StatusFlags, uint16_t *ProductID)
140140{
141141 dS485Container pFrame,pFrameAnswer;
142 pFrame.containerType=DSTELEGRAM_REQUEST;
143 pFrame.destination=dSMdSID;
142 pFrame.containerType=DS485_CONTAINER_REQUEST;
143 pFrame.deviceId=dSMdSID;
144144 pFrame.data[0]=DSMAPI_DEVICE_PROPERTIES;
145145 setParameter(pFrame,1,DeviceId);
146146 setModifier(pFrame,DSMAPI_MODIFIER_GET);
164164 uint16_t DeviceId, uint16_t ZoneId)
165165{
166166 dS485Container pFrame,pFrameAnswer;
167 pFrame.containerType=DSTELEGRAM_REQUEST;
168 pFrame.destination=dSMdSID;
167 pFrame.containerType=DS485_CONTAINER_REQUEST;
168 pFrame.deviceId=dSMdSID;
169169 pFrame.data[0]=DSMAPI_DEVICE_PROPERTIES;
170170 setParameter(pFrame,1,DeviceId);
171171 setParameter(pFrame,2,ZoneId);
180180 uint16_t DeviceId, uint16_t MyClickId)
181181{
182182 dS485Container pFrame,pFrameAnswer;
183 pFrame.containerType=DSTELEGRAM_REQUEST;
184 pFrame.destination=dSMdSID;
183 pFrame.containerType=DS485_CONTAINER_REQUEST;
184 pFrame.deviceId=dSMdSID;
185185 pFrame.data[0]=DSMAPI_DEVICE_PROPERTIES;
186186 setParameter(pFrame,1,DeviceId);
187187 setParameter(pFrame,2,MyClickId);
196196 uint16_t DeviceId, uint16_t MyTargetGroupId)
197197{
198198 dS485Container pFrame,pFrameAnswer;
199 pFrame.containerType=DSTELEGRAM_REQUEST;
200 pFrame.destination=dSMdSID;
199 pFrame.containerType=DS485_CONTAINER_REQUEST;
200 pFrame.deviceId=dSMdSID;
201201 pFrame.data[0]=DSMAPI_DEVICE_PROPERTIES;
202202 setParameter(pFrame,1,DeviceId);
203203 setParameter(pFrame,2,MyTargetGroupId);
212212 uint16_t DeviceId, uint16_t fLocked)
213213{
214214 dS485Container pFrame,pFrameAnswer;
215 pFrame.containerType=DSTELEGRAM_REQUEST;
216 pFrame.destination=dSMdSID;
215 pFrame.containerType=DS485_CONTAINER_REQUEST;
216 pFrame.deviceId=dSMdSID;
217217 pFrame.data[0]=DSMAPI_DEVICE_PROPERTIES;
218218 setParameter(pFrame,1,DeviceId);
219219 setParameter(pFrame,2,fLocked);
228228 uint16_t DeviceId, uint16_t GroupId)
229229{
230230 dS485Container pFrame,pFrameAnswer;
231 pFrame.containerType=DSTELEGRAM_REQUEST;
232 pFrame.destination=dSMdSID;
231 pFrame.containerType=DS485_CONTAINER_REQUEST;
232 pFrame.deviceId=dSMdSID;
233233 pFrame.data[0]=DSMAPI_DEVICE_GROUP_MODIFY;
234234 setParameter(pFrame,1,DeviceId);
235235 setParameter(pFrame,2,GroupId);
244244 uint16_t DeviceId, uint16_t GroupId)
245245{
246246 dS485Container pFrame,pFrameAnswer;
247 pFrame.containerType=DSTELEGRAM_REQUEST;
248 pFrame.destination=dSMdSID;
247 pFrame.containerType=DS485_CONTAINER_REQUEST;
248 pFrame.deviceId=dSMdSID;
249249 pFrame.data[0]=DSMAPI_DEVICE_GROUP_MODIFY;
250250 setParameter(pFrame,1,DeviceId);
251251 setParameter(pFrame,2,GroupId);
260260 uint16_t DeviceId)
261261{
262262 dS485Container pFrame,pFrameAnswer;
263 pFrame.containerType=DSTELEGRAM_REQUEST;
264 pFrame.destination=dSMdSID;
263 pFrame.containerType=DS485_CONTAINER_REQUEST;
264 pFrame.deviceId=dSMdSID;
265265 pFrame.data[0]=DSMAPI_DEVICE_GROUP_MODIFY;
266266 setParameter(pFrame,1,DeviceId);
267267 setModifier(pFrame,DSMAPI_MODIFIER_REMOVE_ALL);
277277 uint16_t *GroupId)
278278{
279279 dS485Container pFrame,pFrameAnswer;
280 pFrame.containerType=DSTELEGRAM_REQUEST;
281 pFrame.destination=dSMdSID;
280 pFrame.containerType=DS485_CONTAINER_REQUEST;
281 pFrame.deviceId=dSMdSID;
282282 pFrame.data[0]=DSMAPI_ZONE_GROUP_MODIFY;
283283 setParameter(pFrame,1,ZoneId);
284284 setModifier(pFrame,DSMAPI_MODIFIER_ADD);
293293 uint16_t ZoneId, uint16_t GroupId)
294294{
295295 dS485Container pFrame,pFrameAnswer;
296 pFrame.containerType=DSTELEGRAM_REQUEST;
297 pFrame.destination=dSMdSID;
296 pFrame.containerType=DS485_CONTAINER_REQUEST;
297 pFrame.deviceId=dSMdSID;
298298 pFrame.data[0]=DSMAPI_ZONE_GROUP_MODIFY;
299299 setParameter(pFrame,1,ZoneId);
300300 setParameter(pFrame,2,GroupId);
309309 uint16_t ZoneId)
310310{
311311 dS485Container pFrame,pFrameAnswer;
312 pFrame.containerType=DSTELEGRAM_REQUEST;
313 pFrame.destination=dSMdSID;
312 pFrame.containerType=DS485_CONTAINER_REQUEST;
313 pFrame.deviceId=dSMdSID;
314314 pFrame.data[0]=DSMAPI_ZONE_GROUP_MODIFY;
315315 setParameter(pFrame,1,ZoneId);
316316 setModifier(pFrame,DSMAPI_MODIFIER_REMOVE_ALL);
325325 uint16_t ZoneId, uint16_t GroupId, uint16_t SceneNr)
326326{
327327 dS485Container pFrame,pFrameAnswer;
328 pFrame.containerType=DSTELEGRAM_REQUEST;
329 pFrame.destination=dSMdSID;
328 pFrame.containerType=DS485_CONTAINER_REQUEST;
329 pFrame.deviceId=dSMdSID;
330330 pFrame.data[0]=DSMAPI_ZONE_GROUP_ACTION;
331331 setModifier(pFrame,DSMAPI_MODIFIER_CALL_SCENE);
332332 setParameter(pFrame,1,ZoneId);
342342 uint16_t ZoneId, uint16_t GroupId, uint16_t SceneNr)
343343{
344344 dS485Container pFrame,pFrameAnswer;
345 pFrame.containerType=DSTELEGRAM_REQUEST;
346 pFrame.destination=dSMdSID;
345 pFrame.containerType=DS485_CONTAINER_REQUEST;
346 pFrame.deviceId=dSMdSID;
347347 pFrame.data[0]=DSMAPI_ZONE_GROUP_ACTION;
348348 setModifier(pFrame,DSMAPI_MODIFIER_SAVE_SCENE);
349349 setParameter(pFrame,1,ZoneId);
359359 uint16_t ZoneId, uint16_t GroupId)
360360{
361361 dS485Container pFrame,pFrameAnswer;
362 pFrame.containerType=DSTELEGRAM_REQUEST;
363 pFrame.destination=dSMdSID;
362 pFrame.containerType=DS485_CONTAINER_REQUEST;
363 pFrame.deviceId=dSMdSID;
364364 pFrame.data[0]=DSMAPI_ZONE_GROUP_ACTION;
365365 setModifier(pFrame,DSMAPI_MODIFIER_UNDO_SCENE);
366366 setParameter(pFrame,1,ZoneId);
374374 uint16_t ZoneId, uint16_t GroupId, uint16_t OutvalIndex, uint16_t Value)
375375{
376376 dS485Container pFrame,pFrameAnswer;
377 pFrame.containerType=DSTELEGRAM_REQUEST;
378 pFrame.destination=dSMdSID;
377 pFrame.containerType=DS485_CONTAINER_REQUEST;
378 pFrame.deviceId=dSMdSID;
379379 pFrame.data[0]=DSMAPI_ZONE_GROUP_ACTION;
380380 setModifier(pFrame,DSMAPI_MODIFIER_SET_OUTVAL);
381381 setParameter(pFrame,1,ZoneId);
391391 uint16_t ZoneId, uint16_t GroupId, uint16_t OutvalIndex)
392392{
393393 dS485Container pFrame,pFrameAnswer;
394 pFrame.containerType=DSTELEGRAM_REQUEST;
395 pFrame.destination=dSMdSID;
394 pFrame.containerType=DS485_CONTAINER_REQUEST;
395 pFrame.deviceId=dSMdSID;
396396 pFrame.data[0]=DSMAPI_ZONE_GROUP_ACTION;
397397 setModifier(pFrame,DSMAPI_MODIFIER_INC_OUTVAL);
398398 setParameter(pFrame,1,ZoneId);
406406 uint16_t ZoneId, uint16_t GroupId, uint16_t OutvalIndex)
407407{
408408 dS485Container pFrame,pFrameAnswer;
409 pFrame.containerType=DSTELEGRAM_REQUEST;
410 pFrame.destination=dSMdSID;
409 pFrame.containerType=DS485_CONTAINER_REQUEST;
410 pFrame.deviceId=dSMdSID;
411411 pFrame.data[0]=DSMAPI_ZONE_GROUP_ACTION;
412412 setModifier(pFrame,DSMAPI_MODIFIER_DEC_OUTVAL);
413413 setParameter(pFrame,1,ZoneId);
421421 uint16_t ZoneId, uint16_t GroupId, uint16_t OutvalIndex)
422422{
423423 dS485Container pFrame,pFrameAnswer;
424 pFrame.containerType=DSTELEGRAM_REQUEST;
425 pFrame.destination=dSMdSID;
424 pFrame.containerType=DS485_CONTAINER_REQUEST;
425 pFrame.deviceId=dSMdSID;
426426 pFrame.data[0]=DSMAPI_ZONE_GROUP_ACTION;
427427 setModifier(pFrame,DSMAPI_MODIFIER_MIN_OUTVAL);
428428 setParameter(pFrame,1,ZoneId);
436436 uint16_t ZoneId, uint16_t GroupId, uint16_t OutvalIndex)
437437{
438438 dS485Container pFrame,pFrameAnswer;
439 pFrame.containerType=DSTELEGRAM_REQUEST;
440 pFrame.destination=dSMdSID;
439 pFrame.containerType=DS485_CONTAINER_REQUEST;
440 pFrame.deviceId=dSMdSID;
441441 pFrame.data[0]=DSMAPI_ZONE_GROUP_ACTION;
442442 setModifier(pFrame,DSMAPI_MODIFIER_MAX_OUTVAL);
443443 setParameter(pFrame,1,ZoneId);
451451 uint16_t ZoneId, uint16_t GroupId, uint16_t OutvalIndex)
452452{
453453 dS485Container pFrame,pFrameAnswer;
454 pFrame.containerType=DSTELEGRAM_REQUEST;
455 pFrame.destination=dSMdSID;
454 pFrame.containerType=DS485_CONTAINER_REQUEST;
455 pFrame.deviceId=dSMdSID;
456456 pFrame.data[0]=DSMAPI_ZONE_GROUP_ACTION;
457457 setModifier(pFrame,DSMAPI_MODIFIER_STOP_OUTVAL);
458458 setParameter(pFrame,1,ZoneId);
466466 uint16_t ZoneId, uint16_t GroupId)
467467{
468468 dS485Container pFrame,pFrameAnswer;
469 pFrame.containerType=DSTELEGRAM_REQUEST;
470 pFrame.destination=dSMdSID;
469 pFrame.containerType=DS485_CONTAINER_REQUEST;
470 pFrame.deviceId=dSMdSID;
471471 pFrame.data[0]=DSMAPI_ZONE_GROUP_ACTION;
472472 setModifier(pFrame,DSMAPI_MODIFIER_REMOVE_LOCAL_PRIO);
473473 setParameter(pFrame,1,ZoneId);
481481 uint16_t ZoneId, uint16_t GroupId)
482482{
483483 dS485Container pFrame,pFrameAnswer;
484 pFrame.containerType=DSTELEGRAM_REQUEST;
485 pFrame.destination=dSMdSID;
484 pFrame.containerType=DS485_CONTAINER_REQUEST;
485 pFrame.deviceId=dSMdSID;
486486 pFrame.data[0]=DSMAPI_ZONE_GROUP_ACTION;
487487 setModifier(pFrame,DSMAPI_MODIFIER_SIGNAL);
488488 setParameter(pFrame,1,ZoneId);
496496 uint16_t ZoneId)
497497{
498498 dS485Container pFrame,pFrameAnswer;
499 pFrame.containerType=DSTELEGRAM_REQUEST;
500 pFrame.destination=dSMdSID;
499 pFrame.containerType=DS485_CONTAINER_REQUEST;
500 pFrame.deviceId=dSMdSID;
501501 pFrame.data[0]=DSMAPI_ZONE_GROUP_ACTION;
502502 setModifier(pFrame,DSMAPI_MODIFIER_SHOW_COLOR);
503503 setParameter(pFrame,1,ZoneId);
511511 uint16_t DeviceId, uint16_t SceneNr)
512512{
513513 dS485Container pFrame,pFrameAnswer;
514 pFrame.containerType=DSTELEGRAM_REQUEST;
515 pFrame.destination=dSMdSID;
514 pFrame.containerType=DS485_CONTAINER_REQUEST;
515 pFrame.deviceId=dSMdSID;
516516 pFrame.data[0]=DSMAPI_DEVICE_ACTION;
517517 setModifier(pFrame,DSMAPI_MODIFIER_CALL_SCENE);
518518 setParameter(pFrame,1,DeviceId);
526526 uint16_t DeviceId, uint16_t SceneNr)
527527{
528528 dS485Container pFrame,pFrameAnswer;
529 pFrame.containerType=DSTELEGRAM_REQUEST;
530 pFrame.destination=dSMdSID;
529 pFrame.containerType=DS485_CONTAINER_REQUEST;
530 pFrame.deviceId=dSMdSID;
531531 pFrame.data[0]=DSMAPI_DEVICE_ACTION;
532532 setModifier(pFrame,DSMAPI_MODIFIER_SAVE_SCENE);
533533 setParameter(pFrame,1,DeviceId);
541541 uint16_t DeviceId)
542542{
543543 dS485Container pFrame,pFrameAnswer;
544 pFrame.containerType=DSTELEGRAM_REQUEST;
545 pFrame.destination=dSMdSID;
544 pFrame.containerType=DS485_CONTAINER_REQUEST;
545 pFrame.deviceId=dSMdSID;
546546 pFrame.data[0]=DSMAPI_DEVICE_ACTION;
547547 setModifier(pFrame,DSMAPI_MODIFIER_UNDO_SCENE);
548548 setParameter(pFrame,1,DeviceId);
555555 uint16_t DeviceId, uint16_t OutvalIndex, uint16_t Value)
556556{
557557 dS485Container pFrame,pFrameAnswer;
558 pFrame.containerType=DSTELEGRAM_REQUEST;
559 pFrame.destination=dSMdSID;
558 pFrame.containerType=DS485_CONTAINER_REQUEST;
559 pFrame.deviceId=dSMdSID;
560560 pFrame.data[0]=DSMAPI_DEVICE_ACTION;
561561 setModifier(pFrame,DSMAPI_MODIFIER_SET_OUTVAL);
562562 setParameter(pFrame,1,DeviceId);
571571 uint16_t DeviceId, uint16_t OutvalIndex)
572572{
573573 dS485Container pFrame,pFrameAnswer;
574 pFrame.containerType=DSTELEGRAM_REQUEST;
575 pFrame.destination=dSMdSID;
574 pFrame.containerType=DS485_CONTAINER_REQUEST;
575 pFrame.deviceId=dSMdSID;
576576 pFrame.data[0]=DSMAPI_DEVICE_ACTION;
577577 setModifier(pFrame,DSMAPI_MODIFIER_INC_OUTVAL);
578578 setParameter(pFrame,1,DeviceId);
585585 uint16_t DeviceId, uint16_t OutvalIndex)
586586{
587587 dS485Container pFrame,pFrameAnswer;
588 pFrame.containerType=DSTELEGRAM_REQUEST;
589 pFrame.destination=dSMdSID;
588 pFrame.containerType=DS485_CONTAINER_REQUEST;
589 pFrame.deviceId=dSMdSID;
590590 pFrame.data[0]=DSMAPI_DEVICE_ACTION;
591591 setModifier(pFrame,DSMAPI_MODIFIER_DEC_OUTVAL);
592592 setParameter(pFrame,1,DeviceId);
599599 uint16_t DeviceId, uint16_t OutvalIndex)
600600{
601601 dS485Container pFrame,pFrameAnswer;
602 pFrame.containerType=DSTELEGRAM_REQUEST;
603 pFrame.destination=dSMdSID;
602 pFrame.containerType=DS485_CONTAINER_REQUEST;
603 pFrame.deviceId=dSMdSID;
604604 pFrame.data[0]=DSMAPI_DEVICE_ACTION;
605605 setModifier(pFrame,DSMAPI_MODIFIER_MIN_OUTVAL);
606606 setParameter(pFrame,1,DeviceId);
613613 uint16_t DeviceId, uint16_t OutvalIndex)
614614{
615615 dS485Container pFrame,pFrameAnswer;
616 pFrame.containerType=DSTELEGRAM_REQUEST;
617 pFrame.destination=dSMdSID;
616 pFrame.containerType=DS485_CONTAINER_REQUEST;
617 pFrame.deviceId=dSMdSID;
618618 pFrame.data[0]=DSMAPI_DEVICE_ACTION;
619619 setModifier(pFrame,DSMAPI_MODIFIER_MAX_OUTVAL);
620620 setParameter(pFrame,1,DeviceId);
627627 uint16_t DeviceId, uint16_t OutvalIndex)
628628{
629629 dS485Container pFrame,pFrameAnswer;
630 pFrame.containerType=DSTELEGRAM_REQUEST;
631 pFrame.destination=dSMdSID;
630 pFrame.containerType=DS485_CONTAINER_REQUEST;
631 pFrame.deviceId=dSMdSID;
632632 pFrame.data[0]=DSMAPI_DEVICE_ACTION;
633633 setModifier(pFrame,DSMAPI_MODIFIER_STOP_OUTVAL);
634634 setParameter(pFrame,1,DeviceId);
641641 uint16_t DeviceId)
642642{
643643 dS485Container pFrame,pFrameAnswer;
644 pFrame.containerType=DSTELEGRAM_REQUEST;
645 pFrame.destination=dSMdSID;
644 pFrame.containerType=DS485_CONTAINER_REQUEST;
645 pFrame.deviceId=dSMdSID;
646646 pFrame.data[0]=DSMAPI_DEVICE_ACTION;
647647 setModifier(pFrame,DSMAPI_MODIFIER_REMOVE_LOCAL_PRIO);
648648 setParameter(pFrame,1,DeviceId);
655655 uint16_t DeviceId)
656656{
657657 dS485Container pFrame,pFrameAnswer;
658 pFrame.containerType=DSTELEGRAM_REQUEST;
659 pFrame.destination=dSMdSID;
658 pFrame.containerType=DS485_CONTAINER_REQUEST;
659 pFrame.deviceId=dSMdSID;
660660 pFrame.data[0]=DSMAPI_DEVICE_ACTION;
661661 setModifier(pFrame,DSMAPI_MODIFIER_SIGNAL);
662662 setParameter(pFrame,1,DeviceId);
672672 uint32_t *Level1, uint32_t *Level2)
673673{
674674 dS485Container pFrame,pFrameAnswer;
675 pFrame.containerType=DSTELEGRAM_REQUEST;
676 pFrame.destination=dSMdSID;
675 pFrame.containerType=DS485_CONTAINER_REQUEST;
676 pFrame.deviceId=dSMdSID;
677677 pFrame.data[0]=DSMAPI_DSM_CIRCUIT_ENERGY_LEVEL;
678678 setModifier(pFrame,DSMAPI_MODIFIER_GET);
679679 setParameterCount(pFrame,0);
688688 uint32_t Level1, uint32_t Level2)
689689{
690690 dS485Container pFrame,pFrameAnswer;
691 pFrame.containerType=DSTELEGRAM_REQUEST;
692 pFrame.destination=dSMdSID;
691 pFrame.containerType=DS485_CONTAINER_REQUEST;
692 pFrame.deviceId=dSMdSID;
693693 pFrame.data[0]=DSMAPI_DSM_CIRCUIT_ENERGY_LEVEL;
694694 setModifier(pFrame,DSMAPI_MODIFIER_SET);
695695 setParameter(pFrame,1,Level1);
705705 uint32_t *PowerConsumption, uint32_t *EnergyMeterValue)
706706{
707707 dS485Container pFrame,pFrameAnswer;
708 pFrame.containerType=DSTELEGRAM_REQUEST;
709 pFrame.destination=dSMdSID;
708 pFrame.containerType=DS485_CONTAINER_REQUEST;
709 pFrame.deviceId=dSMdSID;
710710 pFrame.data[0]=DSMAPI_DSM_CIRCUIT_METERING_VALUE;
711711 setModifier(pFrame,DSMAPI_MODIFIER_GET);
712712 setParameterCount(pFrame,0);
724724{
725725
726726 dS485Container pFrame,pFrameAnswer;
727 pFrame.containerType=DSTELEGRAM_REQUEST;
728 pFrame.destination=dSMdSID;
727 pFrame.containerType=DS485_CONTAINER_REQUEST;
728 pFrame.deviceId=dSMdSID;
729729 pFrame.data[0]=DSMAPI_DSM_TIME;
730730 setModifier(pFrame,DSMAPI_MODIFIER_GET);
731731 setParameterCount(pFrame,0);
739739 uint32_t TimeValue)
740740{
741741 dS485Container pFrame,pFrameAnswer;
742 pFrame.containerType=DSTELEGRAM_REQUEST;
743 pFrame.destination=dSMdSID;
742 pFrame.containerType=DS485_CONTAINER_REQUEST;
743 pFrame.deviceId=dSMdSID;
744744 pFrame.data[0]=DSMAPI_DSM_TIME;
745745 setModifier(pFrame,DSMAPI_MODIFIER_SET);
746746 setParameter(pFrame,1,TimeValue);
755755 dsidType *dsid)
756756{
757757 dS485Container pFrame,pFrameAnswer;
758 pFrame.containerType=DSTELEGRAM_REQUEST;
759 pFrame.destination=dSMdSID;
758 pFrame.containerType=DS485_CONTAINER_REQUEST;
759 pFrame.deviceId=dSMdSID;
760760 pFrame.data[0]=DSMAPI_DSM_DSID;
761761 setModifier(pFrame,DSMAPI_MODIFIER_GET);
762762 setParameterCount(pFrame,0);
783783 uint16_t *RevHW, uint16_t *RevSW, uint16_t *FeatureFlags, uint32_t *BuildTime)
784784{
785785 dS485Container pFrame,pFrameAnswer;
786 pFrame.containerType=DSTELEGRAM_REQUEST;
787 pFrame.destination=dSMdSID;
786 pFrame.containerType=DS485_CONTAINER_REQUEST;
787 pFrame.deviceId=dSMdSID;
788788 pFrame.data[0]=DSMAPI_DSM_INFO;
789789 setModifier(pFrame,DSMAPI_MODIFIER_GET);
790790 setParameterCount(pFrame,0);
801801int MeterMaintance_StartPing(dsidType dSMdSID)
802802{
803803 dS485Container pFrame,pFrameAnswer;
804 pFrame.containerType=DSTELEGRAM_REQUEST;
805 pFrame.destination=dSMdSID;
804 pFrame.containerType=DS485_CONTAINER_REQUEST;
805 pFrame.deviceId=dSMdSID;
806806 pFrame.data[0]=DSMAPI_DSM_PING_DEVICES;
807807 setModifier(pFrame,DSMAPI_MODIFIER_GET);
808808 setParameterCount(pFrame,0);
815815int MeterMaintance_RemoveInactiveDevices(dsidType dSMdSID)
816816{
817817 dS485Container pFrame,pFrameAnswer;
818 pFrame.containerType=DSTELEGRAM_REQUEST;
819 pFrame.destination=dSMdSID;
818 pFrame.containerType=DS485_CONTAINER_REQUEST;
819 pFrame.deviceId=dSMdSID;
820820 pFrame.data[0]=DSMAPI_DSM_REMOVE_INACTIVE;
821821 setModifier(pFrame,DSMAPI_MODIFIER_GET);
822822 setParameterCount(pFrame,0);
829829int MeterRestart(dsidType dSMdSID)
830830{
831831 dS485Container pFrame,pFrameAnswer;
832 pFrame.containerType=DSTELEGRAM_REQUEST;
833 pFrame.destination=dSMdSID;
832 pFrame.containerType=DS485_CONTAINER_REQUEST;
833 pFrame.deviceId=dSMdSID;
834834 pFrame.data[0]=DSMAPI_REBOOT;
835835 setModifier(pFrame,DSMAPI_MODIFIER_GET);
836836 setParameterCount(pFrame,0);
844844 uint16_t DeviceId, uint16_t ConfigClass, uint16_t ConfigId, uint16_t Value)
845845{
846846 dS485Container pFrame,pFrameAnswer;
847 pFrame.containerType=DSTELEGRAM_REQUEST;
848 pFrame.destination=dSMdSID;
847 pFrame.containerType=DS485_CONTAINER_REQUEST;
848 pFrame.deviceId=dSMdSID;
849849 pFrame.data[0]=DSMAPI_DEVICE_CONFIG;
850850 setModifier(pFrame,DSMAPI_MODIFIER_GET);
851851 setParameter(pFrame,1,DeviceId);
863863 uint16_t *ZoneId, unsigned char *GroupMask)
864864{
865865 dS485Container pFrame,pFrameAnswer;
866 pFrame.containerType=DSTELEGRAM_REQUEST;
867 pFrame.destination=dSMdSID;
866 pFrame.containerType=DS485_CONTAINER_REQUEST;
867 pFrame.deviceId=dSMdSID;
868868 pFrame.data[0]=DSMAPI_ZONE_INFO;
869869 setModifier(pFrame,DSMAPI_MODIFIER_GET);
870870 setParameter(pFrame,1,ZoneIndex);
883883{
884884 dS485Container pFrame,pFrameAnswer;
885885
886 pFrame.containerType=DSTELEGRAM_REQUEST;
887 pFrame.destination=dSMdSID;
886 pFrame.containerType=DS485_CONTAINER_REQUEST;
887 pFrame.deviceId=dSMdSID;
888888 pFrame.data[0]=DSMAPI_DEVICE_DSID;
889889 setModifier(pFrame,DSMAPI_MODIFIER_GET);
890890 setParameter(pFrame,1,DeviceId);
911911{
912912 dS485Container pFrame,pFrameAnswer;
913913
914 pFrame.containerType=DSTELEGRAM_REQUEST;
915 pFrame.destination=dSMdSID;
914 pFrame.containerType=DS485_CONTAINER_REQUEST;
915 pFrame.deviceId=dSMdSID;
916916 pFrame.data[0]=DSMAPI_DEVICE_GROUPS;
917917 setModifier(pFrame,DSMAPI_MODIFIER_GET);
918918 setParameter(pFrame,1,DeviceId);
937937 uint16_t *TargetGroup, uint16_t *PingCounter, uint16_t *StatusFlags, uint16_t *ProductId, uint16_t *RevisionsId)
938938{
939939 dS485Container pFrame,pFrameAnswer;
940 pFrame.containerType=DSTELEGRAM_REQUEST;
941 pFrame.destination=dSMdSID;
940 pFrame.containerType=DS485_CONTAINER_REQUEST;
941 pFrame.deviceId=dSMdSID;
942942 pFrame.data[0]=DSMAPI_DEVICE_INFO;
943943 setModifier(pFrame,DSMAPI_MODIFIER_ONLY_ACTIVE);
944944 setParameter(pFrame,1,ZoneId);
965965 uint16_t *TargetGroup, uint16_t *PingCounter, uint16_t *StatusFlags, uint16_t *ProductId, uint16_t *RevisionsId)
966966{
967967 dS485Container pFrame,pFrameAnswer;
968 pFrame.containerType=DSTELEGRAM_REQUEST;
969 pFrame.destination=dSMdSID;
968 pFrame.containerType=DS485_CONTAINER_REQUEST;
969 pFrame.deviceId=dSMdSID;
970970 pFrame.data[0]=DSMAPI_DEVICE_INFO;
971971 setModifier(pFrame,DSMAPI_MODIFIER_ONLY_INACTIVE);
972972 setParameter(pFrame,1,ZoneId);
core/ds485-socket/ds485c.h
(37 / 18)
  
11#ifndef DS485C_H_
22#define DS485C_H_
33
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
4#ifdef __cplusplus
5extern "C" {
6#endif
7
78/**
89 * 96-Bit dSID
910 */
1212 unsigned char value[12];
1313} dsidType;
1414
15
15#if 0
16#define compareDSID(oDSID1,oDSID2) (oDSID1.value == oDSID2.value)
17#else
1618#define compareDSID(oDSID1,oDSID2) ((oDSID1.value[0]==oDSID2.value[0]) && \
1719 (oDSID1.value[1]==oDSID2.value[1]) && \
1820 (oDSID1.value[2]==oDSID2.value[2]) && \
2727 (oDSID1.value[9]==oDSID2.value[9]) && \
2828 (oDSID1.value[10]==oDSID2.value[10]) && \
2929 (oDSID1.value[11]==oDSID2.value[11]))
30#endif
3031
3132/**
3233 * Status des dS485 Bus
3334 */
3435typedef enum {
35 DSBUS_ISOLATED,
36 DSBUS_INACTIVE,
37 DSBUS_ACTIVE
36 DSBUS_ISOLATED,
37 DSBUS_INACTIVE,
38 DSBUS_ACTIVE
3839} BusState_t;
3940
4041/**
41 * Typ des dS485Packets
42 * Typ des Pakets
4243 */
4344typedef enum {
44 DSTELEGRAM_REQUEST,
45 DSTELEGRAM_RESPONSE,
46 DSTELEGRAM_EVENT
47} ContainerType_t;
45 DS485_CONTAINER_REQUEST = 1,
46 DS485_CONTAINER_RESPONSE,
47 DS485_CONTAINER_EVENT
48} dS485ContainerType_t;
4849
4950/**
51 * Flags für das Packet
52 */
53typedef enum {
54 DS485_FLAG_NONE = 0,
55 DS485_FLAG_BROADCAST = 1,
56} dS485ContainerFlags_t;
57
58/**
5059 * dS485 API Daten Container
5160 */
61#define DS485_CONTAINER_DATA_LENGTH 128
62#define DS485_CONTAINER_SIZE (sizeof(struct _dS485Container) - DS485_CONTAINER_DATA_LENGTH)
63
5264typedef struct _dS485Container {
5365
54 dsidType destination;
55 ContainerType_t containerType;
56 unsigned int length;
57 unsigned char data[128];
58} dS485Container;
66 dsidType deviceId;
67 unsigned char deviceAddress;
68 unsigned char containerType;
69 unsigned char containerFlags;
70 unsigned char length;
71 unsigned char data[DS485_CONTAINER_DATA_LENGTH];
5972
73} __attribute__ ((packed)) dS485Container;
74
75
6076/**
6177 * Callback Methoden
6278 */
144144extern int ds485_get_dsid_state(dsidType dSID);
145145
146146#ifdef __cplusplus
147 }
147}
148148#endif
149149
150150
core/sim/dssim.cpp
(7 / 7)
  
10751075 } // distributeFrame
10761076
10771077 void DSDSMeterSim::dSLinkInterrupt(devid_t _shortAddress) const {
1078 dS485Container result;
1079 result.destination=dSIDBroadcast;
1080 setParaCount(result,2);
1081 result.containerType=DSTELEGRAM_EVENT;
1082 result.data[0]=EventDSLinkInterrupt;
1083 setPara(result,1,_shortAddress);
1084 setPara(result,2,0);
1078 dS485Container result;
1079 result.deviceId = dSIDBroadcast;
1080 setParaCount(result,2);
1081 result.containerType = DS485_CONTAINER_EVENT;
1082 result.data[0] = EventDSLinkInterrupt;
1083 setPara(result,1,_shortAddress);
1084 setPara(result,2,0);
10851085 distributeFrame(result);
10861086 } // dSLinkInterrupt
10871087