1 /****************************************************************************** 2 * 3 * Copyright (C) 2011-2012 Broadcom Corporation 4 * 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: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 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 ******************************************************************************/ 18 #include <stdio.h> 19 #include <string.h> 20 #include <stdarg.h> 21 #include <time.h> 22 #include <sys/time.h> 23 #include "bt_target.h" 24 #include "gki.h" 25 26 #define BT_USE_TRACES TRUE 27 28 #if MMI_INCLUDED == TRUE 29 #include "mmi.h" 30 #endif 31 32 volatile UINT8 bte_target_mode; 33 34 #if BT_USE_TRACES == TRUE 35 36 #ifdef __CYGWIN__ 37 #undef RPC_INCLUDED 38 #define RPC_INCLUDED TRUE 39 40 /******************************************************************************* 41 ** 42 ** Function: LogMsg 43 ** 44 ** Description: log a message 45 ** 46 ** Returns: none 47 ** 48 *******************************************************************************/ 49 void 50 LogMsg(UINT32 maskTraceSet, const char *strFormat, ...) 51 { 52 va_list ap; 53 char buffer[256]; 54 struct timeval tv; 55 struct timezone tz; 56 struct tm *tm; 57 time_t t; 58 59 60 gettimeofday(&tv, &tz); 61 time(&t); 62 tm = localtime(&t); 63 64 sprintf(buffer, "%02d:%02d:%02d.%03d ", tm->tm_hour, tm->tm_min, tm->tm_sec, 65 tv.tv_usec / 1000); 66 pth_write(2, buffer, strlen(buffer)); 67 68 va_start(ap, strFormat); 69 vsprintf(buffer, strFormat, ap); 70 pth_write(2, buffer, strlen(buffer)); 71 pth_write(2, "\n", 1); 72 va_end(ap); 73 } 74 75 /******************************************************************************* 76 ** 77 ** Function: ScrLog 78 ** 79 ** Description: log a message 80 ** 81 ** Returns: none 82 ** 83 *******************************************************************************/ 84 void 85 ScrLog(UINT32 maskTraceSet, const char *strFormat, ...) 86 { 87 va_list ap; 88 char buffer[256]; 89 struct timeval tv; 90 struct timezone tz; 91 struct tm *tm; 92 time_t t; 93 94 gettimeofday(&tv, &tz); 95 time(&t); 96 tm = localtime(&t); 97 98 sprintf(buffer, "%02d:%02d:%02d.%03d ", tm->tm_hour, tm->tm_min, tm->tm_sec, 99 tv.tv_usec / 1000); 100 pth_write(2, buffer, strlen(buffer)); 101 102 va_start(ap, strFormat); 103 vsprintf(buffer, strFormat, ap); 104 pth_write(2, buffer, strlen(buffer)); 105 pth_write(2, "\n", 1); 106 va_end(ap); 107 } 108 #endif 109 110 /******************************************************************************** 111 ** 112 ** Function Name: LogMsg_0 113 ** 114 ** Purpose: Encodes a trace message that has no parameter arguments 115 ** 116 ** Input Parameters: maskTraceSet: tester trace type. 117 ** strFormat: displayable string. 118 ** Returns: 119 ** Nothing. 120 ** 121 *********************************************************************************/ 122 void LogMsg_0 (UINT32 maskTraceSet, const char *strFormat) 123 { 124 if (bte_target_mode == BTE_MODE_APPL) 125 { 126 #if RPC_INCLUDED == TRUE 127 LogMsg(maskTraceSet, strFormat); 128 #else 129 return; /* No RPC */ 130 #endif 131 } 132 else if (bte_target_mode == BTE_MODE_SAMPLE_APPS) /* Using demo sample apps */ 133 { 134 #if RPC_INCLUDED == TRUE 135 LogMsg(maskTraceSet, strFormat); 136 #elif MMI_INCLUDED == TRUE 137 if (mmi_debug_traces) 138 MMI_Echo(strFormat); 139 #endif 140 } 141 142 #if (defined(TRACE_TASK_INCLUDED) && TRACE_TASK_INCLUDED == TRUE) 143 LogMsg(maskTraceSet, strFormat); 144 #endif 145 146 #if (defined(DONGLE_MODE_INCLUDED) && DONGLE_MODE_INCLUDED == TRUE) 147 else if (bte_target_mode == BTE_MODE_DONGLE) 148 bte_hcisl_send_traces(maskTraceSet, strFormat); 149 #endif 150 151 152 } 153 154 /******************************************************************************** 155 ** 156 ** Function Name: LogMsg_1 157 ** 158 ** Purpose: Encodes a trace message that has one parameter argument 159 ** 160 ** Input Parameters: maskTraceSet: tester trace type. 161 ** strFormat: displayable string. 162 ** Returns: 163 ** Nothing. 164 ** 165 *********************************************************************************/ 166 void LogMsg_1 (UINT32 maskTraceSet, const char *strFormat, UINT32 p1) 167 { 168 if (bte_target_mode == BTE_MODE_APPL) 169 { 170 #if RPC_INCLUDED == TRUE 171 LogMsg (maskTraceSet, strFormat, p1); 172 #else 173 return; /* No RPC */ 174 #endif 175 } 176 else if (bte_target_mode == BTE_MODE_SAMPLE_APPS) /* Using demo sample apps */ 177 { 178 #if RPC_INCLUDED == TRUE 179 LogMsg (maskTraceSet, strFormat, p1); 180 #elif MMI_INCLUDED == TRUE 181 if (mmi_debug_traces) 182 MMI_Echo(strFormat, p1); 183 #endif 184 } 185 186 #if (defined(TRACE_TASK_INCLUDED) && TRACE_TASK_INCLUDED == TRUE) 187 LogMsg (maskTraceSet, strFormat, p1); 188 #endif 189 190 #if (defined(DONGLE_MODE_INCLUDED) && DONGLE_MODE_INCLUDED == TRUE) 191 else if (bte_target_mode == BTE_MODE_DONGLE) 192 bte_hcisl_send_traces(maskTraceSet, strFormat, p1); 193 #endif 194 } 195 196 /******************************************************************************** 197 ** 198 ** Function Name: LogMsg_2 199 ** 200 ** Purpose: Encodes a trace message that has two parameter arguments 201 ** 202 ** Input Parameters: maskTraceSet: tester trace type. 203 ** strFormat: displayable string. 204 ** Returns: 205 ** Nothing. 206 ** 207 *********************************************************************************/ 208 void LogMsg_2 (UINT32 maskTraceSet, const char *strFormat, UINT32 p1, UINT32 p2) 209 { 210 if (bte_target_mode == BTE_MODE_APPL) 211 { 212 #if RPC_INCLUDED == TRUE 213 LogMsg (maskTraceSet, strFormat, p1, p2); 214 #else 215 return; /* No RPC */ 216 #endif 217 } 218 else if (bte_target_mode == BTE_MODE_SAMPLE_APPS) /* Using demo sample apps */ 219 { 220 #if RPC_INCLUDED == TRUE 221 LogMsg (maskTraceSet, strFormat, p1, p2); 222 #elif MMI_INCLUDED == TRUE 223 if (mmi_debug_traces) 224 MMI_Echo(strFormat, p1, p2); 225 #endif 226 } 227 228 #if (defined(TRACE_TASK_INCLUDED) && TRACE_TASK_INCLUDED == TRUE) 229 LogMsg (maskTraceSet, strFormat, p1, p2); 230 #endif 231 232 #if (defined(DONGLE_MODE_INCLUDED) && DONGLE_MODE_INCLUDED == TRUE) 233 else if (bte_target_mode == BTE_MODE_DONGLE) 234 bte_hcisl_send_traces(maskTraceSet, strFormat, p1, p2); 235 #endif 236 } 237 238 /******************************************************************************** 239 ** 240 ** Function Name: LogMsg_3 241 ** 242 ** Purpose: Encodes a trace message that has three parameter arguments 243 ** 244 ** Input Parameters: maskTraceSet: tester trace type. 245 ** strFormat: displayable string. 246 ** Returns: 247 ** Nothing. 248 ** 249 *********************************************************************************/ 250 void LogMsg_3 (UINT32 maskTraceSet, const char *strFormat, UINT32 p1, UINT32 p2, UINT32 p3) 251 { 252 if (bte_target_mode == BTE_MODE_APPL) 253 { 254 #if RPC_INCLUDED == TRUE 255 LogMsg (maskTraceSet, strFormat, p1, p2, p3); 256 #else 257 return; /* No RPC */ 258 #endif 259 } 260 else if (bte_target_mode == BTE_MODE_SAMPLE_APPS) /* Using demo sample apps */ 261 { 262 #if RPC_INCLUDED == TRUE 263 LogMsg (maskTraceSet, strFormat, p1, p2, p3); 264 #elif MMI_INCLUDED == TRUE 265 if (mmi_debug_traces) 266 MMI_Echo(strFormat, p1, p2, p3); 267 #endif 268 } 269 270 #if (defined(TRACE_TASK_INCLUDED) && TRACE_TASK_INCLUDED == TRUE) 271 LogMsg (maskTraceSet, strFormat, p1, p2, p3); 272 #endif 273 274 #if (defined(DONGLE_MODE_INCLUDED) && DONGLE_MODE_INCLUDED == TRUE) 275 else if (bte_target_mode == BTE_MODE_DONGLE) 276 bte_hcisl_send_traces(maskTraceSet, strFormat, p1, p2, p3); 277 #endif 278 } 279 280 /******************************************************************************** 281 ** 282 ** Function Name: LogMsg_4 283 ** 284 ** Purpose: Encodes a trace message that has four parameter arguments 285 ** 286 ** Input Parameters: maskTraceSet: tester trace type. 287 ** strFormat: displayable string. 288 ** Returns: 289 ** Nothing. 290 ** 291 *********************************************************************************/ 292 void LogMsg_4 (UINT32 maskTraceSet, const char *strFormat, UINT32 p1, UINT32 p2, 293 UINT32 p3, UINT32 p4) 294 { 295 if (bte_target_mode == BTE_MODE_APPL) 296 { 297 #if RPC_INCLUDED == TRUE 298 LogMsg (maskTraceSet, strFormat, p1, p2, p3, p4); 299 #else 300 return; /* No RPC */ 301 #endif 302 } 303 else if (bte_target_mode == BTE_MODE_SAMPLE_APPS) /* Using demo sample apps */ 304 { 305 #if RPC_INCLUDED == TRUE 306 LogMsg (maskTraceSet, strFormat, p1, p2, p3, p4); 307 #elif MMI_INCLUDED == TRUE 308 if (mmi_debug_traces) 309 MMI_Echo(strFormat, p1, p2, p3, p4); 310 #endif 311 } 312 313 #if (defined(TRACE_TASK_INCLUDED) && TRACE_TASK_INCLUDED == TRUE) 314 LogMsg (maskTraceSet, strFormat, p1, p2, p3, p4); 315 #endif 316 317 #if (defined(DONGLE_MODE_INCLUDED) && DONGLE_MODE_INCLUDED == TRUE) 318 else if (bte_target_mode == BTE_MODE_DONGLE) 319 bte_hcisl_send_traces(maskTraceSet, strFormat, p1, p2, p3, p4); 320 #endif 321 } 322 323 /******************************************************************************** 324 ** 325 ** Function Name: LogMsg_5 326 ** 327 ** Purpose: Encodes a trace message that has five parameter arguments 328 ** 329 ** Input Parameters: maskTraceSet: tester trace type. 330 ** strFormat: displayable string. 331 ** Returns: 332 ** Nothing. 333 ** 334 *********************************************************************************/ 335 void LogMsg_5 (UINT32 maskTraceSet, const char *strFormat, UINT32 p1, UINT32 p2, 336 UINT32 p3, UINT32 p4, UINT32 p5) 337 { 338 if (bte_target_mode == BTE_MODE_APPL) 339 { 340 #if RPC_INCLUDED == TRUE 341 LogMsg (maskTraceSet, strFormat, p1, p2, p3, p4, p5); 342 #else 343 return; /* No RPC */ 344 #endif 345 } 346 else if (bte_target_mode == BTE_MODE_SAMPLE_APPS) /* Using demo sample apps */ 347 { 348 #if RPC_INCLUDED == TRUE 349 LogMsg (maskTraceSet, strFormat, p1, p2, p3, p4, p5); 350 #elif MMI_INCLUDED == TRUE 351 if (mmi_debug_traces) 352 MMI_Echo(strFormat, p1, p2, p3, p4, p5); 353 #endif 354 } 355 356 #if (defined(TRACE_TASK_INCLUDED) && TRACE_TASK_INCLUDED == TRUE) 357 LogMsg (maskTraceSet, strFormat, p1, p2, p3, p4, p5); 358 #endif 359 360 #if (defined(DONGLE_MODE_INCLUDED) && DONGLE_MODE_INCLUDED == TRUE) 361 else if (bte_target_mode == BTE_MODE_DONGLE) 362 bte_hcisl_send_traces(maskTraceSet, strFormat, p1, p2, p3, p4, p5); 363 #endif 364 } 365 366 /******************************************************************************** 367 ** 368 ** Function Name: LogMsg_6 369 ** 370 ** Purpose: Encodes a trace message that has six parameter arguments 371 ** 372 ** Input Parameters: maskTraceSet: tester trace type. 373 ** strFormat: displayable string. 374 ** Returns: 375 ** Nothing. 376 ** 377 *********************************************************************************/ 378 void LogMsg_6 (UINT32 maskTraceSet, const char *strFormat, UINT32 p1, UINT32 p2, 379 UINT32 p3, UINT32 p4, UINT32 p5, UINT32 p6) 380 { 381 if (bte_target_mode == BTE_MODE_APPL) 382 { 383 #if RPC_INCLUDED == TRUE 384 LogMsg (maskTraceSet, strFormat, p1, p2, p3, p4, p5, p6); 385 #else 386 return; /* No RPC */ 387 #endif 388 } 389 else if (bte_target_mode == BTE_MODE_SAMPLE_APPS) /* Using demo sample apps */ 390 { 391 #if RPC_INCLUDED == TRUE 392 LogMsg (maskTraceSet, strFormat, p1, p2, p3, p4, p5, p6); 393 #elif MMI_INCLUDED == TRUE 394 if (mmi_debug_traces) 395 MMI_Echo(strFormat, p1, p2, p3, p4, p5, p6); 396 #endif 397 } 398 399 400 #if (defined(TRACE_TASK_INCLUDED) && TRACE_TASK_INCLUDED == TRUE) 401 LogMsg (maskTraceSet, strFormat, p1, p2, p3, p4, p5, p6); 402 #endif 403 404 #if (defined(DONGLE_MODE_INCLUDED) && DONGLE_MODE_INCLUDED == TRUE) 405 else if (bte_target_mode == BTE_MODE_DONGLE) 406 bte_hcisl_send_traces(maskTraceSet, strFormat, p1, p2, p3, p4, p5, p6); 407 #endif 408 409 } 410 411 #endif /* BT_USE_TRACES */ 412 413