feat(firmware): add OCPP schema and constants for charge point management

This commit is contained in:
2026-03-10 10:14:39 +08:00
parent 6014114098
commit 0f47b3d382
4 changed files with 279 additions and 3 deletions

View File

@@ -7,6 +7,11 @@ import { cors } from 'hono/cors'
import { logger } from 'hono/logger'
import { showRoutes } from 'hono/dev'
import { auth } from './lib/auth.ts'
import {
isSupportedOCPP,
SUPPORTED_OCPP_VERSIONS,
type SupportedOCPPVersion,
} from './constants.ts'
const app = new Hono<{
Variables: {
@@ -45,7 +50,7 @@ app.use(
app.on(['POST', 'GET'], '/api/auth/*', (c) => auth.handler(c.req.raw))
app.get('/', (c) => {
app.get('/api', (c) => {
const user = c.get('user')
const session = c.get('session')
@@ -66,13 +71,21 @@ app.get('/', (c) => {
})
app.get(
'/ocpp',
'/ocpp/:chargePointId',
upgradeWebSocket((c) => {
const chargePointId = c.req.param('chargePointId')
return {
onOpen(evt, ws) {
const subProtocol = ws.protocol || 'unknown'
if (!isSupportedOCPP(subProtocol)) {
ws.close(1002, 'Unsupported subprotocol')
return
}
const connInfo = getConnInfo(c)
console.log(
`New connection from ${connInfo.remote.address}:${connInfo.remote.port}`,
`New connection from ${connInfo.remote.address}:${connInfo.remote.port} for station ${chargePointId}`,
)
},
onMessage(evt, ws) {