summaryrefslogtreecommitdiff
path: root/camlibs/ptp2/ptpip.c
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2013-05-15 20:58:24 +0000
committerMarcus Meissner <marcus@jet.franken.de>2013-05-15 20:58:24 +0000
commitc20999a27e533c4c604e428f5d03e94a322509f9 (patch)
tree3ad6f81206f74ecd0d4b9e2026751fdd936bcceb /camlibs/ptp2/ptpip.c
parent6423fbe25fadeb292b6912d9695260574fce0d59 (diff)
downloadlibgphoto2-c20999a27e533c4c604e428f5d03e94a322509f9.tar.gz
https://sourceforge.net/p/gphoto/patches/150/
From: Yifan Lu better ptpip event checking support. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@14417 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'camlibs/ptp2/ptpip.c')
-rw-r--r--camlibs/ptp2/ptpip.c65
1 files changed, 57 insertions, 8 deletions
diff --git a/camlibs/ptp2/ptpip.c b/camlibs/ptp2/ptpip.c
index e34e5a976..ff789237e 100644
--- a/camlibs/ptp2/ptpip.c
+++ b/camlibs/ptp2/ptpip.c
@@ -383,7 +383,7 @@ ptp_ptpip_getresp (PTPParams* params, PTPContainer* resp)
resp->Code = dtoh16a(&data[ptpip_resp_code]);
resp->Transaction_ID = dtoh32a(&data[ptpip_resp_transid]);
- n = (dtoh32(hdr.length) - ptpip_resp_param1)/sizeof(uint32_t);
+ n = (dtoh32(hdr.length) - sizeof(hdr) - ptpip_resp_param1)/sizeof(uint32_t);
switch (n) {
case 5: resp->Param5 = dtoh32a(&data[ptpip_resp_param5]);
case 4: resp->Param4 = dtoh32a(&data[ptpip_resp_param4]);
@@ -524,10 +524,59 @@ ptp_ptpip_init_event_ack (PTPParams* params)
#define PTP_EVENT_CHECK 0x0000 /* waits for */
#define PTP_EVENT_CHECK_FAST 0x0001 /* checks */
+#define ptpip_event_code 0
+#define ptpip_event_transid 2
+#define ptpip_event_param1 6
+#define ptpip_event_param2 10
+#define ptpip_event_param3 14
+
static inline uint16_t
ptp_ptpip_event (PTPParams* params, PTPContainer* event, int wait)
{
- fprintf(stderr,"event()\n");
+ fd_set infds;
+ struct timeval timeout;
+ int ret;
+ unsigned char* data = NULL;
+ PTPIPHeader hdr;
+ int n;
+
+ while (1) {
+ if (wait == PTP_EVENT_CHECK_FAST) {
+ FD_ZERO(&infds);
+ FD_SET(params->evtfd, &infds);
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 1;
+ if (1 != select (params->evtfd+1, &infds, NULL, NULL, &timeout))
+ return PTP_RC_OK;
+ }
+ ret = ptp_ptpip_evt_read (params, &hdr, &data);
+ if (ret != PTP_RC_OK)
+ return ret;
+ gp_log (GP_LOG_DEBUG,"ptpip/event", "hdr type %d, length %d", hdr.type, hdr.length);
+
+ if (dtoh32(hdr.type) == PTPIP_EVENT) {
+ break;
+ }
+
+ /* TODO: Handle cancel transaction and ping/pong
+ * If not PTPIP_EVENT, process it and wait for next PTPIP_EVENT
+ */
+ gp_log (GP_LOG_ERROR, "ptpip/event", "unknown/unhandled event type %d", dtoh32(hdr.type));
+ }
+
+ event->Code = dtoh16a(&data[ptpip_event_code]);
+ event->Transaction_ID = dtoh32a(&data[ptpip_event_transid]);
+ n = (dtoh32(hdr.length) - sizeof(hdr) - ptpip_event_param1)/sizeof(uint32_t);
+ switch (n) {
+ case 3: event->Param3 = dtoh32a(&data[ptpip_event_param3]);
+ case 2: event->Param2 = dtoh32a(&data[ptpip_event_param2]);
+ case 1: event->Param1 = dtoh32a(&data[ptpip_event_param1]);
+ case 0: break;
+ default:
+ gp_log( GP_LOG_ERROR, "ptpip/event", "response got %d parameters?", n);
+ break;
+ }
+ free (data);
return PTP_RC_OK;
}
@@ -656,18 +705,18 @@ ptp_ptpip_connect (PTPParams* params, const char *address) {
close (params->evtfd);
return GP_ERROR_IO;
}
- ret = ptp_ptpip_init_command_request (params);
- if (ret != PTP_RC_OK)
- return translate_ptp_result (ret);
- ret = ptp_ptpip_init_command_ack (params);
- if (ret != PTP_RC_OK)
- return translate_ptp_result (ret);
if (-1 == connect (params->evtfd, (struct sockaddr*)&saddr, sizeof(struct sockaddr_in))) {
perror ("connect evt");
close (params->cmdfd);
close (params->evtfd);
return GP_ERROR_IO;
}
+ ret = ptp_ptpip_init_command_request (params);
+ if (ret != PTP_RC_OK)
+ return translate_ptp_result (ret);
+ ret = ptp_ptpip_init_command_ack (params);
+ if (ret != PTP_RC_OK)
+ return translate_ptp_result (ret);
ret = ptp_ptpip_init_event_request (params);
if (ret != PTP_RC_OK)
return translate_ptp_result (ret);