1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2020] [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 interfaces to raise and clear alarms */
21 #include "AlarmInterface.h"
22 #include "TcpClient.h"
25 /*******************************************************************
27 * @brief Raise an alarm
31 * Function : raiseAlarm
34 * - Raise an alarm by sending alarm info to O1 module over
35 * TCP socket with action set to RAISE
37 * @params[in] alarm information
38 * @return ROK - success
40 ******************************************************************/
41 uint8_t raiseAlarm(AlarmRecord* alrm)
43 if (openSocket(TCP_SERVER_IP,TCP_PORT) == RFAILED)
47 alrm->msgHeader.msgType = ALARM;
48 alrm->msgHeader.action = RAISE_ALARM;
49 if (sendData(alrm,sizeof(AlarmRecord)) < 0 )
58 /*******************************************************************
60 * @brief Clear an alarm
64 * Function : clearAlarm
67 * - Clears an alarm raised earlier by sending the alrm
68 * information to O1 module over TCP socket with action
71 * @params[in] alarm information
72 * @return ROK - success
74 ******************************************************************/
75 uint8_t clearAlarm(AlarmRecord* alrm)
77 if (openSocket(TCP_SERVER_IP,TCP_PORT) == RFAILED)
81 alrm->msgHeader.msgType = ALARM;
82 alrm->msgHeader.action = CLEAR_ALARM;
83 if (sendData(alrm,sizeof(AlarmRecord)) < 0)
93 /*******************************************************************
95 * @brief Raise a cell specific alarm
99 * Function : raiseCellAlrm
102 * - Fills the cell specific alarm parmeters and generate
105 * @params[in] alarm Id, cell Id
106 * @return ROK - success
108 ******************************************************************/
109 uint8_t raiseCellAlrm(uint16_t alrmId, uint16_t cellId)
111 char buff[BUFF_SIZE];
112 time_t now = time(NULL);
115 alrm.eventType = COMMUNICATIONS_ALARM;
116 snprintf (alrm.alarmId, sizeof(alrm.alarmId), "%d",alrmId);
117 alrm.perceivedSeverity = INDETERMINATE;
119 strftime(buff, BUFF_SIZE, "%Y-%m-%d %H:%M:%S", localtime(&now));
120 if(CELL_UP_ALARM_ID == alrmId)
122 /* Fill cell up parameters */
123 snprintf (alrm.additionalText, sizeof(alrm.additionalText), \
124 "cell id [%d] is up",cellId);
125 strcpy(alrm.additionalInfo , "cell UP");
126 strcpy(alrm.specificProblem, "Active");
127 strcpy(alrm.alarmRaiseTime, buff);
131 /* Clear the cell up alarm */
132 clearCellAlrm(CELL_UP_ALARM_ID);
133 /* Fill the cell down parameters */
134 snprintf (alrm.additionalText, sizeof(alrm.additionalText), \
135 "cell [%d] is down",cellId);
136 strcpy(alrm.additionalInfo , "cell down");
137 strcpy(alrm.specificProblem, "Active");
138 strcpy(alrm.alarmRaiseTime, buff);
141 return raiseAlarm(&alrm);
144 /*******************************************************************
146 * @brief Clear the cell alarm
150 * Function : clearCellAlrm
153 * - Clears the cell specific alarm using alarm id
155 * @params[in] alarm Id
156 * @return ROK - success
158 ******************************************************************/
159 uint8_t clearCellAlrm(uint16_t alrmId)
162 snprintf (alrm.alarmId, sizeof(alrm.alarmId), "%d",alrmId);
163 return clearAlarm(&alrm);
167 /**********************************************************************
169 **********************************************************************/