Close

Relay labelling

A project log for ReTest-yg

YG's own version of Mateng's ReTest, but with different features and a palindromic project number!

yann-guidon-ygdesYann Guidon / YGDES 11/18/2018 at 03:210 Comments

I'll have to automate many aspects of the binning process. However I still have to manually handle the parts.

The computer will generate and store the characteristics with SSV log files, but the relays might be loose in bags or boxes. The relays must be marked, manually, because I have no fancy automated marker. There is only me and a fine marker. The marking must be short and practical...

I decided to use an alphanumeric code : 2 or 3 digits, 0-F and A-Z. There are 36 codes per digit, which is the standard capacity of a box of RES15. This allows me to mark boxes with a prefix for easier lookup in the future.

36×36=1296 relays : this is more than I think I can test myself so 2 digits are enough in the beginning but 3 is still possible (up to 46656 codes) because I own more than 1296 relays at this moment.

The test software is written in C because of interfacing and timing constraints. Let's now write the conversion functions :

Beware, it's ugly but quickly coded.

/*
file AN3.c (c) 20181118 Yann Guidon whygee@f-cpu.org
Alphanumeric3 code : 3 digits code up to 46656 values
Not really foolproof but good enough for a hack or two.
*/

#include <stdio.h>

// the character string MUST be terminated
// (by zero or space for example)
int alphanum3_to_integer (char *a) {
  int val=0, i=0;
  char c;

  while (1) {
    if (i>3)
      return val;

    c=a[i++];

    if ((c >= '0') && (c <= '9')) {
      val = val*36;
      val += c-'0';
    }
    else {
      if ((c >= 'A') && (c <= 'Z')) {
        val = val*36;
        val += (c+10)-'A';
      }
      else
    return val;
    }
  }
}

// error can be checkd by looking if a[0] changed
void integer_to_alphanum3(int val, char *a) {
  int div, rem;

  if (val >= 46656)
    return;

  div = val / 1296;
  if (div < 10)
    a[0]=div+'0';
  else
    a[0]=(div+'A')-10;
  val -= div * 1296;

  div = val / 36;
  if (div < 10)
    a[1]=div+'0';
  else
    a[1]=(div+'A')-10;
  val -= div * 36;

  if (val < 10)
    a[2]=val+'0';
  else
    a[2]=(val+'A')-10;
}

A small test shows it works:

int main(int argc, char ** argv) {
  int i, j;
  char buff[6];

  for (i=0; i<46656; i++) {
    integer_to_alphanum3(i, buff);
    buff[3]=0;
    j = alphanum3_to_integer(buff);
    if (j != i)
      printf("%s : %d != %d\n", buff, i, j);
  }
  printf("\n");
}

..

Discussions