Skip to content

Commit

Permalink
Update to handle non-character data
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Nov 1, 2010
1 parent be0d4c9 commit e5b05b2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

/* APPLICATION MESSAGE ID DEFINES */
#define TWM_RXDATA (WM_APP + 1)
#define TWM_TXDATA (WM_APP + 2)

typedef struct _emulator Emulator;
typedef struct _TermInfo TermInfo;
Expand Down
4 changes: 2 additions & 2 deletions src/emulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ typedef struct _emulator {
LPCSTR (*escape_input)(LPVOID data, DWORD input);

/* @since 1 */
DWORD (*receive)(LPVOID data, LPCTSTR rx);
DWORD (*receive)(LPVOID data, BYTE* rx, DWORD len);

/* @since 2 */
DWORD (*paint)(HWND hwnd, LPVOID data, HDC hdc, BOOL force);
DWORD (*paint)(HWND hwnd, LPVOID data, HDC hdc, BOOLEAN force);

/* @since 2 */
DWORD (*on_connect)(LPVOID data);
Expand Down
Empty file added src/emulation/rfid/.keep
Empty file.
4 changes: 2 additions & 2 deletions src/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ int ReadData(HANDLE* fd, HWND hwnd) {
if (cstat.cbInQue > 0) {
DWORD bytes = cstat.cbInQue;
do {
TCHAR* chars = (TCHAR*)malloc(sizeof(TCHAR)*(cstat.cbInQue + 1));
BYTE* chars = (BYTE*)malloc(cstat.cbInQue + 1);
for (i = 0; i < (bytes > 1024 ? 1024 : bytes); i++) {
chars[i] = 0;
/* Read each character individually */
Expand All @@ -162,7 +162,7 @@ int ReadData(HANDLE* fd, HWND hwnd) {
}
chars[i] = 0;

SendMessage(hwnd, TWM_RXDATA, (WPARAM)chars, _tcsclen(chars));
SendMessage(hwnd, TWM_RXDATA, (WPARAM)chars, cstat.cbInQue);
bytes -= (bytes > 1024 ? 1024 : bytes);
} while(bytes > 0);
}
Expand Down
20 changes: 18 additions & 2 deletions src/terminal_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
if (ti->dwMode == kModeConnect) {
DWORD ret = 0;

ti->hEmulator->receive(ti->hEmulator->emulator_data, (LPCTSTR)wParam);
free((LPVOID)wParam);
ti->hEmulator->receive(ti->hEmulator->emulator_data, (BYTE*)wParam, lParam);
free((BYTE*)wParam);

if ((ret = ti->hEmulator->paint(hwnd,
(LPVOID)ti->hEmulator->emulator_data, NULL, FALSE)) != 0) {
Expand All @@ -196,6 +196,22 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
}
}
return 0;
case TWM_TXDATA:
{
if (ti->dwMode == kModeConnect) {
BYTE* data = (BYTE*)wParam;
if (data == NULL)
return 0;

if (SendData(&ti->hCommDev, (LPVOID)data, lParam) != 0) {
DWORD dwError = GetLastError();
ReportError(dwError);
}

free(data);
}
}
return 0;
case WM_DESTROY:
{
CommandMode(hwnd);
Expand Down

0 comments on commit e5b05b2

Please sign in to comment.