Thursday, January 11, 2018

Scion TC 2006 Remote + Immobilizer programming

Remote programming: Source: http://www.remotesremotes.com/v/vspfiles/photos/prog/toyota/to-p7g.pdf
1. Begin with the key out of the ignition. 2. OPEN and UNLOCK the DRIVER'S side door. CLOSE all other doors including the trunk. 3. Within 5 seconds INSERT the key into the ignition and PULL it out TWICE. 4. CLOSE then OPEN the DRIVER's side door TWICE. 5. Insert key INTO the ignition then REMOVE it. 6. CLOSE then OPEN the DRIVER's side door TWICE. 7. Insert the key INTO the ignition and LEAVE it in ignition. 8. CLOSE the DRIVER's side door. 9. Switch the ignition to ON then OFF. 10. REMOVE the key from ignition. 11. The door locks will now cycle to confirm the vehicle has successfully entered programming mode. 12. PUSH and HOLD the LOCK and UNLOCK button for 1.5 seconds on the first remote being programmed. As soon as you let go PUSH the LOCK button and HOLD it for 2 seconds. 13. The door locks will cycle to confirm successful programming of the remote. If you have any additional remotes to program repeat step 12 if you have no additional remotes proceed to step 14. 14. OPEN the DRIVER'S side door. Programming is now complete.
Immobilizer/transponder chip programming: Source: https://www.youtube.com/watch?v=Jf-0dSCVfRY 1. Using a master key (original key), insert (and remove) it from the ignition 5 times. On the 5th time, leave it in the ignition, then: 2. Open and close the driver's door 6 times. 3. Remove the master key. The security light should now stay lit red. 4. Insert the newly cut key. The security light should be blinking red; wait about 60 seconds until the light stops blinking and turns off. 5. Remove the new key. Insert the old master key and start the engine and turn it off. Removing old immobilizer keys from ECU: Source: Sean Figgins from youtube Something that you may want to do, since you do not know how many keys are already programmed, is erase the existing keys and start over. It is very similar to programming your keys. Using your instructions as a template: 1. Using a master key (original key), insert (and remove) it from the ignition 6 times. On the 6th time, leave it in the ignition, then: 2. Open and close the driver's door 7 times. 3. The security light should now stay lit red. When you remove the master key, this will be the only key that is still programmed. After this, you should be able to add your keys. I only have 3 keys myself, but I believe that ~2004 Toyotas will allow 5 master keys, and 3 valet keys to be programmed. Since erasing and reprogramming is so easy, I might just erase and reprogram if I even have to give my master key to anyone. This would keep people from making duplicates and driving off with my car.

Friday, September 25, 2015

pointer to array of ints, array of ints

int aint[] = {12,34,67};
int (*bint)[3];
memcpy(*bint,aint,3*sizeof(int));
int (*cint)[3];
cint = &aint;
printf("(*cint)[2] = %d\n", (*cint)[2]);

Monday, September 21, 2015

Pointer/array: char

static read-only literal:

char x[]="abc";
shorthand for
char x[4] = {0x61,0x62,0x63,0};


static/auto:

char x[30] = "hello";

or

char x[30];
strcpy(x, "hello");

or 

char x[] = "hello"



dynamic:

char *x;
x = malloc(30);
strcpy(x, "hello");

Making string literals const is a C++ idiom and not part of any C standard
declaration; intialization; assignment

Sunday, August 30, 2015

char array, string literal, const

1.

char string[] = "String literal";
string[0] = '[';

everything compiles; then seg fault.

2.
    char* string1  = "String literal"
    string1[0] = '[';
    printf("%c\n", string1[0]);

compiles; prints

3.
  char *p = "ab" ; // string literal, stores in read-only
  char p[] = "ab"; //can be manipulated
  char *p = (char []){'a', 'b', '\0'};
A character string literal is a sequence of zero or more multibyte characters enclosed in double-quotes
http://stackoverflow.com/questions/30533439/string-literals-vs-array-of-char-when-initializing-a-pointer

compilers replace string literals wtih pointers.

const: C, C++


1. T const  *p 
2. const T  *p

1 and 2 are same. However, follow the convention of reading from the right to the left.

T const *p = p is a pointer to const T

p can be changed; however, *p can't be changed

Trick: move the decl-specifier "const" to the right, then read.

3. T  *const p

p is a const pointer to T.
p can't be changed, however *p can be changed

4. T const  *const p
5. const T  *const p

4 &5 are same; but 5 is easy to read: p is a const pointer to const p.
Both p and *p can't be changed.



6. int x[N];
   int const *p  = x;

decl-specifier "const" is usually seen as a formal parameter;
int x[N];
int f(int const *p);

*p = 1;  // error, const can't be changed.
x[0] = 1; //accepeted; x is unqualified
++p; //*p = x[1], accepted; p is unqualified

The latter trick is used to write to ROM (read Dan Sikes articles).

7. volatile vs const .

If there is no 'volatile', compiler optimizes and fucks up every thing. So, volatile forces no optimizations. 
const and volatile: the device can change (volatile), but the program can't (const)


8. qualified types: when const/volatile
     more specific: cv-qualified; const qualified; v qualified.
     cv-unqualified
     int i; //unqualified
    int const j; //c-qualified int
    int volatile k; //v-qualified int
    int const *p; // *p is c-qualified; however, the ptr p is unqualified
  
9. const is a promise

10. qualification conversion: un-qualified >(to) qualified; cf. int > int const
int n = 0
int const *p = &n; //no error 

int const m = 0
int *q = &m; //error  (qual > unqual)

10. 

int *p; // non-const pointer p  to non const int.

11. 
int m = 0;
int *const p = &m; // p points to the same storage area as m designates
int *q = p; //copies p, not an issue, does not change p

no promises violated


Friday, August 21, 2015

C: static keyword

K&R: The static declaration, applied to an external variable or function, limits the scope of that object to the rest of the source file being compiled. 
-can be 'seen' within all functions in this source file
-can't be seen by linked objects used in this file.
-global variables
-if defined within a function f(), intialized during the first call of f(), after that, the static vars act like globals

Thursday, August 20, 2015

C: extern keyword

declaration (no memory allocation)
definition (memory allocated)


int foo(int a, int b); /* declare, by default compiler prepends extern to such declarations */

int foo(int a, int b) {
/* defined*/
}

int foo(int a, int b); = extern int foo(int a, int b)


int bar; /* declare and define; mem allocated */

extern int bar; /* declare; mem not allocated */

extern int bar = 0; /* declare and intialized; hence, mem allocated */


cf: One Definition Rule in C, C++

extern "C" is a linkage specification.