diff --git a/firmware/src/main.rs b/firmware/src/main.rs index cd2c996..245cf6f 100644 --- a/firmware/src/main.rs +++ b/firmware/src/main.rs @@ -11,7 +11,7 @@ use core::cell::{Cell, RefCell}; use core::fmt; use cortex_m::interrupt::Mutex; use smoltcp::Error; -use smoltcp::wire::{EthernetAddress, IpAddress}; +use smoltcp::wire::EthernetAddress; use smoltcp::iface::{ArpCache, SliceArpCache, EthernetInterface}; use smoltcp::socket::{AsSocket, SocketSet}; use smoltcp::socket::{TcpSocket, TcpSocketBuffer}; @@ -156,7 +156,7 @@ fn main() { println!("programmed MAC address is invalid, using default"); hardware_addr = EthernetAddress([0x10, 0xE2, 0xD5, 0x00, 0x03, 0x00]); } - let mut protocol_addrs = [IpAddress::v4(192, 168, 69, 1)]; + let mut protocol_addrs = [config.ip]; println!("MAC {} IP {}", hardware_addr, protocol_addrs[0]); let mut arp_cache_entries: [_; 8] = Default::default(); let mut arp_cache = SliceArpCache::new(&mut arp_cache_entries[..]); @@ -220,7 +220,7 @@ fn main() { match request_status { Ok(true) => { if socket.can_send() { - pages::serve(socket, &request, &LOOP_ANODE, &LOOP_CATHODE, &ELECTROMETER); + pages::serve(socket, &request, &mut config, &LOOP_ANODE, &LOOP_CATHODE, &ELECTROMETER); } request.reset(); socket.close(); diff --git a/firmware/src/network_settings.html b/firmware/src/network_settings.html new file mode 100644 index 0000000..6202ca7 --- /dev/null +++ b/firmware/src/network_settings.html @@ -0,0 +1,39 @@ + + +ionpak + + + + +
+

+ Measure + Gauge settings + Network settings + Firmware +
+ +
+ +
+

Network settings

+
+ +
+

{status}

+
+ +
+
+

+ +

+

+

+
+
+ +
+ + + diff --git a/firmware/src/pages.rs b/firmware/src/pages.rs index 5cd4ecf..f173e69 100644 --- a/firmware/src/pages.rs +++ b/firmware/src/pages.rs @@ -1,11 +1,13 @@ use core::fmt; use core::fmt::Write; use core::cell::RefCell; +use core::str; use cortex_m; use cortex_m::interrupt::Mutex; use smoltcp::socket::TcpSocket; use http; +use config; use loop_anode; use loop_cathode; use electrometer; @@ -31,6 +33,7 @@ impl fmt::LowerExp for OpnFmt { } pub fn serve(output: &mut TcpSocket, request: &http::Request, + config: &mut config::Config, loop_anode_m: &Mutex>, loop_cathode_m: &Mutex>, electrometer_m: &Mutex>) { @@ -61,6 +64,31 @@ pub fn serve(output: &mut TcpSocket, request: &http::Request, cathode_fbv=OpnFmt(cathode.fbv), ion_current=OpnFmt(electrometer.ic.and_then(|x| Some(x*1.0e9)))).unwrap(); }, + b"/network_settings.html" => { + let mut status = ""; + + let ip_arg = request.get_arg(b"ip"); + if ip_arg.is_ok() { + let ip_arg = str::from_utf8(ip_arg.unwrap()); + if ip_arg.is_ok() { + let ip = ip_arg.unwrap().parse(); + if ip.is_ok() { + let ip = ip.unwrap(); + status = "IP address has been updated and will be active after a reboot."; + config.ip = ip; + config.save(); + } else { + status = "failed to parse IP address"; + } + } else { + status = "IP address contains an invalid UTF-8 character"; + } + } + + http::write_reply_header(output, 200, "text/html; charset=utf-8", false).unwrap(); + write!(output, include_str!("network_settings.html"), + status=status, ip=config.ip).unwrap(); + }, b"/firmware.html" => { http::write_reply_header(output, 200, "text/html; charset=utf-8", false).unwrap(); write!(output, include_str!("firmware.html"),