147 struct timeval
TV = { 0 , 0};
229 RESULT RetRes = FAIL;
243 printf(
"cDaisyDownTxStreamCmd - DAISY_WR_DISCONNECTED\n\r");
257 printf(
"cDaisyDownTxStreamCmd - DAISY_WR_NOT_FINISHED\n\r");
270 printf(
"cDaisyDownStreamCmd - DAISY_WR_ERROR\n\r");
285 printf(
"cDaisyDownStreamCmd - DAISY_WR_ERROR\n\r");
317 return (uint)(Port + (Layer * 4));
322 UBYTE MagicCookie = 0;
323 UBYTE BitFieldPointer = 0x01;
326 uint StorePointer = StoreFrom;
328 for(i = 0; i < 4; i++)
330 if(PortField & BitFieldPointer)
332 LargePointer = (uint)(i + (Layer * 4));
336 MagicCookie |= Layer;
337 DataOut[StorePointer] = MagicCookie;
346 BitFieldPointer = (
UBYTE)(BitFieldPointer << 1);
365 UBYTE CheckBit = 0x01;
367 StartPort = (4 * Layer);
369 for(Port = StartPort ; Port < (StartPort + 4); Port++)
379 printf(
"cDaisyCheckBusyBit = %X\n\r", RetVal);
395 CookieIndex = (uint)((Layer * 4) + Port);
401 RESULT Result = FAIL;
409 printf(
"cDaisyMotorDownStream called\n\r");
429 Len = Length + 5 + 4;
439 memcpy(&(
DataOut[7]), pData, Length);
445 printf(
"cDaisyMotorDownStream sent as DAISY_COMMAND_NO_REPLY + DAISY_CHAIN_DOWNSTREAM_WITH_BUSY\n\r");
448 printf(
"DataOut =\n\r");
449 for(ii = 0; ii < (Len+2); ii++)
452 printf(
"DaisyBusyFlags =\n\r");
453 for(ii = 0; ii < 16; ii++)
464 Len = Length + 3 + 4;
471 memcpy(&(
DataOut[5]), pData, Length);
479 printf(
"cDaisyMotorDownStream sent as a normal DIR_CMD_NO_REPLY_WITH_BUSY\n\r");
480 printf(
"After cDaisySetupMagicCookies\n\r");
482 for(help2 = 0; help2 < (Len + 2); help2++)
484 printf(
"%X, ",
DataOut[help2]);
533 RESULT Result = FAIL;
554 printf(
"Did we reach here??\n\r");
557 switch(ReadUsbTransfer->
status)
566 printf(
"\n\rcDaisyAsyncReadCallBack - LIBUSB_TRANSFER_COMPLETED\n\r");
577 printf(
"\n\rcDaisyAsyncReadCallBack - LIBUSB_TRANSFER_TIMED_OUT\n\r");
589 printf(
"\n\rcDaisyAsyncReadCallBack - LIBUSB_TRANSFER_NO_DEVICE\n\r");
603 printf(
"\n\rcDaisyAsyncReadCallBack - LIBUSB_ALL_ERROR\n\r");
615 libusb_fill_interrupt_transfer( ReadTransfer,
635 printf(
"\n\rcDaisyStartReadUnlockAnswer - LIBUSB_SUCCESS\n\r");
647 printf(
"\n\rDaisyStartReadUnlockAnswer - LIBUSB_ERROR_NO_DEVICE\n\r");
658 printf(
"\n\rDaisyStartReadUnlockAnswer - LIBUSB_DEFAULT\n\r");
667 RESULT RetRes = FAIL;
699 memcpy(&(
DataOut[7]), pData, Length);
711 DataOut[4] = DIRECT_COMMAND_NO_REPLY;
713 memcpy(&(
DataOut[5]), pData, Length);
730 UBYTE ThisMagicCookie;
737 printf(
"Here is the call from the HOST to cDaisyCmd\n\r");
746 switch((*pDaisyCmd).DaisyCmd)
753 pDaisyUnlockReply->
Status = OK;
787 printf(
"DAISY_SET_TYPE\n\r");
791 if((*pDaisyCmd).Layer < 1)
799 printf(
"DAISY_SET_TYPE layer < 1 : ");
809 printf(
"DAISY_SET_TYPE Further DOWN\n\r");
812 (*pDaisyCmd).Layer = ((*pDaisyCmd).Layer - 1);
815 memcpy(&(
DataOut[0]), pComCmd, ((*pComCmd).CmdSize + 2));
828 printf(
"Here is the call from the HOST to cDaisyCmd DAISY_CHAIN_DOWNSTREAM - Daisy Layer set to %d\n\r", (*pDaisyCmd).Layer);
831 if((*pDaisyCmd).Layer == 1)
835 (*pComCmd).Cmd = DIRECT_COMMAND_NO_REPLY;
838 (*pComCmd).CmdSize = (*pComCmd).CmdSize - 2;
840 memcpy(&(
DataOut[0]), &((*pComCmd).CmdSize), 5);
843 memcpy(&(
DataOut[5]), &((*pComCmd).PayLoad[2]), ((*pComCmd).CmdSize - 3));
848 printf(
"DAISY_CHAIN_DOWNSTREAM sent as a DIRECT command\n\r");
853 (*pDaisyCmd).Layer = ((*pDaisyCmd).Layer - 1);
855 memcpy(&(
DataOut[0]), pComCmd, ((*pComCmd).CmdSize + 2));
860 printf(
"DAISY_CHAIN_DOWNSTREAM sent as a further down command\n\r");
873 printf(
" case DAISY_CHAIN_DOWNSTREAM_WITH_BUSY - (*pDaisyCmd).Layer == %d\n\r", (*pDaisyCmd).Layer );
886 for(CommandPointer = 3; CommandPointer >= 0; CommandPointer--)
889 ThisMagicCookie = (*pComCmd).PayLoad[((*pComCmd).CmdSize) - CommandPointer -
PAYLOAD_OFFSET];
893 LayerByte |= (
UBYTE)(ThisMagicCookie & 0x03);
906 printf(
"DaisyBusyFlags DOWN:\r\n");
908 for(DebugP = 0; DebugP < 16; DebugP++)
911 printf(
"\r\nCookie setting done..(*pDaisyCmd).Layer == %d OwnLayer == %d\r\n", (*pDaisyCmd).Layer,
cDaisyOwnLayer);
915 if((*pDaisyCmd).Layer == 1)
922 (*pComCmd).CmdSize = (*pComCmd).CmdSize - 2;
925 memcpy(&(
DataOut[0]), &((*pComCmd).CmdSize), 5);
928 memcpy(&(
DataOut[5]), &((*pComCmd).PayLoad[2]), ((*pComCmd).CmdSize - 4));
932 (*pDaisyCmd).Layer = ((*pDaisyCmd).Layer - 1);
935 memcpy(&(
DataOut[0]), pComCmd, ((*pComCmd).CmdSize + 2));
957 return (InSize <= OutSize) ? InSize : OutSize;
965 DATA8 SpeedResult = FULL_SPEED;
968 if((*pUsbSpeed).Speed == FULL_SPEED)
974 printf(
"Connected to FULL_SPEED on Gadget side - DAISY chained\n\r");
982 SpeedResult = HIGH_SPEED;
988 printf(
"Connected to HIGH_SPEED on Gadget side\n\r");
1024 RESULT Result = FAIL;
1026 USB_SPEED *pUsbSpeedTemp;
1030 UsbFile = open(USBDEV_DEVICE_NAME,O_RDWR | O_SYNC);
1035 printf(
"UsbFile = %d\r\n", UsbFile);
1040 pUsbSpeedTemp = (USB_SPEED*)mmap(0,
sizeof(
UWORD), PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, UsbFile, 0);
1042 if(pUsbSpeedTemp == MAP_FAILED)
1047 printf(
"MAP_FAILED\n\r");
1060 printf(
"OK pUsbSpeed in c_Daisy\n\r");
1071 RESULT RetRes = BUSY;
1077 printf(
"Writing TYPE/MODE to SLAVE - Layer = %d, Port = %d, Type = %d, Mode = %d\r\n", Layer, Port, Type, Mode);
1102 printf(
"cDaisyWriteTypeDownstream - DAISY_WR_DISCONNECTED\n\r");
1118 printf(
"cDaisyWriteTypeDownstream - DAISY_WR_NOT_FINISHED\n\r");
1133 printf(
"cDaisyWriteTypeDownstream - DAISY_WR_ERROR\n\r");
1159 RESULT RetVal = FAIL;
1163 printf(
"cDaisySetDeviceType in cDaisy\n\r");
1214 RESULT Result = FAIL;
1220 printf(
"\n\rDaisy Init called\n\r");
1247 if((*pUsbSpeed).Speed == HIGH_SPEED)
1253 printf(
"Connected to HIGH_SPEED on Gadget side\n\r");
1263 printf(
"Connected to FULL_SPEED on Gadget side\n\r");
1279 printf(
"\n\rDaisy Temp >= 0 \n\r");
1298 printf(
"\n\rDaisy valid InterFace??? We have if this is seen...;-)\n\r");
1327 printf(
"\n\rDaisy Init ended (HOST)\n\r");
1338 printf(
"Writing UNLOCK to SLAVE\r\n");
1372 RESULT RetVal = FAIL;
1399 RESULT RetResult = BUSY;
1406 printf(
"cDaisySetDeviceInfo, PushState == DAISY_PUSH_CONNECTED\n\r");
1414 printf(
"cDaisySetDeviceInfo, DaisyInfo == EMPTY\n\r");
1424 for(loop = 0; loop < Length; loop++)
1426 printf(
"DaisyInfoBuffer[%d] = 0x%x\r\n", loop,
DaisyInfoBuffer[loop]);
1453 RESULT SensorResult = FAIL;
1459 printf(
"Her we call c_daisy cDaisyPushUpStream\n\r");
1489 printf(
"cDaisyPushUpStream INFO done!!!!\n\r");
1512 pDaisyReply->
Status = SensorResult;
1518 printf(
"Self DATA (PUSH) collected here: ReadLayerP: %d, ReadSensorP: %d, DeviceNo: %d, Status %d\r\n",
ReadLayerPointer,
ReadSensorPointer, DeviceNo, SensorResult);
1542 printf(
"Before own in PUSH:");
1544 for(w = 0; w < 16; w++)
1556 printf(
"Push MotorFlags from cMotorGetBusyFlags() = %X\n\r", MotorFlags);
1570 printf(
"StartIndex Getting cMotorGetBusyFlags() = %d\n\r", StartIndex);
1573 for(j = StartIndex; j < (StartIndex + 4); j++)
1609 for(z = 0; z < 16; z++)
1611 printf(
"[%d]=%X @ StartIndex:%d", z,
DaisyBusyFlags[z], StartIndex);
1622 printf(
"StreamDataReady set TRUE\n\r");
1633 for(nn = 2; nn < 4; nn++)
1653 printf(
"ReadSensorPointer %d at PrepareNext lige foer reset\n\r",
ReadSensorPointer);
1675 RESULT Result = FAIL;
1680 printf(
"Layer (+1): %d, Port: %d", Layer, Sensor);
1690 NormSensor = Sensor;
1698 if((Layer == 0) && (NormSensor == 1))
1702 case OK: printf(
"Layer 0, Sensor 1, OK\n\r");
1705 case BUSY: printf(
"Layer 0, Sensor 1, BUSY\n\r");
1708 case FAIL: printf(
"Layer 0, Sensor 1, FAIL\n\r");
1711 case STOP: printf(
"Layer 0, Sensor 1, STOP\n\r");
1746 printf(
"Did I reach callback?? 01\r\n");
1755 switch( WriteUsbTransfer->
status)
1763 printf(
"Did I reach callback?? 02\r\n");
1775 printf(
"Did I reach callback?? 03\r\n");
1795 printf(
"Did I reach callback?? 04\r\n");
1809 int EventResult = 0;
1855 int EventResult = 0;
1857 int TempStorePointer = 0;
1874 printf(
"\n\rcDaisyPollFromDownstream - DAISY_RD_DONE - length = %d\n\r",
ReadLength);
1882 printf(
"--DATAIN---\n\r");
1883 for (x = 0; x < 16; x++)
1884 printf(
"%d, ",
DataIn[x]);
1886 for (x = 16; x < 32; x++)
1887 printf(
"%d, ",
DataIn[x]);
1911 printf(
"DaisyInfo from DownStream\n\r");
1947 printf(
"DaisyData polled from DownStream\n\r");
1969 if((
DataIn[k] & 0x80) == 0x00)
1985 if(TempStorePointer > 15)
1998 printf(
"-----\n\r");
1999 for (j = 0; j < 4; j++)
2001 for (i = 0; i < 8; i++)
2003 for (z = 0; z < 32; z++)
2038 printf(
"\n\rcDaisyPollFromDownstream - DAISY_RD_REQUESTED\n\r");
2051 printf(
"\n\rcDaisyPollFromDownstream - DAISY_RD_DISCONNECTED\n\r");
2060 printf(
"\n\rcDaisyPollFromDownstream - DAISY_RD_TIMEDOUT\n\r");
2073 printf(
"\n\rcDaisyPollFromDownstream - DAISY_RD_ERROR\n\r");
2090 printf(
"\n\rcDaisyPollFromDownstream - Device_handle = NULL\n\r");
2095 if(ReadTransfer ==
NULL)
2100 printf(
"\n\rcDaisyPollFromDownstream - ReadTransfer = NULL\n\r");
2106 libusb_fill_interrupt_transfer( ReadTransfer,
2125 printf(
"\n\rcDaisyPollFromDownstream REQ - LIBUSB_SUCCESS\n\r");
2138 printf(
"\n\rcDaisyPollFromDownstream - LIBUSB_ERROR_NO_DEVICE\n\r");
2149 printf(
"\n\rcDaisyPollFromDownstream - LIBUSB_DEFAULT\n\r");
2170 printf(
"DAISY WriteState and IDLE\r\n");
2174 libusb_fill_interrupt_transfer( WriteTransfer,
2188 printf(
"ResValue from write submit = %d\n\r", ResValue);
2199 printf(
"Write submit LIBUSB_SUCCESS\n\r");
2213 printf(
"Write submit LIBUSB_ERROR_NO_DEVICE\n\r");
2227 printf(
"Write submit LIBUSB_ERROR_BUSY\n\r");
2240 printf(
"Write submit DEFAULT in switch\n\r");
2251 RESULT Result = FAIL;
2256 printf(
"cDaisyUnlockOk\n\r");
2266 printf(
"Did we reach RD_DONE in UnLockOk?\n\r");
2275 printf(
"cDaisyUnlockOk -> OK\n\r");
2285 printf(
"cDaisyUnlockOk -> FAIL\n\r");
2309 FILE *pIdVendor =
NULL;
2310 FILE *pIdProduct =
NULL;
2311 char VendorBuffer[64];
2312 char ProductBuffer[64];
2313 RESULT Result = FAIL;
2315 pIdVendor = fopen(
"/sys/bus/usb/devices/1-1/idVendor",
"r");
2317 pIdProduct = fopen(
"/sys/bus/usb/devices/1-1/idProduct",
"r");
2319 if((pIdVendor !=
NULL) && (pIdProduct !=
NULL))
2321 if(fgets(VendorBuffer,
sizeof (VendorBuffer), pIdVendor) !=
NULL)
2323 if(fgets(ProductBuffer,
sizeof (ProductBuffer), pIdProduct) !=
NULL)
2331 if(pIdVendor !=
NULL)
2334 if(pIdProduct !=
NULL)
2342 static ULONG TimeOld = 0;
2356 TimeDiff = TimeNew - TimeOld;
2371 int EventResult = 0;
2383 printf(
"DAISY_DOWN_DISCONNECTED\r\n");
2401 printf(
"DAISY disconnected DOWNSTREAM - No slave bricks!! \r\n");
2412 printf(
"DAISY_DOWN_CONNECTED\r\n");
2427 printf(
"DAISY_DOWN_UNLOCKING\r\n");
2439 printf(
"Before cDaisyStartReadUnlockAnswer()\r\n");
2452 printf(
"DAISY_CHECK_UNLOCK ReadState = %d\r\n",
ReadState);
2460 printf(
"DAISY_RD_DONE\n\r");
2468 printf(
"cDaisyUnlockOk() returned OK\n\r");
2479 printf(
"cDaisyUnlockOk() failed :-( \n\r");
2499 printf(
"DAISY_DOWN_UNLOCKED\r\n");
void cDaisyResetBusyTiming(void)
#define DAISY_INTERRUPT_EP_IN
#define DAISY_CHAIN_DOWNSTREAM_WITH_BUSY
RESULT cDaisyDownStreamCmd(DATA8 *pData, DATA8 Length, DATA8 Layer)
UBYTE cDaisyCheckBusyBit(UBYTE Layer, UBYTE PortBits)
void cDaisyStartReadUnlockAnswer(void)
int GetSensorPointer(void)
#define DAISY_SENSOR_DATA_SIZE
void cDaisySetupMagicCookies(uint StoreFrom, UBYTE Layer, UBYTE PortField)
MSGCNT cDaisyReplyNumber(void)
RESULT cDaisyCheckForAttachedSlave(void)
#define DAISY_MAX_SENSORS_PER_LAYER
void cDaisyFlagDisconnected(DATA8 StartLayer)
void DaisyZeroAllExceptMySelf(void)
void cDaisyFlagFail(DATA8 Layer, DATA8 Sensor)
void cDaisySetMasterCookie(uint Index, UBYTE CookieValue)
void cDaisySetTimeout(int TimeOut)
uint GetDaisyPushCounter(void)
void cDaisySetOwnLayer(UBYTE Layer)
struct libusb_device_handle libusb_device_handle
#define SENSOR_POS_TO_SLAVE
void LogErrorNumber(ERR Err)
#define DAISY_MAX_LAYER_DEPT
int libusb_detach_kernel_driver(libusb_device_handle *dev, int interface)
#define DAISY_DEVICE_PAYLOAD_SIZE
UBYTE DaisyBusyFlags[BUSYFLAGS]
int cDaisyGetLastWriteState(void)
void DaisyResetTheBuffers(int FromLayer)
void DaisyAsyncReadCallBack(struct libusb_transfer *ReadUsbTransfer)
#define BUSYFLAGS_START_POS
int libusb_release_interface(libusb_device_handle *dev, int iface)
RESULT cDaisyCreateSpeedInfo(void)
libusb_device * libusb_get_device(libusb_device_handle *dev_handle)
void ResetDaisyPushCounter(void)
RESULT cDaisyCheckBusyIndex(UBYTE Layer, UBYTE Port)
#define DAISY_COMMAND_REPLY
#define TIME_TO_CHECK_FOR_DAISY_DOWNSTREAM
#define DAISY_PRIORITY_COUNT
DATA8 cDaisyGetUsbUpStreamSpeed(void)
#define DAISY_COMMAND_NO_REPLY
UBYTE DaisyUpstreamDataBuffer[DAISY_DEFAULT_MAX_EP_SIZE]
uint cDaisyGetPosFromLayerAndPort(UBYTE Layer, UBYTE Port)
DATA8 DaisyTempTypeSensor
int DaisyUpstreamDataReady
struct libusb_device_handle * DeviceHandle
RESULT cDaisyGetDeviceInfo(DATA8 Length, UBYTE *pInfo)
enum libusb_transfer_status status
int cDaisyWriteDone(void)
int cDaisyWriteUnlockToSlave()
USB_SPEED UpStreamConnection
int GetSensorStorePointer(void)
int GetLayerStorePointer(void)
#define DAISY_SENSOR_OUTPUT_OFFSET
void cDaisySetBusyFlags(UBYTE Layer, UBYTE Port, UBYTE MagicCookie)
unsigned int ULONG
Basic Type used to symbolise 32 bit unsigned values.
void cDaisyPrepareNext(void)
#define DAISY_CHAIN_DOWNSTREAM
#define DAISY_INTERRUPT_EP_OUT
UBYTE DeviceData[DEVICE_MAX_DATA]
DATA8 DaisyBuffers[DAISY_MAX_LAYER_DEPT][DAISY_MAX_SENSORS_PER_LAYER][DAISY_MAX_DATASIZE]
#define MAX_DEVICE_INFOLENGTH
Number of bytes in the structure above (can not be changed)
#define SIZEOF_REPLY_DAISY_READ
int libusb_get_max_packet_size(libusb_device *dev, unsigned char endpoint)
void cDaisyPollFromDownStream(void)
void cDaisyStuffRefill(void)
UBYTE cDaisyGetOwnLayer(void)
struct libusb_transfer * WriteTransfer
struct libusb_transfer * libusb_alloc_transfer(int iso_packets)
void libusb_close(libusb_device_handle *dev_handle)
UBYTE DataOut[DAISY_DEFAULT_MAX_EP_SIZE]
RESULT cDaisyUnlockOk(void)
int GetLayerPointer(void)
RESULT cDaisyMotorDownStream(DATA8 *pData, DATA8 Length, DATA8 Layer, DATA8 PortField)
#define DIR_CMD_NO_REPLY_WITH_BUSY
RESULT cDaisyWriteTypeDownstream(DATA8 Layer, DATA8 Port, DATA8 Type, DATA8 Mode)
#define DAISY_MAX_DATASIZE
void libusb_free_transfer(struct libusb_transfer *transfer)
void cDaisyUpdateLocalBusyFlags(UBYTE Layer)
unsigned char UBYTE
Basic Type used to symbolise 8 bit unsigned values.
RESULT cDaisyGetDownstreamData(DATA8 Layer, DATA8 Sensor, DATA8 Length, DATA8 *pType, DATA8 *pMode, DATA8 *pData)
void cDaisyIncrementMasterCookie(uint Index)
#define MODE_POS_TO_SLAVE
void DaisyZeroTheBuffers(void)
int libusb_handle_events_timeout(libusb_context *ctx, struct timeval *tv)
RESULT cDaisyChained(void)
#define DAISY_MAX_EP_IN_SIZE
int cDaisyGetMaxPacketSize(libusb_device_handle *DeviceHandle)
#define DAISY_UPSTREAM_DATA_LENGTH
UBYTE cDaisyMasterCookieArray[16]
unsigned short UWORD
Basic Type used to symbolise 16 bit unsigned values.
libusb_device_handle * libusb_open_device_with_vid_pid(libusb_context *ctx, uint16_t vendor_id, uint16_t product_id)
RESULT cDaisyTxDownStream(void)
RESULT cDaisySetDeviceType(DATA8 Layer, DATA8 Port, DATA8 Type, DATA8 Mode)
int libusb_submit_transfer(struct libusb_transfer *transfer)
void cDaisyFlagBusy(DATA8 Layer, DATA8 Sensor)
void cDaisyCmd(RXBUF *pRxBuf, TXBUF *pTxBuf)
#define DAISY_MAX_INPUT_SENSOR_INDEX
#define LAYER_POS_TO_SLAVE
#define SIZEOF_UNLOCK_REPLY
int cDaisyGetLastWriteResult(void)
#define TYPE_POS_TO_SLAVE
int cDaisyGetInterruptPacketSize(void)
#define DAISY_PUSH_NOT_UNLOCKED
void DaisyAsyncWriteCallBack(struct libusb_transfer *WriteUsbTransfer)
void cDaisyPushUpStream(void)
int GetSlaveUnlocked(void)
SBYTE DATA8
VM Type for 1 byte signed value.
UWORD cDaisyData(UBYTE **pData)
UBYTE cMotorGetBusyFlags(void)
RESULT cDaisySetDeviceInfo(DATA8 Length, UBYTE *pInfo)
void DecrementDaisyPushCounter(void)
int libusb_init(libusb_context **ctx)
void cDaisyClearMasterCookie(uint Index)
void SetUnlocked(int Status)
#define DAISY_UNLOCK_SLAVE
int libusb_claim_interface(libusb_device_handle *dev, int iface)
UBYTE DaisyInfoBuffer[DAISY_DEFAULT_MAX_EP_SIZE]
#define SIZEOF_DAISY_INFO_READ
struct libusb_transfer * ReadTransfer
#define DAISY_DEFAULT_MAX_EP_SIZE
void libusb_exit(libusb_context *ctx)
void SetDaisyPushCounter(int Count)
int MaxInterruptPacketSize
#define DAISY_CHAIN_UPSTREAM
#define DAISY_DATA_PACKET
void SetSlaveUnlocked(int Status)
UBYTE DataIn[DAISY_DEFAULT_MAX_EP_SIZE]
#define DAISY_DEFAULT_TIMEOUT