Fix up the incomplete Webserver project so that it integrates with the uIP stack...
[pub/USBasp.git] / Demos / Device / Incomplete / Sideshow / Lib / SideshowCommands.c
index 2726d50..0353af4 100644 (file)
@@ -1,21 +1,21 @@
 /*\r
              LUFA Library\r
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
+     Copyright (C) Dean Camera, 2010.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  copies and that both that the copyright notice and this\r
-  permission notice and warranty disclaimer appear in supporting\r
-  documentation, and that the name of the author not be used in\r
-  advertising or publicity pertaining to distribution of the\r
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, distribute, and sell this \r
+  software and its documentation for any purpose is hereby granted\r
+  without fee, provided that the above copyright notice appear in \r
+  all copies and that both that the copyright notice and this\r
+  permission notice and warranty disclaimer appear in supporting \r
+  documentation, and that the name of the author not be used in \r
+  advertising or publicity pertaining to distribution of the \r
   software without specific, written prior permission.\r
 \r
   The author disclaim all warranties with regard to this\r
   software without specific, written prior permission.\r
 \r
   The author disclaim all warranties with regard to this\r
@@ -134,9 +134,9 @@ static void SideShow_Sync(SideShow_PacketHeader_t* PacketHeader)
        Endpoint_Read_Stream_LE(&ProtocolGUID, sizeof(GUID_t));\r
        Endpoint_ClearOUT();\r
        \r
        Endpoint_Read_Stream_LE(&ProtocolGUID, sizeof(GUID_t));\r
        Endpoint_ClearOUT();\r
        \r
-       if (memcmp(&ProtocolGUID, (uint32_t[])STANDARD_PROTOCOL_GUID, sizeof(GUID_t)) != 0)\r
+       if (!(GUID_COMPARE(&ProtocolGUID, (uint32_t[])STANDARD_PROTOCOL_GUID)))\r
          PacketHeader->Type.NAK = true;\r
          PacketHeader->Type.NAK = true;\r
-\r
+       \r
        Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM);\r
        Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t));                \r
        Endpoint_Write_Stream_LE(&ProtocolGUID, sizeof(GUID_t));\r
        Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM);\r
        Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t));                \r
        Endpoint_Write_Stream_LE(&ProtocolGUID, sizeof(GUID_t));\r
@@ -179,7 +179,7 @@ static void SideShow_GetCapabilities(SideShow_PacketHeader_t* PacketHeader)
 \r
        PacketHeader->Length = sizeof(SideShow_PacketHeader_t);\r
 \r
 \r
        PacketHeader->Length = sizeof(SideShow_PacketHeader_t);\r
 \r
-       if (memcmp(&Property.PropertyGUID, (uint32_t[])SIDESHOW_PROPERTY_GUID, sizeof(GUID_t)) == 0)\r
+       if (GUID_COMPARE(&Property.PropertyGUID, (uint32_t[])SIDESHOW_PROPERTY_GUID))\r
        {\r
                switch (Property.PropertyID)\r
                {\r
        {\r
                switch (Property.PropertyID)\r
                {\r
@@ -233,7 +233,7 @@ static void SideShow_GetCapabilities(SideShow_PacketHeader_t* PacketHeader)
                                break;\r
                }\r
        }\r
                                break;\r
                }\r
        }\r
-       else if (memcmp(&Property.PropertyGUID, (uint32_t[])DEVICE_PROPERTY_GUID, sizeof(GUID_t)) == 0)\r
+       else if (GUID_COMPARE(&Property.PropertyGUID, (uint32_t[])DEVICE_PROPERTY_GUID))\r
        {\r
                switch (Property.PropertyID)\r
                {\r
        {\r
                switch (Property.PropertyID)\r
                {\r
@@ -295,21 +295,26 @@ static void SideShow_GetString(SideShow_PacketHeader_t* PacketHeader, void* Unic
 \r
 static void SideShow_GetApplicationOrder(SideShow_PacketHeader_t* PacketHeader)\r
 {\r
 \r
 static void SideShow_GetApplicationOrder(SideShow_PacketHeader_t* PacketHeader)\r
 {\r
-       uint8_t TotalInstalledApplications = SideShow_GetTotalApplications();\r
-       uint16_t GadgetGUIDBytes           = (TotalInstalledApplications * sizeof(GUID_t));\r
-\r
+       uint8_t  TotalApplications = 0;\r
+                  \r
        Endpoint_ClearOUT();\r
 \r
        Endpoint_ClearOUT();\r
 \r
+       for (uint8_t App = 0; App < MAX_APPLICATIONS; App++)\r
+       {\r
+               if (InstalledApplications[App].InUse)\r
+                 TotalApplications++;\r
+       }\r
+\r
        PacketHeader->Length = sizeof(SideShow_PacketHeader_t) +\r
        PacketHeader->Length = sizeof(SideShow_PacketHeader_t) +\r
-                              sizeof(uint32_t) + GadgetGUIDBytes;\r
+                              sizeof(uint32_t) + (TotalApplications * sizeof(GUID_t));\r
        \r
        Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM);\r
        Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t));\r
        \r
        Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM);\r
        Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t));\r
-       Endpoint_Write_DWord_LE(TotalInstalledApplications);\r
+       Endpoint_Write_DWord_LE(TotalApplications);\r
        \r
        for (uint8_t App = 0; App < MAX_APPLICATIONS; App++)\r
        {\r
        \r
        for (uint8_t App = 0; App < MAX_APPLICATIONS; App++)\r
        {\r
-               if (InstalledApplications[App].InUse == true)\r
+               if (InstalledApplications[App].InUse)\r
                  Endpoint_Write_Stream_LE(&InstalledApplications[App].ApplicationID, sizeof(GUID_t));\r
        }\r
 \r
                  Endpoint_Write_Stream_LE(&InstalledApplications[App].ApplicationID, sizeof(GUID_t));\r
        }\r
 \r
@@ -386,9 +391,7 @@ static void SideShow_DeleteApplication(SideShow_PacketHeader_t* PacketHeader)
        SideShow_Application_t* AppToDelete = SideShow_GetApplicationFromGUID(&ApplicationGUID);\r
 \r
        if (AppToDelete != NULL)\r
        SideShow_Application_t* AppToDelete = SideShow_GetApplicationFromGUID(&ApplicationGUID);\r
 \r
        if (AppToDelete != NULL)\r
-       {\r
-               AppToDelete->InUse = false;\r
-       }\r
+         AppToDelete->InUse = false;\r
        else\r
          PacketHeader->Type.NAK = true;\r
 \r
        else\r
          PacketHeader->Type.NAK = true;\r
 \r