473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Looping problem (revisited for better reading)

Hi all.... I am trying to reduce the code of this function and I presume
there's a way to do it through a loop, buit I can't figure out how. This is
what I got: an embedded processor with a mini webserver running on it, Then
I have a function that substitutes dinamicaly some special codes that I've
spread through the webpage with information that is being written onto my
RAM memory by an external processor. So what I do is: I define the storage
positions:

#define R1DIA ((unsigned char*)0xC000)
#define R1TIPUS ((unsigned char*)0xC001)
#define R1ANY ((unsigned char*)0xC002)
#define R1MES ((unsigned char*)0xC003)
#define R1HORA ((unsigned char*)0xC004)
#define R1MIN ((unsigned char*)0xC005)
#define R1VALOR ((uint16_t*)0xC006)
#define R2DIA ((unsigned char*)0xC008)
#define R2TIPUS ((unsigned char*)0xC009)
#define R2ANY ((unsigned char*)0xC00A)
#define R2MES ((unsigned char*)0xC00B)
#define R2HORA ((unsigned char*)0xC00C)
#define R2MIN ((unsigned char*)0xC00D)
#define R2VALOR ((uint16_t*)0xC00E)
#define R3DIA ((unsigned char*)0xC010)
#define R3TIPUS ((unsigned char*)0xC011)
#define R3ANY ((unsigned char*)0xC012)
#define R3MES ((unsigned char*)0xC013)
#define R3HORA ((unsigned char*)0xC014)
#define R3MIN ((unsigned char*)0xC015)
#define R3VALOR ((uint16_t*)0xC016)
// Then I do all of the stuff my webserver needs and when a request is made
I jump to a loop something like this: (I've omited some of the code so it's
not so long, but you'll get the picture)

void InsertDynamicValues(void)
{

if (TCPTxDataCount < 4) return;
Key = TCP_TX_BUF;

for (i = 0; i < (TCPTxDataCount - 2); i++)
{
if (*Key == '¿') //every time I find a '¿' in my code I search for
next character
{
if (*(Key + 1) == '%')
{
switch (*(Key + 2))
{
case '?':
{
switch (*(Key + 3)) // So I have found the whole
string, no go for the last caractes and make a substitution
{
case 'a': // from what will be written
on the webpage, two of the vars have to go
//through a small
external calculation (Get_value) that will return a float
//number
{
sprintf(NewKey, "%02x/%02x/%02x
%02x:%02x %s%04.2f ", *R1DIA, *R1MES, *R1ANY, *R1HORA, *R1MIN, "(",
Get_value(*R1VALOR,*R1TIPUS));
memcpy(Key, NewKey, 23);
break;
}
case 'b':
{
sprintf(NewKey, "%02x/%02x/%02x
%02x:%02x %s%04.2f ", *R2DIA, *R2MES, *R2ANY, *R2HORA, *R2MIN, "(",
Get_value(*R2VALOR,*R2TIPUS));
memcpy(Key, NewKey, 23);
break;
}
case 'c':
{
sprintf(NewKey, "%02x/%02x/%02x
%02x:%02x %s%04.2f ", *R3DIA, *R3MES, *R3ANY, *R3HORA, *R3MIN, "(",
Get_value(*R3VALOR,*R3TIPUS));
memcpy(Key, NewKey, 23);
break;
}
}
}
break;
} //and when all of my letters are done (from 'a' to 'Z') I
switch the preceeding character and go around again
case '%' :
{
switch (*(Key + 3))
{
case 'a':
{
sprintf(NewKey, "%s",
Detect_type(*R1TIPUS,*R1VALOR));
memcpy(Key, NewKey, 15);
break;
}
case 'b':
{
sprintf(NewKey, "%s",
Detect_type(*R2TIPUS,*R2VALOR));
memcpy(Key, NewKey, 15);
break;
}
case 'c':
{
sprintf(NewKey, "%s",
Detect_type(*R3TIPUS,*R3VALOR));
memcpy(Key, NewKey, 15);
break;
}
}
}
break;
}
}
}
Key++;
}
}

/* So far, so good. This works smoothly, but since I have to set 300
variables on the system now, the code has become extremely large, and I
think I could do it some other way. I'm going to try to outline it, but I'm
not sure I can do it... see if you guys can give me some guide lines as
where to go...*/

void InsertDynamicValues(void)
{
unsigned char *Key;
unsigned char NewKey[5];
unsigned int e;
unsigned char leter = a ;
*Dia = (unsigned char *)0xc000; //Inicialize pointers on the first
memory address where they will start
*Tipus = (unsigned char *)0xC001;
*Any = (unsigned char *)0xC002;
*Mes = (unsigned char *)0xC003;
*Hora = (unsigned char *)0xC004;
*Minut = (unsigned char *)0xC005;
*Valor = (unsigned int *)0xC006; // note that the last value is 2 words
length instead of one

if (TCPTxDataCount < 4) return;
Key = TCP_TX_BUF;

for (i = 0; i < (TCPTxDataCount - 2); i++)
{
if (*Key == '¿')
{
if (*(Key + 1) == '%')
{
switch (*(Key + 2))
{
case '?':
{
for (leter = a; leter < Z ; leter++)
{
if (*(Key + 3) == leter)
{
sprintf(NewKey, "%02x/%02x/%02x
%02x:%02x %s%04.2f ", *DIA, *MES, *ANY, *HORA, *MIN, "(",
Get_value(*VALOR,*TIPUS));
memcpy(Key, NewKey, 23);
break;
}
else
{
leter = leter+1;
*DIA = *DIA +8;
*MES = *MES +8;
*ANY = *ANY +8;
*HORA = *HORA +8;
*MIN = *MIN +8;
*VALOR = *VALOR+ 8;
*TIPUS = *TIPUS+ 8;
if (LETRA >'Z') break;
}
Key++;
}
}

/*Now, I feel there are some big gaps that go beyond my level of C and I
really don't know if something like this should ever work, but, it seems
pretty logical to me, though at times finding the sintaxis to do what I want
to do it's a hard task.....

Thanks in advance

Yodai */

Nov 14 '05 #1
0 1282

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Chris Reedy | last post by:
For everyone - Apologies for the length of this message. If you don't want to look at the long example, you can skip to the end of the message. And for the Python gurus among you, if you can...
11
by: Kay Schluehr | last post by:
Since George Sakkis proposed a new way of doing list comprehensions http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/ac5023ad18b2835f/d3ff1b81fa70c8a7#d3ff1b81fa70c8a7 ...
27
by: Mike P | last post by:
I will be passing my function a two dimensional array of varying length. Within that array is one data point, and the number of times it should loop through. So, for example, I might pass this...
9
by: B Wagner | last post by:
This message was posted (not by me) in July and never saw any responses...I'm having the same exact issue and then some...first the original post (can also be seen here:...
9
by: Sheldon | last post by:
Hi, I am trying to make sense of this endian problem and so far, it is still Greek to me. I am have some files that have stored lat and lon data in binary format. The data was originally floats...
14
by: Sheldon | last post by:
Hi, I have a python script that uses a C extention. I keep getting a recurring problem that causes a core dump a few lines after the C extention return data back tp python. I tried using pbd and...
7
by: saif.shakeel | last post by:
Hi, I need to replace a string in xml file with something else.Ex - <SERVICEPARAMETER id="_775" Semantics="subfunction" DDORef="_54"> <SHORTNAME>rate</SHORTNAME> <LONGNAME>rate</LONGNAME>...
5
mythescriptid
by: mythescriptid | last post by:
Hi All, I know templates and STL might have been discussed many a times here, I'm bit of newbie as far as templates are concerned and was itching to test my new found linking of templates. I would...
35
by: James Kanze | last post by:
Just ran into an interesting question concerning SFINAE. Given the following code: #include <iostream> #include <typeinfo> template< typename T > class P { public:
1
by: vijayarl | last post by:
Hi Everyone, i have the written this logic : basically a file operation open (CONFIGFILE, "$config_file") or die; while (<CONFIGFILE>) { chomp;
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.