22 #include <sys/socket.h>
23 #include <arpa/inet.h>
26 #include <sys/types.h>
28 #include "mocaSrvMgr.h"
30 #include "NetworkMgrMain.h"
31 #include "NetworkMedium.h"
35 bool mocaLogEnable=
true;
36 unsigned int mocaLogDuration=3600;
40 bool MocaNetworkMgr::instanceIsReady =
false;
44 MocaNetworkMgr::MocaNetworkMgr() {}
45 MocaNetworkMgr::~MocaNetworkMgr() { }
53 instanceIsReady =
true;
59 int MocaNetworkMgr::Start()
66 IARM_Bus_RegisterCall(IARM_BUS_NETWORK_MANAGER_MOCA_getTelemetryLogDuration, mocaTelemetryLogDuration);
72 void *mocaTelemetryThrd(
void* arg)
77 MocaNetworkMgr::printMocaTelemetry();
81 MocaNetworkMgr::printMocaTelemetry();
82 sleep(mocaLogDuration);
95 pthread_attr_init(&attr);
96 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
101 void MocaNetworkMgr::printMocaTelemetry()
104 RMH_LinkStatus status;
105 unsigned int ncNodeID;
108 RMH_MoCAVersion mocaVersion;
109 unsigned int totalMoCANode;
110 unsigned int count=0;
111 unsigned int selfNodeId;
113 static char bFirst=1;
115 GString *resString=g_string_new(NULL);
118 LOG_ERR(
"Failed calling RMH_Self_GetLinkStatus!");
120 else if(status == RMH_LINK_STATUS_UP)
122 LOG_INFO(
"TELEMETRY_MOCA_STATUS:UP");
125 LOG_INFO(
"TELEMETRY_MOCA_LINK_STATUS_CHANGED:%d",status);
129 LOG_ERR(
"Failed calling RMH_Network_GetMoCAVersion!");
136 LOG_ERR(
"Failed calling RMH_Network_GetNCNodeId!");
139 LOG_INFO(
"TELEMETRY_MOCA_NC_NODEID:%d",ncNodeID);
142 LOG_ERR(
"Failed calling RMH_Network_GetNCMacString!");
149 LOG_ERR(
"Failed calling RMH_Network_GetNumNodes!");
152 LOG_INFO(
"TELEMETRY_MOCA_TOTAL_NODE:%d",totalMoCANode);
156 LOG_ERR(
"Failed calling RMH_Network_GetNodeId!");
158 LOG_ERR(
"Failed calling RMH_Network_GetAssociatedIds!");
160 g_string_assign(resString,
"");
161 for (i = 0; i < RMH_MAX_MOCA_NODES; i++) {
162 if (nodeList.nodePresent[i]) {
165 LOG_ERR(
"Failed calling RemoteNode_GetRxUnicastPhyRate!");
168 LOG_INFO(
"TELEMETRY_MOCA_PHYRXRATE_%d_%d:%d", selfNodeId, i, phyRate);
169 g_string_append_printf(resString,
"%d,",phyRate);
173 if (resString->len > 0) {
174 g_string_truncate(resString, resString->len-1);
175 LOG_INFO(
"TELEMETRY_MOCA_PHY_RX_RATE:%s", resString->str);
176 g_string_assign(resString,
"");
179 for (i = 0; i < RMH_MAX_MOCA_NODES; i++) {
180 if (nodeList.nodePresent[i]) {
183 LOG_ERR(
"Failed calling RMH_RemoteNode_GetTxUnicastPhyRate!");
186 LOG_INFO(
"TELEMETRY_MOCA_PHYTXRATE_%d_%d:%d", selfNodeId, i, phyRate);
187 g_string_append_printf(resString,
"%d,",phyRate);
191 if (resString->len > 0) {
192 g_string_truncate(resString, resString->len-1);
193 LOG_INFO(
"TELEMETRY_MOCA_PHY_TX_RATE:%s", resString->str);
194 g_string_assign(resString,
"");
197 for (i = 0; i < RMH_MAX_MOCA_NODES; i++) {
198 if (nodeList.nodePresent[i]) {
201 LOG_ERR(
"Failed calling RemoteNode_GetRxUnicastPower!");
204 LOG_INFO(
"TELEMETRY_MOCA_RXPOWER_%d_%d:%2.02f", selfNodeId, i, power);
205 g_string_append_printf(resString,
"%2.02f,",power);
209 if (resString->len > 0) {
210 g_string_truncate(resString, resString->len-1);
211 LOG_INFO(
"TELEMETRY_MOCA_RX_POWER:%s", resString->str);
212 g_string_assign(resString,
"");
215 g_string_assign(resString,
"");
216 for (i = 0; i < RMH_MAX_MOCA_NODES; i++) {
217 if (nodeList.nodePresent[i]) {
218 uint32_t powerReduction;
220 LOG_ERR(
"Failed calling RMH_RemoteNode_GetTxPowerReduction!");
223 LOG_INFO(
"TELEMETRY_MOCA_TXPOWERREDUCTION_%d_%d:%d", selfNodeId, i, powerReduction);
224 g_string_append_printf(resString,
"%d,",powerReduction);
228 if (resString->len > 0) {
229 g_string_truncate(resString, resString->len-1);
230 LOG_INFO(
"TELEMETRY_MOCA_TX_POWER_REDUCTION:%s", resString->str);
231 g_string_assign(resString,
"");
235 if (selfNodeId == ncNodeID )
237 LOG_INFO(
"TELEMETRY_MOCA_IS_CURRENT_NODE_NC:1");
241 LOG_INFO(
"TELEMETRY_MOCA_IS_CURRENT_NODE_NC:0");
247 LOG_INFO(
"TELEMETRY_MOCA_STATUS:DOWN");
250 g_string_free(resString,
TRUE);
253 static void _mocaEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
256 if (strcmp(owner, IARM_BUS_NM_SRV_MGR_NAME) == 0) {
258 case IARM_BUS_NETWORK_MANAGER_MOCA_TELEMETRY_LOG:
260 bool *param = (
bool *)data;
261 mocaLogEnable=*param;
262 LOG_INFO(
"got event IARM_BUS_NETWORK_MANAGER_MOCA_TELEMETRY_LOG %d", mocaLogEnable);
265 case IARM_BUS_NETWORK_MANAGER_MOCA_TELEMETRY_LOG_DURATION:
267 unsigned int *param = (
unsigned int *)data;
268 mocaLogDuration=*param;
269 LOG_INFO(
"got event IARM_BUS_NETWORK_MANAGER_MOCA_TELEMETRY_LOG_DURATION %d", mocaLogDuration);
278 IARM_Result_t MocaNetworkMgr::mocaTelemetryLogEnable(
void *arg)
281 IARM_Result_t ret = IARM_RESULT_SUCCESS;
282 bool *param = (
bool *)arg;
283 *param=mocaLogEnable;
284 LOG_INFO(
"get event to get status of telemetry log enable %d", mocaLogEnable);
288 IARM_Result_t MocaNetworkMgr::mocaTelemetryLogDuration(
void *arg)
291 IARM_Result_t ret = IARM_RESULT_SUCCESS;
292 unsigned int *param = (
unsigned int *)arg;
293 *param=mocaLogDuration;
294 LOG_INFO(
"get venent to get the moca log duration set %d", mocaLogDuration);
298 static void eventCallback(
const enum RMH_Event event,
const struct RMH_EventData *eventData,
void* userContext) {
300 case RMH_EVENT_LINK_STATUS_CHANGED:
301 LOG_INFO(
"MoCA Link status changed to %d", eventData->RMH_EVENT_LINK_STATUS_CHANGED.status );
302 LOG_INFO(
"TELEMETRY_MOCA_LINK_STATUS_CHANGED:%d", eventData->RMH_EVENT_LINK_STATUS_CHANGED.status);
304 case RMH_EVENT_MOCA_VERSION_CHANGED:
309 LOG_ERR(
"MoCA Event Not Supported");