Skip to content

Commit

Permalink
Hopefully send messages rather than char arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Nov 8, 2010
1 parent 9e10eab commit b378ce1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/emulation/rfid/rfid.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,25 @@ DWORD rfid_paint(HWND hwnd, LPVOID data, HDC hdc, BOOLEAN force) {
*/
DWORD rfid_on_connect(LPVOID data) {
RFID_Data* dat = (RFID_Data*)data;
CHAR* msg = "\x01\x08\x00\x03\x01\x40\x4B\xB4\0";
RFID_A2D_GetVersion* msg;

SetDlgItemText(dat->dialog, RFID_CONNSTATUS, TEXT("Connected"));

ShowWindow(dat->dialog, SW_SHOW);
//ShowWindow(dat->console, SW_HIDE);
ShowWindow(dat->console, SW_HIDE);

SendMessage(dat->console, TWM_TXDATA, (WPARAM)msg, 8);
msg = (RFID_A2D_GetVersion*)malloc(sizeof(RFID_A2D_GetVersion));
msg->header.sof = 0x1;
msg->header.length = sizeof(RFID_A2D_GetVersion);
msg->header.deviceID = 0x3;
msg->header.command1 = 0x1;
msg->header.command2 = 0x40;

/* TODO: Make this dynamically calculated */
msg->bcc.lrc = 0x4B;
msg->bcc.i_lrc = 0xB4;

SendMessage(dat->console, TWM_TXDATA, (WPARAM)msg, msg->header.length);
return 0;
}

Expand Down
8 changes: 8 additions & 0 deletions src/emulation/rfid/rfid.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ typedef struct _rfid_data {
BYTE screenrow;
} RFID_Data;

/**
* @implementation rfid_util.c
*/
LPCTSTR rfid_entity_name(BYTE entity);

/**
* @implementation rfid_util.c
*/
RFID_BCC rfid_calc_bcc(LPVOID message, WORD size);

/**
* @implementation rfid_dlg.c
*/
Expand Down
12 changes: 12 additions & 0 deletions src/emulation/rfid/rfid_structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma pack(1)

typedef struct _rfid_header {
BYTE soframe;
WORD length;
BYTE deviceID;
BYTE command1;
Expand All @@ -16,12 +17,23 @@ typedef struct _rfid_bcc {
BYTE i_lrc;
} RFID_BCC;

typedef struct _rfid_a2d_getversion {
RFID_Header header;
RFID_BCC bcc;
} RFID_A2D_GetVersion;

typedef struct _rfid_d2a_getversion {
RFID_Header header;
BYTE status;
BYTE entityID;
} RFID_D2A_GetVersion;

typedef struct _rfid_a2d_findtoken {
RFID_Header header;
BYTE timeout;
RFID_BCC bcc;
} RFID_A2D_FindToken;

typedef struct _rfid_d2a_findtoken {
RFID_Header header;
BYTE status;
Expand Down
17 changes: 16 additions & 1 deletion src/emulation/rfid/rfid_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,19 @@ LPCTSTR rfid_entity_name(BYTE entity) {
default:
return TEXT("Unknown");
}
}
}

RFID_BCC rfid_calc_bcc(LPVOID message, WORD size) {
BYTE lrc = 0;
DWORD i = 0;

for (i = 0; i < size; i++) {
lrc ^= (BYTE)(*message + i);
}

RFID_BCC bcc;
bcc.lrc = lrc;
bcc.i_lrc = (lrc ^ 0xFF);

return bcc;
}

0 comments on commit b378ce1

Please sign in to comment.