Skip to content

Commit e967f24

Browse files
author
brentru
committed
1 parent 8aae595 commit e967f24

File tree

3 files changed

+60
-60
lines changed

3 files changed

+60
-60
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@
137137
'remote_ip': 0,
138138
'remote_port': 0}
139139

140-
class WIZNET:
141-
"""Interface for WIZNET5k module.
140+
class WIZNET5K:
141+
"""Interface for WIZNET5K module.
142142
:param ~busio.SPI spi_bus: The SPI bus the Wiznet module is connected to.
143143
:param ~digitalio.DigitalInOut cs: Chip select pin.
144144
:param ~digitalio.DigitalInOut rst: Optional reset pin.

adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
BROADCAST_SERVER_ADDR = 255, 255, 255, 255
7676

7777
# pylint: enable=bad-whitespace
78-
_buff = bytearray(317)
78+
_BUFF = bytearray(317)
7979

8080
class DHCP:
8181
"""W5k DHCP Client implementation.
@@ -87,7 +87,7 @@ class DHCP:
8787
8888
"""
8989

90-
# pylint: disable=too-many-arguments, too-many-instance-attributes
90+
# pylint: disable=too-many-arguments, too-many-instance-attributes, invalid-name
9191
def __init__(self, eth, mac_address, timeout=1, timeout_response=1):
9292
self._timeout = timeout
9393
self._response_timeout = timeout_response
@@ -124,95 +124,95 @@ def send_dhcp_message(self, state, time_elapsed):
124124
attempted to acquire/renew a lease.
125125
"""
126126
# OP
127-
_buff[0] = DHCP_BOOT_REQUEST
127+
_BUFF[0] = DHCP_BOOT_REQUEST
128128
# HTYPE
129-
_buff[1] = DHCP_HTYPE10MB
129+
_BUFF[1] = DHCP_HTYPE10MB
130130
# HLEN
131-
_buff[2] = DHCP_HLENETHERNET
131+
_BUFF[2] = DHCP_HLENETHERNET
132132
# HOPS
133-
_buff[3] = DHCP_HOPS
133+
_BUFF[3] = DHCP_HOPS
134134

135135
# Transaction ID (xid)
136136
self._initial_xid = htonl(self._transaction_id)
137137
self._initial_xid = self._initial_xid.to_bytes(4, 'l')
138-
_buff[4:7] = self._initial_xid
138+
_BUFF[4:7] = self._initial_xid
139139

140140
# seconds elapsed
141-
_buff[8] = ((int(time_elapsed) & 0xff00) >> 8)
142-
_buff[9] = (int(time_elapsed) & 0x00ff)
141+
_BUFF[8] = ((int(time_elapsed) & 0xff00) >> 8)
142+
_BUFF[9] = (int(time_elapsed) & 0x00ff)
143143

144144
# flags
145145
flags = htons(0x8000)
146146
flags = flags.to_bytes(2, 'b')
147-
_buff[10] = flags[1]
148-
_buff[11] = flags[0]
147+
_BUFF[10] = flags[1]
148+
_BUFF[11] = flags[0]
149149

150150
# NOTE: Skipping cidaddr/yiaddr/siaddr/giaddr
151151
# as they're already set to 0.0.0.0
152152

153153
# chaddr
154-
_buff[28:34] = self._mac_address
154+
_BUFF[28:34] = self._mac_address
155155

156156
# NOTE: 192 octets of 0's, BOOTP legacy
157157

158158
# Magic Cookie
159-
_buff[236] = ((MAGIC_COOKIE >> 24)& 0xFF)
160-
_buff[237] = ((MAGIC_COOKIE >> 16)& 0xFF)
161-
_buff[238] = ((MAGIC_COOKIE >> 8)& 0xFF)
162-
_buff[239] = (MAGIC_COOKIE& 0xFF)
159+
_BUFF[236] = ((MAGIC_COOKIE >> 24)& 0xFF)
160+
_BUFF[237] = ((MAGIC_COOKIE >> 16)& 0xFF)
161+
_BUFF[238] = ((MAGIC_COOKIE >> 8)& 0xFF)
162+
_BUFF[239] = (MAGIC_COOKIE& 0xFF)
163163

164164
# Option - DHCP Message Type
165-
_buff[240] = 53
166-
_buff[241] = 0x01
167-
_buff[242] = state
165+
_BUFF[240] = 53
166+
_BUFF[241] = 0x01
167+
_BUFF[242] = state
168168

169169
# Option - Client Identifier
170-
_buff[243] = 61
170+
_BUFF[243] = 61
171171
# Length
172-
_buff[244] = 0x07
172+
_BUFF[244] = 0x07
173173
# HW Type - ETH
174-
_buff[245] = 0x01
174+
_BUFF[245] = 0x01
175175
# Client MAC Address
176176
for mac in range(0, len(self._mac_address)):
177-
_buff[246+mac] = self._mac_address[mac]
177+
_BUFF[246+mac] = self._mac_address[mac]
178178

179179
# Option - Host Name
180-
_buff[252] = 12
181-
_buff[253] = len(b"Wiznet") + 6
182-
_buff[254:260] = b"WIZnet"
180+
_BUFF[252] = 12
181+
_BUFF[253] = len(b"Wiznet") + 6
182+
_BUFF[254:260] = b"WIZnet"
183183

184184
for mac in range(0, 5):
185-
_buff[260+mac] = self._mac_address[mac]
185+
_BUFF[260+mac] = self._mac_address[mac]
186186

187187
if state == DHCP_REQUEST:
188188
# Set the parsed local IP addr
189-
_buff[266] = 50
190-
_buff[267] = 0x04
189+
_BUFF[266] = 50
190+
_BUFF[267] = 0x04
191191

192-
_buff[268:272] = self.local_ip
192+
_BUFF[268:272] = self.local_ip
193193
# Set the parsed dhcp server ip addr
194-
_buff[272] = 54
195-
_buff[273] = 0x04
196-
_buff[274:278] = self.dhcp_server_ip
194+
_BUFF[272] = 54
195+
_BUFF[273] = 0x04
196+
_BUFF[274:278] = self.dhcp_server_ip
197197

198-
_buff[278] = 55
199-
_buff[279] = 0x06
198+
_BUFF[278] = 55
199+
_BUFF[279] = 0x06
200200
# subnet mask
201-
_buff[280] = 1
201+
_BUFF[280] = 1
202202
# routers on subnet
203-
_buff[281] = 3
203+
_BUFF[281] = 3
204204
# DNS
205-
_buff[282] = 6
205+
_BUFF[282] = 6
206206
# domain name
207-
_buff[283] = 15
207+
_BUFF[283] = 15
208208
# renewal (T1) value
209-
_buff[284] = 58
209+
_BUFF[284] = 58
210210
# rebinding (T2) value
211-
_buff[285] = 59
212-
_buff[286] = 255
211+
_BUFF[285] = 59
212+
_BUFF[286] = 255
213213

214214
# Send DHCP packet
215-
self._sock.send(_buff)
215+
self._sock.send(_BUFF)
216216

217217
def parse_dhcp_response(self, response_timeout):
218218
"""Parse DHCP response from DHCP server.
@@ -228,44 +228,44 @@ def parse_dhcp_response(self, response_timeout):
228228
return 255
229229
time.sleep(0.05)
230230
# store packet in buffer
231-
_buff = self._sock.recv(packet_sz)[0]
231+
_BUFF = self._sock.recv(packet_sz)[0]
232232

233233
# Check OP, if valid, let's parse the packet out!
234-
assert _buff[0] == DHCP_BOOT_REPLY, "Malformed Packet - \
234+
assert _BUFF[0] == DHCP_BOOT_REPLY, "Malformed Packet - \
235235
DHCP message OP is not expected BOOT Reply."
236236

237237
# Client Hardware Address (CHADDR)
238238
chaddr = bytearray(6)
239239
for mac, _ in enumerate(chaddr):
240-
chaddr[mac] = _buff[28+mac]
240+
chaddr[mac] = _BUFF[28+mac]
241241

242242
if chaddr != 0:
243-
xid = _buff[4:8]
243+
xid = _BUFF[4:8]
244244
if bytes(xid) < self._initial_xid:
245245
return 0, 0
246246

247247
# Your IP Address (YIADDR)
248-
self.local_ip = _buff[16:20]
248+
self.local_ip = _BUFF[16:20]
249249

250250
# Gateway IP Address (GIADDR)
251-
self.gateway_ip = _buff[20:24]
251+
self.gateway_ip = _BUFF[20:24]
252252

253253
# NOTE: Next 192 octets are 0's for BOOTP legacy
254254

255255
# DHCP Message Type
256-
msg_type = _buff[242]
256+
msg_type = _BUFF[242]
257257
# DHCP Server ID
258-
self.dhcp_server_ip = _buff[245:249]
258+
self.dhcp_server_ip = _BUFF[245:249]
259259
# Lease Time, in seconds
260-
self._lease_time = int.from_bytes(_buff[251:255], 'l')
260+
self._lease_time = int.from_bytes(_BUFF[251:255], 'l')
261261
# T1 value
262-
self._t1 = int.from_bytes(_buff[257:261], 'l')
262+
self._t1 = int.from_bytes(_BUFF[257:261], 'l')
263263
# T2 value
264-
self._t2 = int.from_bytes(_buff[263:267], 'l')
264+
self._t2 = int.from_bytes(_BUFF[263:267], 'l')
265265
# Subnet Mask
266-
self.subnet_mask = _buff[269:273]
266+
self.subnet_mask = _BUFF[269:273]
267267
# DNS Server
268-
self.dns_server_ip = _buff[285:289]
268+
self.dns_server_ip = _BUFF[285:289]
269269

270270
return msg_type, xid
271271

examples/wiznet5k_simpletest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import board
44
import busio
55
import digitalio
6-
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET
6+
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
77
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
88

99
# Name address for wifitest.adafruit.com
@@ -13,7 +13,7 @@
1313
spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
1414

1515
# Initialize ethernet interface with DHCP
16-
eth = WIZNET(spi_bus, cs)
16+
eth = WIZNET5K(spi_bus, cs)
1717

1818
print("DHCP Assigned IP: ", eth.pretty_ip(eth.ip_address))
1919

0 commit comments

Comments
 (0)