forked from Team254/cheesy-arena
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30b59ed
commit fbe4dfe
Showing
4 changed files
with
102 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2018 Team 254. All Rights Reserved. | ||
// Author: [email protected] (Patrick Fairbank) | ||
// | ||
// Web handlers for the field monitor display showing robot connection status. | ||
|
||
package web | ||
|
||
import ( | ||
//"github.com/Team254/cheesy-arena/game" | ||
//"github.com/Team254/cheesy-arena/model" | ||
"encoding/json" | ||
"net/http" | ||
|
||
) | ||
|
||
|
||
// RequestPayload represents the structure of the incoming POST data. | ||
type RequestPayload struct { | ||
Channel int `json:"channel"` | ||
State bool `json:"state"` | ||
} | ||
|
||
// Renders the field monitor display. | ||
func (web *Web) eStopStatePostHandler(w http.ResponseWriter, r *http.Request) { | ||
// Ensure the request is a POST request. | ||
if r.Method != http.MethodPost { | ||
http.Error(w, "Invalid request method", http.StatusMethodNotAllowed) | ||
return | ||
} | ||
|
||
// Parse the request body. | ||
var payload []RequestPayload | ||
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil { | ||
http.Error(w, "Invalid request payload", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
for _, item := range payload { | ||
web.arena.Plc.SetAlternateIOStopState(item.Channel, item.State) | ||
} | ||
|
||
// Respond with success. | ||
w.WriteHeader(http.StatusOK) | ||
w.Write([]byte("eStop state updated successfully.")) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters