-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetstatus.cpp
More file actions
200 lines (192 loc) · 6.04 KB
/
getstatus.cpp
File metadata and controls
200 lines (192 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "FileStreambuf.hpp"
#include "libcapt/Protocol/Enums.hpp"
#include "libcapt/Protocol/ExtendedStatus.hpp"
#include "libcapt/Protocol/Protocol.hpp"
#include <iostream>
#include <cstdio>
using namespace Capt;
static void printBasicStatus(BasicStatus status) {
std::printf("BasicStatus = 0x%02X\n", static_cast<int>(status));
int check = 0;
if ((static_cast<int>(status) & 1) != 0) { // 1
std::puts(" UNKNOWN 1");
check |= 1;
}
if ((status & BasicStatus::NOT_READY) != 0) { // 2
std::puts(" NOT_READY");
check |= 2;
}
if ((static_cast<int>(status) & 4) != 0) { // 4
std::puts(" *RCF_CMD_BUSY");
check |= 4;
}
if ((static_cast<int>(status) & 8) != 0) { // 8
std::puts(" *RCF_IM_DATA_BUSY");
check |= 8;
}
if ((status & BasicStatus::OFFLINE) != 0) { // 16
std::puts(" OFFLINE");
check |= 16;
}
if ((static_cast<int>(status) & 32) != 0) { // 32
std::puts(" UNKNOWN 32");
check |= 32;
}
if ((status & BasicStatus::UNIT_FREE) != 0) { // 64
std::puts(" UNIT_FREE");
check |= 64;
}
if ((status & BasicStatus::ERROR_BIT) != 0) { // 128
std::puts(" ERROR_BIT");
check |= 128;
}
if (status != check) {
std::printf("Check mismatch: 0x%02X != 0x%02X\n", static_cast<int>(status), check);
}
}
static void printAuxStatus(AuxStatus status) {
std::printf("AuxStatus = 0x%02X\n", static_cast<int>(status));
int check = 0;
if ((static_cast<int>(status) & 1) != 0) { // 1
std::puts(" UNKNOWN 1");
check |= 1;
}
if ((status & AuxStatus::PRINTER_BUSY) != 0) { // 2
std::puts(" PRINTER_BUSY");
check |= 2;
}
if ((status & AuxStatus::PAPER_DELIVERY) != 0) { // 4
std::puts(" PAPER_DELIVERY");
check |= 4;
}
if ((static_cast<int>(status) & 8) != 0) { // 8
std::puts(" UNKNOWN 8");
check |= 8;
}
if ((static_cast<int>(status) & 16) != 0) { // 16
std::puts(" UNKNOWN 16");
check |= 16;
}
if ((static_cast<int>(status) & 32) != 0) { // 32
std::puts(" UNKNOWN 32");
check |= 32;
}
if ((static_cast<int>(status) & 64) != 0) { // 64
std::puts(" UNKNOWN 64");
check |= 64;
}
if ((status & AuxStatus::SAFE_TIMER) != 0) { // 128
std::puts(" SAFE_TIMER");
check |= 128;
}
if (status != check) {
std::printf("Check mismatch: 0x%02X != 0x%02X\n", static_cast<int>(status), check);
}
}
static void printControllerStatus(ControllerStatus status) {
std::printf("ControllerStatus = 0x%02X\n", static_cast<int>(status));
int check = 0;
if ((status & ControllerStatus::OVERRUN) != 0) { // 1
std::puts(" OVERRUN");
check |= 1;
}
if ((status & ControllerStatus::UNDERRUN) != 0) { // 2
std::puts(" UNDERRUN");
check |= 2;
}
if ((status & ControllerStatus::MISSING_EOP) != 0) { // 4
std::puts(" MISSING_EOP");
check |= 4;
}
if ((status & ControllerStatus::INVALID_DATA) != 0) { // 8
std::puts(" INVALID_DATA");
check |= 8;
}
if ((status & ControllerStatus::ENGINE_COMM_ERROR) != 0) { // 16
std::puts(" ENGINE_COMM_ERROR");
check |= 16;
}
if ((status & ControllerStatus::ENGINE_RESET_IN_PROGRESS) != 0) { // 32
std::puts(" ENGINE_RESET_IN_PROGRESS");
check |= 32;
}
if ((status & ControllerStatus::PRINT_REJECTED) != 0) { // 64
std::puts(" PRINT_REJECTED");
check |= 64;
}
if (status != check) {
std::printf("Check mismatch: 0x%02X != 0x%02X\n", static_cast<int>(status), check);
}
}
static void printEngineStatus(EngineReadyStatus status) {
std::printf("EngineReadyStatus = 0x%02X\n", static_cast<int>(status));
int check = 0;
if ((status & EngineReadyStatus::DOOR_OPEN) != 0) { // 0x4000
std::puts(" DOOR_OPEN");
check |= 0x4000;
}
if ((status & EngineReadyStatus::NO_CARTRIDGE) != 0) { // 0x2000
std::puts(" NO_CARTRIDGE");
check |= 0x2000;
}
if ((status & EngineReadyStatus::WAITING) != 0) { // 0x1000
std::puts(" WAITING");
check |= 0x1000;
}
if ((status & EngineReadyStatus::TEST_PRINTING) != 0) { // 0x400
std::puts(" TEST_PRINTING");
check |= 0x400;
}
if ((status & EngineReadyStatus::NO_PRINT_PAPER) != 0) { // 0x200
std::puts(" NO_PRINT_PAPER");
check |= 0x200;
}
if ((status & EngineReadyStatus::JAM) != 0) { // 0x100
std::puts(" JAM");
check |= 0x100;
}
if ((status & EngineReadyStatus::CLEANING) != 0) { // 4
std::puts(" CLEANING");
check |= 4;
}
if ((status & EngineReadyStatus::SERVICE_CALL) != 0) { // 2
std::puts(" SERVICE_CALL");
check |= 2;
}
if ((status & EngineReadyStatus::MIS_PRINT) != 0) { // 0x80
std::puts(" MIS_PRINT");
check |= 0x80;
}
if ((status & EngineReadyStatus::MIS_PRINT_2) != 0) { // 0x40
std::puts(" MIS_PRINT_2");
check |= 0x40;
}
if (status != check) {
std::printf("Check mismatch: 0x%02X != 0x:%02X\n", static_cast<int>(status), check);
}
}
static void printStatus(ExtendedStatus ex) {
printBasicStatus(ex.Basic);
printAuxStatus(ex.Aux);
printControllerStatus(ex.Controller);
printEngineStatus(ex.Engine);
std::printf("Start = %u\n", ex.Start);
std::printf("Printing = %u\n", ex.Printing);
std::printf("Shipped = %u\n", ex.Shipped);
std::printf("Printed = %u\n", ex.Printed);
std::printf("Paper = 0x%x\n", ex.PaperAvailableBits);
}
int main(int argc, char* argv[]) {
if (argc != 2) {
std::printf("Usage: %s printerdev\n", argv[0]);
return 1;
}
FileStreambuf fs;
if (!fs.Open(argv[1], "r+")) {
std::puts("Failed to open printer stream");
return 1;
}
std::iostream printerStream(&fs);
printStatus(Protocol::PC_GET_EXTENDED_STATUS(printerStream));
return 0;
}