blob: 6bf4ef45738d8e7edcd3b7f3f8fcf755cab585d6 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/* Copyright Statement:
2 *
3 * This software/firmware and related documentation ("MediaTek Software") are
4 * protected under relevant copyright laws. The information contained herein
5 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6 * Without the prior written permission of MediaTek inc. and/or its licensors,
7 * any reproduction, modification, use or disclosure of MediaTek Software,
8 * and information contained herein, in whole or in part, shall be strictly prohibited.
9 */
10/* MediaTek Inc. (C) 2010. All rights reserved.
11 *
12 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
13 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
14 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
15 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
18 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
21 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
22 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
23 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
24 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
25 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
26 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
27 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
28 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
29 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
30 *
31 * The following software/firmware and/or related documentation ("MediaTek Software")
32 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
33 * applicable license agreements with MediaTek Inc.
34 */
35
36#include <string>
37#include <iostream>
38using namespace std;
39
40#include <log/log.h>
41#include "UserData.h"
42#include "HexDump.h"
43
44constexpr int UserData::ASCII_NL_INDEX;
45constexpr int UserData::ASCII_CR_INDEX;
46const char UserData::ASCII_MAP[] = { ' ', '!', '"', '#', '$', '%', '&', '\'',
47 '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6',
48 '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E',
49 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
50 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c',
51 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
52 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~' };
53
54const int UserData::ASCII_MAP_MAX_INDEX = ASCII_MAP_BASE_INDEX
55 + sizeof(ASCII_MAP) / sizeof(char) - 1;
56
57std::map<char, uint8_t> UserData::charToAscii = UserData::init();
58
59std::map<char, uint8_t> UserData::init() {
60 std::map<char, uint8_t> temp;
61 for (uint32_t i = 0; i < sizeof(ASCII_MAP) / sizeof(char); i++) {
62 temp.insert(
63 pair<char, uint8_t>(ASCII_MAP[i], PRINTABLE_ASCII_MIN_INDEX + i));
64 }
65 temp.insert(pair<char, uint8_t>('\n', ASCII_NL_INDEX));
66 temp.insert(pair<char, uint8_t>('\r', ASCII_CR_INDEX));
67 return temp;
68}
69
70//uint8_t* UserData::stringToAscii(string msg, int* length) {
71std::vector<uint8_t> UserData::stringToAscii(std::string msg) {
72 int len = msg.length();
73 //uint8_t* result = new uint8_t[len];
74 std::vector<uint8_t> result;
75 for (int i = 0; i < len; i++) {
76 uint8_t charCode;
77 try {
78 charCode = charToAscii.at(msg[i]);
79 } catch (const out_of_range &e) {
80 //TBD log.
81 return result;
82 }
83 result.push_back(charCode);
84 //result[i] = charCode;
85
86 }
87 return result;
88}
89
90UserData::UserData() {
91
92}
93
94UserData::~UserData() {
95
96}
97
98std::string UserData::toString() {
99 string builder;
100 builder.append("UserData ");
101 builder.append("{ msgEncoding=");
102 builder.append(msgEncodingSet ? std::to_string(msgEncoding) : "unset");
103 builder.append(", msgType=" + std::to_string(msgType));
104 builder.append(", paddingBits=" + std::to_string(paddingBits));
105 builder.append(", numFields=" + std::to_string(numFields));
106 builder.append(
107 ", userDataHeader="
108 + string(userDataHeader ? userDataHeader->toString() : "unset"));
109 builder.append(", payload='" + HexDump::toHexString(payload) + string("'"));
110 builder.append(", payloadStr='" + payloadStr + "'");
111 std::cout << "message content: " << payloadStr << std::endl;
112 RLOGD("[MT_CDMA_SMS]Message conetent: %s", payloadStr.c_str());
113 builder.append(" }");
114 return builder;
115}