Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
Ugh anybody have a good reference for me to learn how to C++(11?) on microcontrollers without burning the house down? I write C most of the time and C++ is weird to me as-is, but I want to be an hero and do it on a micro with interrupt handlers, no heap memory, minimal library support and all that other good stuff. Specifically Cortex-M0.

Adbot
ADBOT LOVES YOU

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

Awia posted:

i mean, i have a few copies of the same device, a bluetooth pedometer, exactly the same make and model

Are these devices using Bluetooth Low Energy, or classic (v3) Bluetooth? Often BLE devices will advertise their service UUIDs or include it in the scan response. This would be exactly what you'd want to filter on if you can get it. What are the contents of these devices' advertising packets?

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

:eyepop:

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
Man, I just don't *get* C++ or OOP. I'm not even sure which. There's nothing you can say to help me :(

I've got a deadline in a few hours and I've been holding back everybody else. Feels lovely. Just wanted to E/N post, thanks guys.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

I'm employed :smith:

My teammates are nice and help as much as they can but we have a rushed schedule and I've been bothering them too much anyway. I usually do embedded stuff in C, but that's about it. Now I'm writing a bunch of classes for a network protocol in babby's first C++11 that are supposed to work on both embedded and real-computer systems. If anything it's been a real eye-opener 'cause I was starting to get comfortable with my C stuff.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

Bloody posted:

oop takes your functions and structs and says "these should probably go together most of the time"

Understood, I sometimes write C like that for device drivers and it can work well in my simple mind. I even know how a vtable works (yeah, I know that's not impressive) it's just understanding how to use things like inheritance to my advantage, not disadvantage in a design that are hard.

I'm pissed off, I don't know poo poo about good OO architecture so here I am refucking the interfaces and relationships of these same objects for the Nth time in the last week because it "doesn't feel right" or because I didn't realize it needed to also do X and that screws everything up.

Yes I have Meyers' and the GoF books. No, I don't have time to read AND understand enough in time without an adderall prescription.

My co-workers are leaving me in the dust, even the new hire straight out of school (I've been here two years). Though I can poo poo on him because he doesn't bat an eye about committing code that causes dozens of compiler warnings (using int32_t as a pointer, wtf) or having a bunch of excessively-scoped (even global) variables all over his sources.

Goddammit I just want to quit this tech bullshit, the IoT can go straight to hell for all I care.

/rant

Hunter2 Thompson fucked around with this message at 19:32 on Sep 15, 2015

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
YOSPOS Terrible programmers are good friends :)

I printed out the Apple and NeXT manuals on my work's dime. I'm going to roll them into a huge spliff and smoke until I understand.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
You're clearly smart, so don't doubt yourself. I didn't have a problem understanding the code you posted, even if it was pretty disorganized. IMO most "good" programming is really just knowing the art of keeping things tidy and easy to understand at first-read. It's a craft and takes time to learn, but it's not difficult to do. Focus on this for maybe 8-10 hours of practice and you'll improve a ton.

Start writing and using functions to automate things you do often. The calls ClientSocket1.Socket.SendText are good candidates for this. Give them helpful names which describe what they do, but not how they do it.

That's all, good luck!

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

Blinkz0rz posted:

waiting on a call back to talk salary. any suggestions for negotiating?

If they give you a number you're happy with, say "I'm excited to start, but was thinking <5-10k> more since my *expertise in something* will bring you a lot of value". If they give you a number you don't like, say "I'm excited to work for you, but the typical pay is <a number you like + 5-10k>, but since I can bring your company a lot of value with my *expertise in something*, I was thinking more like <5-10k on top of that>".

Don't give a number first, if most experienced negotiators are to believed.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

NihilCredo posted:

so that is why a couple of my coworkers have this annoying habit of declaring all local variables at the start of a method instead of putting them in context. They both have a Delphi background, but I had never actually seen delphi so I never made the connection.

I always thought that was a prehistoric C thing from when compilers weren't smart enough to figure out how far to move the stack pointer on their own.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

Blinkz0rz posted:

that's exactly what i did. just negotiated a cool six and a half figgies plus 10% bonus per quarter plus stock options



NICE

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
hi(g_pTerrible_programmers);

Put yourself in my life for a moment: Work is me doing nasty embedded systems bitch work on a tight schedule to make rich people expensive toys, it puts the fear in me that I'll never move past insignificant work with slow microcontrollers.

One day I think: man, wouldn't it be cool to work remotely, travel and live an fulfilling life? Maybe if airport security didn't think my projectos are bombas this could work nicely. Maybe I should look into other tech sub-fields. It's not too unfamiliar that it's scary. I am going to become an interesting person. This will be great. Excitement builds inside me. YOSPOS, kill my dumb dreams.

I work for the only tech company in town and I walk to work somewhere in a nicer part of the (extended) SF bay area. Rent is cheap, house is nice, I live downtown, salary is not good for SF but decent here but my work is meaningless garbage. With these (super) first word problems and no internal direction, what would Y'ALLSPOS do?

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

Bloody posted:

I would get a MBA

Are MBAs the STEM equivalent of a Library Science degree for the humanities, or is the knowledge actually practical? I've heard MBAs are all about making connections while in the program.

gonadic io posted:

Volunteer to teach those skills at the weekend. Was it Sagebrush who helped out at a robotics club/competition thing for example?

I like this idea, my weekends are mostly empty and this could make me feel good.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

MononcQc posted:

hello fellow programmers, I have written a story and wanted to share it with you http://ferd.ca/the-little-printf.html

I love this. Your story makes me want to find some more meaning in what I've been doing for the last two years, it's gradually slipped away.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
I'm trying to work my way through the Algorithm Design Manual by Skiena, but I am incredulous / don't understand his solution for the "Psychic Modeling" War Story. Perhaps some of you have done this one or like a puzzle.

The premise is a psychic chooses a set S of n lottery numbers to play, knowing that j of the numbers in S are correct.

A purchased lottery ticket lets the buyer choose k numbers to play. If the player chooses l (that's an L) correct played numbers, the ticket is a winner. In Skiena's example n = 15, j = 4, k = 6, l = 3.

The idea is to buy the least number of lottery tickets while covering (all?) the l-subsets of S.

Here's a link to the full description, but I think I've paraphrased it decently. He follows with that he didn't model the problem correctly, but I don't understand this first attempt.

This is his pseudo-code [I use C(n, k) for 'n choose k']:

code:
LottoTicketSet(n, k, l)
    Initialize the C(n, l)-element bit-vector V to all false
    While there exists a false entry in V
        Select a k-subset T of {1, ..., n} as the next ticket to buy
        For each of the l-subsets T_i of T, V[rank(T_i)] = true
    Report the set of tickets bought
Using his numbers, there's a 455-long bit vector with each bit representing one of the l-sized subsets of S, right? Then the program loops until all of those are "covered", if I understand correctly.

I have trouble with the line "Select a k-subset T of {1, ..., n} as the next ticket to buy", does this literally mean to make a k-sized set of the numbers between 1 and n? Shouldn't it be out of S, the numbers the psychic guessed, not {1, ..., n}? And why doesn't j, the number of guesses that are known to be correct, come into this at all? Major confusion here!

After that, is rank() just a way to map the subset to the previously-mentioned bit vector? I think that's maybe the case.

Thanks YOSPOS, this isn't homework --I wish I learned this stuff in school though (I did computer engineering, aka watered-down EE).

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

LeftistMuslimObama posted:

Cynical reasons:
1) Variation on above, I was never supposed to get this far in life. I was born and raised in Wisconsin and I don't know that I'd even want to live in some of the major tech areas, even if I could get a job there. I doubt google is looking for programmers with poetry degrees and a history with the law.

The Google engineer on the other end of my first phone screen interview (which I absolutely flunked) had a degree in poetry, so don't discount yourself :)

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

pepito sanchez posted:

but being the terrible programmer i am i still recently did this



:doh:

As a terrible programmer, I don't get OO. Why is this terrible? Should you have just folded ReadWritable and ReadWriter into the Game class?

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

Barnyard Protein posted:

when game1,2,3 extend ReadWriter they also implement the ReadWritable interface because what they are extending implements it, so there is no need to explicitly declare that the game classes implement ReadWritable

Oh, duhhh :downs:

Thanks

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
I need to try something besides embedded C one of these days. Erlang sounds cool, maybe I can write embedded erlang...

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
i made you guys a video

https://www.youtube.com/watch?v=mnmIFu4WqE4

skip to 2:00 if you're an ADD

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
I wonder what percentage of humans would fail a turing test.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

BANME.sh posted:

terrible programmer here. what do you do when you feel completely out of your element on a project. and it makes you procrastinate way longer than you should. and when you do try to work on it, you don't really make any useful progress. and it's too late to ask for help because everyone would know you just pissed away all that time. so its a horrible combined feeling that you're inadequate and a fraud.

what do you do.

besides drink i mean.

asking for a friend.

I don't know, keep it up? If you're like me you also start falling asleep any time you try to get familiar with the technologies involved in the project.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
This year I got a knockoff CamelBak embroidered with the company logo. I've yet to see anybody wearing/sipping one at their desk yet, maybe I'll be the first!!!

Edit: I suppose it ought to be filled with Kool-Aid

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
No phones (except cell phones given away like candy/for development) where I work. The receptionist gets calls like that all day on the land-line but everybody is always "in a meeting". You think they'd get a hint, but the same people have been calling every day for months asking to speak with $list_of_employees.

Edit: They're mostly bottom-shelf Android phones though, not a brag.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
I'm trying to port u-boot to a stupid mediatek soc and it's loving hard and stresses me out :(

I'm humbled, u-boot is not that big of a project (but it's the largest I've ever touched) and it appears well-organized but I'm just so confused...

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
Stupid Linux thing: I want my program to poop out a core dump when it crashes, but I don't want other crashing programs to dump their core (I am on an embedded system, there is barely any memory). Nobody else has ever asked for this according to google. Possible/not possible?

Edit: I was looking for stuff about 'ulimit' called from a shell, but maybe I can use the systemcall setrlimit from inside my program!

Hunter2 Thompson fucked around with this message at 19:49 on Jan 20, 2016

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
Does C++ have a way to get string representations of enums yet?

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

VikingofRock posted:

Sure does!

C++ code:
#include <iostream>
#include <string>

enum class Foo {
	YOS,
	POS
};

std::string to_string(const Foo foo) {
	switch (foo) {
		case Foo::YOS: return "YOS";
		case Foo::POS: return "POS";
	}
}

std::ostream& operator<<(std::ostream& os, const Foo foo) {
	return os << to_string(foo);
}

int main() {
	std::cout << Foo::YOS << Foo::POS << std::endl; //prints "YOSPOS"
}

C++ :golfclap:

Here's my "improvement" but I don't know if this is horrible or good:

C++ code:
#include <iostream>
#include <string>

// Add new Foos here, not elsewhere. Good luck.
#define FOO_LIST \
    X(YOS) \
    X(POS) \
    X(BITCH)

enum Foo {
#define X(x) x,
    FOO_LIST
#undef X
};

std::string to_string(const Foo foo) {
	switch (foo) {
#define X(x) case x: return #x;
                FOO_LIST
#undef X
	}
}

std::ostream& operator<<(std::ostream& os, const Foo foo) {
	return os << to_string(foo);
}

int main() {
	std::cout << Foo::YOS << Foo::POS << Foo::BITCH << std::endl; //prints "YOSPOSBITCH"
}
Edit: I can't figure out how to get it to work with enum class but there you go

Hunter2 Thompson fucked around with this message at 20:12 on Jan 26, 2016

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
I'm working on an IoThing that comes up as a wifi AP on first boot. The user connects to the AP, then uses our app to send the SSID and password of their home network to the IoThing (as the IoThing doesn't have a display or keyboard of its own).

The IoThing scans in-range wifi networks and presents a user with a list of SSIDs, to improve the ~user experience~.

This whole thing is done using a small webserver running on the IoThing and HTTP GETs, PUT, etc. If you know the URL, you can connect to the AP and get JSON back with a list of nearby SSIDs.

It turns out if there's an SSID named "*", you'll get the following in your JSON:

code:
{"wifi_survey: [
    {
          "BSSID": "REDACTED",
          "SSID": "factory_reset.sh factory_test.sh firmware_update.sh
            get_calibration.sh initial_setup.sh network_info.sh package_update.sh
            reboot.sh setup_lan.sh system_dump.sh wifi_survey.sh",
          "Channel": 1,
          "Mode": "11b/g/n",
          "Signal": 100,
          "Security": "WPA2PSK/AES"
     }, ...]
}
You can imagine what SSIDs like "/*" or "/*/*" produce...

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
A recently-departed (quit, not dead) coworker wrote most of the IoThing code and I'm attempting to clean up some of the mess.

Our IoThing hasn't shipped yet (and this will be fixed when it does), so I don't think it counts for InternetOfShit, as much as I wish it would. I'm sure I'll see our stuff there eventually because the product is ridiculous. We paid for ten grand for a security audit and they didn't find this --so I'm sure there will be lots of other, better bugs uncovered soon.

For those interested, the hole comes from using the shell builtin "read" to go line-by-line through the wifi site survey, I guess read globs the *. I don't think there's a remote-execution by a carefully-crafted SSID vulnerability but since I'm an idiot at shell-scripting I don't know for sure. I tried making an SSID named $(echo "owned" > /tmp/owned) but it did nothing.

I'm fixing the problem with a C++ program that uses ioctl to get the nearby APs and output JSON directly instead of this shell script string manipulation garbage.

Hunter2 Thompson fucked around with this message at 03:34 on Jan 29, 2016

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

Shaggar posted:

security audits are the most useless poo poo

It's now my impression security audits like this exist only for CYA reasons, not to actually find or fix issues. One "critical" issue the audit uncovered was that you could get a root console on the device --if you had physical access, opened the case and soldered a serial cable to the right test pads. Give me a break.

From all the crazy poo poo I read on the internet I've learned that if somebody really wants to reverse-engineer your lovely IoT product, a password on the serial console isn't going to stop them. They're going to unsolder your flash memory and dump it over SPI...

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

JawnV6 posted:

ive updated my BLE stack

the old version smuggled functions around by hiding them behind #define's with \'s at endline to club a few of them together

that obfuscation wasn't good enough for the vendor. so now they're handling those callback inits with a 20 entry array passed in with mostly NULLs and I can't find the index definitions anywhere

Please name this vendor so I can avoid them tia

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

meatpotato posted:

I'm fixing the problem with a C++ program that uses ioctl to get the nearby APs and output JSON directly instead of this shell script string manipulation garbage.

No I'm not.

The ioctl returns the same column-formatted data that 'iwpriv iface scan' (or w/e) returns. Why try?

I looked into the wifi driver source code, dug around until I found a 900-line struct an noped the gently caress out.

Edit: I'm so amazed that operating systems don't crash more often due to terrible drivers. Does the kernel protect against drivers doing stupid poo poo?

Hunter2 Thompson fucked around with this message at 21:41 on Jan 29, 2016

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
Another great bug:

Sometimes the system would get into a state where HTTP GETs to our CGI handler would instead return the handler executable (!!!) rather than executing the handler and replying with its output.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

Soricidus posted:

you could at least parse the column-formatted data in a language that doesn't helpfully treat strings as filesystem globs?

Available tools: awk, sed, etc., C++ std lib.

Which do I use? I'm proficient at none, gonna learn something though.

Side note: Sorry people with leading or trailing spaces in your SSID, I guess we can't connect to you.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

JawnV6 posted:

who out there is super happy with their BLE folks? nordic seems like a moving target, TI's great if you're big enough to get support, broadcom/csr/etc won't talk to you until you're in the millions

vendor's been great for everything else, but this one part smells like a recent acquisition. and i should've been dealing with this stuff a while ago, but I kept the tools frozen until the last release

I was very happy with Nordic's nRF51822 when I did a project based on it. The SoftDevice was really easy to use and fit most of our non-exotic needs. We used CrossWorks' toolchain/IDE but if I had to go back I'd probably just make a GCC and CMake toolchain myself.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

craisins posted:

can't you just escape poo poo? when you see /* just turn it into /\* or something stupid and change it back when not using JSON?

qntm posted:

this is actually hilariously tricky to do correctly

I changed the shell script in two ways, only one of which is required to solve this specific problem but more is better, right?

1) Set the IFS to '\n' (to read a line at a time, rather than the default which is merely whitespace-separated) and use a for loop rather than 'read', which was globbing. Actually, this behavior makes shell scripting 1000% better. It should be the default IMO (learned about it here http://redsymbol.net/articles/unofficial-bash-strict-mode/).
2) I later learned that I can simply disable globbing with 'set -f' at the start of the script.

I'm looking into more ways to harden these stupid scripts, but I don't know how to attack them so I don't know how to harden them. The first step ought to be checking if lighttpd is escaping query strings, I think.

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
Nah, we're using somebody else's sh-based hand-rolled json library. Large parts of the project are hosed up, but it's not completely stupid. Actually, the largest part of the system is C++ with a few non-std libs. I'm just off in a small corner that was written in sh instead. I don't know C++ well enough to justify re-writing the few mostly-working scripts we already have.

Our processing power is actually really good, I think our main application only uses ~10% CPU time. Like Soricidus said, space is a limiting factor. We have <8 MB of flash to hold Linux + our application + persistent data storage + everything else we need (debug tools, etc.).

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
I think we have 128 (or 64, can't remember) MB of RAM. The Linux image is stored compressed in a special section of flash and a bootloader unzips the kernel to RAM when the system boots. Very common as far as I can tell.

Adbot
ADBOT LOVES YOU

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme

Ludwig van Halen posted:

8mb? what luxury!

Up until now my only paid programming experience has been with under 256 kB of flash and 16 kB of RAM, so yeah it actually feels pretty nice.

Unfortunately those small systems are way easier to debug.

Since /tmp maps to RAM we have space for some decently-sized debugging tools on this system. However, MIPS is a ghetto and while lots of relatively standard software will compile to a MIPS target, it won't run. Valgrind, for instance, just hangs and consumes 100% CPU. We can run gdbserver and remote debug easily, but it's not really completely functional. Most of the time we can't get a backtrace when poo poo crashes. This partially is because MIPS doesn't have a frame pointer register, but also because the signal handler code for Linux on MIPS isn't complete. :(

  • Locked thread