Keyple Card Calypso C++ Library 2.2.2
Reference Terminal Reader API for C++
SvLoadLogRecordAdapter.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2022 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional information regarding *
5 * copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the terms of the Eclipse *
8 * Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 *
9 * *
10 * SPDX-License-Identifier: EPL-2.0 *
11 **************************************************************************************************/
12
14
15/* Keyple Core Util */
16#include "ByteArrayUtil.h"
17#include "HexUtil.h"
18#include "KeypleStd.h"
19#include "System.h"
20
21namespace keyple {
22namespace card {
23namespace calypso {
24
25using namespace keyple::core::util;
26using namespace keyple::core::util::cpp;
27
29 const std::vector<uint8_t>& cardResponse, const int offset)
30: mOffset(offset), mCardResponse(cardResponse) {}
31
32const std::vector<uint8_t>& SvLoadLogRecordAdapter::getRawData() const
33{
34 return mCardResponse;
35}
36
38{
39 return ByteArrayUtil::extractInt(mCardResponse, mOffset + 8, 3, true);
40}
41
43{
44 return ByteArrayUtil::extractInt(mCardResponse, mOffset + 5, 3, true);
45}
46
47const std::vector<uint8_t> SvLoadLogRecordAdapter::getLoadTime() const
48{
49 std::vector<uint8_t> loadTime(2);
50 loadTime[0] = mCardResponse[mOffset + 11];
51 loadTime[1] = mCardResponse[mOffset + 12];
52
53 return loadTime;
54}
55
56const std::vector<uint8_t> SvLoadLogRecordAdapter::getLoadDate() const
57{
58 std::vector<uint8_t> loadDate(2);
59 loadDate[0] = mCardResponse[mOffset + 0];
60 loadDate[1] = mCardResponse[mOffset + 1];
61
62 return loadDate;
63}
64
65const std::vector<uint8_t> SvLoadLogRecordAdapter::getFreeData() const
66{
67 std::vector<uint8_t> freeData(2);
68 freeData[0] = mCardResponse[mOffset + 2];
69 freeData[1] = mCardResponse[mOffset + 4];
70
71 return freeData;
72}
73
75{
76 return mCardResponse[mOffset + 3];
77}
78
79const std::vector<uint8_t> SvLoadLogRecordAdapter::getSamId() const
80{
81 std::vector<uint8_t> samId(4);
82 System::arraycopy(mCardResponse, mOffset + 13, samId, 0, 4);
83
84 return samId;
85}
86
88{
89 std::vector<uint8_t> tnNum(2);
90 tnNum[0] = mCardResponse[mOffset + 20];
91 tnNum[1] = mCardResponse[mOffset + 21];
92
93 return ByteArrayUtil::extractInt(tnNum, 0, 2, false);
94}
95
97{
98 std::vector<uint8_t> samTNum(3);
99 System::arraycopy(mCardResponse, mOffset + 17, samTNum, 0, 3);
100
101 return ByteArrayUtil::extractInt(samTNum, 0, 3, false);
102}
103
104std::ostream& operator<<(std::ostream& os, const SvLoadLogRecordAdapter& ra)
105{
106 os << "SV_LOAD_LOG_RECORD_ADAPTER: {"
107 << "AMOUNT: " << ra.getAmount() << ", "
108 << "BALANCE: " << ra.getBalance() << ", "
109 << "DEBIT_DATE:" << ra.getLoadDate() << ", "
110 << "LOAD_TIME:" << ra.getLoadDate() << ", "
111 << "FREE_BYTES: " << ra.getFreeData() << ", "
112 << "KVC: " << ra.getKvc() << ", "
113 << "SAM_ID: " << ra.getSamId() << ", "
114 << "SV_TRANSACTION_NUMBER: " << ra.getSvTNum() << ", "
115 << "SV_SAM_TRANSACTION_NUMBER: " << ra.getSamTNum()
116 << "}";
117
118 return os;
119}
120
121std::ostream& operator<<(std::ostream& os, const std::shared_ptr<SvLoadLogRecordAdapter> ra)
122{
123 if (ra == nullptr) {
124 os << "SV_LOAD_LOG_RECORD_ADAPTER: null";
125 } else {
126 os << *ra.get();
127 }
128
129 return os;
130}
131
133{
134 return "{" \
135 "\"amount\":" + std::to_string(getAmount()) + ", " \
136 "\"balance\":" + std::to_string(getBalance()) + ", " \
137 "\"debitDate\":" + HexUtil::toHex(getLoadDate()) + ", " \
138 "\"loadTime\":" + HexUtil::toHex(getLoadDate()) + ", " \
139 "\"freeBytes\": \"" + HexUtil::toHex(getFreeData()) + "\", " \
140 "\"kvc\":" + std::to_string(getKvc()) + ", " \
141 "\"samId\": \"" + HexUtil::toHex(getSamId()) + "\", " \
142 "\"svTransactionNumber\":" + std::to_string(getSvTNum()) + ", " \
143 "\"svSamTransactionNumber\":" + std::to_string(getSamTNum()) + "" \
144 "}";
145}
146
147}
148}
149}
const std::vector< uint8_t > & getRawData() const override
const std::vector< uint8_t > getSamId() const override
const std::vector< uint8_t > getLoadTime() const override
const std::vector< uint8_t > getFreeData() const override
SvLoadLogRecordAdapter(const std::vector< uint8_t > &cardResponse, const int offset)
const std::vector< uint8_t > getLoadDate() const override
std::ostream & operator<<(std::ostream &os, const std::shared_ptr< ApduRequestAdapter > ara)