plptools
Loading...
Searching...
No Matches
rpcs32.cc
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * along with this program; if not, see <https://www.gnu.org/licenses/>.
18 *
19 */
20#include "config.h"
21
22#include "rpcs32.h"
23#include "bufferstore.h"
24#include "bufferarray.h"
25#include "tcpsocket.h"
26
27#include <iostream>
28
29#include <memory>
30#include <stdio.h>
31#include <stdlib.h>
32#include <time.h>
33
34using namespace std;
35
36RPCS32::RPCS32(std::unique_ptr<TCPSocket> socket) {
37 socket_ = std::move(socket);
38 mtCacheS5mx = 0;
39 reset();
40}
41
42Enum<RFSV::errs> RPCS32::getCmdLine(const char *process, string &ret) {
45
46 a.addStringT(process);
49 }
50 if ((res = getResponse(a, true)) == RFSV::E_PSI_GEN_NONE) {
51 ret = a.getString(0);
52 }
53 return res;
54}
55
59
62 if ((res = getResponse(a, true)) != RFSV::E_PSI_GEN_NONE)
63 return res;
64 if (a.getLen() != 256)
66 mi.machineType = (enum RPCS::machs)a.getDWord(0);
67 strncpy(mi.machineName, a.getString(16), 16);
68 mi.machineName[16] = '\0';
69 mi.machineUID = a.getDWord(44);
70 mi.machineUID <<= 32;
71 mi.machineUID |= a.getDWord(40);
72 mi.countryCode = a.getDWord(56);
73 mi.uiLanguage = (enum RPCS::languages)a.getDWord(164);
74
75 mi.romMajor = a.getByte(4);
76 mi.romMinor = a.getByte(5);
77 mi.romBuild = a.getWord(6);
78 mi.romSize = a.getDWord(140);
79
80 mi.ramSize = a.getDWord(136);
81 mi.ramMaxFree = a.getDWord(144);
82 mi.ramFree = a.getDWord(148);
83 mi.ramDiskSize = a.getDWord(152);
84
85 mi.registrySize = a.getDWord(156);
86 mi.romProgrammable = (a.getDWord(160) != 0);
87
88 mi.displayWidth = a.getDWord(32);
89 mi.displayHeight = a.getDWord(36);
90
91 mi.time.tv_low = a.getDWord(48);
92 mi.time.tv_high = a.getDWord(52);
93
94 mi.tz.utc_offset = a.getSDWord(60);
95 mi.tz.dst_zones = a.getDWord(64);
96 mi.tz.home_zone = a.getDWord(68);
97
99
100 mi.mainBatteryInsertionTime.tv_low = a.getDWord(72);
101 mi.mainBatteryInsertionTime.tv_high = a.getDWord(76);
102 mi.mainBatteryStatus = (enum RPCS::batterystates)a.getDWord(80);
103 mi.mainBatteryUsedTime.tv_low = a.getDWord(84);
104 mi.mainBatteryUsedTime.tv_high = a.getDWord(88);
105 mi.mainBatteryCurrent = a.getDWord(92);
106 mi.mainBatteryUsedPower = a.getDWord(96);
107 mi.mainBatteryVoltage = a.getDWord(100);
108 mi.mainBatteryMaxVoltage = a.getDWord(104);
109
110 mi.backupBatteryStatus = (enum RPCS::batterystates)a.getDWord(108);
111 mi.backupBatteryVoltage = a.getDWord(112);
112 mi.backupBatteryMaxVoltage = a.getDWord(116);
113 mi.externalPowerUsedTime.tv_low = a.getDWord(124);
114 mi.externalPowerUsedTime.tv_high = a.getDWord(128);
115 mi.externalPower = (a.getDWord(120) != 0);
116
117 mtCacheS5mx |= 8;
118 if (res == RFSV::E_PSI_GEN_NONE) {
119 if (!strcmp(mi.machineName, "SERIES5mx")) {
120 mtCacheS5mx |= 2;
121 }
122 }
123
124 return res;
125}
126
130
133 if ((res = (enum RFSV::errs)getResponse(a, true)) != RFSV::E_PSI_GEN_NONE) {
134 return res;
135 }
136 a.addByte(0);
137 string s = a.getString(0);
138 owner.clear();
139 int p = 0;
140 int l;
141 while ((l = s.find('\006', p)) != s.npos) {
142 BufferStore b;
143 b.addStringT(s.substr(p, l - p).c_str());
144 owner += b;
145 p = l + 1;
146 }
147 if (s.substr(p).length()) {
148 BufferStore b;
149 b.addStringT(s.substr(p).c_str());
150 owner += b;
151 }
152 return res;
153}
154
155Enum<RFSV::errs> RPCS32::regOpenIter(uint32_t uid, char *match, uint16_t &handle) {
158
159 cout << "Oiter" << endl;
160 a.addDWord(uid);
161 a.addDWord(strlen(match));
162 a.addStringT(match);
165 }
166 res = getResponse(a, true);
167 cout << "ro: r=" << res << " a=" << a << endl;
168 if (a.getLen() == 2) {
169 handle = a.getWord(0);
170 }
172}
173
177
178 cout << "Riter" << endl;
179 a.addWord(handle);
182 }
183 res = getResponse(a, true);
184 cout << "ro: r=" << res << " a=" << a << endl;
185 if ((a.getLen() == 3) && (a.getByte(2) == 0xff)) {
187 }
189}
190
194 PsiTime pt;
195 psi_timezone ptz;
197
198 // cout << "settime" << endl;
199 if ((res = getMachineInfo(mi)) == RFSV::E_PSI_GEN_NONE) {
200 if (PsiZone::getInstance().getZone(ptz)) {
201 pt = PsiTime(time + ptz.utc_offset);
202 a.addDWord(pt.getPsiTimeLo());
203 a.addDWord(pt.getPsiTimeHi());
204 a.addDWord(mi.countryCode);
205 a.addDWord(ptz.utc_offset);
206 a.addDWord(ptz.dst_zones);
207 a.addDWord(ptz.home_zone);
208 // cout << "a=" << a << endl;
212 } else
214 } else
215 return res;
216}
217
218Enum<RFSV::errs> RPCS32::configOpen(uint16_t &handle, uint32_t size) {
221
222 a.addDWord(size);
225 res = getResponse(a, true);
226 if (res == RFSV::E_PSI_GEN_NONE && (a.getLen() >= 2))
227 handle = a.getWord(0);
228 return res;
229}
230
233 uint16_t handle;
235
236 ret.init();
237 if ((res = configOpen(handle, size)) != RFSV::E_PSI_GEN_NONE)
238 return res;
239 do {
240 a.init();
241 a.addWord(handle);
242 a.addDWord(2047);
245 if ((res = getResponse(a, true)) != RFSV::E_PSI_GEN_NONE) {
246 closeHandle(handle);
247 return res;
248 }
249 if (a.getLen() > 0)
250 ret.addBuff(a);
251 } while (a.getLen() > 0);
253}
254
257 uint16_t handle;
259
261 if ((res = configOpen(handle, data.getLen())) != RFSV::E_PSI_GEN_NONE)
262 return res;
263 do {
264 a.init();
265 long l = (data.getLen() > 2047) ? 2047 : data.getLen();
266 a.addWord(handle);
267 a.addBuff(data, l);
268 data.discardFirstBytes(l);
271 if ((res = getResponse(a, true)) != RFSV::E_PSI_GEN_NONE) {
272 closeHandle(handle);
273 return res;
274 }
275 } while (data.getLen() > 0);
277}
278
281
282 a.addWord(handle);
285 return getResponse(a, true);
286}
An array of BufferStores.
Definition: bufferarray.h:30
A generic container for an array of bytes.
Definition: bufferstore.h:36
void addBuff(const BufferStore &b, long maxLen=-1)
Appends data to the content of this instance.
Definition: bufferstore.cc:180
void addStringT(const char *s)
Appends a string to the content of this instance.
Definition: bufferstore.cc:169
unsigned long getLen() const
Retrieves the length of a BufferStore.
Definition: bufferstore.cc:92
void discardFirstBytes(int len=0)
Removes bytes from the start of the buffer.
Definition: bufferstore.cc:141
void init()
Initializes the BufferStore.
Definition: bufferstore.cc:74
Wrapper class featuring range-checking and string representation of enumerated values.
Definition: Enum.h:135
Psion time related utility class.
Definition: psitime.h:124
uint32_t getPsiTimeHi(void)
Retrieves the instance's current value in Psion time format, low 32 bits.
Definition: psitime.cc:144
uint32_t getPsiTimeLo(void)
Retrieves the instance's current value in Psion time format, high 32 bits.
Definition: psitime.cc:140
void setZone(psi_timezone &ptz)
Definition: psitime.cc:297
static PsiZone & getInstance()
Retrieve the singleton object.
Definition: psitime.cc:286
errs
The known error codes.
Definition: rfsv.h:113
@ E_PSI_GEN_FAIL
Definition: rfsv.h:115
@ E_PSI_FILE_DISC
Definition: rfsv.h:156
@ E_PSI_GEN_NONE
Definition: rfsv.h:114
@ E_PSI_FILE_EOF
Definition: rfsv.h:142
Enum< RFSV::errs > getCmdLine(const char *, std::string &)
Retrieves the command line of a running process.
Definition: rpcs32.cc:42
Enum< RFSV::errs > closeHandle(uint16_t)
Definition: rpcs32.cc:279
Enum< RFSV::errs > regReadIter(uint16_t handle)
Definition: rpcs32.cc:174
Enum< RFSV::errs > setTime(time_t time)
Definition: rpcs32.cc:191
Enum< RFSV::errs > getOwnerInfo(BufferArray &owner)
Retrieve owner information of the remote machine.
Definition: rpcs32.cc:127
Enum< RFSV::errs > configOpen(uint16_t &, uint32_t)
Prepare scratch RAM in Series 5 for read/write.
Definition: rpcs32.cc:218
RPCS32(std::unique_ptr< TCPSocket > socket)
Definition: rpcs32.cc:36
Enum< RFSV::errs > regOpenIter(uint32_t uid, char *match, uint16_t &handle)
Definition: rpcs32.cc:155
Enum< RFSV::errs > configRead(uint32_t, BufferStore &)
Read from Series 5 scratch RAM.
Definition: rpcs32.cc:231
Enum< RFSV::errs > configWrite(BufferStore)
Write to Series 5 scratch RAM.
Definition: rpcs32.cc:255
Enum< RFSV::errs > getMachineInfo(machineInfo &)
Retrieve general Information about the connected machine.
Definition: rpcs32.cc:56
batterystates
The known battery states.
Definition: rpcs.h:110
languages
The known interface languages.
Definition: rpcs.h:75
std::unique_ptr< TCPSocket > socket_
The socket, used for communication with ncpd.
Definition: rpcs.h:447
machs
The known machine types.
Definition: rpcs.h:57
int mtCacheS5mx
Flag: getMachineType and getMachineInfo have been called and the machine is an S5mx.
Definition: rpcs.h:490
bool sendCommand(enum commands cc, BufferStore &data)
Sends a command to the remote side.
Definition: rpcs.cc:134
void reset()
Initializes a connection to the remote machine.
Definition: rpcs.cc:109
Enum< RFSV::errs > getResponse(BufferStore &data, bool statusIsFirstByte)
Definition: rpcs.cc:156
@ REG_READ_ITER
Definition: rpcs.h:473
@ REG_OPEN_ITER
Definition: rpcs.h:472
@ SET_TIME
Definition: rpcs.h:477
@ CLOSE_HANDLE
Definition: rpcs.h:471
@ GET_CMDLINE
Definition: rpcs.h:468
@ CONFIG_WRITE
Definition: rpcs.h:480
@ CONFIG_OPEN
Definition: rpcs.h:478
@ CONFIG_READ
Definition: rpcs.h:479
@ GET_MACHINE_INFO
Definition: rpcs.h:470
@ GET_OWNERINFO
Definition: rpcs.h:466
Definition: doctest.h:522
static BufferStore owner
Definition: main.cc:60
static RFSV * a
Definition: main.cc:55
This struct holds the data returned by RPCS::getMachineInfo.
Definition: rpcs.h:121
unsigned long ramSize
Definition: rpcs.h:134
unsigned long mainBatteryUsedPower
Definition: rpcs.h:150
Enum< languages > uiLanguage
Definition: rpcs.h:126
unsigned long displayHeight
Definition: rpcs.h:141
unsigned long mainBatteryVoltage
Definition: rpcs.h:151
psi_timeval externalPowerUsedTime
Definition: rpcs.h:158
bool externalPower
Definition: rpcs.h:159
bool romProgrammable
Definition: rpcs.h:132
Enum< batterystates > backupBatteryStatus
Definition: rpcs.h:154
psi_timeval mainBatteryInsertionTime
Definition: rpcs.h:146
psi_timeval time
Definition: rpcs.h:143
Enum< machs > machineType
Definition: rpcs.h:122
unsigned short romMajor
Definition: rpcs.h:128
unsigned long ramDiskSize
Definition: rpcs.h:137
unsigned long mainBatteryCurrent
Definition: rpcs.h:149
psi_timeval mainBatteryUsedTime
Definition: rpcs.h:148
Enum< batterystates > mainBatteryStatus
Definition: rpcs.h:147
unsigned short romBuild
Definition: rpcs.h:130
unsigned long countryCode
Definition: rpcs.h:125
unsigned short romMinor
Definition: rpcs.h:129
char machineName[17]
Definition: rpcs.h:123
unsigned long ramMaxFree
Definition: rpcs.h:136
unsigned long long machineUID
Definition: rpcs.h:124
unsigned long backupBatteryMaxVoltage
Definition: rpcs.h:156
unsigned long registrySize
Definition: rpcs.h:139
unsigned long displayWidth
Definition: rpcs.h:140
unsigned long ramFree
Definition: rpcs.h:135
unsigned long mainBatteryMaxVoltage
Definition: rpcs.h:152
psi_timezone tz
Definition: rpcs.h:144
unsigned long romSize
Definition: rpcs.h:131
unsigned long backupBatteryVoltage
Definition: rpcs.h:155
uint32_t tv_low
The lower 32 bits.
Definition: psitime.h:74
uint32_t tv_high
The upper 32 bits.
Definition: psitime.h:78
holds a Psion time zone description.
Definition: psitime.h:84
unsigned long home_zone
Definition: psitime.h:97
unsigned long dst_zones
Definition: psitime.h:96
signed long utc_offset
Definition: psitime.h:95