*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
char buffer[4096];
GetLocalTime(&time);
- sprintf (buffer, "%4d-%02d-%02d %2d:%02d:%02d. ",
+ __ms_sprintf (buffer, "%4d-%02d-%02d %2d:%02d:%02d. ",
time.wYear, time.wMonth, time.wDay,
time.wHour, time.wMinute, time.wSecond);
va_start(a, fmt);
- vsprintf(buffer + strlen(buffer), fmt, a);
+ __ms_vsprintf(buffer + strlen(buffer), fmt, a);
va_end(a);
fputs(buffer, log);
return list;
}
+static struct {
+ unsigned int vid, pid;
+ char *name;
+} name_map[] = {
+ { .vid = 0xfffe, .pid = 0x000d, .name = "EasyTimer" },
+ { .vid = 0xfffe, .pid = 0x0028, .name = "EasyMega" },
+ { .vid = 0xfffe, .pid = 0x002c, .name = "EasyMotor" },
+ { .name = NULL },
+};
+
PUBLIC int
altos_list_next(struct altos_list *list, struct altos_device *device)
{
DWORD friendlyname_len;
char instanceid[1024];
DWORD instanceid_len;
+ int i;
dev_info_data.cbSize = sizeof (SP_DEVINFO_DATA);
while(SetupDiEnumDeviceInfo(list->dev_info, list->index,
if (result != 0) {
altos_set_last_windows_error();
} else {
- sscanf((char *) symbolic + sizeof("\\??\\USB#VID_") - 1,
+ __ms_sscanf((char *) symbolic + sizeof("\\??\\USB#VID_") - 1,
"%04X", &vid);
- sscanf((char *) symbolic + sizeof("\\??\\USB#VID_XXXX&PID_") - 1,
+ __ms_sscanf((char *) symbolic + sizeof("\\??\\USB#VID_XXXX&PID_") - 1,
"%04X", &pid);
- sscanf((char *) symbolic + sizeof("\\??\\USB#VID_XXXX&PID_XXXX#") - 1,
+ __ms_sscanf((char *) symbolic + sizeof("\\??\\USB#VID_XXXX&PID_XXXX#") - 1,
"%d", &serial);
}
if (vid == 0 || pid == 0 || serial == 0) {
instanceid,
sizeof (instanceid),
&instanceid_len)) {
- sscanf((char *) instanceid + sizeof("USB\\VID_") - 1,
+ __ms_sscanf((char *) instanceid + sizeof("USB\\VID_") - 1,
"%04X", &vid);
- sscanf((char *) instanceid + sizeof("USB\\VID_XXXX&PID_") - 1,
+ __ms_sscanf((char *) instanceid + sizeof("USB\\VID_XXXX&PID_") - 1,
"%04X", &pid);
- sscanf((char *) instanceid + sizeof("USB\\VID_XXXX&PID_XXXX\\") - 1,
+ __ms_sscanf((char *) instanceid + sizeof("USB\\VID_XXXX&PID_XXXX\\") - 1,
"%d", &serial);
} else {
altos_set_last_windows_error();
altos_set_last_windows_error();
continue;
}
+
+ char *space = friendlyname;
+ while (*space) {
+ if (*space == ' ') {
+ *space = '\0';
+ break;
+ }
+ space++;
+ }
+
+ for (i = 0; name_map[i].name; i++) {
+ if (name_map[i].vid == vid && name_map[i].pid == pid) {
+ strcpy(friendlyname, name_map[i].name);
+ break;
+ }
+ }
+
device->vendor = vid;
device->product = pid;
device->serial = serial;
ba2str(BTH_ADDR ba, char *str)
{
- sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
+ __ms_sprintf(str, "%02X:%02X:%02X:%02X:%02X:%02X",
get_byte(ba, 0),
get_byte(ba, 1),
get_byte(ba, 2),
{
unsigned int bytes[6];
- sscanf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
+ __ms_sscanf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
&bytes[0],
&bytes[1],
&bytes[2],
struct altos_file_windows *file;
SOCKADDR_BTH sockaddr_bth;
int ret;
+ int channel = 0;
file = calloc(1, sizeof (struct altos_file_windows));
if (!file) {
memset(&sockaddr_bth, '\0', sizeof (sockaddr_bth));
sockaddr_bth.addressFamily = AF_BTH;
sockaddr_bth.btAddr = str2ba(device->addr);
- sockaddr_bth.port = 1;
+
+ channel = altos_bt_port(device);
+ if (channel == 0)
+ channel = BT_PORT_DEFAULT;
+
+ sockaddr_bth.port = channel;
ret = connect(file->socket, (SOCKADDR *) &sockaddr_bth, sizeof (sockaddr_bth));
altos_set_last_winsock_error();
closesocket(file->socket);
free(file);
+ log_message("Connection attempted to address %s port %d\n", device->addr, sockaddr_bth.port);
return NULL;
}
return &file->file;
}
+void
+altos_pause_one_second(void)
+{
+ Sleep(1000);
+}