29 #include <uuid/uuid.h>
35 #include <sys/syscall.h>
56 #include "trm/MessageProcessor.h"
57 #include "trm/Activity.h"
58 #include "trm/JsonEncoder.h"
59 #include "trm/JsonDecoder.h"
61 #include "trm/Klass.h"
62 #include "trm/TunerReservation.h"
63 #include "trm/TunerReservation.h"
67 static void getDiagParameter(
int type);
68 static void processBuffer(
const char* buf,
int len);
71 #define __TIMESTAMP() do { \
73 struct timeval __tv; \
74 gettimeofday(&__tv, NULL); \
75 localtime_r(&__tv.tv_sec, &__tm); \
76 printf("\r\n[tid=%ld]:TestDiag %02d%02d%02d-%02d:%02d:%02d:%06d ", \
77 syscall(SYS_gettid), \
78 __tm.tm_year+1900-2000, \
88 int main(
int argc,
char *argv[])
92 printf(
"%s : <Type - 0 - TRM Version | 1 - IN BAND TUNER | 2 - Device ID | 3 TUNER_RESERVATION | \r\n 4-CONNECTION_ERRORS | 5-TUNER_CONFLICTS \r\n", argv[0]);
96 int type = atoi((
const char *)argv[1]);
98 if (type >= TRMMgr_MSG_TYPE_MAX)
100 printf(
"%s : <Type - 0 - TRM Version | 1 - IN BAND TUNER | 2 - Device ID | 3 TUNER_RESERVATION | \r\n 4-CONNECTION_ERRORS | 5-TUNER_CONFLICTS \r\n", argv[0]);
105 printf(
"Enter %s():%d \n" , __FUNCTION__, __LINE__);
111 getDiagParameter(type);
121 static void getDiagParameter(
int type)
125 __TIMESTAMP();printf(
"Enter %s():%d \n" , __FUNCTION__, __LINE__);
127 memset(&infoParam, 0,
sizeof(infoParam));
132 case TRMMgr_MSG_TYPE_GET_TRM_VERSION:
134 __TIMESTAMP();printf(
"%s : Get Diag Info for GET_TRM_VERSION \r\n",__FUNCTION__);
136 infoParam.retCode = TRMMgr_ERR_UNKNOWN;
137 infoParam.bufLen = 0;
138 infoParam.msgType = TRMMgr_MSG_TYPE_GET_TRM_VERSION;
141 (
char *)IARM_BUS_TRMMGR_API_GetTRMDiagInfo,
145 if (infoParam.retCode == TRMMgr_ERR_NONE)
147 __TIMESTAMP();printf(
"%s() Get Diag Info Return Sucess for GET_TRM_VERSION \r\n",__FUNCTION__);
148 processBuffer(&(infoParam.buf[0]),infoParam.bufLen);
155 case TRMMgr_MSG_TYPE_GET_NUM_IN_BAND_TUNERS:
157 __TIMESTAMP();printf(
"%s : Get Diag Info for GET_NUM_IN_BAND_TUNERS \r\n",__FUNCTION__);
159 infoParam.retCode = TRMMgr_ERR_UNKNOWN;
160 infoParam.bufLen = 0;
161 infoParam.numOfTuner = 0;
162 infoParam.msgType = TRMMgr_MSG_TYPE_GET_NUM_IN_BAND_TUNERS;
165 (
char *)IARM_BUS_TRMMGR_API_GetTRMDiagInfo,
169 if (infoParam.retCode == TRMMgr_ERR_NONE)
171 __TIMESTAMP();printf(
"%s() Get Diag Info Return Sucess for GET_NUM_IN_BAND_TUNERS \r\n",__FUNCTION__);
173 __TIMESTAMP();printf(
"%s : Num of Tuner Supported = %d \r\n",__FUNCTION__,infoParam.numOfTuner);
179 case TRMMgr_MSG_TYPE_GET_CONN_DEVICE_IDS:
181 __TIMESTAMP();printf(
"%s() Get Diag Info for GET_CONN_DEVICE_IDS \r\n",__FUNCTION__);
183 infoParam.retCode = TRMMgr_ERR_UNKNOWN;
184 infoParam.bufLen = 0;
185 infoParam.msgType = TRMMgr_MSG_TYPE_GET_CONN_DEVICE_IDS;
188 (
char *)IARM_BUS_TRMMGR_API_GetTRMDiagInfo,
192 if (infoParam.retCode == TRMMgr_ERR_NONE)
194 __TIMESTAMP();printf(
"%s() Get Diag Info Return Sucess for GET_CONN_DEVICE_IDS \r\n",__FUNCTION__);
195 processBuffer(&(infoParam.buf[0]),infoParam.bufLen);
200 case TRMMgr_MSG_TYPE_GET_TUNER_RESERVATION:
202 __TIMESTAMP();printf(
"%s : Get Diag Info for GET_TUNER_RESERVATION \r\n",__FUNCTION__);
204 infoParam.retCode = TRMMgr_ERR_UNKNOWN;
205 infoParam.bufLen = 0;
206 infoParam.msgType = TRMMgr_MSG_TYPE_GET_TUNER_RESERVATION;
209 (
char *)IARM_BUS_TRMMGR_API_GetTRMDiagInfo,
213 if (infoParam.retCode == TRMMgr_ERR_NONE)
215 __TIMESTAMP();printf(
"%s() Get Diag Info Return Sucess for GET_TUNER_RESERVATION \r\n",__FUNCTION__);
216 processBuffer(&(infoParam.buf[0]),infoParam.bufLen);
223 case TRMMgr_MSG_TYPE_GET_NUM_TRM_ERRORS:
225 __TIMESTAMP();printf(
"%s : Get Diag Info for GET_NUM_TRM_ERRORS \r\n",__FUNCTION__);
227 infoParam.retCode = TRMMgr_ERR_UNKNOWN;
228 infoParam.bufLen = 0;
229 infoParam.numOfTRMError = 0;
230 infoParam.msgType = TRMMgr_MSG_TYPE_GET_NUM_TRM_ERRORS;
233 (
char *)IARM_BUS_TRMMGR_API_GetTRMDiagInfo,
237 if (infoParam.retCode == TRMMgr_ERR_NONE)
239 __TIMESTAMP();printf(
"%s() Get Diag Info Return Sucess for GET_NUM_TRM_ERRORS \r\n",__FUNCTION__);
240 __TIMESTAMP();printf(
"%s : Num of TRM Errors = %d \r\n",__FUNCTION__,infoParam.numOfTRMError);
247 case TRMMgr_MSG_TYPE_GET_CONNECTION_ERRORS:
249 __TIMESTAMP();printf(
"%s : Get Diag Info for GET_CONNECTION_ERRORS \r\n",__FUNCTION__);
251 infoParam.retCode = TRMMgr_ERR_UNKNOWN;
252 infoParam.bufLen = 0;
253 infoParam.msgType = TRMMgr_MSG_TYPE_GET_CONNECTION_ERRORS;
256 (
char *)IARM_BUS_TRMMGR_API_GetTRMDiagInfo,
260 if (infoParam.retCode == TRMMgr_ERR_NONE)
262 __TIMESTAMP();printf(
"%s() Get Diag Info Return Sucess for GET_CONNECTION_ERRORS \r\n",__FUNCTION__);
263 processBuffer(&(infoParam.buf[0]),infoParam.bufLen);
269 case TRMMgr_MSG_TYPE_GET_TUNER_CONFLICTS:
271 __TIMESTAMP();printf(
"%s : Get Diag Info for GET_TUNER_CONFLICTS \r\n",__FUNCTION__);
278 __TIMESTAMP();printf(
"%s Error: Diag Info not supported \r\n",__FUNCTION__);
283 __TIMESTAMP();printf(
"Exit %s():%d \n" ,__FUNCTION__,__LINE__);
309 int statusCode = msg.getStatus().getStatusCode();
310 if (TRM::ResponseStatus::kOk == statusCode)
312 __TIMESTAMP();printf(
"(GetAllConnectedDeviceIdsResponse) Sucess = %d\r\n",statusCode);
314 const std::list<std::string> & DeviceIds = msg.getDeviceIds();
315 std::list<std::string>::const_iterator it;
317 for (it = DeviceIds.begin(); it != DeviceIds.end(); it++) {
318 __TIMESTAMP();printf(
"conDeviceIDs = %s \r\n",(*it).c_str());
323 __TIMESTAMP();printf(
"(GetAllConnectedDeviceIdsResponse) StatusCode = %d \r\n",statusCode);
334 int statusCode = msg.getStatus().getStatusCode();
335 if (TRM::ResponseStatus::kOk == statusCode)
337 __TIMESTAMP();printf(
"(GetVersionResponse) Sucess = %d \r\n",statusCode);
338 __TIMESTAMP();printf(
"(TRM Version is ) = %s\r\n",msg.getVersion().c_str());
342 __TIMESTAMP();printf(
"(GetVersionResponse) StatusCode = %d \r\n",statusCode);
355 int statusCode = msg.getStatus().getStatusCode();
357 if (TRM::ResponseStatus::kOk == statusCode)
359 __TIMESTAMP();printf(
"(GetAllReservationsResponse) Sucess = %d\r\n",statusCode);
361 const std::map<std::string, std::list<TunerReservation> > & allReservations = msg.getAllReservations();
362 std::map<std::string, std::list<TunerReservation> >::const_iterator it;
364 for (it = allReservations.begin(); it != allReservations.end(); it++)
366 const std::list<TunerReservation> & tunerReservations = it->second;
367 std::list<TunerReservation>::const_iterator it1;
369 __TIMESTAMP();printf(
"Information for Tuner Reservation %d \r\n",tuner);
370 for (it1 = tunerReservations.begin(); it1 != tunerReservations.end(); it1++)
373 __TIMESTAMP();printf(
"Info for Tuner %d \r\n",tuner);
374 __TIMESTAMP();printf(
"----------------------------------------------------------- \r\n");
375 __TIMESTAMP();printf(
"reservationToken - %s \r\n",(*it1).getReservationToken().c_str());
376 __TIMESTAMP();printf(
"device - %s \r\n",(*it1).getDevice().c_str());
377 __TIMESTAMP();printf(
"serviceLocator - %s \r\n",(*it1).getServiceLocator().c_str());
378 __TIMESTAMP();printf(
"startTime - %llu \r\n",(*it1).getStartTime());
379 __TIMESTAMP();printf(
"duration - %llu \r\n",(*it1).getDuration());
381 if ((*it1).getActivity() == Activity::kLive) {
382 __TIMESTAMP();printf(
"Tuner is reserved for Live \r\n");
384 else if ((*it1).getActivity() == Activity::kRecord){
385 __TIMESTAMP();printf(
"Tuner is reserved for Record \r\n");
388 else if ((*it1).getActivity() == Activity::kEAS){
389 __TIMESTAMP();printf(
"Tuner is reserved for EAS \r\n");
392 else if ((*it1).getActivity() == Activity::kNone){
394 __TIMESTAMP();printf(
"Tuner is reserved for None and Free \r\n");
396 __TIMESTAMP();printf(
"----------------------------------------------------------- \r\n");
403 __TIMESTAMP();printf(
"(GetAllReservationsResponse) StatusCode = %d \r\n",statusCode);
416 int statusCode = msg.getStatus().getStatusCode();
417 if (TRM::ResponseStatus::kOk == statusCode)
419 __TIMESTAMP();printf(
"(GetTRMConnectionEvents) Sucess = %d\r\n",statusCode);
424 __TIMESTAMP();printf(
"(GetTRMConnectionEvents) StatusCode = %d \r\n",statusCode);
432 static void processBuffer(
const char* buf,
int len)
436 __TIMESTAMP();printf(
"Response %s \r\n", buf);
437 __TIMESTAMP();printf(
"Response Length %d - %d\r\n", strlen(buf),len);
439 std::vector<uint8_t> response;
440 response.insert( response.begin(), buf, buf+len);
444 jdecoder.decode( response);