summaryrefslogtreecommitdiffstats
path: root/Src/Network/IndustrialStack_ApiGeneric.h
blob: 730f157699035a89320de3306c5c2639de38eb30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * Video On Demand Samples
 *
 * Copyright (C) 2015 Microchip Technology Germany II GmbH & Co. KG
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * You may also obtain this software under a propriety license from Microchip.
 * Please contact Microchip for further information.
 *
 */

/*----------------------------------------------------------*/
/*! \file
 *  \brief  This file contains the CIndustrialStack class (Generic commands).
 */
/*----------------------------------------------------------*/

#ifndef INDUSTRIAL_STACK_API_GENERIC_H
#define INDUSTRIAL_STACK_API_GENERIC_H

#include "IndustrialStack.h"
#include "Network.h"
#include "Types.h"

class CGeneric_SendConfigOk : public CISSendMostMsgElement
{
public:
    CGeneric_SendConfigOk(bool isOkay)
    {
        ElementName = "CGeneric_SendConfigOk";
        
        Request.IsValid = true;
        Request.SourceAddress = 0x2;
        Request.TargetAddress = 0x3C8;
        Request.FBlock = 0x2;
        Request.Func = 0xA00;
        Request.Inst = 0x00;
        Request.OpType = CISOpType_STATUS;
        Request.PayloadLen = 1;
        Request.Payload[0] = isOkay;
    }
};

class CGeneric_GetMacAddress : public CISSendMostMsgElement
{
public:
    CGeneric_GetMacAddress(uint16_t nodeAddress)
    {
        ElementName = "CGeneric_GetMacAddress";
        
        Request.IsValid = true;
        Request.SourceAddress = 0x2;
        Request.TargetAddress = nodeAddress;
        Request.FBlock = 0x1;
        Request.Func = 0x013;
        Request.Inst = 0x00;
        Request.OpType = CISOpType_GET;
        Request.PayloadLen = 0;
    }
};

class CGeneric_GetGroupAddress : public CISSendMostMsgElement
{
public:
    CGeneric_GetGroupAddress(uint16_t nodeAddress)
    {
        ElementName = "CGeneric_GetGroupAddress";
        
        Request.IsValid = true;
        Request.SourceAddress = 0x2;
        Request.TargetAddress = nodeAddress;
        Request.FBlock = 0x1;
        Request.Func = 0x004;
        Request.Inst = 0x00;
        Request.OpType = CISOpType_GET;
        Request.PayloadLen = 0;
    }
};

class CGeneric_SendMostMessage : public CISSendMostMsgElement
{
public:
    CGeneric_SendMostMessage(const uint8_t *pPayload, uint32_t payloadLength,
        uint16_t nodeAddress, uint8_t fblockId, uint8_t instanceId, 
        uint16_t functionId, uint8_t opTypeRequest, uint8_t opTypeResponse) 
    {
        if (payloadLength > sizeof(Request.Payload))
        {
            ConsolePrintf(PRIO_ERROR, RED"CGeneric_SendMostMessage was called"\
                " with to big payload size"RESETCOLOR"\n");
            payloadLength = sizeof(Request.Payload);
        }
        ElementName = "CGeneric_SendMostMessage";
        
        Request.IsValid = true;
        Request.SourceAddress = 0x2;
        Request.TargetAddress = nodeAddress;
        Request.FBlock = fblockId;
        Request.Func = functionId;
        Request.Inst = instanceId;
        Request.OpType = (CISOpType_t)opTypeRequest;
        Request.PayloadLen = payloadLength;
        if (0 != payloadLength)
            memcpy(Request.Payload, pPayload, payloadLength);
        if( 0xFF != opTypeResponse )
        {
            WaitForResponse = true;
            WaitForResponseOpType = (CISOpType_t)opTypeResponse;
        }
    }
};

#endif //INDUSTRIAL_STACK_API_GENERIC_H