Removed both sdCardMount and unMount api end points, they are now replaced by a single end point taking a parameter
This commit is contained in:
parent
ab6260a2ac
commit
65d43ae1d1
@ -124,34 +124,50 @@ boolean rtcSetTimeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean sdCardUnmountApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
|
||||
boolean sdCardActionApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
|
||||
{
|
||||
SdCardApiPacket *pV = (SdCardApiPacket*)pData;
|
||||
SAB *p = (SAB *)pV->pSab;
|
||||
float *sdCardSize = (float *) &pV->pView->sdCardSize;
|
||||
char buffer[200];
|
||||
p->getSdCardManager().unMountSD();
|
||||
*sdCardSize = 0.0;
|
||||
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"ok\", \"card\" : \"unmounted\" }");
|
||||
wc->print(buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean sdCardMountApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
|
||||
{
|
||||
SdCardApiPacket *pV = (SdCardApiPacket*)pData;
|
||||
SAB *p = (SAB *)pV->pSab;
|
||||
float *sdCardSize = (float *) &pV->pView->sdCardSize;
|
||||
char buffer[200];
|
||||
|
||||
if(p->getSdCardManager().mountSD())
|
||||
//We first retrieve the parameter that indicates the action :
|
||||
if(HRD.getParams.count() != 1)
|
||||
{
|
||||
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"ok\", \"card\" : \"mounted\" }");
|
||||
*sdCardSize = p->getSdCardManager().getSize(GBYTE);
|
||||
strcpy_P(buffer, PSTR("{\"status\":\"error\",\"message\":\"One and only one parameter is expected\"}"));
|
||||
}
|
||||
else
|
||||
sprintf(buffer,"HTTP/1.1 500 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"error\", \"message\" : \"begin failed\" }");
|
||||
|
||||
{
|
||||
if(HRD.getParams("action") != NULL)
|
||||
{
|
||||
if(strcmp_P(HRD.getParams("action")->getString(), PSTR("mount")) == 0)
|
||||
{
|
||||
if(p->getSdCardManager().mountSD())
|
||||
{
|
||||
strcpy_P(buffer, PSTR("{\"status\":\"ok\",\"card\":\"mounted\"}"));
|
||||
*sdCardSize = p->getSdCardManager().getSize(GBYTE);
|
||||
}
|
||||
else
|
||||
strcpy_P(buffer, PSTR("{\"status\":\"error\",\"message\":\"begin failed\"}"));
|
||||
}
|
||||
else if(strcmp_P(HRD.getParams("action")->getString(), PSTR("unmount")) == 0)
|
||||
{
|
||||
p->getSdCardManager().unMountSD();
|
||||
*sdCardSize = 0.0;
|
||||
strcpy_P(buffer, PSTR("{\"status\":\"ok\",\"card\":\"unmounted\"}"));
|
||||
}
|
||||
else //Error
|
||||
{
|
||||
strcpy_P(buffer, PSTR("{\"status\":\"error\",\"message\":\"Parameter 'action' should be mount or unmount\"}"));
|
||||
}
|
||||
}
|
||||
else //Error
|
||||
{
|
||||
strcpy_P(buffer, PSTR("{\"status\":\"error\",\"message\":\"Parameter should be 'action'\"}"));
|
||||
}
|
||||
}
|
||||
|
||||
WEBServer<WEBClient>::injectApiHeader(buffer, "application/json", buffer);
|
||||
wc->print(buffer);
|
||||
return true;
|
||||
}
|
||||
|
@ -16,8 +16,7 @@ typedef struct sdCardApiPacket
|
||||
SAB *pSab;
|
||||
View1Packet *pView;
|
||||
} SdCardApiPacket;
|
||||
boolean sdCardUnmountApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
|
||||
boolean sdCardMountApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
|
||||
boolean sdCardActionApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
|
||||
|
||||
boolean apScannerApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
|
||||
boolean staWifiInfoApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
|
||||
|
Loading…
Reference in New Issue
Block a user