1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2020-2021] [HCL Technologies Ltd.] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /* This file contains C interfaces for ODU to raise and clear alarms */
23 #include "GlobalDefs.hpp"
24 #include "AlarmInterface.h"
25 #include "UnixSocketClient.hpp"
27 /*******************************************************************
29 * @brief Raise an alarm
33 * Function : raiseAlarm
36 * - Raise an alarm by sending alarm info to O1 module over
37 * Unix socket with action set to RAISE
39 * @params[in] alarm information
40 * @return O1::SUCCESS - success
41 * O1::FAILURE - failure
42 ******************************************************************/
43 uint8_t raiseAlarm(AlarmRecord* alrm)
46 UnixSocketClient uxClient(O1::ALARM_SOCK_PATH);
47 if (uxClient.openSocket() == O1::FAILURE)
51 alrm->msgHeader.msgType = ALARM;
52 alrm->msgHeader.action = RAISE_ALARM;
53 if (uxClient.sendData(alrm,sizeof(AlarmRecord)) < 0 )
55 uxClient.closeSocket();
58 uxClient.closeSocket();
62 /*******************************************************************
64 * @brief Clear an alarm
68 * Function : clearAlarm
71 * - Clears an alarm raised earlier by sending the alrm
72 * information to O1 module over Unix socket with action
75 * @params[in] alarm information
76 * @return O1::SUCCESS - success
77 * O1::FAILURE - failure
78 ******************************************************************/
79 uint8_t clearAlarm(AlarmRecord* alrm)
81 UnixSocketClient uxClient(O1::ALARM_SOCK_PATH);
82 if (uxClient.openSocket() == O1::FAILURE)
86 alrm->msgHeader.msgType = ALARM;
87 alrm->msgHeader.action = CLEAR_ALARM;
88 if (uxClient.sendData(alrm,sizeof(AlarmRecord)) < 0)
90 uxClient.closeSocket();
93 uxClient.closeSocket();
98 /*******************************************************************
100 * @brief Raise a cell specific alarm
104 * Function : raiseCellAlrm
107 * - Fills the cell specific alarm parmeters and generate
110 * @params[in] alarm Id, cell Id
111 * @return O1::SUCCESS - success
112 * O1::FAILURE - failure
113 ******************************************************************/
114 uint8_t raiseCellAlrm(uint16_t alrmId, uint16_t cellId)
116 char buff[BUFF_SIZE];
117 time_t now = time(NULL);
120 alrm.eventType = COMMUNICATIONS_ALARM;
121 snprintf (alrm.alarmId, sizeof(alrm.alarmId), "%d",alrmId);
122 alrm.perceivedSeverity = INDETERMINATE;
124 strftime(buff, BUFF_SIZE, "%Y-%m-%d %H:%M:%S", localtime(&now));
125 if(CELL_UP_ALARM_ID == alrmId)
127 /* Fill cell up parameters */
128 snprintf (alrm.additionalText, sizeof(alrm.additionalText), \
129 "CELL %d UP",cellId);
130 strcpy(alrm.additionalInfo , "CELL UP");
131 strcpy(alrm.specificProblem, "Active");
132 strcpy(alrm.alarmRaiseTime, buff);
136 /* Clear the cell up alarm */
137 clearCellAlrm(CELL_UP_ALARM_ID);
138 /* Fill the cell down parameters */
139 snprintf (alrm.additionalText, sizeof(alrm.additionalText), \
140 "CELL %d DOWN",cellId);
141 strcpy(alrm.additionalInfo , "CELL DOWN");
142 strcpy(alrm.specificProblem, "Active");
143 strcpy(alrm.alarmRaiseTime, buff);
146 return raiseAlarm(&alrm);
149 /*******************************************************************
151 * @brief Clear the cell alarm
155 * Function : clearCellAlrm
158 * - Clears the cell specific alarm using alarm id
160 * @params[in] alarm Id
161 * @return O1::SUCCESS - success
162 * O1::FAILURE - failure
163 ******************************************************************/
164 uint8_t clearCellAlrm(uint16_t alrmId)
167 snprintf (alrm.alarmId, sizeof(alrm.alarmId), "%d",alrmId);
168 return clearAlarm(&alrm);
172 /**********************************************************************
174 **********************************************************************/