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 <stdio.h>
30#include <stdlib.h>
31#include <time.h>
32
33using namespace std;
34
36{
37 skt = _skt;
38 mtCacheS5mx = 0;
39 reset();
40}
41
43getCmdLine(const char *process, string &ret)
44{
47
48 a.addStringT(process);
51 if ((res = getResponse(a, true)) == rfsv::E_PSI_GEN_NONE)
52 ret = a.getString(0);
53 return res;
54}
55
58{
61
64 if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
65 return res;
66 if (a.getLen() != 256)
68 mi.machineType = (enum rpcs::machs)a.getDWord(0);
69 strncpy(mi.machineName, a.getString(16), 16);
70 mi.machineName[16] = '\0';
71 mi.machineUID = a.getDWord(44);
72 mi.machineUID <<= 32;
73 mi.machineUID |= a.getDWord(40);
74 mi.countryCode = a.getDWord(56);
75 mi.uiLanguage = (enum rpcs::languages)a.getDWord(164);
76
77 mi.romMajor = a.getByte(4);
78 mi.romMinor = a.getByte(5);
79 mi.romBuild = a.getWord(6);
80 mi.romSize = a.getDWord(140);
81
82 mi.ramSize = a.getDWord(136);
83 mi.ramMaxFree = a.getDWord(144);
84 mi.ramFree = a.getDWord(148);
85 mi.ramDiskSize = a.getDWord(152);
86
87 mi.registrySize = a.getDWord(156);
88 mi.romProgrammable = (a.getDWord(160) != 0);
89
90 mi.displayWidth = a.getDWord(32);
91 mi.displayHeight = a.getDWord(36);
92
93 mi.time.tv_low = a.getDWord(48);
94 mi.time.tv_high = a.getDWord(52);
95
96 mi.tz.utc_offset = a.getSDWord(60);
97 mi.tz.dst_zones = a.getDWord(64);
98 mi.tz.home_zone = a.getDWord(68);
99
101
102 mi.mainBatteryInsertionTime.tv_low = a.getDWord(72);
103 mi.mainBatteryInsertionTime.tv_high = a.getDWord(76);
104 mi.mainBatteryStatus = (enum rpcs::batterystates)a.getDWord(80);
105 mi.mainBatteryUsedTime.tv_low = a.getDWord(84);
106 mi.mainBatteryUsedTime.tv_high = a.getDWord(88);
107 mi.mainBatteryCurrent = a.getDWord(92);
108 mi.mainBatteryUsedPower = a.getDWord(96);
109 mi.mainBatteryVoltage = a.getDWord(100);
110 mi.mainBatteryMaxVoltage = a.getDWord(104);
111
112 mi.backupBatteryStatus = (enum rpcs::batterystates)a.getDWord(108);
113 mi.backupBatteryVoltage = a.getDWord(112);
114 mi.backupBatteryMaxVoltage = a.getDWord(116);
115 mi.externalPowerUsedTime.tv_low = a.getDWord(124);
116 mi.externalPowerUsedTime.tv_high = a.getDWord(128);
117 mi.externalPower = (a.getDWord(120) != 0);
118
119 mtCacheS5mx |= 8;
120 if (res == rfsv::E_PSI_GEN_NONE) {
121 if (!strcmp(mi.machineName, "SERIES5mx"))
122 mtCacheS5mx |= 2;
123 }
124
125 return res;
126}
127
130{
133
136 if ((res = (enum rfsv::errs)getResponse(a, true)) != rfsv::E_PSI_GEN_NONE)
137 return res;
138 a.addByte(0);
139 string s = a.getString(0);
140 owner.clear();
141 int p = 0;
142 int l;
143 while ((l = s.find('\006', p)) != s.npos) {
144 bufferStore b;
145 b.addStringT(s.substr(p, l - p).c_str());
146 owner += b;
147 p = l + 1;
148 }
149 if (s.substr(p).length()) {
150 bufferStore b;
151 b.addStringT(s.substr(p).c_str());
152 owner += b;
153 }
154 return res;
155}
156
158regOpenIter(uint32_t uid, char *match, uint16_t &handle)
159{
162
163 cout << "Oiter" << endl;
164 a.addDWord(uid);
165 a.addDWord(strlen(match));
166 a.addStringT(match);
169 res = getResponse(a, true);
170 cout << "ro: r=" << res << " a=" << a << endl;
171 if (a.getLen() == 2)
172 handle = a.getWord(0);
174}
175
177regReadIter(uint16_t handle)
178{
181
182 cout << "Riter" << endl;
183 a.addWord(handle);
186 res = getResponse(a, true);
187 cout << "ro: r=" << res << " a=" << a << endl;
188 if ((a.getLen() == 3) && (a.getByte(2) == 0xff))
191}
192
194setTime(time_t time)
195{
198 PsiTime pt;
199 psi_timezone ptz;
201
202 // cout << "settime" << endl;
203 if ((res = getMachineInfo(mi)) == rfsv::E_PSI_GEN_NONE) {
204 if (PsiZone::getInstance().getZone(ptz)) {
205 pt = PsiTime(time + ptz.utc_offset);
206 a.addDWord(pt.getPsiTimeLo());
207 a.addDWord(pt.getPsiTimeHi());
208 a.addDWord(mi.countryCode);
209 a.addDWord(ptz.utc_offset);
210 a.addDWord(ptz.dst_zones);
211 a.addDWord(ptz.home_zone);
212 // cout << "a=" << a << endl;
216 } else
218 } else
219 return res;
220}
221
223configOpen(uint16_t &handle, uint32_t size)
224{
227
228 a.addDWord(size);
231 res = getResponse(a, true);
232 if (res == rfsv::E_PSI_GEN_NONE && (a.getLen() >= 2))
233 handle = a.getWord(0);
234 return res;
235}
236
238configRead(uint32_t size, bufferStore &ret)
239{
241 uint16_t handle;
243
244 ret.init();
245 if ((res = configOpen(handle, size)) != rfsv::E_PSI_GEN_NONE)
246 return res;
247 do {
248 a.init();
249 a.addWord(handle);
250 a.addDWord(2047);
253 if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE) {
254 closeHandle(handle);
255 return res;
256 }
257 if (a.getLen() > 0)
258 ret.addBuff(a);
259 } while (a.getLen() > 0);
261}
262
265{
267 uint16_t handle;
269
271 if ((res = configOpen(handle, data.getLen())) != rfsv::E_PSI_GEN_NONE)
272 return res;
273 do {
274 a.init();
275 long l = (data.getLen() > 2047) ? 2047 : data.getLen();
276 a.addWord(handle);
277 a.addBuff(data, l);
278 data.discardFirstBytes(l);
281 if ((res = getResponse(a, true)) != rfsv::E_PSI_GEN_NONE) {
282 closeHandle(handle);
283 return res;
284 }
285 } while (data.getLen() > 0);
287}
288
290closeHandle(uint16_t handle)
291{
293
294 a.addWord(handle);
297 return getResponse(a, true);
298}
Wrapper class featuring range-checking and string representation of enumerated values.
Definition: Enum.h:136
Psion time related utility class.
Definition: psitime.h:125
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
A class for dealing with sockets.
Definition: tcpsocket.h:38
An array of bufferStores.
Definition: bufferarray.h:31
A generic container for an array of bytes.
Definition: bufferstore.h:37
void discardFirstBytes(int len=0)
Removes bytes from the start of the buffer.
Definition: bufferstore.cc:143
void init()
Initializes the bufferStore.
Definition: bufferstore.cc:77
void addBuff(const bufferStore &b, long maxLen=-1)
Appends data to the content of this instance.
Definition: bufferstore.cc:182
void addStringT(const char *s)
Appends a string to the content of this instance.
Definition: bufferstore.cc:171
unsigned long getLen() const
Retrieves the length of a bufferStore.
Definition: bufferstore.cc:94
errs
The known error codes.
Definition: rfsv.h:109
@ E_PSI_GEN_NONE
Definition: rfsv.h:110
@ E_PSI_FILE_EOF
Definition: rfsv.h:138
@ E_PSI_GEN_FAIL
Definition: rfsv.h:111
@ E_PSI_FILE_DISC
Definition: rfsv.h:152
Enum< rfsv::errs > setTime(time_t time)
Definition: rpcs32.cc:194
Enum< rfsv::errs > getOwnerInfo(bufferArray &owner)
Retrieve owner information of the remote machine.
Definition: rpcs32.cc:129
Enum< rfsv::errs > regReadIter(uint16_t handle)
Definition: rpcs32.cc:177
rpcs32(TCPSocket *)
Definition: rpcs32.cc:35
Enum< rfsv::errs > getMachineInfo(machineInfo &)
Retrieve general Information about the connected machine.
Definition: rpcs32.cc:57
Enum< rfsv::errs > closeHandle(uint16_t)
Definition: rpcs32.cc:290
Enum< rfsv::errs > getCmdLine(const char *, std::string &)
Retrieves the command line of a running process.
Definition: rpcs32.cc:43
Enum< rfsv::errs > configWrite(bufferStore)
Write to Series 5 scratch RAM.
Definition: rpcs32.cc:264
Enum< rfsv::errs > configRead(uint32_t, bufferStore &)
Read from Series 5 scratch RAM.
Definition: rpcs32.cc:238
Enum< rfsv::errs > configOpen(uint16_t &, uint32_t)
Prepare scratch RAM in Series 5 for read/write.
Definition: rpcs32.cc:223
Enum< rfsv::errs > regOpenIter(uint32_t uid, char *match, uint16_t &handle)
Definition: rpcs32.cc:158
machs
The known machine types.
Definition: rpcs.h:56
TCPSocket * skt
The socket, used for communication with ncpd.
Definition: rpcs.h:420
languages
The known interface languages.
Definition: rpcs.h:74
bool sendCommand(enum commands cc, bufferStore &data)
Sends a command to the remote side.
Definition: rpcs.cc:135
@ CONFIG_READ
Definition: rpcs.h:452
@ REG_OPEN_ITER
Definition: rpcs.h:445
@ CONFIG_WRITE
Definition: rpcs.h:453
@ GET_CMDLINE
Definition: rpcs.h:441
@ CONFIG_OPEN
Definition: rpcs.h:451
@ SET_TIME
Definition: rpcs.h:450
@ CLOSE_HANDLE
Definition: rpcs.h:444
@ REG_READ_ITER
Definition: rpcs.h:446
@ GET_MACHINE_INFO
Definition: rpcs.h:443
@ GET_OWNERINFO
Definition: rpcs.h:439
batterystates
The known battery states.
Definition: rpcs.h:109
Enum< rfsv::errs > getResponse(bufferStore &data, bool statusIsFirstByte)
Definition: rpcs.cc:157
void reset()
Initializes a connection to the remote machine.
Definition: rpcs.cc:105
int mtCacheS5mx
Flag: getMachineType and getMachineInfo have been called and the machine is an S5mx.
Definition: rpcs.h:463
Definition: doctest.h:522
static bufferStore owner
Definition: main.cc:58
static rfsv * a
Definition: main.cc:53
uint32_t tv_low
The lower 32 bits.
Definition: psitime.h:75
uint32_t tv_high
The upper 32 bits.
Definition: psitime.h:79
holds a Psion time zone description.
Definition: psitime.h:85
unsigned long home_zone
Definition: psitime.h:98
unsigned long dst_zones
Definition: psitime.h:97
signed long utc_offset
Definition: psitime.h:96
This struct holds the data returned by rpcs::getMachineInfo.
Definition: rpcs.h:120
Enum< languages > uiLanguage
Definition: rpcs.h:125
psi_timeval time
Definition: rpcs.h:142
unsigned short romMajor
Definition: rpcs.h:127
psi_timeval mainBatteryUsedTime
Definition: rpcs.h:147
psi_timezone tz
Definition: rpcs.h:143
unsigned long displayWidth
Definition: rpcs.h:139
unsigned long long machineUID
Definition: rpcs.h:123
unsigned short romBuild
Definition: rpcs.h:129
Enum< batterystates > backupBatteryStatus
Definition: rpcs.h:153
psi_timeval externalPowerUsedTime
Definition: rpcs.h:157
Enum< batterystates > mainBatteryStatus
Definition: rpcs.h:146
unsigned long ramMaxFree
Definition: rpcs.h:135
unsigned short romMinor
Definition: rpcs.h:128
unsigned long mainBatteryVoltage
Definition: rpcs.h:150
unsigned long countryCode
Definition: rpcs.h:124
unsigned long ramFree
Definition: rpcs.h:134
unsigned long mainBatteryUsedPower
Definition: rpcs.h:149
char machineName[17]
Definition: rpcs.h:122
unsigned long ramSize
Definition: rpcs.h:133
unsigned long romSize
Definition: rpcs.h:130
unsigned long ramDiskSize
Definition: rpcs.h:136
unsigned long displayHeight
Definition: rpcs.h:140
unsigned long backupBatteryMaxVoltage
Definition: rpcs.h:155
psi_timeval mainBatteryInsertionTime
Definition: rpcs.h:145
unsigned long mainBatteryMaxVoltage
Definition: rpcs.h:151
unsigned long mainBatteryCurrent
Definition: rpcs.h:148
unsigned long registrySize
Definition: rpcs.h:138
unsigned long backupBatteryVoltage
Definition: rpcs.h:154
bool externalPower
Definition: rpcs.h:158
Enum< machs > machineType
Definition: rpcs.h:121
bool romProgrammable
Definition: rpcs.h:131