1
1
/* Hey EMACS -*- linux-c -*- */
2
/* $Id: dbus_pkt.c 4166 2008-04-09 15:57:23Z roms $ */
4
4
/* libticalcs - Ti Calculator library, a part of the TiLP project
5
5
* Copyright (C) 1999-2005 Romain Li�vin
15
15
* GNU General Public License for more details.
17
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
* along with this program; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26
26
#include <string.h>
28
28
#include "ticalcs.h"
29
30
#include "dbus_pkt.h"
30
31
#include "logging.h"
32
33
#include "macros.h"
34
35
// We split packets into chucks to get control regularly and update statistics.
35
static unsigned int BLK_SIZE; // refresh pbars every 5%
36
static unsigned int MIN_SIZE; // don't refresh at all if packet is < 512 bytes
36
static unsigned int BLK_SIZE; // refresh pbars every 5%
37
static unsigned int MIN_SIZE; // don't refresh at all if packet is < 512 bytes
39
40
Send a packet from PC (host) to TI (target):
40
41
- target [in] : a machine ID uint8_t
41
- cmd [in] : a command ID uint8_t
42
- cmd [in] : a command ID uint8_t
42
43
- length [in] : length of buffer
43
- data [in] : data to send (or 0x00 if NULL)
44
- int [out] : an error code
44
- data [in] : data to send (or 0x00 if NULL)
45
- int [out] : an error code
46
int dbus_send(CalcHandle* handle, uint8_t target, uint8_t cmd, uint16_t len, uint8_t* data)
47
TIEXPORT3 int TICALL dbus_send(CalcHandle* handle, uint8_t target, uint8_t cmd, uint16_t len, uint8_t* data)
50
uint32_t length = (len == 0x0000) ? 65536 : len; // wrap around
51
uint8_t *buf = (uint8_t *)handle->priv2; //[65536+6];
51
uint32_t length = (len == 0x0000) ? 65536 : len; // wrap around
53
54
static int ref = 0;
58
ticalcs_critical("%s: handle is NULL", __FUNCTION__);
59
return ERR_INVALID_HANDLE;
61
buf = (uint8_t *)handle->priv2; //[65536+6];
64
ticalcs_critical("%s: handle->priv2 is NULL", __FUNCTION__);
65
return ERR_INVALID_HANDLE;
55
68
ticables_progress_reset(handle->cable);
65
TRYF(ticables_cable_send(handle->cable, buf, 4));
78
// TI80 does not use length
81
TRYF(ticables_cable_send(handle->cable, buf, 2));
85
TRYF(ticables_cable_send(handle->cable, buf, 4));
181
193
static int ref = 0;
183
// Any packet has always at least 4 bytes (MID, CID, LEN)
184
TRYF(ticables_cable_recv(handle->cable, buf, 4));
197
ticalcs_critical("%s: handle is NULL", __FUNCTION__);
198
return ERR_INVALID_HANDLE;
200
if (host == NULL || cmd == NULL || length == NULL)
202
ticalcs_critical("%s: an argument is NULL", __FUNCTION__);
203
return ERR_INVALID_PACKET;
206
// Any packet has always at least 2 bytes (MID, CID)
207
TRYF(ticables_cable_recv(handle->cable, buf, 2));
188
*length = buf[2] | (buf[3] << 8);
212
// Any non-TI80 packet has a length; TI80 data packets also have a length
213
if(*host != TI80_PC || *cmd == CMD_XDP)
215
TRYF(ticables_cable_recv(handle->cable, buf, 2));
217
*length = buf[0] | (buf[1] << 8);
190
221
//removed for probing (pb here !)
191
222
//if(host_check && (*host != host_ids(handle)))
192
223
// return ERR_INVALID_HOST;
194
if(*cmd == CMD_ERR ||*cmd == CMD_ERR2)
225
if(*cmd == CMD_ERR || *cmd == CMD_ERR2)
195
226
return ERR_CHECKSUM;
280
317
- data [out] : received data (depending on command)
281
318
- int [out] : an error code
283
int dbus_recv(CalcHandle* handle, uint8_t* host, uint8_t* cmd, uint16_t* length, uint8_t* data)
320
TIEXPORT3 int TICALL dbus_recv(CalcHandle* handle, uint8_t* host, uint8_t* cmd, uint16_t* length, uint8_t* data)
285
322
return dbus_recv_(handle, host, cmd, length, data, !0);
325
// used only by probe.c
288
326
int dbus_recv_2(CalcHandle* handle, uint8_t* host, uint8_t* cmd, uint16_t* length, uint8_t* data)
290
328
return dbus_recv_(handle, host, cmd, length, data, 0);
293
/* Fill-up a 8-chars buffer with NUL chars */
294
void pad_buffer(uint8_t *varname, uint8_t value)
331
//! Fill up to 8 chars the \a varname buffer with chars of value \a value.
332
void pad_buffer_to_8_chars(uint8_t *varname, uint8_t value)
297
unsigned int len = strlen((char*)varname);
299
for (i = len; i < 8; i++)
339
len = strlen((char*)varname);
341
for (i = len; i < 8; i++)