Keyple Card Calypso C++ Library 2.1.0
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 "KeypleStd.h"
18#include "System.h"
19
20namespace keyple {
21namespace card {
22namespace calypso {
23
24using namespace keyple::core::util;
25using namespace keyple::core::util::cpp;
26
28 const std::vector<uint8_t>& cardResponse, const int offset)
29: mOffset(offset), mCardResponse(cardResponse) {}
30
31const std::vector<uint8_t>& SvLoadLogRecordAdapter::getRawData() const
32{
33 return mCardResponse;
34}
35
37{
38 return ByteArrayUtil::threeBytesSignedToInt(mCardResponse, mOffset + 8);
39}
40
42{
43 return ByteArrayUtil::threeBytesSignedToInt(mCardResponse, mOffset + 5);
44}
45
46const std::vector<uint8_t> SvLoadLogRecordAdapter::getLoadTime() const
47{
48 std::vector<uint8_t> loadTime(2);
49 loadTime[0] = mCardResponse[mOffset + 11];
50 loadTime[1] = mCardResponse[mOffset + 12];
51
52 return loadTime;
53}
54
55const std::vector<uint8_t> SvLoadLogRecordAdapter::getLoadDate() const
56{
57 std::vector<uint8_t> loadDate(2);
58 loadDate[0] = mCardResponse[mOffset + 0];
59 loadDate[1] = mCardResponse[mOffset + 1];
60
61 return loadDate;
62}
63
64const std::vector<uint8_t> SvLoadLogRecordAdapter::getFreeData() const
65{
66 std::vector<uint8_t> freeData(2);
67 freeData[0] = mCardResponse[mOffset + 2];
68 freeData[1] = mCardResponse[mOffset + 4];
69
70 return freeData;
71}
72
74{
75 return mCardResponse[mOffset + 3];
76}
77
78const std::vector<uint8_t> SvLoadLogRecordAdapter::getSamId() const
79{
80 std::vector<uint8_t> samId(4);
81 System::arraycopy(mCardResponse, mOffset + 13, samId, 0, 4);
82
83 return samId;
84}
85
87{
88 std::vector<uint8_t> tnNum(2);
89 tnNum[0] = mCardResponse[mOffset + 20];
90 tnNum[1] = mCardResponse[mOffset + 21];
91
92 return ByteArrayUtil::twoBytesToInt(tnNum, 0);
93}
94
96{
97 std::vector<uint8_t> samTNum(3);
98 System::arraycopy(mCardResponse, mOffset + 17, samTNum, 0, 3);
99
100 return ByteArrayUtil::threeBytesToInt(samTNum, 0);
101}
102
103std::ostream& operator<<(std::ostream& os, const SvLoadLogRecordAdapter& ra)
104{
105 os << "SV_LOAD_LOG_RECORD_ADAPTER: {"
106 << "AMOUNT: " << ra.getAmount() << ", "
107 << "BALANCE: " << ra.getBalance() << ", "
108 << "DEBIT_DATE:" << ra.getLoadDate() << ", "
109 << "LOAD_TIME:" << ra.getLoadDate() << ", "
110 << "FREE_BYTES: " << ra.getFreeData() << ", "
111 << "KVC: " << ra.getKvc() << ", "
112 << "SAM_ID: " << ra.getSamId() << ", "
113 << "SV_TRANSACTION_NUMBER: " << ra.getSvTNum() << ", "
114 << "SV_SAM_TRANSACTION_NUMBER: " << ra.getSamTNum()
115 << "}";
116
117 return os;
118}
119
120std::ostream& operator<<(std::ostream& os, const std::shared_ptr<SvLoadLogRecordAdapter> ra)
121{
122 if (ra == nullptr) {
123 os << "SV_LOAD_LOG_RECORD_ADAPTER: null";
124 } else {
125 os << *ra.get();
126 }
127
128 return os;
129}
130
132{
133 return "{" \
134 "\"amount\":" + std::to_string(getAmount()) + ", " \
135 "\"balance\":" + std::to_string(getBalance()) + ", " \
136 "\"debitDate\":" + ByteArrayUtil::toHex(getLoadDate()) + ", " \
137 "\"loadTime\":" + ByteArrayUtil::toHex(getLoadDate()) + ", " \
138 "\"freeBytes\": \"" + ByteArrayUtil::toHex(getFreeData()) + "\", " \
139 "\"kvc\":" + std::to_string(getKvc()) + ", " \
140 "\"samId\": \"" + ByteArrayUtil::toHex(getSamId()) + "\", " \
141 "\"svTransactionNumber\":" + std::to_string(getSvTNum()) + ", " \
142 "\"svSamTransactionNumber\":" + std::to_string(getSamTNum()) + "" \
143 "}";
144}
145
146}
147}
148}
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)