The anti🚫-derailment🚃 & thread🧵 hijackingšŸ”« thread🧵 ⁉

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

Time is a construct. Play with it however you like.

2 Likes

Ah. But the architecture reminds me of New Scotland Yard, so I submit that this is in fact on the heart of London and so very close to the meridian. I did find an article which suggested that in fact current 6am should be 0/10 but that was purely their suggestion. They didn’t mention time zones at all but given they chose 6am to represent the start of daylight I think that they assumed local time.

So, if there are only 10 hours in the day this is 00:26… As this is London (prove me wrong) this is the middle of the night.

Time is Relative (just ask Einstein)