summaryrefslogtreecommitdiff
path: root/source/CEH/ZRpcInterface.cpp
blob: ea0c82a27be0bae4be4b2dab9db7414f912886e8 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*******************************************************************************
 * Copyright (C) ST-Ericsson SA 2011
 * License terms: 3-clause BSD license
 ******************************************************************************/

#include "ZRpcInterface.h"

ZRpcInterface::ZRpcInterface(CmdResult *CmdResult, LcmInterface *LcmInterface)
{
    Z_Payload = 0;
    Z_Payload_SetBaudrate = 0;
    cmdResult_ = CmdResult;
    lcmInterface_ = LcmInterface;

    Z_IndataBuffer = new LockLessQueue(10);
}

ZRpcInterface::~ZRpcInterface()
{
    delete Z_IndataBuffer;
    delete[] Z_Payload;
    delete[] Z_Payload_SetBaudrate;
}

ErrorCode_e ZRpcInterface::Do_CEH_Callback(CommandData_t *CmdData_p)
{
    ErrorCode_e Status = E_GENERAL_FATAL_ERROR;

    Status = DoneRPC_Z_ReadImpl(*CmdData_p);

    return Status;
}

ErrorCode_e ZRpcInterface::DoRPC_Z_VersionRequest()
{
    ErrorCode_e Result = E_SUCCESS;

    if (Z_Payload != 0) {
        delete [] Z_Payload;
        Z_Payload = 0;
    }

    Z_Payload = new uint8[2];
    Z_Payload[0] = 0x01;
    Z_Payload[1] = 0x3F;

    Result = lcmInterface_->CommunicationSend(Z_Payload);

    return Result;
}

ErrorCode_e ZRpcInterface::DoRPC_Z_SetBaudrate(int Baudrate)
{
    ErrorCode_e Result = E_SUCCESS;
    char Rate;

    switch (Baudrate) {
    case 9600:
        Rate = '0';
        break;

    case 19200:
        Rate = '1';
        break;

    case 38400:
        Rate = '2';
        break;

    case 57600:
        Rate = '3';
        break;

    case 115200:
        Rate = '4';
        break;

    case 230400:
        Rate = '5';
        break;

    case 460800:
        Rate = '6';
        break;

    case 921600:
        Rate = '7';
        break;

    case 1625000:
        Rate = '8';
        break;

    default :
        return E_INVALID_INPUT_PARAMETERS;
    }

    if (Z_Payload != 0) {
        delete [] Z_Payload;
        Z_Payload = 0;
    }

    Z_Payload = new uint8[2];

    Z_Payload[0] = 0x01;
    Z_Payload[1] = 'S';

    Result = lcmInterface_->CommunicationSend(Z_Payload);

    Z_Payload_SetBaudrate = new uint8[2];
    Z_Payload_SetBaudrate[0] = 0x01;
    Z_Payload_SetBaudrate[1] = Rate;

    Result = lcmInterface_->CommunicationSend(Z_Payload_SetBaudrate);

    return Result;
}

ErrorCode_e ZRpcInterface::DoRPC_Z_Exit_Z_Protocol()
{
    ErrorCode_e Result = E_SUCCESS;

    if (Z_Payload != 0) {
        delete [] Z_Payload;
        Z_Payload = 0;
    }

    Z_Payload = new uint8[2];
    Z_Payload[0] = 0x01;
    Z_Payload[1] = 'Q';

    Result = lcmInterface_->CommunicationSend(Z_Payload);

    return Result;
}

ErrorCode_e ZRpcInterface::DoneRPC_Z_ReadImpl(CommandData_t CmdData)
{
    unsigned char Data_p = *CmdData.Payload.Data_p;
    bool Full = false;

    Z_IndataBuffer->Push(Data_p, &Full);

    if (Full == true) {
        return E_GENERAL_FATAL_ERROR;
    }

    return E_SUCCESS;
}