Subversion Repositories svn.mios32

Rev

Rev 1754 | Rev 1810 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1052 tk 1
// $Id: seq_file_gc.c 1794 2013-05-31 19:25:43Z tk $
2
/*
3
 * Global Config File access functions
4
 *
5
 * NOTE: before accessing the SD Card, the upper level function should
6
 * synchronize with the SD Card semaphore!
7
 *   MUTEX_SDCARD_TAKE; // to take the semaphore
8
 *   MUTEX_SDCARD_GIVE; // to release the semaphore
9
 *
10
 * ==========================================================================
11
 *
12
 *  Copyright (C) 2008 Thorsten Klose (tk@midibox.org)
13
 *  Licensed for personal non-commercial use only.
14
 *  All other rights reserved.
15
 *
16
 * ==========================================================================
17
 */
18
 
19
/////////////////////////////////////////////////////////////////////////////
20
// Include files
21
/////////////////////////////////////////////////////////////////////////////
22
 
23
#include <mios32.h>
24
#include "tasks.h"
25
 
26
#include <string.h>
27
 
1311 tk 28
#include <osc_client.h>
29
 
1261 tk 30
#include "file.h"
1052 tk 31
#include "seq_file.h"
32
#include "seq_file_gc.h"
33
#include "seq_file_b.h"
34
 
35
 
36
#include "seq_ui.h"
37
#include "seq_bpm.h"
38
#include "seq_song.h"
39
#include "seq_mixer.h"
40
#include "seq_midi_in.h"
1323 tk 41
#include "seq_midi_port.h"
1052 tk 42
#include "seq_midi_router.h"
1316 tk 43
#include "seq_midi_sysex.h"
1052 tk 44
#include "seq_pattern.h"
1754 tk 45
#include "seq_record.h"
1052 tk 46
#include "seq_core.h"
1083 tk 47
#include "seq_cv.h"
1316 tk 48
#include "seq_blm.h"
49
 
1052 tk 50
#if !defined(MIOS32_FAMILY_EMULATION)
51
#include "uip.h"
52
#include "uip_task.h"
53
#include "osc_server.h"
54
#endif
55
 
56
 
57
/////////////////////////////////////////////////////////////////////////////
58
// for optional debugging messages via DEBUG_MSG (defined in mios32_config.h)
59
/////////////////////////////////////////////////////////////////////////////
60
 
61
// Note: verbose level 1 is default - it prints error messages!
62
#define DEBUG_VERBOSE_LEVEL 1
63
 
64
 
65
/////////////////////////////////////////////////////////////////////////////
66
// Local definitions
67
/////////////////////////////////////////////////////////////////////////////
68
 
69
// in which subdirectory of the SD card are the MBSEQ files located?
70
// use "/" for root
71
// use "/<dir>/" for a subdirectory in root
72
// use "/<dir>/<subdir>/" to reach a subdirectory in <dir>, etc..
73
 
74
#define SEQ_FILES_PATH "/"
75
//#define SEQ_FILES_PATH "/MySongs/"
76
 
77
 
78
/////////////////////////////////////////////////////////////////////////////
79
// Local types
80
/////////////////////////////////////////////////////////////////////////////
81
 
82
// file informations stored in RAM
83
typedef struct {
84
  unsigned valid: 1;   // file is accessible
85
} seq_file_gc_info_t;
86
 
87
 
88
/////////////////////////////////////////////////////////////////////////////
89
// Local prototypes
90
/////////////////////////////////////////////////////////////////////////////
91
 
92
 
93
/////////////////////////////////////////////////////////////////////////////
94
// Local variables
95
/////////////////////////////////////////////////////////////////////////////
96
 
97
static seq_file_gc_info_t seq_file_gc_info;
98
 
99
 
100
/////////////////////////////////////////////////////////////////////////////
101
// Initialisation
102
/////////////////////////////////////////////////////////////////////////////
103
s32 SEQ_FILE_GC_Init(u32 mode)
104
{
105
  // invalidate file info
106
  SEQ_FILE_GC_Unload();
107
 
108
  return 0; // no error
109
}
110
 
111
 
112
/////////////////////////////////////////////////////////////////////////////
113
// Loads global config file
114
// Called from SEQ_FILE_GCheckSDCard() when the SD card has been connected
115
// returns < 0 on errors
116
/////////////////////////////////////////////////////////////////////////////
117
s32 SEQ_FILE_GC_Load(void)
118
{
119
  s32 error;
120
  error = SEQ_FILE_GC_Read();
121
#if DEBUG_VERBOSE_LEVEL >= 2
122
  DEBUG_MSG("[SEQ_FILE_GC] Tried to open global config file, status: %d\n", error);
123
#endif
124
 
125
  return error;
126
}
127
 
128
 
129
/////////////////////////////////////////////////////////////////////////////
130
// Unloads global config file
131
// Called from SEQ_FILE_GCheckSDCard() when the SD card has been disconnected
132
// returns < 0 on errors
133
/////////////////////////////////////////////////////////////////////////////
134
s32 SEQ_FILE_GC_Unload(void)
135
{
136
  seq_file_gc_info.valid = 0;
137
 
138
  return 0; // no error
139
}
140
 
141
 
142
 
143
/////////////////////////////////////////////////////////////////////////////
144
// Returns 1 if global config file valid
145
// Returns 0 if global config file not valid
146
/////////////////////////////////////////////////////////////////////////////
147
s32 SEQ_FILE_GC_Valid(void)
148
{
149
  return seq_file_gc_info.valid;
150
}
151
 
152
 
153
/////////////////////////////////////////////////////////////////////////////
154
// help function which parses a decimal or hex value
155
// returns >= 0 if value is valid
156
// returns -1 if value is invalid
157
/////////////////////////////////////////////////////////////////////////////
158
static s32 get_dec(char *word)
159
{
160
  if( word == NULL )
161
    return -1;
162
 
163
  char *next;
164
  long l = strtol(word, &next, 0);
165
 
166
  if( word == next )
167
    return -1;
168
 
169
  return l; // value is valid
170
}
171
 
172
/////////////////////////////////////////////////////////////////////////////
173
// help function which parses an IP value
174
// returns > 0 if value is valid
175
// returns 0 if value is invalid
176
/////////////////////////////////////////////////////////////////////////////
177
static u32 get_ip(char *brkt)
178
{
179
  u8 ip[4];
180
  char *word;
181
 
182
  int i;
183
  for(i=0; i<4; ++i) {
1117 tk 184
    if( (word=strtok_r(NULL, ".", &brkt)) ) {
1052 tk 185
      s32 value = get_dec(word);
186
      if( value >= 0 && value <= 255 )
187
    ip[i] = value;
188
      else
189
    return 0;
190
    }
191
  }
192
 
193
  if( i == 4 )
194
    return (ip[0]<<24)|(ip[1]<<16)|(ip[2]<<8)|(ip[3]<<0);
195
  else
196
    return 0; // invalid IP
197
}
198
 
199
 
200
/////////////////////////////////////////////////////////////////////////////
201
// reads the global config file content (again)
202
// returns < 0 on errors (error codes are documented in seq_file.h)
203
/////////////////////////////////////////////////////////////////////////////
204
s32 SEQ_FILE_GC_Read(void)
205
{
206
  s32 status = 0;
207
  seq_file_gc_info_t *info = &seq_file_gc_info;
1261 tk 208
  file_t file;
1052 tk 209
 
210
  info->valid = 0; // will be set to valid if file content has been read successfully
211
 
212
  char filepath[MAX_PATH];
213
  sprintf(filepath, "%sMBSEQ_GC.V4", SEQ_FILES_PATH);
214
 
215
#if DEBUG_VERBOSE_LEVEL >= 2
216
  DEBUG_MSG("[SEQ_FILE_GC] Open global config file '%s'\n", filepath);
217
#endif
218
 
1261 tk 219
  if( (status=FILE_ReadOpen(&file, filepath)) < 0 ) {
1052 tk 220
#if DEBUG_VERBOSE_LEVEL >= 2
221
    DEBUG_MSG("[SEQ_FILE_GC] failed to open file, status: %d\n", status);
222
#endif
223
    return status;
224
  }
225
 
226
  // read global config values
227
  char line_buffer[128];
228
  do {
1261 tk 229
    status=FILE_ReadLine((u8 *)line_buffer, 128);
1052 tk 230
 
231
    if( status > 1 ) {
232
#if DEBUG_VERBOSE_LEVEL >= 3
233
      DEBUG_MSG("[SEQ_FILE_GC] read: %s", line_buffer);
234
#endif
235
 
236
      // sscanf consumes too much memory, therefore we parse directly
237
      char *separators = " \t";
238
      char *brkt;
239
      char *parameter;
240
 
241
      if( (parameter = strtok_r(line_buffer, separators, &brkt)) ) {
242
 
243
    if( *parameter == '#' ) {
244
      // ignore comments
245
#if !defined(MIOS32_FAMILY_EMULATION)
246
    } else if( strcmp(parameter, "ETH_LocalIp") == 0 ) {
247
      u32 value;
248
      if( !(value=get_ip(brkt)) ) {
249
#if DEBUG_VERBOSE_LEVEL >= 1
250
        DEBUG_MSG("[SEQ_FILE_GC] ERROR invalid IP format for parameter '%s'\n", parameter);
251
#endif
252
      } else {
253
        UIP_TASK_IP_AddressSet(value);
254
      }
255
    } else if( strcmp(parameter, "ETH_Netmask") == 0 ) {
256
      u32 value;
257
      if( !(value=get_ip(brkt)) ) {
258
#if DEBUG_VERBOSE_LEVEL >= 1
259
        DEBUG_MSG("[SEQ_FILE_GC] ERROR invalid IP format for parameter '%s'\n", parameter);
260
#endif
261
      } else {
262
        UIP_TASK_NetmaskSet(value);
263
      }
264
    } else if( strcmp(parameter, "ETH_Gateway") == 0 ) {
265
      u32 value;
266
      if( !(value=get_ip(brkt)) ) {
267
#if DEBUG_VERBOSE_LEVEL >= 1
268
        DEBUG_MSG("[SEQ_FILE_GC] ERROR invalid IP format for parameter '%s'\n", parameter);
269
#endif
270
      } else {
271
        UIP_TASK_GatewaySet(value);
272
      }
1083 tk 273
#endif /* !defined(MIOS32_FAMILY_EMULATION) */
1052 tk 274
    } else {
275
      char *word = strtok_r(NULL, separators, &brkt);
276
      s32 value = get_dec(word);
277
 
278
      if( value < 0 ) {
279
#if DEBUG_VERBOSE_LEVEL >= 1
280
        DEBUG_MSG("[SEQ_FILE_GC] ERROR invalid value for parameter '%s'\n", parameter);
281
#endif
282
      } else if( strcmp(parameter, "MetronomePort") == 0 ) {
283
        seq_core_metronome_port = (mios32_midi_port_t)value;
284
      } else if( strcmp(parameter, "MetronomeChannel") == 0 ) {
285
        seq_core_metronome_chn = value;
286
      } else if( strcmp(parameter, "MetronomeNoteM") == 0 ) {
287
        seq_core_metronome_note_m = value;
288
      } else if( strcmp(parameter, "MetronomeNoteB") == 0 ) {
289
        seq_core_metronome_note_b = value;
1754 tk 290
      } else if( strcmp(parameter, "RecQuantisation") == 0 ) {
291
        seq_record_quantize = value;
1075 tk 292
      } else if( strcmp(parameter, "PasteClrAll") == 0 ) {
293
        seq_core_options.PASTE_CLR_ALL = value;
1794 tk 294
      } else if( strcmp(parameter, "InitCC") == 0 ) {
295
        seq_core_options.INIT_CC = value;
296
      } else if( strcmp(parameter, "PatternMixerMapCoupling") == 0 ) {
297
        seq_core_options.PATTERN_MIXER_MAP_COUPLING = value;
1323 tk 298
      } else if( strcmp(parameter, "MultiPortEnableFlags") == 0 ) {
299
        seq_midi_port_multi_enable_flags = value;
1052 tk 300
      } else if( strcmp(parameter, "RemoteMode") == 0 ) {
1316 tk 301
        seq_midi_sysex_remote_mode = (value > 2) ? 0 : value;
1052 tk 302
      } else if( strcmp(parameter, "RemotePort") == 0 ) {
1316 tk 303
        seq_midi_sysex_remote_port = value;
1052 tk 304
      } else if( strcmp(parameter, "RemoteID") == 0 ) {
1316 tk 305
        seq_midi_sysex_remote_id = (value > 128) ? 0 : value;
1083 tk 306
      } else if( strcmp(parameter, "CV_AOUT_Type") == 0 ) {
307
        SEQ_CV_IfSet(value);
308
      } else if( strcmp(parameter, "CV_PinMode") == 0 ) {
309
        u32 cv = value;
310
        if( cv >= SEQ_CV_NUM ) {
311
          DEBUG_MSG("[SEQ_FILE_GC] ERROR wrong CV channel %u for parameter '%s'\n", value);
312
        } else {
313
          word = strtok_r(NULL, separators, &brkt);
314
          u32 curve = get_dec(word);
315
          if( curve >= SEQ_CV_NUM_CURVES ) {
316
        DEBUG_MSG("[SEQ_FILE_GC] ERROR wrong curve %u for parameter '%s', CV channel %u\n", curve, cv);
317
          } else {
318
        word = strtok_r(NULL, separators, &brkt);
319
        u32 slewrate = get_dec(word);
320
        if( slewrate >= 256 ) // saturate
321
          slewrate = 255;
1052 tk 322
 
1083 tk 323
        word = strtok_r(NULL, separators, &brkt);
324
        u32 range = get_dec(word);
325
        if( range >= 127 ) // saturate
326
          range = 2; // default value
327
 
328
        SEQ_CV_CurveSet(cv, curve);
329
        SEQ_CV_SlewRateSet(cv, slewrate);
330
        SEQ_CV_PitchRangeSet(cv, range);
331
          }
332
        }
333
      } else if( strcmp(parameter, "CV_GateInv") == 0 ) {
334
        SEQ_CV_GateInversionAllSet(value);
335
      } else if( strcmp(parameter, "CV_ClkPulsewidth") == 0 ) {
336
        SEQ_CV_ClkPulseWidthSet(value);
337
      } else if( strcmp(parameter, "CV_ClkDivider") == 0 ) {
338
        SEQ_CV_ClkDividerSet(value);
1052 tk 339
      } else if( strcmp(parameter, "BLM_SCALAR_Port") == 0 ) {
340
        seq_blm_port = value;
341
 
342
        MUTEX_MIDIOUT_TAKE;
343
        SEQ_BLM_SYSEX_SendRequest(0x00); // request layout from BLM_SCALAR
344
        MUTEX_MIDIOUT_GIVE;
345
        blm_timeout_ctr = 0; // fake timeout (so that "BLM not found" message will be displayed)
346
 
347
#if !defined(MIOS32_FAMILY_EMULATION)
348
      } else if( strcmp(parameter, "ETH_Dhcp") == 0 ) {
349
        UIP_TASK_DHCP_EnableSet((value >= 1) ? 1 : 0);
1058 tk 350
      } else if( strcmp(parameter, "OSC_RemoteIp") == 0 ) {
351
        if( value > OSC_SERVER_NUM_CONNECTIONS ) {
352
          DEBUG_MSG("[SEQ_FILE_GC] ERROR invalid connection number for parameter '%s'\n", parameter);
353
        } else {
354
          u8 con = value;
355
          u32 ip;
356
          if( !(ip=get_ip(brkt)) ) {
357
#if DEBUG_VERBOSE_LEVEL >= 1
358
        DEBUG_MSG("[SEQ_FILE_GC] ERROR invalid IP format for parameter '%s'\n", parameter);
359
#endif
360
          } else {
361
        OSC_SERVER_RemoteIP_Set(con, ip);
362
          }
363
        }
1052 tk 364
      } else if( strcmp(parameter, "OSC_RemotePort") == 0 ) {
1058 tk 365
        if( value > OSC_SERVER_NUM_CONNECTIONS ) {
366
          DEBUG_MSG("[SEQ_FILE_GC] ERROR invalid connection number for parameter '%s'\n", parameter);
367
        } else {
368
          u8 con = value;
369
          word = strtok_r(NULL, separators, &brkt);
370
          if( (value=get_dec(word)) < 0 ) {
371
        DEBUG_MSG("[SEQ_FILE_GC] ERROR invalid port number for parameter '%s'\n", parameter);
372
          } else {
373
        OSC_SERVER_RemotePortSet(con, value);
374
          }
375
        }
1052 tk 376
      } else if( strcmp(parameter, "OSC_LocalPort") == 0 ) {
1058 tk 377
        if( value > OSC_SERVER_NUM_CONNECTIONS ) {
378
          DEBUG_MSG("[SEQ_FILE_GC] ERROR invalid connection number for parameter '%s'\n", parameter);
379
        } else {
380
          u8 con = value;
381
          word = strtok_r(NULL, separators, &brkt);
382
          if( (value=get_dec(word)) < 0 ) {
383
        DEBUG_MSG("[SEQ_FILE_GC] ERROR invalid port number for parameter '%s'\n", parameter);
384
          } else {
385
        OSC_SERVER_LocalPortSet(con, value);
386
          }
387
        }
388
      } else if( strcmp(parameter, "OSC_TransferMode") == 0 ) {
389
        if( value > OSC_SERVER_NUM_CONNECTIONS ) {
390
          DEBUG_MSG("[SEQ_FILE_GC] ERROR invalid connection number for parameter '%s'\n", parameter);
391
        } else {
392
          u8 con = value;
393
          word = strtok_r(NULL, separators, &brkt);
394
          if( (value=get_dec(word)) < 0 ) {
395
        DEBUG_MSG("[SEQ_FILE_GC] ERROR invalid transfer mode number for parameter '%s'\n", parameter);
396
          } else {
1311 tk 397
        OSC_CLIENT_TransferModeSet(con, value);
1058 tk 398
          }
399
        }
1052 tk 400
#endif
401
      } else {
402
#if DEBUG_VERBOSE_LEVEL >= 2
403
        // changed error level from 1 to 2 here, since people are sometimes confused about these messages
404
        // on file format changes
405
        DEBUG_MSG("[SEQ_FILE_GC] ERROR: unknown parameter: %s", line_buffer);
406
#endif
407
      }
408
    }
409
      } else {
410
#if DEBUG_VERBOSE_LEVEL >= 1
411
    DEBUG_MSG("[SEQ_FILE_GC] ERROR no space separator in following line: %s", line_buffer);
412
#endif
413
      }
414
    }
415
 
416
  } while( status >= 1 );
417
 
418
  // close file
1261 tk 419
  status |= FILE_ReadClose(&file);
1052 tk 420
 
1058 tk 421
#if !defined(MIOS32_FAMILY_EMULATION)
422
  // OSC_SERVER_Init(0) has to be called after all settings have been done!
423
  OSC_SERVER_Init(0);
424
#endif
425
 
1052 tk 426
  if( status < 0 ) {
427
#if DEBUG_VERBOSE_LEVEL >= 1
428
    DEBUG_MSG("[SEQ_FILE_GC] ERROR while reading file, status: %d\n", status);
429
#endif
430
    return SEQ_FILE_GC_ERR_READ;
431
  }
432
 
433
  // file is valid! :)
434
  info->valid = 1;
435
 
436
  // change tempo to given preset
437
  SEQ_CORE_BPM_Update(seq_core_bpm_preset_tempo[seq_core_bpm_preset_num], seq_core_bpm_preset_ramp[seq_core_bpm_preset_num]);
438
 
439
  return 0; // no error
440
}
441
 
442
 
443
/////////////////////////////////////////////////////////////////////////////
444
// help function to write data into file or send to debug terminal
445
// returns < 0 on errors (error codes are documented in seq_file.h)
446
/////////////////////////////////////////////////////////////////////////////
447
static s32 SEQ_FILE_GC_Write_Hlp(u8 write_to_file)
448
{
449
  s32 status = 0;
450
  char line_buffer[128];
451
 
1261 tk 452
#define FLUSH_BUFFER if( !write_to_file ) { DEBUG_MSG(line_buffer); } else { status |= FILE_WriteBuffer((u8 *)line_buffer, strlen(line_buffer)); }
1052 tk 453
 
454
  // write global config values
455
  sprintf(line_buffer, "MetronomePort %d\n", (u8)seq_core_metronome_port);
456
  FLUSH_BUFFER;
457
 
458
  sprintf(line_buffer, "MetronomeChannel %d\n", (u8)seq_core_metronome_chn);
459
  FLUSH_BUFFER;
460
 
461
  sprintf(line_buffer, "MetronomeNoteM %d\n", (u8)seq_core_metronome_note_m);
462
  FLUSH_BUFFER;
463
 
464
  sprintf(line_buffer, "MetronomeNoteB %d\n", (u8)seq_core_metronome_note_b);
465
  FLUSH_BUFFER;
466
 
1754 tk 467
  sprintf(line_buffer, "RecQuantisation %d\n", (u8)seq_record_quantize);
468
  FLUSH_BUFFER;
469
 
1075 tk 470
  sprintf(line_buffer, "PasteClrAll %d\n", seq_core_options.PASTE_CLR_ALL);
471
  FLUSH_BUFFER;
472
 
1794 tk 473
  sprintf(line_buffer, "InitCC %d\n", seq_core_options.INIT_CC);
474
  FLUSH_BUFFER;
475
 
476
  sprintf(line_buffer, "PatternMixerMapCoupling %d\n", seq_core_options.PATTERN_MIXER_MAP_COUPLING);
477
  FLUSH_BUFFER;
478
 
1323 tk 479
  sprintf(line_buffer, "MultiPortEnableFlags 0x%06x\n", seq_midi_port_multi_enable_flags);
480
  FLUSH_BUFFER;
481
 
1316 tk 482
  sprintf(line_buffer, "RemoteMode %d\n", (u8)seq_midi_sysex_remote_mode);
1052 tk 483
  FLUSH_BUFFER;
484
 
1316 tk 485
  sprintf(line_buffer, "RemotePort %d\n", (u8)seq_midi_sysex_remote_port);
1052 tk 486
  FLUSH_BUFFER;
487
 
1316 tk 488
  sprintf(line_buffer, "RemoteID %d\n", (u8)seq_midi_sysex_remote_id);
1052 tk 489
  FLUSH_BUFFER;
490
 
1083 tk 491
  sprintf(line_buffer, "CV_AOUT_Type %d\n", (u8)SEQ_CV_IfGet());
492
  FLUSH_BUFFER;
493
 
494
  int cv;
495
  for(cv=0; cv<SEQ_CV_NUM; ++cv) {
496
    sprintf(line_buffer, "CV_PinMode %d %d %d %d\n", cv, SEQ_CV_CurveGet(cv), (int)SEQ_CV_SlewRateGet(cv), (int)SEQ_CV_PitchRangeGet(cv));
497
    FLUSH_BUFFER;
498
  }
499
 
500
  sprintf(line_buffer, "CV_GateInv 0x%02x\n", (u8)SEQ_CV_GateInversionAllGet());
501
  FLUSH_BUFFER;
502
 
503
  sprintf(line_buffer, "CV_ClkPulsewidth %d\n", SEQ_CV_ClkPulseWidthGet());
504
  FLUSH_BUFFER;
505
 
506
  sprintf(line_buffer, "CV_ClkDivider %d\n", SEQ_CV_ClkDividerGet());
507
  FLUSH_BUFFER;
508
 
1052 tk 509
  sprintf(line_buffer, "BLM_SCALAR_Port %d\n", (u8)seq_blm_port);
510
  FLUSH_BUFFER;
511
 
512
#if !defined(MIOS32_FAMILY_EMULATION)
513
  {
514
    u32 value = UIP_TASK_IP_AddressGet();
515
    sprintf(line_buffer, "ETH_LocalIp %d.%d.%d.%d\n",
516
        (value >> 24) & 0xff,
517
        (value >> 16) & 0xff,
518
        (value >>  8) & 0xff,
519
        (value >>  0) & 0xff);
520
    FLUSH_BUFFER;
521
  }
522
 
523
  {
524
    u32 value = UIP_TASK_NetmaskGet();
525
    sprintf(line_buffer, "ETH_Netmask %d.%d.%d.%d\n",
526
        (value >> 24) & 0xff,
527
        (value >> 16) & 0xff,
528
        (value >>  8) & 0xff,
529
        (value >>  0) & 0xff);
530
    FLUSH_BUFFER;
531
  }
532
 
533
  {
534
    u32 value = UIP_TASK_GatewayGet();
535
    sprintf(line_buffer, "ETH_Gateway %d.%d.%d.%d\n",
536
        (value >> 24) & 0xff,
537
        (value >> 16) & 0xff,
538
        (value >>  8) & 0xff,
539
        (value >>  0) & 0xff);
540
    FLUSH_BUFFER;
541
  }
542
 
543
  sprintf(line_buffer, "ETH_Dhcp %d\n", UIP_TASK_DHCP_EnableGet());
544
  FLUSH_BUFFER;
545
 
1058 tk 546
  int con;
547
  for(con=0; con<OSC_SERVER_NUM_CONNECTIONS; ++con) {
548
    u32 value = OSC_SERVER_RemoteIP_Get(con);
549
    sprintf(line_buffer, "OSC_RemoteIp %d %d.%d.%d.%d\n",
550
        con,
1052 tk 551
        (value >> 24) & 0xff,
552
        (value >> 16) & 0xff,
553
        (value >>  8) & 0xff,
554
        (value >>  0) & 0xff);
555
    FLUSH_BUFFER;
556
 
1058 tk 557
    sprintf(line_buffer, "OSC_RemotePort %d %d\n", con, OSC_SERVER_RemotePortGet(con));
558
    FLUSH_BUFFER;
1052 tk 559
 
1058 tk 560
    sprintf(line_buffer, "OSC_LocalPort %d %d\n", con, OSC_SERVER_LocalPortGet(con));
561
    FLUSH_BUFFER;
1052 tk 562
 
1311 tk 563
    sprintf(line_buffer, "OSC_TransferMode %d %d\n", con, OSC_CLIENT_TransferModeGet(con));
1058 tk 564
    FLUSH_BUFFER;
565
  }
566
 
1052 tk 567
#endif
568
 
569
  return status;
570
}
571
 
572
 
573
/////////////////////////////////////////////////////////////////////////////
574
// writes data into global config file
575
// returns < 0 on errors (error codes are documented in seq_file.h)
576
/////////////////////////////////////////////////////////////////////////////
577
s32 SEQ_FILE_GC_Write(void)
578
{
579
  seq_file_gc_info_t *info = &seq_file_gc_info;
580
 
581
  char filepath[MAX_PATH];
582
  sprintf(filepath, "%sMBSEQ_GC.V4", SEQ_FILES_PATH);
583
 
584
#if DEBUG_VERBOSE_LEVEL >= 2
585
  DEBUG_MSG("[SEQ_FILE_GC] Open global config file '%s' for writing\n", filepath);
586
#endif
587
 
588
  s32 status = 0;
1261 tk 589
  if( (status=FILE_WriteOpen(filepath, 1)) < 0 ) {
1052 tk 590
#if DEBUG_VERBOSE_LEVEL >= 1
591
    DEBUG_MSG("[SEQ_FILE_GC] Failed to open/create global config file, status: %d\n", status);
592
#endif
1261 tk 593
    FILE_WriteClose(); // important to free memory given by malloc
1052 tk 594
    info->valid = 0;
595
    return status;
596
  }
597
 
598
  // write file
599
  status |= SEQ_FILE_GC_Write_Hlp(1);
600
 
601
  // close file
1261 tk 602
  status |= FILE_WriteClose();
1052 tk 603
 
604
 
605
  // check if file is valid
606
  if( status >= 0 )
607
    info->valid = 1;
608
 
609
#if DEBUG_VERBOSE_LEVEL >= 2
610
  DEBUG_MSG("[SEQ_FILE_GC] global config file written with status %d\n", status);
611
#endif
612
 
613
  return (status < 0) ? SEQ_FILE_GC_ERR_WRITE : 0;
614
 
615
}
616
 
617
/////////////////////////////////////////////////////////////////////////////
618
// sends global config data to debug terminal
619
// returns < 0 on errors
620
/////////////////////////////////////////////////////////////////////////////
621
s32 SEQ_FILE_GC_Debug(void)
622
{
623
  return SEQ_FILE_GC_Write_Hlp(0); // send to debug terminal
624
}