Keyple Card Calypso C++ Library 2.2.5.6
Reference Terminal Reader API for C++
CmdSamReadCeilings.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2023 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
13#include "CmdSamReadCeilings.h"
14
15/* Keyple Card Calypso */
18#include "SamUtilAdapter.h"
19
20/* Keyple Core Util */
21#include "ApduUtil.h"
22#include "ByteArrayUtil.h"
23#include "IllegalArgumentException.h"
24
25namespace keyple {
26namespace card {
27namespace calypso {
28
29using namespace keyple::core::util;
30using namespace keyple::core::util::cpp::exception;
31
32const CalypsoSamCommand CmdSamReadCeilings::mCommand = CalypsoSamCommand::READ_CEILINGS;
33
34const std::map<const int, const std::shared_ptr<StatusProperties>>
35 CmdSamReadCeilings::STATUS_TABLE = initStatusTable();
36
37CmdSamReadCeilings::CmdSamReadCeilings(std::shared_ptr<CalypsoSamAdapter> calypsoSam,
38 const CeilingsOperationType ceilingsOperationType,
39 const int target)
40: AbstractSamCommand(mCommand, 48, calypsoSam),
41 mCeilingsOperationType(ceilingsOperationType),
42 mFirstEventCeilingNumber(ceilingsOperationType == CeilingsOperationType::READ_SINGLE_CEILING ?
43 target : (target - 1) * 9)
44{
45 const uint8_t cla = SamUtilAdapter::getClassByte(calypsoSam->getProductType());
46
47 uint8_t p1;
48 uint8_t p2;
49
50 if (ceilingsOperationType == CeilingsOperationType::READ_SINGLE_CEILING) {
51
52 p1 = target;
53 p2 = 0xB8;
54
55 } else {
56
57 p1 = 0x00;
58 p2 = static_cast<uint8_t>(0xB0 + target);
59 }
60
62 std::make_shared<ApduRequestAdapter>(
63 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, 0x00)));
64}
65
66const std::map<const int, const std::shared_ptr<StatusProperties>>
67 CmdSamReadCeilings::initStatusTable()
68{
69 std::map<const int, const std::shared_ptr<StatusProperties>> m =
71
72 m.insert({0x6900,
73 std::make_shared<StatusProperties>("An event counter cannot be incremented.",
75 m.insert({0x6A00,
76 std::make_shared<StatusProperties>("Incorrect P1 or P2.",
77 typeid(CalypsoSamIllegalParameterException))});
78 m.insert({0x6200,
79 std::make_shared<StatusProperties>("Correct execution with warning: data not signed.",
80 typeid(nullptr))});
81
82 return m;
83}
84
85const std::map<const int, const std::shared_ptr<StatusProperties>>&
87{
88 return STATUS_TABLE;
89}
90
91void CmdSamReadCeilings::parseApduResponse(std::shared_ptr<ApduResponseApi> apduResponse)
92{
94
95 const std::vector<uint8_t> dataOut = apduResponse->getDataOut();
96
97 if (mCeilingsOperationType == CeilingsOperationType::READ_SINGLE_CEILING) {
98
99 getCalypsoSam()->putEventCeiling(dataOut[8],
100 ByteArrayUtil::extractInt(dataOut, 9, 3, false));
101
102 } else {
103
104 for (int i = 0; i < 9; i++) {
105
106 getCalypsoSam()->putEventCeiling(
107 mFirstEventCeilingNumber + i,
108 ByteArrayUtil::extractInt(dataOut, 8 + (3 * i), 3, false));
109 }
110 }
111}
112
113}
114}
115}
virtual void setApduRequest(const std::shared_ptr< ApduRequestAdapter > apduRequest) final
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
const std::shared_ptr< CalypsoSamAdapter > getCalypsoSam() const
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
static const CalypsoSamCommand READ_CEILINGS
CmdSamReadCeilings(std::shared_ptr< CalypsoSamAdapter > calypsoSam, const CeilingsOperationType ceilingsOperationType, const int target)
void parseApduResponse(std::shared_ptr< ApduResponseApi > apduResponse) override
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
static uint8_t getClassByte(const ProductType productType)