The antišŸš«-derailmentšŸšƒ & threadšŸ§µ hijackingšŸ”« threadšŸ§µ ā‰

tenor (1)

image

2 Likes

It can be arranged. :imp:

:rofl:

So closeā€¦

2 Likes

Hey @Backpackingvet , I thought you had your Covid Jabs :microbe:

It looks like you might need a booster

You have run out of (((5G)))

2 Likes

Guau, muy buen descuento !

Son para tus amigos de trabajo?

2 Likes

ok wellā€¦ i got the hardware all wired up on the Photon and it works with pin control test logicā€¦ butā€¦ damn strings and countersā€¦

I have string data coming in as const char *data that I need to parse. The first bit will be a number (the number of sales, could be 1 to 3 digits long), then a space, then some more alphanumeric string stuff. I need to figure out how to pull the number into an int variable then track if itā€™s increased since the last time the data came in. Strings and data types and finding the first space character so I know how to split it offā€¦ well letā€™s just say I donā€™t think in these low level computer logic terms so well. My thought was to create a separate function call and pass the data variable to which could parse it and check the current count with a global variableā€™s value and if itā€™s > then hit the pin real quick before passing control back to the loopā€¦ but likeā€¦ how?

Short and simple :slight_smile:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{ 
  char *p;
  int i;
  
  if(argc <= 1 || !argv[1][0]) {
    printf("Pass me a string in the form \"123 Some alphanumeric string\" as the first argument and I will magically split it\n");
    return(-1);
  }

  for(p = argv[1];p[0] && p[0] != ' '; p++);
  if(p[0])
    0[p++] = 0;

  i = atoi(argv[1]);

  printf("First integer part:       %d\n", i);
  printf("Second alphanumeric part: %s\n", p);

  return(0);
}
4 Likes

Thanks! Iā€™ll check it out later once I get a chance to tinker on this again.

If youā€™ve ever wondered how those anti-theft tags work, when you pass through the portal at the store, whether they are RFID, RF, UHFā€¦ wonder no more: I found this cool video from Ben ā€œApplied Scienceā€ Krasnow (if you donā€™t know this guy incidentally, watch his videos: youā€™ll wonder how you went through school without him as a teacher):

Itā€™s nothing to do with RFID - or it is, in a caveman sort of way - and itā€™s pretty damn interesting.

2 Likes

Actually not this partā€¦ these are called ā€œbit tagsā€ either binary 1 or 0, on or offā€¦ RFID tags are iso15693 and 13.56MHz that leverage EAS features (electronic article surveillance)ā€¦ in fact we have to disable these features on the VivoKey Spark 1 or you might possibly be setting off badly configured antitheft systems in certain stores that use RFID tags for inventory control (and antitheft is part of that system).

I get an error;

cannot convert ā€˜const char*ā€™ to ā€˜char**ā€™ for argument ā€˜2ā€™ to ā€˜int salescount(int, char**)ā€™

My ignorance (and unwillingness to properly figure this out myself) is woefully showing here, but basically what Iā€™d like to do is something like this;

int salescount = 0; //global var tracking sales count

void soundtrigger(char salesdatastring)
{
//magic that splits the salesdatastring
magic splitty uppy code

//magic that checks split count against global var
if argv[0] > salescount {
digitalWrite(sound, HIGH); // sets the LED on
delay(200); // waits for 200mS
digitalWrite(sound, LOW); // sets the LED off
salescount = argv[0]; // update global sales count var
}

return;
}

Part of the problem is that C doesnā€™t really have a ā€œstringā€ type, it uses an array of characters instead (and frequently just deals with pointers to those arrays).

However, if you can guarantee that the format of the array is 1 to 3 numeric digit characters, followed by a space, followed by some alphanumeric data that we donā€™t really care about, it is a lot easier.

Fortunately as @anon3825968 noted the atoi function ignores any leading white space, converts the digits into an integer, and then stops when it hits the first non-digit character.

So to grab the integer you just needā€¦

int number;

number = atoi(data);

So, save your current count and have a comparisonā€¦

#include <stdlib.h>

void hitpin();

/* Stuff */

char * data;
int count, number;

/* More stuff */

number = atoi(data);
if (number > count)
{
  count = number;
  hitpin();
}

/* Even more stuff */

If this doesnā€™t do what you want then you need to let us know what you want.

Added the following after your latest postā€¦

Converting your pseudo codeā€¦

int salescount = 0; //global var tracking sales count

void soundtrigger(char *salesdatastring)
{
int newcount;

//magic that splits the salesdatastring
newcount = atoi(salesdatastring);

//magic that checks split count against global var

if newcount > salescount {
digitalWrite(sound, HIGH); // sets the LED on
delay(200); // waits for 200mS
digitalWrite(sound, LOW); // sets the LED off
salescount = newcount; // update global sales count var
}

return;
}
2 Likes

pinapples

6 Likes

Ah yes sorry, I should have mentioned it: argv in a main() function is mutable - and I whipped up my code snippet based on that cuz I thought it was obvious.

You need to copy your const char * to a char * if you want to modify it. If you donā€™t intend to modify it and the compiler complains about the assignment, you can cast it but itā€™s not terribly clean.

EDIT: looks like that ship has sailed. I really should refresh my browser more often :slight_smile:

1 Like

tumbleweed-highway

3 Likes

d2-soon

@Pilgrimsmaster Tumbleweeds? Stand back, I got this.

I present to you an argument against metric time.

That oughta stir 'em up!

1 Like

So that is 10.18. Presumably 10 is noon/midnight, so 10.18 would equate to almost 13 minutes past noon.

What is so difficult about that?

O.k. it is 10.1827 which is just the other side of 12:13. I did assume 20 hours in a day, 10 ante meridian and 10 post meridian. If not then this is remarkably well lit for the middle of the night.

3 Likes

I canā€™t for the life of me imagine that metric time, given itā€™s pedantic need for unambiguity would permit an A.M or P.M. designation. I submit to you sir that there are only 10 hours per day.

Furthermore I would point out the possibly false assumption that this time system would experience time zones (see unambiguity comment from above).

So itā€™s 18 metric minutes past the origin point, which is assumably the Greenwich Observatory, although that would be an assumption all of itā€™s own.

The clock could then be anywhere in the world, although the sunlight would suggest itā€™s nearly opposite whatever is being used as a prime meridian.

prove-me-wrong1