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
|
/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Initial Developer of this code is David Baum.
* Portions created by David Baum are Copyright (C) 1998 David Baum.
* All Rights Reserved.
*/
#include <stdio.h>
#include <string.h>
#include "RCX_Log.h"
#include "RCX_Cmd.h"
#include "RCX_Link.h"
#define kPointsPerUpload 10
RCX_Log::RCX_Log()
{
fLength = 0;
fData = nil;
fTypes = nil;
}
RCX_Log::~RCX_Log()
{
SetLength(0);
}
void RCX_Log::SetLength(int length)
{
// clear old data
if (fLength)
{
delete [] fData;
delete [] fTypes;
}
if (length)
{
fData = new short[length];
fTypes = new UByte[length];
}
else
{
fData = nil;
fTypes = nil;
}
fLength = length;
}
RCX_Result RCX_Log::Upload(RCX_Link *link)
{
RCX_Result result;
RCX_Cmd cmd;
int length;
int i;
int pos, n;
link->Sync();
// get length of log
result = link->Send(cmd.MakeUploadDatalog(0, 1));
if (result < 0) return result;
if (result != 3) return kRCX_ReplyError;
// figure out length of data (don't include the length entry itself)
length = (link->GetReplyByte(1) + (link->GetReplyByte(2) << 8)) - 1;
SetLength(length);
for(pos = 0; pos<length; )
{
// how many points to upload
n = length - pos;
if (n > kPointsPerUpload)
n = kPointsPerUpload;
// upload the data itself
result = link->Send(cmd.MakeUploadDatalog(pos+1, n));
if (result < 0) return result;
if (result != n * 3) return kRCX_ReplyError;
// copy data into log
for(i=0; i<n; i++)
{
fTypes[pos+i] = link->GetReplyByte(i*3);
fData[pos+i] = (short)(link->GetReplyByte(i*3+1) +
((UShort)link->GetReplyByte(i*3+2) << 8));
}
pos += n;
if (!link->DownloadProgress(pos, length)) break;
}
return pos;
}
void RCX_Log::SPrintEntry(char *buf, int index, bool verbose) const
{
if (verbose)
{
UByte type = GetType(index);
switch(type & 0xe0)
{
case 0:
sprintf(buf, "Variable %d: ", type & 0x1f);
break;
case 0x20:
sprintf(buf, "Timer %d: ", type & 0x1f);
break;
case 0x40:
sprintf(buf, "Sensor %d: ", (type & 0x1f) + 1);
break;
case 0x80:
sprintf(buf, "Watch: ");
break;
default:
sprintf(buf, "%02x: ", type);
break;
}
buf += strlen(buf);
}
sprintf(buf, "%d", GetData(index));
}
|