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 /**********************************************************************
26 Description : Raise an alarm by sending alarm info to O1 module over
27 TCP socket with action set to RAISE
28 Params[In] : Alarm information
29 Return : ROK - success
31 **********************************************************************/
32 uint8_t raiseAlarm(AlarmRecord* alrm)
34 if (openSocket(TCP_SERVER_IP,TCP_PORT) == RFAILED)
38 alrm->msgHeader.action = RAISE;
39 if (sendData(alrm,sizeof(AlarmRecord)) < 0 )
48 /**********************************************************************
49 Description : Clears an alarm raised earlier by sending the alrm
50 information to O1 module over TCP socket with action
52 Params[In] : Alarm information
53 Return : ROK - success
55 **********************************************************************/
56 uint8_t clearAlarm(AlarmRecord* alrm)
58 if (openSocket(TCP_SERVER_IP,TCP_PORT) == RFAILED)
62 alrm->msgHeader.action = CLEAR;
63 if (sendData(alrm,sizeof(AlarmRecord)) < 0)
73 /**********************************************************************
74 Description : Fill the cell specific alarm parmeters and generate
76 Params[In] : alarm Id, cell Id
77 Return : ROK - success
79 **********************************************************************/
80 uint8_t raiseCellAlrm(uint16_t alrmId, uint16_t cellId)
83 time_t now = time(NULL);
86 alrm.eventType = COMMUNICATIONS_ALARM;
87 snprintf (alrm.alarmId, sizeof(alrm.alarmId), "%d",alrmId);
88 alrm.perceivedSeverity = INDETERMINATE;
90 strftime(buff, BUFF_SIZE, "%Y-%m-%d %H:%M:%S", localtime(&now));
91 if(CELL_UP_ALARM_ID == alrmId)
93 /* Fill cell up parameters */
94 snprintf (alrm.additionalText, sizeof(alrm.additionalText), \
95 "cell id [%d] is up",cellId);
96 strcpy(alrm.additionalInfo , "cell UP");
97 strcpy(alrm.specificProblem, "Active");
98 strcpy(alrm.alarmRaiseTime, buff);
102 /* Clear the cell up alarm */
103 clearCellAlrm(CELL_UP_ALARM_ID);
104 /* Fill the cell down parameters */
105 snprintf (alrm.additionalText, sizeof(alrm.additionalText), \
106 "cell [%d] is down",cellId);
107 strcpy(alrm.additionalInfo , "cell down");
108 strcpy(alrm.specificProblem, "Active");
109 strcpy(alrm.alarmRaiseTime, buff);
112 return raiseAlarm(&alrm);
115 /**********************************************************************
116 Description : Clear the cell alarm
117 Params[In] : alarm Id
118 Return : ROK - success
120 **********************************************************************/
121 uint8_t clearCellAlrm(uint16_t alrmId)
124 snprintf (alrm.alarmId, sizeof(alrm.alarmId), "%d",alrmId);
125 return clearAlarm(&alrm);
129 /**********************************************************************
131 **********************************************************************/