2020-08-27

Pseudo C++ using cpp (the RevK macro)

I am not sure if this is evil, or genius, or both. Either way I take full credit.

Mainly for a library where we want to add extra optional options in the future, so want almost C++ style optional and tagged arguments to a function, but in normal C (because C++ is just evil all by itself).


Not quite as flexible as C++, as no defaults for missing arguments, but you can often live with that knowing they are zero or NULL.

Unless someone can cite a prior art - please call this the RevK macro.

P.S. I have updated my string decimal library to use this, and it is way neater!

Some explanation...

Normally a function call in C has a fixed set of arguments. Well, not quite, some can have variable arguments at the end, like printf(...) but that is handled in a special way and you have to know (usually from a format string) how many arguments and which type.

However, in some languages, like C++, you can have optional arguments which are pre-defined types and names, but you can stop early in the list. In C++ you can say what default these missing arguments have. You also have the option to leave some arguments our and "tag" some others.

So, the idea you can call myfunc("hello",flag2:1) is setting the first argument (s), and the third (flag2) and not specifying the middle one (flag1) which ends up zeroed. I can't set defaults but can expect unspecified to be zeroed.

Now, normally, if I had some function you call as func(a,b,c) and I want some extra option later on, I would have to either change to func(a,b,c,d) everywhere it is used in every program, even if people specify d as 0 or NULL,  or make a new separate function that takes the extra argument as an alternative, e.g. func2(a,b,c,d).

With this trick I am able to add this extra argument which is optional, knowing that if the extra argument is not specified it has a known value of 0/NULL.

The way the trick works is by using the standard C pre-processor which does text substitution, and expanding the full list of arguments (...) in the macro (as __VA_ARGS__) within a structure initialisation. Unlike function arguments, C has a syntax to initialise a structure which allows you to omit arguments and tag arguments. I am using that syntax in the function, so myfunc("hello",flag2:1) becomes a structure initialiser {"hello",flag2:1} and this structure is passed to the function.

Of course I could just used C++, but that comes with a lot of other baggage, and not something I am that keen on. It has its merits and works well for some applications.

💩

 I have been involved with SMS (i.e. text messaging) for a long time. I was even on the ETSI committees that designed GSM (not specifically SMS, sadly), and have been doing things with SMS for nearly 30 years in one way or another, including an SMS->fax/email gateway, and even the ETSI landline SMS module for asterisk. Now, at A&A, we have code to send and receive SMS via a variety of carriers and even a SIP a-law based ETSI landline SMS system.

The specification for SMS is a typical telecoms specification - very different to internet specifications where single bits packed in some small data header can subtly change the interpretation of some or all that follows. These specifications are normally very precise but absolutely horrid, in my view.

But where does the pile of poo come in, and how does it relate to a 30 year old specification for SMS? Well, you may be surprised, but SMS allows for 💩.

SMS are actually coded in the signalling used for calls, and so had limited space. There were actually only 140 bytes (or more correctly octets) of data for the text itself. As you may know SMS allow 160 characters, so this is achieved by packing a 7 bit alphabet in to the 140 bytes.

In fact SMS allows 4 ways the data can be coded, a 7 bit special alphabet, an 8 bit Latin-1 alphabet, and 16 bit unicode (allowing 70 characters). There are also ways to send one longer message in smaller parts. The SMS can also be raw data to be sent to a SIM rather than displayed. Had I written this I'd have used 2 bits to say which it is, but no, the specification uses a Data Coding Scheme which is complicated to say the least. Some times the coding is in 2 bits but others it is implied. It is not fun.

The 7 bit alphabet is sort of ASCII, but does allow some interesting characters - being a European spec it includes some accented characters and even some Greek letters.

Of course this also leaves out some key ASCII such as {, }, [ ], and does not even have € (which was added later). These are coded as two character sequences using ESC.

The 8 bit character set is just normal Latin 1, and the 16 bit is unicode. The unicode allows all unicode characters U+0000 to U+FFFF, but where is pile of poo? It is U+1F4A9 which is too big for 16 bits.

The way this is done is to use a little known trick called UTF-16. There are reserved 16 bit unicode characters U+D800 to U+DFFF. Using two such codes it is possible to encode U+10000 to U+10FFFF.

This means 💩 is actually coded as two 16 bit sequences, 0xD83D 0xDCA9 in SMS!

Why does this matter, I mean, who sends 💩 by SMS? As you can imagine, in the early 90's nobody had heard of 💩, and the best emojis we had were :-)

But we do care, honest, as we use it as a blue* M&M test for carriers we deal with. If they have enough attention to detail to handle a pile of poo they probably have the rest sewn up, technically. We are working with a new carrier for SMS messages, and I am pleased to say the unicode is working. They properly translate to/from UTF-8 coding in the messages we exchange (which is what we use internally). Unlike our previous carrier who could not cope. (* see comments)

We have seen a range of such failures, even the case where one carrier could not handle an @ symbol (presumably as it coded to 0x00 which is an end of string in languages like C). Thankfully that carrier was happy for us to send a raw hex TPDU for SMS, and hence allowing us to code any characters. Our SIP2SIM service has handled pile of poo since we launched it...

The end result is that, shortly, we will be handling a lot more SMS with unicode characters correctly, in most cases, both incoming and outgoing. Watch this space.

2020-08-15

Making a meme?

This is my attempt to make a meme.


Of course, there is a danger that it will be seen as insensitive. Tricky one. If anything I am having a go at ofqual. I do feel rather sad for students struggling with downgraded exam results this year. The whole situation is crazy.

I know there are plenty of people that say that they got poor results and did fine, and I know that a lot of companies would not worry about A-level grades when hiring someone, but it is a gateway to university. I vaguely remember my concern over results and whether it met the offers I got from universities. Wrong grades can ruin a promising carrier before it starts, especially in vocations like medicine. I really hope they fix this somehow.

As for making a meme - we will see. I did include a "deliberate mistake" so people can feel smug pointing it out - I think that is a feature that helps a meme happen. (well, one mistake, one that looks like a mistake but sort of isn't, so people can argue over it).

P.S. My keyboard broke, started constantly repeating keys - ones I went nowhere near with the screw driver. I think it is just getting it's own back at me.

2020-08-01

A simple flat tyre - but this is 2020, so no...

Really boring post for your today...

On cycling out of Bracknell town on one of the cycle paths (see, I do use them when they go where I want), I hit a pot hole. I have been back and looked since and it looks really innocuous, but it was very jarring and my first thought is that it will have killed my tyres.

Unsurprisingly, within half a mile, or so, I had a flat back tyre. Crap!

I got a lift back from Tescos, and later walked in (3 miles) with my cycle repair kit and pump. The puncture was obvious, and not that small, so I used the sandpaper thing on the rubber and applied a self adhesive (skabs) patch, pumped up and cycled home. Perfect, job done.

Next morning, tyre flat! I investigated and it was the patch, it had popped allowing air out the side. WTF? I patched again and it immediately popped when pumping up.

I figured that maybe the glue goes off, this repair kit was a few years old, so ordered more. When that arrived, patched, and the same!

So I ordered a different make of self adhesive patch this time.

Again, popped as soon as inflated. This is mental.

I figured it was on a seam in the tyre, so I carefully trimmed that flat with a scalpel blade and tried again, no joy.

OK, time to go old school. I ordered good old fashioned repair kit with the rubber patches and the rubber glue.

I have probably done hundreds of puncture repairs in my life, and never had this trouble.

To my surprise, that did not work either, WTF?

Just to be clear, and thanks for all of the helpful advice, I did apply glue and wait for it to dry before applying the patch. I also, on some attempts, applied glue to the patch, which I don't normally have to do.

I tried the large patch sideways to cover where it popped, no joy.

I even applied a patch on top of the patch where it popped, no joy.

As an almost last resort I even used some Loctite 480 which is especially for bonding rubber. Close, but still popped.

This really is getting beyond a joke. I have never had this much trouble with a simple patch to an inner tube in my life.

I think I now have six puncture repair kits.

I have ordered a new inner tube, and some would say that should have been step 1, or at most step 2. Well, yes, except this is the back wheel with hub brakes, hub gears, and enclosed chain guard, all of which need removing, and at least one cable needs unhooking (and hence re-fitting and adjusting) and to be honest that seemed like a lot of hassle. Hence trying the simple puncture repair.

I then had a brain wave... This puncture is not a usual puncture. Well, apart from now being a tear around 5mm long because of the number of patches I had removed, it was on the inside of the inner tube, i.e. facing the wheel. This fits with it being pinched when I went over a pot hole - after all the tyres I have are meant to be puncture resistant. So not the usual place to get a puncture, which would typically be from a spiky thing through the tyre and hence on the outside. In fact, it was almost certainly exactly on the part where the inner tube is not going to be smooth when inflated, but actually a step where the inside of the tyre is in the wheel. This may be the clue, and why it only popped when inflated ing the tyre (I could inflate quite a bit outside the tyre with no issue).

My fix! Well, for a start I used the Loctite to weld the tear shut anyway, and applied a rubber patch over that. The trick, though, was a plastic card (credit card sized) bent round on the inside of the tyre between the wheel and in inner tube. A real hack, but magically the tyre inflated, and I have managed to cycle round the block and no sign of it deflating yet.

Yay, sorted, and, bollocks, the front tyre is now flat. That seems to be a much smaller slow puncture which was actually simple to fix with a patch as normal (well, so far).

So yay. I do have a spare inner tube coming tomorrow, and I hope I don't need it.

I would stress that this has taken (I think) 4 days now, and so given my run of luck I fully expect to find both tries flat tomorrow, probably pecked by a crow or eaten by a squirrel or something...

Update: Using a card was certainly a clue, as it lasted a lot longer than anything else, but today (the next day) the back tyre is flat again - so fun with dismantling stuff when the inner tube arrives. FML.

... And someone has "borrowed" my Allen keys, arrrg!

Update: I have two inner tubes and new Allen keys. Yay. I figured I would change front one first. It literally exploded in the tyre at around 50psi. WTF?! So now waiting until tomorrow for another new inner tube. I did not have this on my 2020 bingo card.

Looks like it is a full moon at just before 5pm today - is that a bad sign I wonder?

Update: Finally, new inner tube fitted to the back. All working. Pain in the arse to take it all apart though.


P.S. I now find I put the front wheel back wrong and have been cycling with brakes partly on - I thought I was just unfit (which I am), but that was daft. Finally all sorted now.

2020-07-16

Account switching (Barclays to Monzo)

As you almost certainly know, there is an "account switching service" which UK banks use. I had never used it before.

TL;DR: Switching works, but it seems Barclays "mess about" for a whole day, losing details of payments and even losing credits down the cracks - yes, money just going missing!!!

Why have I not used it before? well, I have accounts with several banks, and there is really no reason to close an "old" account at any point, especially given the hassle it is to open most bank accounts (Monzo and Starling being obvious exceptions). So why would I "switch"? I can simply start using a new account for some things, simples. I appreciate that some people can't do that quite as easily.

The switching does several things - moving over your Direct Debits, and Standing Orders, transferring the old balance over, and closing the old account. Importantly any credits to the old account are forwarded to the new account.

I was interested in the mechanics of the process. I know from dealing with BACS and Direct Debits that there is a method to advise when an account has changed. As a Direct Debit originator we get told if someone changes their bank account and we are required to update the Direct Debit details. We also get told if we send money to a closed account that we used the wrong details (the money is forwarded).

I would hope there is a process for Fast Payments in the same way...

So here goes...

Setting it up (on Monzo)

Monzo make it easy - they have a button with a simple step by step guide. But there is a snag - the step by step instructions say you need last 5 digits of a debit card on the account. Hmm, the account in question did not have a debit card, so I had to order one from Barclays and wait for it to arrive. However, when I then continued with the process it DOES NOT ask for the card digits because I was moving a business account not a domestic one. I have fed back to Monzo.

I had to confirm the Barclays account, name, and address, and agree some terms, and that was it. Simple. It is then set for 8 days later.

Notifications


Monzo immediately did an in app notice saying it was started, a couple of days later another saying they had confirmation from Barclays, and then on the day a notice saying it was done.

Barclays posted a letter saying I was transferring.

All very slick.

On the day


I was curious as to the timing. Banks (traditional banks) tend to work on banking days. So I expected that it would be everything on 13th (the day before) would be normal, then everything dated 14th would be on new account, with closing balance on 13th being the amount transferred to my new account. To my surprise that was not quite the case.

Barclays were a bit odd, they said they would send printed statements, but that if I had another account and continued access to on-line banking that I would be able to see on there and that they would not send a statement. On the 13th they charged me for sending statements (not checked at office if they did). This was slightly devious as I had cleared the account to £0.00. This unexpected charge would make it overdrawn if I had not checked, and break the switch somehow.

07:09 I sent a £1 fast payment from a Lloyds account to the Barclays account. It arrived as normal, showed on the Barclays on-line banking. So I transferred out leaving £0.00 still. So the switch had not happened yet.

09:00 Monzo popped up and said switch done. So I checked Barclays, and account no longer showing. Seems the switch happens at 9am. Would have been good to know to be honest. It was lucky I had downloaded the CSV for previous day from Barclays before 9am, as I could not after 9am.

10:08 I sent another £1 fast payment. It went, and vanished!

15:34 I get a transfer to Monzo, not with the details of the fast payment I sent, but cryptically BFA ACC SWITCH GLOS reference  RESIDUAL BALANCE from account 20-33-83 88010803...

So I assume Barclays idea of when the switch was done, is not quite the same...

16:41 I send another £1, and to my surprise it is not immediately sent to Monzo. It has vanished!

Also, to my surprise, the Fast Payment process has not updated the payee details. Does it lack the simple "wrong account" logic that exists in BACS? That would be really silly, surely? I suppose, as a stretch, the BACS AWACS system is used to update, and so will happen in a day or two.

I emailed my Barclays account manager, and she said "it takes a day to switch" and that it will be all OK tomorrow... Hmm...

Next day


Still no sign of the missing £1.

A download CSV all accounts download from Barclays DOES NOT INCLUDE the old account, so I don't have the transaction on the day of transfer - that is a tad annoying!

08:52 I sent £1.15 from Lloyds to Barclays, and ka-ching, Monzo showed the payment instantly. Monzo shows correct sender sort code and account (i.e. not the Barclays one) and the correct reference. This is working nicely.

The bank details on my Lloyds account have not updated. So looks like fast payment does not have a "push back" to advise the new details. Maybe it uses BACS AWAS, in which case it will be a day or two, so I'll check.

The day after


I checked my Lloyds account, and now the details shown have magically changed to the new account. I assume this was BACS AWACS, but it works. Yay!

Issues


  • It is unclear why Barclays "mess about" for a whole day - surely they could simply set a time, such as 9am, transfer the balance at that time, and relay all payments after that time. It is messy.
  • Whilst a payment in the morning did arrive later as a "residual balance" there are no details. I assume if I had several payments in the morning I would not have seen any details of them, or even how many payments, just a balance. That is crazy. It is fortunate we already had most customers using the new account.
  • The payment in the afternoon is missing still! I will wait and see if it turns up. Of course, customers could have also paid us in the afternoon and also be missing. Very worrying!
  • Of course, I could only download CSVs of my Barclays accounts to the day before, and only because I checked before 9am, so no way to get a CSV of transactions on the day of the switch - also crazy.
My account manager at Barclays says it is the same for all banks - which I doubt. Has anyone else done a bank switch and can they confirm if they have the same fiasco for transactions on the day?

I'll update if I hear any more of the missing £1. I half expected it to arrive 15:30 on 15th, but no, it had just vanished in to thin air. Scary stuff.

Update: After 2 days of nagging my account manager, they say they have found the £1 and sent it to me. However, it has not turned up, even allowing for 2 day BACS (why would they do that anyway), so still chasing. Worrying.

Update: After more chasing, 15:34, 3 days later, they fast payment me the missing £1. Finally.

2020-07-04

New covid rules (England, July 4th)

There are new rules - at almost no notice without any parliamentary oversight, as is now usual!

They have gone for a complete rewrite this time.
The Health Protection (Coronavirus, Restrictions) (No. 2) (England) Regulations 2020

Basically, gatherings up to 30 people now and more places allowed to be open subject to risk assessments and measures. All a bit wooly if you ask me.

But also special rules for Leicester
The Health Protection (Coronavirus, Restrictions) (Leicester) Regulations 2020

The way they have defined the area is rather odd, if you ask me. It seems they have picked something, perhaps a distance, or drawn a line, or some such, and then used a tool to make a list of postcodes and addresses. It would seem to me to have been simpler to just cover whole postcode areas rather than have 24 pages listing postcodes and addresses.

The addresses include gems like this on page 34!

PUBLIC TELEPHONE 33M FROM 109 WELFORD ROAD 9M FROM UNNAMED ROAD ROUNDABOUT AT THE JUNCTION OF GUTHLAXTON WAY AND WELFORD ROAD WIGSTON LE18 3TE


I found it on street view.


So no gatherings of two or more people in that phone box!
That, to me, suggests this was really not thought about in any detail.

2020-06-23

Beyond credit cards - is this a way forward?

We all buy things on-line all the time, and use credit or debit cards to pay on web sites all of the time. As a company we have taken cards with orders in the past, but now most of our business is ongoing services paid by Direct Debit.

Recently we changed the main account to which customers can send payment (when not paying by Direct Debit) to Monzo Bank. The reason, as I explained in my blog post, was that we get instant web hooks for incoming fast payments. I suspect this may be possible with some other banks, perhaps with OpenBanking, and that is something we do want to investigate, but it works well with Monzo.

Apart from allowing incoming payments to instantly be assigned to customer accounts, allowing sales and accounts staff to see the money and ship goods, place orders, or remove restrictions on an account, we also introduced a new feature for deposits with orders.

The idea was to take money by bank transfer as part of an order. This helps avoid some fraudulent orders, and means we have money up front. It also means we have bank details to validate correct Direct Debit instructions.

This was rather experimental - we had no idea how customers would react. We know people are familiar with a credit or debit card with an order, but sending money by bank transfer is not something that is at all common. We made it totally optional, but obviously having had payment with order it means we can progress orders a lot more quickly. Sales staff can immediately ship goods without waiting for our accounts department to check credit or get a deposit.

Over time we have gradually added to more and more types of orders and for lower amounts, and even for existing customers if they do not have a direct debit set up or working. In some cases we only ask for £1 or £2 deposit even, in others it is the whole cost of equipment being supplied.

To my utter surprise it is hugely popular - we have now handled many tens of thousands of pounds in this way. I recall only one case of someone specifically declining to pay a deposit with order so far, and I am frankly gobsmacked, this is excellent!

As a merchant

As a merchant this is a lot easier than taking credit or debit cards.
  • No card processing fees.
  • No delay receiving payment.
  • No PCI DSS hassle (yes, obviously we comply with GDPR and have a privacy policy).
  • No risk of a chargeback - it is just like cash.
  • Allows us to validate Direct Debit details for on-going services, reducing mistakes and fraud.
  • No choosing which cards to take or not take as any UK bank can send faster payments.
  • No joke, scam, or fraudulent orders as they don't seem to want to send money up front.
  • No real minimum, though some banks seem to dislike smaller than £1 (card fees often make small purchases by card less cost effective).
Overall it is a stupidly good deal for us - we get payment just like cash but don't even have the hassle or cost of handling cash! We can automate a lot of things, unlike cash.

As a customer

As a customer, are there advantages? Are there disadvantages? As we say, for a start, we make it optional (except in one case where we do see fraud with a particular VoIP service), but people do love it, which is great news.
  • Faster order processing, we have the money so we can go ahead with the order, often automatically (so for VoIP, and L2TP these can be working in seconds any time of day or night, and for broadband the order for lines/circuits are even sent automatically).
  • The UK banking system's "Confirmation of Payee" process means that the customer knows they are paying us, by name, and so they know who has their money (very often unclear when paying by card).
  • If an order does not go ahead, or any other reason for refund, it can be instant, unlike (mostly) with card payments - though it does depend on us sending it back (which we do).
  • If we refund, that is final - unlike cases I am now seeing where a card chargeback is now being disputed by the merchant months later, and I don't know for sure if my chargeback is "safe" yet.
  • The lack of fees helps keep prices low.
  • No need for address match - if wanting to send to a friend you can, as you have paid, just like cash.
Of course there are some disadvantages. With a card, a chargeback is possible, and it is also possible with a credit card for some amounts to hold the card company liable for failure. Obviously this also only works if you have the money and don't need credit from a card.

I really think there are businesses that could operate entirely like this without the need to take credit or debit cards at all. For small companies, especially struggling to recover after COVID-19, this could be extremely useful.

Teething problems?

Obviously the process was not without some issues, but we have it quite slick now. Most issues are around people who simply cannot type a correct payment reference.
  • Monzo very quickly fixed a Confirmation of Payee issue with our company name, and are working on the missing ampersand at present.
  • We created a system to allocate a payment reference (account number on our system) without customer details yet, and ensure that did not then change later for future payments.
  • We created a system so that the ordering process can check for incoming payments on such an account number cleanly and get bank details for setting up Direct Debit.
  • We created a system to refund (by BACS at present) any deposit if the order does not complete. Hopefully in future we'll have a faster payment means to refund, and I can do it manually (as I have been).
  • We had to decide how much money to charge - if just a deposit for good will and Direct Debit details, or if paying the total up front. We fine tuned how much we ask in each case over some months depending on the type of service, the risk to us, the goods being supplied, etc.
  • We decided to make the up front payment whole pounds to try and avoid typing errors, and this has worked well - we are selling ongoing services so any balance of pence just ends up part of the first Direct Debit. This will obviously not be the case when just selling goods (which we plan to do also).
  • We discovered just how bad people are at typing a payment reference correctly - it is a real shame that the Confirmation of Payee system does not allow us to send a regex for the reference! However, when a payment is wrong, we can easily immediately return it with "Wrong reference". This worked well and for once customer they resent with the right reference, all during the order process!
  • The real time payments, and the payer name and bank details, also help allow us to easily tie up a payment with an order if a customer does make mistakes. We allow the customer to say carry on without deposit and flag that they had issues with the order. That has worked well for those few cases.
  • We have introduced a checksum system that makes it easier to ensure a wrong payment does not simply go to someone else's account (easy to spot, but more of a nuisance as we email that customer confirming payment). Sadly we do not yet have a means to instantly automatically return such payments, but one day we will I am sure.
  • Not really for new customer orders, but we have added a system to automatically email a statement to any existing customer paying - we also set a system to cancel any pending Direct Debits that are possible when applying the new payment. We even set the system to automatically remove restrictions on service automatically once payment arrives. Customers have used this to pay by bank transfer instead, and the system is totally automatic now!

Barcodes?

I have suggested before that we need barcodes for this, and someone has pointed to a draft RFC (here).

This is similar to what I proposed in 2017. If it actually becomes an RFC that may be a good start to people actually understanding them. We just need banking apps to start handling payto: URLs and things will be a lot simpler.

Spectre

A "Spectre" is a new shape. Yes, I did say new shape ! It is pretty incredible that there can be any such things as  new shape , I...