rubyfit 0.0.11 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,19 @@
1
- ////////////////////////////////////////////////////////////////////////////////
2
- // The following FIT Protocol software provided may be used with FIT protocol
3
- // devices only and remains the copyrighted property of Dynastream Innovations Inc.
4
- // The software is being provided on an "as-is" basis and as an accommodation,
5
- // and therefore all warranties, representations, or guarantees of any kind
6
- // (whether express, implied or statutory) including, without limitation,
7
- // warranties of merchantability, non-infringement, or fitness for a particular
8
- // purpose, are specifically disclaimed.
9
- //
10
- // Copyright 2016 Dynastream Innovations Inc.
11
- ////////////////////////////////////////////////////////////////////////////////
12
-
13
-
14
- #if !defined(FIT_INCLUDE_H)
15
- #define FIT_INCLUDE_H
16
-
17
- // Add application specific header file includes here.
18
-
19
- #endif // !defined(FIT_INCLUDE_H)
1
+ ////////////////////////////////////////////////////////////////////////////////
2
+ // The following FIT Protocol software provided may be used with FIT protocol
3
+ // devices only and remains the copyrighted property of Garmin Canada Inc.
4
+ // The software is being provided on an "as-is" basis and as an accommodation,
5
+ // and therefore all warranties, representations, or guarantees of any kind
6
+ // (whether express, implied or statutory) including, without limitation,
7
+ // warranties of merchantability, non-infringement, or fitness for a particular
8
+ // purpose, are specifically disclaimed.
9
+ //
10
+ // Copyright 2020 Garmin Canada Inc.
11
+ ////////////////////////////////////////////////////////////////////////////////
12
+
13
+
14
+ #if !defined(FIT_INCLUDE_H)
15
+ #define FIT_INCLUDE_H
16
+
17
+ // Add application specific header file includes here.
18
+
19
+ #endif // !defined(FIT_INCLUDE_H)
@@ -1,203 +1,211 @@
1
- ////////////////////////////////////////////////////////////////////////////////
2
- // The following FIT Protocol software provided may be used with FIT protocol
3
- // devices only and remains the copyrighted property of Dynastream Innovations Inc.
4
- // The software is being provided on an "as-is" basis and as an accommodation,
5
- // and therefore all warranties, representations, or guarantees of any kind
6
- // (whether express, implied or statutory) including, without limitation,
7
- // warranties of merchantability, non-infringement, or fitness for a particular
8
- // purpose, are specifically disclaimed.
9
- //
10
- // Copyright 2016 Dynastream Innovations Inc.
11
- ////////////////////////////////////////////////////////////////////////////////
12
- // ****WARNING**** This file is auto-generated! Do NOT edit this file.
13
- // Profile Version = 20.16Release
14
- // Tag = production/akw/20.16.00-0-gce20b51
15
- // Product = EXAMPLE
16
- // Alignment = 4 bytes, padding disabled.
17
- ////////////////////////////////////////////////////////////////////////////////
18
-
19
-
20
- #include <string.h>
21
-
22
- #include "fit_ram.h"
23
- #include "fit_crc.h"
24
- #include "fit_convert.h"
25
-
26
- #if defined(FIT_RAM_INCLUDE)
27
-
28
- ///////////////////////////////////////////////////////////////////////////////
29
- // Private Variables
30
- ///////////////////////////////////////////////////////////////////////////////
31
-
32
- static FIT_UINT32 read_crc_offset;
33
- static FIT_UINT16 read_crc;
34
-
35
-
36
- ///////////////////////////////////////////////////////////////////////////////
37
- // Public Functions
38
- ///////////////////////////////////////////////////////////////////////////////
39
-
40
- FIT_RAM_FILE FitRAM_LookupFile(FIT_FILE file)
41
- {
42
- FIT_RAM_FILE ram_file;
43
-
44
- for (ram_file = (FIT_RAM_FILE)0; ram_file < FIT_RAM_FILES; ram_file++)
45
- {
46
- if (file == fit_ram_files[ram_file]->file_def->type)
47
- return ram_file;
48
- }
49
-
50
- return FIT_RAM_FILES;
51
- }
52
-
53
- FIT_UINT32 FitRAM_GetFileSize(FIT_RAM_FILE file)
54
- {
55
- if (file >= FIT_RAM_FILES)
56
- return 0;
57
-
58
- return FIT_FILE_HDR_SIZE + fit_ram_files[file]->file_def->data_size + sizeof(FIT_UINT16);
59
- }
60
-
61
- void FitRAM_FileReadBytes(FIT_RAM_FILE file, FIT_UINT16 file_index, FIT_UINT32 file_offset, void *data, FIT_UINT32 data_size)
62
- {
63
- FIT_BYTE *data_ptr = (FIT_BYTE *) data;
64
- const FIT_RAM_FILE_DATA *file_data = fit_ram_files[file]->data;
65
- FIT_UINT16 data_index = 0;
66
- FIT_UINT32 offset = file_offset;
67
- FIT_UINT32 size;
68
- FIT_UINT8 read_crc_size = 0;
69
-
70
- if ((file_offset + data_size) > (FIT_FILE_HDR_SIZE + fit_ram_files[file]->file_def->data_size))
71
- {
72
- read_crc_size = (FIT_UINT8)((file_offset + data_size) - (FIT_FILE_HDR_SIZE + fit_ram_files[file]->file_def->data_size)); // Don't include file crc in copy.
73
- data_size -= read_crc_size;
74
-
75
- if (read_crc_size > 2)
76
- read_crc_size = 2;
77
- }
78
-
79
- if (data_size > 0)
80
- {
81
- do
82
- {
83
- while ((data_index < fit_ram_files[file]->data_count) && ((file_data->file_offset + file_data->size) <= offset))
84
- {
85
- file_data++;
86
- data_index++;
87
- }
88
-
89
- if ((data_index >= fit_ram_files[file]->data_count) || (file_data->file_offset >= (file_offset + data_size)))
90
- {
91
- size = file_offset + data_size - offset;
92
- memcpy(&data_ptr[offset - file_offset], &fit_ram_files[file]->file[offset], size);
93
- offset += size;
94
- break; // Done.
95
- }
96
-
97
- if (offset < file_data->file_offset)
98
- {
99
- size = file_data->file_offset - offset;
100
-
101
- if ((offset + size) > (file_offset + data_size))
102
- size = file_offset + data_size - offset;
103
-
104
- memcpy(&data_ptr[offset - file_offset], &fit_ram_files[file]->file[offset], size);
105
- offset += size;
106
- }
107
-
108
- size = offset + file_data->size;
109
-
110
- if (size > (file_offset + data_size))
111
- size = file_offset + data_size;
112
-
113
- size -= offset;
114
- memcpy(&data_ptr[offset - file_offset], &((FIT_BYTE *)file_data->data)[offset - file_data->file_offset], size);
115
- offset += size;
116
- } while (offset < (file_offset + data_size));
117
-
118
- if (file_offset == 0)
119
- {
120
- read_crc = 0;
121
- read_crc_offset = 0;
122
- }
123
-
124
- if (file_offset > read_crc_offset)
125
- read_crc_offset = file_offset; // Non-contiguous read. CRC will be invalid.
126
-
127
- if ((file_offset + data_size) > read_crc_offset)
128
- read_crc = FitCRC_Update16(read_crc, &data_ptr[read_crc_offset - file_offset], (FIT_UINT8)(file_offset + data_size - read_crc_offset));
129
-
130
- read_crc_offset = file_offset + data_size;
131
- }
132
-
133
- if (read_crc_size > 0)
134
- {
135
- data_ptr[offset - file_offset] = (FIT_BYTE)read_crc;
136
- offset++;
137
-
138
- if (read_crc_size == 1)
139
- return;
140
-
141
- data_ptr[offset - file_offset] = (FIT_BYTE)(read_crc >> 8);
142
- }
143
- }
144
-
145
- void FitRAM_FileWriteBytes(FIT_RAM_FILE file, FIT_UINT16 file_index, FIT_UINT32 file_offset, const void *data, FIT_UINT32 data_size)
146
- {
147
- const FIT_RAM_FILE_DATA *file_data;
148
- FIT_UINT16 data_index;
149
- FIT_BYTE *src;
150
- FIT_BYTE *dest;
151
- FIT_UINT32 size;
152
-
153
- for (data_index = 0; data_index < fit_ram_files[file]->data_count; data_index++)
154
- {
155
- file_data = &fit_ram_files[file]->data[data_index];
156
-
157
- if (file_data->file_offset >= (file_offset + data_size))
158
- return; // Data start is after end of write so we are done.
159
-
160
- if (file_offset >= (file_data->file_offset + file_data->size))
161
- continue; // Data end is after write so continue to next data element.
162
-
163
- src = (FIT_BYTE *) data;
164
- dest = (FIT_BYTE *) file_data->data;
165
- size = data_size;
166
-
167
- if (file_offset < file_data->file_offset)
168
- {
169
- size -= file_data->file_offset - file_offset;
170
- src += file_data->file_offset - file_offset;
171
- }
172
- else
173
- {
174
- dest += file_offset - file_data->file_offset;
175
- }
176
-
177
- if (size > file_data->size)
178
- size = file_data->size;
179
-
180
- memcpy(dest, src, size);
181
- }
182
- }
183
-
184
- void FitRAM_FileWriteMesg(FIT_RAM_FILE file, FIT_UINT16 file_index, FIT_UINT16 mesg_num, const void *mesg_data, FIT_BOOL restore_fields)
185
- {
186
- FIT_UINT32 offset;
187
- FIT_UINT8 size;
188
- FIT_BYTE old_mesg[FIT_MESG_SIZE];
189
-
190
- offset = Fit_GetFileMesgOffset(fit_ram_files[file]->file_def, mesg_num, 0);
191
- size = Fit_GetMesgSize(mesg_num);
192
-
193
- if (restore_fields)
194
- {
195
- FitRAM_FileReadBytes(file, file_index, offset, old_mesg, size);
196
- FitConvert_RestoreFields(old_mesg);
197
- }
198
-
199
- FitRAM_FileWriteBytes(file, file_index, offset, mesg_data, size);
200
- }
201
-
202
- #endif // defined(FIT_RAM_INCLUDE)
203
-
1
+ ////////////////////////////////////////////////////////////////////////////////
2
+ // The following FIT Protocol software provided may be used with FIT protocol
3
+ // devices only and remains the copyrighted property of Garmin Canada Inc.
4
+ // The software is being provided on an "as-is" basis and as an accommodation,
5
+ // and therefore all warranties, representations, or guarantees of any kind
6
+ // (whether express, implied or statutory) including, without limitation,
7
+ // warranties of merchantability, non-infringement, or fitness for a particular
8
+ // purpose, are specifically disclaimed.
9
+ //
10
+ // Copyright 2020 Garmin Canada Inc.
11
+ ////////////////////////////////////////////////////////////////////////////////
12
+ // ****WARNING**** This file is auto-generated! Do NOT edit this file.
13
+ // Profile Version = 21.27Release
14
+ // Tag = production/akw/21.27.00-0-gef9575d
15
+ // Product = EXAMPLE
16
+ // Alignment = 4 bytes, padding disabled.
17
+ ////////////////////////////////////////////////////////////////////////////////
18
+
19
+
20
+ #include <string.h>
21
+
22
+ #include "fit_ram.h"
23
+ #include "fit_crc.h"
24
+ #include "fit_convert.h"
25
+
26
+ #if defined(FIT_RAM_INCLUDE)
27
+
28
+ ///////////////////////////////////////////////////////////////////////////////
29
+ // Private Variables
30
+ ///////////////////////////////////////////////////////////////////////////////
31
+
32
+ static FIT_UINT32 read_crc_offset;
33
+ static FIT_UINT16 read_crc;
34
+
35
+
36
+ ///////////////////////////////////////////////////////////////////////////////
37
+ // Public Functions
38
+ ///////////////////////////////////////////////////////////////////////////////
39
+
40
+ FIT_RAM_FILE FitRAM_LookupFile(FIT_FILE file)
41
+ {
42
+ FIT_RAM_FILE ram_file;
43
+
44
+ for (ram_file = (FIT_RAM_FILE)0; ram_file < FIT_RAM_FILES; ram_file++)
45
+ {
46
+ if (file == fit_ram_files[ram_file]->file_def->type)
47
+ return ram_file;
48
+ }
49
+
50
+ return FIT_RAM_FILES;
51
+ }
52
+
53
+ FIT_UINT32 FitRAM_GetFileSize(FIT_RAM_FILE file)
54
+ {
55
+ if (file >= FIT_RAM_FILES)
56
+ return 0;
57
+
58
+ return FIT_FILE_HDR_SIZE + fit_ram_files[file]->file_def->data_size + sizeof(FIT_UINT16);
59
+ }
60
+
61
+ void FitRAM_FileReadBytes(FIT_RAM_FILE file, FIT_UINT16 file_index, FIT_UINT32 file_offset, void *data, FIT_UINT32 data_size)
62
+ {
63
+ FIT_BYTE *data_ptr = (FIT_BYTE *) data;
64
+ const FIT_RAM_FILE_DATA *file_data = fit_ram_files[file]->data;
65
+ FIT_UINT16 data_index = 0;
66
+ FIT_UINT32 offset = file_offset;
67
+ FIT_UINT32 size;
68
+ FIT_UINT8 read_crc_size = 0;
69
+
70
+ if ((file_offset + data_size) > (FIT_FILE_HDR_SIZE + fit_ram_files[file]->file_def->data_size))
71
+ {
72
+ read_crc_size = (FIT_UINT8)((file_offset + data_size) - (FIT_FILE_HDR_SIZE + fit_ram_files[file]->file_def->data_size)); // Don't include file crc in copy.
73
+ data_size -= read_crc_size;
74
+
75
+ if (read_crc_size > 2)
76
+ read_crc_size = 2;
77
+ }
78
+
79
+ if (data_size > 0)
80
+ {
81
+ do
82
+ {
83
+ while ((data_index < fit_ram_files[file]->data_count) && ((file_data->file_offset + file_data->size) <= offset))
84
+ {
85
+ file_data++;
86
+ data_index++;
87
+ }
88
+
89
+ if ((data_index >= fit_ram_files[file]->data_count) || (file_data->file_offset >= (file_offset + data_size)))
90
+ {
91
+ size = file_offset + data_size - offset;
92
+ memcpy(&data_ptr[offset - file_offset], &fit_ram_files[file]->file[offset], size);
93
+ offset += size;
94
+ break; // Done.
95
+ }
96
+
97
+ if (offset < file_data->file_offset)
98
+ {
99
+ size = file_data->file_offset - offset;
100
+
101
+ if ((offset + size) > (file_offset + data_size))
102
+ size = file_offset + data_size - offset;
103
+
104
+ memcpy(&data_ptr[offset - file_offset], &fit_ram_files[file]->file[offset], size);
105
+ offset += size;
106
+ }
107
+
108
+ size = offset + file_data->size;
109
+
110
+ if (size > (file_offset + data_size))
111
+ size = file_offset + data_size;
112
+
113
+ size -= offset;
114
+ memcpy(&data_ptr[offset - file_offset], &((FIT_BYTE *)file_data->data)[offset - file_data->file_offset], size);
115
+ offset += size;
116
+ } while (offset < (file_offset + data_size));
117
+
118
+ if (file_offset == 0)
119
+ {
120
+ read_crc = 0;
121
+ read_crc_offset = 0;
122
+ }
123
+
124
+ if (file_offset > read_crc_offset)
125
+ read_crc_offset = file_offset; // Non-contiguous read. CRC will be invalid.
126
+
127
+ if ((file_offset + data_size) > read_crc_offset)
128
+ read_crc = FitCRC_Update16(read_crc, &data_ptr[read_crc_offset - file_offset], (FIT_UINT8)(file_offset + data_size - read_crc_offset));
129
+
130
+ read_crc_offset = file_offset + data_size;
131
+ }
132
+
133
+ if (read_crc_size > 0)
134
+ {
135
+ data_ptr[offset - file_offset] = (FIT_BYTE)read_crc;
136
+ offset++;
137
+
138
+ if (read_crc_size == 1)
139
+ return;
140
+
141
+ data_ptr[offset - file_offset] = (FIT_BYTE)(read_crc >> 8);
142
+ }
143
+ }
144
+
145
+ void FitRAM_FileWriteBytes(FIT_RAM_FILE file, FIT_UINT16 file_index, FIT_UINT32 file_offset, const void *data, FIT_UINT32 data_size)
146
+ {
147
+ const FIT_RAM_FILE_DATA *file_data;
148
+ FIT_UINT16 data_index;
149
+ FIT_BYTE *src;
150
+ FIT_BYTE *dest;
151
+ FIT_UINT32 size;
152
+
153
+ for (data_index = 0; data_index < fit_ram_files[file]->data_count; data_index++)
154
+ {
155
+ file_data = &fit_ram_files[file]->data[data_index];
156
+
157
+ if (file_data->file_offset >= (file_offset + data_size))
158
+ return; // Data start is after end of write so we are done.
159
+
160
+ if (file_offset >= (file_data->file_offset + file_data->size))
161
+ continue; // Data end is after write so continue to next data element.
162
+
163
+ src = (FIT_BYTE *) data;
164
+ dest = (FIT_BYTE *) file_data->data;
165
+ size = data_size;
166
+
167
+ if (file_offset < file_data->file_offset)
168
+ {
169
+ size -= file_data->file_offset - file_offset;
170
+ src += file_data->file_offset - file_offset;
171
+ }
172
+ else
173
+ {
174
+ dest += file_offset - file_data->file_offset;
175
+ }
176
+
177
+ if (size > file_data->size)
178
+ size = file_data->size;
179
+
180
+ memcpy(dest, src, size);
181
+ }
182
+ }
183
+
184
+ #if defined(FIT_CONVERT_MULTI_THREAD)
185
+ void FitRAM_FileWriteMesg(FIT_CONVERT_STATE *state, FIT_RAM_FILE file, FIT_UINT16 file_index, FIT_UINT16 mesg_num, const void *mesg_data, FIT_BOOL restore_fields)
186
+ #else
187
+ void FitRAM_FileWriteMesg(FIT_RAM_FILE file, FIT_UINT16 file_index, FIT_UINT16 mesg_num, const void *mesg_data, FIT_BOOL restore_fields)
188
+ #endif
189
+ {
190
+ FIT_UINT32 offset;
191
+ FIT_UINT8 size;
192
+ FIT_BYTE old_mesg[FIT_MESG_SIZE];
193
+
194
+ offset = Fit_GetFileMesgOffset(fit_ram_files[file]->file_def, mesg_num, 0);
195
+ size = Fit_GetMesgSize(mesg_num);
196
+
197
+ if (restore_fields)
198
+ {
199
+ FitRAM_FileReadBytes(file, file_index, offset, old_mesg, size);
200
+ #if defined(FIT_CONVERT_MULTI_THREAD)
201
+ FitConvert_RestoreFields(state, old_mesg);
202
+ #else
203
+ FitConvert_RestoreFields(old_mesg);
204
+ #endif
205
+ }
206
+
207
+ FitRAM_FileWriteBytes(file, file_index, offset, mesg_data, size);
208
+ }
209
+
210
+ #endif // defined(FIT_RAM_INCLUDE)
211
+