Jean Chalard | a5d5849 | 2011-02-18 17:50:58 +0900 | [diff] [blame] | 1 | /* |
Ken Wakasa | 5460ea3 | 2012-07-30 16:27:44 +0900 | [diff] [blame] | 2 | * Copyright (C) 2011, The Android Open Source Project |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Jean Chalard | a5d5849 | 2011-02-18 17:50:58 +0900 | [diff] [blame] | 16 | |
| 17 | #ifndef LATINIME_DEBUG_H |
| 18 | #define LATINIME_DEBUG_H |
| 19 | |
| 20 | #include "defines.h" |
| 21 | |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 22 | static inline unsigned char *convertToUnibyteString(unsigned short *input, unsigned char *output, |
Jean Chalard | a5d5849 | 2011-02-18 17:50:58 +0900 | [diff] [blame] | 23 | const unsigned int length) { |
Jean Chalard | 1ff8dc4 | 2012-05-02 16:00:24 +0900 | [diff] [blame] | 24 | unsigned int i = 0; |
Jean Chalard | cc1062c | 2012-08-17 09:24:45 +0900 | [diff] [blame] | 25 | for (; i < length && input[i] != 0; ++i) |
Jean Chalard | a5d5849 | 2011-02-18 17:50:58 +0900 | [diff] [blame] | 26 | output[i] = input[i] & 0xFF; |
| 27 | output[i] = 0; |
| 28 | return output; |
| 29 | } |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 30 | |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 31 | static inline unsigned char *convertToUnibyteStringAndReplaceLastChar(unsigned short *input, |
| 32 | unsigned char *output, const unsigned int length, unsigned char c) { |
Jean Chalard | 1ff8dc4 | 2012-05-02 16:00:24 +0900 | [diff] [blame] | 33 | unsigned int i = 0; |
Jean Chalard | cc1062c | 2012-08-17 09:24:45 +0900 | [diff] [blame] | 34 | for (; i < length && input[i] != 0; ++i) |
Jean Chalard | a5d5849 | 2011-02-18 17:50:58 +0900 | [diff] [blame] | 35 | output[i] = input[i] & 0xFF; |
Jean Chalard | 1ff8dc4 | 2012-05-02 16:00:24 +0900 | [diff] [blame] | 36 | if (i > 0) output[i-1] = c; |
Jean Chalard | a5d5849 | 2011-02-18 17:50:58 +0900 | [diff] [blame] | 37 | output[i] = 0; |
| 38 | return output; |
| 39 | } |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 40 | |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 41 | static inline void LOGI_S16(unsigned short *string, const unsigned int length) { |
Jean Chalard | a5d5849 | 2011-02-18 17:50:58 +0900 | [diff] [blame] | 42 | unsigned char tmp_buffer[length]; |
| 43 | convertToUnibyteString(string, tmp_buffer, length); |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 44 | AKLOGI(">> %s", tmp_buffer); |
Jean Chalard | a5d5849 | 2011-02-18 17:50:58 +0900 | [diff] [blame] | 45 | // The log facility is throwing out log that comes too fast. The following |
| 46 | // is a dirty way of slowing down processing so that we can see all log. |
| 47 | // TODO : refactor this in a blocking log or something. |
| 48 | // usleep(10); |
| 49 | } |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 50 | |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 51 | static inline void LOGI_S16_PLUS(unsigned short *string, const unsigned int length, |
Jean Chalard | a5d5849 | 2011-02-18 17:50:58 +0900 | [diff] [blame] | 52 | unsigned char c) { |
| 53 | unsigned char tmp_buffer[length+1]; |
| 54 | convertToUnibyteStringAndReplaceLastChar(string, tmp_buffer, length, c); |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 55 | AKLOGI(">> %s", tmp_buffer); |
Jean Chalard | a5d5849 | 2011-02-18 17:50:58 +0900 | [diff] [blame] | 56 | // Likewise |
| 57 | // usleep(10); |
| 58 | } |
| 59 | |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 60 | static inline void printDebug(const char *tag, int *codes, int codesSize, int MAX_PROXIMITY_CHARS) { |
Ken Wakasa | 267030d | 2012-08-14 18:54:13 +0900 | [diff] [blame] | 61 | unsigned char *buf = static_cast<unsigned char *>(malloc((1 + codesSize) * sizeof(*buf))); |
Jean Chalard | c2bbc6a | 2011-02-25 17:56:53 +0900 | [diff] [blame] | 62 | |
| 63 | buf[codesSize] = 0; |
Ken Wakasa | bcec82d | 2012-08-12 11:10:48 +0900 | [diff] [blame] | 64 | while (--codesSize >= 0) { |
| 65 | buf[codesSize] = static_cast<unsigned char>(codes[codesSize * MAX_PROXIMITY_CHARS]); |
| 66 | } |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 67 | AKLOGI("%s, WORD = %s", tag, buf); |
Jean Chalard | c2bbc6a | 2011-02-25 17:56:53 +0900 | [diff] [blame] | 68 | |
| 69 | free(buf); |
| 70 | } |
Jean Chalard | a5d5849 | 2011-02-18 17:50:58 +0900 | [diff] [blame] | 71 | #endif // LATINIME_DEBUG_H |