Keyple Card Calypso C++ Library 2.2.2
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 "IllegalArgumentException.h"
23
24namespace keyple {
25namespace card {
26namespace calypso {
27
28using namespace keyple::core::util;
29using namespace keyple::core::util::cpp::exception;
30
31const CalypsoSamCommand CmdSamReadCeilings::mCommand = CalypsoSamCommand::READ_CEILINGS;
32const int CmdSamReadCeilings::MAX_CEILING_NUMB = 26;
33const int CmdSamReadCeilings::MAX_CEILING_REC_NUMB = 3;
34
35const std::map<const int, const std::shared_ptr<StatusProperties>>
36 CmdSamReadCeilings::STATUS_TABLE = initStatusTable();
37
39 const CeilingsOperationType operationType,
40 const int index)
41: AbstractSamCommand(mCommand, 0)
42{
43 const uint8_t cla = SamUtilAdapter::getClassByte(productType);
44
45 uint8_t p1;
46 uint8_t p2;
47
48 if (operationType == CeilingsOperationType::CEILING_RECORD) {
49 if (index < 0 || index > MAX_CEILING_REC_NUMB) {
50 throw IllegalArgumentException("Record Number must be between 1 and " +
51 std::to_string(MAX_CEILING_REC_NUMB) +
52 ".");
53 }
54
55 p1 = 0x00;
56 p2 = static_cast<uint8_t>(0xB0 + index);
57
58 } else {
59 /* SINGLE_CEILING */
60 if (index < 0 || index > MAX_CEILING_NUMB) {
61 throw IllegalArgumentException("Counter Number must be between 0 and " +
62 std::to_string(MAX_CEILING_NUMB) +
63 ".");
64 }
65
66 p1 = static_cast<uint8_t>(index);
67 p2 = 0xB8;
68 }
69
71 std::make_shared<ApduRequestAdapter>(
72 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, 0x00)));
73}
74
75const std::map<const int, const std::shared_ptr<StatusProperties>>
76 CmdSamReadCeilings::initStatusTable()
77{
78 std::map<const int, const std::shared_ptr<StatusProperties>> m =
80
81 m.insert({0x6900,
82 std::make_shared<StatusProperties>("An event counter cannot be incremented.",
84 m.insert({0x6A00,
85 std::make_shared<StatusProperties>("Incorrect P1 or P2.",
86 typeid(CalypsoSamIllegalParameterException))});
87 m.insert({0x6200,
88 std::make_shared<StatusProperties>("Correct execution with warning: data not signed.",
89 typeid(nullptr))});
90
91 return m;
92}
93
94const std::vector<uint8_t> CmdSamReadCeilings::getCeilingsData() const
95{
96 return isSuccessful() ? getApduResponse()->getDataOut() : std::vector<uint8_t>();
97}
98
99const std::map<const int, const std::shared_ptr<StatusProperties>>&
101{
102 return STATUS_TABLE;
103}
104
105}
106}
107}
virtual const std::shared_ptr< ApduResponseApi > getApduResponse() const final
virtual void setApduRequest(const std::shared_ptr< ApduRequestAdapter > apduRequest) final
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
static const CalypsoSamCommand READ_CEILINGS
const std::vector< uint8_t > getCeilingsData() const
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
CmdSamReadCeilings(const CalypsoSam::ProductType productType, const CeilingsOperationType operationType, const int index)
static uint8_t getClassByte(const ProductType productType)
CalypsoSam::ProductType ProductType